Skip to content

Commit

Permalink
renamed symbol APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbo committed Dec 30, 2022
1 parent 7aa1a23 commit 773cc36
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 35 deletions.
10 changes: 5 additions & 5 deletions libmem/include/libmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,13 @@ LM_EnumSymbolsEx(lm_process_t proc,
lm_void_t *arg);

LM_API lm_address_t
LM_GetSymbol(lm_module_t mod,
lm_cstring_t symstr);
LM_FindSymbol(lm_module_t mod,
lm_cstring_t symstr);

LM_API lm_address_t
LM_GetSymbolEx(lm_process_t proc,
lm_module_t mod,
lm_cstring_t symstr);
LM_FindSymbolEx(lm_process_t proc,
lm_module_t mod,
lm_cstring_t symstr);

/****************************************/

Expand Down
8 changes: 4 additions & 4 deletions libmem/src/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,9 @@ _LM_CallDlopen(lm_process_t proc,
if (!_LM_FindLibc(proc, &libc_mod))
return ret;

dlopen_addr = LM_GetSymbolEx(proc, libc_mod, "__libc_dlopen_mode");
dlopen_addr = LM_FindSymbolEx(proc, libc_mod, "__libc_dlopen_mode");
if (dlopen_addr == LM_ADDRESS_BAD) {
dlopen_addr = LM_GetSymbolEx(proc, libc_mod, "dlopen");
dlopen_addr = LM_FindSymbolEx(proc, libc_mod, "dlopen");
if (dlopen_addr == LM_ADDRESS_BAD)
return ret;
}
Expand Down Expand Up @@ -747,9 +747,9 @@ _LM_CallDlclose(lm_process_t proc,
if (!_LM_FindLibc(proc, &libc_mod))
return ret;

dlclose_addr = LM_GetSymbolEx(proc, libc_mod, "__libc_dlclose");
dlclose_addr = LM_FindSymbolEx(proc, libc_mod, "__libc_dlclose");
if (dlclose_addr == LM_ADDRESS_BAD) {
dlclose_addr = LM_GetSymbolEx(proc, libc_mod, "dlclose");
dlclose_addr = LM_FindSymbolEx(proc, libc_mod, "dlclose");
if (dlclose_addr == LM_ADDRESS_BAD)
return ret;
}
Expand Down
37 changes: 14 additions & 23 deletions libmem/src/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ LM_EnumSymbolsEx(lm_process_t proc,

#if LM_OS == LM_OS_WIN
LM_PRIVATE lm_address_t
_LM_GetSymbol(lm_module_t mod,
lm_cstring_t symstr)
_LM_FindSymbol(lm_module_t mod,
lm_cstring_t symstr)
{
lm_address_t symaddr = LM_ADDRESS_BAD;
HMODULE hModule;
Expand All @@ -187,16 +187,16 @@ _LM_GetSymbol(lm_module_t mod,
}
#else
LM_PRIVATE lm_address_t
_LM_GetSymbol(lm_module_t mod,
lm_cstring_t symstr)
_LM_FindSymbol(lm_module_t mod,
lm_cstring_t symstr)
{
lm_address_t symaddr = LM_ADDRESS_BAD;
lm_process_t proc;

if (!LM_OpenProcess(&proc))
return symaddr;

symaddr = LM_GetSymbolEx(proc, mod, symstr);
symaddr = LM_FindSymbolEx(proc, mod, symstr);

LM_CloseProcess(&proc);

Expand All @@ -205,12 +205,12 @@ _LM_GetSymbol(lm_module_t mod,
#endif

LM_API lm_address_t
LM_GetSymbol(lm_module_t mod,
LM_FindSymbol(lm_module_t mod,
lm_cstring_t symstr)
{
LM_ASSERT(symstr != LM_NULLPTR);

return _LM_GetSymbol(mod, symstr);
return _LM_FindSymbol(mod, symstr);
}

/********************************/
Expand All @@ -221,9 +221,9 @@ typedef struct {
} _lm_get_symbol_t;

LM_PRIVATE lm_bool_t
_LM_GetSymbolExCallback(lm_cstring_t symbol,
lm_address_t addr,
lm_void_t *arg)
_LM_FindSymbolExCallback(lm_cstring_t symbol,
lm_address_t addr,
lm_void_t *arg)
{
_lm_get_symbol_t *parg = (_lm_get_symbol_t *)arg;

Expand All @@ -236,9 +236,9 @@ _LM_GetSymbolExCallback(lm_cstring_t symbol,
}

LM_API lm_address_t
LM_GetSymbolEx(lm_process_t proc,
lm_module_t mod,
lm_cstring_t symstr)
LM_FindSymbolEx(lm_process_t proc,
lm_module_t mod,
lm_cstring_t symstr)
{
_lm_get_symbol_t arg;

Expand All @@ -247,17 +247,8 @@ LM_GetSymbolEx(lm_process_t proc,
arg.symbol = symstr;
arg.addr = LM_ADDRESS_BAD;

LM_EnumSymbolsEx(proc, mod, _LM_GetSymbolExCallback, (lm_void_t *)&arg);
LM_EnumSymbolsEx(proc, mod, _LM_FindSymbolExCallback, (lm_void_t *)&arg);

return arg.addr;
}

/********************************/

/********************************/

/********************************/




2 changes: 1 addition & 1 deletion tests/test1.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ main()
LM_FindModule(LM_MOD_BY_ADDR, mod.base, &mod);
LM_GetModuleName(mod, modname, LM_ARRLEN(modname));
LM_GetModulePath(mod, modpath, LM_ARRLEN(modpath));
main_sym = LM_GetSymbol(mod, "main");
main_sym = LM_FindSymbol(mod, "main");
LM_PRINTF(LM_STR("[*] Module Name: %s\n"), modname);
LM_PRINTF(LM_STR("[*] Module Path: %s\n"), modpath);
LM_PRINTF(LM_STR("[*] Module Base: %p\n"), mod.base);
Expand Down
4 changes: 2 additions & 2 deletions tests/test2.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ main()
LM_FindModuleEx(proc, LM_MOD_BY_ADDR, mod.base, &mod);
LM_GetModuleNameEx(proc, mod, modname, LM_ARRLEN(modname));
LM_GetModulePathEx(proc, mod, modpath, LM_ARRLEN(modpath));
main_sym = LM_GetSymbolEx(proc, mod, "main");
val_sym = LM_GetSymbolEx(proc, mod, "val");
main_sym = LM_FindSymbolEx(proc, mod, "main");
val_sym = LM_FindSymbolEx(proc, mod, "val");
LM_PRINTF(LM_STR("[*] Module Name: %s\n"), modname);
LM_PRINTF(LM_STR("[*] Module Path: %s\n"), modpath);
LM_PRINTF(LM_STR("[*] Module Base: %p\n"), mod.base);
Expand Down

0 comments on commit 773cc36

Please sign in to comment.