/
hookMyApp.py
35 lines (34 loc) · 907 Bytes
/
hookMyApp.py
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
import frida
import os
targetProcessName = "MyApp.exe"
try:
session = frida.attach(targetProcessName)
except Exception as ex:
print ex
os.system('pause')
sys.exit(-1)
script = session.create_script("""
var module = Process.enumerateModulesSync()
.filter(function(x) {
return x.name == '%s';
})[0];
var patched = false;
Process.enumerateRanges('rw-', {
onMatch: function(range) {
var matches = Memory.scanSync(range.base, range.size, '90 33 d2 89 55 ?? 90');
if (matches.length == 0) {
return;
}
var match = matches[0];
Memory.writeByteArray(match.address, [ 0x31, 0xD2, 0x42 ]);
console.log('Patched code at ' + match.address);
patched = true;
},
onComplete: function() { }
});
if (!patched) {
console.log('Failed to patch code');
}
""" % targetProcessName)
script.load()
os.system('pause')