nowsecure / r2frida

Radare2 and Frida better together.
MIT License
1.18k stars 121 forks source link

build error #178

Closed s0i37 closed 5 years ago

s0i37 commented 5 years ago

I've tried install through r2pm and git:

> r2frida-agent@3.7.0 build /root/src/r2frida
> frida-compile src/agent -o src/_agent.js

 frida-compile src/agent -o src/_agent.js
{ [TypeScript error: ../../node_modules/@types/node/index.d.ts(6208,55): Error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.]
  message: '../../node_modules/@types/node/index.d.ts(6208,55): Error TS2583: Cannot find name \'Map\'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.',
  fileName: '../../node_modules/@types/node/index.d.ts',
  line: 6208,
  column: 55,
  name: 'TypeScript error',
  inputs: 
   Set {
     '/root/src/r2frida/src/agent/index.js',
     '/root/node_modules/@types/node/index.d.ts',
     '/root/node_modules/@types/node/inspector.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.es5.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.dom.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.webworker.importscripts.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.scripthost.d.ts' } }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! r2frida-agent@3.7.0 build: `frida-compile src/agent -o src/_agent.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the r2frida-agent@3.7.0 build 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!     /root/.npm/_logs/2019-08-02T16_14_26_977Z-debug.log

/root/.npm/_logs/2019-08-02T16_14_26_977Z-debug.log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/n/versions/node/9.6.1/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using npm@5.6.0
3 info using node@v9.6.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle r2frida-agent@3.7.0~prebuild: r2frida-agent@3.7.0
6 info lifecycle r2frida-agent@3.7.0~build: r2frida-agent@3.7.0
7 verbose lifecycle r2frida-agent@3.7.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle r2frida-agent@3.7.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/root/src/r2frida/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/rvm/bin:/opt/radare2/bin:/root/.go/bin:/usr/local/rvm/bin
9 verbose lifecycle r2frida-agent@3.7.0~build: CWD: /root/src/r2frida
10 silly lifecycle r2frida-agent@3.7.0~build: Args: [ '-c', 'frida-compile src/agent -o src/_agent.js' ]
11 silly lifecycle r2frida-agent@3.7.0~build: Returned: code: 1  signal: null
12 info lifecycle r2frida-agent@3.7.0~build: Failed to exec build script
13 verbose stack Error: r2frida-agent@3.7.0 build: `frida-compile src/agent -o src/_agent.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
13 verbose stack     at EventEmitter.emit (events.js:127:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:127:13)
13 verbose stack     at maybeClose (internal/child_process.js:933:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
14 verbose pkgid r2frida-agent@3.7.0
15 verbose cwd /root/src/r2frida
16 verbose Linux 4.18.10-rt5
17 verbose argv "/usr/local/n/versions/node/9.6.1/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v9.6.1
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error r2frida-agent@3.7.0 build: `frida-compile src/agent -o src/_agent.js`
22 error Exit status 1
23 error Failed at the r2frida-agent@3.7.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
trufae commented 5 years ago

Builds fine here, we don't use typescript, so i don't get the error and i cant repro

trufae commented 5 years ago

Please try again with r2pm -ci r2frida

s0i37 commented 5 years ago

Unfortunately I've same error.

s0i37 commented 5 years ago

After running make I have node_modules/typescript/

enovella commented 5 years ago

Wait a minute, which OS are you working on? Did you install the dependencies as explained in the README.md?

s0i37 commented 5 years ago

Debian x64 I have all these packages: make gcc libzip-dev nodejs npm curl pkg-config git

enovella commented 5 years ago

Yeah, the issue could be related to TypeScript.

I got an older Node version:

>  nodejs --version
v8.10.0

On Ubuntu 18.04.2, r2pm works fine:

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@2.0.7
npm run build

> r2frida-agent@3.7.0 build /home/edu/.local/share/radare2/r2pm/git/r2frida
> frida-compile src/agent -o src/_agent.js

xxd -i < src/_agent.js > src/_agent.h
cc -c -fPIC -g -I/usr/include/libr -DWITH_CYLANG=0 -Iext/frida src/io_frida.c -o src/io_frida.o
In file included from src/io_frida.c:15:0:
src/io_frida.c: In function ‘r_io_frida_free’:
ext/frida/frida-core.h:11803:18: warning: passing argument 1 of ‘_frida_g_object_unref’ discards ‘volatile’ qualifier from pointer target type [-Wdiscarded-qualifiers]
       (destroy) (_ptr);                                                        \
                  ^
ext/frida/frida-core.h:28217:36: note: in expansion of macro ‘g_clear_pointer’
 #define g_clear_object(object_ptr) g_clear_pointer ((object_ptr), g_object_unref)
                                    ^~~~~~~~~~~~~~~
src/io_frida.c:133:2: note: in expansion of macro ‘g_clear_object’
  g_clear_object (&rf->crash);
  ^~~~~~~~~~~~~~
In file included from src/io_frida.c:15:0:
ext/frida/frida-core.h:2278:24: note: expected ‘gpointer {aka void *}’ but argument is of type ‘volatile FridaCrash * {aka volatile struct _FridaCrash *}’
 #define g_object_unref _frida_g_object_unref
                        ^
ext/frida/frida-core.h:28036:13: note: in expansion of macro ‘g_object_unref’
 void        g_object_unref                    (gpointer        object);
             ^~~~~~~~~~~~~~
pkg-config --cflags r_core
-I/usr/include/libr
g++ src/io_frida.o -o io_frida.so -shared -fPIC -g -lr_core -lssl -lcrypto -lr_config -lr_debug -lr_bin -lr_anal -lr_bp -lr_egg -lr_asm -lr_lang -lr_parse -lr_flag -lr_cons -lr_reg -lr_search -lr_syscall -lr_fs -lr_magic -lr_crypto -lr_hash -lr_io -lr_socket -lr_util -ldl -Wl,-dead_strip  ext/frida/libfrida-core.a -lresolv
/usr/bin/ld: warning: cannot find entry symbol ad_strip; defaulting to 0000000000187000
make[1]: Leaving directory '/home/edu/.local/share/radare2/r2pm/git/r2frida'
mkdir -p /"/home/edu/.local/share/radare2/plugins"
cp -f io_frida.so* /"/home/edu/.local/share/radare2/plugins"
s0i37 commented 5 years ago
node --version
v9.6.1
trufae commented 5 years ago

r2pm -ci r2frida

And use node10 at least, its LTS

And in your logs i dont see any error. The plugin is compiled and installed

On 13 Aug 2019, at 11:13, s0i37 notifications@github.com wrote:

node --version v9.6.1 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

s0i37 commented 5 years ago
node -v
v10.13.0

r2pm -ci r2frida

Cleaning r2frida...
Updated yet.
clean Done For r2frida
/root/.local/share/radare2/r2pm/db/r2frida TGZ=
Cleaning up /root/.local/share/radare2/r2pm/git//r2frida...
Cloning into «r2frida»…
remote: Enumerating objects: 73, done.
remote: Counting objects: 100% (73/73), done.
remote: Compressing objects: 100% (68/68), done.
remote: Total 73 (delta 1), reused 42 (delta 0), pack-reused 0
Extracting: 100% (73/73), done.
Submodule «ext/swift-frida» (https://github.com/trufae/swift-frida.git) has been registered as «ext/swift-frida»
Cloning into «/root/.local/share/radare2/r2pm/git/r2frida/ext/swift-frida»…
remote: Enumerating objects: 676, done.        
remote: Total 676 (delta 0), reused 0 (delta 0), pack-reused 676        
Obtainting objects: 100% (676/676), 247.51 KiB | 58.00 KiB/s, done.
Checking changes: 100% (446/446), done.
Submodule «ext/swift-frida»: ready «23523bc23f2daecac0b7a67738d715b425660cc8»
Install Done For r2frida
Makefile:1: config.mk: file not found
./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for working directories... current
using prefix '/usr/local'
checking for c compiler... gcc
checking for c++ compiler... g++
Using PKGCONFIG: pkg-config
checking pkg-config flags for r_core... yes
checking for curl... /usr/bin/curl
checking for wget... /usr/bin/wget
checking for git... /usr/bin/git
checking for xz... /usr/bin/xz
checking for node... /usr/local/bin/node
checking for npm... /usr/local/bin/npm
creating ./config.mk
cleaning temporally files... done

Final report:
 - WITH_CYLANG = 0
rm -f ext/frida
mkdir -p ext/frida-linux-12.6.12/_
curl -Ls https://github.com/frida/frida/releases/download/12.6.12/frida-core-devkit-12.6.12-linux-x86_64.tar.xz | xz -d | tar -C ext/frida-linux-12.6.12/_ -xf -
mv ext/frida-linux-12.6.12/_/* ext/frida-linux-12.6.12
rmdir ext/frida-linux-12.6.12/_
#mv ext/frida ext/frida-linux-12.6.12
cd ext && ln -fs frida-linux-12.6.12 frida
[ "`readlink ext/frida`" = frida-linux-12.6.12 ] || \
    (cd ext && rm -f frida ; ln -fs frida-linux-12.6.12 frida)
make io_frida.so
make[1]: entering in «/root/.local/share/radare2/r2pm/git/r2frida»
((test packages.json -nt packages-lock.json) || (test -d node_modules && false || true)) && npm i || true

> core-js@2.6.9 postinstall /root/.local/share/radare2/r2pm/git/r2frida/node_modules/core-js
> node scripts/postinstall || echo "ignore"

internal/modules/cjs/loader.js:582
    throw err;
    ^

Error: Cannot find module '/root/.local/share/radare2/r2pm/git/r2frida/node_modules/core-js/scripts/postinstall'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
Aborted
ignore

> core-js-pure@3.1.4 postinstall /root/.local/share/radare2/r2pm/git/r2frida/node_modules/core-js-pure
> node scripts/postinstall || echo "ignore"

internal/modules/cjs/loader.js:582
    throw err;
    ^

Error: Cannot find module '/root/.local/share/radare2/r2pm/git/r2frida/node_modules/core-js-pure/scripts/postinstall'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
Aborted
ignore
npm WARN prepublish-on-install As of npm@5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.
npm WARN lifecycle r2frida-agent@3.7.0~prepublish: cannot run in wd r2frida-agent@3.7.0 npm run build (wd=/root/.local/share/radare2/r2pm/git/r2frida)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.0.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 491 packages from 245 contributors and audited 10230 packages in 11.833s
found 0 vulnerabilities

Aborted
npm run build

> r2frida-agent@3.7.0 build /root/.local/share/radare2/r2pm/git/r2frida
> frida-compile src/agent -o src/_agent.js

{ [TypeScript error: ../../../../../../node_modules/@types/node/index.d.ts(6208,55): Error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.]
  message:
   '../../../../../../node_modules/@types/node/index.d.ts(6208,55): Error TS2583: Cannot find name \'Map\'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.',
  fileName: '../../../../../../node_modules/@types/node/index.d.ts',
  line: 6208,
  column: 55,
  name: 'TypeScript error',
  inputs:
   Set {
     '/root/.local/share/radare2/r2pm/git/r2frida/src/agent/index.js',
     '/root/node_modules/@types/node/index.d.ts',
     '/root/node_modules/@types/node/inspector.d.ts',
     '/root/.local/share/radare2/r2pm/git/r2frida/node_modules/typescript/lib/lib.d.ts',
     '/root/.local/share/radare2/r2pm/git/r2frida/node_modules/typescript/lib/lib.es5.d.ts',
     '/root/.local/share/radare2/r2pm/git/r2frida/node_modules/typescript/lib/lib.dom.d.ts',
     '/root/.local/share/radare2/r2pm/git/r2frida/node_modules/typescript/lib/lib.webworker.importscripts.d.ts',
     '/root/.local/share/radare2/r2pm/git/r2frida/node_modules/typescript/lib/lib.scripthost.d.ts' } }
Aborted
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! r2frida-agent@3.7.0 build: `frida-compile src/agent -o src/_agent.js`
npm ERR! Exit status 134
npm ERR! 
npm ERR! Failed at the r2frida-agent@3.7.0 build 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!     /root/.npm/_logs/2019-08-13T12_38_28_495Z-debug.log
Makefile:164:     «src/_agent.js»
make[1]: *** [src/_agent.js]  
make[1]:   «/root/.local/share/radare2/r2pm/git/r2frida»
Makefile:113:   «all»
make: *** [all]   2
ERROR: Build failed
enovella commented 5 years ago

Ok thanks a lot for the log. I will try to reproduce in a Debian VM.

trufae commented 5 years ago

There are two things that make no sense here

Btw i have also noticed that the travis for r2frida is only compiling r2.

Can you try building with a clean checkout. Maybe removing the node_modules directory?

On 13 Aug 2019, at 15:01, s0i37 notifications@github.com wrote:

npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

s0i37 commented 5 years ago

so,

rm -r node_modules
npm install
node ~/src/frida-compile/bin/compile.js src/agent -o src/_agent.js

I've used https://github.com/frida/frida-compile And

{ [TypeScript error: ../../node_modules/@types/node/index.d.ts(6208,55): Error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.]
  message:
   '../../node_modules/@types/node/index.d.ts(6208,55): Error TS2583: Cannot find name \'Map\'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.',
  fileName: '../../node_modules/@types/node/index.d.ts',
  line: 6208,
  column: 55,
  name: 'TypeScript error',
  inputs:
   Set {
     '/root/src/r2frida/src/agent/index.js',
     '/root/node_modules/@types/node/index.d.ts',
     '/root/node_modules/@types/node/inspector.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.es5.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.dom.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.webworker.importscripts.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.scripthost.d.ts' } }
xiaobfly commented 5 years ago

xian@GIH-D-20057:/$ r2 -H R2_PREFIX=/usr MAGICPATH=/share/radare2/2.3.0/magic PREFIX=/usr INCDIR=/usr/include/libr LIBDIR=/usr/lib/x86_64-linux-gnu LIBEXT=so RHOMEDIR=/home/xian/.config/radare2 LIBR_PLUGINS=/usr/lib/radare2/2.3.0 USER_PLUGINS=/home/xian/.config/radare2/plugins USER_ZIGNS=/home/xian/.config/radare2/zigns xian@GIH-D-20057:/$ r2pm install r2frida Already up to date. Install Done For r2frida Please install r2 Makefile:43: recipe for target 'r2' failed make: *** [r2] Error 1 ERROR: Build failed xian@GIH-D-20057:/$

?????????????

radare commented 5 years ago

r2frida builds fine for me on debian9 x86-32 with node8 and archlinux x86-64 with node10. i just can't reproduce :/

radare commented 5 years ago

use r2pm -ci r2frida

radare commented 5 years ago

also it seems like you are using a very old version of r2 (2.3 is more than a year old). and r2frida from git expects r2 from git (or at least last release). please ensure you have uninstalled your old r2 from the distro package first

xiaobfly commented 5 years ago

also it seems like you are using a very old version of r2 (2.3 is more than a year old). and r2frida from git expects r2 from git (or at least last release). please ensure you have uninstalled your old r2 from the distro package first

The updated version has been resolved.

trufae commented 5 years ago

What does it mean?

On 19 Aug 2019, at 04:44, xuxian notifications@github.com wrote:

also it seems like you are using a very old version of r2 (2.3 is more than a year old). and r2frida from git expects r2 from git (or at least last release). please ensure you have uninstalled your old r2 from the distro package first

The updated version has been resolved.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

xiaobfly commented 5 years ago

What does it mean? On 19 Aug 2019, at 04:44, xuxian @.***> wrote: also it seems like you are using a very old version of r2 (2.3 is more than a year old). and r2frida from git expects r2 from git (or at least last release). please ensure you have uninstalled your old r2 from the distro package first The updated version has been resolved. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

update radare2 to last version.

  1. r2pm -uu

  2. git clone https://github.com/radare/radare2 cd radare2 sys/install.sh # just run this script to update r2 from git

  3. r2pm -ci r2frida

done.

trufae commented 5 years ago

So problem solved? Can wr close this issue?

On 19 Aug 2019, at 11:25, xuxian notifications@github.com wrote:

What does it mean? … On 19 Aug 2019, at 04:44, xuxian @.***> wrote: also it seems like you are using a very old version of r2 (2.3 is more than a year old). and r2frida from git expects r2 from git (or at least last release). please ensure you have uninstalled your old r2 from the distro package first The updated version has been resolved. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

update radare2 to last version.

r2pm -uu

git clone https://github.com/radare/radare2 cd radare2 sys/install.sh # just run this script to update r2 from git

r2pm -ci r2frida

done.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

xiaobfly commented 5 years ago

but the issue is not mine.

@s0i37

So problem solved? Can wr close this issue? On 19 Aug 2019, at 11:25, xuxian @.> wrote: What does it mean? … On 19 Aug 2019, at 04:44, xuxian @.> wrote: also it seems like you are using a very old version of r2 (2.3 is more than a year old). and r2frida from git expects r2 from git (or at least last release). please ensure you have uninstalled your old r2 from the distro package first The updated version has been resolved. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread. update radare2 to last version. r2pm -uu git clone https://github.com/radare/radare2 cd radare2 sys/install.sh # just run this script to update r2 from git r2pm -ci r2frida done. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

s0i37 commented 5 years ago

I've solved my problem. The short explanation - node automaticaly try to detect typescript and will use them if finds .d.ts (https://github.com/facebook/create-react-app/issues/5669). My backtrace contains these files:

{ [TypeScript error: ../../node_modules/@types/node/index.d.ts(6208,55): Error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.]
  message:
   '../../node_modules/@types/node/index.d.ts(6208,55): Error TS2583: Cannot find name \'Map\'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.',
  fileName: '../../node_modules/@types/node/index.d.ts',
  line: 6208,
  column: 55,
  name: 'TypeScript error',
  inputs:
   Set {
     '/root/src/r2frida/src/agent/index.js',
---> '/root/node_modules/@types/node/index.d.ts',    <-- !!!!!!!
---> '/root/node_modules/@types/node/inspector.d.ts', <-- !!!!!!!
     '/root/src/r2frida/node_modules/typescript/lib/lib.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.es5.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.dom.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.webworker.importscripts.d.ts',
     '/root/src/r2frida/node_modules/typescript/lib/lib.scripthost.d.ts' } }

Moreover node will use ~/node_modules even I if specify $NODE_PATH to another place. The solve is: mv /root/node_modules /root/_node_modules r2pm -ci r2frida after that I've got an error:

Error: Cannot find module '/root/.local/share/radare2/r2pm/git/r2frida/node_modules/core-js-pure/scripts/postinstall'

I had met this error previously when I tryed to build r2frida from git manually. So I have repeated frida-compile command from r2pm git folder: cd /root/.local/share/radare2/r2pm/git/r2frida node ~/src/frida-compile/bin/compile.js src/agent -o src/_agent.js r2pm -i r2frida And It seems work finally:

r2pm list | grep r2frida
r2 frida://$(pidof top)