通过HOOK技术破解Assembly-CSharp.dll

Home / Article MrLee 2017-11-10 8027

  现在越来越多的PC端,手机端游戏的游戏引擎是Unity3D,简单介绍下Unity3D。Unity3D是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏、建筑可视化、实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎。Unity类似于Director,Blender game engine, Virtools 或 Torque Game Builder等利用交互的图型化开发环境为首要方式的软件。其编辑器运行在Windows 和Mac OS X下,可发布游戏至Windows、Mac、Wii、iPhone、WebGL(需要HTML5)、Windows phone 8和Android平台。也可以利用Unity web player插件发布网页游戏,支持Mac和Windows的网页浏览。它的网页播放器也被Mac 所支持。


  本文源自于网络上,在Android平台下hook加载函数mono_image_open_from_data_with_name实现Assembly-CSharp.dll解密。实现也非常简单,代码不多。

#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_with_name) (char *data, int data_len, int need_copy, char *status, char *filename);
	void (*mono_image_close)(struct _MonoImage *);
    char *errorInfo;
    struct _MonoImage* result;
    
    // dlopen 函数还会自动解析共享库中的依赖项。这样,如果您打开了一个依赖于其他共享库的对象,它就会自动加载它们。
    // 函数返回一个句柄,该句柄用于后续的 API 调用
    libm_handle = dlopen("/data/local/tmp/libmono.so", RTLD_LAZY );
    // 如果返回 NULL 句柄,表示无法找到对象文件,过程结束。否则的话,将会得到对象的一个句柄,可以进一步询问对象
    if (!libm_handle){
        // 如果返回 NULL 句柄,通过dlerror方法可以取得无法访问对象的原因
        printf("Open Error:%s.\n",dlerror());
        return 0;
    }
    // 使用 dlsym 函数,尝试解析新打开的对象文件中的符号。您将会得到一个有效的指向该符号的指针,或者是得到一个 NULL 并返回一个错误
    mono_image_open_from_data_with_name = dlsym(libm_handle,"mono_image_open_from_data_with_name");
    errorInfo = dlerror();// 调用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_with_name);
	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_with_name)(data, len, 0, 0, "Assembly-CSharp.dll");
	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://www.it72.com/12282.htm

推荐阅读
最新回复 (0)
返回