Skip to content

Commit d3a70fd

Browse files
committed
首次推送
1 parent 494cae7 commit d3a70fd

13 files changed

+1658
-0
lines changed

Header/il2cpp_api.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// assembly
2+
DO_API(const Il2CppImage*, il2cpp_assembly_get_image, (const Il2CppAssembly* assembly));
3+
4+
// image
5+
DO_API(const char*, il2cpp_image_get_name, (const Il2CppImage* image));
6+
DO_API(size_t, il2cpp_image_get_class_count, (const Il2CppImage* image));
7+
DO_API(const Il2CppClass*, il2cpp_image_get_class, (const Il2CppImage* image, size_t index));
8+
9+
DO_API(Il2CppString*, il2cpp_string_new_utf16, (const wchar_t* text, int32_t len));
10+
// class
11+
DO_API(Il2CppClass*, il2cpp_class_from_name, (const Il2CppImage* image, const char* namespaze, const char* name));
12+
DO_API(const MethodInfo*, il2cpp_class_get_methods, (Il2CppClass* klass, void** iter));
13+
DO_API(const MethodInfo*, il2cpp_class_get_method_from_name, (Il2CppClass* klass, const char* name, int argsCount));
14+
DO_API(FieldInfo*, il2cpp_class_get_field_from_name, (Il2CppClass* klass, const char* name));
15+
DO_API(const char*, il2cpp_class_get_name, (const Il2CppClass* klass));
16+
DO_API(const char*, il2cpp_class_get_namespace, (const Il2CppClass* klass));
17+
DO_API(const Il2CppClass*, il2cpp_class_get_parent, (const Il2CppClass* klass));
18+
DO_API(const Il2CppClass*, il2cpp_class_get_declaring_type, (const Il2CppClass* klass));
19+
DO_API(FieldInfo*, il2cpp_class_get_fields, (Il2CppClass* klass, void** iter));
20+
DO_API(int32_t, il2cpp_field_get_offset, (FieldInfo* field));
21+
DO_API(const char*, il2cpp_field_get_name, (FieldInfo* field));
22+
23+
// field
24+
DO_API(void, il2cpp_field_static_get_value, (FieldInfo* field, void* value));
25+
DO_API(const Il2CppType*, il2cpp_field_get_type, (FieldInfo* field));
26+
27+
// domain
28+
DO_API(Il2CppDomain*, il2cpp_domain_get, ());
29+
DO_API(const Il2CppAssembly*, il2cpp_domain_assembly_open, (Il2CppDomain* domain, const char* name));
30+
DO_API(const Il2CppAssembly**, il2cpp_domain_get_assemblies, (const Il2CppDomain* domain, size_t* size));
31+
32+
// method
33+
DO_API(const Il2CppType*, il2cpp_method_get_return_type, (const MethodInfo* method));
34+
DO_API(const char*, il2cpp_method_get_name, (const MethodInfo* method));
35+
DO_API(uint32_t, il2cpp_method_get_param_count, (const MethodInfo* method));
36+
DO_API(const Il2CppType*, il2cpp_method_get_param, (const MethodInfo* method, uint32_t index));
37+
DO_API(const char*, il2cpp_method_get_param_name, (const MethodInfo* method, uint32_t index));
38+
DO_API(uint32_t, il2cpp_method_get_flags, (const MethodInfo* method, uint32_t* iflags));
39+
DO_API(Il2CppObject*, il2cpp_runtime_invoke, (const MethodInfo* method, void* obj, void** params, Il2CppObject** exc));
40+
41+
// thread
42+
DO_API(Il2CppThread*, il2cpp_thread_attach, (Il2CppDomain* domain));
43+
44+
// type
45+
DO_API(char*, il2cpp_type_get_name, (const Il2CppType* type));
46+
DO_API(const char*, il2cpp_class_get_assemblyname, (const Il2CppClass* klass));

Header/il2cpp_function.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
DO_FUNC(Il2CppArray*, FindObjectsOfType, (void*), "UnityEngine.CoreModule", "UnityEngine", "Object", "Object[] FindObjectsOfType(Type type);");
2+
DO_FUNC(Il2CppArray*, FindObjectsOfTypeAll, (void*), "UnityEngine.CoreModule", "UnityEngine", "Resources", "Object[] FindObjectsOfTypeAll(Type type);");
3+
DO_FUNC(Il2CppArray*, FindObjectsByTypeBool , (void*,bool), "UnityEngine.CoreModule", "UnityEngine", "Object", "Object[] FindObjectsOfType(Type type,Boolean includeInactive);");
4+
//DO_FUNC(Il2CppArray*, FindGameObjectsWithTag, (Il2CppString*), "UnityEngine.CoreModule", "UnityEngine", "GameObject", "GameObject[] FindGameObjectsWithTag(String tag);");
5+
DO_FUNC(void*, GetType, (Il2CppString*), "mscorlib", "System", "Type", "Type GetType(String typeName);");
6+
DO_FUNC(void*, PtrToStringAnsi, (const char*), "mscorlib", "System.Runtime.InteropServices", "Marshal", "String PtrToStringAnsi(IntPtr ptr);");
7+
DO_FUNC(Camera*, GetMainCamera, (), "UnityEngine.CoreModule", "UnityEngine", "Camera", "Camera get_main();");
8+
DO_FUNC(void*, GameObject_Find, (Il2CppString*), "UnityEngine.CoreModule", "UnityEngine", "GameObject", "GameObject Find(String name);");
9+
10+
DO_FUNC(Transform*, GetTransform, (GameObject*), "UnityEngine.CoreModule", "UnityEngine", "GameObject", "Transform get_transform();");
11+
DO_FUNC(void, SetActive, (GameObject*,bool), "UnityEngine.CoreModule", "UnityEngine", "GameObject", "Void SetActive(Boolean value);");
12+
DO_FUNC(Transform*, GetTransform_Component, (void*), "UnityEngine.CoreModule", "UnityEngine", "Component", "Transform get_transform();");
13+
DO_FUNC(Vector3, GetPosition, (Transform*), "UnityEngine.CoreModule", "UnityEngine", "Transform", "Vector3 get_position();");
14+
DO_FUNC(Vector3, GetEulerAngles, (Transform*), "UnityEngine.CoreModule", "UnityEngine", "Transform", "Vector3 get_eulerAngles();");
15+
DO_FUNC(GameObject*, GetGameObject, (void*), "UnityEngine.CoreModule", "UnityEngine", "Component", "GameObject get_gameObject();");
16+
DO_FUNC(Il2CppString*, Gettag, (void*), "UnityEngine.CoreModule", "UnityEngine", "Component", "String get_tag();");
17+
DO_FUNC(int, GetChildCount, (Transform*), "UnityEngine.CoreModule", "UnityEngine", "Transform", "Int32 get_childCount();");
18+
DO_FUNC(Transform*, GetChild, (Transform*, int), "UnityEngine.CoreModule", "UnityEngine", "Transform", "Transform GetChild(Int32 index);");
19+
DO_FUNC(Vector3, GetForward, (Transform*), "UnityEngine.CoreModule", "UnityEngine", "Transform", "Vector3 get_forward();");
20+
DO_FUNC(Shader*, FindShader, (Il2CppString*), "UnityEngine.CoreModule", "UnityEngine", "Shader", "Shader Find(String name);");
21+
22+
DO_FUNC(void, SetGlobalColor, (Il2CppString*,Color), "UnityEngine.CoreModule", "UnityEngine", "Shader", "Void SetGlobalColor(String name,Color value);");
23+
DO_FUNC(void, SetGlobalMatrix, (Il2CppString*,Matrix4x4), "UnityEngine.CoreModule", "UnityEngine", "Shader", "Void SetGlobalMatrix(String name,Matrix4x4 value);");
24+
DO_FUNC(void, SetGlobalVector, (Il2CppString*,Vector4), "UnityEngine.CoreModule", "UnityEngine", "Shader", "Void SetGlobalVector(String name,Vector4 value);");
25+
DO_FUNC(void, SetGlobalFloat, (Il2CppString*,float), "UnityEngine.CoreModule", "UnityEngine", "Shader", "Void SetGlobalFloat(String name,Single value);");
26+
DO_FUNC(void, SetGlobalInt, (Il2CppString*,int), "UnityEngine.CoreModule", "UnityEngine", "Shader", "Void SetGlobalInt(String name,Int32 value);");
27+
DO_FUNC(void, SetMaximumLOD, (void*, int), "UnityEngine.CoreModule", "UnityEngine", "Shader", "Void set_maximumLOD(Int32 value);");
28+
DO_FUNC(void, SetGlobalMaximumLOD, (int), "UnityEngine.CoreModule", "UnityEngine", "QualitySettings", "Void set_maximumLODLevel(Int32 value);");
29+
DO_FUNC(int, GetPassCount, (void*), "UnityEngine.CoreModule", "UnityEngine", "Shader", "Int32 get_passCount();");
30+
DO_FUNC(Il2CppString*, GetUnityVersion, (), "UnityEngine.CoreModule", "UnityEngine", "Application", "String get_unityVersion();");

Menu/DumpSdk.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include "DumpSdk.h"
2+
3+
4+
void DumpSdk::il2cpp_dump_init(HMODULE Module) {
5+
hModule = Module;
6+
}
7+
bool DumpSdk::il2cpp_Dump2File(string file)
8+
{
9+
try {
10+
ofstream io(file + "\\dump.cs");
11+
ofstream io2(file + "\\il2cpp.hpp");
12+
ofstream io3(file + "\\il2cpp-func.hpp");
13+
14+
if (!io) return false;
15+
stringstream str;
16+
stringstream str2;
17+
stringstream str3;
18+
19+
vector<Il2CppAssembly*> Assemblys;
20+
for (size_t i = 0, max = il2cpp_EnummAssembly(Assemblys); i < max; i++)
21+
{
22+
auto image = il2cpp_GetImage(Assemblys[i]);
23+
str << "// Image " << i << ": " << il2cpp_GetImageName(image) << " - " << il2cpp_GetClassCount(image) << endl;
24+
}
25+
str << endl << endl << endl;
26+
for (size_t i = 0, max = Assemblys.size(); i < max; i++)
27+
{
28+
auto image = il2cpp_GetImage(Assemblys[i]);
29+
vector<Il2CppClass*> classes;
30+
for (size_t i_c = 0, max_c = il2cpp_EnumClasses(image, classes); i_c < max_c; i_c++)
31+
{
32+
str << "// Assembly: " << il2cpp_class_get_assemblyname(classes[i_c]) << endl;
33+
str << "// Namespace: " << il2cpp_GetClassNamespace(classes[i_c]) << "\npublic class " << il2cpp_GetClassName(classes[i_c]) << "\n{\n\t// Fields" << endl;
34+
str2 << "struct " << il2cpp_GetClassName(classes[i_c]) << "\n" << "{" << endl;
35+
36+
vector<FieldInfo*> Field;
37+
for (size_t i_f = 0, max_f = il2cpp_EnumFields(classes[i_c], Field); i_f < max_f; i_f++)
38+
{
39+
auto Typename = il2cpp_GetTypeName(il2cpp_GetFieldType(Field[i_f]));
40+
string Type = Typename;
41+
if (Typename.find_last_of(".") != string::npos)
42+
{
43+
size_t MaxIndex = Typename.find("<");
44+
if (MaxIndex == string::npos)
45+
{
46+
Type = Typename.substr(Typename.find_last_of(".") + 1);
47+
}
48+
else
49+
{
50+
size_t LastIndex = Typename.find_last_of(".");
51+
while (LastIndex != string::npos
52+
&& LastIndex > MaxIndex)
53+
{
54+
LastIndex = Typename.find_last_of(".", LastIndex - 1);
55+
}
56+
57+
if (LastIndex != string::npos)
58+
Type = Typename.substr(LastIndex + 1);
59+
}
60+
}
61+
str << "\tpublic " << Type << " " << il2cpp_GetFieldName(Field[i_f]) << "; // 0x" << hex << il2cpp_GetFieldOffset(Field[i_f]) << dec << endl;
62+
str2 << "\t" << Type << " " << il2cpp_GetFieldName(Field[i_f]) << "; // 0x" << hex << il2cpp_GetFieldOffset(Field[i_f]) << dec << endl;
63+
}
64+
str << endl << endl << endl << "\t// Methods" << endl;
65+
str2 << "\n};" << endl;
66+
67+
vector<MethodInfo*> Methods;
68+
for (size_t i_m = 0, max_m = il2cpp_EnumMethods(classes[i_c], Methods); i_m < max_m; i_m++)
69+
{
70+
str << "\t// RVA: 0x" << hex << (il2cpp_GetMethodAddress(Methods[i_m]) - (DWORD_PTR)hModule) << dec << endl;
71+
72+
auto retTypename = il2cpp_GetTypeName(il2cpp_GetMethodRetType(Methods[i_m]));
73+
string retType = retTypename;
74+
if (retTypename.find_last_of(".") != string::npos)
75+
{
76+
retType = retTypename.substr(retTypename.find_last_of(".") + 1, retTypename.length());
77+
}
78+
str << "\tpublic " << retType << " " << il2cpp_GetMethodName(Methods[i_m]) << "(";
79+
str3 << "DO_API(" << retType << ", " << il2cpp_GetClassName(classes[i_c]) << "_" << il2cpp_GetMethodName(Methods[i_m]) << ", (";
80+
81+
for (size_t i_p = 0, max_p = il2cpp_GetMethodParamCount(Methods[i_m]); i_p < max_p; i_p++)
82+
{
83+
auto Typename = il2cpp_GetTypeName(il2cpp_GetMethodParam(Methods[i_m], i_p));
84+
string Type = Typename;
85+
if (Typename.find_last_of(".") != string::npos)
86+
{
87+
Type = Typename.substr(Typename.find_last_of(".") + 1, Typename.length());
88+
}
89+
90+
str << Type << " " << il2cpp_GetMethodParamName(Methods[i_m], i_p) << (1 == (max_p - i_p) ? "" : ", ");
91+
str3 << Type << " " << il2cpp_GetMethodParamName(Methods[i_m], i_p) << (1 == (max_p - i_p) ? "" : ", ");
92+
93+
}
94+
str << ");\n\n";
95+
str3 << "));\n";
96+
}
97+
str << "}" << endl << endl << endl;
98+
}
99+
}
100+
io << str.str();
101+
io2 << str2.str();
102+
io3 << str3.str();
103+
io.close();
104+
io2.close();
105+
io3.close();
106+
return true;
107+
}catch (exception& e){
108+
InfoMesseng::ColorPrint("ERROR", ("Error: " + string(e.what())).c_str(), 2);
109+
return false;
110+
}
111+
}

Menu/DumpSdk.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#pragma once
2+
#include "base.h"
3+
#include "engine.h"
4+
#include "../Misc/ColorInfo/InfoMesseng.h"
5+
#include <vector>
6+
#include <fstream>
7+
#include <sstream>
8+
class DumpSdk
9+
{
10+
protected:
11+
inline static HMODULE hModule = nullptr;
12+
public:
13+
static size_t il2cpp_EnummAssembly(std::vector<Il2CppAssembly*>& Assemblys)
14+
{
15+
size_t nrofassemblies = 0;
16+
Il2CppAssembly** assemblies = (Il2CppAssembly**)il2cpp_domain_get_assemblies(il2cpp_domain_get(), &nrofassemblies);
17+
for (int i = 0; i < nrofassemblies; i++)
18+
Assemblys.push_back(assemblies[i]);
19+
return Assemblys.size();
20+
}
21+
static Il2CppImage* il2cpp_GetImage(Il2CppAssembly* Assembly)
22+
{
23+
return (Il2CppImage*)il2cpp_assembly_get_image(Assembly);
24+
}
25+
static string il2cpp_GetImageName(Il2CppImage* Image)
26+
{
27+
return il2cpp_image_get_name(Image);
28+
}
29+
static size_t il2cpp_GetClassCount(Il2CppImage* Image)
30+
{
31+
return il2cpp_image_get_class_count(Image);
32+
}
33+
static size_t il2cpp_EnumClasses(Il2CppImage* Image, std::vector<Il2CppClass*>& classes)
34+
{
35+
size_t count = il2cpp_image_get_class_count(Image);
36+
classes.reserve(count);
37+
for (size_t i = 0; i < count; i++)
38+
{
39+
Il2CppClass* Class = (Il2CppClass*)il2cpp_image_get_class(Image, i);
40+
if (!Class) continue;
41+
classes.push_back(Class);
42+
}
43+
return classes.size();
44+
}
45+
static string il2cpp_GetClassNamespace(Il2CppClass* klass)
46+
{
47+
return il2cpp_class_get_namespace(klass);
48+
}
49+
static string il2cpp_GetClassName(Il2CppClass* klass)
50+
{
51+
return il2cpp_class_get_name(klass);
52+
}
53+
static size_t il2cpp_EnumFields(Il2CppClass* klass, std::vector<FieldInfo*>& Fields)
54+
{
55+
void* iter = NULL;
56+
FieldInfo* field;
57+
do
58+
{
59+
field = il2cpp_class_get_fields(klass, &iter);
60+
if (!field) continue;
61+
Fields.push_back(field);
62+
} while (field);
63+
return Fields.size();
64+
}
65+
static string il2cpp_GetTypeName(Il2CppType* type)
66+
{
67+
return il2cpp_type_get_name(type);
68+
}
69+
static Il2CppType* il2cpp_GetFieldType(FieldInfo* field)
70+
{
71+
return (Il2CppType*)il2cpp_field_get_type(field);
72+
}
73+
static string il2cpp_GetFieldName(FieldInfo* field)
74+
{
75+
return il2cpp_field_get_name(field);
76+
}
77+
static size_t il2cpp_GetFieldOffset(FieldInfo* field)
78+
{
79+
return il2cpp_field_get_offset(field);
80+
}
81+
static size_t il2cpp_EnumMethods(Il2CppClass* klass, std::vector<MethodInfo*>& Methods)
82+
{
83+
void* iter = NULL;
84+
MethodInfo* method;
85+
do
86+
{
87+
method = (MethodInfo*)il2cpp_class_get_methods(klass, &iter);
88+
if (!method) continue;
89+
Methods.push_back(method);
90+
} while (method);
91+
return Methods.size();
92+
}
93+
static DWORD_PTR il2cpp_GetMethodAddress(MethodInfo* method)
94+
{
95+
96+
if (!method) return 0;
97+
return *reinterpret_cast<DWORD_PTR*>(method);
98+
}
99+
static Il2CppType* il2cpp_GetMethodRetType(MethodInfo* Method)
100+
{
101+
return (Il2CppType*)il2cpp_method_get_return_type(Method);
102+
}
103+
static string il2cpp_GetMethodName(MethodInfo* Method)
104+
{
105+
return il2cpp_method_get_name(Method);
106+
}
107+
static size_t il2cpp_GetMethodParamCount(MethodInfo* Method)
108+
{
109+
return il2cpp_method_get_param_count(Method);
110+
}
111+
static Il2CppType* il2cpp_GetMethodParam(MethodInfo* Method, size_t index)
112+
{
113+
return (Il2CppType*)il2cpp_method_get_param(Method, (uint32_t)index);
114+
}
115+
static string il2cpp_GetMethodParamName(MethodInfo* Method, size_t index)
116+
{
117+
return il2cpp_method_get_param_name(Method, (uint32_t)index);
118+
}
119+
120+
static void il2cpp_dump_init(HMODULE Module);
121+
static bool il2cpp_Dump2File(string file);
122+
};
123+

0 commit comments

Comments
 (0)