Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is what I learnt today.
- //Credits: http://stackoverflow.com/questions/10264512/asssembly-base-pointer-and-stack-pointer
- #include <Windows.h>
- #include <iostream>
- int inc = 0;
- int timesrun = 555;
- /*
- What it looks like after the stack frame is setup
- +-------------+
- | Parameter 2 | <-- [ebp + 12]
- +-------------+
- | Parameter 1 | <-- [ebp + 8]
- +-------------+
- | Return Addr | <-- [ebp + 4]
- +-------------+
- | saved ebp | <-- ebp
- +-------------+ <-- esp
- */
- void twoargs()
- {
- void* basePtr;
- __asm mov basePtr, ebp;
- /*If you make this a pointer and dereference it, it'll make int main() run |timesrun| amount of times*/
- DWORD* retnaddr = (DWORD*)((DWORD)basePtr+ 0x4); //Return address of twoargs()
- //Example: DWORD* retnaddr = (DWORD*)(*(DWORD*)basePtr+ 0x4); // Return address of main()
- if (timesrun > 1)
- {
- timesrun -= 1;
- *retnaddr -= 0x5; //Move it back to ebp - 0x1
- }
- inc++;
- }
- int main()
- {
- int expected = timesrun;
- twoargs();
- printf("%i\nexpected output: %i", inc, expected);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment