Git Product home page Git Product logo

frida-compile's Introduction

Frida

Dynamic instrumentation toolkit for developers, reverse-engineers, and security researchers. Learn more at frida.re.

Two ways to install

1. Install from prebuilt binaries

This is the recommended way to get started. All you need to do is:

pip install frida-tools # CLI tools
pip install frida       # Python bindings
npm install frida       # Node.js bindings

You may also download pre-built binaries for various operating systems from Frida's releases page on GitHub.

2. Build your own binaries

Run:

make

You may also invoke ./configure first if you want to specify a --prefix, or any other options.

CLI tools

For running the Frida CLI tools, e.g. frida, frida-ls-devices, frida-ps, frida-kill, frida-trace, frida-discover, etc., you need a few packages:

pip install colorama prompt-toolkit pygments

Apple OSes

First make a trusted code-signing certificate. You can use the guide at https://sourceware.org/gdb/wiki/PermissionsDarwin in the sections “Create a certificate in the System Keychain” and “Trust the certificate for code signing”. You can use the name frida-cert instead of gdb-cert if you'd like.

Next export the name of the created certificate to relevant environment variables, and run make:

export MACOS_CERTID=frida-cert
export IOS_CERTID=frida-cert
export WATCHOS_CERTID=frida-cert
export TVOS_CERTID=frida-cert
make

To ensure that macOS accepts the newly created certificate, restart the taskgated daemon:

sudo killall taskgated

Learn more

Have a look at our documentation.

frida-compile's People

Contributors

chichou avatar cosmosgenius avatar dependabot[bot] avatar freehuntx avatar gergesh avatar hsorbo avatar kc57 avatar leonitousconforti avatar leonjza avatar mrmacete avatar oleavr avatar riverar avatar strazzere avatar trufae avatar vfsfitvnm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

frida-compile's Issues

error on compilation: force install [email protected]

Trying to install frida-compile on WSL (also tested on Windows and Ubuntu 18.04).

running the command npm install and an old version of cylang (1.0.4) is attempted to be installed and failing due to missing .hpp files.

Upon force installing [email protected] (most recent), it will then fail on installing an old version of frida. Upon force installing the most recent of frida, it will try and pull down the old version of cylang again.

Error shown below:

npm install
npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated [email protected]: 🙌 Thanks for using Babel: we recommend using babel-preset-env now: please read https://babeljs.io/env to update!
npm WARN deprecated [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated [email protected]: request has been deprecated, see request/request#3142
npm WARN deprecated [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated

[email protected] install /mnt/c/Users/XXX/frida/compile/node_modules/frida-compile/node_modules/cylang
prebuild --install

prebuild info begin Prebuild version 4.5.0
prebuild info looking for local prebuild @ prebuilds/cylang-v1.0.4-node-v64-linux-x64.tar.gz
prebuild info looking for cached prebuild @ /home/user/.npm/_prebuilds/https-build.frida.re-cylang-v1.0.4-cylang-v1.0.4-node-v64-linux-x64.tar.gz
prebuild http request GET https://build.frida.re/cylang/v1.0.4/cylang-v1.0.4-node-v64-linux-x64.tar.gz
prebuild http 404 https://build.frida.re/cylang/v1.0.4/cylang-v1.0.4-node-v64-linux-x64.tar.gz
prebuild WARN install No prebuilt binaries found (target=v10.19.0 arch=x64 platform=linux)
prebuild info install We will now try to compile from source.
prebuild verb starting node-gyp process
prebuild verb execute node-gyp with node index.js rebuild --target=v10.19.0 --target_arch=x64
prebuild verb ok
prebuild verb ok
prebuild verb ok
make: Entering directory '/mnt/c/Users/XXX/frida/compile/node_modules/frida-compile/node_modules/cylang/build'
make: Warning: File 'cylang_binding.target.mk' has modification time 0.72 s in the future
CXX(target) Release/obj.target/cylang_binding/addon.o
../addon.cpp:23:10: fatal error: Driver.hpp: No such file or directory
23 | #include "Driver.hpp"
| ^~~~~~~~~~~~
compilation terminated.
make: *** [cylang_binding.target.mk:109: Release/obj.target/cylang_binding/addon.o] Error 1
make: Leaving directory '/mnt/c/Users/XXX/frida/compile/node_modules/frida-compile/node_modules/cylang/build'
prebuild ERR! build error
prebuild ERR! stack Error: make failed with exit code: 2
prebuild ERR! stack at ChildProcess.onExit (/mnt/c/Users/XXX/frida/compile/node_modules/node-gyp/lib/build.js:262:23)
prebuild ERR! stack at ChildProcess.emit (events.js:198:13)
prebuild ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
prebuild ERR! not ok
prebuild ERR! build Error: make failed with exit code: 2
prebuild ERR! build at ChildProcess.onExit (/mnt/c/Users/XXX/frida/compile/node_modules/node-gyp/lib/build.js:262:23)
prebuild ERR! build at ChildProcess.emit (events.js:198:13)
prebuild ERR! build at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)

ParseError: 'import' and 'export' may appear only with 'sourceType: module'

frida-compile version:

10.2.4

trace.js

import { JNIInterceptor } from "jnitrace-engine";

// Attach to the JNI FindClass method
JNIInterceptor.attach("FindClass", {
    onEnter(args) {
        // called whenever the FindClass is about to be called
        console.log("FindClass method called");
        this.className = Memory.readCString(args[1]);
    },
    onLeave(retval) {
        // called whenever the FindClass method has finished executing
        console.log("\tLoading Class:", this.className);
        console.log("\tClass ID:", retval.get());
    }
});

command

frida-compile trace.js -o agent.js

log

[SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'] {
  line: 1,
  column: 1,
  annotated: '\n' +
    '/Users/cyc/Projects/jnitrace/trace.js:1\n' +
    'import { JNIInterceptor } from "jnitrace-engine";\n' +
    '^\n' +
    "ParseError: 'import' and 'export' may appear only with 'sourceType: module'",
  stream: Labeled {
    _readableState: ReadableState {
      objectMode: true,
      highWaterMark: 16,
      buffer: BufferList { length: 0 },
      length: 0,
      pipes: [Labeled],
      pipesCount: 1,
      flowing: true,
      ended: false,
      endEmitted: false,
      reading: true,
      sync: false,
      needReadable: true,
      emittedReadable: false,
      readableListening: false,
      resumeScheduled: false,
      destroyed: false,
      defaultEncoding: 'utf8',
      awaitDrain: 0,
      readingMore: false,
      decoder: null,
      encoding: null
    },
    readable: true,
    _events: [Object: null prototype] {
      end: [Array],
      finish: [Function],
      error: [Function (anonymous)],
      data: [Function: ondata],
      _mutate: [Function]
    },
    _eventsCount: 5,
    _maxListeners: undefined,
    _writableState: WritableState {
      objectMode: true,
      highWaterMark: 16,
      finalCalled: false,
      needDrain: false,
      ending: false,
      ended: false,
      finished: false,
      destroyed: false,
      decodeStrings: true,
      defaultEncoding: 'utf8',
      length: 1,
      writing: true,
      corked: 0,
      sync: false,
      bufferProcessing: false,
      onwrite: [Function (anonymous)],
      writecb: [Function: nop],
      writelen: 1,
      bufferedRequest: null,
      lastBufferedRequest: null,
      pendingcb: 1,
      prefinished: false,
      errorEmitted: false,
      bufferedRequestCount: 0,
      corkedRequestsFree: [CorkedRequest]
    },
    writable: true,
    allowHalfOpen: true,
    _options: { objectMode: true },
    _wrapOptions: { objectMode: true },
    _streams: [ [DestroyableTransform] ],
    length: 1,
    label: 'syntax',
    [Symbol(kCapture)]: false
  },
  inputs: Set(7) {
    '/Users/cyc/Projects/jnitrace/trace.js',
    '/usr/local/lib/node_modules/frida-compile/node_modules/typescript/lib/lib.d.ts',
    '/usr/local/lib/node_modules/frida-compile/node_modules/typescript/lib/lib.es5.d.ts',
    '/usr/local/lib/node_modules/frida-compile/node_modules/typescript/lib/lib.dom.d.ts',
    '/usr/local/lib/node_modules/frida-compile/node_modules/typescript/lib/lib.webworker.importscripts.d.ts',
    '/usr/local/lib/node_modules/frida-compile/node_modules/typescript/lib/lib.scripthost.d.ts',
    '/Users/cyc/Projects/jnitrace/package.json'
  }
}

Anyone help? Thanks in advance.

Invalid tokens

Just out of curiosity, why are the invalid tokens in the generated output?

in frida-agent-example,

$ npx frida-compile agent/index.ts -o _agent.js -c

image

This doen's look valid javascript by the way..., that is to say,

% node _agent.js 
/Users/wc/scratch/frida-tools/frida-agent-example/_agent.js:1
📦
^

SyntaxError: Invalid or unexpected token
    at Object.compileFunction (node:vm:352:18)

Won't compile after importing external node libraries

Step to reproduce:

  • Clone frida-agent-example and delete the lock file
  • Run npm install @types/lodash lodash
  • Import and use lodash in index.ts
  • Run npm run build

Error:

> [email protected] build
> frida-compile agent/index.ts -o _agent.js -c

TypeError: node.expression.getText is not a function
    at visitCallExpression (file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/cjstoesm.js:1577:25)
    at visitNode (file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/cjstoesm.js:2633:16)
    at file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/cjstoesm.js:2894:33
    at visitNode (file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/typescript.js:85139:21)
    at visitEachChildOfParenthesizedExpression (file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/typescript.js:85817:32)
    at Object.visitEachChild (file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/typescript.js:85389:35)
    at Object.childContinuation (file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/cjstoesm.js:2893:47)
    at visitNode (file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/cjstoesm.js:2635:20)
    at file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/cjstoesm.js:2894:33
    at visitNode (file:///home/user/Documents/src/frida-agent-test/node_modules/frida-compile/ext/typescript.js:85139:21)

how it's work ?!

I think this project can compile a JavaScript file in a way that doesn't require Frida gadget or any other dependencies to run, and the JavaScript code can be executed on its own. But how does it work? I didn't understand the meaning of the agent. What exactly should I provide?
I might have misunderstood correctly. I am interested in putting a JS file that contains instructions for an APK file inside the APK file in a way that I don't need to be connected to a computer to execute Frida and have it executed and loaded by the application itself. Does this project do the same thing?

Folders with spaces don't work

At least in Windows environments, folders with spaces produce errors.

8:08:22 p.m. - Starting compilation in watch mode...

error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'CallableFunction'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'NewableFunction'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
error TS6053: File 'C:/Users/Falcon/Desktop/new%20n/node_modules/frida-compile/ext/lib.es2020.d.ts' not found.
  The file is in the program because:
    Library 'lib.es2020.d.ts' specified in compilerOptions

8:08:23 p.m. - Found 9 errors. Watching for file changes.

Removing the error compiles correctly.

Duplicate identifier `File` in frida-gum

When compiling a simple script I get:

  message:
   '/home/test/node_modules/@types/frida-gum/index.d.ts(2200,15): Error TS2300: Duplicate identifier \'File\'.',
  fileName:
  '/home/test/node_modules/@types/frida-gum/index.d.ts',

Adding "skipLibCheck": true to the tsconfig.json fixes (apparently) the problem, not sure its the right way though.

I used the same package.json deps as in the agent example:

    "@types/frida-gum": "^16.3.0",
    "@types/node": "^14.14.22",
    "frida-compile": "^10.0.0"

"Require is not defined"

Hi,

I'm trying to use frida-compile, when compiling binaries and then executing them with frida i'm getting the error require is not defined
It seems like require() functions are not removed from the compiled sources ?

Reproduction

main.js

const a = require("./lib")
console.log(a())

lib.js

export default {
    a : function(){
        return 1;
    }
}

execution :

➜  test-frida-compile $ frida-compile test.js -o test-compiled.js
➜  test-frida-compile $ frida -l test-compiled.js -f /bin/ls 
     ____
    / _  |   Frida 16.0.2 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at https://frida.re/docs/home/
   . . . .
   . . . .   Connected to Local System (id=local)
Spawned `/bin/ls`. Resuming main thread!                                
ReferenceError: 'require' is not defined
    at <anonymous> (test.js:1)

Versions

node : v16.17.1
frida-compile : v16.1.3
frida : 16.0.2

How to make script's variables available in Frida command-line?

When I use regular (non-compiled) script in Frida like frida -H ... ... -l myscript.js, I can then access the global variables which were declared in the script from the Frida's command line.
But variables in the compiled script stay in the inner scope and cannot be accessed from command line.
How do I "export" them from compiled script?
For now the only way I could find is to manually edit compiled script which is definitely not nice.
Sorry if it is a noob question.

ReferenceError: window is not defined

Using frida 12.8.15 and latest frida-compile, im getting the error ReferenceError: window is not defined after running frida-compile and executing script with frida

Parse error with "let"

Hello,

I have a problem with the ES6 let Keyword. It always results in a parse error.

At first I have tried to "compile" this sample:
https://frida.re/news/2016/10/25/frida-8-1-released/

At least I also have trouble with this litte code snippet:
let a = 42; console.log("Hello World", a);

frida-compile does not transpile the let keyword for me.

After the script startup with Frida it results in: Failed to load script: script(line 46): SyntaxError: parse error

I am relatively new to frida and would be very thankful for any hint.

Version: 10.1.0

npm install frida-compile fails to install (dependency of itself)

I get this error when I run npm install frida-compile:

npm ERR! Linux 4.13.0-37-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "frida-compile"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code ENOSELF

npm ERR! Refusing to install frida-compile as a dependency of itself
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /home/axelle/softs/frida-compile/npm-debug.log

npm-debug.log mentions:

verbose stack Error: Refusing to install frida-compile as a dependency of itself
42 verbose stack     at checkSelf (/usr/share/npm/lib/install/validate-args.js:40:14)
42 verbose stack     at Array.<anonymous> (/usr/share/npm/node_modules/slide/lib/bind-actor.js:15:8)
42 verbose stack     at LOOP (/usr/share/npm/node_modules/slide/lib/chain.js:15:14)
42 verbose stack     at chain (/usr/share/npm/node_modules/slide/lib/chain.js:20:5)
42 verbose stack     at /usr/share/npm/lib/install/validate-args.js:15:5
42 verbose stack     at /usr/share/npm/node_modules/slide/lib/async-map.js:52:35
42 verbose stack     at Array.forEach (native)
42 verbose stack     at /usr/share/npm/node_modules/slide/lib/async-map.js:52:11
42 verbose stack     at Array.forEach (native)
42 verbose stack     at asyncMap (/usr/share/npm/node_modules/slide/lib/async-map.js:51:8)

Unable to resolve local module on 16.1.10

Host Windows 10
Target iOS

index.ts

import { blabla } from "./utils";

blabla();

utils.ts

export function blabla() {
    console.log('Hi');
}

Error

Error: unable to resolve: E:/Aeon/agent/utils
    at Object.bundle (file:///E:/Aeon/node_modules/frida-compile/dist/compiler.js:324:23)
    at Module.build (file:///E:/Aeon/node_modules/frida-compile/dist/compiler.js:47:20)
    at main (file:///E:/Aeon/node_modules/frida-compile/dist/cli.js:37:33)
    at file:///E:/Aeon/node_modules/frida-compile/dist/cli.js:57:5
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

TypeScript error

Good day.
If I use frida-compile I've a TypeScript error.
May you please explain what the reason of this behaviour?

Unable to run command on MacBook

Hi,
I have installed the Frida-compile instructed on readme page but while running the command I am getting following error.

exrme:frida-uikit manish$ frida-compile
-bash: frida-compile: command not found

Thanks

prebuild-install http 404 https://github.com/frida/frida/releases/download/10.6.13/frida-v10.6.13-node-v59-darwin-x64.tar.gz

devzkndeMacBook-Pro:passionfruit devzkn$ sudo npm install frida-compile
Password:
Sorry, try again.
Password:

> [email protected] install /Users/devzkn/code/demo/passionfruit/node_modules/frida
> prebuild-install || node-gyp rebuild

prebuild-install info begin Prebuild-install version 2.3.0
prebuild-install info looking for local prebuild @ prebuilds/frida-v10.6.13-node-v59-darwin-x64.tar.gz
prebuild-install info looking for cached prebuild @ /Users/devzkn/.npm/_prebuilds/https-github.com-frida-frida-releases-download-10.6.13-frida-v10.6.13-node-v59-darwin-x64.tar.gz
prebuild-install http request GET https://github.com/frida/frida/releases/download/10.6.13/frida-v10.6.13-node-v59-darwin-x64.tar.gz
prebuild-install http 404 https://github.com/frida/frida/releases/download/10.6.13/frida-v10.6.13-node-v59-darwin-x64.tar.gz
prebuild-install WARN install No prebuilt binaries found (target=9.3.0 runtime=node arch=x64 platform=darwin)
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/devzkn/code/demo/passionfruit/node_modules/frida/build'
gyp ERR! System Darwin 17.2.0
gyp ERR! command "/usr/local/Cellar/node/9.3.0_1/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/devzkn/code/demo/passionfruit/node_modules/frida
gyp ERR! node -v v9.3.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm WARN [email protected] requires a peer of browserify@>= 10.x but none is installed. You must install peer dependencies yourself.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/devzkn/.npm/_logs/2017-12-22T07_41_33_777Z-debug.log

frida-compile installation error

can't install frida-compile using npm install firda-compile command.
tried windows , mac and kali linux . all of them showing the same error.

PS C:\WINDOWS\system32> npm install frida-compile
npm WARN saveError ENOENT: no such file or directory, open 'C:\WINDOWS\system32\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\WINDOWS\system32\package.json'
npm WARN system32 No description
npm WARN system32 No repository field.
npm WARN system32 No README data
npm WARN system32 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ [email protected]
updated 1 package and audited 609 packages in 4.414s

8 packages are looking for funding
  run `npm fund` for details

found 1040 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
PS C:\WINDOWS\system32>

WeakRef collides with esnext proposal

  "devDependencies": {
    "@types/frida-gum": "^15.3.0",
    "@types/node": "^13.7.0",
    "frida-compile": "^10.0.0"
  }

I noticed that there was a new feature in esnext called WeakRef, while frida has a feature that has the same name.

https://github.com/microsoft/TypeScript/blob/bd1d8e5/src/lib/esnext.weakref.d.ts

It makes TypeScript uncompilable.

TypeScript error: H:/Grapefruit/agent/node_modules/@types/frida-gum/index.d.ts(4669,19): Error TS2300: Duplicate identifier 'WeakRef'.

"TypeError: fileSystemEntryExists is not a function" when using --watch

Hi, thanks for working on frida and its fantastic tooling. I encounter a weird error when using frida-compile with the --watch flag.

Reproduction

Here is a minimum example which generates the error. I ran these commands in a Powershell terminal.

# create a fresh npm project frida-compile-issue
mkdir frida-compile-issue
cd frida-compile-issue
npm init --yes
# install frida-compile
npm install [email protected]
# create an empty agent.ts file
# the file's contents are irrelevant to the issue
New-Item agent.ts
# Posix version of the above command:
#touch agent.ts
# execute frida-compile without the --watch flag and check that it works correctly
npx frida-compile agent.ts --output agent.js
cat agent.js
# up to this point everything worked fine
# execute frida-compile with the --watch flag
npx frida-compile agent.ts --output agent.js --watch 
# the error is encountered

Stack Trace

Here is the output of the frida-compile command executed with the --watch flag as above.

10:43:36 - Starting compilation in watch mode...

file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:6735
            let watcher = !fileSystemEntryExists(fileOrDirectory, entryKind) ?
                           ^

TypeError: fileSystemEntryExists is not a function
    at fsWatch (file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:6735:28)
    at Object.watchDirectory (file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:6670:24)
    at watchDirectory (file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:116412:75)
    at file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:116435:30
    at Object.compilerHost.watchTypeRootsDirectory (file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:124354:68)
    at createTypeRootsWatch (file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:122753:35)
    at file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:19647:30
    at Map.forEach (<anonymous>)
    at Object.mutateMap (file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:19644:16)
    at Object.updateTypeRootsWatch (file:///C:/Users/IT-PC-HTY4CK3/Documents/Projects/Tools/frida-compile-issue/node_modules/frida-compile/ext/typescript.js:122788:20)

System information

Software Version
OS Windows 11
node v16.15.1
npm 8.11.0
frida-compile 16.1.0

ParseError: 'import' and 'export' may appear only with 'sourceType: module

Hi!

With last versions of frida-compile I obtain again the exception "ParseError: 'import' and 'export' may appear only with 'sourceType: module'" that was fixed in #13.

By looking at the code in the repository it seems that the fix code in the pull request #13. is not present. Am I wrong?

Thank you a lot for your support and for your great job!

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

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" } }

Error compiling on MacOS v11.5.1

Trying to compile Frida-compile via:

npm install [email protected]
and
make gum-macos NODE=/usr/local/bin/node (From Frida source)

npm ERR! code ETARGET
npm ERR! notarget No matching version found for frida-compile@^10.2.4.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

Logfile output:
49 verbose cwd /Users/user/apps/frida/frida-gum/bindings/gumjs
50 verbose Darwin 20.6.0
51 verbose argv "/usr/local/Cellar/node/16.6.0/bin/node" "/usr/local/bin/npm" "install"
52 verbose node v16.6.0
53 verbose npm v7.19.1
54 error code ETARGET
55 error notarget No matching version found for frida-compile@^10.2.4.
56 error notarget In most cases you or one of your dependencies are requesting
56 error notarget a package version that doesn't exist.

unable to use import statement

hello, i ran into a problem when i wanted to refactor my code, the fact is that when i add the import "./utils.ts" (or any other file) to the index.ts (main file) i get a compilation error

frida -Uf com.android.support -l index.ts --runtime v8 --keepalive-interval 30
     ____
    / _  |   Frida 16.0.17 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at https://frida.re/docs/home/
   . . . .
   . . . .   Connected to Redmi Note 9 (id=)
Compiling index.ts...
Failed to bundle: ReferenceError: process is not defined

after that, the REPL dies, no messages are displayed like Process teminated or Device lost in other words, the console freezes

pc: windows 10 x64
using lastest frida-server (16.0.17) on android 13 with magisk 26.1

Windows: TypeError: Cannot read properties of undefined (reading 'options')

PS D:\progs\apk\tools\tiktok> npm install --location=global frida-compile
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.

changed 76 packages, and audited 77 packages in 6s

12 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
PS D:\progs\apk\tools\tiktok> frida-compile -o o.js server.js
TypeError: Cannot read properties of undefined (reading 'options')
    at makeCompilerOptions (file:///C:/Users/jem/AppData/Roaming/npm/node_modules/frida-compile/dist/compiler.js:102:130)
    at Module.build (file:///C:/Users/jem/AppData/Roaming/npm/node_modules/frida-compile/dist/compiler.js:18:26)
    at main (file:///C:/Users/jem/AppData/Roaming/npm/node_modules/frida-compile/dist/cli.js:24:24)
    at file:///C:/Users/jem/AppData/Roaming/npm/node_modules/frida-compile/dist/cli.js:27:1
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Windows 10
What could be the problem?

Error in frida-agent-example when update to new version.

Step to produce:

  1. clone frida-agent-example
  2. yarn add frida-compile
  3. yarn run build

Now error shows:
yarn run v1.22.15

$ frida-compile agent/index.ts -o _agent.js -c
Error: unable to resolve: F:\frida-agent-example\agent\logger
    at Object.bundle (file:///F:/frida-agent-example/node_modules/frida-compile/dist/compiler.js:311:23)
    at Module.build (file:///F:/frida-agent-example/node_modules/frida-compile/dist/compiler.js:46:26)
    at main (file:///F:/frida-agent-example/node_modules/frida-compile/dist/cli.js:37:39)
    at file:///F:/frida-agent-example/node_modules/frida-compile/dist/cli.js:56:1
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Error during frida-compile.

CMD : frida-compile script.js -o run.js
Error: Unable to detect shim directory; please file a bug
at Module.queryDefaultAssets (file:///C:/Users/user1/AppData/Roaming/npm/node_modules/frida-compile/dist/compiler.js:161:19)
at main (file:///C:/Users/user1/AppData/Roaming/npm/node_modules/frida-compile/dist/cli.js:23:29)
at file:///C:/Users/user1/AppData/Roaming/npm/node_modules/frida-compile/dist/cli.js:57:5
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Compiler went crazy.

Hi,

Compiler is not working for me. Compiled file is starting like this:

 📦
5629 /arf.js.map
4253 /arf.js
✄
{"version":3,"file":"arf.js","sourceRoot":"C:/Users/gktgo/Desktop/","sources":["arf.js"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAClC,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;AAEzC,MAAM,GAAG,GAAG,OAAO,EAAE,CAAA;AACrB,IAAI,EAAE,CAAC;AACP,IAAI,SAAS,CAAC;AACd,IAAI,UAAU,CAAC;AACf,IAAI,GAAG,CAAC;AACR,IAAI,IAAI,CAAC;AACT,IAAI,UAAU,CAAC;AACf,IAAI,GAAG,CAAC;AAER,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC;IAC1B,QAAQ,EAAE,KAAK;CAClB,CAAC,CAAC,CAAC;AAEJ,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAA;AAE1B,IAAI,CAAC,OAAO,CAAC;IACT,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAC5C,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC1C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,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;QAC1C,GAAG,CAAC,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;QAChC,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;QAC3B,GAAG,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;QACjC,MAAM,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7B,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC3C,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC7C,IAAG;YACC,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;YACzC,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;SAC5C;QACD,OAAM,CAAC,EAAC;YACJ,KAAK,GAAG,EAAE,CAAC;YACX,KAAK,GAAG,EAAE,CAAC;SACd;IACL,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QACjB,UAAU,EAAE,MAAM;QAClB,WAAW,EAAE,OAAO;QACpB,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;KACnB,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AACH,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA"}
✄

Duplicate identifier 'gc' when using with @types/node >= 16

Reproducible after updating all packages used in frida-agent-example to the latest available, delete the lock file and run npm install.

package.json after update:

{
  "name": "frida-agent-example",
  "version": "1.0.0",
  "description": "Example Frida agent written in TypeScript",
  "private": true,
  "main": "agent/index.ts",
  "scripts": {
    "prepare": "npm run build",
    "build": "frida-compile agent/index.ts -o _agent.js -c",
    "watch": "frida-compile agent/index.ts -o _agent.js -w"
  },
  "devDependencies": {
    "@types/frida-gum": "^16.5.0",
    "@types/node": "^16.0.1",
    "frida-compile": "^10.2.4"
  }
}

`session.create_script(path)` fails when importing from node_modules

I'm using typescript for a frida module that's being loaded on Android.

Reproduction steps:
git clone https://github.com/oleavr/frida-agent-example.git
cd frida-agent-example
npm install
npm run build

Create this python file:

import frida
import pathlib
process_name: str = "My android app"
def main():
    device: frida.core.Device = frida.get_usb_device()
    sess: frida.core.Session
    sess = device.attach(process_name)
    script_path: pathlib.Path = pathlib.Path("_agent.js")
    assert script_path.exists()
    script: frida.core.Script = sess.create_script(script_path.read_text())
    script.load()
if __name__ == "__main__":
    main()

That all works, but when I add a package:
npm install --save rxjs
Then import that package in index.ts:

import {Observable} from "rxjs";
let observable = new Observable();

Then build again npm run build
The build step completes, but when I try to load the script through python I'm getting this error:

Traceback (most recent call last):
  File "/home/myles/frida-agent-example/frida-gadget-main.py", line 13, in <module>
    main()
  File "/home/myles/frida-agent-example/frida-gadget-main.py", line 10, in main
    script: frida.core.Script = sess.create_script(script_path.read_text())
  File "/home/myles/frida-agent-example/venv/lib/python3.10/site-packages/frida/core.py", line 86, in wrapper
    return f(*args, **kwargs)
  File "/home/myles/frida-agent-example/venv/lib/python3.10/site-packages/frida/core.py", line 628, in create_script
    return Script(self._impl.create_script(source, **kwargs))  # type: ignore
frida.InvalidArgumentError: could not load module '/node_modules/rxjs/dist/esm5/internal/Observable'

Any ideas on what I'm doing wrong here? How can I get it to pick up imports from node_modules?

Import class error

Case 1

In AClass.js

export default class AClass {
    // xxxxx
}

In b.js

import AClass from './AClass';

Then error occurred

Compilation failed: 
/Users/xiaozhuai/work/GLEavesdropper/node_modules/@babel/runtime-corejs2/helpers/esm/classCallCheck.js:1
export default function _classCallCheck(instance, Constructor) {
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

Case 2

In fff.js

export default function fff({ args }, data) {
    let [a, b] = args;
    return a;
}

In c.js

import AClass from './fff';

Then error occurred

Compilation failed: 
/Users/xiaozhuai/work/GLEavesdropper/node_modules/@babel/runtime-corejs2/helpers/esm/slicedToArray.js:1
import arrayWithHoles from "./arrayWithHoles";
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

Finally, I make this change, and it works, any ideas?

        // ignore: [/[\/\\]node_modules[\/\\](@babel|core-js|core-js-pure|lodash)([\/\\]|$)/],
        ignore: [/[\/\\]node_modules[\/\\](core-js|core-js-pure|lodash)([\/\\]|$)/],

breaks in wrong workdir: Error: Cannot find module @frida/uglifyify from build/bindings/gumjs

i get this error in frida-gum when node_modules is not in frida-gum/build/bindings/gumjs/node_modules

[120/214] Generating bindings/gumjs/gumjs-runtime with a custom command
FAILED: bindings/gumjs/gumcmodule-runtime.h bindings/gumjs/gumquickscript-runtime.h bindings/gumjs/gumquickscript-objc.h bindings/gumjs/gumquickscript-java.
h bindings/gumjs/gumv8script-runtime.h bindings/gumjs/gumv8script-objc.h bindings/gumjs/gumv8script-java.h 
/build/source/bindings/gumjs/generate-runtime.py qjs,v8 x86_64 little /build/source/bindings/gumjs /build/source/gum /nix/store/aw5yynzqi8cg4h733qjch53zcm4n
kshr-capstone-5.0-rc2/include/capstone/capstone /nix/store/rz0irj616wmqiqwwmf0zvf86ck9qn144-frida-tinycc-unstable-2022-04-01/lib/tcc/include /build/source/b
uild/bindings/gumjs/quickcompile /build/source/build/bindings/gumjs
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: Cannot find module '@frida/uglifyify' from '/build/source/build/bindings/gumjs'
    at /nix/store/fap27a1nkgx2xxyh5h3hq333zyim0jcm-node-dependencies-frida-gum-0.0.0/lib/node_modules/resolve/lib/async.js:146:35
    at processDirs (/nix/store/fap27a1nkgx2xxyh5h3hq333zyim0jcm-node-dependencies-frida-gum-0.0.0/lib/node_modules/resolve/lib/async.js:299:39)
    at isdir (/nix/store/fap27a1nkgx2xxyh5h3hq333zyim0jcm-node-dependencies-frida-gum-0.0.0/lib/node_modules/resolve/lib/async.js:306:32)
    at /nix/store/fap27a1nkgx2xxyh5h3hq333zyim0jcm-node-dependencies-frida-gum-0.0.0/lib/node_modules/resolve/lib/async.js:34:69
    at FSReqCallback.oncomplete (node:fs:207:21)
Emitted 'error' event on Browserify instance at:
    at /nix/store/fap27a1nkgx2xxyh5h3hq333zyim0jcm-node-dependencies-frida-gum-0.0.0/lib/node_modules/browserify/index.js:375:34
    at /nix/store/fap27a1nkgx2xxyh5h3hq333zyim0jcm-node-dependencies-frida-gum-0.0.0/lib/node_modules/resolve/lib/async.js:148:17
    at processDirs (/nix/store/fap27a1nkgx2xxyh5h3hq333zyim0jcm-node-dependencies-frida-gum-0.0.0/lib/node_modules/resolve/lib/async.js:299:39)
    [... lines matching original stack trace ...]
    at FSReqCallback.oncomplete (node:fs:207:21) {
  code: 'MODULE_NOT_FOUND'
}

Node.js v18.13.0
Command '[PosixPath('/nix/store/fap27a1nkgx2xxyh5h3hq333zyim0jcm-node-dependencies-frida-gum-0.0.0/lib/node_modules/.bin/frida-compile'), PosixPath('runtime/entrypoint-quickjs.js'), '-o', PosixPath('runtime-build-quick/frida.js'), '-c']' returned non-zero exit status 1.

for example, when i install frida-compile to a different prefix and patch frida_compile to some absolute path

    frida_compile = output_dir / "node_modules" / ".bin" / make_script_filename("frida-compile")

which is called with cwd=output_dir

        subprocess.run([frida_compile, runtime_reldir / "entrypoint-quickjs.js", "-o", runtime] + quick_options, cwd=output_dir, check=True)

ideally frida-compile should be workdir-independent = should work when installed globally

version: frida-compile 10.2.5

Is there any support for evaling compiled scripts?

Frida-compile gives packaged scripts that don't seem to play well with eval. I see Frida provides Script.load and Script.execute but they don't seem to handle this container format either.

I'm testing with

import { readFileOnDevice } from '../lib/Utilities.js';

const Log = Java.use("android.util.Log");
const script = readFileOnDevice('run.js');

try {
	Log.v("game", "running");
	Script.evaluate("beatstar", script);
}
catch(e) {
	Log.v("game", e);
}

Where run.js is

const Log = Java.use("android.util.Log");
Log.v("game", "I ran");

When compiled, no output is produced and the catch statement isn't executed either.

When not compiled and left as raw code it prints out "I ran" as expected.

Is this at all supported in some way?

"unable to resolve: {path}" when importing a module from upper directory

Hello.

Importing a module from upper directory (depth of the upper directory doesn't matter) causes "unable to resolve" error.
Example: import * as test from '../test.js'

How to reproduce

mkdir frida_compile_test
mkdir frida_compile_test/subdir
echo "" > frida_compile_test/test.js
echo "import * as test from '../test.js'" > frida_compile_test/subdir/test2.js
frida-compile frida_compile_test/subdir/test2.js -o bundle.js

On my machine outputs:
unable to resolve: $(pwd)/frida_compile_test/test.js

The first "null" in the code will be gone when options.sourcemap is not set

This is an interesting bug. The first occurred null will be missing when it compiles.

Source:

const free = new NativeFunction(Module.findExportByName(null, 'free'), 'void', ['pointer'])

Result:

var free = new NativeFunction(Module.findExportByName(, 'free'), 'void', ['pointer']);
//                                                    ^^^ it's gone

Just couldn't figure out which code generator caused the bug.

Related issue: chaitin/passionfruit#17

Temporary workaround: use undefined instead.

16.1.0 require is not defined

It looks like the frida-compiler v16.1.0 has a shim for the http module. Which tells me that I should be able to use the http module. However, as seen below it does not work.

Host Windows 10
Target iOS

Code

import * as http from 'http';

const host = '0.0.0.0';
const port = 8000;

const requestListener = function (req: any, res: any) {
    res.writeHead(200);
    res.end("My first server!");
};

const server = http.createServer(requestListener);

server.listen(port, host, () => {
    console.log(`Server is running on http://${host}:${port}`);
});

Dependencies

"devDependencies": {
  "@types/frida-gum": "^18.1.0",
  "@types/node": "^18.7.18",
  "frida-compile": "^16.1.0"
}

Error

ReferenceError: require is not defined
    at lookupAndListen (/node_modules/@frida/net/index.js:1146:3)
    at Server.listen (/node_modules/@frida/net/index.js:1127:9)
    at agent/index.ts:33:8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.