From 9f085e08ed92257f90145664bb0c56671b8ba5b7 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 10 Dec 2024 12:40:18 +0100 Subject: [PATCH] Fix #23759 - Implement entrypoint symbols command 'ies' ##bin --- libr/core/cmd_info.inc.c | 85 ++++++++++++++++++++++++++++++++++++++++ test/db/cmd/cmd_ie | 16 ++++++++ 2 files changed, 101 insertions(+) diff --git a/libr/core/cmd_info.inc.c b/libr/core/cmd_info.inc.c index 95165cbd5bad6..f9a9537494199 100644 --- a/libr/core/cmd_info.inc.c +++ b/libr/core/cmd_info.inc.c @@ -29,6 +29,7 @@ static RCoreHelpMessage help_msg_is = { "is.", "", "current symbol", "is*", "", "same as above, but in r2 commands", "isj", "", "in json format", + "ise", "", "entrypoints symbols", NULL }; @@ -1847,6 +1848,88 @@ static bool fdof_cb(void *user, void *data, ut32 id) { return true; } +static bool is_entrypoint_symbol(const char *name) { +#if 0 + On Swift any method can be an entrypoint if @main is used as attribute +#endif + const char *words[] = { + "main", "_start", "_main", "Main", + "WinMain", "wmain", "DllMain", "wWinMain", + "UIApplicationMain", + "applicationDidFinishLaunching", + "application:didFinishLaunchingWithOptions", + "applicationWillResignActive", + "applicationDidEnterBackground", + "applicationWillEnterForeground", + "applicationDidBecomeActive", + "applicationWillTerminate", + "application:configurationForConnectingSceneSession:options", + "application:didDiscardSceneSessions", + "application:openURL:options", + "application:performFetchWithCompletionHandler", + "application:didReceiveRemoteNotification:fetchCompletionHandler", + "application:handleEventsForBackgroundURLSession:completionHandler", + "application:shouldSaveSecureApplicationState", + "application:shouldRestoreSecureApplicationState", + "application:didRegisterForRemoteNotificationsWithDeviceToken", + "application:didFailToRegisterForRemoteNotificationsWithError", + "application:didReceiveRemoteNotification", + "application:handleOpenURL", + "application:continueUserActivity:restorationHandler", + "application:didUpdateUserActivity", + "scene:willConnectToSession:options", + "sceneDidDisconnect", + "sceneDidBecomeActive", + "sceneWillResignActive", + "sceneWillEnterForeground", + "sceneDidEnterBackground", + "application:handleWatchKitExtensionRequest:reply", + "main", + "loadView", + "viewDidLoad" + }; + size_t i, size = sizeof (words) / sizeof (words[0]); + + for (i = 0; i < size; i++) { + if (!strcmp (name, words[i])) { + return true; + } + } + return false; +} + +static void cmd_ies(RCore *core, const char *input, PJ *pj, int mode, int va) { + // iterate over symbols and class methods that match + RBinSymbol *sym; + RVecRBinSymbol *symbols = r_bin_get_symbols_vec(core->bin); + R_VEC_FOREACH (symbols, sym) { + const char *name = r_bin_name_tostring2 (sym->name, 'o'); + if (is_entrypoint_symbol (name)) { + r_cons_printf ("0x%08"PFMT64x" %s\n", sym->vaddr, name); + } + } + RList *bfiles = r_core_bin_files (core); + RBinFile *bf; + RListIter *objs_iter; + r_list_foreach (bfiles, objs_iter, bf) { + RBinObject *obj = bf->bo; + RBinClass *klass; + RListIter *iter, *iter2; + core->bin->cur = bf; + RBinSymbol *method; + r_list_foreach (obj->classes, iter, klass) { + r_list_foreach (klass->methods, iter2, method) { + const char *name = r_bin_name_tostring2 (method->name, 'o'); + if (is_entrypoint_symbol (name)) { + const char *kname = r_bin_name_tostring2 (klass->name, 'o'); + r_cons_printf ("0x%08"PFMT64x" %s.%s\n", + method->vaddr, kname, name); + } + } + } + } +} + static void cmd_ie(RCore *core, const char *input, PJ *pj, int mode, bool is_array, int va) { char i1 = input[1]; if (i1 == ',') { @@ -1856,6 +1939,8 @@ static void cmd_ie(RCore *core, const char *input, PJ *pj, int mode, bool is_arr } if (i1 == '?') { r_core_cmd_help (core, help_msg_ie); + } else if (i1 == 's') { + cmd_ies (core, input, pj, mode, va); } else if (i1 == ' ' || i1 == '*' || i1 == 'e' || i1 == 'j' || i1 == '=' || i1 == 'q' || !i1) { RList *objs = r_core_bin_files (core); RListIter *iter; diff --git a/test/db/cmd/cmd_ie b/test/db/cmd/cmd_ie index ea27493cf708b..d25a9c8b148e5 100644 --- a/test/db/cmd/cmd_ie +++ b/test/db/cmd/cmd_ie @@ -202,3 +202,19 @@ paddr vaddr phaddr vhaddr type 0x0000074a 0x0000074a 0x0004dd80 0x0004dd80 preinit EOF RUN + +NAME=ies +FILE=bins/mach0/BatteryLife.arm_64.1 +CMDS=<