frida / frida-compile

Compile a Frida script comprised of one or more Node.js modules
Other
186 stars 49 forks source link

unable to resolve: tls, crypto, zlib, bufferutil, utf-8-validate #65

Open Gavin0210 opened 1 year ago

Gavin0210 commented 1 year ago

code import WebSocket from 'ws'; command: frida-compile test_compile.js -o test.js frida-compile version 16.1.8 following is package.json { "name": "test_frida_compile", "version": "1.0.0", "description": "", "main": "test.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "type": "module", "dependencies": { "ws": "^8.13.0" } }

ExternalAddress4401 commented 1 year ago

Crypto definitely worked in version 10. This is one of the most disappointing updates I've seen. How did we go from a working project to one that barely works without scouring the closed issues section?

It looks like 10 did something with browserify? to add node modules but has since dropped it so they just don't work.

oleavr commented 1 year ago

Crypto definitely worked in version 10. This is one of the most disappointing updates I've seen. How did we go from a working project to one that barely works without scouring the closed issues section?

Sorry to hear that. The how is pretty simple: I ran out of time. So much blood, sweat and tears went into the rewrite that at some point I had to draw the line and consider it complete enough to get back to focusing on higher priority areas in Frida.

It looks like 10 did something with browserify? to add node modules but has since dropped it so they just don't work.

The new compiler only supports ESM, which means we couldn't use the existing Browserify shims without porting them. That's what I've done, but there are still a few missing. Perhaps you'd be interested in taking a stab at adding the ones you need for your particular project? PRs are super-appreciated. I am spread way too thin unfortunately.

ExternalAddress4401 commented 1 year ago

Crypto definitely worked in version 10. This is one of the most disappointing updates I've seen. How did we go from a working project to one that barely works without scouring the closed issues section?

Sorry to hear that. The how is pretty simple: I ran out of time. So much blood, sweat and tears went into the rewrite that at some point I had to draw the line and consider it complete enough to get back to focusing on higher priority areas in Frida.

It looks like 10 did something with browserify? to add node modules but has since dropped it so they just don't work.

The new compiler only supports ESM, which means we couldn't use the existing Browserify shims without porting them. That's what I've done, but there are still a few missing. Perhaps you'd be interested in taking a stab at adding the ones you need for your particular project? PRs are super-appreciated. I am spread way too thin unfortunately.

At this point I'm only missing crypto and could work around it but I'd be very interested in creating the new shims but I wouldn't be that sure how.

I noticed for example the assert shim looks a lot like https://github.com/nodejs/node/blob/main/lib/assert.js but you've mentioned browserify shims which I'm not exactly sure about the specifics on.

I'm still going to investigate but is there a brief high level explanation you could give regarding creating shims?

EDIT: I've discovered the browserify shims at repos like https://github.com/browserify/crypto-browserify

This should help me get started.

I'm going to start with trying zlib since crypto looks like a lot of work. The only outside dependency the browserify shim uses is pako which I think I have converted that I want to try.

I'm doing lots of slow research into CJS vs ESM and converting some of these gross looking Object.defineProperty(exports statements as well as how I'd do this in ESM

import * as binding from "./binding.js";
binding.Z_MIN_WINDOWBITS = 8;

But I think it's coming along well.

oleavr commented 1 year ago

At this point I'm only missing crypto and could work around it but I'd be very interested in creating the new shims but I wouldn't be that sure how.

I noticed for example the assert shim looks a lot like https://github.com/nodejs/node/blob/main/lib/assert.js but you've mentioned browserify shims which I'm not exactly sure about the specifics on.

I'm still going to investigate but is there a brief high level explanation you could give regarding creating shims?

Thanks! Basically what I've done is extract/port Node.js internals where the implementation seems reasonably untangled from their native code, and the Browserify shim when that isn't the case.

EDIT: I've discovered the browserify shims at repos like https://github.com/browserify/crypto-browserify

This should help me get started.

Note that Frida's Checksum API should be enough to cover e.g. createHash(), to avoid some unnecessary JavaScript bloat.

I'm going to start with trying zlib since crypto looks like a lot of work. The only outside dependency the browserify shim uses is pako which I think I have converted that I want to try.

Sounds like a great plan!

I'm doing lots of slow research into CJS vs ESM and converting some of these gross looking Object.defineProperty(exports statements as well as how I'd do this in ESM

Cool! The cjstoesm project might be helpful, at least as a starting point.

ExternalAddress4401 commented 1 year ago

I've half succeeded!

image

This is a gross mashup of code but I've proven to myself I can do it so now I can go back and better examine the exports.

Tomorrow hopefully I can clean up zlib and then tackle the beast that is crypto for my project.

kolanski commented 11 months ago

So any solution for this?

dzervas commented 11 months ago

@kolanski you can try the esbuild way Take a look at my project on how to configure it: https://github.com/dzervas/frida-afterburner

My project should be a PR to both frida cli and frida-compile but rn I don't have time...

blogtron commented 4 months ago

@Gavin0210 did you manage to compile ws?