Minor improvements for the r2papi sync make logic

This commit is contained in:
pancake 2024-06-23 02:05:54 +02:00 committed by GitHub
parent 220b849025
commit 7e7eca2413
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 23 deletions

View File

@ -1,5 +1,8 @@
include deps.mk
USE_MINIFY=1
USE_UGLIFY=0
ifeq ($(QJS_BRANCH),frida)
QJS_NAME=quickjs-frida
QJS_GITURL=https://github.com/frida/quickjs
@ -27,13 +30,15 @@ QJS_VERSION=$(shell cat src/VERSION.txt)
JS_CFILES:=js_repl.c js_r2papi.c js_require.c
all: src $(JS_CFILES)
all: $(JS_CFILES)
# $(JS_CFILES): node_modules
node_modules:
mkdir -p node_modules
npm i
src:
sync-qjs qjs-sync sync:
$(MAKE) $(QJS_NAME)
rm -rf src
mv $(QJS_NAME) src
@ -48,66 +53,95 @@ src:
NM=node_modules
js_r2papi.c:
R2PAPI_FILES=
R2PAPI_FILES+=index.js
R2PAPI_FILES+=r2papi.js
R2PAPI_FILES+=r2pipe.js
R2PAPI_FILES+=base64.js
R2PAPI_FILES+=ai.js
R2PAPI_FILES+=r2frida.js
R2PAPI_FILES+=shell.js
R2PAPI_FILES+=esil.js
R2PAPI_FILES_JS=$(addprefix $(NM)/r2papi/,$(R2PAPI_FILES))
js_r2papi.c: node_modules
# npm i js_r2papi
printf "Using r2papi version: "
-jq .version node_modules/r2papi/package.json
mkdir -p $(NM)
cat \
$(NM)/r2papi/r2papi.js \
$(NM)/r2papi/r2pipe.js \
$(NM)/r2papi/base64.js \
$(NM)/r2papi/ai.js \
$(NM)/r2papi/shell.js \
$(NM)/r2papi/esil.js \
> $(NM)/r2papi/entrypoint.js
cat $(R2PAPI_FILES_JS) > $(NM)/r2papi/entrypoint.js
echo 'var G={};' > js_r2papi.qjs
sed \
-e 's,exports,G,g' \
-e 's,require(,G;//,g' \
< $(NM)/r2papi/entrypoint.js \
| grep -v 'use strict' \
| grep -v 'r2pipe\.js' \
> js_r2papi.qjs
>> js_r2papi.qjs
echo 'const r2pipe_js_1 = G;' >> js_r2papi.qjs
ifeq ($(USE_MINIFY),1)
npx minify --help > /dev/null npm i minify
npx minify --js < js_r2papi.qjs > js_r2papi.mini.qjs
else
cp -f js_r2papi.qjs js_r2papi.mini.qjs
endif
ifeq ($(USE_UGLIFY),1)
npx uglify-js --help > /dev/null || npm i uglify-js
npx uglify-js --no-annotations --toplevel --validate -c < js_r2papi.mini.qjs > js_r2papi.tiny.qjs
else
cp -f js_r2papi.mini.qjs js_r2papi.tiny.qjs
endif
@ls -l js_r2papi.qjs
@ls -l js_r2papi.mini.qjs
@ls -l js_r2papi.tiny.qjs
echo 'static const char *const js_r2papi_qjs = "" \\' > js_r2papi.c
r2 -fqcpcc js_r2papi.mini.qjs | grep -v ^const >> js_r2papi.c
# r2 -fqcpcc js_r2papi.tiny.qjs | grep -v ^const >> js_r2papi.c
rm -f js_r2papi.mini.qjs js_r2papi.tiny.qjs
# rm -f js_r2papi.mini.qjs js_r2papi.tiny.qjs
js_require.c:
ifeq ($(USE_MINIFY),1)
npx minify --help > /dev/null npm i minify
npx minify --js < js_require.qjs > mini.qjs
echo "`du -hs js_require.qjs|awk '{print $$1}'` => `du -hs mini.qjs|awk '{print $$1}'`"
npx minify --js < js_require.qjs > js_require.mini.qjs
else
cp -f js_require.qjs js_require.mini.qjs
endif
echo "`du -hs js_require.qjs|awk '{print $$1}'` => `du -hs js_require.mini.qjs|awk '{print $$1}'`"
ifeq ($(USE_UGLIFY),1)
# 20K uglify
npx uglify-js --help > /dev/null || npm i uglify-js
npx uglify-js --no-annotations --toplevel --validate -c < mini.qjs > tiny.qjs
@ls -l mini.qjs
@ls -l tiny.qjs
echo "`du -hs mini.qjs|awk '{print $$1}'` => `du -hs tiny.qjs|awk '{print $$1}'`"
npx uglify-js --no-annotations --toplevel --validate -c < js_require.mini.qjs > js_require.tiny.qjs
else
cp -f js_require.mini.qjs js_require.tiny.qjs
endif
@ls -l js_require.mini.qjs
@ls -l js_require.tiny.qjs
echo "`du -hs js_require.mini.qjs|awk '{print $$1}'` => `du -hs js_require.tiny.qjs|awk '{print $$1}'`"
npx minify --help > /dev/null npm i minify
npx minify --js < tiny.qjs > mini.qjs
echo "`du -hs tiny.qjs|awk '{print $$1}'` => `du -hs mini.qjs|awk '{print $$1}'`"
npx minify --js < js_require.tiny.qjs > js_require.mini.qjs
echo "`du -hs js_require.tiny.qjs|awk '{print $$1}'` => `du -hs mini.qjs|awk '{print $$1}'`"
echo 'static const char *const js_require_qjs = "" \\' > js_require.c
r2 -fqcpcc mini.qjs | grep -v ^const >> js_require.c
r2 -fqcpcc js_require.mini.qjs | grep -v ^const >> js_require.c
js_repl.c:
# goto this s
# 19K https://www.toptal.com/developers/javascript-minifier
# ??K
ifeq ($(USE_MINIFY),1)
npx minify --help > /dev/null npm i minify
npx minify --js < js_repl.qjs > mini.qjs
else
cp -f js_repl.qjs mini.qjs
endif
echo "`du -hs js_repl.qjs|awk '{print $$1}'` => `du -hs mini.qjs|awk '{print $$1}'`"
ifeq ($(USE_UGLIFY),1)
# 20K uglify
npx uglify-js --help > /dev/null || npm i uglify-js
npx uglify-js --no-annotations --toplevel --validate -c < mini.qjs > tiny.qjs
else
cp -f mini.qjs tiny.qjs
endif
@ls -l mini.qjs
@ls -l tiny.qjs
echo "`du -hs mini.qjs|awk '{print $$1}'` => `du -hs tiny.qjs|awk '{print $$1}'`"

View File

@ -1,5 +1,9 @@
{
"dependencies": {
"r2papi": "0.3.3"
"r2papi": "0.4.7"
},
"devDependencies": {
"minify": "11.2.1",
"uglify": "0.1.5"
}
}