Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Gavin0210 opened this issue Mar 21, 2023 · 8 comments
Open

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

Gavin0210 opened this issue Mar 21, 2023 · 8 comments

Comments

@Gavin0210
Copy link

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
Copy link

ExternalAddress4401 commented Apr 23, 2023

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
Copy link
Member

oleavr commented Apr 23, 2023

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
Copy link

ExternalAddress4401 commented Apr 23, 2023

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
Copy link
Member

oleavr commented Apr 24, 2023

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
Copy link

ExternalAddress4401 commented Apr 25, 2023

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
Copy link

So any solution for this?

@dzervas
Copy link

dzervas commented Oct 20, 2023

@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
Copy link

@Gavin0210 did you manage to compile ws?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants