diff --git a/src/common/symbol.c b/src/common/symbol.c index 637a26de..0e408cd6 100644 --- a/src/common/symbol.c +++ b/src/common/symbol.c @@ -49,7 +49,7 @@ LM_FindSymbolAddress(const lm_module_t *module, find_symbol_t parg; if (!module || !symbol_name) - return LM_FALSE; + return LM_ADDRESS_BAD; parg.symbol_name = symbol_name; parg.addr = LM_ADDRESS_BAD; diff --git a/tests/target.c b/tests/target.c index 5933f9b7..118c14f7 100644 --- a/tests/target.c +++ b/tests/target.c @@ -24,6 +24,7 @@ wait_message() fflush(stdout); } +LM_API_EXPORT int main() { printf("[*] Target Process\n"); diff --git a/tests/unit/helpers.h b/tests/unit/helpers.h index 95329423..ef3ccc24 100644 --- a/tests/unit/helpers.h +++ b/tests/unit/helpers.h @@ -65,3 +65,8 @@ struct scan_args { lm_process_t *ptargetproc; lm_address_t scanaddr; }; + +struct find_symbol_args { + lm_module_t *curmod; + lm_module_t *targetmod; +}; diff --git a/tests/unit/symbol.c b/tests/unit/symbol.c index 0407f5ea..d8d721c5 100644 --- a/tests/unit/symbol.c +++ b/tests/unit/symbol.c @@ -30,16 +30,17 @@ char *test_LM_EnumSymbols(lm_module_t *pmod) return NULL; } -char *test_LM_FindSymbolAddress(lm_module_t *pmod) +char *test_LM_FindSymbolAddress(struct find_symbol_args *arg) { lm_address_t symaddr = LM_ADDRESS_BAD; - symaddr = LM_FindSymbolAddress(pmod, real_symbol); + symaddr = LM_FindSymbolAddress(arg->curmod, real_symbol); mu_assert("invalid symbol address", symaddr != LM_ADDRESS_BAD); mu_assert("incorrect symbol address", symaddr == (lm_address_t)real_symbol_addr); - mu_assert("function attempted to run with bad arguments (invalid pmod)", LM_FindSymbolAddress(LM_NULLPTR, real_symbol) == LM_FALSE); - mu_assert("function attempted to run with bad arguments (invalid callback)", LM_FindSymbolAddress(pmod, LM_NULLPTR) == LM_FALSE); + mu_assert("failed to find 'main' symbol in target process", LM_FindSymbolAddress(arg->targetmod, "main") != LM_ADDRESS_BAD); + mu_assert("function attempted to run with bad arguments (invalid pmod)", LM_FindSymbolAddress(LM_NULLPTR, real_symbol) == LM_ADDRESS_BAD); + mu_assert("function attempted to run with bad arguments (invalid callback)", LM_FindSymbolAddress(arg->curmod, LM_NULLPTR) == LM_ADDRESS_BAD); return NULL; } diff --git a/tests/unit/unit.c b/tests/unit/unit.c index 8573dbb4..19117f77 100644 --- a/tests/unit/unit.c +++ b/tests/unit/unit.c @@ -109,15 +109,21 @@ void test_segment(lm_process_t *pcurproc, lm_process_t *ptargetproc) UNIT_TEST_P(LM_FindSegmentEx, ptargetproc); } -void test_symbol(lm_process_t *pcurproc) +void test_symbol(lm_process_t *pcurproc, lm_process_t *ptargetproc) { /* TODO: Retrieve module from 'module' tests and reuse here! */ lm_module_t mod; + lm_module_t target_mod; + struct find_symbol_args arg; assert(LM_FindModule(pcurproc->name, &mod) == LM_TRUE); + assert(LM_FindModuleEx(ptargetproc, ptargetproc->name, &target_mod) == LM_TRUE); + + arg.curmod = &mod; + arg.targetmod = &target_mod; UNIT_TEST_P(LM_EnumSymbols, &mod); - UNIT_TEST_P(LM_FindSymbolAddress, &mod); + UNIT_TEST_P(LM_FindSymbolAddress, &arg); UNIT_TEST(LM_DemangleSymbol); UNIT_TEST(LM_FreeDemangledSymbol); UNIT_TEST_P(LM_EnumSymbolsDemangled, &mod); @@ -172,7 +178,7 @@ main() test_segment(¤t_process, &target_process); test_memory(&target_process); test_module(¤t_process, &target_process); - test_symbol(¤t_process); + test_symbol(¤t_process, &target_process); test_hook(&target_process); test_scan(&target_process); test_vmt();