Initial commit

This commit is contained in:
Nick Cano
2015-04-20 09:12:03 -07:00
parent 1b4e5ffd6d
commit 25284fb5bb
40 changed files with 3950 additions and 0 deletions
+16
View File
@@ -26,3 +26,19 @@
*.exe
*.out
*.app
# VS stuff
*.suo
*.sdf
*.user
#other directories
*/ipch/*
*/Debug/*
*/Release/*
*/BuildTemp/*
ipch/*
Debug/*
Release/*
BuildTemp/*
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{E28E3DC6-2614-43B9-83E4-86D6F9A585B1}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Chapter10_ResponsiveHacks</RootNamespace>
<ProjectName>Chapter10_ResponsiveHacks</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<FixedBaseAddress>
</FixedBaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main-responsiveHacks.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,118 @@
#include <iostream>
#include <Windows.h>
#include <vector>
// WARNING: if this code is killed mid-execute or you switch to another window (not the console)
// while it's executing, it may cause the system to think a modifier key is stuck.
// If this happens, you can tap shift, ctrl, and alt on the LEFT side of your keyboard to "unstick it"
// SendInput() example code
void sendKeyWithSendInput(WORD key, bool up)
{
INPUT input = {0};
input.type = INPUT_KEYBOARD;
input.ki.wVk = key;
input.ki.dwFlags = 0;
if (up)
input.ki.dwFlags |= KEYEVENTF_KEYUP;
SendInput(1, &input, sizeof(input));
}
void sendModifiersWithSendInput(DWORD flags, bool up)
{
if (flags & 1)
sendKeyWithSendInput(VK_LSHIFT, up);
if (flags & 2)
sendKeyWithSendInput(VK_LCONTROL, up);
if (flags & 4)
sendKeyWithSendInput(VK_LMENU, up);
}
void sendCharWithSendInput(char letter)
{
SHORT keyFlags = VkKeyScanA(letter);
WORD key = keyFlags & 0xFF;
DWORD flags = (keyFlags >> 8) & 0xFF;
sendModifiersWithSendInput(flags, false);
sendKeyWithSendInput(key, false);
sendKeyWithSendInput(key, true);
sendModifiersWithSendInput(flags, true);
}
void typeStringWithSendInput(const char* string)
{
for (int i = 0; i < strlen(string); i++)
{
sendCharWithSendInput(string[i]);
Sleep(80);
}
}
// SendMessage example code
void sendKeyWithSendMessage(HWND window, WORD key, char letter)
{
SendMessageA(window, WM_KEYDOWN, key, 0);
if (letter != 0)
SendMessageA(window, WM_CHAR, letter, 1);
SendMessageA(window, WM_KEYUP, key, 1);
}
void sendCharWithSendMessage(HWND window, char letter)
{
SHORT keyFlags = VkKeyScanA(letter);
WORD key = keyFlags & 0xFF;
DWORD flags = (keyFlags >> 8) & 0xFF;
sendKeyWithSendMessage(window, key, letter);
}
void typeStringWithSendMessage(HWND window, const char* string)
{
for (int i = 0; i < strlen(string); i++)
{
sendCharWithSendMessage(window, string[i]);
Sleep(80);
}
}
DWORD WINAPI exampleThread(LPVOID lpParam)
{
Sleep(500);
typeStringWithSendInput("Typing using SendInput()!\rHow does it look? :)\r\r");
auto window = FindWindowA(NULL, "Chapter10 Input Example");
typeStringWithSendMessage(window, "Typing using SendMessage()!\rEffectively the same, but more powerful :-)\r\r");
return 0;
}
int main(void)
{
std::cout << "WARNING: Don't switch between windows until this application is done typing" << std::endl;
system("pause");
std::cout << "Everything below here is being programmatically typed using the keyboard" << std::endl << std::endl;
SetConsoleTitleA("Chapter10 Input Example");
CreateThread(NULL, 0, exampleThread, 0, 0, NULL);
char temp;
while (true) {
std::cin >> temp;
}
}
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main-CodeToMemory.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{42D11C4C-AC06-47BD-B6CD-FC6DBAF54472}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Chapter4_CodeToMemory</RootNamespace>
<ProjectName>Chapter4_CodeToMemory</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<FixedBaseAddress>
</FixedBaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main-codeToMemory.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+159
View File
@@ -0,0 +1,159 @@
#include <iostream>
#include <windows.h>
/* numeric values */
unsigned char ubyteValue = 0xFF;
char byteValue = 0xFE;
unsigned short uwordValue = 0x4142;
short wordValue = 0x4344;
unsigned int udwordValue = 0xDEADBEEF;
int dwordValue = 0xDEADBEEF;
unsigned long long ulongLongValue = 0xEFCDAB8967452301;
long long longLongValue = 0xEFCDAB8967452301;
float floatValue = 1337.7331;
/* string values */
char* thinStringP = "my_thin_terminated_value_pointer";
char thinStringA[40] = "my_thin_terminated_value_array";
wchar_t* wideStringP = L"my_wide_terminated_value_pointer";
wchar_t wideStringA[40] = L"my_wide_terminated_value_array";
/* structures */
struct MyStruct {
unsigned char ubyteValue;
char byteValue;
unsigned short uwordValue;
short wordValue;
unsigned int udwordValue;
int dwordValue;
unsigned long long ulongLongValue;
char interruptor;
long long longLongValue;
float floatValue;
};
/* classes with no VF tables */
class bar {
public:
bar() : bar1(0x898989), bar2(0x10203040) {}
void myfunction() { bar1++; }
int bar1, bar2;
};
/* classes with VF tables */
class foo {
public:
foo() : myValue1(0xDEADBEEF), myValue2(0xBABABABA) {}
int myValue1;
static int myStaticValue;
virtual void bar() { printf("foo::bar()\n"); }
virtual void baz() { printf("foo::baz()\n"); }
virtual void barbaz() {}
int myValue2;
};
int foo::myStaticValue = 0x12121212;
class fooa : public foo {
public:
fooa() : foo() {}
virtual void bar() { printf("fooa::bar()\n"); }
virtual void baz() { printf("fooa::baz()\n"); }
};
class foob : public foo {
public:
foob() : foo() { }
virtual void bar() { printf("foob::bar()\n"); }
virtual void baz() { printf("foob::baz()\n"); }
};
/* class protection */
class baz {
public:
baz() : baz1(0x11111111), baz2(0x22222222),
baz3(0x33333333), baz4(0x44444444) {}
int baz1, baz2;
void printStuff()
{
printf("0x%x : baz->baz1\n", &this->baz1);
printf("0x%x : baz->baz2\n", &this->baz2);
printf("0x%x : baz->baz3\n", &this->baz3);
printf("0x%x : baz->baz4\n", &this->baz4);
}
private:
int baz3, baz4;
};
int main(void)
{
/* just using global values so they don't get optimized away */
ubyteValue = ubyteValue;
byteValue = byteValue;
wordValue = wordValue;
uwordValue = uwordValue;
udwordValue = udwordValue;
dwordValue = dwordValue;
ulongLongValue = ulongLongValue;
longLongValue = longLongValue;
floatValue = floatValue;
thinStringP = thinStringP;
if (thinStringA){}
wideStringP = wideStringP;
if (wideStringA){}
/* printing addresses so we can easily find the dumps */
printf("0x%x : ubyteValue\n", &ubyteValue);
printf("0x%x : thinStringP\n", &thinStringP);
/* showing structure arrangement */
MyStruct* m = 0;
printf("Offsets: %d,%d,%d,%d,%d,%d,%d,%d,%d\n",
&m->ubyteValue, &m->byteValue,
&m->uwordValue, &m->wordValue,
&m->udwordValue, &m->dwordValue,
&m->ulongLongValue, &m->longLongValue,
&m->floatValue);
/* union stuff */
union {
BYTE byteValue;
struct {
WORD first;
WORD second;
} words;
DWORD value;
} dwValue;
dwValue.value = 0xDEADBEEF;
printf("Size %d; Addresses 0x%x,0x%x; Values 0x%x,0x%x\n",
sizeof(dwValue), &dwValue.value, &dwValue.words,
dwValue.words.first, dwValue.words.second);
/* classes with no VF tables */
bar _bar = bar();
printf("Size %d; Address 0x%x : _bar\n", sizeof(_bar), &_bar);
/* class VF call */
foo* _testfoo = (foo*)new fooa();
_testfoo->bar();
/* classes with VF tables */
foo _foo = foo();
fooa _fooa = fooa();
foob _foob = foob();
printf("0x%x : _foo\n", &_foo);
printf("0x%x : _fooa\n", &_fooa);
printf("0x%x : _foob\n", &_foob);
_foo.barbaz();
_fooa.bar();
_foob.baz();
/* class protection */
baz* _baz = 0;
_baz->printStuff();
system("pause");
}
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6C658EF9-CCA4-4E18-8AD7-CEBDC04AB3AB}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Chapter5_AdvancedMemoryForensics_Scanning</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<FixedBaseAddress>
</FixedBaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main-advancedMemoryForensics-Scanning.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,169 @@
#include <iostream>
#include <windows.h>
#include <vector>
#include <list>
#include <map>
struct PlayerVital {
int current, maximum;
};
PlayerVital health = {450, 500};
std::vector<DWORD> vectorData;
std::list<DWORD> listData;
typedef int keyInt;
typedef int valInt;
std::map<keyInt, valInt> mapData;
void printString(const char* text, int one, int two)
{
printf(text, one, two);
}
void printHealth()
{
printString("Health: %d of %d\n", health.current, health.maximum);
}
// VECTOR
void readVector(DWORD vectorAddress)
{
struct _vector
{
DWORD* begin;
DWORD* end;
DWORD* tail;
};
_vector* vec = (_vector*)vectorAddress;
DWORD count = ((DWORD)vec->end - (DWORD)vec->begin) / sizeof(DWORD);
DWORD capacity = ((DWORD)vec->tail - (DWORD)vec->begin) / sizeof(DWORD);
printf("Vector has %d items and %d capacity\n", count, capacity);
for (int i = 0; i < count; i++)
printf("\tValue at %d is %d\n", i, vec->begin[i]);
}
// LIST
void readList(DWORD listAddress)
{
struct listItem
{
listItem* next;
listItem* prev;
DWORD value;
};
struct _list
{
listItem* root;
DWORD size;
};
_list* list = (_list*)listAddress;
printf("List has %d items\n", list->size);
for (listItem* it = list->root->next; it != list->root; it = it->next)
printf("\tForward value is %d\n", it->value);
for (listItem* it = list->root->prev; it != list->root; it = it->prev)
printf("\tReverse value is %d\n", it->value);
}
// MAP
struct mapItem {
mapItem* left;
mapItem* parent;
mapItem* right;
keyInt key;
valInt value;
};
struct _map {
DWORD irrelevant;
mapItem* rootNode;
int size;
};
mapItem* findItem(keyInt key, mapItem* node, mapItem* root)
{
if (node != root) {
if (key == node->key)
return node;
else if (key < node->key)
return findItem(key, node->left, root);
else
return findItem(key, node->right, root);
}
else
return root;
}
mapItem* searchMap(keyInt key, _map* map)
{
mapItem* ret =
findItem(key, map->rootNode->parent, map->rootNode);
if (ret == map->rootNode) return NULL;
return ret;
}
void iterateMap(mapItem* node, mapItem* root)
{
if (node == root) return;
iterateMap(node->left, root);
printf("\tKey %d has value 0x%04x\n", node->key, node->value);
iterateMap(node->right, root);
}
void readMap(DWORD mapAddress)
{
_map* map = (_map*)mapAddress;
printf("Nodes in map: %d\n", map->size);
iterateMap(map->rootNode->parent, map->rootNode);
printf("\tMap search for 1 yields: 0x%04x\n", searchMap(1, map)->value);
printf("\tMap search for 2 yields: 0x%04x\n", searchMap(2, map)->value);
printf("\tMap search for 3 yields: 0x%04x\n", searchMap(3, map)->value);
printf("\tMap search for 5 yields: 0x%04x\n", searchMap(5, map)->value);
}
int main(void)
{
vectorData.reserve(20);
vectorData.push_back(12345);
vectorData.push_back(54321);
listData.push_back(123);
listData.push_back(321);
listData.push_back(121);
mapData.insert(std::pair<DWORD, int>(1, 0x100));
mapData.insert(std::pair<DWORD, int>(2, 0x200));
mapData.insert(std::pair<DWORD, int>(3, 0x200));
mapData.insert(std::pair<DWORD, int>(5, 0x500));
while (true) // stupid loop to keep anything needed for the example from being optimized away
{
auto something = &printString;
printHealth();
readVector((DWORD)&vectorData);
readList((DWORD)&listData);
readMap((DWORD)&mapData);
health.current = (health.current == health.maximum) ? 1 : (health.current + 1);
health.maximum = 500;
system("pause");
}
}
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4C3B87D1-43D3-44DB-913E-E4A1D99909CB}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Chapter6_AccessingMemory</RootNamespace>
<ProjectName>Chapter6_AccessingMemory</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<FixedBaseAddress>
</FixedBaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main-accessingMemory.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,169 @@
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
void printMyPid()
{
wchar_t myTitle[1024];
GetConsoleTitle(&myTitle[0], 1024);
HWND myWindow = FindWindow(NULL, myTitle);
DWORD pid;
GetWindowThreadProcessId(myWindow, &pid);
printf("My pid is %d\n", pid);
}
void printExplorerPid()
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
std::wstring binaryPath = entry.szExeFile;
if (binaryPath.find(L"explorer.exe") != std::wstring::npos)
{
printf("Explorer's pid is %d\n", entry.th32ProcessID);
break;
}
}
}
CloseHandle(snapshot);
}
template<typename T>
T readMemoryAPI(HANDLE process, LPVOID address)
{
T value;
ReadProcessMemory(process, address, &value, sizeof(T), NULL);
return value;
}
template<typename T>
void writeMemoryAPI(HANDLE process, LPVOID address, T value)
{
WriteProcessMemory(process, address, &value, sizeof(T), NULL);
}
template<typename T>
DWORD protectMemory(HANDLE process, LPVOID address, DWORD prot)
{
DWORD oldProt;
VirtualProtectEx(process, address, sizeof(T), prot, &oldProt);
return oldProt;
}
void readAndWriteMemoryAPI(HANDLE process, LPVOID address)
{
DWORD value = readMemoryAPI<DWORD>(process, address);
printf("Current mem value is %d\n", value);
value++;
DWORD oldProt = protectMemory<DWORD>(process, address, PAGE_READWRITE);
writeMemoryAPI<DWORD>(process, address, value);
protectMemory<DWORD>(process, address, oldProt);
value = readMemoryAPI<DWORD>(process, address);
printf("New mem value is %d\n", value);
}
template<typename T>
T readMemoryPointer(LPVOID address)
{
return *((T*)address);
}
template<typename T>
void writeMemoryPointer(LPVOID address, T value)
{
*((T*)address) = value;
}
template<typename T>
T* pointMemory(LPVOID address)
{
return ((T*)address);
}
void readAndWriteMemoryMarshall(LPVOID address)
{
DWORD value = readMemoryPointer<DWORD>(address);
printf("Current mem value is %d\n", value);
value++;
writeMemoryPointer<DWORD>(address, value);
value = readMemoryPointer<DWORD>(address);
printf("New mem value is %d\n", value);
}
DWORD getMyBaseAddressGMH()
{
return (DWORD)GetModuleHandle(NULL);
}
DWORD getMyBaseAddressFS()
{
DWORD newBase;
__asm
{
MOV EAX, DWORD PTR FS:[0x30]
MOV EAX, DWORD PTR DS:[EAX+0x8]
MOV newBase, EAX
}
return newBase;
}
DWORD getMyBaseRemoteGMH(HANDLE Process)
{
LPVOID TIB;
__asm
{
MOV EAX, DWORD PTR FS:[0x18]
ADD EAX, 0x30
MOV TIB, EAX
}
// read 0x30 bytes past _the_game's_ TIB to get the PEB
DWORD PEB = readMemoryAPI<DWORD>(Process, TIB);
// read 0x8 bytes past _the_game's_ PEB to get the base
return readMemoryAPI<DWORD>(Process, (LPVOID)(PEB + 0x08));
}
void printMyBaseAddresses(HANDLE Process)
{
DWORD base1 = getMyBaseAddressGMH();
DWORD base2 = getMyBaseAddressFS();
DWORD base3 = getMyBaseRemoteGMH(Process);
if (base1 != base2 || base2 != base3)
printf("Woah, this should be impossible!\n");
else
printf("My base address is 0x%08x\n", base1);
}
int main(void)
{
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
printMyBaseAddresses(proc);
printMyPid();
printExplorerPid();
// lets do some memory stuff.. to ourself
DWORD someValue = 1234;
readAndWriteMemoryAPI(proc, &someValue);
readAndWriteMemoryMarshall(&someValue);
system("pause");
}
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{A20C8EDD-02C5-499E-8DB6-1CB8081FD62B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Chapter7_CodeInjection</RootNamespace>
<ProjectName>Chapter7_CodeInjection</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<FixedBaseAddress>
</FixedBaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main-codeInjection.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,173 @@
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
DWORD printStringManyTimes(int times, const char* string)
{
for (int i = 0; i < times; i++)
printf(string);
return 0;
}
void injectCodeUsingThreadInjection(HANDLE process, LPVOID func, int times, const char* string)
{
BYTE codeCave[20] = {
0xFF, 0x74, 0x24, 0x04, // PUSH DWORD PTR[ESP+0x4]
0x68, 0x00, 0x00, 0x00, 0x00, // PUSH 0
0xB8, 0x00, 0x00, 0x00, 0x00, // MOV EAX, 0x0
0xFF, 0xD0, // CALL EAX
0x83, 0xC4, 0x08, // ADD ESP, 0x08
0xC3 // RETN
};
// copy values to the shellcode
memcpy(&codeCave[5], &times, 4);
memcpy(&codeCave[10], &func, 4);
// allocate memory for the coe cave
int stringlen = strlen(string) + 1;
int fulllen = stringlen + sizeof(codeCave);
LPVOID remoteString = VirtualAllocEx(process, NULL, fulllen, MEM_COMMIT, PAGE_EXECUTE);
LPVOID remoteCave = (LPVOID)((DWORD)remoteString + stringlen);
// write the code cave
WriteProcessMemory(process, remoteString, string, stringlen, NULL);
WriteProcessMemory(process, remoteCave, codeCave, sizeof(codeCave), NULL);
// run the thread
HANDLE thread = CreateRemoteThread(process, NULL, NULL,
(LPTHREAD_START_ROUTINE)remoteCave,
remoteString, NULL, NULL);
WaitForSingleObject(thread, INFINITE);
CloseHandle(thread);
}
DWORD GetProcessThreadID(HANDLE Process)
{
THREADENTRY32 entry;
entry.dwSize = sizeof(THREADENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (Thread32First(snapshot, &entry) == TRUE)
{
DWORD PID = GetProcessId(Process);
while (Thread32Next(snapshot, &entry) == TRUE)
{
if (entry.th32OwnerProcessID == PID)
{
CloseHandle(snapshot);
return entry.th32ThreadID;
}
}
}
CloseHandle(snapshot);
return NULL;
}
void injectCodeUsingThreadRedirection(HANDLE process, LPVOID func, int times, const char* string)
{
BYTE codeCave[31] = {
0x60, //PUSHAD
0x9C, //PUSHFD
0x68, 0x00, 0x00, 0x00, 0x00, // PUSH 0
0x68, 0x00, 0x00, 0x00, 0x00, // PUSH 0
0xB8, 0x00, 0x00, 0x00, 0x00, // MOV EAX, 0x0
0xFF, 0xD0, // CALL EAX
0x83, 0xC4, 0x08, // ADD ESP, 0x08
0x9D, //POPFD
0x61, //POPAD
0x68, 0x00, 0x00, 0x00, 0x00, // PUSH 0
0xC3 // RETN
};
// allocate memory for the coe cave
int stringlen = strlen(string) + 1;
int fulllen = stringlen + sizeof(codeCave);
LPVOID remoteString = VirtualAllocEx(process, NULL, fulllen, MEM_COMMIT, PAGE_EXECUTE);
LPVOID remoteCave = (LPVOID)((DWORD)remoteString + stringlen);
// suspend the thread and query its control context
DWORD threadID = GetProcessThreadID(process);
HANDLE thread = OpenThread((THREAD_GET_CONTEXT | THREAD_SUSPEND_RESUME | THREAD_SET_CONTEXT), false, threadID);
SuspendThread(thread);
CONTEXT threadContext;
threadContext.ContextFlags = CONTEXT_CONTROL;
GetThreadContext(thread, &threadContext);
// copy values to the shellcode (happens late because we need values from allocation)
memcpy(&codeCave[3], &remoteString, 4);
memcpy(&codeCave[8], &times, 4);
memcpy(&codeCave[13], &func, 4);
memcpy(&codeCave[25], &threadContext.Eip, 4);
// write the code cave
WriteProcessMemory(process, remoteString, string, stringlen, NULL);
WriteProcessMemory(process, remoteCave, codeCave, sizeof(codeCave), NULL);
//redirect the thread
threadContext.Eip = (DWORD)remoteCave;
threadContext.ContextFlags = CONTEXT_CONTROL;
SetThreadContext(thread, &threadContext);
ResumeThread(thread);
//clean
CloseHandle(thread);
}
DWORD WINAPI redirectionThread(LPVOID lpParam)
{
injectCodeUsingThreadRedirection((HANDLE)lpParam, &printStringManyTimes, 2, "redirected\n");
return 1;
}
void LoadDll(HANDLE process, const wchar_t* dllPath)
{
// write the dll name to memory
int namelen = wcslen(dllPath) + 1;
LPVOID remoteString = VirtualAllocEx(process, NULL, namelen * 2, MEM_COMMIT, PAGE_EXECUTE);
WriteProcessMemory(process, remoteString, dllPath, namelen * 2, NULL);
// get the address of GetModuleHandle()
HMODULE k32 = GetModuleHandleA("kernel32.dll");
LPVOID funcAdr = GetProcAddress(k32, "LoadLibraryW");
// create the thread
HANDLE thread =
CreateRemoteThread(process, NULL, NULL, (LPTHREAD_START_ROUTINE)funcAdr, remoteString, NULL, NULL);
// let the thread finish and clean up
WaitForSingleObject(thread, INFINITE);
CloseHandle(thread);
}
int main(void)
{
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
// inject code into self using thread injection
injectCodeUsingThreadInjection(proc, &printStringManyTimes, 2, "injected\n");
// inject code into self using thread re-direction
// we need to do it from a secondary thread or else
// the redirection code would redirect itself.. which
// doesn't work
CreateThread(NULL, 0, redirectionThread, proc, 0, NULL);
LoadDll(proc, L"Chapter7_CodeInjection_DLL.dll");
while (true) // stay busy
{
Sleep(100);
}
}
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{37305F21-BB4B-4492-A713-DDD94653C16E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Chapter7_CodeInjection_DLL</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;CHAPTER7_CODEINJECTION_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CHAPTER7_CODEINJECTION_DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
</Project>
+28
View File
@@ -0,0 +1,28 @@
#include <windows.h>
DWORD WINAPI nonTrivialSomething(LPVOID lpParam)
{
return 1;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL, "DLL Attached!\n", "Game Hacking", MB_OK | MB_TOPMOST);
CreateThread(NULL, 0, &nonTrivialSomething, NULL, 0, NULL);
break;
case DLL_PROCESS_DETACH:
MessageBoxA(NULL, "DLL Detached!\n", "Game Hacking", MB_OK | MB_TOPMOST);
break;
}
return TRUE;
}
+105
View File
@@ -0,0 +1,105 @@
#include "AdobeAirHook.h"
#include "AdobeAirHookCallbacks.h"
#include "ExecutableModule.h"
#include "DebugConsole.h"
#include "ThreadLock.h"
AdobeAirHook* AdobeAirHook::instance = NULL;
const char encodePattern[16] = {0x8B, 0xCE, 0xE8, 0xA6, 0xFF, 0xFF, 0xFF, 0x83, 0xF8, 0xFF, 0x74, 0x16, 0x03, 0xF8, 0x3B, 0xBE};
const char decodePattern[12] = {0x8B, 0xCE, 0xE8, 0x7F, 0xF7, 0xFF, 0xFF, 0x83, 0xF8, 0xFF, 0x89, 0x86};
AdobeAirHook::AdobeAirHook()
{
this->airModule = new ExecutableModule(L"Adobe AIR.dll");
this->socketLock = new ThreadLock();
this->socketLock->enter();
this->socketLock->leave();
}
AdobeAirHook::~AdobeAirHook()
{
this->socketLock->enter();
this->socketLock->leave();
delete this->airModule;
delete this->socketLock;
}
void AdobeAirHook::execute()
{
DebugConsole::getInstance();
do
{
if (!this->airModule->isValid())
{
printf("invalid module!\n");
break;
}
DWORD encodeAddress = this->airModule->findPattern(encodePattern, 16);
DWORD decodeAddress = this->airModule->findPattern(decodePattern, 12);
if (!encodeAddress || !decodeAddress)
{
printf("invalid encode/decode address!\n");
break;
}
encodeAddress += 2; decodeAddress += 2; //call is 2 bytes past start of each pattern
encodeHookFunction = this->airModule->addCallHook("encode", encodeAddress, &myEncode);
if (!encodeHookFunction)
{
printf("encode hook failed!\n");
break;
}
decodeHookFunction = this->airModule->addCallHook("decode", decodeAddress, &myDecode);
if (!encodeHookFunction)
{
printf("encode hook failed!\n");
break;
}
printf("hooks installed!\n");
return; //success
} while (0);
//error is here
this->terminate();
}
void AdobeAirHook::terminate()
{
this->airModule->clearCallHooks();
DebugConsole::deleteInstance();
}
DWORD AdobeAirHook::getEncodeHookFunction()
{
return this->encodeHookFunction;
}
DWORD AdobeAirHook::getDecodeHookFunction()
{
return this->decodeHookFunction;
}
void AdobeAirHook::encodeHookCallback(const unsigned char* buffer, unsigned int size)
{
if (size == 0xFFFFFFFF) return;
this->socketLock->enter();
DebugConsole::getInstance()->dumpBuffer(buffer, size, "Outgoing packet collected");
this->socketLock->leave();
}
void AdobeAirHook::decodeHookCallback(const unsigned char* buffer, unsigned int size)
{
if (size == 0xFFFFFFFF) return;
this->socketLock->enter();
DebugConsole::getInstance()->dumpBuffer(buffer, size, "Incoming packet collected");
this->socketLock->leave();
}
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include <Windows.h>
class ExecutableModule;
class ThreadLock;
class PacketCollector;
class AdobeAirHook
{
public:
static AdobeAirHook* getInstance()
{
if (!AdobeAirHook::instance)
AdobeAirHook::instance = new AdobeAirHook();
return AdobeAirHook::instance;
}
static void deleteInstance()
{
if (AdobeAirHook::instance)
{
delete AdobeAirHook::instance;
AdobeAirHook::instance = NULL;
}
}
void execute();
void terminate();
DWORD getEncodeHookFunction();
DWORD getDecodeHookFunction();
void encodeHookCallback(const unsigned char* buffer, unsigned int size);
void decodeHookCallback(const unsigned char* buffer, unsigned int size);
private:
AdobeAirHook();
~AdobeAirHook();
static AdobeAirHook* instance;
ExecutableModule* airModule;
ThreadLock* socketLock;
DWORD encodeHookFunction, decodeHookFunction;
};
+101
View File
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{D041E046-6A67-413E-869B-14E3CE06A21B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Chapter8_AdobeAirHook</RootNamespace>
<ProjectName>Chapter8_AdobeAirHook</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;ADOBEAIRHOOK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ADOBEAIRHOOK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="AdobeAirHook.h" />
<ClInclude Include="AdobeAirHookCallbacks.h" />
<ClInclude Include="DebugConsole.h" />
<ClInclude Include="ExecutableModule.h" />
<ClInclude Include="ThreadLock.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\Chapter7_CodeInjection_DLL\dllmain.cpp" />
<ClCompile Include="AdobeAirHook.cpp" />
<ClCompile Include="DebugConsole.cpp" />
<ClCompile Include="dllmain.cpp">
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsManaged>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="ExecutableModule.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Header Files\Utils">
<UniqueIdentifier>{ec0c29ac-a76b-41e3-a066-77cd77437405}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Utils">
<UniqueIdentifier>{e2f43ad2-b882-46d5-ad16-5f30255ba5b5}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Core">
<UniqueIdentifier>{1a0cd66b-65d6-498a-92a4-8dcf66820d1a}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Core">
<UniqueIdentifier>{93221b58-954d-43c9-bdf5-2f94f2022512}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="DebugConsole.h">
<Filter>Header Files\Utils</Filter>
</ClInclude>
<ClInclude Include="ThreadLock.h">
<Filter>Header Files\Utils</Filter>
</ClInclude>
<ClInclude Include="AdobeAirHook.h">
<Filter>Header Files\Core</Filter>
</ClInclude>
<ClInclude Include="AdobeAirHookCallbacks.h">
<Filter>Header Files\Core</Filter>
</ClInclude>
<ClInclude Include="ExecutableModule.h">
<Filter>Header Files\Core</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DebugConsole.cpp">
<Filter>Source Files\Utils</Filter>
</ClCompile>
<ClCompile Include="AdobeAirHook.cpp">
<Filter>Source Files\Core</Filter>
</ClCompile>
<ClCompile Include="ExecutableModule.cpp">
<Filter>Source Files\Core</Filter>
</ClCompile>
<ClCompile Include="..\Chapter7_CodeInjection_DLL\dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
@@ -0,0 +1,68 @@
#include "AdobeAirHook.h"
#include <Windows.h>
#include <iostream>
DWORD __stdcall reportEncode(const unsigned char* buffer, unsigned int size, unsigned int loopCounter)
{
if (loopCounter == 0)
AdobeAirHook::getInstance()->encodeHookCallback(buffer, size);
return AdobeAirHook::getInstance()->getEncodeHookFunction();
}
DWORD __stdcall getDecode()
{
return AdobeAirHook::getInstance()->getDecodeHookFunction();
}
void __stdcall reportDecode(const unsigned char* buffer, unsigned int size)
{
AdobeAirHook::getInstance()->decodeHookCallback(buffer, size);
}
void __declspec(naked) myEncode()
{
__asm
{
MOV EAX, DWORD PTR SS:[ESP + 0x4] // get buffer
MOV EDX, DWORD PTR DS:[ESI + 0x3C58] // get full size
PUSH ECX // store ecx
PUSH EDI // push current pos
PUSH EDX // push size
PUSH EAX // push buffer
CALL reportEncode // report the encode call
POP ECX // restore ecx
JMP EAX // jump to original function (returned by reportEncode)
}
}
void __declspec(naked) myDecode()
{
__asm
{
MOV EAX, DWORD PTR SS:[ESP + 0x4] // get second arg
MOV EDX, DWORD PTR SS:[ESP + 0x8] // get first arg
PUSH EDX // re-push first arg ------------------.
PUSH EAX // re-push second arg -----------------|
PUSH ECX // store ecx -----------------------. |
CALL getDecode // get the function to call | |
POP ECX // restore ecx ----------------------' |
CALL EAX // call the original function ---------'
MOV EDX, DWORD PTR SS:[ESP + 0x4] // get first arg, its the buffer now
PUSH EAX // store eax ----------------------------.
PUSH ECX // store ecx --------------------------. |
PUSH EAX // push the size -------------------. | |
PUSH EDX // push the buffer -----------------| | |
CALL reportDecode // report the results now -' | |
POP ECX // restore ecx -------------------------' |
POP EAX // restore eax ---------------------------'
RETN 8 // return
}
}
+109
View File
@@ -0,0 +1,109 @@
#include "DebugConsole.h"
#include <fcntl.h>
#include <io.h>
#include <iostream>
#include <fstream>
DebugConsole* DebugConsole::instance = NULL;;
DebugConsole::DebugConsole()
{
this->show();
}
DebugConsole::~DebugConsole()
{
this->hide();
}
void DebugConsole::show()
{
using namespace std;
auto out = freopen("C:\\leaguelog.txt","w",stdout);
return;
static const WORD MAX_CONSOLE_LINES = 5000;
int hConHandle;
long lStdHandle;
CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;
// allocate a console for this app
AllocConsole();
// set the screen buffer to be big enough to let us scroll text
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = MAX_CONSOLE_LINES;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
// redirect unbuffered STDOUT to the console
lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen( hConHandle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
// redirect unbuffered STDIN to the console
lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen( hConHandle, "r" );
*stdin = *fp;
setvbuf( stdin, NULL, _IONBF, 0 );
// redirect unbuffered STDERR to the console
lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen( hConHandle, "w" );
*stderr = *fp;
setvbuf( stderr, NULL, _IONBF, 0 );
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
// point to console as well
ios::sync_with_stdio();
}
void DebugConsole::hide()
{
FreeConsole();
}
void DebugConsole::dumpBuffer(const char* buffer, unsigned int size, const char* title)
{
printf("%s> %d bytes", title, size);
for (unsigned int o = 0; o < ceil(size / 16.0f); o++)
{
printf("\n ");
for (unsigned int t = 0; t < 2; t++)
{
for (unsigned int i = 0; i < 16; i++)
{
unsigned char val = buffer[(o * 16) + i] & 0xFF;
if (t == 0)
{
if (i == 8)
printf("| ");
if ((o * 16) + i < size)
printf("%02X ", val);
else
printf(" ", val);
}
else if ((o * 16) + i < size)
{
if (val > ' ' && val <= '~')
printf("%c", val);
else
printf(".");
}
else
printf(" ");
}
printf("|");
}
}
printf("\n");
}
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include <windows.h>
#include <stdio.h>
#ifdef _DEBUG
#define LOG(message) printf("%s (%d): %s\n", __FUNCTION__, __LINE__, message)
#else
#define LOG(message)
#endif
class DebugConsole
{
public:
static DebugConsole* getInstance()
{
if (!DebugConsole::instance)
DebugConsole::instance = new DebugConsole();
return DebugConsole::instance;
}
static void deleteInstance()
{
if (DebugConsole::instance)
{
delete DebugConsole::instance;
DebugConsole::instance = NULL;
}
}
void dumpBuffer(const char* buffer, unsigned int size, const char* title);
void dumpBuffer(char* buffer, unsigned int size, const char* title) { this->dumpBuffer((const char*)buffer, size, title); }
void dumpBuffer(unsigned char* buffer, unsigned int size, const char* title) { this->dumpBuffer((const char*)buffer, size, title); }
void dumpBuffer(const unsigned char* buffer, unsigned int size, const char* title) { this->dumpBuffer((const char*)buffer, size, title); }
private:
static DebugConsole* instance;
DebugConsole();
~DebugConsole();
void show();
void hide();
};
+116
View File
@@ -0,0 +1,116 @@
#include "ExecutableModule.h"
#include <tlhelp32.h>
#include <string>
ExecutableModule::ExecutableModule(const wchar_t* moduleName) : name(moduleName), base(0), size(0), oldProtect(0)
{
this->getModuleInformation();
}
ExecutableModule::~ExecutableModule(void)
{
}
DWORD ExecutableModule::findPattern(const char* pattern, unsigned int patternLength, unsigned int occurance)
{
unsigned int ocur = 0;
for (DWORD adr = this->base; adr < this->base + this->size - patternLength; adr++)
{
if (memcmp((LPVOID)pattern, (LPVOID)adr, patternLength) == 0)
{
ocur++;
if (ocur == occurance)
return adr;
}
}
return 0;
}
DWORD ExecutableModule::addCallHook(const char* name, DWORD address, LPVOID function)
{
callHookInformation hook;
hook.hookAtAddress = address;
hook.newFuncAddress = (DWORD)function;
if (this->readMemory<BYTE>(hook.hookAtAddress) != 0xE8)
{
printf("Hook %s is not on a valid opcode (saw 0x%02x at address 0x%08x)!\n",
name,
this->readMemory<BYTE>(hook.hookAtAddress),
hook.hookAtAddress);
return 0;
}
bool hooked = true;
this->allowOPCodeModification(hook.hookAtAddress + 1, 4);
{
hook.oldFuncOffset = this->readMemory<DWORD>(hook.hookAtAddress + 1);
if (!this->writeMemory<DWORD>(hook.hookAtAddress + 1, hook.newFuncAddress - hook.hookAtAddress - 5))
{
printf("Failed to write memory for hook %s!\n", name);
hooked = false;
}
}
this->disallowOPCodeModification(hook.hookAtAddress + 1, 4);
if (!hooked)
return 0;
this->callHooks.push_back(hook);
return hook.getOldFunctionAddress();
}
void ExecutableModule::clearCallHooks()
{
for (auto hook = this->callHooks.begin(); hook != this->callHooks.end(); hook++)
{
this->allowOPCodeModification(hook->hookAtAddress + 1, 4);
this->writeMemory<DWORD>(hook->hookAtAddress + 1, hook->oldFuncOffset);
this->disallowOPCodeModification(hook->hookAtAddress + 1, 4);
}
this->callHooks.clear();
}
void ExecutableModule::getModuleInformation()
{
MODULEENTRY32 entry;
entry.dwSize = sizeof(MODULEENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, NULL);
if (Module32First(snapshot, &entry) == TRUE)
{
while (Module32Next(snapshot, &entry) == TRUE)
{
std::wstring binaryPath = entry.szModule;
if (binaryPath.find(this->name) != std::wstring::npos)
{
this->size = (DWORD)entry.modBaseSize;
this->base = (DWORD)entry.modBaseAddr;
break;
}
}
}
CloseHandle(snapshot);
}
void ExecutableModule::allowOPCodeModification(DWORD address, unsigned int size)
{
this->oldProtect = this->setRegionProtection(address, size, PAGE_EXECUTE_READWRITE);
}
void ExecutableModule::disallowOPCodeModification(DWORD address, unsigned int size)
{
this->setRegionProtection(address, size, (oldProtect) ? oldProtect : PAGE_WRITECOPY);
}
DWORD ExecutableModule::setRegionProtection(DWORD address, unsigned int size, DWORD protection)
{
DWORD oldProtection;
VirtualProtect((LPVOID)address, size, protection, &oldProtection);
return oldProtection;
}
+71
View File
@@ -0,0 +1,71 @@
#pragma once
#include <Windows.h>
#include <list>
class ExecutableModule
{
public:
ExecutableModule(const wchar_t* moduleName);
~ExecutableModule();
DWORD findPattern(const char* pattern, unsigned int patternLength, unsigned int occurance = 1);
DWORD addCallHook(const char* name, DWORD address, LPVOID function);
void clearCallHooks();
bool isValid() { return this->base > 0 && this->size > 0; }
DWORD getBase() { return this->base; }
DWORD getSize() { return this->size; }
template <class T>
T* pointMemory(DWORD address)
{
return (T*)address;
}
template <class T>
T readMemory(DWORD address)
{
if (address < this->base || address > (this->base + this->size))
{
T ret;
memset(&ret, 0, sizeof(T));
return ret;
}
return *(T*)address;
}
template <class T>
bool writeMemory(DWORD address, T value)
{
if (address < this->base || address > (this->base + this->size))
return false;
*(T*)(address) = value;
return true;
}
private:
struct callHookInformation
{
const char* name;
DWORD hookAtAddress;
DWORD newFuncAddress;
DWORD oldFuncOffset;
DWORD getOldFunctionAddress()
{
return hookAtAddress + oldFuncOffset + 5;
}
};
const wchar_t* name;
DWORD base, size, oldProtect;
std::list<callHookInformation> callHooks;
void getModuleInformation();
void allowOPCodeModification(DWORD address, unsigned int size);
void disallowOPCodeModification(DWORD address, unsigned int size);
DWORD setRegionProtection(DWORD address, unsigned int size, DWORD protection);
};
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#include <Windows.h>
class ThreadLock
{
public:
ThreadLock()
{
InitializeCriticalSection(&cs);
}
~ThreadLock(){
DeleteCriticalSection(&cs);
}
void enter()
{
EnterCriticalSection(&cs);
}
void leave()
{
LeaveCriticalSection(&cs);
}
private:
CRITICAL_SECTION cs;
};
+25
View File
@@ -0,0 +1,25 @@
#include <Windows.h>
#include "AdobeAirHook.h"
AdobeAirHook* hook;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
AdobeAirHook::getInstance()->execute();
break;
case DLL_PROCESS_DETACH:
AdobeAirHook::getInstance()->terminate();
AdobeAirHook::deleteInstance();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{ACA1A8FF-6D8C-407A-983C-929D6F958D83}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Chapter8_ControlFlow</RootNamespace>
<ProjectName>Chapter8_ControlFlow</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<FixedBaseAddress>
</FixedBaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main-controlFlow.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+321
View File
@@ -0,0 +1,321 @@
#include <iostream>
#include <Windows.h>
#include <vector>
//helpers
template<typename T>
T readMemory(DWORD address)
{
return *((T*)address);
}
template<typename T>
T* pointMemory(DWORD address)
{
return ((T*)address);
}
template<typename T>
void writeMemory(DWORD address, T value)
{
*((T*)address) = value;
}
template<typename T>
DWORD protectMemory(DWORD address, DWORD prot)
{
DWORD oldProt;
VirtualProtect((LPVOID)address, sizeof(T), prot, &oldProt);
return oldProt;
}
// NOP example code
struct _creature
{
_creature(int hb, bool e, bool c) : healthBar(hb), isEnemy(e), isCloaked(c) {}
int healthBar;
bool isEnemy, isCloaked;
};
std::vector<_creature> creatures;
int creaturesDrawn = 0;
void drawHealthBar(int healthbar)
{
creaturesDrawn++; // make a note that we drew it
Sleep(healthbar); // just an example, we're not really doing anything
}
void drawCreatureHealthBarExample()
{
for (int i = 0; i < creatures.size(); i++) {
auto c = creatures[i];
if (c.isEnemy && c.isCloaked) continue;
drawHealthBar(c.healthBar);
}
}
template<int SIZE>
void writeNop(DWORD address)
{
auto oldProtection = protectMemory<BYTE[SIZE]>(address, PAGE_EXECUTE_READWRITE);
for (int i = 0; i < SIZE; i++)
writeMemory<BYTE>(address + i, 0x90);
protectMemory<BYTE[SIZE]>(address, oldProtection);
}
DWORD getAddressForNOP(DWORD functionStart)
{
// i cannot hard-code any addresses from within this application,
// as they may change upon re-compile. For this reason, I'll locate
// the address of the JMP that I want to replace programatically
// by scanning for the 'JMP -67' statement (bytes 0xEB 0xBD)
// somewhere within 1000 bytes of the start of the function
auto oldProtection = protectMemory<BYTE[1000]>(functionStart, PAGE_EXECUTE_READ); // make sure memory is readable, just incase
auto mem = pointMemory<BYTE>(functionStart);
DWORD ret = 0;
for (int i = 0; i < 999; i++) {
if (mem[i] == 0xEB && mem[i+1] == 0xBD) {
ret = functionStart + i;
break;
}
}
protectMemory<BYTE[1000]>(functionStart, oldProtection); // restore old memory protection
return ret;
}
void NOPExample()
{
// nop it
auto address = getAddressForNOP((DWORD)&drawCreatureHealthBarExample);
if (address)
writeNop<2>(address);
// add some make creatures
creatures.push_back(_creature(0, true, true));
creatures.push_back(_creature(0, true, false));
creatures.push_back(_creature(0, false, true));
creatures.push_back(_creature(0, false, false));
//call the function
drawCreatureHealthBarExample();
//check if NOP worked
if (creaturesDrawn == 4)
printf("NOP worked! Drew all creatures!\n");
else
printf("NOP failed! :( Only drew %d/4 creatures.\n", creaturesDrawn);
}
// call hook
DWORD functionToBeHooked(DWORD arg1, DWORD arg2, DWORD arg3)
{
if (arg1 == arg2 && arg2 == 3 && arg3 == 4)
printf("Call hook worked! Parameters intercepted and changed!\n");
else
printf("Call hook failed!\n");
return 0;
}
void whereHookGoes()
{
functionToBeHooked(0, 0, 0);
}
DWORD getAddressForCallHook(DWORD functionStart)
{
// same story as with NOP, except we're looking for the first CALL (0xE8)
auto oldProtection = protectMemory<BYTE[1000]>(functionStart, PAGE_EXECUTE_READ); // make sure memory is readable, just incase
auto mem = pointMemory<BYTE>(functionStart);
DWORD ret = 0;
for (int i = 0; i < 1000; i++) {
if (mem[i] == 0xE8) {
ret = functionStart + i;
break;
}
}
protectMemory<BYTE[1000]>(functionStart, oldProtection); // restore old memory protection
return ret;
}
typedef DWORD (__cdecl _origFunc)(DWORD arg1, DWORD arg2, DWORD arg3);
_origFunc* originalFunction;
DWORD __cdecl someNewFunction(DWORD arg1, DWORD arg2, DWORD arg3)
{
return originalFunction(3, 3, 4);
}
DWORD callHook(DWORD hookAt, DWORD newFunc)
{
DWORD newOffset = newFunc - hookAt - 5;
auto oldProtection = protectMemory<DWORD>(hookAt + 1, PAGE_EXECUTE_READWRITE);
DWORD originalOffset = readMemory<DWORD>(hookAt + 1);
writeMemory<DWORD>(hookAt + 1, newOffset);
protectMemory<DWORD>(hookAt + 1, oldProtection);
return originalOffset + hookAt + 5;
}
void callHookExample()
{
auto address = getAddressForCallHook((DWORD)&whereHookGoes);
if (address)
originalFunction = (_origFunc*)callHook(address, (DWORD)&someNewFunction);
whereHookGoes();
}
// vf table hook
class someBaseClass
{
public:
virtual DWORD someFunction(DWORD arg1) { return 0; }
};
class someClass : public someBaseClass
{
public:
virtual DWORD someFunction(DWORD arg1)
{
if (arg1 == 1)
printf(" VF Table hook worked! Parameters intercepted and changed!\n");
else
printf(" VF Table hook failed!\n");
return 0;
}
};
DWORD originalVFFunction;
DWORD __stdcall someNewVFFunction(DWORD arg1)
{
static DWORD _this, _ret;
__asm MOV _this, ECX
printf("VFHook pre\n");
__asm {
PUSH 1
MOV ECX, _this
CALL [originalVFFunction]
MOV _ret, EAX
}
printf("VFHook Post\n");
__asm MOV ECX, _this
return _ret;
}
DWORD hookVF(DWORD classInst, DWORD funcIndex, DWORD newFunc)
{
DWORD VFTable = readMemory<DWORD>(classInst);
DWORD hookAddress = VFTable + funcIndex * sizeof(DWORD);
auto oldProtection = protectMemory<DWORD>(hookAddress, PAGE_READWRITE);
DWORD originalFunc = readMemory<DWORD>(hookAddress);
writeMemory<DWORD>(hookAddress, newFunc);
protectMemory<DWORD>(hookAddress, oldProtection);
return originalFunc;
}
void VFHookExample()
{
someClass* inst = new someClass();
originalVFFunction = hookVF((DWORD)inst, 0, (DWORD)&someNewVFFunction);
inst->someFunction(0);
delete inst;
}
// iat hook
DWORD hookIAT(const char* functionName, DWORD newFunctionAddress)
{
DWORD baseAddress = (DWORD)GetModuleHandle(NULL);
auto dosHeader = pointMemory<IMAGE_DOS_HEADER>(baseAddress);
if (dosHeader->e_magic != 0x5A4D)
return 0;
auto optHeader = pointMemory<IMAGE_OPTIONAL_HEADER>(baseAddress + dosHeader->e_lfanew + 24);
if (optHeader->Magic != 0x10B)
return 0;
if (optHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size == 0 ||
optHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress == 0)
return 0;
IMAGE_IMPORT_DESCRIPTOR* importDescriptor = pointMemory<IMAGE_IMPORT_DESCRIPTOR>(baseAddress + optHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); //what is the rule of adding them?
while (importDescriptor->FirstThunk)
{
int n = 0;
IMAGE_THUNK_DATA* thunkData = pointMemory<IMAGE_THUNK_DATA>(baseAddress + importDescriptor->OriginalFirstThunk);
while (thunkData->u1.Function)
{
char* importFunctionName = pointMemory<char>(baseAddress + (DWORD)thunkData->u1.AddressOfData + 2);
if (strcmp(importFunctionName, functionName) == 0)
{
auto vfTable = pointMemory<DWORD>(baseAddress + importDescriptor->FirstThunk);
DWORD original = vfTable[n];
auto oldProtection = protectMemory<DWORD>((DWORD)&vfTable[n], PAGE_READWRITE);
vfTable[n] = newFunctionAddress;
protectMemory<DWORD>((DWORD)&vfTable[n], oldProtection);
return original;
}
n++;
thunkData++;
}
importDescriptor++;
}
return 0;
}
typedef VOID (WINAPI _origSleep)(DWORD ms);
_origSleep* originalSleep;
VOID WINAPI newSleepFunction(DWORD ms)
{
if (ms > 100)
printf("Sleep hook worked! Denied sleep for %d miliseconds.\n", ms);
else
originalSleep(ms);
}
void IATHookExample()
{
originalSleep = (_origSleep*)hookIAT("Sleep", (DWORD)&newSleepFunction);
Sleep(1234);
}
int main(void)
{
// due to differences in the way functions are compiled between
// DEBUG and RELEASE builds, this example will only work in RELEASE.
// This is only because of the way I'm finding the address to be NOP'd
NOPExample();
callHookExample();
VFHookExample();
IATHookExample();
while (true) // stay busy
{
Sleep(100);
}
}
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{E621BD23-8A39-4BA3-9DB0-191661BBF6C9}</ProjectGuid>
<RootNamespace>Chapter8_Direct3DApplication</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IntDir>$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IntDir>$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
+298
View File
@@ -0,0 +1,298 @@
/*
This is just a test application for the Direct3D hook proof-of-concept.
The code for this application is from http://www.directxtutorial.com/
The only thing I added was 'LoadLibrary("Chapter8_Direct3DHook.dll");'
to load the POC hook.
*/
// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
// define the screen resolution
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
// include the Direct3D Library files
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
// global declarations
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
LPDIRECT3DINDEXBUFFER9 i_buffer = NULL;
// function prototypes
void initD3D(HWND hWnd);
void render_frame(void);
void cleanD3D(void);
void init_graphics(void);
void init_light(void); // sets up the light and the material
struct CUSTOMVERTEX {FLOAT X, Y, Z; D3DVECTOR NORMAL;};
#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_NORMAL)
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = "WindowClass";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL, "WindowClass", "Our Direct3D Program",
WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
// set up and initialize Direct3D
initD3D(hWnd);
// enter the main loop:
MSG msg;
while(TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_QUIT)
break;
render_frame();
}
// clean up DirectX and COM
cleanD3D();
return msg.wParam;
}
// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
// create a device class using this information and the info from the d3dpp stuct
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
init_graphics(); // call the function to initialize the cube
init_light(); // call the function to initialize the light and material
d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE); // turn on the 3D lighting
d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE); // turn on the z-buffer
d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(15, 15, 15)); // ambient light
LoadLibrary("Chapter8_Direct3DHook.dll");
}
// this is the function used to render a single frame
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
d3ddev->BeginScene();
// select which vertex format we are using
d3ddev->SetFVF(CUSTOMFVF);
// set the view transform
D3DXMATRIX matView;
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (0.0f, 8.0f, 25.0f), // the camera position
&D3DXVECTOR3 (0.0f, 0.0f, 0.0f), // the look-at position
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView);
// set the projection transform
D3DXMATRIX matProjection;
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT,
1.0f, // the near view-plane
100.0f); // the far view-plane
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);
// set the world transform
static float index = 0.0f; index+=0.03f;
D3DXMATRIX matRotateY;
D3DXMatrixRotationY(&matRotateY, index);
d3ddev->SetTransform(D3DTS_WORLD, &(matRotateY));
// select the vertex and index buffers to use
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->SetIndices(i_buffer);
// draw the cube
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12);
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}
// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
v_buffer->Release();
i_buffer->Release();
d3ddev->Release();
d3d->Release();
}
// this is the function that puts the 3D models into video RAM
void init_graphics(void)
{
// create the vertices using the CUSTOMVERTEX struct
CUSTOMVERTEX vertices[] =
{
{ -3.0f, -3.0f, 3.0f, 0.0f, 0.0f, 1.0f, }, // side 1
{ 3.0f, -3.0f, 3.0f, 0.0f, 0.0f, 1.0f, },
{ -3.0f, 3.0f, 3.0f, 0.0f, 0.0f, 1.0f, },
{ 3.0f, 3.0f, 3.0f, 0.0f, 0.0f, 1.0f, },
{ -3.0f, -3.0f, -3.0f, 0.0f, 0.0f, -1.0f, }, // side 2
{ -3.0f, 3.0f, -3.0f, 0.0f, 0.0f, -1.0f, },
{ 3.0f, -3.0f, -3.0f, 0.0f, 0.0f, -1.0f, },
{ 3.0f, 3.0f, -3.0f, 0.0f, 0.0f, -1.0f, },
{ -3.0f, 3.0f, -3.0f, 0.0f, 1.0f, 0.0f, }, // side 3
{ -3.0f, 3.0f, 3.0f, 0.0f, 1.0f, 0.0f, },
{ 3.0f, 3.0f, -3.0f, 0.0f, 1.0f, 0.0f, },
{ 3.0f, 3.0f, 3.0f, 0.0f, 1.0f, 0.0f, },
{ -3.0f, -3.0f, -3.0f, 0.0f, -1.0f, 0.0f, }, // side 4
{ 3.0f, -3.0f, -3.0f, 0.0f, -1.0f, 0.0f, },
{ -3.0f, -3.0f, 3.0f, 0.0f, -1.0f, 0.0f, },
{ 3.0f, -3.0f, 3.0f, 0.0f, -1.0f, 0.0f, },
{ 3.0f, -3.0f, -3.0f, 1.0f, 0.0f, 0.0f, }, // side 5
{ 3.0f, 3.0f, -3.0f, 1.0f, 0.0f, 0.0f, },
{ 3.0f, -3.0f, 3.0f, 1.0f, 0.0f, 0.0f, },
{ 3.0f, 3.0f, 3.0f, 1.0f, 0.0f, 0.0f, },
{ -3.0f, -3.0f, -3.0f, -1.0f, 0.0f, 0.0f, }, // side 6
{ -3.0f, -3.0f, 3.0f, -1.0f, 0.0f, 0.0f, },
{ -3.0f, 3.0f, -3.0f, -1.0f, 0.0f, 0.0f, },
{ -3.0f, 3.0f, 3.0f, -1.0f, 0.0f, 0.0f, },
};
// create a vertex buffer interface called v_buffer
d3ddev->CreateVertexBuffer(24*sizeof(CUSTOMVERTEX),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_buffer,
NULL);
VOID* pVoid; // a void pointer
// lock v_buffer and load the vertices into it
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
v_buffer->Unlock();
// create the indices using an int array
short indices[] =
{
0, 1, 2, // side 1
2, 1, 3,
4, 5, 6, // side 2
6, 5, 7,
8, 9, 10, // side 3
10, 9, 11,
12, 13, 14, // side 4
14, 13, 15,
16, 17, 18, // side 5
18, 17, 19,
20, 21, 22, // side 6
22, 21, 23,
};
// create an index buffer interface called i_buffer
d3ddev->CreateIndexBuffer(36*sizeof(short),
0,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&i_buffer,
NULL);
// lock i_buffer and load the indices into it
i_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, indices, sizeof(indices));
i_buffer->Unlock();
}
void init_light()
{
D3DMATERIAL9 material;
ZeroMemory(&material, sizeof(D3DMATERIAL9));
material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
d3ddev->SetMaterial(&material);
}
@@ -0,0 +1,216 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="LoLOracle Hook"
ProjectGUID="{784C482A-F6EC-4BCB-851E-07BE782BB040}"
RootNamespace="LoLOracleHook"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;C:\Program Files (x86)\Microsoft Research\ms detours 1.5 src\src&quot;;&quot;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LOLORACLEHOOK_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="detours.lib"
OutputFile="$(OutDir)\loloracle.dll"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;C:\Program Files (x86)\Microsoft Research\ms detours 1.5 src\lib&quot;"
GenerateDebugInformation="true"
SubSystem="2"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;C:\Program Files (x86)\Microsoft Research\ms detours 1.5 src\src&quot;;&quot;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LOLORACLEHOOK_EXPORTS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="detours.lib"
OutputFile="$(OutDir)\loloracle.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;C:\Program Files (x86)\Microsoft Research\ms detours 1.5 src\lib&quot;"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\CDirectX.cpp"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\CDirectX.h"
>
</File>
<File
RelativePath=".\main.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>Chapter8_Direct3DHook</ProjectName>
<ProjectGuid>{784C482A-F6EC-4BCB-851E-07BE782BB040}</ProjectGuid>
<RootNamespace>Chapter8_Direct3DHook</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)\BuildTemp\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)\BuildTemp\$(ProjectName)_$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<ExecutablePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ExecutablePath)</ExecutablePath>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectName)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>C:\Program Files (x86)\Microsoft Research\ms detours 1.5 src\src;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LOLORACLEHOOK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>detours.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>C:\Program Files (x86)\Microsoft Research\ms detours 1.5 src\src;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;LOLORACLEHOOK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="DirectXHook.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DirectXHook.h" />
<ClInclude Include="DirectXHookCallbacks.h" />
<ClInclude Include="memory.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DirectXHook.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="memory.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DirectXHook.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DirectXHookCallbacks.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
+257
View File
@@ -0,0 +1,257 @@
#include "DirectXHook.h"
#include "DirectXHookCallbacks.h"
#include "memory.h"
DirectXHook* DirectXHook::instance = NULL;
unsigned char* DirectXHook::originalEndSceneCode = NULL;
DWORD DirectXHook::endSceneAddress = NULL;
LPDIRECT3DDEVICE9 DirectXHook::hookedDevice = NULL;
_reset DirectXHook::origReset = NULL;
_endScene DirectXHook::origEndScene = NULL;
_drawPrimitive DirectXHook::origDrawPrimitive = NULL;
_drawIndexedPrimitive DirectXHook::origDrawIndexedPrimitive = NULL;
bool DirectXHook::hookReady = false;
bool DirectXHook::hookReadyPre = false;
void DirectXHook::initialize()
{
while (!GetModuleHandleA("d3d9.dll"))
Sleep(10);
DirectXHook::endSceneAddress = this->locateEndScene();
if (DirectXHook::endSceneAddress)
DirectXHook::originalEndSceneCode = hookWithJump(DirectXHook::endSceneAddress, (DWORD)&endSceneTrampoline);
while (!DirectXHook::hookReadyPre)
Sleep(10);
DirectXHook::hookReady = true;
}
void DirectXHook::addDrawFrameCallback(_drawFrameCallback cb)
{
if (!DirectXHook::hookReady)
this->drawFrameCallbacks.push_back(cb);
}
void DirectXHook::addDrawPrimitiveCallback(_drawPrimitiveCallback cb)
{
if (!DirectXHook::hookReady)
this->drawPrimitiveCallbacks.push_back(cb);
}
void DirectXHook::addDrawIndexedPrimitiveCallback(_drawIndexedPrimitiveCallback cb)
{
if (!DirectXHook::hookReady)
this->drawIndexedPrimitiveCallbacks.push_back(cb);
}
LPDIRECT3DTEXTURE9 DirectXHook::addTexture(std::wstring imagePath)
{
if (DirectXHook::hookReady)
{
LPDIRECT3DTEXTURE9 texture;
if (D3DXCreateTextureFromFile(this->hookedDevice, imagePath.c_str(), &texture) < 0)
return NULL;
return texture;
}
return NULL;
}
int DirectXHook::addSpriteImage(std::wstring imagePath)
{
if (DirectXHook::hookReady)
{
LPDIRECT3DTEXTURE9 texture;
LPD3DXSPRITE sprite;
D3DSURFACE_DESC desc;
if (D3DXCreateTextureFromFile(this->hookedDevice, imagePath.c_str(), &texture) < 0)
return -1;
if(D3DXCreateSprite(this->hookedDevice, &sprite) < 0)
return -1;
texture->GetLevelDesc(0, &desc);
this->imageBitmaps.push_back(texture);
this->imageSprites.push_back(sprite);
this->imageDescriptions.push_back(desc);
return this->imageBitmaps.size()-1;
}
return -1;
}
void DirectXHook::drawText(int x, int y, D3DCOLOR color, const char *text, ...)
{
RECT rect;
va_list va_alist;
char buf[256] = {0};
va_start (va_alist, text);
_vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), text, va_alist);
va_end (va_alist);
rect.left=x+1;
rect.top=y+1;
rect.right=rect.left+1000;
rect.bottom=rect.top+1000;
this->font->DrawTextA(NULL, buf, -1, &rect, 0, D3DCOLOR_ARGB(255, 10, 10, 10));
rect.left--;
rect.top--;
this->font->DrawTextA(NULL, buf, -1, &rect, 0, color);
}
void DirectXHook::drawSpriteImage(int imageID, int x, int y, int w, int h)
{
if (imageID >= this->imageBitmaps.size() || imageID < 0)
return;
D3DSURFACE_DESC desc = this->imageDescriptions[imageID];
D3DXVECTOR2 scaleFactor;
if (h == -1 && w == -1)
{
scaleFactor = D3DXVECTOR2(1.0, 1.0);
}
else if (h == -1)
{
float scale = (float)w / (float)desc.Width;
scaleFactor = D3DXVECTOR2(scale, scale);
}
else if (w == -1)
{
float scale = (float)h / (float)desc.Height;
scaleFactor = D3DXVECTOR2(scale, scale);
}
else
scaleFactor = D3DXVECTOR2((float)w / (float)desc.Width, (float)h / (float)desc.Height);
D3DXMATRIX spriteMatrix;
D3DXMatrixTransformation2D(&spriteMatrix, NULL, 0, &scaleFactor, NULL, 0, NULL);
D3DXVECTOR3 imagepos((float)x * (1.0f / scaleFactor.x), (float)y * (1.0f / scaleFactor.y), 0);
this->imageSprites[imageID]->Begin(D3DXSPRITE_ALPHABLEND);
this->imageSprites[imageID]->SetTransform(&spriteMatrix);
this->imageSprites[imageID]->Draw(this->imageBitmaps[imageID], NULL, NULL, &imagepos, 0xFFFFFFFF);
this->imageSprites[imageID]->End();
}
DWORD DirectXHook::initHookCallback(LPDIRECT3DDEVICE9 device)
{
DirectXHook::hookedDevice = device;
while (DirectXHook::originalEndSceneCode == NULL){}
unhookWithJump(DirectXHook::endSceneAddress, originalEndSceneCode);
D3DXCreateFont(DirectXHook::hookedDevice, 15, 0, FW_BOLD, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial", &this->font);
this->placeHooks();
DirectXHook::hookReadyPre = true;
return DirectXHook::endSceneAddress;
}
DX_API DirectXHook::resetHookCallback(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
{
auto result = origReset(pDevice, pPresentationParameters);
if (result == D3D_OK)
this->onLostDevice();
return result;
}
DX_API DirectXHook::endSceneHookCallback(LPDIRECT3DDEVICE9 pDevice)
{
for (int i = 0; i < drawFrameCallbacks.size(); i++)
drawFrameCallbacks[i](this, pDevice);
auto result = origEndScene(pDevice);
this->placeHooks();
return result;
}
DX_API DirectXHook::drawPrimitiveHookCallback(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
{
for (int i = 0; i < drawPrimitiveCallbacks.size(); i++)
drawPrimitiveCallbacks[i](this, pDevice, PrimitiveType, StartVertex, PrimitiveCount);
return origDrawPrimitive(pDevice, PrimitiveType, StartVertex, PrimitiveCount);
}
DX_API DirectXHook::drawIndexedPrimitiveHookCallback(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount)
{
for (int i = 0; i < drawIndexedPrimitiveCallbacks.size(); i++)
drawIndexedPrimitiveCallbacks[i](this, pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
return origDrawIndexedPrimitive(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
}
void DirectXHook::placeHooks()
{
static const DWORD VHHookCount = 4;
static VFHookInfo VFHooks[VHHookCount] =
{
VFHookInfo(16, (DWORD)&myReset, (DWORD*)&DirectXHook::origReset),
VFHookInfo(42, (DWORD)&myEndScene, (DWORD*)&DirectXHook::origEndScene),
VFHookInfo(81, (DWORD)&myDrawPrimitive, (DWORD*)&DirectXHook::origDrawPrimitive),
VFHookInfo(82, (DWORD)&myDrawIndexedPrimitive, (DWORD*)&DirectXHook::origDrawIndexedPrimitive),
};
for (int hook = 0; hook < VHHookCount; hook++)
{
DWORD ret = hookVF((DWORD)DirectXHook::hookedDevice, VFHooks[hook].index, VFHooks[hook].callback);
if (ret != VFHooks[hook].callback)
*VFHooks[hook].origFunc = ret;
}
}
void DirectXHook::onLostDevice()
{
if (this->font)
this->font->OnLostDevice();
for (int i = 0; i < this->imageSprites.size(); i++)
this->imageSprites[i]->OnLostDevice();
}
DWORD DirectXHook::locateEndScene()
{
WNDCLASSEXA wc =
{
sizeof(WNDCLASSEX),
CS_CLASSDC,
DefWindowProc,
0L,0L,
GetModuleHandleA(NULL),
NULL, NULL, NULL, NULL,
"DX", NULL
};
RegisterClassExA(&wc);
HWND hWnd = CreateWindowA("DX",NULL,WS_OVERLAPPEDWINDOW,100,100,600,600,GetDesktopWindow(),NULL,wc.hInstance,NULL);
LPDIRECT3D9 pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (!pD3D)
return 0;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
LPDIRECT3DDEVICE9 pd3dDevice;
HRESULT res = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice);
if (FAILED(res))
return 0;
DWORD EndSceneAddress = getVF((DWORD)pd3dDevice, 42);
pD3D->Release();
pd3dDevice->Release();
DestroyWindow(hWnd);
return EndSceneAddress;
}
+109
View File
@@ -0,0 +1,109 @@
#pragma once
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
#include <stdio.h>
#include <fstream>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#include <vector>
#define DX_API HRESULT WINAPI
typedef HRESULT (WINAPI* _reset)(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
typedef HRESULT (WINAPI* _endScene)(LPDIRECT3DDEVICE9 pDevice);
typedef HRESULT (WINAPI* _drawPrimitive)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
typedef HRESULT (WINAPI* _drawIndexedPrimitive)(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount);
class DirectXHook;
typedef void (*_drawFrameCallback)(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice);
typedef void (*_drawPrimitiveCallback)(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
typedef void (*_drawIndexedPrimitiveCallback)(DirectXHook* hook, LPDIRECT3DDEVICE9 device, D3DPRIMITIVETYPE primType, INT baseVertexIndex, UINT minVertexIndex, UINT numVertices, UINT startIndex, UINT primCount);
class DirectXHook
{
public:
static _reset origReset;
static _endScene origEndScene;
static _drawPrimitive origDrawPrimitive;
static _drawIndexedPrimitive origDrawIndexedPrimitive;
static DirectXHook* getInstance()
{
if (!DirectXHook::instance)
DirectXHook::instance = new DirectXHook();
return DirectXHook::instance;
}
static void deleteInstance()
{
if (DirectXHook::instance)
{
delete DirectXHook::instance;
DirectXHook::instance = NULL;
}
}
void initialize();
void addDrawFrameCallback(_drawFrameCallback cb);
void addDrawPrimitiveCallback(_drawPrimitiveCallback cb);
void addDrawIndexedPrimitiveCallback(_drawIndexedPrimitiveCallback cb);
LPDIRECT3DTEXTURE9 addTexture(std::wstring imagePath);
int addSpriteImage(std::wstring imagePath);
void drawText(int x, int y, D3DCOLOR color, const char *text, ...);
void drawSpriteImage(int imageID, int x, int y, int w, int h);
DWORD initHookCallback(LPDIRECT3DDEVICE9 device);
DX_API resetHookCallback(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters);
DX_API endSceneHookCallback(LPDIRECT3DDEVICE9 pDevice);
DX_API drawPrimitiveHookCallback(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
DX_API drawIndexedPrimitiveHookCallback(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount);
private:
DirectXHook(void) {};
~DirectXHook(void) {};
static DirectXHook* instance;
static unsigned char* originalEndSceneCode;
static DWORD endSceneAddress;
static LPDIRECT3DDEVICE9 hookedDevice;
static bool hookReadyPre, hookReady;
std::vector<_drawFrameCallback> drawFrameCallbacks;
std::vector<_drawPrimitiveCallback> drawPrimitiveCallbacks;
std::vector<_drawIndexedPrimitiveCallback> drawIndexedPrimitiveCallbacks;
std::vector<LPDIRECT3DTEXTURE9> imageBitmaps;
std::vector<D3DSURFACE_DESC> imageDescriptions;
std::vector<LPD3DXSPRITE> imageSprites;
LPD3DXFONT font;
void onLostDevice();
void placeHooks();
DWORD locateEndScene();
struct VFHookInfo
{
VFHookInfo(DWORD _index, DWORD cb, DWORD* _origFunc) : index(_index), callback(cb), origFunc(_origFunc) {}
DWORD index, callback;
DWORD* origFunc;
};
};
@@ -0,0 +1,38 @@
#include "DirectXHook.h"
DWORD __stdcall reportInitEndScene(LPDIRECT3DDEVICE9 discoveredDeviceAddress)
{
return DirectXHook::getInstance()->initHookCallback(discoveredDeviceAddress);
}
__declspec(naked) void endSceneTrampoline()
{
__asm
{
MOV EAX, DWORD PTR SS:[ESP + 0x4]
PUSH EAX
CALL reportInitEndScene
JMP EAX
}
}
DX_API myReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters)
{
return DirectXHook::getInstance()->resetHookCallback(pDevice, pPresentationParameters);
}
DX_API myEndScene(LPDIRECT3DDEVICE9 pDevice)
{
return DirectXHook::getInstance()->endSceneHookCallback(pDevice);
}
DX_API myDrawPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
{
return DirectXHook::getInstance()->drawPrimitiveHookCallback(pDevice, PrimitiveType, StartVertex, PrimitiveCount);
}
DX_API myDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount)
{
return DirectXHook::getInstance()->drawIndexedPrimitiveHookCallback(pDevice, PrimType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
}
+127
View File
@@ -0,0 +1,127 @@
#include "DirectXHook.h"
int primitivesDrawn = 0;
int gliderImage = 0;
bool initialized = false;
////////////////// CHAPTER 9 LIGTHACK STUFF //////////////////
bool lightHack = false;
void enableLightHackDirectional(LPDIRECT3DDEVICE9 pDevice)
{
D3DLIGHT9 light;
ZeroMemory(&light, sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
light.Direction = D3DXVECTOR3(-1.0f, -0.5f, -1.0f);
pDevice->SetLight(0, &light);
pDevice->LightEnable(0, TRUE);
lightHack = true;
}
void enableLightHackAmbient(LPDIRECT3DDEVICE9 pDevice)
{
pDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(100, 100, 100));
lightHack = true;
}
void lightHackFrame(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice)
{
if (!lightHack)
{
if (GetAsyncKeyState(VK_F1))
enableLightHackDirectional(pDevice);
else if (GetAsyncKeyState(VK_F2))
enableLightHackAmbient(pDevice);
}
if (!lightHack)
hook->drawText(10, 188, D3DCOLOR_ARGB(255, 255, 0, 0), "There is currently no lighting. To enable light hack, press F1 for directional or F2 for ambient.");
else
hook->drawText(10, 188, D3DCOLOR_ARGB(255, 255, 0, 0), "Lighthack has been enabled, you should see the cube clearly now.");
}
////////////////// CHAPTER 9 WALLHACK STUFF //////////////////
bool wallHack = false;
LPDIRECT3DTEXTURE9 redTexture = NULL;
void wallHackFrame(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice)
{
if (!wallHack && GetAsyncKeyState(VK_F3))
wallHack = true;
if (!wallHack)
hook->drawText(10, 203, D3DCOLOR_ARGB(255, 255, 0, 0), "Wallhack example isnt running! Press F3 to enable.");
else
hook->drawText(10, 203, D3DCOLOR_ARGB(255, 255, 0, 0), "Wallhack is enabled! The cube should be drawn in red with no z-buffering now!");
}
void onDrawIndexedPrimitive(DirectXHook* hook, LPDIRECT3DDEVICE9 device, D3DPRIMITIVETYPE primType, INT baseVertexIndex, UINT minVertexIndex, UINT numVertices, UINT startIndex, UINT primCount)
{
primitivesDrawn++;
if (wallHack && numVertices == 24 && primCount == 12)
{
device->SetRenderState(D3DRS_ZENABLE, false);
if (redTexture) device->SetTexture(0, redTexture);
DirectXHook::origDrawIndexedPrimitive(device, primType, baseVertexIndex, minVertexIndex, numVertices, startIndex, primCount);
device->SetRenderState(D3DRS_ZENABLE, true);
}
}
////////////////// CHAPTER 8 STUFF //////////////////
void initialize(LPDIRECT3DDEVICE9 pDevice)
{
gliderImage = DirectXHook::getInstance()->addSpriteImage(L"glider.png");
redTexture = DirectXHook::getInstance()->addTexture(L"red.png"); // CHAPTER 9 WALLHACK STUFF
initialized = true;
}
void onDrawFrame(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice)
{
if (!initialized) initialize(pDevice);
hook->drawText(10, 10, D3DCOLOR_ARGB(255, 255, 0, 0), "Direct3D hook working! Intercepted drawing of %d primitives!", primitivesDrawn);
hook->drawText(10, 25, D3DCOLOR_ARGB(255, 255, 0, 0), "Image drawn by hook:");
hook->drawSpriteImage(gliderImage, 10, 40, 128, 128);
lightHackFrame(hook, pDevice); // CHAPTER 9 LIGTHACK STUFF
wallHackFrame(hook, pDevice); // CHAPTER 9 WALLHACK STUFF
primitivesDrawn = 0;
}
void onDrawPrimitive(DirectXHook* hook, LPDIRECT3DDEVICE9 pDevice, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
{
primitivesDrawn++;
}
DWORD WINAPI LoopFunction(LPVOID lpParam)
{
DirectXHook::getInstance()->addDrawFrameCallback(&onDrawFrame);
DirectXHook::getInstance()->addDrawPrimitiveCallback(&onDrawPrimitive);
DirectXHook::getInstance()->addDrawIndexedPrimitiveCallback(&onDrawIndexedPrimitive);
DirectXHook::getInstance()->initialize();
return 0;
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
CreateThread(0, 0, LoopFunction, 0, 0, 0);
}
else if(dwReason == DLL_PROCESS_DETACH)
{
}
return TRUE;
}
Binary file not shown.
+74
View File
@@ -0,0 +1,74 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter4_CodeToMemory", "Chapter4_CodeToMemory\Chapter4_CodeToMemory.vcxproj", "{42D11C4C-AC06-47BD-B6CD-FC6DBAF54472}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter5_AdvancedMemoryForensics_Scanning", "Chapter5_AdvancedMemoryForensics_Scanning\Chapter5_AdvancedMemoryForensics_Scanning.vcxproj", "{6C658EF9-CCA4-4E18-8AD7-CEBDC04AB3AB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter6_AccessingMemory", "Chapter6_AccessingMemory\Chapter6_AccessingMemory.vcxproj", "{4C3B87D1-43D3-44DB-913E-E4A1D99909CB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter7_CodeInjection", "Chapter7_CodeInjection\Chapter7_CodeInjection.vcxproj", "{A20C8EDD-02C5-499E-8DB6-1CB8081FD62B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter7_CodeInjection_DLL", "Chapter7_CodeInjection_DLL\Chapter7_CodeInjection_DLL.vcxproj", "{37305F21-BB4B-4492-A713-DDD94653C16E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter8_ControlFlow", "Chapter8_ControlFlow\Chapter8_ControlFlow.vcxproj", "{ACA1A8FF-6D8C-407A-983C-929D6F958D83}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter8_AdobeAirHook", "Chapter8_AdobeAirHook\AdobeAirHook.vcxproj", "{D041E046-6A67-413E-869B-14E3CE06A21B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter8_Direct3DApplication", "Chapter8_Direct3DApplication\Chapter8_Direct3DApplication.vcxproj", "{E621BD23-8A39-4BA3-9DB0-191661BBF6C9}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter8_Direct3DHook", "Chapter8_Direct3DHook\Chapter8_Direct3DHook.vcxproj", "{784C482A-F6EC-4BCB-851E-07BE782BB040}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chapter10_ResponsiveHacks", "Chapter10_ResponsiveHacks\Chapter10_ResponsiveHacks.vcxproj", "{E28E3DC6-2614-43B9-83E4-86D6F9A585B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{42D11C4C-AC06-47BD-B6CD-FC6DBAF54472}.Debug|Win32.ActiveCfg = Debug|Win32
{42D11C4C-AC06-47BD-B6CD-FC6DBAF54472}.Debug|Win32.Build.0 = Debug|Win32
{42D11C4C-AC06-47BD-B6CD-FC6DBAF54472}.Release|Win32.ActiveCfg = Release|Win32
{42D11C4C-AC06-47BD-B6CD-FC6DBAF54472}.Release|Win32.Build.0 = Release|Win32
{6C658EF9-CCA4-4E18-8AD7-CEBDC04AB3AB}.Debug|Win32.ActiveCfg = Debug|Win32
{6C658EF9-CCA4-4E18-8AD7-CEBDC04AB3AB}.Debug|Win32.Build.0 = Debug|Win32
{6C658EF9-CCA4-4E18-8AD7-CEBDC04AB3AB}.Release|Win32.ActiveCfg = Release|Win32
{6C658EF9-CCA4-4E18-8AD7-CEBDC04AB3AB}.Release|Win32.Build.0 = Release|Win32
{4C3B87D1-43D3-44DB-913E-E4A1D99909CB}.Debug|Win32.ActiveCfg = Debug|Win32
{4C3B87D1-43D3-44DB-913E-E4A1D99909CB}.Debug|Win32.Build.0 = Debug|Win32
{4C3B87D1-43D3-44DB-913E-E4A1D99909CB}.Release|Win32.ActiveCfg = Release|Win32
{4C3B87D1-43D3-44DB-913E-E4A1D99909CB}.Release|Win32.Build.0 = Release|Win32
{A20C8EDD-02C5-499E-8DB6-1CB8081FD62B}.Debug|Win32.ActiveCfg = Debug|Win32
{A20C8EDD-02C5-499E-8DB6-1CB8081FD62B}.Debug|Win32.Build.0 = Debug|Win32
{A20C8EDD-02C5-499E-8DB6-1CB8081FD62B}.Release|Win32.ActiveCfg = Release|Win32
{A20C8EDD-02C5-499E-8DB6-1CB8081FD62B}.Release|Win32.Build.0 = Release|Win32
{37305F21-BB4B-4492-A713-DDD94653C16E}.Debug|Win32.ActiveCfg = Debug|Win32
{37305F21-BB4B-4492-A713-DDD94653C16E}.Debug|Win32.Build.0 = Debug|Win32
{37305F21-BB4B-4492-A713-DDD94653C16E}.Release|Win32.ActiveCfg = Release|Win32
{37305F21-BB4B-4492-A713-DDD94653C16E}.Release|Win32.Build.0 = Release|Win32
{ACA1A8FF-6D8C-407A-983C-929D6F958D83}.Debug|Win32.ActiveCfg = Debug|Win32
{ACA1A8FF-6D8C-407A-983C-929D6F958D83}.Debug|Win32.Build.0 = Debug|Win32
{ACA1A8FF-6D8C-407A-983C-929D6F958D83}.Release|Win32.ActiveCfg = Release|Win32
{ACA1A8FF-6D8C-407A-983C-929D6F958D83}.Release|Win32.Build.0 = Release|Win32
{D041E046-6A67-413E-869B-14E3CE06A21B}.Debug|Win32.ActiveCfg = Debug|Win32
{D041E046-6A67-413E-869B-14E3CE06A21B}.Debug|Win32.Build.0 = Debug|Win32
{D041E046-6A67-413E-869B-14E3CE06A21B}.Release|Win32.ActiveCfg = Release|Win32
{D041E046-6A67-413E-869B-14E3CE06A21B}.Release|Win32.Build.0 = Release|Win32
{E621BD23-8A39-4BA3-9DB0-191661BBF6C9}.Debug|Win32.ActiveCfg = Debug|Win32
{E621BD23-8A39-4BA3-9DB0-191661BBF6C9}.Debug|Win32.Build.0 = Debug|Win32
{E621BD23-8A39-4BA3-9DB0-191661BBF6C9}.Release|Win32.ActiveCfg = Release|Win32
{E621BD23-8A39-4BA3-9DB0-191661BBF6C9}.Release|Win32.Build.0 = Release|Win32
{784C482A-F6EC-4BCB-851E-07BE782BB040}.Debug|Win32.ActiveCfg = Debug|Win32
{784C482A-F6EC-4BCB-851E-07BE782BB040}.Debug|Win32.Build.0 = Debug|Win32
{784C482A-F6EC-4BCB-851E-07BE782BB040}.Release|Win32.ActiveCfg = Release|Win32
{784C482A-F6EC-4BCB-851E-07BE782BB040}.Release|Win32.Build.0 = Release|Win32
{E28E3DC6-2614-43B9-83E4-86D6F9A585B1}.Debug|Win32.ActiveCfg = Debug|Win32
{E28E3DC6-2614-43B9-83E4-86D6F9A585B1}.Debug|Win32.Build.0 = Debug|Win32
{E28E3DC6-2614-43B9-83E4-86D6F9A585B1}.Release|Win32.ActiveCfg = Release|Win32
{E28E3DC6-2614-43B9-83E4-86D6F9A585B1}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal