能力值:
( LV2,RANK:10 )
2 楼
.版本 2 .子程序 进程_PID取路径, 文本型, 公开, 解决了一个句柄泄漏问题 .参数 PID, 整数型, , 进程ID .局部变量 handle, 整数型 .局部变量 a, 文本型 .局部变量 buf, 文本型 handle = OpenProcess (1024, 0, PID) .如果真 (handle = 0) handle = 进程_强力打开进程 (1024, 假, PID) .如果真结束 buf = 取空白文本 (512) .如果真 (GetProcessImageFileName (handle, buf, 512) = 0) 返回 (“”) .如果真结束 CloseHandle (handle) buf = DOS路径转换_ (buf) buf = 删首尾空 (buf) .如果 (buf = “”) 返回 (“-”) .否则 a = buf a = 子文本替换 (a, “\Device\HarddiskVolume6”, “H:”, , , 假) a = 子文本替换 (a, “\Device\HarddiskVolume5”, “G:”, , , 假) a = 子文本替换 (a, “\Device\HarddiskVolume4”, “F:”, , , 假) a = 子文本替换 (a, “\Device\HarddiskVolume3”, “E:”, , , 假) a = 子文本替换 (a, “\Device\HarddiskVolume2”, “D:”, , , 假) a = 子文本替换 (a, “\Device\HarddiskVolume1”, “C:”, , , 假) 返回 (a) .如果结束 用这些api吧...
能力值:
( LV2,RANK:10 )
3 楼
#include <stdio.h>
#include <locale.h>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <Psapi.h>
#pragma comment (lib,"Psapi.lib")
BOOL DosPathToNtPath(LPTSTR pszDosPath, LPTSTR pszNtPath)
{
TCHAR szDriveStr[500];
TCHAR szDrive[3];
TCHAR szDevName[100];
INT iDevName;
INT i;
//检查参数
if (!pszDosPath || !pszNtPath)
return FALSE;
//获取本地磁盘所有盘符,以'\0'分隔,所以下面+4
if (GetLogicalDriveStrings(sizeof(szDriveStr), szDriveStr))
{
for (i = 0; szDriveStr[i]; i += 4)
{
if (!lstrcmpi(&(szDriveStr[i]), _T("A:\\")) || !lstrcmpi(&(szDriveStr[i]), _T("B:\\")))
continue; //从C盘开始
//盘符
szDrive[0] = szDriveStr[i];
szDrive[1] = szDriveStr[i + 1];
szDrive[2] = '\0';
if (!QueryDosDevice(szDrive, szDevName, 100))//查询 Dos 设备名(盘符由NT查询DOS)
return FALSE;
iDevName = lstrlen(szDevName);
if (_tcsnicmp(pszDosPath, szDevName, iDevName) == 0)//是否为此盘
{
lstrcpy(pszNtPath, szDrive);//复制驱动器
lstrcat(pszNtPath, pszDosPath + iDevName);//复制路径
return TRUE;
}
}
}
lstrcpy(pszNtPath, pszDosPath);
return FALSE;
}
//获取进程完整路径
BOOL GetProcessFullPath(DWORD dwPID)
{
TCHAR szImagePath[MAX_PATH];
TCHAR pszFullPath[MAX_PATH];
HANDLE hProcess;
if (!pszFullPath)
return FALSE;
pszFullPath[0] = '\0';
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, dwPID); //由线程ID获得线程信息
if (!hProcess)
return FALSE;
if (!GetProcessImageFileName(hProcess, szImagePath, MAX_PATH)) //得到线程完整DOS路径
{
CloseHandle(hProcess);
return FALSE;
}
if (!DosPathToNtPath(szImagePath, pszFullPath)) //DOS路径转NT路径
{
CloseHandle(hProcess);
return FALSE;
}
CloseHandle(hProcess);
printf("%5d %s \r\n", dwPID, pszFullPath);
return TRUE;
}
int main()
{
DWORD Pid = 0;
printf("输入pid:");
scanf_s("%d",&Pid);
setlocale(LC_ALL, "chs"); //不设置解析中文字符时可能会出问题
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //得到系统所有线程快照
if (INVALID_HANDLE_VALUE == hSnapshot)
{
return NULL;
}
PROCESSENTRY32 pe = { 0 };
pe.dwSize = sizeof(PROCESSENTRY32);
BOOL fOk;
for (fOk = Process32First(hSnapshot, &pe); fOk; fOk = Process32Next(hSnapshot, &pe)) //遍历
{
if (Pid == pe.th32ProcessID)
{
GetProcessFullPath(pe.th32ProcessID);
system("pause");
break;
}
}
return 0;
}
能力值:
( LV13,RANK:385 )
4 楼
https://www.cnblogs.com/iBinary/p/12095895.html
能力值:
( LV2,RANK:10 )
5 楼
TkBinary
https://www.cnblogs.com/iBinary/p/12095895.html
谢谢大佬
能力值:
( LV2,RANK:10 )
6 楼
难寻
.版本 2
.子程序 进程_PID取路径, 文本型, 公开, 解决了一个句柄泄漏问题
.参数 PID, 整数型, , 进程ID
.局部变量 handle, 整数型
.局部变量 a, 文本型 ...
谢谢大佬
能力值:
( LV2,RANK:10 )
7 楼
D貓
#include <stdio.h>
#include <locale.h>
#include& ...
谢谢大佬
能力值:
( LV2,RANK:10 )
8 楼
GetModuleFileName https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea
能力值:
( LV2,RANK:10 )
9 楼
xuddk
GetModuleFileName
https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-g ...
谢谢大佬,已经解决了
能力值:
( LV3,RANK:20 )
10 楼
procedure TForm1.hotykey(var msg: TMessage); //注意:要在x32dbg的标题栏上按Ctrl+Shift+T var h: hwnd; pid: Cardinal; pHandle: THandle; buf: array[0..MAX_PATH] of Char; lpCaption: array[Byte] of Char; p: TPoint; match: TMatch; str1: string; TempA: string; ps: array[0..254] of Char; //这个是定义激活的窗口的控件名 path: string; //激活窗口的路径 arr: array[0..254] of Char; aWnd: hwnd; aBuf: array[0..254] of char; begin if (GetAsyncKeyState(VK_CONTROL) < 0) and (GetAsyncKeyState(VK_SHIFT) < 0) and (GetAsyncKeyState(Ord('T')) < 0) then //Ctrl+Shift+T begin h := GetForegroundWindow; GetWindowThreadProcessId(h, @pid); pHandle := OpenProcess(PROCESS_ALL_ACCESS, False, pid); GetModuleFileNameEx(pHandle, 0, buf, Length(buf)); CloseHandle(pHandle); // ShowMessage(buf); //这个是得到x32dbg.exe完整路径的! // ShowMessage(Format('%u', [pid])); //得到激活窗口的pid可行 ShowMessage('激活窗口的pid是:' + IntToHex(StrToInt(Format('%u', [pid])), 4)); //再转换成 16进制,因为x32dbg/x64dbg 附加进程用到的是 16进制数 Form3.Caption := (StringReplace(buf, 'exe', 'ini', [])); //前面加上【编辑字样】,后面替换【exe为ini】 Form3.Memo1.Lines.LoadFromFile(StringReplace(buf, 'exe', 'ini', []), TEncoding.UTF8); //, TEncoding.UTF8这个是重要的参数,加了就不会乱码了! Form3.Show; GetCursorPos(p); h := WindowFromPoint(p); IntToStr(GetWindowText(h, lpCaption, 255)); // ShowMessage(lpCaption); //这个是得到x32dbg标题完整信息 {SetCursorPos(850, 350); Sleep(1000); keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0); //按下Ctrl键 keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); //按下回车键 keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); //弹起回车键 keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0); //弹起Ctrl match := TRegEx.match(lpCaption, '(?<=模块:\s).*(?=\s-\s线程:)'); if match.Success then begin ShowMessage(match.Value); //这样就得到了x32dbg/x64dbg中显示的模块名,接下来再弄一个Ctrl+Shift+G(完成RVA地址的定位) Clipboard.AsText := match.Value; end; } end;