thanks for the info. You know, I didn't realize that there is usually (i guess) a large 'cave' area at the end... that is simple enough.
For any other newbies... here is what I did (this is just a random piece of code):
say we have these lines:
Code:
006B8E63 6A 00 PUSH 0
006B8E65 8D45 F8 LEA EAX, DWORD PTR SS:[EBP-8]
006B8E68 50 PUSH EAX
006B8E69 A1 C0907A00 MOV EAX, DWORD PTR DS:[7A90C0]
006B8E6E A1 C0907A00 MOV EBX, DWORD PTR DS:[7A90C0]
Now lets say I want to insert a line of code here:
Code:
006B8E63 6A 00 PUSH 0
006B8E65 8D45 F8 LEA EAX, DWORD PTR SS:[EBP-8]
<insert> B8 99000000 MOV EAX, 99
006B8E68 50 PUSH EAX
006B8E69 A1 C0907A00 MOV EAX, DWORD PTR DS:[7A90C0]
006B8E6E A1 C0907A00 MOV EBX, DWORD PTR DS:[7A90C0]
I accomplished that by moving everything between the first and last line of that segment to an empty area thusly:
1. First find an empty area... I am using ollydbg, and I simply navigated to the bottom of the code where I found a large area that looked like this:
Code:
006BEFE9 00 DB 00
006BEFEA 00 DB 00
006BEFEB 00 DB 00
006BEFEC 00 DB 00
006BEFED 00 DB 00
006BEFEE 00 DB 00
006BEFEF 00 DB 00
2. This area can be overwritten without consequences (From what I understand). So first we will overwrite this area with the lines we want to move (making sure to include the code you want to add):
Code:
006BEFE9 8D45 F8 LEA EAX, DWORD PTR SS:[EBP-8]
006BEFEC B8 99000000 MOV EAX, 99
006BEFF1 50 PUSH EAX
006BEFF2 A1 C0907A00 MOV EAX, DWORD PTR DS:[7A90C0]
3. Now, we'll replace the lines from the original segment with a statement to jump to this new segment (I'll NOP out the excess area for aesthetics):
Code:
006B8E63 6A 00 PUSH 0
006B8E65 E9 7F610000 JMP 006BEFE9
006B8E6A 90 NOP
006B8E6B 90 NOP
006B8E6C 90 NOP
006B8E6D 90 NOP
006B8E6E A1 C0907A00 MOV EBX, DWORD PTR DS:[7A90C0]
4. Finally, we'll add a jump statement at the end of the new segment to return and continue executing the last line of the original segment:
Code:
006BEFE9 8D45 F8 LEA EAX, DWORD PTR SS:[EBP-8]
006BEFEC B8 99000000 MOV EAX, 99
006BEFF1 50 PUSH EAX
006BEFF2 A1 C0907A00 MOV EAX, DWORD PTR DS:[7A90C0]
006BEFF7 E9 729EFFFF JMP 006B8E6E
5. So in summation, here is the route that the program now takes when executing the code:
Code:
006B8E63 6A 00 PUSH 0
006B8E65 E9 7F610000 JMP 006BEFE9
006BEFE9 8D45 F8 LEA EAX, DWORD PTR SS:[EBP-8]
006BEFEC B8 99000000 MOV EAX, 99
006BEFF1 50 PUSH EAX
006BEFF2 A1 C0907A00 MOV EAX, DWORD PTR DS:[7A90C0]
006BEFF7 E9 729EFFFF JMP 006B8E6E
006B8E6E A1 C0907A00 MOV EBX, DWORD PTR DS:[7A90C0]
I know that is a large rundown for such a simple concept.. but hopefully someone will find it useful.