Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow

    Detouring a single instruction?

    Ohai guise.

    So... I have this single instruction.

    Code:
    mov [esi+0x154],edi
    I need to change what is written to ESI+0x154, the problem is ESI is dynamic. Now, I had a couple of ideas but obviously they didn't get me far otherwise I wouldn't be making this thread.

    Any suggestions on how to retrieve the contents of ESI without having to set a breakpoint on it? As the title says, I was thinking about a detour, but it isn't a function so I wouldn't get how that would work. I was also thinking of just having an instruction to call my own function but I have no idea where to begin.

    Bare with me, I'm terrible at memory hacking and just getting the basics. I didn't put this in the assembly/reversing section 'cause I want to code this in C++ and hoping some of you could lend me a hand.

    So guise, any suggestions?

  2. The Following User Says Thank You to Void For This Useful Post:

    therofl (11-02-2010)

  3. #2
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    Allocate some memory, relocate a couple instructions near where you're placing the detour and place it in the allocated memory to make room for a long jump or for a push and ret instruction(assuming you're performing an absolute jump to the allocated memory.) After the relocated instructions place a call to a naked routine(no epi\sublog) in your injected code. Have this code log whatever ESI is, then do an absolute jump to return. Also, make sure this memory region has executable flags set for it.

    You could also do calls instead of jumps, which would be much easier.

    IMHO, That's way overkill, just use a hardware breakpoint and install a vectored exception handler(make sure yours is first in the chain..)
    Last edited by radnomguywfq3; 06-11-2010 at 06:14 PM.

  4. The Following 4 Users Say Thank You to radnomguywfq3 For This Useful Post:

    Obama (06-11-2010),therofl (11-02-2010),Void (06-12-2010),why06 (06-11-2010)

  5. #3
    Obama's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    The Black house
    Posts
    22,195
    Reputation
    870
    Thanks
    6,076
    My Mood
    Cool
    Quote Originally Posted by Jetamay View Post
    Allocate some memory, relocate a couple instructions near where you're placing the detour and place it in the allocated memory to make room for a long jump or for a push and ret instruction(assuming you're performing an absolute jump to the allocated memory.) After the relocated instructions place a call to a naked routine(no epi\sublog) in your injected code. Have this code log whatever ESI is, then do an absolute jump to return. Also, make sure this memory region has executable flags set for it.

    You could also do calls instead of jumps, which would be much easier.

    IMHO, That's way overkill, just use a hardware breakpoint and install a vectored exception handler(make sure yours is first in the chain..)
    The master returns D:

  6. #4
    scimmyboy's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Location
    https://mpgh.net MPGHCash: $442,596,199
    Posts
    5,645
    Reputation
    26
    Thanks
    896
    My Mood
    Happy
    omg jetamay can speak binary xD

  7. #5
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Hit me on msn I have hw breakpoint shizzle for u ^^
    Ah we-a blaze the fyah, make it bun dem!

  8. #6
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    I tried that vectored exception handling, shit.... as soon as it get to my handler shit starts failing epicly for unknown reasons? all I know is if I return Continue search I only get two iterations, but if I call COntinue execution I get more, but my exception I wanted to handle is still never handled. Im injecting my exception handler, so I don't know if that's having issues or what... I also heard there's only certain function u can call in an exception handler.
    Code:
    LONG CALLBACK ExceptionHandler( EXCEPTION_POINTERS* e )
    {
    
        if( e->ExceptionRecord->ExceptionCode != EXCEPTION_SINGLE_STEP )
        {
    		e->ContextRecord->EFlags |= (1 << 16);
            return EXCEPTION_CONTINUE_SEARCH;
        }
    	
    
        Context_t *Context = GContextHook.GetContextInfo();
    	
    	//this code is never entered.
        if( Context )
        {
    
            if( e->ExceptionRecord->ExceptionAddress == ( PVOID )Context->Hook1 ||
                e->ExceptionRecord->ExceptionAddress == ( PVOID )Context->Hook2 ||
                e->ExceptionRecord->ExceptionAddress == ( PVOID )Context->Hook3 ||
                e->ExceptionRecord->ExceptionAddress == ( PVOID )Context->Hook4 )
            {
                oCHandler Handler = GContextHook.GetHandlerInfo(); //whatever ur personal handler is gonna be
    			
                if( Handler )
                {
                    Handler( Context, e ); // will call ur handler now using the Context_t class
                }
    
                return EXCEPTION_CONTINUE_EXECUTION;
            }
        }
        return EXCEPTION_CONTINUE_SEARCH;
    }

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  9. #7
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Thanks guys.

    Jetamay, I believe I've tried your method but I just keep getting errors ( not compiling errors ). Hardcoding has always been really hard for me.

    I've tried allocating memory, jumping to it, place the original instruction there and return back, just to test if the jump would work, and it wouldn't work at all. Mind giving me a small example of how you would go about it?

  10. The Following User Says Thank You to Void For This Useful Post:

    therofl (11-02-2010)

  11. #8
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    Void, what's the problem? Do you have any description of the exception being thrown, and is your target protected?

    Make sure after you've inserted your call and nops, that all the instructions are aligned and that none have been overwritten(other than the once you've relocated ofc).

    Can you show me what you've got in your naked routine?

  12. #9
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by Jetamay View Post
    Can you show me what you've got in your naked routine?
    David, with that he means code, not you doing scary stuff without clothes infront of your PC.
    Ah we-a blaze the fyah, make it bun dem!

  13. The Following User Says Thank You to Hell_Demon For This Useful Post:

    why06 (06-12-2010)

  14. #10
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    I haven't got anything coded yet, I was busy all day and yesterday I was failing horribly. Seeing as I'm not able to do this even with you're guys' guidance I guess I should look more into this subject before attempting this.

    And yes Wesley, I know that..

  15. #11
    shad0w''s Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    27
    Reputation
    12
    Thanks
    13
    Find the pointer to ESI, everything mentioned above is beyond overkill.
    Last edited by shad0w'; 06-15-2010 at 05:17 AM.
    [IMG]https://i234.photobucke*****m/albums/ee320/silent712/Shad0w1-1.png[/IMG]

  16. #12
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    ESI is a register not an address..

  17. The Following User Says Thank You to Void For This Useful Post:

    therofl (11-02-2010)

  18. #13
    shad0w''s Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    27
    Reputation
    12
    Thanks
    13
    Quote Originally Posted by Void View Post
    ESI is a register not an address..
    ESI is probably holding a pValue.

    Every class has a pointer set dynamically to it once initialised for the processor to copy it to the next segment.

    I understand that ESI is a register, trust me. However you must understand that ESI isn't any old register it's actually a source index that point's to data.

    FYI, In the assembly you posted; a string is being copied or will be copied (Probably).

    EDIT: Perhaps if you were to post more of the assembly than one instruction I/Others could be of more help
    Last edited by shad0w'; 06-16-2010 at 12:37 AM.
    [IMG]https://i234.photobucke*****m/albums/ee320/silent712/Shad0w1-1.png[/IMG]

  19. The Following User Says Thank You to shad0w' For This Useful Post:

    therofl (11-02-2010)

  20. #14
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    Quote Originally Posted by shad0w' View Post
    ESI is probably holding a pValue.

    Every class has a pointer set dynamically to it once initialised for the processor to copy it to the next segment.

    I understand that ESI is a register, trust me. However you must understand that ESI isn't any old register it's actually a source index that point's to data.

    FYI, In the assembly you posted; a string is being copied or will be copied (Probably).

    EDIT: Perhaps if you were to post more of the assembly than one instruction I/Others could be of more help
    You said "Find the pointer to esi". A pointer is something which points to a point in your RAM. Since ESI isn't located anywhere in memory(except on the processor), we cannot 'point' to it. If you wan't to get REALLY technical though, windows does save the registers on a temporary stack while switching between threads, but you still cannot point to this from a usermode application. Whether you write or copy to\from this register is held in the object-code constructing the instruction being executed.

    Also, a pointer to a register would be completely useless because the register changes like a million times in a single second. You'd have no way of determining what it's been pointing to after the first change.

  21. The Following 3 Users Say Thank You to radnomguywfq3 For This Useful Post:

    Hell_Demon (06-16-2010),therofl (11-02-2010),why06 (06-16-2010)

  22. #15
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    if there was ever any doubt that settled it. Sometimes its better to just admit ur wrong, arguing little points like this detours the conversation. As is usually the outcome when trying to get technical, with other technical people.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  23. The Following User Says Thank You to why06 For This Useful Post:

    Hell_Demon (06-16-2010)

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 11
    Last Post: 02-18-2008, 12:23 PM
  2. coding detour?
    By laserdude45 in forum C++/C Programming
    Replies: 3
    Last Post: 01-20-2008, 03:11 PM
  3. just ask for instructions stupids
    By loopdedoo1 in forum WarRock Korea Hacks
    Replies: 3
    Last Post: 06-08-2007, 04:44 PM
  4. a private trainer that dosnt have instructions
    By killerwpn8 in forum WarRock - International Hacks
    Replies: 0
    Last Post: 04-02-2007, 11:36 PM