特定应用程序无法识别DLL入口点

时间:2014-02-09 23:29:57

标签: c dll native

我有些奇怪......

我正在尝试为旧游戏(基于LithTech引擎,放弃软件,Windows 98应用程序)执行代理DLL,因此我使用了wrappit,制作了DLL,使其编译,但是......嗯...... / p>

DLL本身似乎没问题。当使用OllyDbg的LOADDLL进行测试时,至少会执行DllMain ...

但是当我将其插入游戏文件夹而不是原始DLL时,它会加载DLL,然后它不会执行DLL入口点DllMain!在某些版本(Visual Studio 2005)中,它什么也没说。在其他版本(Visual Studio 2010)中,它会引发c0000139异常(即“未找到入口点”)。但是如果在ollydbg中使用LOADDLL加载时没有找到入口点,这意味着入口oint到位了吗?

请帮助我!

UPD: 发布dumpbin / exports输出:

原始DLL:

Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file IMUSIC25_.DLL

File Type: DLL

  Section contains the following exports for IMUSIC25.DLL

    00000000 characteristics
    33713027 time date stamp Thu May 08 05:45:11 1997
        0.00 version
           1 ordinal base
          29 number of functions
          29 number of names

    ordinal hint RVA      name

          6    0 0000FD8B DllCanUnloadNow
          7    1 0000FDF9 DllGetClassObject
          8    2 0000FD85 DllRegisterServer
          9    3 0000FD88 DllUnregisterServer
          1    4 000105BD _AllocAAEngine2@8
          2    5 00010507 _AllocAAEngine@4
          3    6 00007101 _AllocAALoader@4
          4    7 000074FC _AllocAALoaderLite@4
          5    8 00010675 _AllocAAMIDIIn@4
         10    9 000106A1 _GetFinalMIDISink@4
         11    A 0001127F _LoadBandFile@12
         12    B 000115F9 _LoadMotifFile@12
         13    C 00011601 _LoadPatternFile@12
         14    D 0001123C _LoadPersonalityByName@12
         15    E 000111F9 _LoadPersonalityFile@12
         16    F 000118F7 _LoadPersonalityFromMemory@12
         17   10 0001131E _LoadSectionFile@12
         18   11 000114BB _LoadSongFile@12
         19   12 000111B6 _LoadStyleByName@12
         20   13 00011173 _LoadStyleFile@12
         21   14 0001182C _LoadStyleFromMemory@12
         22   15 0001155A _LoadTemplateFile@12
         23   16 000102B1 _MusicEngineSimpleInit95@12
         24   17 00010497 _MusicEngineSimpleInit@12
         25   18 00010066 _MusicEngineSimpleInitNT@12
         26   19 000119C2 _Panic@4
         27   1A 00011465 _SaveSectionAsMIDIFile@8
         28   1B 000113E1 _SaveSectionFile@8
         29   1C 00010692 _SetAADebug@4

  Summary

        4000 .data
        1000 .idata
        1000 .rdata
        2000 .reloc
        1000 .rsrc
       1B000 .text

我制作的DLL:

Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file IMUSIC25.DLL

File Type: DLL

  Section contains the following exports for imusic25.dll

    00000000 characteristics
    52F816DB time date stamp Mon Feb 10 04:01:31 2014
        0.00 version
           1 ordinal base
          30 number of functions
          30 number of names

    ordinal hint RVA      name

          6    0 00001020 DllCanUnloadNow = ___E__0__@0
          7    1 00001030 DllGetClassObject = ___E__1__@0
          8    2 00001040 DllRegisterServer = ___E__2__@0
          9    3 00001050 DllUnregisterServer = ___E__3__@0
          2    4 00001060 _AllocAAEngine = ___E__5__@0
          1    5 00001130 _AllocAAEngine2 = ___E__4__@0
          3    6 00001070 _AllocAALoader = ___E__6__@0
          4    7 00001080 _AllocAALoaderLite = ___E__7__@0
          5    8 00001090 _AllocAAMIDIIn = ___E__8__@0
         30    9 00001000 _DllMain@12 = _DllMain@12
         10    A 000010A0 _GetFinalMIDISink = ___E__9__@0
         11    B 000010B0 _LoadBandFile = ___E__10__@0
         12    C 000010C0 _LoadMotifFile = ___E__11__@0
         13    D 000010D0 _LoadPatternFile = ___E__12__@0
         14    E 000010E0 _LoadPersonalityByName = ___E__13__@0
         15    F 000010F0 _LoadPersonalityFile = ___E__14__@0
         16   10 00001100 _LoadPersonalityFromMemory = ___E__15__@0
         17   11 00001130 _LoadSectionFile = ___E__4__@0
         18   12 00001110 _LoadSongFile = ___E__17__@0
         19   13 00001120 _LoadStyleByName = ___E__18__@0
         20   14 00001130 _LoadStyleFile = ___E__4__@0
         21   15 00001150 _LoadStyleFromMemory = ___E__20__@0
         22   16 00001160 _LoadTemplateFile = ___E__21__@0
         24   17 00001180 _MusicEngineSimpleInit = ___E__23__@0
         23   18 00001170 _MusicEngineSimpleInit95 = ___E__22__@0
         25   19 00001190 _MusicEngineSimpleInitNT = ___E__24__@0
         26   1A 000011A0 _Panic = ___E__25__@0
         27   1B 000011B0 _SaveSectionAsMIDIFile = ___E__26__@0
         28   1C 000011C0 _SaveSectionFile = ___E__27__@0
         29   1D 000011D0 _SetAADebug = ___E__28__@0

  Summary

        1000 .data
        1000 .rdata
        1000 .rsrc
        1000 .text

UPD:我在失败的LoadLibraryA调用上检查了“GetLastError” - 它是0x1E7(487) - ERROR_INVALID_ADDRESS

1 个答案:

答案 0 :(得分:0)

好吧,我设法通过更改函数的定义并使它们像原始函数一样来解决这个问题。

为此,您需要将函数类型设置为WINAPI(实际上它是__stdcall,但似乎编译器/链接器以某种方式区分它们?因为__stdcall和WINAPI之间的重整行为不同)并定义函数参数 - 您可以从受损名称的最后一部分计算所需数量(实际上不存在于DEF文件中的DLL):@ 4表示一个4字节大小的参数(例如 - int),@ 8表示两个,如果你正在使用wrappit生成的函数,你甚至不需要知道哪个是参数类型 - 你只需要调整大小以使修正更正确。

接下来,您需要在DEF文件中定义受损名称和序数之间的关系。

根据C++ DLL Export: Decorated/Mangled names(@ wqw的答案),使用#pragma comment(linker, "/EXPORT:Function=Function@4,@1")可能有更好更简单的方法,但我还没有尝试过。

此外,我需要在项目设置中设置重定位 - 这可能是“ERROR_INVALID_ADDRESS”的原因。

案件结案。