扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
.text:7C812C8D GetCommandLineA proc near .text:7C812C8D mov eax, dword_7C8835F4 //dword_7C8835F4 就是命令行参数字符串的地址 //该指令机器码为 A1 F4 35 88 7C,从第2个字节开始的4个字节就是我们要的地址 .text:7C812C92 retn .text:7C812C92 GetCommandLineA endp |
.text:BFF8C907 GetCommandLineA proc near .text:BFF8C907 mov eax, dword_BFFCADE4 .text:BFF8C90C mov ecx, [eax] .text:BFF8C90E mov eax, [ecx+0C0h] .text:BFF8C914 test eax, eax .text:BFF8C916 jnz short locret_BFF8C91E .text:BFF8C918 mov eax, [ecx+40h] .text:BFF8C91B mov eax, [eax+8] //算到这儿,才是我们想要的地址 .text:BFF8C91E .text:BFF8C91E locret_BFF8C91E: ; CODE XREF: GetCommandLineA+F. .text:BFF8C91E retn |
DWORD g_GetCmdLine(DWORD dwPID,TCHAR* pCmdLine,DWORD dwBufLen) { #define BUFFER_LEN 512 //reading buffer for the commandline HANDLE hProc = OpenProcess(PROCESS_VM_READ,FALSE,dwPID); if(hProc == NULL) { return GetLastError(); } DWORD dwRet = -1; DWORD dwAddr = *(DWORD*)((DWORD)GetCommandLine + 1);//第2个字节开始才是我们要读的地址 TCHAR tcBuf[BUFFER_LEN] = {0}; DWORD dwRead = 0; //判断平台 DWORD dwVer = GetVersion(); try { if(dwVer < 0x80000000) // Windows NT/2000/XP { if(ReadProcessMemory(hProc,(LPVOID)dwAddr,&dwAddr,4,&dwRead)) { if(ReadProcessMemory(hProc,(LPVOID)dwAddr,tcBuf,BUFFER_LEN,&dwRead)) { _tcsncpy(pCmdLine,tcBuf,dwBufLen); //最好检查一下dwRead和dwBufLen的大小,使用较小的那个 dwRet = 0; } } } else // Windows 95/98/Me and Win32s { while(true) //使用while是为了出错时方便跳出循环 { if(!ReadProcessMemory(hProc,(LPVOID)dwAddr,&dwAddr,4,&dwRead)) break; if(!ReadProcessMemory(hProc,(LPVOID)dwAddr,&dwAddr,4,&dwRead)) break; if(!ReadProcessMemory(hProc,(LPVOID)(dwAddr + 0xC0),tcBuf,BUFFER_LEN,&dwRead)) break; if(*tcBuf == 0) { if(!ReadProcessMemory(hProc,(LPVOID)(dwAddr + 0x40),&dwAddr,4,&dwRead)) break; if(!ReadProcessMemory(hProc,(LPVOID)(dwAddr + 0x8),&dwAddr,4,&dwRead)) break; if(!ReadProcessMemory(hProc,(LPVOID)dwAddr,tcBuf,BUFFER_LEN,&dwRead)) break; } _tcsncpy(pCmdLine,tcBuf,dwBufLen); //最好检查一下dwRead和dwBufLen的大小,使用较小的那个 dwRet = 0; break; } } } catch(...) { dwRet = ERROR_INVALID_ACCESS; //exception } CloseHandle(hProc); return dwRet; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者