Skip to content

Commit 2270755

Browse files
committedFeb 4, 2023
Initial commit
0 parents  commit 2270755

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-0
lines changed
 

‎.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bin/
2+
obj/
3+
.vs/
4+
*.sln
5+
*.vcxproj
6+
*.filters
7+
*.user

‎.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vendor/patterns"]
2+
path = vendor/patterns
3+
url = https://github.com/ThirteenAG/Hooking.Patterns

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Bigfile logger
2+
3+
Simple module to inject into the game process to log all bigfile requests. This can be used to create file lists for easily browsing the archives.
4+
5+
Has been tested with the following games:
6+
- Tomb Raider Legend
7+
- Tomb Raider Anniversary
8+
- Tomb Raider Underworld
9+
- Lara Croft and the Guardian of Light
10+
- Lara Croft and the Temple of Osiris
11+
- Rise of the Tomb Raider

‎premake5.lua

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
workspace "BigfileLogger"
2+
configurations { "Debug", "Release" }
3+
platforms { "Win32", "Win64" }
4+
5+
project "BigfileLogger"
6+
kind "SharedLib"
7+
8+
language "C++"
9+
cppdialect "C++17"
10+
11+
files "src/**"
12+
13+
files { "vendor/patterns/*.cpp" }
14+
includedirs { "vendor/patterns" }
15+
16+
symbols "On"
17+
18+
filter "platforms:Win32"
19+
architecture "x86"
20+
links "MinHook.x86.lib"
21+
22+
filter "platforms:Win64"
23+
architecture "x86_64"
24+
links "MinHook.x64.lib"
25+
26+
filter "configurations:Debug"
27+
defines { "DEBUG", "_DEBUG" }
28+
29+
filter "configurations:Release"
30+
defines { "NDEBUG" }
31+
optimize "On"

‎src/main.cpp

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#include <Windows.h>
2+
#include <MinHook.h>
3+
#include <Hooking.Patterns.h>
4+
5+
#include <cassert>
6+
#include <fstream>
7+
#include <set>
8+
9+
std::ofstream file;
10+
std::set<unsigned int> hashes;
11+
12+
void Log(unsigned int hash, const char* filename)
13+
{
14+
// keep internal list so we don't write 100 duplicates to log
15+
if (hashes.find(hash) == hashes.end())
16+
{
17+
hashes.insert(hash);
18+
19+
file << filename << std::endl;
20+
}
21+
}
22+
23+
unsigned int(__stdcall* orgArchiveFileSystem_CalculateHash)(const char* filename);
24+
unsigned int __stdcall ArchiveFileSystem_CalculateHash(const char* filename)
25+
{
26+
auto hash = orgArchiveFileSystem_CalculateHash(filename);
27+
28+
Log(hash, filename);
29+
30+
return hash;
31+
}
32+
33+
// tiger variant
34+
#ifndef _WIN64
35+
unsigned int(__cdecl* orgTigerArchiveFileSystem_CalculateHash)(const char* filename);
36+
unsigned int __cdecl TigerArchiveFileSystem_CalculateHash(const char* filename)
37+
#else
38+
unsigned int(__fastcall* orgTigerArchiveFileSystem_CalculateHash)(const char* filename);
39+
unsigned int __fastcall TigerArchiveFileSystem_CalculateHash(const char* filename)
40+
#endif
41+
{
42+
auto hash = orgTigerArchiveFileSystem_CalculateHash(filename);
43+
44+
Log(hash, filename);
45+
46+
return hash;
47+
}
48+
49+
template<typename T>
50+
T GetAddress(void* ptr)
51+
{
52+
#ifndef _WIN64
53+
return (T)((__int32)ptr + *(__int32*)((__int32)ptr + 1) + 5);
54+
#else
55+
return (T)((__int64)ptr + *(__int32*)((__int64)ptr + 1) + 5);
56+
#endif
57+
}
58+
59+
void Initialize()
60+
{
61+
MH_Initialize();
62+
63+
// set hooks
64+
#ifndef _WIN64
65+
auto archiveCalculateHash = hook::pattern("83 EC 0C 8B 44 24 10 53 55 56 57 8B D9 50 89 5C 24 1C E8").count_hint(1);
66+
auto tigerCalculateHash = hook::pattern("89 4D FC 33 FF 89 45 F8 8B F0 E8").count_hint(1);
67+
68+
if (!archiveCalculateHash.empty())
69+
{
70+
MH_CreateHook(
71+
GetAddress<void*>(archiveCalculateHash.get_first(18)),
72+
ArchiveFileSystem_CalculateHash,
73+
reinterpret_cast<void**>(&orgArchiveFileSystem_CalculateHash));
74+
}
75+
76+
if (!tigerCalculateHash.empty())
77+
{
78+
MH_CreateHook(
79+
GetAddress<void*>(tigerCalculateHash.get_first(10)),
80+
TigerArchiveFileSystem_CalculateHash,
81+
reinterpret_cast<void**>(&orgTigerArchiveFileSystem_CalculateHash));
82+
}
83+
#else
84+
auto tigerCalculateHash = hook::pattern("8B 71 30 48 8B E9 48 8B CA 33 DB 44 8B DE E8").count_hint(1);
85+
86+
if (!tigerCalculateHash.empty())
87+
{
88+
MH_CreateHook(
89+
GetAddress<void*>(tigerCalculateHash.get_first(14)),
90+
TigerArchiveFileSystem_CalculateHash,
91+
reinterpret_cast<void**>(&orgTigerArchiveFileSystem_CalculateHash));
92+
}
93+
#endif
94+
95+
// open output file
96+
file.open("./filelist.txt", std::ios::out | std::ios::ate , _SH_DENYWR);
97+
98+
MH_EnableHook(MH_ALL_HOOKS);
99+
}
100+
101+
void Uninitialize()
102+
{
103+
MH_Uninitialize();
104+
105+
file.close();
106+
hashes.clear();
107+
}
108+
109+
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
110+
{
111+
switch (ul_reason_for_call)
112+
{
113+
case DLL_PROCESS_ATTACH:
114+
Initialize();
115+
116+
break;
117+
case DLL_PROCESS_DETACH:
118+
Uninitialize();
119+
120+
break;
121+
case DLL_THREAD_ATTACH:
122+
case DLL_THREAD_DETACH:
123+
break;
124+
}
125+
126+
return TRUE;
127+
}

‎vendor/patterns

Submodule patterns added at 62d4ff8

0 commit comments

Comments
 (0)
Please sign in to comment.