-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.cpp
More file actions
72 lines (63 loc) · 2.38 KB
/
Copy pathDebug.cpp
File metadata and controls
72 lines (63 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Created by mirasrael on 11/25/2022.
//
#include "Debug.h"
#include "MonoAssembly.h"
void* SearchByPattern(void* address, uint64_t pattern, uint64_t mask, uint32_t maxDistance)
{
auto ptr = (uint64_t)address;
auto end = ptr + maxDistance;
for (; ptr < end; ++ptr)
{
if (((*(uint64_t*)ptr) & mask) == pattern)
return (void*)ptr;
}
return nullptr;
}
void* SearchAndResolveByRelativeCall(void* caller, uint64_t offset)
{
auto callAddress = SearchByPattern(caller, 0xe8 | (offset << 8), 0xffffffffff, 1024);
return callAddress != nullptr ? (void*)((uint64_t) callAddress + offset + 5) : nullptr;
}
void DebugTransforms()
{
auto assembly = (MonoAssembly*) malloc(sizeof(MonoAssembly));
auto inited = assembly->Init("D:/projects/testing/UnityTest/Build VS/build/bin/UnityTest_Data/Managed/UnityEngine.CoreModule.dll");
if (inited)
{
auto monoFuncAddress = assembly->LookupInternalMethod("UnityEngine.Transform:set_position_Injected");
if (monoFuncAddress != nullptr)
{
auto rvaBasePlayer = GetModuleHandle("UnityPlayer.dll");
auto rvaBaseEditor = GetModuleHandle("Unity.exe");
HANDLE rvaBase;
void* funcAddress;
if ((rvaBase = rvaBasePlayer) != 0)
funcAddress = SearchAndResolveByRelativeCall(monoFuncAddress, 0x00aaf45e);
else if ((rvaBase = rvaBaseEditor) != 0)
funcAddress = SearchAndResolveByRelativeCall(monoFuncAddress, 0x00c62ba1);
else
MessageBox(nullptr, "Can't resolve module", "Test", MB_OK);
if (funcAddress != nullptr) {
char message[1000];
message[0] = 0;
sprintf_s(message, sizeof(message), "set_Position VA: 0x%x RVA: 0x%x RVABase: 0x%x",
(uint64_t) funcAddress,
(uint64_t) funcAddress - (uint64_t) rvaBase, rvaBase);
MessageBox(nullptr, message, "Test", MB_OK);
} else
MessageBox(nullptr, "Can't find call by pattern", "Test", MB_OK);
}
else
MessageBoxA(nullptr, "No Func", "Test", MB_OK);
}
else
MessageBox(nullptr, "Failed to Init Mono", "Test", MB_OK);
assembly->Dispose();
free(assembly);
}
void DebugBreakIfAttached()
{
if (IsDebuggerPresent())
DebugBreak();
}