- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个调用 GetOpenFileNameA 和 GetSaveFileNameA 的旧应用程序。两次调用都是错误的。应用程序崩溃!我已经使用 OllyDbg 和 API Monitor 来读取存储在 OPENFILENAME 结构中的大小。该结构的大小为 76 字节(使用 Windows 7 x64 进行测试)。调用 GetOpenFileNameA 或 GetSaveFileNameA 时出现访问冲突异常。我假设在运行时窗口试图读取 88 字节而不是 76 字节。看看这个: http://dotnetbutchering.blogspot.de/2007/10/vc-60-getting-0xc0000005-access.html还有这个 http://www.asmcommunity.net/board/index.php?topic=5768.15
我做了一些研究,同时我发现了以下行为:运行 Microsoft Spy++ 时应用程序不会崩溃!!我单步调试调试器,发现访问冲突异常仍然发生,但异常被吞没了。该应用程序工作正常!我可以加载和保存文件。
我有以下想法。你觉得他们怎么样?
写某事。就像 Loader.exe 一样,它的功能与 Spy++ 相同。在调用两个 API 时吞下访问冲突异常。
使用 DLL 注入(inject)和 API Hook 。我可以将 GetOpenFileName 和 GetSaveFileName 与自定义 DLL 中的自定义实现 Hook 。我的实现将修复该结构并将更正后的结构传递给原始 API 调用。
使用 SetWindowsHook Hook 窗口消息 ?!?!?!
修补二进制文件。是否可以通过使用 HEX 编辑器进行修补来解决此结构大小问题?
哪一个会起作用?你有更好的办法解决这个问题吗?
我无法获得这个旧应用程序的源代码。我必须使用现有的二进制文件修复它。我的解决方案必须至少适用于 Windows XP 和 Windows 7(x86、x64)
工具 PEiD 向我显示了有关旧应用程序的以下信息:链接器信息:2.55MS Visual C++ 4.0
最佳答案
The size of the struct is 76 Bytes (testing with Windows 7 x64). I get an access violation exception while GetOpenFileNameA or GetSaveFileNameA is called. I assume that at runtime windows tries to read 88 Bytes instead of 76 Bytes.
如果您查看 OPENFILENAME
struct
,您会注意到:
#if (_WIN32_WINNT >= 0x0500)
void * pvReserved;
DWORD dwReserved;
DWORD FlagsEx;
#endif // (_WIN32_WINNT >= 0x0500)
在 32 位程序中(VC++ 4 不支持 64 位目标)转换为恰好 12 字节的差异。只要调用者正确设置了 lStructSize
,这根本就不是问题。可能值得使用 Microsoft/Sysinternals 的 procdump
来获取确切状态的小型转储(或附加调试器并进行调查)。您遇到的异常不一定是由于 struct
大小造成的。如果是的话,微软很可能在向后兼容这个功能时失手了。显然 OPENFILENAME::lStructSize
用于对 struct
进行版本控制,并确保不会发生您遇到的情况。但是,我们谈论的是使用 Windows 2000 之前的编译器/链接器构建的程序。
write sth. like a Loader.exe which does the same like Spy++. Swallowing the access violation exception when both APIs are called. It's a fair point. If you would insert exception handling at the top level you could do things you want, but it may cause side-effects depending on what exactly caused the exception (i.e. which exact memory was overwritten).
Use DLL Injection and API Hooking. I could hook GetOpenFileName and GetSaveFileName with a custom implementation in a custom DLL. My implementation would fix the struct and pass the corrected struct to the original API calls. This is pretty much related to the first one. I think it will be easiest and safest in all, because this way you can correct the behavior without too much intrusion. Please read further below. Also, check out NInjectLib.
Use SetWindowsHook to hook a window message ?!?!?! I don't see how that helps other than facilitating the injection of a DLL (for 1. and 2.).
Patch the binary file. Is it possible to fix this struct size issue by patching using a HEX Editor? This may be the trickiest, depending on whether the
OPENFILENAME
is inside the binary (initialized data) or on stack or whether it gets allocated on the heap (easy then).
1. 和 2. 的一种可能的混合方法是:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
以您正在执行的程序命名(例如 foo.exe
) Debugger
的 REG_SZ
值,并将该值设置为我现在将尝试简要描述的程序。这有效地为您的这个旧应用程序设置了一个调试器,这意味着我们要编写的调试器将接收您的应用程序的命令行作为参数。它很方便,因为它对最终用户是透明的,您可以根据自己的需要进行调整。
您需要编写一个调试器。这个任务并不像最初看起来那么难,因为您可以使用 Win32 提供的调试助手。要点在调试器循环中。通常,您可以使用 CreateProcess
传递适当的标志来自行创建目标进程,以便能够对其进行调试。使用 WaitForDebugEvent
和 ContinueDebugEvent
来控制执行。出于所有实际目的,您甚至可能根本不需要调试器循环,因为您可以创建目标应用程序的主线程挂起(将 CREATE_SUSPENDED
传递给 CreateProcess
)然后指向最开始将主线程的CONTEXT
设置为自己的代码,然后调用ResumeThread(pi.hThread)
。这样你就可以在主线程启动之前完成。但是,由于 kernel32.dll
的 CreateThread
工作方式(它涉及向 Win32 子系统又名 csrss.exe< 注册新线程,这可能会导致问题
)。因此,最好在内存或类似的东西中修补目标的 IAT。毕竟您只对两个功能感兴趣。
我个人更喜欢基于来自 PaiMei 的 PyDbg
编写我的调试器,但我承认我没有尝试在 Image File Execution Options
中使用这样一个基于 Python 的调试器。
关于c++ - 替换或修改外部应用程序中的 API 调用(GetOpenFileName、GetSaveFileName),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10739312/
如何指示 webpack 排除所有 d3 模块? // does not work externals: { "d3-*": "d3" } 所以如果应用导入了d3-submod
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: What does “outer =>” really mean? 我在哪里可以找到有关信息 trait After
这是一个简单的循环,我正在尝试对性能进行基准测试。 var extremeLoop=function(n){ var time=new Date() var t=0; for(
问题+概述 下面是两个片段,其中包含最初隐藏的 div,然后通过单击 button 和 jQuery 的 .show() 显示。两个 div 都具有由外部样式表应用的 display: grid; 样
我有一个 HTML 页面和一个单独的 .js 文件,该文件包含在带有 的页面中标签。 这是我的 .js 文件: element = document.getElementById("test");
我在 linux 静态库项目中有 3 个文件,我想在两个类方法实现文件中使用的静态字段存在链接问题。我有 class1.h、class1main.cpp 和 class1utils.cpp。 clas
我正在尝试将颜色背景更改为默认背景颜色,当我点击输入框外 我尝试使用“null”或“none”但没有用? window.addEventListener('click', outsideClick);
我正在编写一个应用程序,要求用户在手机上选择各种类型的文件。我使用此代码启动文件选择器 Intent : Intent intent = new Intent(Intent.ACTION_GET_C
在 android 中,不可移动(内部)的外部存储和内部存储有什么区别?我不确定在哪里保存我的数据。我只需要保存一个人可以随时提取的游戏统计数据 谢谢 最佳答案 在许多较新的设备中,将不再有物理区别,
在 C++ 中,假设我们有这个头文件: myglobals.h #ifndef my_globals_h #define my_globals_h int monthsInYear = 12; #en
我正在尝试使用 externs 在 C++ 中连接到 Ada。这两种实现有什么区别? 实现A namespace Ada { extern "C" { int getN
这个问题在这里已经有了答案: Get selected element's outer HTML (30 个答案) 关闭 2 年前。 想象一下我们有这样的东西: Hello World 如果我们这样
假设我在模块的顶部有这个: Public Declare Function getCustomerDetails Lib "CustomerFunctions" () As Long 如果我从 VB6
我目前正在使用这段代码: var wordRandomizer = { run: function (targetElem) { var markup = this.creat
我们正在使用 SVN 试水,并以 Beanstalk 作为主机。我们的设置如下所示: 存储库:模块 模块一 模块二 模块 3 存储库:网站1 自定义网站代码 svn:对模块 1 的外部引用 svn:对
有没有办法在负载均衡器中设置自动外部 IP 分配给像谷歌这样的服务? 我在裸机上运行 Kubernetes。 谢谢 最佳答案 使用 nodePort 类型的服务,它会将您的服务绑定(bind)到所有节
是否有可能在 Controller 之外使用 generateUrl() 方法? 我尝试在带有 $this->get('router') 的自定义存储库类中使用它,但它没有用。 更新 我在这里找到了一
我目前正在尝试通过 Webpack 外部对象外部化 Angular 依赖项来缩短构建时间。到目前为止,我已经为 React 和其他小库实现了这一目标。 如果我只是移动 '@angular/compil
我想创建一个自动应用其他插件的插件(外部插件)。这要求在我称为“应用插件”之前为插件设置构建脚本依赖项。但是似乎我无法在插件中添加buildscript依赖项,或者得到了: 您不能更改处于未解析状态的
我是R包的创建者EnvStats . 有一个我经常使用的函数,叫做 stripChart .我刚开始学习ggplot2 ,并在过去几天里仔细研究了 Hadley 的书、Winston 的书、Stack
我是一名优秀的程序员,十分优秀!