2013-09-22 305 views
0

我尝试使用内联汇编插入JMP指令,但我得到一个错误说:C++内联汇编错误

“预期的表达”

// Allocate a place in memory for the bytes 
BYTE *jmp = (BYTE*)malloc(len + 5); 

// Copy the bytes of original + length to the allocated memory place: 
memcpy(jmp, orig, len); 

// Next we want to insert a jump back to the original + length 
jmp += len; // increment to the end of the copied bytes 
jmp[0] = _asm JMP // this is where i get the error 

*(DWORD*)(jmp + 1) = (DWORD)(orig + len - jmp) - 5; 

我是新来组装和想以另一种方式了解实现这一目标的方法。

回答

1
jmp[0] = _asm JMP 

永远不能作为JMP操作码(占本指令字节(S))的工作依赖于操作(参数指令)。请参阅英特尔®64和IA-32架构软件开发人员手册中的Vol. 2A 3-433

看起来好像是在JMP rel32之后,在这种情况下,您应该用0xE9代替_asm JMP

欲了解更多信息,我建议在网络上的x86指令编码链接的英特尔文件或其他许多来源之一。例如。 this one from osdev wiki