使用mingw构建64位dll以与rundll一起使用

时间:2012-08-15 12:27:25

标签: gcc dll 64-bit mingw rundll32

我目前正在尝试将我的项目更新为64位支持。该项目用于使用i686-w64-mingw32工具链构建一个32位dll,可以与rundll一起使用来启动它。

现在,我试图使用x86_64-w64-mingw32工具链来构建它的64位版本。编译时我也使用-m64。 DLL可以构建和链接甚至执行。但是当我在windbg中检查结果时我得到了奇怪的结果(参见下面的输出)。看起来它将我的mmbbq.dll加载到32位地址空间。它还加载某些依赖项的32位版本。我们可以通过在加载模块时查看基址来查看输出。它首先加载一些64位dll(可能是rundll依赖)。然后它开始加载32位的东西,最后我的64位dll以32位模式的形式。有趣的是,当我检查它的PE头时,我的DLL是64位版本。

对此行为的任何解释或我可能搞砸了什么,或者我只是误解了输出?我认为基址应该看起来与64位模式不同。

CommandLine: C:\Windows\SysWOW64\rundll32.exe mmbbq.dll rundll_inject
Starting directory: E:\cygwin\home\will\praty\reversing\mmbbq\dist  
Symbol search path is: SRV*c:\symbols*http://msdl.microsoft.com/download/symbols
Executable search path is: 
ModLoad: 00000000`00530000 00000000`0053e000   rundll32.exe
ModLoad: 00000000`779a0000 00000000`77b49000   ntdll.dll
ModLoad: 00000000`77b80000 00000000`77d00000   ntdll32.dll
ModLoad: 00000000`75200000 00000000`7523f000   C:\Windows\SYSTEM32\wow64.dll
ModLoad: 00000000`751a0000 00000000`751fc000   C:\Windows\SYSTEM32\wow64win.dll
ModLoad: 00000000`75190000 00000000`75198000   C:\Windows\SYSTEM32\wow64cpu.dll
(1870.1660): Break instruction exception - code 80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00000000`77a4cb60 cc              int     3
0:000> g
ModLoad: 00000000`77720000 00000000`7783f000   WOW64_IMAGE_SECTION
ModLoad: 00000000`76ce0000 00000000`76df0000   WOW64_IMAGE_SECTION
ModLoad: 00000000`77720000 00000000`7783f000   NOT_AN_IMAGE
ModLoad: 00000000`77620000 00000000`7771a000   NOT_AN_IMAGE
ModLoad: 00000000`76ce0000 00000000`76df0000   C:\Windows\syswow64\kernel32.dll
ModLoad: 00000000`76c30000 00000000`76c76000   C:\Windows\syswow64\KERNELBASE.dll
ModLoad: 00000000`75520000 00000000`75620000   C:\Windows\syswow64\USER32.dll
ModLoad: 00000000`75620000 00000000`756b0000   C:\Windows\syswow64\GDI32.dll
ModLoad: 00000000`76330000 00000000`7633a000   C:\Windows\syswow64\LPK.dll
ModLoad: 00000000`77220000 00000000`772bd000   C:\Windows\syswow64\USP10.dll
ModLoad: 00000000`77170000 00000000`7721c000   C:\Windows\syswow64\msvcrt.dll
ModLoad: 00000000`76b90000 00000000`76c30000   C:\Windows\syswow64\ADVAPI32.dll
ModLoad: 00000000`76ae0000 00000000`76af9000   C:\Windows\SysWOW64\sechost.dll
ModLoad: 00000000`764a0000 00000000`76590000   C:\Windows\syswow64\RPCRT4.dll
ModLoad: 00000000`75260000 00000000`752c0000   C:\Windows\syswow64\SspiCli.dll
ModLoad: 00000000`75250000 00000000`7525c000   C:\Windows\syswow64\CRYPTBASE.dll
ModLoad: 00000000`756b0000 00000000`756da000   C:\Windows\syswow64\imagehlp.dll
(1870.1660): WOW64 breakpoint - code 4000001f (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
ntdll32!LdrpDoDebuggerBreak+0x2c:
77c20fab cc              int     3
0:000:x86> g
ModLoad: 72cb0000 72cfc000   C:\Windows\SysWOW64\apphelp.dll
ModLoad: 6a090000 6a11d000   C:\Windows\AppPatch\AcLayers.DLL
ModLoad: 756e0000 7632a000   C:\Windows\syswow64\SHELL32.dll
ModLoad: 76c80000 76cd7000   C:\Windows\syswow64\SHLWAPI.dll
ModLoad: 76340000 7649c000   C:\Windows\syswow64\ole32.dll
ModLoad: 76b00000 76b8f000   C:\Windows\syswow64\OLEAUT32.dll
ModLoad: 72d80000 72d97000   C:\Windows\SysWOW64\USERENV.dll
ModLoad: 72d70000 72d7b000   C:\Windows\SysWOW64\profapi.dll
ModLoad: 75120000 75171000   C:\Windows\SysWOW64\WINSPOOL.DRV
ModLoad: 6a320000 6a332000   C:\Windows\SysWOW64\MPR.dll
ModLoad: 74970000 7497e000   C:\Windows\AppPatch\AcWow64.DLL
ModLoad: 75180000 75189000   C:\Windows\SysWOW64\VERSION.dll
ModLoad: 752f0000 75350000   C:\Windows\SysWOW64\IMM32.DLL
ModLoad: 765a0000 7666c000   C:\Windows\syswow64\MSCTF.dll
ModLoad: 6c440000 6cdf4000   mmbbq.dll
ModLoad: 00000000`6c440000 00000000\`6cdf4000   mmbbq.dll
ModLoad: 00000000`6c440000 00000000\`6cdf4000   mmbbq.dll
ModLoad: 00000000`6c440000 00000000\`6cdf4000   E:\cygwin\home\will\praty\reversing    \mmbbq\dist\mmbbq.dll
(1870.30c): Break instruction exception - code 80000003 (first chance)
ntdll!DbgBreakPoint:
00000000`779f0530 cc              int     3

更新 从System32目录使用rundll32后,它看起来更好。但我仍然困惑我的DLL加载到段“0x00000000”。这是常规的64位行为吗?

CommandLine: C:\Windows\System32\rundll32.exe "mmbbq.dll",rundll_inject 0,0,0,0
Starting directory: E:\cygwin\home\will\praty\reversing\mmbbq\dist
Symbol search path is: SRV*c:\symbols*http://msdl.microsoft.com/download/symbols
Executable search path is: 
ModLoad: 00000000`ff350000 00000000`ff35f000   rundll32.exe
ModLoad: 00000000`779a0000 00000000`77b49000   ntdll.dll
ModLoad: 00000000`77720000 00000000`7783f000   C:\Windows\system32\kernel32.dll
ModLoad: 000007fe`fe0c0000 000007fe`fe12c000   C:\Windows\system32\KERNELBASE.dll
ModLoad: 00000000`77620000 00000000`7771a000   C:\Windows\system32\USER32.dll
ModLoad: 000007fe`feb10000 000007fe`feb77000   C:\Windows\system32\GDI32.dll
ModLoad: 000007fe`fe560000 000007fe`fe56e000   C:\Windows\system32\LPK.dll
ModLoad: 000007fe`ffbe0000 000007fe`ffca9000   C:\Windows\system32\USP10.dll
ModLoad: 000007fe`fe1d0000 000007fe`fe26f000   C:\Windows\system32\msvcrt.dll
ModLoad: 000007fe`fe730000 000007fe`fe749000   C:\Windows\system32\imagehlp.dll
ModLoad: 000007fe`ffb00000 000007fe`ffbdb000   C:\Windows\system32\ADVAPI32.dll
ModLoad: 000007fe`fe690000 000007fe`fe6af000   C:\Windows\SYSTEM32\sechost.dll
ModLoad: 000007fe`fe7a0000 000007fe`fe8cd000   C:\Windows\system32\RPCRT4.dll
(1b24.1b70): Break instruction exception - code 80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00000000`77a4cb60 cc              int     3
0:000> g
ModLoad: 000007fe`fe270000 000007fe`fe29e000   C:\Windows\system32\IMM32.DLL
ModLoad: 000007fe`ff9f0000 000007fe`ffaf9000   C:\Windows\system32\MSCTF.dll
ModLoad: 00000000`6c440000 00000000`6cdf4000   mmbbq.dll
ModLoad: 00000000`6c440000 00000000`6cdf4000   mmbbq.dll
ModLoad: 00000000`6c440000 00000000`6cdf4000   mmbbq.dll
ModLoad: 00000000`6c440000 00000000`6cdf4000   E:\cygwin\home\will\praty\reversing\mmbbq\dist\mmbbq.dll
ModLoad: 00000000`77b70000 00000000`77b77000   C:\Windows\system32\PSAPI.DLL
ModLoad: 000007fe`fe6b0000 000007fe`fe721000   C:\Windows\system32\SHLWAPI.dll
ModLoad: 000007fe`fe750000 000007fe`fe79d000   C:\Windows\system32\WS2_32.dll
ModLoad: 000007fe`fe550000 000007fe`fe558000   C:\Windows\system32\NSI.dll
ModLoad: 000007fe`feb80000 000007fe`ff908000   C:\Windows\system32\shell32.dll

1 个答案:

答案 0 :(得分:2)

您正在运行c:\Windows\syswow64\rundll32.exe这是您要运行的{32}版rundll32.exe {。}}。

您正在启动一个32位进程,可以从所有syswow64模块和c:\windows\system32\rundll32.exe提示符中看到。