Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
badApple001 committed Feb 21, 2024
1 parent e488736 commit 12da9b2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
39 changes: 39 additions & 0 deletions File.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <fstream>
#include <string>

namespace File {

bool Contain(const char* path, const char* dest) {
std::ifstream infile(path, std::ios::in | std::ios::binary | std::ios::ate);
size_t size = infile.tellg();
infile.seekg(0, std::ios::beg);
char* buffer = new char[size];
infile.read(buffer, size);
infile.close();
std::string alltext(buffer, size);
delete[] buffer;
return alltext.find(dest) != std::string::npos;
}

char* ReadBytes(const char* path) {
std::ifstream infile(path, std::ios::in | std::ios::binary | std::ios::ate);
size_t size = infile.tellg();
infile.seekg(0, std::ios::beg);
char* buffer = new char[size];
infile.read(buffer, size);
infile.close();
return buffer;
}

std::string Extract(const char* path, size_t offset, size_t length) {
char* buffer = ReadBytes(path);
if (buffer) {
std::string a(buffer + offset, length);
delete[] buffer;
return a;
}
delete[] buffer;
return nullptr;
}

}
1 change: 1 addition & 0 deletions Il2cppEncrtypt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="File.hpp" />
<ClInclude Include="framework.h" />
<ClInclude Include="Native.h" />
<ClInclude Include="pch.h" />
Expand Down
3 changes: 3 additions & 0 deletions Il2cppEncrtypt.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<ClInclude Include="Native.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="File.hpp">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand Down
24 changes: 13 additions & 11 deletions Native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <climits>
#include <sstream>
#include <direct.h>
#include "File.hpp"
using namespace std;


Expand Down Expand Up @@ -43,10 +44,6 @@ bool Contain(const char* path, const char* dest) {
return alltext.find(dest) != std::string::npos;
}

bool CheackUnityVersion(const char* path) {
return Contain(path, "2021.3.22f1");
}


//加密混淆核心逻辑
char* encrtypt_file(char* src, size_t& file_size) {
Expand Down Expand Up @@ -158,11 +155,6 @@ void OverrideLoader(char* path) {
string dest_loaderCpp = dest + "\\unityLibrary\\src\\main\\Il2CppOutputProject\\IL2CPP\\libil2cpp\\vm\\MetadataLoader.cpp";
string dest_memoryMappedFileH = dest + "\\unityLibrary\\src\\main\\Il2CppOutputProject\\IL2CPP\\libil2cpp\\utils\\MemoryMappedFile.h";
string dest_memoryMappedFileCpp = dest + "\\unityLibrary\\src\\main\\Il2CppOutputProject\\IL2CPP\\libil2cpp\\utils\\MemoryMappedFile.cpp";
string unity_version_file1 = localpath + "\\unityLibrary\\src\\main\\resources\\META-INF\\com.android.games.engine.build_fingerprint";
string unity_version_file2 = localpath + "\\unityLibrary\\build\\il2cpp_armeabi-v7a_ReleasePlus\\il2cpp_cache\\buildstate\\bee-inputdata.json";
string unity_version_file3 = localpath + "\\unityLibrary\\build\\il2cpp_armeabi-v7a_ReleasePlus\\il2cpp_cache\\buildstate\\bee.dag.json";


if (!file_exist(dest_loaderCpp.c_str()))
{
Log("error: not found dest loaderCpp");
Expand All @@ -178,8 +170,9 @@ void OverrideLoader(char* path) {
Log("error: not found dest memoryMapped source file");
return;
}
if (!CheackUnityVersion(unity_version_file1.c_str()) && !CheackUnityVersion(unity_version_file2.c_str()) && !CheackUnityVersion(unity_version_file3.c_str())) {
Log("error: unity version err.");
if (File::Extract((dest + "\\unityLibrary\\src\\main\\assets\\bin\\Data\\data.unity3d").c_str(), 0x12, 11) != "2021.3.22f1") {
//避免不同版本il2cpp源码不同 导致可能能正常跑起来 但是线上会引发崩溃
Log("version erro: must be 2021.3.22f1");
return;
}

Expand All @@ -192,12 +185,21 @@ void OverrideLoader(char* path) {
workpath = NULL;
}


Log("owner: 31games");
Log("anchor: https://geek7.blog.csdn.net/");
Log("email: [email protected]");
Log("override Loader code complete.");
}

//外部调用
void EncryptionCode(char* export_android_path)
{
if (NULL == export_android_path || strcmp(export_android_path, "") == 0) {
Log("export android path is null: %s", export_android_path);
return;
}

//wait input
string global_metadata_path = export_android_path;
if (NULL == strstr(global_metadata_path.c_str(), "global-metadata.dat")) {
Expand Down

0 comments on commit 12da9b2

Please sign in to comment.