Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you call a function in another address-space in C++
    primarykey
    data
    text
    <p>I'm aware of the threading issues etc that this could cause and of its dangers but I need to know how to do this for a security project I am doing at school. I need to know how to call a function in a remote address space of a given calling convention with arguments - preferably recovering the data the remote function has returned though its really not required that I do.</p> <p>If I can get specifics from the remote function's function prototype at compile time, I will be able to make this method work. I need to know how big the arguments are and if the arguments are explicitly declared as pointers or not <code>(void*, char*, int*, etc...)</code></p> <p>I.e if I define a function prototype like:</p> <pre><code>typedef void (__cdecl *testFunc_t)(int* pData); </code></pre> <p>I would need to, at compile time, get the size of arguments at least, and if I could, which ones are pointers or not. Here we are assuming the remote function is either an <code>stdcall</code> or <code>_cdecl</code> call.</p> <p>The IDE I am using is Microsoft Visual Studio 2007 in case the solution is specific to a particular product.</p> <p>Here is my plan:</p> <ol> <li><p>Create a thread in the remote process using <code>CreateRemoteThread</code> at the origin of the function want to call, though I would do so in a suspended state.</p></li> <li><p>I would setup the stack such that the return address was that of a stub of code allocated inside of the process that would call <code>ExitThread(eax)</code> - as this would exit the thread with the function's return value - I would then recover this by by using <code>GetExitCodeThread</code></p></li> <li><p>I would also copy the arguments for the function call from my local stack to that of the newly created thread - this is where I need to know if function arguments are pointers and the size of the arguments.</p></li> <li><p>Resume the thread and wait for it to exit, at which point I will return to the caller with the threads exit code.</p></li> </ol> <p>I know that this should be doable at compile time but whether the compiler has some method I can use to do it, I'm not sure. I'm also aware all this data can be easily recovered from a PDB file created after compiling the code and that the size of arguments might change if the compiler performs optimizations. I don't need to be told how dangerous this is, as I am fully aware of it, but this is not a commercial product but a small project I must do for school.</p> <p>The question: If I have a function prototype such as typedef void (__cdecl testFunc_t)(int pData); </p> <p>Is there anyway I can get the size of this prototype's arguments at compile time(i.e in the above example, the arguments would sum to a total size of sizeof(int*) If, for example, I have a function like: </p> <pre><code>template&lt;typename T&gt; unsigned long getPrototypeArgLength&lt;T&gt;() { //would return size of arguments described in the prototype T } //when called as getPrototypeArgLength&lt;testFunc&gt;() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload