1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Reading from registers

Discussion in 'C++' started by fireup6, Aug 28, 2010.

  1. fireup6

    fireup6 New Member

    Aug 28, 2010
    Likes Received:
    Trophy Points:
    I'm coding a dll which i am injecting into a target process. This dll patches some code to intercept some function calls before they happen, and i need to read whats in the registers and possibly modify them before i return.

    The EDX register for instance, will hold an address pointing to the first char of a string.

    Here is my current code to read the string:

    unsigned long _edx;
    char textarray[5]; //create array to store 5 chars of the string

    void Main()
    _asm{mov [_edx], edx} //save the value of EDX into an unsigned long
    char *pedx = reinterpret_cast(_edx);//create a pointer from the saved value
    for(int i = 0;i < 5; i++) {textarray = *(pedx++);}//loop through 5 chars of the string and save them into our array
    string text(textarray,5);//save our array into a string
    This code works, but I'm wondering if there are any more efficient and less troublesome ways of doing this. I've tried using GetThreadContext() which also works, but yields practically the same result with many more steps.


Share This Page