简体   繁体   English

DLL监控

[英]DLL monitoring

Is there an application which allows me to see what is being sent to a DLL from a process? 是否有一个应用程序允许我查看从进程发送到DLL的内容?

I have a process and I have a DLL and I would like to monitor the parameters that are being sent to the functions so that I can use the DLL myself. 我有一个进程,我有一个DLL,我想监视发送到函数的参数,以便我自己可以使用DLL。

The EXPORT of the DLL is. DLL的导出是。

??0CCPCompressor@@AAE@XZ ?? 0CCPCompressor @@ AAE @ XZ
??0CCPExpandor@@AAE@XZ ?? 0CCPExpandor @@ AAE @ XZ
??1CCPCompressor@@AAE@XZ ?? 1CCPCompressor @@ AAE @ XZ
??1CCPExpandor@@AAE@XZ ?? 1CCPExpandor @@ AAE @ XZ
?Clear@CCPCompressor@@QAEHXZ ?清除@ CCPCompressor @@ QAEHXZ
?Clear@CCPExpandor@@QAEHXZ ?清除@ CCPExpandor @@ QAEHXZ
..Compress@CCPCompressor.. ..Compress @ CCPCompressor ..
..Delete@CCPCompressor.. ..Delete @ CCPCompressor ..
..Delete@CCPExpandor.. ..Delete @ CCPExpandor ..
..Expand@CCPExpandor.. ..Expand @ CCPExpandor ..
..Free@CCPCompressor.. ..Free @ CCPCompressor ..
..Free@CCPExpandor.. ..Free @ CCPExpandor ..
..Init@CCPCompressor.. ..Init @ CCPCompressor ..
..Init@CCPExpandor.. ..Init @ CCPExpandor ..
..New@CCPCompressor.. ..New @ CCPCompressor ..
..New@CCPExpandor.. ..New @ CCPExpandor ..

In general, this is a bad idea. 一般来说,这是一个坏主意。 Even if you have some set of captured parameters, without deep analysis of the DLL code you don't know what to do with those parameters and what ranges of parameters are accepted by certain methods. 即使您有一些捕获的参数集,如果没有深入分析DLL代码,您也不知道如何处理这些参数以及某些方法接受的参数范围。 Example: if I call a method DoMathOperation(Add, 1, 2), you can mimic this call, but you won't be able to do DoMathOperation(Multiply, 2, 2) as you don't know that this is possible. 示例:如果我调用方法DoMathOperation(Add,1,2),您可以模仿此调用,但是您将无法执行DoMathOperation(Multiply,2,2),因为您不知道这是可能的。

The simplest approach has been to simply relocate the original dll, and create a new dll that you make yourself, with the same exports. 最简单的方法是简单地重新定位原始dll,并使用相同的导出创建一个自己创建的新dll。 This dll would LoadLibrary the old dll from the alternate location. 这个DLL将从备用位置LoadLibrary旧的dll。

This doesn't quite apply here - the dll is exporting c++ class members which has two consequences: c++ classes have to be statically loaded as there is no c++ mechanism to 'glue' c++ function pointers (obtained via GetProcAddress) into a class instance. 这在这里不太适用 - dll导出c ++类成员,这有两个结果:c ++类必须静态加载,因为没有c ++机制将c ++函数指针(通过GetProcAddress获取)“粘合”到类实例中。

This means your shim dll would be in the unfortunate place of having to both import, and export, and identical set of symbols. 这意味着您的垫片dll将处于导入,导出和相同的符号集的不幸位置。

The only way around this is to write your shim dll in two parts: 解决这个问题的唯一方法是将你的垫片dll分为两部分:

Shim1: Shim1:

One part would get the name of the original dll, and would export the same class defintion the original dll exported: 一部分将获得原始dll的名称,并将导出原始dll导出的相同类定义:

 class __decldpec(dllexport) CCPCompressor {
  ...

Depends can crack the name decoration, or Undname.exe is distributed with Visual Studio. 取决于可以破解名称装饰,或者Undname.exe随Visual Studio一起发布。

This part would LoadLibrary() using an explicit path to shimdll2.dll located in some other folder, along with the original dll. 这部分将LoadLibrary()使用shimdll2.dll的显式路径,该路径位于其他文件夹中,以及原始dll。 GetProcAddress() would be needed to import functions exported by shimdll2.dll 导入shimdll2.dll导出的函数需要GetProcAddress()

Shim2: Shim2:

The other shim dll would be located in a folder with the dll you are trying to intercept. 另一个垫片dll将位于您试图拦截的DLL的文件夹中。 This dll would have to import the class from the original compressor dll: 这个dll必须从原始压缩器dll导入类:

class __declspec(dllimport) CCPCompressor {
  ...

You can use the dll import library made by the first dll to actually link the symbols. 您可以使用第一个dll生成的dll导入库来实际链接符号。 Then its a case of exporting functions from shim2.dll that shim1.dll will call whenever a CCPCompressor method is called. 然后是一个从shim2.dll导出函数的情况,shim1.dll将在调用CCPCompressor方法时调用。

NB. NB。 Other things: your version of the CCPCompressor class will need to have, at least, a large dummy array as you can't know from the dll exports how big the application expects the class to be (unless you happen to have an actual header file describing the class). 其他的事情:你的CCPCompressor类版本至少需要一个大的虚拟数组,因为你无法从dll中知道应用程序对类的期望有多大(除非你碰巧有一个实际的头文件)描述这个类)。


To decompose the exported names to build a class definition: Open up the Visual Studio 20XX Command Prompt from the Start > Programs > Visual Studio 20XX -> Tools menu. 要分解导出的名称以构建类定义:从“开始”>“程序”>“Visual Studio 20XX” - >“工具”菜单中打开Visual Studio 20XX命令提示符。

c:\...\VC>undname ?Clear@CCPCompressor@@QAEHXZ
Microsoft (R) C++ Name Undecorator

Undecoration of :- "?Clear@CCPCompressor@@QAEHXZ"
is :- "public: int __thiscall CCPCompressor:Clear(void)"

c:\...\VC>_

Do that for each function exported from the original dll (undname accepts some kind of text file to speed this process up) to find out how to declare a matching class def. 对从原始dll导出的每个函数执行此操作(undname接受某种文本文件以加快此过程)以找出如何声明匹配类def。

Is using detours compatible with your requirements? 是否使用与您的要求兼容的弯路

From the site: 从网站:

Overview 概观

Innovative systems research hinges on the ability to easily instrument and extend existing operating system and application functionality. 创新系统研究取决于轻松检测和扩展现有操作系统和应用程序功能的能力。 With access to appropriate source code, it is often trivial to insert new instrumentation or extensions by rebuilding the OS or application. 通过访问适当的源代码,通过重建OS或应用程序来插入新的工具或扩展通常很简单。 However, in today's world systems researchers seldom have access to all relevant source code. 但是,在今天的世界系统中,研究人员很少能够访问所有相关的源代码。

Detours is a library for instrumenting arbitrary Win32 functions on x86, x64, and IA64 machines. Detours是一个用于在x86,x64和IA64机器上检测任意Win32函数的库。 Detours intercepts Win32 functions by re-writing the in-memory code for target functions. Detours通过重写目标函数的内存代码来拦截Win32函数。 The Detours package also contains utilities to attach arbitrary DLLs and data segments (called payloads) to any Win32 binary. Detours包还包含将任意DLL和数据段(称为有效负载)附加到任何Win32二进制文件的实用程序。

Detours preserves the un-instrumented target function (callable through a trampoline) as a subroutine for use by the instrumentation. Detours保留未装备的目标函数(可通过蹦床调用)作为仪器使用的子程序。 Our trampoline design enables a large class of innovative extensions to existing binary software. 我们的蹦床设计为现有的二进制软件提供了大量创新扩展。

We have used Detours to create an automatic distributed partitioning system, to instrument and analyze the DCOM protocol stack, and to create a thunking layer for a COM-based OS API. 我们使用Detours创建了一个自动分布式分区系统,用于检测和分析DCOM协议栈,并为基于COM的OS API创建一个thunking层。 Detours is used widely within Microsoft and within the industry. Detours在微软和业内广泛使用。

The only reliable way is to debug your program (using any debugger like OllyDBG) and set breakpoint on required export function. 唯一可靠的方法是调试程序(使用任何调试器,如OllyDBG)并在所需的导出函数上设置断点。 Then you can simply trace the stack parameters sent to the calling function. 然后您可以简单地跟踪发送到调用函数的堆栈参数。 This is only the start, you need to fully analyze function instructions within a debugger or disassembler to see what each parameter is doing and its type. 这只是一个开始,您需要在调试器或反汇编程序中完全分析函数指令,以查看每个参数正在执行的操作及其类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM