|
发表于 2019-10-7 09:07:48
|
显示全部楼层
湖北省随州市
VirtualAlloc申请的内存堆释放是必崩的 -1肯定是空指针
程序传进程的指针就是个空指针 减1也是空指针 所以就崩了
减1法过保护 你不要搞笑了 看看-1是怎么来的
上面是RtlFreeHeap的反汇编崩溃的地方 能看懂就看吧 看不懂我也懒的再回复了
性能的话你自己看吧 1是你模块的 2是IsBadReadPtr检测内存可读 3是SEH
哪个速度快自己看咯 SEH 0.5S
代码一并给你
#include <windows.h>
#include <ntdll.h>
void Jmp(LPVOID dwTo, DWORD dwFrom)
{
DWORD dwOldProtect;
HANDLE Handle = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId());
VirtualProtectEx(Handle, (LPVOID)dwFrom, 10, PAGE_EXECUTE_READWRITE, &dwOldProtect);
*(BYTE*)dwFrom = 0xE9;
dwFrom += 1;
*(DWORD*)dwFrom = (DWORD)dwTo - (dwFrom + 4);
CloseHandle(Handle);
}
BOOL WINAPI MyHeapFree(HANDLE HeapHandle, ULONG Flags, PVOID Address) {
if (0 != IsBadReadPtr((PVOID)((DWORD)Address - 8), 8))
return FALSE;
return RtlFreeHeap(HeapHandle, Flags, Address);
/////////////////////SEH////////////////////////////////
//__try {
// return RtlFreeHeap(HeapHandle, Flags, Address);
//}
//__except (1)
//{
// return FALSE;
//}
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, PVOID pvReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
Jmp(MyHeapFree, (DWORD)HeapFree);
}
return TRUE;
}
Release.zip
(82.91 KB, 下载次数: 2)
|
|