Unity 游戏脚本解密
文章有不足之处,请不吝赐教。
现在用Unity的游戏大多都加密了Assembly-CSharp.dll, 这篇文章给出一个通用的解密方法。
原理:是通过调用游戏自身的libmono.so的导出函数mono_image_open_from_data对游戏自身脚本文件的解密。
#include <stdio.h>
#include <dlfcn.h>
struct _MonoImage {
/*
* The number of assemblies which reference this MonoImage though their 'image'
* field plus the number of images which reference this MonoImage through their
* 'modules' field, plus the number of threads holding temporary references to
* this image between calls of mono_image_open () and mono_image_close ().
*/
int ref_count;
void *raw_data_handle;
char *raw_data;
int raw_data_len;
};
int main()
{
void * libm_handle = NULL;
struct _MonoImage* (*mono_image_open_from_data) (char *data, int data_len, int need_copy, char *status);
void (*mono_image_close)(struct _MonoImage *);
char *errorInfo;
struct _MonoImage* result;
libm_handle = dlopen("/data/local/tmp/libmono.so", RTLD_LAZY );
if (!libm_handle){
printf("Open Error:%s.\n",dlerror());
return 0;
}
mono_image_open_from_data = dlsym(libm_handle,"mono_image_open_from_data");
errorInfo = dlerror();
if (errorInfo != NULL){
printf("Dlsym Error:%s.\n",errorInfo);
return 0;
}
printf("call mono_image_open_from_data:0x%x\n", mono_image_open_from_data);
const char* pDll = "/data/local/tmp/Assembly-CSharp.dll";
FILE *fpDll;
fpDll = fopen(pDll, "r");
if(fpDll == NULL)
{
printf("open fail\n");
}
fseek(fpDll, 0, SEEK_END);
int len = ftell(fpDll);
fseek(fpDll, 0, SEEK_SET);
char *data = (char *)malloc(len);
fread(data, 1, len, fpDll);
fclose(fpDll);
result = (*mono_image_open_from_data)(data, len, 0, 0);
printf("call result:0x%x\n", result);
char *pData = result->raw_data;
int size = result->raw_data_len;
printf("%d", size);
FILE* pFile = fopen("dump.dll","wb");
fwrite(pData,size,1,pFile);
fclose(pFile);
dlclose(libm_handle);
return 0;
} 这里提供一份编译好的文件
https://yunpan.cn/cqGdHYi2P7g5K 访问密码 36eb
