From 978f5021d112eff3e6ae0843f023746be1a880b1 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 10 Dec 2024 16:40:22 +0100 Subject: [PATCH] Implement the 'ies' command --- src/agent/index.ts | 1 + src/agent/lib/info/index.ts | 40 +++++++++++++++++++++++++++++++++++++ src/io_frida.c | 2 +- test/db/extras/version | 4 ++-- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/agent/index.ts b/src/agent/index.ts index 2c86c55b..657f2f17 100644 --- a/src/agent/index.ts +++ b/src/agent/index.ts @@ -96,6 +96,7 @@ const commandHandlers = { ie: [info.listEntrypoint, 'show entrypoint of binary in current offset'], ieq: info.listEntrypointQuiet, 'ie*': info.listEntrypointR2, + ies: info.listEntrypointSymbols, iej: info.listEntrypointJson, afs: [anal.analFunctionSignature, 'Show function signature', '[klass] [method]'], ii: [info.listImports, 'list imports'], diff --git a/src/agent/lib/info/index.ts b/src/agent/lib/info/index.ts index 34847cf1..f5eea0f8 100644 --- a/src/agent/lib/info/index.ts +++ b/src/agent/lib/info/index.ts @@ -11,6 +11,7 @@ import strings from '../strings.js'; import { belongsTo, padPointer, sanitizeString } from '../utils.js'; import { parseMachoHeader, hasMainLoop } from '../darwin/index.js'; import { r2frida } from "../../plugin.js"; +import { listClassesLoaded } from './classes.js'; export async function dumpInfo() { @@ -186,6 +187,44 @@ export function listHeadersR2(args: string[]) : string { return ""; } +interface Symbol { + name: string; + address: string; +} + +export function listEntrypointSymbols(args: string[]): string { + const validEntrypoints = [ + "UIApplicationMain", + ]; + const symbols = new Array(); + if (ObjC.available) { + const classes = ObjC.classes; + Object.keys(classes).forEach(function (className: string) { + var cls = ObjC.classes[className]; + var methods = cls.$methods; // $ownMethods? + methods.forEach(function (methodName) { + try { + var address = cls[methodName].implementation; // Get the implementation address + console.log(" Method: " + methodName + " | Address: " + address); + if (validEntrypoints.includes(methodName)) { + symbols.push({ name: methodName, address: address }); + } + } catch (e) { + console.error(" [Error getting implementation address for method " + methodName + "]: " + e); + } + }); + }); + } + + if (symbols.length === 0) { + return ""; + } + const entries = symbols + .map((entry) => { + return 'f entry.' + entry.name + ' = ' + entry.address; + }).join('\n'); + return "fs+symbols\n" + entries + "\nfs-"; +} export function listEntrypointR2(args: string[]) : string { let n = 0; const entries = listEntrypointJson() @@ -631,6 +670,7 @@ export default { dumpInfoJson, listEntrypointJson, listEntrypointR2, + listEntrypointSymbols, listEntrypointQuiet, listEntrypoint, listImports, diff --git a/src/io_frida.c b/src/io_frida.c index 53a0e83f..a95f0749 100644 --- a/src/io_frida.c +++ b/src/io_frida.c @@ -2147,7 +2147,7 @@ RIOPlugin r_io_plugin_frida = { .close = __close, .read = __read, .check = __check, -#if ((R2_VERSION_MAJOR == 5 && R2_VERSION_MINOR >= 4) || R2_VERSION_MAJOR > 5) +#if R2_VERSION_NUMBER >= 50405 .seek = __lseek, #else .lseek = __lseek, diff --git a/test/db/extras/version b/test/db/extras/version index 2baa5c82..c5a46fff 100644 --- a/test/db/extras/version +++ b/test/db/extras/version @@ -4,7 +4,7 @@ CMDS=<