跨进程获取程序的基地址另一写法VC6实现
// 5566.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include<stdio.h>
#include<windows.h>
#include <psapi.h>//居然修改成功了 加了一堆的宏定义
#include <cassert>
#include <cstdio>
#include <iostream>
#include <TlHelp32.h>
#include <vector>
using namespace std;
HANDLE FindProcessByName(const char* name)
{
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
return NULL;
}
if (Process32First(hProcessSnap, &pe32))
{
do
{
if (strcmp(pe32.szExeFile, name) == 0)
{
CloseHandle(hProcessSnap);
return OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
}
} while (Process32Next(hProcessSnap, &pe32));
}
CloseHandle(hProcessSnap);
return NULL;
}
/**
* @brief 枚举指定进程所有内存块
* @Param hProcess 要枚举的进程,至少需拥有PROCESS_QUERY_INFORMATION权限
* @param memories 返回枚举到的内存块数组
* @Return 成功返回true,失败返回false.
*/
int main(int argc, char* argv[])
{
HANDLE hProcess = FindProcessByName("trashcleaner.exe");
if (hProcess == NULL)
{
printf("FindProcessByName failed\n");
return -1;
}
// 获取每一个模块加载基址
DWORD pro_base = NULL;
DWORD prodll_base = NULL;
HMODULE hModule = { 0 };
DWORD dwRet = 0;
int num = 0;
int bRet = EnumProcessModulesEx(hProcess, (HMODULE *)(hModule), sizeof(hModule), &dwRet, NULL);
if (bRet == 0){
printf("EnumProcessModules");
}
// 总模块个数
num = dwRet / sizeof(HMODULE);int ii;
printf("总模块个数: %d\n", num);
// 打印每一个模块加载基址
char lpBaseName;
for (int i = 0; i < num; i++){
GetModuleBaseNameA(hProcess, hModule, lpBaseName, sizeof(lpBaseName));
printf("%-2d %-25s基址: 0x%p\n", i, lpBaseName, hModule);
char str2 = "edobjectmodule.dll";
if (strcmp(lpBaseName, str2) == 0)//留着后面解决吧输入了 ==号 就运行正常了
{
printf("//////////////////////%-2d %-25s基址: 0x%p\n///////////////////", i, lpBaseName, hModule);
ii = i;
}
}
pro_base = (DWORD)hModule; prodll_base = (DWORD)hModule;
printf("程序基址: 0x%p\n", pro_base); printf("基址: 0x%p\n", prodll_base);
printf("Hello World!\n");
return 0;
}
C:\Program Files (x86)\Microsoft Visual Studio\VC98\Include放入附件新的Psapi.h
C:\Program Files (x86)\Microsoft Visual Studio\VC98\Lib 放入附件新的Kernel32.lib 有什么好的封装工具很多人调试不好 ruan1893 发表于 2023-10-22 14:17
有什么好的封装工具很多人调试不好
不知道 也只会依葫芦画瓢 不错,加油
页:
[1]