seia-soto / snapit-pkg

A simple tool to extract resources from Pkg executable dynamically.
MIT License
2 stars 0 forks source link

Support pkg version 4 (Failed to find a valid hooking point!) #1

Open xOnlyFadi opened 2 years ago

xOnlyFadi commented 2 years ago

Hi Snapit Pkg author when I used your tool with the same commands that they were given in in readme I get the error meesage Failed to find a valid hooking point! is there a way to fix it?

seia-soto commented 2 years ago

Hello, thank you for reporting. I am about to start investigation in few days after scheduling the work. Before, the investigation, please checkout following items again.

I checked the original file on https://github.com/vercel/pkg/blob/main/prelude/diagnostic.js but there was no change since 2021.

xOnlyFadi commented 2 years ago

Hey Thank you for responding when checking the exe and searching for installDiagnostic I did not find anything about that function and in the package.json i saw

{
    "pkg": {
        "scripts": [
            "source.js",
            "mangareader.js",
        ],
        "targets": [
            "node10-linux-x64", "node10-macos-x64", "node10-win-x64"
        ]
    }
}
seia-soto commented 2 years ago

Thanks for checking out. I confirmed that the previous hooker only works on binaries which enabled debug flag when building. The latest commit should work even there is no debug flag set when building. Please, try out.

xOnlyFadi commented 2 years ago

I just tested it there is no errors anymore but I don't see the patched file to run it

seia-soto commented 2 years ago

You should see original_filename.patched in the same folder. Don't you see it?

xOnlyFadi commented 2 years ago

I don't see a file called original_filename.patched

xOnlyFadi commented 2 years ago

I just ran it again and saw a dot removed and I still get the same error

snapit-pkg/hookers/pkg.js:122
      throw new Error('Failed to find a valid hooking point!'
seia-soto commented 2 years ago

What's your original file name? Can you give me an example, so I can check my understanding again?

xOnlyFadi commented 2 years ago

the current file name is localnoderserverunkillable_win.exe, If you want the file I can give you the file so you can test it on your side

seia-soto commented 2 years ago

Sure, use your preferred file sharing service. You can email me: seia@outlook.kr (PGP supported).

xOnlyFadi commented 2 years ago

just sent a email with the link

seia-soto commented 2 years ago

I checked it and confirmed the reason is because your binary compiled using pkg version 4. I'll prepare the patch.

xOnlyFadi commented 2 years ago

oh ok thanks for the help one more question when getting the patched file out do rename the file to exe and just run it right?

seia-soto commented 2 years ago

Yes, that's right. On macOS, you can use 'chmod +x` command to convert into executable.

xOnlyFadi commented 2 years ago

and what if I was on windows do I rename the file to exe and run it?

xOnlyFadi commented 2 years ago

I just ran the command I got filesync error TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received function patch

seia-soto commented 2 years ago

Yes, I am working on.

xOnlyFadi commented 2 years ago

are there more fixes for it, so it can be compatible with pkg4?

seia-soto commented 2 years ago

Yup, I am expecting full refactor soon. I am super busy due to university registration these days. Can you check latest commit?

xOnlyFadi commented 2 years ago

tested it on windows and I get the file but on macos I get this error Error [ERR_LOADER_CHAIN_INCOMPLETE]: "file:///Users/username/Desktop/snapit-pkg-master/.pnp.loader.mjs 'resolve'" did not call the next hook in its chain and did not explicitly signal a short circuit. If this is intentional, includeshortCircuit: truein the hook's return.

xOnlyFadi commented 2 years ago

I can't run the file on windows when it's get patched by snapit

seia-soto commented 2 years ago

Yarn error on macOS is not reproducible. You should stash local changes and pull again to refresh the repo. Reinstalling the dependencies are recommended.

But about Windows, I think I need take time to setup Windows development environment.

xOnlyFadi commented 2 years ago

did the patching on mac or windows I get the same error Mac image

Windows image

xOnlyFadi commented 2 years ago

It’s late for me we can continue tomorrow or when you have time to fix it

seia-soto commented 2 years ago

Sorry but I cannot continue soon due to university registration process at least till 17. You should dive into the binary if you're in emergency.

xOnlyFadi commented 2 years ago

It’s okay I'm not in a emergency you can finish everything that is important in your life and then you can fix it

xOnlyFadi commented 2 years ago

Hey Seia when reading the error that was given in the console it was from the patch for child_process patch I don't know what made child_process not work when requiring it and the error is coming from here

// /////////////////////////////////////////////////////////////////
// PROMISIFY ///////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////

(function () {
  var util = require('util');
  var promisify = util.promisify;
  if (promisify) {
    var custom = promisify.custom;
    var binding = process.binding('util');
    var createPromise = binding.createPromise;
    var promiseResolve = binding.promiseResolve;
    var promiseReject = binding.promiseReject;
    var customPromisifyArgs = require('internal/util').customPromisifyArgs;

    // /////////////////////////////////////////////////////////////
    // FS //////////////////////////////////////////////////////////
    // /////////////////////////////////////////////////////////////

    Object.defineProperty(require('fs').exists, custom, {
      value: function (path) {
        var promise = createPromise();

        require('fs').exists(path, function (exists) {
          promiseResolve(promise, exists);
        });

        return promise;
      }
    });

    Object.defineProperty(require('fs').read, customPromisifyArgs, {
      value: [ 'bytesRead', 'buffer' ]
    });

    Object.defineProperty(require('fs').write, customPromisifyArgs, {
      value: [ 'bytesWritten', 'buffer' ]
    });

    // /////////////////////////////////////////////////////////////
    // CHILD_PROCESS ///////////////////////////////////////////////
    // /////////////////////////////////////////////////////////////

    var customPromiseExecFunction = function (orig) {
      return function () {
        var args = Array.from(arguments);
        var promise = createPromise();

        orig.apply(undefined, args.concat(function (error, stdout, stderr) {
          if (error !== null) {
            error.stdout = stdout;
            error.stderr = stderr;
            promiseReject(promise, error);
          } else {
            promiseResolve(promise, { stdout: stdout, stderr: stderr });
          }
        }));

        return promise;
      };
    };

    Object.defineProperty(require('child_process').exec, custom, {
      value: customPromiseExecFunction(require('child_process').exec)
    });

    Object.defineProperty(require('child_process').execFile, custom, {
      value: customPromiseExecFunction(require('child_process').execFile)
    });
  }
}());
xOnlyFadi commented 2 years ago

Hey Seia when are university registration process is gonna end so we can work and know why child_process is getting broken at that line?

seia-soto commented 2 years ago

Several major events are ongoing this year such as SAT and interviews. I will process this as I finish tasks at higher priority or requested earlier such as outsourcing projects or educational projects. You can do it yourself since you know what to do now and can access the dead simple sourcecode as I noted: you can do yourself if you need to grab the package content quickly.

seia-soto commented 2 years ago

I can tell you the exact date of majority events, but unfortunately, I could not give you an exact date to work in this package. I am really focusing in educational goals.