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

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' #1

Open
AregGhazaryan opened this issue Dec 23, 2021 · 0 comments

Comments

@AregGhazaryan
Copy link

I am getting an error when compiling using frida-compile

agent.js looks like this

const ExNativeFunction = require('frida-ex-nativefunction');

const openAddr = Module.findExportByName('libc.so', 'open');
const open = new ExNativeFunction(openAddr, 'int', ['pointer', 'int']);

console.log(open.address); // The provided openAddr
console.log(open.retType); // The provided return type
console.log(open.argTypes); // The provided argument types
console.log(open.abi); // The provided abi

// Shorthand for Interceptor.attach
const listener = open.intercept({
  onEnter: function (arg) {
    console.log(args);
  },
  onLeave: function () {},
});
listener.detach(); // You can use it like usual

// Shorthand for Interceptor.replace
open.replace((pathPtr, flags) => {
  return open(pathPtr, flags);
});

Now when i run frida-compile agent.js -o _agent.js, it throws an error regarding the imports

SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (27:0) while parsing C:\Users\Areg\Downloads\New folder (4)\node_modules\frida-ex-nativefunction\index.js while parsing file: C:\Users\Areg\Downloads\New folder (4)\node_modules\frida-ex-nativefunction\index.js
    at DestroyableTransform.end [as _flush] (C:\Users\Areg\AppData\Roaming\npm\node_modules\frida-compile\node_modules\insert-module-globals\index.js:114:21)
    at DestroyableTransform.prefinish (C:\Users\Areg\AppData\Roaming\npm\node_modules\frida-compile\node_modules\readable-stream\lib\_stream_transform.js:138:10)
    at DestroyableTransform.emit (events.js:315:20)
    at prefinish (C:\Users\Areg\AppData\Roaming\npm\node_modules\frida-compile\node_modules\readable-stream\lib\_stream_writable.js:619:14)
    at finishMaybe (C:\Users\Areg\AppData\Roaming\npm\node_modules\frida-compile\node_modules\readable-stream\lib\_stream_writable.js:627:5)
    at endWritable (C:\Users\Areg\AppData\Roaming\npm\node_modules\frida-compile\node_modules\readable-stream\lib\_stream_writable.js:638:3)
    at DestroyableTransform.Writable.end (C:\Users\Areg\AppData\Roaming\npm\node_modules\frida-compile\node_modules\readable-stream\lib\_stream_writable.js:594:41)
    at DestroyableTransform.onend (C:\Users\Areg\AppData\Roaming\npm\node_modules\frida-compile\node_modules\readable-stream\lib\_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:421:28)
    at DestroyableTransform.emit (events.js:327:22) {
  type: 'syntax',
  filename: 'C:\\Users\\Areg\\Downloads\\New folder (4)\\node_modules\\frida-ex-nativefunction\\index.js',
  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],
      error: [Function (anonymous)],
      data: [Function: ondata],
      _mutate: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    _writableState: WritableState {
      objectMode: true,
      highWaterMark: 16,
      finalCalled: false,
      needDrain: false,
      ending: true,
      ended: true,
      finished: true,
      destroyed: false,
      decodeStrings: true,
      defaultEncoding: 'utf8',
      length: 0,
      writing: false,
      corked: 0,
      sync: false,
      bufferProcessing: false,
      onwrite: [Function (anonymous)],
      writecb: null,
      writelen: 0,
      bufferedRequest: null,
      lastBufferedRequest: null,
      pendingcb: 0,
      prefinished: true,
      errorEmitted: false,
      bufferedRequestCount: 0,
      corkedRequestsFree: [CorkedRequest]
    },
    writable: false,
    allowHalfOpen: true,
    _options: { objectMode: true },
    _wrapOptions: { objectMode: true },
    _streams: [ [Deps], [Transform] ],
    length: 2,
    label: 'deps',
    [Symbol(kCapture)]: false
  },
  inputs: Set(21) {
    'C:\\Users\\Areg\\Downloads\\New folder (4)\\agent.js',
    'C:/Users/Areg/Downloads/New folder (4)/agent.js',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es6.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es5.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.core.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.collection.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.iterable.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.symbol.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.generator.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.promise.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.proxy.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.reflect.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.dom.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.dom.iterable.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.webworker.importscripts.d.ts',
    'C:/Users/Areg/AppData/Roaming/npm/node_modules/frida-compile/node_modules/typescript/lib/lib.scripthost.d.ts',
    'C:\\Users\\Areg\\Downloads\\New folder (4)\\package.json',
    'C:\\Users\\Areg\\Downloads\\New folder (4)\\node_modules\\frida-ex-nativefunction\\package.json',
    'C:\\Users\\Areg\\Downloads\\New folder (4)\\node_modules\\frida-ex-nativefunction\\index.js'
  }
}
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

1 participant