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