写一个c语言版本的dll,【C语言】求个用C语言写的DLL补丁源码

[C] 纯文本查看 复制代码#include

#include

#define EXENAME L"IPposition.exe"

#define DLLNAME L"winHttp.dll"

#define OFFSET 0x00001234

struct PSINFO

{

HANDLE hProcess;

DWORD dBaseAddr;

};

//DLL入口

BOOL DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)

{

return TRUE;

}

//获取指定进程指定dll的基地址

BOOL GetDllHandle(PSINFO * psInfo)

{

DWORD ret = 0;

DWORD dllAddr;

HANDLE hProcess;

PROCESSENTRY32 pe = { sizeof(PROCESSENTRY32) };

HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

Process32First(hSnapshot, &pe);

while (Process32Next(hSnapshot, &pe))

{

if (wcsicmp(pe.szExeFile, EXENAME) == 0)

{

ret = pe.th32ProcessID;

break;

}

}

CloseHandle(hSnapshot);

if (ret)

{

hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ret);

if (hProcess == INVALID_HANDLE_VALUE)

{

return FALSE;

}

MODULEENTRY32 me32 = { sizeof(MODULEENTRY32) };//存放快照信息的结构体

hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ret);

Module32First(hSnapshot, &me32);

while (Module32Next(hSnapshot, &me32))

{

if (wcsicmp(me32.szModule, DLLNAME) == 0)

{

dllAddr = (DWORD)me32.modBaseAddr;

break;

}

}

if (dllAddr!=0)

{

psInfo->hProcess = hProcess;

psInfo->dBaseAddr = dllAddr;

CloseHandle(hSnapshot);

return TRUE;

}

}

return FALSE;

}

//导出函数,修改内存

extern "C" __declspec(dllexport) BOOL WINAPI pj()

{

PSINFO psInfo;

BYTE buf[] = "\x90\x90\x90";

if (GetDllHandle(&psInfo))

{

return WriteProcessMemory(psInfo.hProcess, (LPVOID)(psInfo.dBaseAddr + OFFSET), buf, 3, NULL);

}

return FALSE;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值