想用BeaEngine的反汇编引擎做一些工作,从官方网站上下载了相关的包,官网上提供的例子,为使用.lib的静态编译方法,源码如下:
#include <stdio.h>
#include <string.h>
#define BEA_ENGINE_STATIC /* specify the usage of a static version of BeaEngine */
#define BEA_USE_STDCALL /* specify the usage of a stdcall version of BeaEngine */
#include "BeaEngine.h"
int main(int argc, char* argv [])
{
/* ============================= Init datas */
DISASM MyDisasm;
int len, i = 0;
int Error = 0;
// 出错
if (! fRunTimeLinkSuccess)
printf("error; %u\n",GetLastError());
MyDisasm.EIP = (UIntPtr) &main;
/* ============================= Loop for Disasm */
while ((!Error) && (i<20))
{
len = Disasm(&MyDisasm);
if (len != UNKNOWN_OPCODE) {
(void) puts(MyDisasm.CompleteInstr);
MyDisasm.EIP = MyDisasm.EIP + (UIntPtr)len;
i++;
}
else {
Error = 1;
}
};
}
问题是:LoadLibrary能够加载BeaEngine.dll,GetProcAddress能够获得_BeaEngineRevision@0和_Disasm@4的地址,前者的查看版本信息的调用能够正常,但是运行到如下代码,总是会显示XXXX地址内存访问冲突~,其中的XXXX为GetProcAddress获得的DLL中导出函数_Disasm@4的地址。。。
len = Disasm(&MyDisasm);