How can I rewrite _start(entry point) of main function

Jason Yang jasonyangshadow@gmail.com
Sun Jan 19 05:05:00 GMT 2020


Dear Siddhesh Poyarekar,

Thanks so much for your help.

My case is a different one.

I use execve to run an executable, but I could not modify argv0 passed 
to main function(I use ld.so as the first arg), after execve is called, 
I do not have chance to modify argv0 passed to main function any more, 
so I want to find a cut point between execve and real main function to 
give me a chance of changing the value of argv0.

I expect to use ld_preload trick to trap or overwrite some functions in 
order to change values. Can I do that?

On 2020/01/19 13:31, Siddhesh Poyarekar wrote:
> (redirecting to libc-help)
>
> On 18/01/20 8:35 pm, Jason Yang wrote:
>> Dear developers:
>>
>> I have a demand that changing the argv array passed to main function
>> after execve syscall. I knew that _start or even __libc_start_main are
>> called before user's main function is called. Can I use LD_PRELOAD
>> tricks to overwrite _start or any other functions in order for the
>> modifications of argv before user's main function is called?
>>
>>
>> Thanks so much! Looking forward your responses!
> You can use constructors to run code before main() executes.  Basically
> implement a function with __attribute__((constructor)):
>
> https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html
>
> Siddhesh



More information about the Libc-help mailing list