Click here to Skip to main content
15,920,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Help with a couple of C questions Pin
BadKarma28-Nov-07 3:36
BadKarma28-Nov-07 3:36 
Questionnfo Pin
john563227-Nov-07 23:24
john563227-Nov-07 23:24 
AnswerRe: nfo Pin
toxcct27-Nov-07 23:28
toxcct27-Nov-07 23:28 
GeneralOfftopic Pin
Nelek28-Nov-07 3:13
protectorNelek28-Nov-07 3:13 
GeneralRe: Offtopic Pin
toxcct28-Nov-07 3:18
toxcct28-Nov-07 3:18 
GeneralRe: Offtopic Pin
Nelek28-Nov-07 21:43
protectorNelek28-Nov-07 21:43 
GeneralRe: Offtopic Pin
toxcct28-Nov-07 21:47
toxcct28-Nov-07 21:47 
QuestionConsult the issue of Win API routine address and code injection Pin
Jude Deng27-Nov-07 23:04
Jude Deng27-Nov-07 23:04 
Hi everybody,
Could you give me the answer which concern to inject code to other process.My questions are:
[1]Must Windows API function have the same address in all process?
[2]Why would crash when a remote thread proceduer directly call Windows API function?

Now I show my code:

<br />
DWORD __stdcall RemoteThreadProc(LPVOID lParam)    <br />
{    <br />
     LoadLibraryA(NULL);   //crash!!! Why crash???<br />
     return 0;    <br />
}<br />
<br />
DWORD Inject(HANDLE hTargetProcess)<br />
{<br />
    //Compare local calling with calling in remote thread proceduer.<br />
    LoadLibraryA(NULL);	  //Ok!!!<br />
    //=======================================================<br />
<br />
    DWORD dwWriteBytes;<br />
    //The size of thread procedure code. Estimated it.<br />
    DWORD dwThreadSize = 5000;	<br />
<br />
    //Allocate memory in another process space<br />
    void* pRemoteThread = VirtualAllocEx(hTargetProcess, 0, <br />
        dwThreadSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);<br />
<br />
    //Write thread procedure code to target process.<br />
    if (!WriteProcessMemory(hTargetProcess, pRemoteThread, <br />
        RemoteThreadProc, dwThreadSize, 0)) {<br />
        //Failed!!!<br />
        return 0;<br />
    }<br />
<br />
    //Create remote thread<br />
    HANDLE hRemoteThread = CreateRemoteThread(<br />
        hTargetProcess, NULL, 0, (DWORD (__stdcall *)(void *))pRemoteThread,<br />
        NULL, 0, &dwWriteBytes);<br />
<br />
    if (!hRemoteThread) {<br />
        //Failed!!!<br />
        return -1;<br />
    }<br />
    <br />
    return 1; //Successfully<br />
}<br />
//============================================<br />
//Base on WinsowsXP sp2 、VC6.0 <br />
//============================================<br />


As far as known, Windows API function have same address in all process, but I can`t make sure it. For example, the address of "LoadLibraryA" is 0x7c801d77 in some process which I tested.[I get the address by printf(TEXT("%x"), LoadLibraryA ); ].
If Winsows API function have same address in all process, there are no reason to crash when the remote thread proceduer call API function .

Please give me an answer or an illumination.
Thank you.
AnswerRe: Consult the issue of Win API routine address and code injection [modified] Pin
maciu202028-Nov-07 0:20
maciu202028-Nov-07 0:20 
GeneralRe: Consult the issue of Win API routine address and code injection Pin
Jude Deng28-Nov-07 14:48
Jude Deng28-Nov-07 14:48 
GeneralRe: Consult the issue of Win API routine address and code injection Pin
maciu202028-Nov-07 23:15
maciu202028-Nov-07 23:15 
QuestionRe: Consult the issue of Win API routine address and code injection Pin
David Crow29-Nov-07 2:43
David Crow29-Nov-07 2:43 
AnswerRe: Consult the issue of Win API routine address and code injection Pin
maciu202029-Nov-07 9:47
maciu202029-Nov-07 9:47 
AnswerRe: Consult the issue of Win API routine address and code injection Pin
Jude Deng29-Nov-07 13:26
Jude Deng29-Nov-07 13:26 
QuestionRe: Consult the issue of Win API routine address and code injection Pin
David Crow30-Nov-07 2:40
David Crow30-Nov-07 2:40 
QuestionOpening and reading XML files in MFC (C++) Pin
MrFloyd200927-Nov-07 23:01
MrFloyd200927-Nov-07 23:01 
AnswerRe: Opening and reading XML files in MFC (C++) Pin
toxcct27-Nov-07 23:06
toxcct27-Nov-07 23:06 
GeneralRe: Opening and reading XML files in MFC (C++) Pin
MrFloyd200927-Nov-07 23:26
MrFloyd200927-Nov-07 23:26 
GeneralRe: Opening and reading XML files in MFC (C++) Pin
ThatsAlok27-Nov-07 23:28
ThatsAlok27-Nov-07 23:28 
GeneralRe: Opening and reading XML files in MFC (C++) Pin
toxcct27-Nov-07 23:29
toxcct27-Nov-07 23:29 
AnswerRe: Opening and reading XML files in MFC (C++) Pin
Hamid_RT27-Nov-07 23:44
Hamid_RT27-Nov-07 23:44 
QuestionProbllem related to recv() function in winsock.h header fle Pin
Raghavendra Pise27-Nov-07 22:47
Raghavendra Pise27-Nov-07 22:47 
AnswerRe: Probllem related to recv() function in winsock.h header fle Pin
led mike28-Nov-07 4:53
led mike28-Nov-07 4:53 
AnswerRe: Probllem related to recv() function in winsock.h header fle Pin
Mark Salsbery28-Nov-07 5:47
Mark Salsbery28-Nov-07 5:47 
Questionhow to read event log Pin
T@su27-Nov-07 22:39
T@su27-Nov-07 22:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.