-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixThumbRegionAndDump.java
More file actions
71 lines (55 loc) · 3.02 KB
/
Copy pathFixThumbRegionAndDump.java
File metadata and controls
71 lines (55 loc) · 3.02 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import ghidra.app.script.GhidraScript;
import ghidra.app.decompiler.DecompInterface;
import ghidra.app.decompiler.DecompileResults;
import ghidra.program.model.address.Address;
import ghidra.program.model.lang.Register;
import ghidra.program.model.listing.Function;
import ghidra.util.task.ConsoleTaskMonitor;
import java.math.BigInteger;
import java.io.PrintWriter;
import java.io.FileWriter;
public class FixThumbRegionAndDump extends GhidraScript {
// Диапазон вокруг найденных Thumb-прологов и нашей строки "Kernelcache image not valid"
long RANGE_START = 0x8403a000L;
long RANGE_END = 0x8403d000L; // с запасом вокруг 0x8403b1ae
@Override
public void run() throws Exception {
Register tmode = currentProgram.getProgramContext().getRegister("TMode");
Address start = toAddr(RANGE_START);
Address end = toAddr(RANGE_END);
println("=== Чистим и помечаем как Thumb: " + start + " - " + end + " ===");
clearListing(start, end);
currentProgram.getProgramContext().setValue(tmode, start, end, BigInteger.ONE);
disassemble(start);
println("=== Запускаем полный повторный автоанализ ===");
analyzeAll(currentProgram);
println("=== Анализ завершён, декомпилируем функции в диапазоне и ищем совпадения ===");
DecompInterface decompiler = new DecompInterface();
decompiler.openProgram(currentProgram);
String outPath = "/tmp/ibec_thumb_region_dump.txt";
PrintWriter out = new PrintWriter(new FileWriter(outPath));
var funcIter = currentProgram.getListing().getFunctions(start, true);
int total = 0;
int matches = 0;
while (funcIter.hasNext()) {
Function func = funcIter.next();
if (func.getEntryPoint().getOffset() > RANGE_END) break;
total++;
DecompileResults result = decompiler.decompileFunction(func, 30, new ConsoleTaskMonitor());
if (!result.decompileCompleted()) continue;
String code = result.getDecompiledFunction().getC();
out.println("\n\n=== " + func.getName() + " @ " + func.getEntryPoint() + " ===");
out.println(code);
if (code.contains("valid") || code.contains("macho") || code.contains("Mach") ||
code.contains("Kernelcache") || code.contains("feedface") || code.contains("0xfeedface")) {
matches++;
println("\n>>>>> СОВПАДЕНИЕ: " + func.getName() + " @ " + func.getEntryPoint() + " <<<<<");
println(code);
}
}
out.close();
decompiler.dispose();
println("\n=== ГОТОВО: обработано " + total + " функций в диапазоне, совпадений: " + matches + " ===");
println("=== Полный дамп региона сохранён в: " + outPath + " ===");
}
}