Closed baltpeter closed 1 year ago
Parcel does support inlining files without transforming them. However, for that to work, you need to use readFileSync
and __dirname
exactly like this:
const unpinningScript = readFileSync(join(__dirname, 'external', 'frida-android-unpinning.js'), 'utf-8');
Using readFile
from fs/promises
or import.meta
instead of __dirname
does not work.
However, if we do use __dirname
, we can't run the example scripts through tsx
anymore. That uses esbuild
under the hood which doesn't have support for Parcel's __dirname
hack:
/home/benni/coding/JS/tweasel/appstraction/src/android.ts:627
const unpinningScript = readFileSync(join(__dirname, 'external', 'frida-android-unpinning.js'), 'utf-8');
^
ReferenceError: __dirname is not defined
at Object.startApp (/home/benni/coding/JS/tweasel/appstraction/src/android.ts:627:55)
at <anonymous> (/home/benni/coding/JS/tweasel/appstraction/examples/android-device.ts:47:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
So, we need our own hack. If I rename the file to frida-android-unpinning.js.txt
, doesn't recognize it as JavaScript anymore and leaves it alone. shrug
The problem is that Parcel builds the unpinning script instead of treating it as a text file. It adds:
The JS engine Frida uses doesn't understand that, thus the error.