首先mono没有重新编译成功的请先阅读第一篇window 重新编译 mono5.6 (c# 热更新 第一步)
- 将需要热更的dll 文件放到安装包的archive下
-
载xxtea加密库
这里是c语言版本的xxtea加密库:
https://github.com/xxtea/xxtea-c解压到本地备用。
-
加密可以使用c#代码进行
-
.把xxtea库添加到mono库
1.在下载好xxtea后,复制xxtea.c和xxtea.h两个文件到开始下载的mono的源码里。
具体位置在mono/mono/metadata文件夹下。2.然后再用vs2010打开mono/msvc/mono.sln,将上面的xxtea的两个文件添加到libmono里
(项目右键→添加项→现有项→选择xxtea.h和xxtea.c文件即可),记得保存一些解决方案,
或者退出vs,会提示你保存解决方案,要不然这两个文件没有引入哦。
注:如果该方法依然找不到方法,就把该方法整合到该类中就可以了 - mono\mono\metadata\image.c 方法:mono_image_open_from_data_with_name 中做修改
mono_image_open_from_data_with_name (char *data, guint32 data_len, gboolean need_copy, MonoImageOpenStatus *status, gboolean refonly, const char *name) { do { if (NULL == name) { break; } gboolean new_need_copy = need_copy; MonoImageOpenStatus *new_status = status; gboolean new_refonly = refonly; GString *new_name = NULL; MonoImage *new_mono_image = NULL; gchar *new_data = NULL; gsize new_data_len = 0; GError *error = NULL; //得到archive下是否有需要热更的 dll new_name = get_hot_update_library_file_name (name); if (NULL == new_name) { break; } //得到热更的dll if (!g_file_get_contents (new_name->str, &new_data, &new_data_len, &error)) { g_warning ("Hot update: fail to read data with new name: %s, data: %s, len: %d", new_name->str, new_data, new_data_len); if (NULL != error) { g_warning ("Hot update: Got an error (%s)", error->message); g_error_free (error); error = NULL; } g_string_free (new_name, TRUE); new_name = NULL; break; } if (error != NULL) { g_warning ("Hot update: Got an error (%s) returning TRUE", error->message); g_string_free (new_name, TRUE); new_name = NULL; g_error_free (error); error = NULL; break; } if (new_data == NULL) { g_string_free (new_name, TRUE); new_name = NULL; g_warning ("Hot update: Content is NULL"); break; } //解密 密钥要与加密的保持一致 char *key = "密钥"; size_t decrypt_data_len; g_warning ("Hot update: %s ====>>>> new_data len: %d",new_name->str,new_data_len); //解密 char *decrypt_data = xxtea_decrypt(new_data, new_data_len, key, &decrypt_data_len); int i = 0; for(i = 0;i < decrypt_data_len;++i) { new_data[i] = decrypt_data[i]; } g_free(decrypt_data); new_data_len = decrypt_data_len; g_warning ("Hot update: %s ====>>>> xxtea_decrypt new_data len: %d",new_name->str, new_data_len); new_mono_image = mono_image_open_from_new_data_with_name (new_data, new_data_len, new_need_copy, new_status, new_refonly, new_name->str); g_warning ("Hot update: %s ====>>>> %s, len: %d", name, new_name->str, new_data_len); g_string_free (new_name, TRUE); new_name = NULL; g_free (new_data); new_data = NULL; return new_mono_image; } while (TRUE); return mono_image_open_from_new_data_with_name(data, data_len, need_copy, status, refonly, name); }