Created
February 25, 2026 00:02
-
-
Save kzaremski/aa54e0a585c86479f93ed4437c556955 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ghidra.app.script.GhidraScript; | |
| import ghidra.app.decompiler.*; | |
| import ghidra.program.model.listing.*; | |
| import java.io.*; | |
| public class GhidraDecompile extends GhidraScript { | |
| @Override | |
| public void run() throws Exception { | |
| DecompInterface decomp = new DecompInterface(); | |
| decomp.openProgram(currentProgram); | |
| FunctionManager fm = currentProgram.getFunctionManager(); | |
| FunctionIterator funcs = fm.getFunctions(true); | |
| String[] targets = { | |
| "ZMEDIA=NULL", "ZMEDIA=%lld", "Z_PK=%ld", "ZFILENAME", | |
| "ZFALLBACKIMAGEGENERATION", "ZFALLBACKPDFGENERATION", | |
| "ZPASSWORDPROTECTED", "Z_PRIMARYKEY", "ZICCLOUDSYNCINGOBJECT", | |
| "PRAGMA table_info", "NoteStore.sqlite", | |
| "AppleNotesDatabaseParser", "TableParser", | |
| "sqlite3_open", "sqlite3_prepare", "sqlite3_step", | |
| "fetchNotes", "fetchFolders", "generateHTML", | |
| "resolveAttachment", "getTableColumns", "parseTable" | |
| }; | |
| PrintWriter out = new PrintWriter(new FileWriter("/tmp/ghidra_decompiled.txt")); | |
| int count = 0; int decompiled = 0; | |
| while (funcs.hasNext()) { | |
| Function f = funcs.next(); count++; | |
| DecompileResults results = decomp.decompileFunction(f, 30, monitor); | |
| if (results.getDecompiledFunction() != null) { | |
| String code = results.getDecompiledFunction().getC(); | |
| if (code != null) { | |
| boolean match = false; | |
| for (String target : targets) { | |
| if (code.contains(target)) { match = true; break; } | |
| } | |
| if (match) { | |
| decompiled++; | |
| out.println("=== FUNCTION: " + f.getName() + " @ " + f.getEntryPoint() + " ==="); | |
| out.println(code); out.println(""); | |
| } | |
| } | |
| } | |
| } | |
| out.close(); decomp.dispose(); | |
| println("Scanned " + count + " functions, found " + decompiled + " matching"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment