How to find the program argcand argvof the shared object? I am writing a library in C that will be loaded through LD_PRELOAD. I managed to find the stack in two different ways:
argc
argv
LD_PRELOAD
rsp
__asm__
/proc/<pid>/maps
Then I can create a pointer, point it to the stack segment, and then repeat the data search. The problem is that I cannot find an effective way to determine what bytes are argc, and a pointer to a pointer to a string argv.
I know it /proc/<pid>/cmdlinealso contains arguments, each of which is separate 0x00, but I am interested in finding everything in memory.
/proc/<pid>/cmdline
0x00
In gdb, I see a DWORDfor argcfollowed by QWORD, which is the first pointer. 20 bytes before the address argcis a pointer that points to a segment of the main program code. But this is not a deterministic way to identify argcand argv.
DWORD
QWORD
I saw some posts, but not working code:
, ( Gnu/Linux ), LD_PRELOAD.
; :
int foo(int argc, char **argv, char **env) { // Do something with argc, argv (and env, if desired) }
.init_array:
.init_array
__attribute__((section(".init_array"))) static void *foo_constructor = &foo;
, LD_PRELOADing , , foo, , argc argv, main ( environ).
foo
main
environ
, , /proc/<pid>/cmdline, C (, ).
, (fx main) , (fx x86-64). , , main , - , , , .
, , main, /. , (, -, main ).
, , , , , , , CRT (, , ).
argv argc , CRT (Microsoft CRT , GNU AFAIK).
, , , GCC init CRT, argv argc -, . , , , CRT- (fx ).
Source: https://habr.com/ru/post/1625255/More articles:How to add sample list type code to XML comments? - c #How does the java compiler assign an index to a local variable table? - javaAssignment of parameters. Automatically using the UseJwtBearerAuthentication function - asp.net-coreIs uWSGI master process useful for Heroku? - pythonPOST file with other form data using HttpURLConnection - androidGet servlet init parameters in servlet context listener - servletsЯвляется ли присваивание эквивалентным загрузке/хранению для std:: atomic - c++Visual Studio 2015: Enabling MSTest Magazine - DebuggingФоновое изображение не работает в Ionic/Javascript/Angular - javascriptHow to pass password from file to mysql command? - unixAll Articles