tweaselORG / appstraction

An abstraction layer for common instrumentation functions (e.g. installing and starting apps, setting preferences, etc.) on Android and iOS.
MIT License
4 stars 1 forks source link

Fixes #110, #24, #101: Use httptoolkit/frida-android-unpinning #111

Closed baltpeter closed 11 months ago

baltpeter commented 11 months ago

The problem is that Parcel builds the unpinning script instead of treating it as a text file. It adds:

export {$ee1b1628d2dcda72$exports as default};

The JS engine Frida uses doesn't understand that, thus the error.

baltpeter commented 11 months 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)
baltpeter commented 11 months ago

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