hook技术有关问题
hook技术问题
api提供了一个叫setwindowshookex的函数,,但最后一个参数需要被hook目标的线程id,而我却只能得到那个目标进程的句柄,,,有没办法通过这个进程句柄得到进程所含有的线程id?
------解决方案--------------------
GetThreadId ?
------解决方案--------------------
NULL 不就是所有
GetWindowThreadProcessId
------解决方案--------------------
貌似不能挂起一个线程钩子 要不过滤试试
------解决方案--------------------
http://www.cnblogs.com/kingdom_0/articles/2740864.html
------解决方案--------------------
------解决方案--------------------
你有进程句柄
调用GetProcessId得到进程id
调用CreateToolhelp32Snapshot得到所有线程列表
枚举线程列表,看哪一个对应的进程id和已获得的进程id相等,加入结果集
于是你得到了进程中的所有线程id
api提供了一个叫setwindowshookex的函数,,但最后一个参数需要被hook目标的线程id,而我却只能得到那个目标进程的句柄,,,有没办法通过这个进程句柄得到进程所含有的线程id?
------解决方案--------------------
GetThreadId ?
------解决方案--------------------
NULL 不就是所有
GetWindowThreadProcessId
------解决方案--------------------
貌似不能挂起一个线程钩子 要不过滤试试
------解决方案--------------------
http://www.cnblogs.com/kingdom_0/articles/2740864.html
------解决方案--------------------
BOOL EnumProcessInfo()
{
//定义进程信息结构
PROCESSENTRY32 pe32 = {sizeof(pe32)};
//创建系统当前的进程快照
HANDLE hProcessShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessShot == INVALID_HANDLE_VALUE)
{
return false;
}
//输出进程信息到文件
ofstream fout("EnumInfo_ToolHelp_process.txt");
//循环枚举进程信息
char szBuf[300] = {0};
if (Process32First(hProcessShot, &pe32))
{
do
{
memset(szBuf, 0, sizeof(szBuf));
//把宽字符的进程名转化为ANSI字符串
WideCharToMultiByte(CP_ACP, 0, pe32.szExeFile,
wcslen(pe32.szExeFile),szBuf,sizeof(szBuf),NULL,NULL);
fout<<"Process: "<<szBuf<<endl;
fout<<'\t'<<"Usage :"<<pe32.cntUsage<<endl;
fout<<'\t'<<"ProcessID: "<<pe32.th32ProcessID<<endl;
fout<<'\t'<<"DefaultHeapID :"<<(ULONG_PTR)pe32.th32DefaultHeapID<<endl;
fout<<'\t'<<"ModuleID :"<<pe32.th32ModuleID<<endl;
fout<<'\t'<<"ThreadNum :"<<pe32.cntThreads<<endl;
fout<<'\t'<<"ParentProcessID :"<<pe32.th32ParentProcessID<<endl;
fout<<'\t'<<"PriClassBase :"<<pe32.pcPriClassBase<<endl;
} while (Process32Next(hProcessShot, &pe32));
}
fout.close();
CloseHandle(hProcessShot);
return true;
}
BOOL EnumThreadInfo()
{
//定义线程信息结构
THREADENTRY32 te32 = {sizeof(te32)};
//创建系统线程快照
HANDLE hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hThreadSnap == INVALID_HANDLE_VALUE)
{
return false;
}
//输出线程信息到文件
ofstream fout("EnumInfo_ToolHelp_thread.txt");
//循环枚举线程信息
if (Thread32First(hThreadSnap, &te32))
{
do
{
fout<<"ThreadId:"<<te32.th32ThreadID<<endl;
fout<<'\t'<<"OwnerProcessID:"<<te32.th32OwnerProcessID<<endl;
fout<<'\t'<<"Usage :"<<te32.cntUsage<<endl;
fout<<'\t'<<"Default Priority :"<<te32.tpDeltaPri<<endl;
fout<<'\t'<<"Base Priority :"<<te32.tpBasePri<<endl;
} while (Thread32Next(hThreadSnap, &te32));
}
return TRUE;
}
------解决方案--------------------
你有进程句柄
调用GetProcessId得到进程id
调用CreateToolhelp32Snapshot得到所有线程列表
枚举线程列表,看哪一个对应的进程id和已获得的进程id相等,加入结果集
于是你得到了进程中的所有线程id