怎样编写一个全局勾子勾住系统中的API ?(十万火急)

cabbage 2000-04-21 10:55:00
需要解决的问题:
一旦利用这个勾子勾住系统中的API后,对所有的
进程都有效,不管那个进程调用这个API,首先都被拦截.

...全文
338 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Un1 2000-05-26
  • 打赏
  • 举报
回复
大把,比如:
http://iflower.363.net/pmzhz.htm
yueyue 2000-05-06
  • 打赏
  • 举报
回复
waiting...
superbat 2000-04-25
  • 打赏
  • 举报
回复
Unl:
鼠标取词源码在哪?
cabbage 2000-04-24
  • 打赏
  • 举报
回复
zzh: 跳转指令怎么写
lu0 2000-04-22
  • 打赏
  • 举报
回复
看DETOUR的实现.全局的影响说来简单,其实也难.有些DLL的加载次序不一样.对
它的拦截就需要是动态的.当然KERNEL32,USER32,GDI32通常是在相同地址出现.
一个巧妙的拦截应该是拦截LOADLIBRARY.根据目标的加载而拦截.(KERNEL32永远
映射到同一地址.所以拦截LOADLIBRARY是安全,完整的解决方案.)
http://lu0.126.com
zzh 2000-04-21
  • 打赏
  • 举报
回复
我这有一段代码,是用来勾住函数的,你修改一下就可以使用了。代码如下
bool HookFunc (BYTE* pbCodeBuffer, DWORD& dwBufLen)
{
// ole libraries probably have been initialized, just get the handle
HMODULE hModule = GetModuleHandle (_T ("ds_avc.dll"));
if (hModule == NULL)
{
hModule = LoadLibrary (_T ("ds_avc.dll"));
}

// get address of the original CLSIDFromProgID
PVOID pfnOrg = (PVOID) GetProcAddress (hModule, "AvcCmdSetStreamState");

HANDLE hProcess = GetCurrentProcess ();

DWORD dwRead = 0;

// calculate offset from the original procedure to our;
// it doesn't matter the base address of our DLL, since "CPU" jumps always forward;
// notice dwJmpInstructionLen - the offset is calculated from next instruction
DWORD dwHookOffest = (DWORD)FuncProc -
((DWORD) pfnOrg + 5);//dwJmpInstructionLen);

if (!ReadProcessMemory (hProcess,
pfnOrg,
pbCodeBuffer,
dwJmpInstructionLen,
&dwRead))
{
// should be zero in this case
dwBufLen = 0;
return false;
}

// will be used to restore the original code during UnHook
dwBufLen = dwRead;

DWORD dwWritten = 0;

// write the jmp instruction. NT will perform copy-on-write, therefore no
// process will be affected by the change

if (!WriteProcessMemory (hProcess,
pfnOrg, // write at start of CLSIDFromProgID
(LPVOID) &bJmpCode, // jmp code 0xE9
sizeof (bJmpCode),
&dwWritten) && dwWritten != 0)
{
return false;
}

dwWritten = 0;
// write the offset to CLSIDProgIDProc
return (WriteProcessMemory (hProcess,
(LPVOID)((DWORD) pfnOrg + 1), // from the next byte
&dwHookOffest, // offset calculated before
sizeof (DWORD), &dwWritten) &&
dwWritten != 0);
}

bool HookFunc2 (BYTE* pbCodeBuffer, DWORD& dwBufLen)
{
// ole libraries probably have been initialized, just get the handle
HMODULE hModule = GetModuleHandle (_T ("ds_avc.dll"));
if (hModule == NULL)
{
hModule = LoadLibrary (_T ("ds_avc.dll"));
}

// get address of the original CLSIDFromProgID
PVOID pfnOrg = (PVOID) GetProcAddress (hModule, "AvcCmdGetVideoInputLumaSatGainThresh");

HANDLE hProcess = GetCurrentProcess ();

DWORD dwRead = 0;

// calculate offset from the original procedure to our;
// it doesn't matter the base address of our DLL, since "CPU" jumps always forward;
// notice dwJmpInstructionLen - the offset is calculated from next instruction
DWORD dwHookOffest = (DWORD)FuncProc2 -
((DWORD) pfnOrg + 5);//dwJmpInstructionLen);

if (!ReadProcessMemory (hProcess,
pfnOrg,
pbCodeBuffer,
dwJmpInstructionLen,
&dwRead))
{
// should be zero in this case
dwBufLen = 0;
return false;
}

// will be used to restore the original code during UnHook
dwBufLen = dwRead;

DWORD dwWritten = 0;

// write the jmp instruction. NT will perform copy-on-write, therefore no
// process will be affected by the change

if (!WriteProcessMemory (hProcess,
pfnOrg, // write at start of CLSIDFromProgID
(LPVOID) &bJmpCode, // jmp code 0xE9
sizeof (bJmpCode),
&dwWritten) && dwWritten != 0)
{
return false;
}

dwWritten = 0;
// write the offset to CLSIDProgIDProc
return (WriteProcessMemory (hProcess,
(LPVOID)((DWORD) pfnOrg + 1), // from the next byte
&dwHookOffest, // offset calculated before
sizeof (DWORD), &dwWritten) &&
dwWritten != 0);
}


// restore the previously saved code
void UnHookFunc (BYTE* pbCodeBuffer, DWORD dwBufLen)
{
HMODULE hModule = GetModuleHandle (_T ("ds_avc.dll"));
if (hModule != NULL)
{
// the ole32.DLL must be in memory
// get address of the original CLSIDFromProgID
PVOID pfnOrg = (PVOID) GetProcAddress (hModule, "AvcCmdSetStreamState");

HANDLE hProcess = GetCurrentProcess ();

DWORD dwWritten = 0;
WriteProcessMemory (hProcess,
pfnOrg,
pbCodeBuffer,
dwBufLen,
&dwWritten);

}
}

//-----------------------------------------------------------------------------------//
// the actual hook code
//-----------------------------------------------------------------------------------//



UINT _cdecl FuncProc (PVOID,PVOID, UINT state,UINT options)
{

TRACE("state options :0x%x,0x%x\n",state,options);

return options;
}
UINT _cdecl FuncProc2 (PVOID, UINT *gain)
{

TRACE("FuncProc2\n");
*gain = 0;

return 0;
}
GreenStuff 2000-04-21
  • 打赏
  • 举报
回复
必须是一个DLL
Un1 2000-04-21
  • 打赏
  • 举报
回复
去看看“鼠标取词”源码!

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧