From da81ba5be8fbc1231a47d7dcc7bea2d467c1a80e Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 26 Oct 2021 19:03:03 +0200 Subject: Fixed some program (like the one made in rust) that was getting the command line properly --- src/emu/x64run_private.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/emu/x64run_private.c b/src/emu/x64run_private.c index 1939807f..6c2e5bc1 100755 --- a/src/emu/x64run_private.c +++ b/src/emu/x64run_private.c @@ -32,14 +32,21 @@ int32_t EXPORT my___libc_start_main(x64emu_t* emu, int *(main) (int, char * *, c { (void)argc; (void)ubp_av; (void)fini; (void)rtld_fini; (void)stack_end; - // let's cheat and set all args... if(init) { + Push64(emu, GetRBP(emu)); // set frame pointer + SetRBP(emu, GetRSP(emu)); // save RSP + SetRSP(emu, GetRSP(emu)&~0xFLL); // Align RSP PushExit(emu); + SetRDX(emu, (uint64_t)my_context->envv); + SetRSI(emu, (uint64_t)my_context->argv); + SetRDI(emu, (uint64_t)my_context->argc); R_RIP=(uint64_t)*init; printf_log(LOG_DEBUG, "Calling init(%p) from __libc_start_main\n", *init); DynaRun(emu); if(emu->error) // any error, don't bother with more return 0; + SetRSP(emu, GetRBP(emu)); // restore RSP + SetRBP(emu, Pop64(emu)); // restore RBP emu->quit = 0; } printf_log(LOG_DEBUG, "Transfert to main(%d, %p, %p)=>%p from __libc_start_main\n", my_context->argc, my_context->argv, my_context->envv, main); -- cgit 1.4.1