forked from nowsecure/r2frida
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin-libc.js
41 lines (37 loc) · 1.18 KB
/
plugin-libc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// run '\. plugin.js' inside an 'r2 frida://' session to load it
// run '\.-test' to unload it and '\.' to list hem all
function sym(name, ret, arg) {
try {
return new NativeFunction(Module.findExportByName(null, name), ret, arg);
} catch (e) {
console.error(name, ':', e);
}
}
var libcCommands = {
'getuid': sym('getuid', 'int', []),
'getgid': sym('getgid', 'int', []),
'setuid': sym('setuid', 'int', ['int']),
'setgid': sym('setgid', 'int', ['int']),
'remove': sym('remove', 'int', ['string']),
'system': sym('system', 'int', ['string'])
};
r2frida.pluginRegister('libc', function(name) {
if (name === 'libc') {
return function(args) {
if (args.length === 0) {
return Object.keys(libcCommands).join('\n');
}
const command = args.shift();
for (var arg in args) {
if (+args[arg] || args[arg] === '0') {
args[arg] = +args[arg];
} else if (args[arg].substring(0, 2) === '0x') {
args[arg] = ptr(args[arg]);
} else if (args[arg] === 'true' || args[arg] === 'false') {
args[arg] = args[arg] === 'true';
}
}
return libcCommands[command].apply(null, args);
}
}
});