Skip to content

Commit

Permalink
fixed issue with LM_FindSymbolAddress; added test for external symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbo committed Apr 10, 2024
1 parent 6d220d1 commit 8ce59c3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/common/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ wait_message()
fflush(stdout);
}

LM_API_EXPORT
int main()
{
printf("[*] Target Process\n");
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
9 changes: 5 additions & 4 deletions tests/unit/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -172,7 +178,7 @@ main()
test_segment(&current_process, &target_process);
test_memory(&target_process);
test_module(&current_process, &target_process);
test_symbol(&current_process);
test_symbol(&current_process, &target_process);
test_hook(&target_process);
test_scan(&target_process);
test_vmt();
Expand Down

0 comments on commit 8ce59c3

Please sign in to comment.