@reversense/dexcalibur-frida-compile
v10.2.6
Published
Compile a Frida script comprised of one or more Node.js modules
Readme
@dexcalibur/dexcalibur-frida-compile
A compiler for Frida scripts comprised of one or more Node.js modules, supporting JavaScript, TypeScript, and Cylang.
Overview
This tool compiles Node.js modules into Frida-compatible scripts using Browserify and tsify. It bundles your code along with dependencies, handles TypeScript compilation, and provides optional features like compression, bytecode compilation, and watch mode for development.
Installation
npm install @dexcalibur/dexcalibur-frida-compileRequirements
- Node.js >= 10.12.0
Usage
Command Line
frida-compile [options] <module>Options
-o, --output <file>- Set output file (required)-w, --watch- Watch for changes and recompile automatically-b, --bytecode- Output bytecode (requiresfridapackage)-S, --no-sourcemap- Omit sourcemap-c, --compress- Compress using UglifyJS2-a, --use-absolute-paths- Use absolute source paths-t, --tsconfig <file>- Path to tsconfig file for TypeScript compilation-s, --standalone <name>- Export agent contents under external module name
Examples
Basic compilation:
frida-compile index.js -o agent.jsTypeScript with watch mode:
frida-compile agent.ts -o _agent.js -wCompressed bytecode output:
frida-compile index.js -o agent.js -c -bWith custom TypeScript config:
frida-compile agent.ts -o _agent.js -t tsconfig.jsonProgrammatic API
const compiler = require('@dexcalibur/dexcalibur-frida-compile');Build Once
await compiler.build(inputPath, outputPath, options);Parameters:
inputPath(string) - Path to entry moduleoutputPath(string) - Path for output fileoptions(object) - Compilation optionscwd(string) - Base directorysourcemap(boolean) - Include sourcemap (default: true)compress(boolean) - Compress outputbytecode(boolean) - Compile to bytecodetsconfig(string) - Path to tsconfig.jsonstandalone(string) - Standalone module name
Example:
const compiler = require('@dexcalibur/dexcalibur-frida-compile');
await compiler.build('./agent.js', './_agent.js', {
compress: true,
sourcemap: true
});Watch Mode
const watcher = compiler.watch(inputPath, outputPath, options);Returns an EventEmitter with the following events:
compile- Emitted on successful compilationwatcher.on('compile', ({ files, duration }) => { console.log(`Compiled ${files.length} files in ${duration}ms`); });error- Emitted on compilation errorwatcher.on('error', (error) => { console.error('Compilation failed:', error); });
Example:
const compiler = require('@dexcalibur/dexcalibur-frida-compile');
const watcher = compiler.watch('./agent.ts', './_agent.js', {
sourcemap: true
});
watcher.on('compile', ({ files, duration }) => {
console.log(` Compiled ${files.length} files in ${duration}ms`);
});
watcher.on('error', (error) => {
console.error(' Compilation failed:', error.message);
});Features
Supported File Types
- JavaScript (
.js) - Standard ES modules - TypeScript (
.ts) - Automatically transpiled - JSON (
.json) - Imported as modules - Cylang (
.cy) - Requirescylangpackage
Frida-Compatible Builtins
The following Node.js modules are replaced with Frida-compatible implementations:
process�frida-processbuffer�frida-bufferfs�frida-fshttp�frida-httpnet�frida-netany-promise�frida-any-promisebignum�bignumber.js
Bytecode Compilation
To compile to bytecode, you need to install the frida package:
npm install fridaThen use the -b or --bytecode flag:
frida-compile agent.js -o agent.js -bTypeScript Support
TypeScript files are automatically detected and compiled. You can provide a custom tsconfig.json:
frida-compile agent.ts -o _agent.js -t ./tsconfig.jsonCompression
Code compression using UglifyJS2 can be enabled with the -c flag:
frida-compile agent.js -o agent.js -cDevelopment
# Lint code
npm run pretestRelated Projects
- Frida - Dynamic instrumentation toolkit
- Browserify - Module bundler
- tsify - TypeScript plugin for Browserify
