1.1.3-Constructing Assembly statements

Source: Internet
Author: User

Recently intends to "old code to know the way" to do it again, the first to take the structure of the assembly sentence surgery.

1.1.3

Embed assembly statements in the C language to construct machine instructions for MOV and JMP, allowing the program to run at its own specified path.

See Code:

1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4 5 intgi;6 void*address;7 8 void*Buildcode ();9 Ten intMain () { One     void*code=Buildcode (); A _asm { - mov address,offset _lb1 -     } theGi= A; -printf"gi=%d\n", GI); - _asm jmp Code -Gi= -; + _LB1: -printf"gi=%d\n", GI);//Output + GetChar (); A     return 0; at } - void*Buildcode () { -     Char*code= (Char*)malloc( -); -     Char*pmov=Code; -     Char*pjmp=code+Ten; -     Char*paddress; in     //mov gi,18 -pmov[0]=0xc7; topmov[1]=0x05; +paddress=pmov+2; -*((int*) paddress) = (int) &gi; the*((int*) (paddress+4))= -; *     //JMP Address $pjmp[0]=0xFF;Panax Notoginsengpjmp[1]=0x25; -*((int*) (&pjmp[2]))=(int) &address; the     returnCode; +}

Buildcode () is to construct a two-sentence assembly instruction at code, which runs the code at _LB1, outputting 18.

Disassembly View Code:

The code was constructed successfully.

1.1.3-Constructing Assembly statements

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.