forked from Jadis0x/il2cpp-reverse-engineering-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.cpp
More file actions
89 lines (71 loc) · 2.39 KB
/
helpers.cpp
File metadata and controls
89 lines (71 loc) · 2.39 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Generated C++ file by Il2CppInspectorPro - https://github.com/jadis0x
// Helper functions
#include "pch-il2cpp.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
#include <codecvt>
#include "helpers.h"
#include <iostream>
// Log file location
extern const LPCWSTR LOG_FILE;
// Helper function to get the module base address
uintptr_t il2cppi_get_base_address() {
return (uintptr_t)GetModuleHandleW(L"GameAssembly.dll");
}
// Helper function to append text to a file
void il2cppi_log_write(std::string text) {
HANDLE hfile = CreateFileW(LOG_FILE, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hfile == INVALID_HANDLE_VALUE)
MessageBoxW(0, L"Could not open log file", 0, 0);
DWORD written;
WriteFile(hfile, text.c_str(), (DWORD)text.length(), &written, NULL);
WriteFile(hfile, "\r\n", 2, &written, NULL);
CloseHandle(hfile);
}
void LogError(const char* msg, bool showBox)
{
std::cout << "[ERROR] " << msg << std::endl;
il2cppi_log_write(msg);
if (showBox) MessageBoxA(NULL, msg, "Error", MB_OK | MB_ICONERROR);
}
// Helper function to open a new console window and redirect stdout there
void il2cppi_new_console() {
AllocConsole();
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
}
#if _MSC_VER >= 1920
// Helper function to convert Il2CppString to std::string
std::string il2cppi_to_string(Il2CppString* str) {
if (!str)
return std::string{};
const auto length = str->length;
if (length <= 0)
return std::string{};
const auto* begin = reinterpret_cast<const char16_t*>(str->chars);
const auto* end = begin + static_cast<size_t>(length);
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(begin, end);
}
// Helper function to convert System.String to std::string
std::string il2cppi_to_string(app::String* str) {
return il2cppi_to_string(reinterpret_cast<Il2CppString*>(str));
}
app::String* convert_to_system_string(const char* str)
{
Il2CppString* il2cpp_str = il2cpp_string_new(str);
if (!il2cpp_str) return nullptr;
return reinterpret_cast<app::String*>(il2cpp_str);
}
std::string ToString(app::Object* Object)
{
std::string type = il2cppi_to_string(app::Object_ToString(Object, NULL));
if (type == "System.String") {
return il2cppi_to_string((app::String*)Object);
}
return type;
}
app::String* ToString(app::Object_1* Object)
{
return app::Object_1_GetName(Object, nullptr);
}
#endif