r/AskReverseEngineering • • Oct 22 '24
Reverse engineering a dumped C program
I have a container a C program that is read protected. I need to modify that program a bit, to patch a certain behaviour that I want to change.
It's read/write protected, but I can still execute it, and inject my own code with LD_PRELOAD to simply read most sections from /proc/self/maps. I then tried to reverse it in ghidra. Here is an exemple of what I have:
For a simple C program:
Source:
#include <stdio.h>
int main()
{
printf("test\n");
FILE *f = fopen("./output", "w+");
fwrite("test", 4, 1, f);
fclose(f);
}Compiled and dumped using the method above gives me this in ghidra:
undefined8 FUN_001011a9(void)
{
undefined8 uVar1;
FUN_00101080(&DAT_00102004);
uVar1 = FUN_001010a0("./output",&DAT_00102009);
FUN_001010b0(&DAT_00102004,4,1,uVar1);
FUN_00101090(uVar1);
return 0;
}So I clearly have something, all the function calls/static strings match. Execpt when following a call (here to printf for exemple) ghidra only shows me this:
void FUN_00101080(void)
{
/* WARNING: Treating indirect jump as call */
(*(code *)0x1030)();
return;
}From my understanding, that's a call from to a dynamically loaded library (libc). My question is: Is there a way for me to have ghidra automatically resolve thoses calls to libraries ? Do I need to rearrange some sections that I grabbed from the dump ?
View all comments
Show parent comment
1
u/anaccountbyanyname Oct 25 '24
A core dump is a correctly formatted ELF file. It has all the information in it that gdb needs to present you with an environment as though you just attached to the running process and suspended it. That may or may not be best suited to what you're doing, but it's usually the most complete view you can get of a running process you can't attach to live