Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remap a symbol to call a different function

Tags:

linux

gcc

elf

I have an ELF shared object, and I want to modify it so that calls to the system function memcpy are actually routed through to a custom version of memcpy.

I've been researching and I have read about PLT Redirection and ELF Infection, but I'm still not sure how I can accomplish my goal.

Can anyone give me some hint and tips, or elaborate on the PLT Redirection and ELF Infection?

Regards,

Paul

like image 427
paultop6 Avatar asked Nov 06 '22 09:11

paultop6


1 Answers

Have you tried the -wrap option to ld when you link your executable? It should redirect the symbol so that all calls to the original function, including those inside libraries, will go to your replacement.

See this example.

[Edit: The above commenter is correct in pointing out that if the library inlined calls to memcpy, you have no recourse short of rebuilding the library.]

like image 131
user47559 Avatar answered Nov 09 '22 12:11

user47559