MinGW编译ollydbg插件问题

11 views
Skip to first unread message

lynnux

unread,
Nov 19, 2014, 7:33:35 AM11/19/14
to chi...@googlegroups.com
我在写一个ollydbg1.1的插件,但是用MinGW编译在link的时候死活链接不上。
不知道是不是link exe的问题,因为OD的插件最终会import ollydbg.exe上的函数。

网上搜索了下,发现xunxun大哥编译windows平台上的带dragonegg插件就用到了link exe——我在https://code.google.com/p/pcxllvm/downloads/detail?name=Dragonegg_MinGW64CRT_gcc4.6.1_win32.7z&can=1&q= 下了一个看,比如dragonegg-cc1.dll导入表里确实是引入了cc1.exe的导出函数。所以这里也特别请教下xunxun大哥,这是如何做到的?

lynnux

unread,
Nov 19, 2014, 9:04:34 AM11/19/14
to chi...@googlegroups.com
我尝试从头开始,模拟exe导出函数,然后dll去链接。发现原生的MinGW好像不行,于是下载了xunxun的-enable-plugin版本的gcc,在这里下的:http://mingw.5.n7.nabble.com/gcc-enable-plugin-experimental-built-on-windows-td14088.html 

测试生成的exe确实有导出函数,但是dll去链接就是不行:
测试代码:
-----------------------------------------------------------------------------------------------
ollydbg.cpp:
extern "C" int __cdecl  Plugingetvalue(int type)
{
return 0;
}
int main()
{
  return 0;
}
-----------------------------------------------------------------------------------------------
testdll.cpp:
extern "C" int __cdecl  Plugingetvalue(int type);
int main()
{
return Plugingetvalue(1);
}
-----------------------------------------------------------------------------------------------
makefile:
exe: obj
gcc -o ollydbg.exe ollydbg.o -Wl,--output-def,ollydbg.def,--out-implib,OLLYDBG110.a
obj:
gcc -c -o ollydbg.o -Wl,--export-all-symbols ollydbg.cpp
testdll:
gcc -o testdll.dll -shared D:\MinGW_GCC4.6.1_test\MinGW\OLLYDBG110.a testdll.cpp

错误提示:
gcc -o testdll.dll -shared D:\MinGW_GCC4.6.1_test\MinGW\OLLYDBG110.a testdll.cpp

C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKm6nLu.o:testdll.cpp:(.text+0x16): undefine
d reference to `Plugingetvalue'
collect2: ld returned 1 exit status
makefile:6: recipe for target `dll' failed
mingw32-make: *** [dll] Error 1

lynnux

unread,
Nov 19, 2014, 8:48:00 PM11/19/14
to chi...@googlegroups.com
有头绪了,在这里http://mingw.5.n7.nabble.com/Help-exporting-functions-from-an-exe-tt22444.html#a22446
这个测试就是有效的方法

lynnux

unread,
Nov 19, 2014, 9:21:53 PM11/19/14
to chi...@googlegroups.com
按照上面的方法我尝试了也不行,最后到cmake的bin目录看了下其实已经生成dll,错误提示来自一个cmake小错误(生成另一个工程却没有link OD lib),把那个错误改了用OD提供的lib就可以了——之前在看雪上有人说用MinGW没法编译ollydbg插件,他们的问题其实是在头文件上面,这个我早就解决了。

总结:MinGW链接exe导出函数是完全可以的,而用MinGW生成exe含导出函数需要加__declspec(dllexport),如果没有__declspec(dllexport)就需要patch版本的如xunxun上面提供的-enable-plugin的gcc

Reply all
Reply to author
Forward
0 new messages