gpt4 book ai didi

c# - Easyhook 32 位应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:53 27 4
gpt4 key购买 nike

我正在使用 EasyHook 拦截注册表调用。更详细地说,我使用 RegQueryValue 来拦截从注册表中读取一个键并用其他东西改变它的值的调用。相关代码如下:

[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
delegate int DRegQueryValueExW(
IntPtr hKey,
string lpValueName,
int lpReserved,
ref Microsoft.Win32.RegistryValueKind lpType,
StringBuilder lpData,
ref int lpcbData);

[DllImport("Advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
static extern int RegQueryValueExW(
IntPtr hKey,
string lpValueName,
int lpReserved,
ref Microsoft.Win32.RegistryValueKind lpType,
StringBuilder lpData,
ref int lpcbData);

int RegQueryValueExW_Hooked(
IntPtr hKey,
string lpValueName,
int lpReserved,
ref Microsoft.Win32.RegistryValueKind lpType,
StringBuilder lpData,
ref int lpcbData)
{
// todo: change value of lpData and return 0
return RegQueryValueExW(hKey, lpValueName, lpReserved, ref lpType, lpData, ref lpcbData);
}

如果我使用目标 x64 构建所有内容,这一切都可以毫无问题地执行。

但是,如果我使用目标 x32 构建它,它会在 RegQueryValueExW_Hooked 中崩溃并出现错误:

Unhandled Exception: System.Runtime.InteropServices.SEHException: External component has thrown an exception. at DummyDCA.Program.Main(String[] args) Unhandled Exception: System.ArgumentOutOfRangeException: Capacity exceeds maximum capacity. Parameter name: capacity at AG.RU.Valuation.Controller.AFMToolbox.Inject.Main.RegQueryValueExW(IntPtrhKey, String lpValueName, Int32 lpReserved, RegistryValueKind& lpType, StringBuilder lpData, Int32& lpcbData) at AG.RU.Valuation.Controller.AFMToolbox.Inject.Main.RegQueryValueExW_Hooked(IntPtr hKey, String lpValueName, Int32 lpReserved, RegistryValueKind& lpType, StringBuilder lpData, Int32& lpcbData)

问题似乎是 StringBuilder 类型的 lpData(某种溢出,StringBuilder 不够大或其他原因)。如果我用 IntPtr 替换 StringBuilder,它不会崩溃;但是我有一个指针而不是 StringBuilder,所以我不确定如何替换 lpData 的值。

有没有人知道为什么会这样,应该怎么做?

谢谢!

最佳答案

似乎我不得不使用 IntPtr 而不是 StringBuilder; RegQueryValueExW_Hooked 的实现也比较特殊。

Luaan 在此线程中描述了实际的解决方案:Changing the string to which an IntPtr is pointing

关于c# - Easyhook 32 位应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21722555/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com