简体   繁体   English

将struct参数传递给CreateThread()而不接收char *变量

[英]Passing struct argument to CreateThread() and not receiving char* variable

I'm reflectively injecting a dll into another processes's memory, and I need to call CreateThread() obviously. 我将dll反射性地注入另一个进程的内存中,并且显然需要调用CreateThread()。 I'm passing certain parameters to the dll that I'm injecting using my loader_data struct. 我正在使用loader_data结构将某些参数传递给要注入的dll。 I have certain variables I need to pass such as sizes of a chunk of memory, etc. These all get delivered to my injected dll successfully, however when passing a char* into my struct it ends up as empty to my injected dll in the reserved parameter of DllMain. 我有一些需要传递的变量,例如一块内存的大小等。所有这些变量都已成功传递到注入的dll,但是当将char *传递到我的结构中时,对于保留的注入的dll最终为空DllMain的参数。

loader_data_t *parameter = new loader_data_t();
... initialize variables.

lpRemoteLibraryBuffer3 = VirtualAllocEx(proc, NULL, sizeof(loader_data_t), MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);

WriteProcessMemory(proc, lpRemoteLibraryBuffer3, parameter, sizeof(loader_data_t), NULL);

That's how I'm allocating space for the parameter. 这就是我为参数分配空间的方式。

typedef struct loader_data_t {
    char *chunk;
    int chunk_size;
    ULONG_PTR reloc_address;
};

And that is the struct that I'm passing. 这就是我要传递的结构。 I'm definitely initializing it correctly, I've checked to make sure that everything is getting set correctly. 我肯定正确地对其进行了初始化,已经检查以确保所有设置都正确。 However, when it gets passed to the reserved parameter in DllMain, all other variables are correct except the char* chunk variable. 但是,当它传递给DllMain中的保留参数时,除char * chunk变量外,所有其他变量都是正确的。 I'm really confused, excuse the possibly vague title. 我真的很困惑,请原谅可能含糊的标题。

Assuming you set 'chunk' in the initialize data code then the pointer in the remote address space will be referencing the address in the local process. 假设您在初始化数据代码中设置了“块”,那么远程地址空间中的指针将引用本地进程中的地址。

The easy way to get around this would be to make chunk an array (probably the last member of the struct) and allocate a block large enough to hold chunk's data. 解决此问题的简单方法是使块成为数组(可能是结构的最后一个成员)并分配一个足以容纳块数据的块。

More complicated would be to allocate a second block in the remote process for chunk's data, copy the data to that block write that address to the local instance's chunk member and only then write the local struct to the remote process. 更复杂的是在远程进程中为块的数据分配第二个块,将数据复制到该块,然后将该地址写入本地实例的块成员,然后再将本地结构写入远程进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM