Skip to content

Commit

Permalink
Fix #23759 - Implement entrypoint symbols command 'ies' ##bin
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored Dec 10, 2024
1 parent 3726196 commit 9f085e0
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
85 changes: 85 additions & 0 deletions libr/core/cmd_info.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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 == ',') {
Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions test/db/cmd/cmd_ie
Original file line number Diff line number Diff line change
Expand Up @@ -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=<<EOF
ies
EOF
EXPECT=<<EOF
0x1000ff3e4 UIApplicationMain
0x1000052fc mainView.viewDidLoad
0x100009064 pageViewController.viewDidLoad
0x10000a69c lifeViewController.viewDidLoad
0x10000f330 masterViewController.viewDidLoad
0x1000807ac GADViewController.viewDidLoad
0x100083178 GADBrowserViewController.viewDidLoad
EOF
RUN

0 comments on commit 9f085e0

Please sign in to comment.