Three methods to print the return address value of the main function (old EIP) (usage, you know !)

Source: Internet
Author: User

Here, we can simply modify the return address of any function, and customize the EIP point to execute any commands of the current process space. Here, we just make everyone better aware of the stack frame structure, there are no Inline hooks related to cross-process operations. Later, we will explain how to read any process memory and modify the execution process of any process function.

If you don't talk much about it, just serve it directly:


# Include <stdio. h> # include <windows. h>/* print the return address value of the main function (usage, you know !) Required knowledge: function stack frame structure C call convention, push argv push argc call main from right to left, JMP mainmain: Push EBP mov EBP, esp sub ESP, 0x4; 0x4 = sum (sizeof (type) * count) STACK: argv argc; new EBP + 8 EIP; main RET address = new EBP + 4 EBP; old EBP value, new EBP postation I; I local variable = new EBP-4 */INT main (INT argc, char * argv []) {int I = 0; // EBP-4 _ ASM {mov eax, [EBP + 4] mov I, eax} printf ("% 08x \ n", I ); printf ("% P \ n", * (DWORD *) (DWORD) & argc)-4); printf ("% P \ n ", * (DWORD *) (DWORD) & I) + 8); Return 0 ;}


See the following debugging diagram at a Glance:




Three methods to print the return address value of the main function (old EIP) (usage, you know !)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.