mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-07-31 21:38:39 +00:00
Merge commit 'dabc40cb19
' as 'ext/detours'
This commit is contained in:
commit
77523940b3
178 changed files with 102613 additions and 0 deletions
67
ext/detours/tests/corruptor.cpp
Normal file
67
ext/detours/tests/corruptor.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Unit Test Image Corruptor (corruptor.cpp of unittests.exe)
|
||||
//
|
||||
// Microsoft Research Detours Package
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
#include "windows.h"
|
||||
#include "corruptor.h"
|
||||
|
||||
ImageCorruptor::ImageCorruptor(PIMAGE_DOS_HEADER Header)
|
||||
{
|
||||
m_TargetDosHeader = Header;
|
||||
m_OriginalDosHeader = *Header;
|
||||
m_OriginalDosProtection = 0;
|
||||
m_TargetNtHeaders = (PIMAGE_NT_HEADERS)((PBYTE)Header + Header->e_lfanew);
|
||||
m_OriginalNtHeaders = *m_TargetNtHeaders;
|
||||
m_OriginalNtProtection = 0;
|
||||
|
||||
VirtualProtect(
|
||||
m_TargetDosHeader,
|
||||
sizeof(*m_TargetDosHeader),
|
||||
PAGE_READWRITE,
|
||||
&m_OriginalDosProtection);
|
||||
|
||||
VirtualProtect(
|
||||
m_TargetNtHeaders,
|
||||
sizeof(*m_TargetNtHeaders),
|
||||
PAGE_READWRITE,
|
||||
&m_OriginalNtProtection);
|
||||
}
|
||||
|
||||
ImageCorruptor::~ImageCorruptor()
|
||||
{
|
||||
// Restore original header contents.
|
||||
//
|
||||
*m_TargetDosHeader = m_OriginalDosHeader;
|
||||
*m_TargetNtHeaders = m_OriginalNtHeaders;
|
||||
|
||||
// Restore original protection of DOS header.
|
||||
//
|
||||
DWORD OldProtection {};
|
||||
VirtualProtect(
|
||||
m_TargetDosHeader,
|
||||
sizeof(*m_TargetDosHeader),
|
||||
m_OriginalDosProtection,
|
||||
&OldProtection);
|
||||
|
||||
// Restore original protection of NT headers.
|
||||
//
|
||||
VirtualProtect(
|
||||
m_TargetNtHeaders,
|
||||
sizeof(*m_TargetNtHeaders),
|
||||
m_OriginalNtProtection,
|
||||
&OldProtection);
|
||||
}
|
||||
|
||||
void ImageCorruptor::ModifyDosMagic(WORD Value)
|
||||
{
|
||||
m_TargetDosHeader->e_magic = Value;
|
||||
}
|
||||
|
||||
void ImageCorruptor::ModifyNtSignature(ULONG Value)
|
||||
{
|
||||
m_TargetNtHeaders->Signature = Value;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue