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

Wire up dataDir in \i #157

Merged
merged 1 commit into from
Jun 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions src/agent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,16 +542,16 @@ if (Process.platform === 'darwin') {

const traceListeners = [];

function dumpInfo () {
async function dumpInfo () {
const padding = (x) => ''.padStart(20 - x, ' ');
const properties = dumpInfoJson();
const properties = await dumpInfoJson();
return Object.keys(properties)
.map(k => k + padding(k.length) + properties[k])
.join('\n');
}

function dumpInfoR2 () {
const properties = dumpInfoJson();
async function dumpInfoR2 () {
const properties = await dumpInfoJson();
return [
'e asm.arch=' + properties.arch,
'e asm.bits=' + properties.bits,
Expand Down Expand Up @@ -795,7 +795,7 @@ function chDir (args) {
return '';
}

function dumpInfoJson () {
async function dumpInfoJson () {
const res = {
arch: getR2Arch(Process.arch),
bits: pointerSize * 8,
Expand All @@ -812,22 +812,18 @@ function dumpInfoJson () {
isDebuggerAttached: Process.isDebuggerAttached(),
cwd: getCwd()
};

if (JavaAvailable) {
res.cacheDir = Java.classFactory.cacheDir;
Java.perform(function () {
await performOnJavaVM(() => {
const ActivityThread = Java.use('android.app.ActivityThread');

res.dataDir = ActivityThread.currentApplication().getApplicationContext().getDataDir().getAbsolutePath();
res.cacheDir = Java.classFactory.cacheDir;

res.jniEnv = ptr(Java.vm.getEnv()).toString();
});
/*
Java.perform(function () {
try {
const curApp = Java.use('android.app.ActivityThread').currentApplication();
res.datadir = curApp.getApplicationContext(); // .getDataDir();
} catch (e) {
console.error(e);
}
});
*/
}

return res;
}

Expand Down Expand Up @@ -3534,6 +3530,19 @@ function fsOpen (args) {
return fs.open(args[0] || Gcwd);
}

function performOnJavaVM (fn) {
return new Promise((resolve, reject) => {
Java.perform(() => {
try {
const result = fn();
resolve(result);
} catch (e) {
reject(e);
}
});
});
}

function onStanza (stanza, data) {
const handler = requestHandlers[stanza.type];
if (handler !== undefined) {
Expand Down