Skip to content

Commit

Permalink
调整导出格式以修复2020.2以上bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfare committed Nov 20, 2021
1 parent 90a8fb3 commit 1b93333
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
7 changes: 2 additions & 5 deletions module/src/main/cpp/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
#define RIRU_IL2CPPDUMPER_GAME_H

#define GamePackageName "com.game.packagename"
#define UnityVersion 2021.1.0f1
#define UnityVersion 2020.2.4f1

// 2018.3.0f2 and up enable it
#define VersionAbove2018dot3

// 2020.2.0f1 and up enable it
#define VersionAbove2020dot2

// 2021.1.0f1 and up enable it
#define VersionAbove2021dot1
//#define VersionAbove2021dot1

// UnityVersion Compatible list
// 5.3.0f4 | 5.3.0f4 - 5.3.1f1 | v16
Expand Down
42 changes: 15 additions & 27 deletions module/src/main/cpp/il2cpp_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,7 @@ std::string dump_type(const Il2CppType *type) {
outPut << ", " << extends[i];
}
}
#ifdef VersionAbove2020dot2
outPut << " // TypeDefIndex: " << type->data.__klassIndex << "\n{";
#else
outPut << " // TypeDefIndex: " << type->data.klassIndex << "\n{";
#endif
outPut << "\n{";
outPut << dump_field(klass);
outPut << dump_property(klass);
outPut << dump_method(klass);
Expand All @@ -350,31 +346,27 @@ void il2cpp_dump(void *handle, char *outDir) {
std::stringstream imageOutput;
for (int i = 0; i < size; ++i) {
auto image = il2cpp_assembly_get_image(assemblies[i]);
imageOutput << "// Image " << i << ": " << image->name << " - " << typeDefinitionsCount
<< "\n";
imageOutput << "// Image " << i << ": " << image->name << " - " << "typeCount : "
<< image->typeCount << "\n";
typeDefinitionsCount += image->typeCount;
}
std::vector<std::string> outPuts(typeDefinitionsCount);
LOGI("typeDefinitionsCount: %i", typeDefinitionsCount);
il2cpp_base = get_module_base("libil2cpp.so");
LOGI("il2cpp_base: %" PRIx64"", il2cpp_base);
std::vector<std::string> outPuts;
#ifdef VersionAbove2018dot3
//使用il2cpp_image_get_class
for (int i = 0; i < size; ++i) {
auto image = il2cpp_assembly_get_image(assemblies[i]);
std::stringstream imageStr;
imageStr << "\n// Dll : " << image->name;
auto classCount = il2cpp_image_get_class_count(image);
for (int j = 0; j < classCount; ++j) {
auto klass = il2cpp_image_get_class(image, j);
auto type = il2cpp_class_get_type(const_cast<Il2CppClass *>(klass));
//LOGD("type name : %s", il2cpp_type_get_name(type));
#ifdef VersionAbove2020dot2
auto klassIndex = type->data.__klassIndex;
#else
auto klassIndex = type->data.klassIndex;
#endif
if (outPuts[klassIndex].empty()) {
outPuts[klassIndex] = dump_type(type);
}
auto outPut = imageStr.str() + dump_type(type);
outPuts.push_back(outPut);
}
}
#else
Expand Down Expand Up @@ -404,6 +396,8 @@ void il2cpp_dump(void *handle, char *outDir) {
LOGI("dumping...");
for (int i = 0; i < size; ++i) {
auto image = il2cpp_assembly_get_image(assemblies[i]);
std::stringstream imageStr;
imageStr << "\n// Dll : " << image->name;
//LOGD("image name : %s", image->name);
auto imageName = std::string(image->name);
auto pos = imageName.rfind('.');
Expand All @@ -424,24 +418,18 @@ void il2cpp_dump(void *handle, char *outDir) {
auto klass = il2cpp_class_from_system_type((Il2CppReflectionType *) items[j]);
auto type = il2cpp_class_get_type(klass);
//LOGD("type name : %s", il2cpp_type_get_name(type));
auto klassIndex = type->data.klassIndex;
if (outPuts[klassIndex].empty()) {
outPuts[klassIndex] = dump_type(type);
}
auto outPut = imageStr.str() + dump_type(type);
outPuts.push_back(outPut);
}
}
#endif
LOGI("write dump file");
auto outPath = std::string(outDir).append("/files/dump.cs");
std::ofstream outStream(outPath);
outStream << imageOutput.str();
for (int i = 0; i < typeDefinitionsCount; ++i) {
if (!outPuts[i].empty()) {
outStream << outPuts[i];
} else {
// <Module> always missing
//LOGW("miss typeDefinition: %d", i);
}
auto count = outPuts.size();
for (int i = 0; i < count; ++i) {
outStream << outPuts[i];
}
outStream.close();
LOGI("dump done!");
Expand Down

0 comments on commit 1b93333

Please sign in to comment.