internal static void LogException(string message, Exception exception) { // Send a debug message to terminal LogDebug(message, true, true); // Checking whether Logs.txt is in local folder if (!File.Exists(PathMgr.Local("Logs.txt"))) { // Create an empty Logs.txt if file not exists File.WriteAllText(PathMgr.Local("Logs.txt"), string.Empty); } try { using (var streamWriter = new StreamWriter(PathMgr.Local("Logs.txt"), true)) { streamWriter.WriteLine( "=== START =============================================================================="); streamWriter.WriteLine(message); streamWriter.WriteLine($"Date: {DateTime.Now.ToString()}"); streamWriter.WriteLine($"Exception Message: {exception.Message}"); streamWriter.WriteLine($"Exception StackTrace: {exception.StackTrace}"); streamWriter.WriteLine( "=== END ================================================================================"); streamWriter.WriteLine(); } } catch (Exception) { // Empty } }
private static void DevMode() { if ((bool)ConfigMgr.GetValue(ConfigMgr.Key.DevelopmentMode)) { string text = PathMgr.Temp("dev"); string text2 = PathMgr.Temp("dev", "raw"); string path = PathMgr.Local("raw.zip"); if (Directory.Exists(text)) { Utils.Rmdir(text); } if (File.Exists(path)) { File.Delete(path); } Directory.CreateDirectory(text); Directory.CreateDirectory(text2); foreach (KeyValuePair <Mods, bool> keyValuePair in Program.ListOfMod) { if (keyValuePair.Value) { string name = "scripts-" + keyValuePair.Key.ToString().ToLower().Replace("_", "-"); string path2 = keyValuePair.Key.ToString().ToLower().Replace("_", "-"); Directory.CreateDirectory(Path.Combine(text2, path2)); foreach (string text3 in Directory.GetFiles(PathMgr.Assets(name), "*.*", SearchOption.AllDirectories)) { File.Copy(text3, Path.Combine(Path.Combine(text2, path2), Path.GetFileName(text3))); } } } ZipFile.CreateFromDirectory(text, "raw.zip"); } }
internal static void Initialize() { var iniPath = PathMgr.Local("Configuration.ini"); foreach (var line in File.ReadAllLines(iniPath)) { if (line.Contains("=")) { var s = line.Split('='); var key = s[0]; object value = s[1]; foreach (Key keyName in Enum.GetValues(typeof(Key))) { if (key.Compare(keyName)) { Add(keyName, value.GetValue()); } } foreach (Mods modName in Enum.GetValues(typeof(Mods))) { if (key.Compare(modName)) { Program.SetValue(modName, (bool)value.GetValue()); } } } } }
internal static void NewCommand(string argument) { using (var process = new Process()) { process.StartInfo.FileName = "cmd"; process.StartInfo.Arguments = $"/c {argument}"; process.StartInfo.WorkingDirectory = PathMgr.Local(); process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.Start(); process.WaitForExit(); } }
static ConfigMgr() { if (Program.ListOfLua == null) { Program.ListOfLua = new List <string>() { "aircraft_template.lua.txt", "enemy_data_statistics.lua.txt" }; } if (Program.ListOfMod == null) { Program.ListOfMod = new List <string>(); } if (Instance == null) { var iniPath = PathMgr.Local("Configuration.ini"); if (File.Exists(iniPath)) { Update(iniPath); } if (!File.Exists(iniPath)) { File.WriteAllText(iniPath, Properties.Resources.Configuration); } Instance = new Dictionary <string, string>(); foreach (var line in File.ReadAllLines(iniPath)) { if (line.Contains('=')) { var s = line.Split('='); if (s[0] == "Temporary_Folder" || s[0] == "Version" || s[0] == "Godmode" || s[0] == "Weakenemy" || s[0] == "Godmode_Damage" || s[0] == "Godmode_Cooldown" || s[0] == "Godmode_Weakenemy" || s[0] == "Godmode_Damage_Cooldown" || s[0] == "Godmode_Damage_Weakenemy" || s[0] == "Godmode_Damage_Cooldown_Weakenemy" || s[0] == "RemoveSkill") { Instance.Add(s[0], s[1]); } } } Parse(); } }
private static void Execute(string lua, Tasks task) { var luaPath = lua; if (Program.IsDevMode == false) { lua = Path.Combine(PathMgr.Local(task == Tasks.Decompile ? "decrypted_lua" : "encrypted_lua"), Path.GetFileName(lua)); luaPath = Path.Combine(PathMgr.Local(task == Tasks.Decompile ? "decompiled_lua" : "recompiled_lua"), Path.GetFileName(lua)); if (File.Exists(luaPath)) { File.Delete(luaPath); } } Utils.LogInfo("{0} {1}...", true, false, task == Tasks.Decompile ? "Decompiling" : "Recompiling", Path.GetFileName(lua).Replace(".txt", string.Empty)); try { Utils.Command( task == Tasks.Decompile ? $"python main.py -f \"{lua}\" -o \"{luaPath}\"" : $"luajit.exe -b \"{lua}\" \"{luaPath}\"", PathMgr.Thirdparty(task == Tasks.Decompile ? "ljd" : "luajit")); } catch (Exception e) { Utils.LogException( $"Exception detected (Executor.2) during {(task == Tasks.Decompile ? "decompiling" : "recompiling")} {Path.GetFileName(lua).Replace(".txt", string.Empty)}", e); } finally { if (File.Exists(luaPath)) { SuccessCount++; Utils.Write(" <done>", false, true); } else { FailedCount++; Utils.Write(" <failed>", false, true); } } }
internal static void Log(string message, Exception exception) { if (!File.Exists(PathMgr.Local("Logs.txt"))) { File.WriteAllText(PathMgr.Local("Logs.txt"), string.Empty); } using (var streamWriter = new StreamWriter(PathMgr.Local("Logs.txt"), true)) { streamWriter.WriteLine("=== START ================================================================================="); streamWriter.WriteLine(message); streamWriter.WriteLine($"Date: {DateTime.Now.ToString()}"); streamWriter.WriteLine($"Exception Message: {exception.Message}"); streamWriter.WriteLine($"Exception StackTrace: {exception.StackTrace}"); streamWriter.WriteLine("=== END ==================================================================================="); streamWriter.WriteLine(); } Program.ExceptionCount++; }
static ConfigMgr() { if (Instance == null) { var iniPath = PathMgr.Local("Configuration.ini"); Instance = new Dictionary <string, string>(); foreach (var line in File.ReadAllLines(iniPath)) { if (line.Contains('=')) { var s = line.Split('='); if (s[0] == "Thirdparty_Folder") { Instance.Add(s[0], s[1]); } } } } }
private static void Execute(string lua, Tasks task) { if (lua.ToLower().Contains("unity_assets_files")) { lua = Path.Combine(PathMgr.Local("Decrypted_Lua"), Path.GetFileName(lua)); } var luaPath = Path.Combine(PathMgr.Local(task == Tasks.Decompile ? "Decompiled_Lua" : "Recompiled_Lua"), Path.GetFileName(lua)); if (File.Exists(luaPath)) { File.Delete(luaPath); } Utils.pInfof(string.Format("{0} {1}...", (task == Tasks.Decompile ? "Decompiling" : "Recompiling"), Path.GetFileName(lua))); try { Utils.NewCommand(task == Tasks.Decompile ? $"python main.py -f \"{lua}\" -o \"{luaPath}\"" : $"luajit.exe -b \"{lua}\" \"{luaPath}\""); } catch (Exception e) { Utils.eLogger(string.Format("Exception detected during {0} {1}", (task == Tasks.Decompile ? "decompiling" : "recompiling"), Path.GetFileName(lua)), e); } finally { if (File.Exists(luaPath)) { SuccessCount++; Console.Write(" <Done>\n"); } else { Console.Write(" <Failed>\n"); FailedCount++; } } }
private static void Main(string[] args) { if (args.Length < 1) { using (var dialog = new OpenFileDialog()) { dialog.Title = "Open an AssetBundle..."; dialog.Filter = "Azurlane AssetBundle|scripts*"; dialog.CheckFileExists = true; dialog.Multiselect = false; dialog.ShowDialog(); if (File.Exists(dialog.FileName)) { args = new[] { dialog.FileName }; } else { Console.WriteLine("Please open an AssetBundle..."); goto END; } } } else if (args.Length > 1) { Console.WriteLine("Invalid argument, usage: Azurlane.exe <path-to-assetbundle>"); goto END; } var filePath = Path.GetFullPath(args[0]); var fileDirectoryPath = Path.GetDirectoryName(filePath); var fileName = Path.GetFileName(filePath); if (!File.Exists(filePath)) { Console.WriteLine(Directory.Exists(fileDirectoryPath) ? string.Format("{0} is a directory, please input a file...", args[0]) : string.Format("{0} does not exists...", args[0])); goto END; } if (!AssetBundleMgr.IsAssetBundleValid(filePath)) { Console.WriteLine("Not a valid AssetBundle file..."); goto END; } ConfigMgr.Initialize(); for (var i = 0; i < ListOfMod.Count; i++) { ListOfMod[i] = string.Format("{0}-{1}", fileName, ListOfMod[i]); } if (File.Exists(PathMgr.Local("Logs.txt"))) { File.Delete(PathMgr.Local("Logs.txt")); } Clean(fileName); if (!Directory.Exists(PathMgr.Temp())) { Directory.CreateDirectory(PathMgr.Temp()); } var index = 1; if (ListOfAction == null) { ListOfAction = new List <Action>() { { () => { try { Utils.pInfof("Copying AssetBundle to temporary workspace..."); File.Copy(filePath, PathMgr.Temp(fileName), true); Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during copying AssetBundle to temporary workspace", e); } } }, { () => { try { Utils.pInfof("Decrypting AssetBundle..."); Utils.NewCommand(string.Format("Azcli.exe --decrypt \"{0}\"", PathMgr.Temp(fileName))); Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during decrypting AssetBundle", e); } } }, { () => { try { Utils.pInfof("Unpacking AssetBundle..."); Utils.NewCommand(string.Format("Azcli.exe --unpack \"{0}\"", PathMgr.Temp(fileName))); Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during unpacking AssetBundle", e); } } }, { () => { try { var showDoneMessage = true; Utils.pInfof("Decrypting Lua..."); foreach (var lua in ListOfLua) { Utils.NewCommand(string.Format("Azcli.exe --unlock \"{0}\"", PathMgr.Lua(fileName, lua))); if (LuaMgr.CheckLuaState(PathMgr.Lua(fileName, lua)) == LuaMgr.State.Encrypted) { Utils.pDebugln(string.Format("Failed to decrypt {0}", Path.GetFileName(lua))); showDoneMessage = false; } } if (showDoneMessage) { Console.Write(" <Done>\n"); } } catch (Exception e) { Utils.eLogger("Exception detected during decrypting Lua", e); } } }, { () => { try { Utils.pInfof("Decompiling Lua..."); foreach (var lua in ListOfLua) { Console.Write($" {index}/{ListOfLua.Count}"); Utils.NewCommand(string.Format("Azcli.exe --decompile \"{0}\"", PathMgr.Lua(fileName, lua))); index++; } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during decompiling Lua", e); } } }, { () => { try { Utils.pInfof("Creating a copy of Lua & AssetBundle"); foreach (var mod in ListOfMod) { if (!Directory.Exists(PathMgr.Lua(mod))) { Directory.CreateDirectory(PathMgr.Lua(mod)); } foreach (var lua in ListOfLua) { File.Copy(PathMgr.Lua(fileName, lua), PathMgr.Lua(mod, lua), true); } File.Copy(PathMgr.Temp(fileName), PathMgr.Temp(mod), true); } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during creating a copy of Lua & AssetBundle", e); } } }, { () => { try { Utils.pInfof("Cleaning..."); if (File.Exists(PathMgr.Temp(fileName))) { File.Delete(PathMgr.Temp(fileName)); } if (Directory.Exists(PathMgr.Lua(fileName).Replace("\\CAB-android", ""))) { Utils.Rmdir(PathMgr.Lua(fileName).Replace("\\CAB-android", "")); } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during cleaning", e); } } }, { () => { try { Utils.pInfof("Rewriting Lua..."); Utils.NewCommand("Rewriter.exe"); Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during rewriting Lua", e); } } }, { () => { try { Utils.pInfof("Recompiling Lua..."); foreach (var mod in ListOfMod) { foreach (var lua in ListOfLua) { Utils.NewCommand(string.Format("Azcli.exe --recompile \"{0}\"", PathMgr.Lua(mod, lua))); } } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during recompiling Lua", e); } } }, { () => { try { var showDoneMessage = true; Utils.pInfof("Encrypting Lua..."); foreach (var mod in ListOfMod) { foreach (var lua in ListOfLua) { Utils.NewCommand(string.Format("Azcli.exe --lock \"{0}\"", PathMgr.Lua(mod, lua))); if (LuaMgr.CheckLuaState(PathMgr.Lua(mod, lua)) == LuaMgr.State.Decrypted) { Utils.pDebugln(string.Format("Failed to encrypt {0}/{1}...", mod, Path.GetFileName(lua))); showDoneMessage = false; } } } if (showDoneMessage) { Console.Write(" <Done>\n"); } } catch (Exception e) { Utils.eLogger("Exception detected during encrypting Lua", e); } } }, { () => { try { Utils.pInfof("Repacking AssetBundle..."); foreach (var mod in ListOfMod) { Console.Write($" {index}/{ListOfMod.Count}"); Utils.NewCommand(string.Format("Azcli.exe --repack \"{0}\"", PathMgr.Temp(mod))); index++; } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during repacking AssetBundle", e); } } }, { () => { try { Utils.pInfof("Encrypting AssetBundle..."); foreach (var mod in ListOfMod) { Utils.NewCommand(string.Format("Azcli.exe --encrypt \"{0}\"", PathMgr.Temp(mod))); } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during encrypting AssetBundle", e); } } }, { () => { try { Utils.pInfof("Copying modified AssetBundle to original location..."); foreach (var mod in ListOfMod) { if (File.Exists(Path.Combine(fileDirectoryPath, mod))) { File.Delete(Path.Combine(fileDirectoryPath, mod)); } File.Copy(PathMgr.Temp(mod), Path.Combine(fileDirectoryPath, mod)); } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during copying modified AssetBundle to original location", e); } } } }; } try { foreach (var action in ListOfAction) { if (index != 1) { index = 1; } action.Invoke(); } } finally { Utils.pInfoln("Finishing..."); Clean(fileName); Console.WriteLine(); Console.WriteLine("Finished."); } END: Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
/// <summary> /// [Executor.1] Encrypt or decrypt a binary /// </summary> /// <param name="lua"></param> /// <param name="bytes"></param> /// <param name="task"></param> /// <param name="state"></param> private static void Execute(string lua, byte[] bytes, Tasks task, State state) { var luaPath = lua; if (Program.IsDevMode == false) { luaPath = Path.Combine(PathMgr.Local(task == Tasks.Decrypt ? "decrypted_Lua" : "encrypted_lua"), Path.GetFileName(lua)); if (File.Exists(lua)) { File.Delete(lua); } } try { Utils.LogInfo("{0} {1}...", true, false, task == Tasks.Decrypt ? "Decrypting" : "Encrypting", Path.GetFileName(lua).Replace(".txt", string.Empty)); using (var stream = new MemoryStream(bytes)) { using (var reader = new BinaryReader(stream)) { // src: ljd\rawdump\header.py + Perfare var magic = reader.ReadBytes(3); var version = reader.ReadByte(); var bits = reader.ReadUleb128(); var is_stripped = ((bits & 2u) != 0u); if (!is_stripped) { var length = reader.ReadUleb128(); var name = Encoding.UTF8.GetString(reader.ReadBytes((int)length)); } while (reader.BaseStream.Position < reader.BaseStream.Length) { var size = reader.ReadUleb128(); if (size == 0) { break; } var next = reader.BaseStream.Position + size; bits = reader.ReadByte(); var arguments_count = reader.ReadByte(); var framesize = reader.ReadByte(); var upvalues_count = reader.ReadByte(); var complex_constants_count = reader.ReadUleb128(); var numeric_constants_count = reader.ReadUleb128(); var instructions_count = reader.ReadUleb128(); var start = (int)reader.BaseStream.Position; if (state == State.Encrypted && task == Tasks.Decrypt) { bytes[3] = 0x02; bytes = Unlock(start, bytes, (int)instructions_count); } else if (state == State.Decrypted && task == Tasks.Encrypt) { bytes[3] = 0x80; bytes = Lock(start, bytes, (int)instructions_count); } else { break; } reader.BaseStream.Position = next; } } } File.WriteAllBytes(luaPath, bytes); } catch (Exception e) { Utils.LogException($"Exception detected (Executor.1) during {(task == Tasks.Decrypt ? "decrypting" : "encrypting")} {Path.GetFileName(lua).Replace(".txt", string.Empty)}", e); } finally { if (File.Exists(luaPath)) { SuccessCount++; Utils.Write(" <done>", false, true); } else { FailedCount++; Utils.Write(" <failed>", false, true); } } }
private static void Execute(string lua, byte[] bytes, Tasks task, State state) { var luaPath = Path.Combine(PathMgr.Local(task == Tasks.Decrypt ? "Decrypted_Lua" : "Encrypted_lua"), Path.GetFileName(lua)); if (File.Exists(luaPath)) { File.Delete(luaPath); } try { Utils.pInfof(string.Format("{0} {1}...", (task == Tasks.Decrypt ? "Decrypting" : "Encrypting"), Path.GetFileName(lua))); using (var stream = new MemoryStream(bytes)) { using (var reader = new BinaryReader(stream)) { // ljd\rawdump\header.py + Perfare var magic = reader.ReadBytes(3); var version = reader.ReadByte(); var bits = reader.ReadUleb128(); var is_stripped = ((bits & 2u) != 0u); if (!is_stripped) { var length = reader.ReadUleb128(); var name = Encoding.UTF8.GetString(reader.ReadBytes((int)length)); } while (reader.BaseStream.Position < reader.BaseStream.Length) { var size = reader.ReadUleb128(); if (size == 0) { break; } var next = reader.BaseStream.Position + size; bits = reader.ReadByte(); var arguments_count = reader.ReadByte(); var framesize = reader.ReadByte(); var upvalues_count = reader.ReadByte(); var complex_constants_count = reader.ReadUleb128(); var numeric_constants_count = reader.ReadUleb128(); var instructions_count = reader.ReadUleb128(); var start = (int)reader.BaseStream.Position; if (state == State.Encrypted && task == Tasks.Decrypt) { bytes[3] = 0x02; bytes = Unlock(start, bytes, (int)instructions_count); } else if (state == State.Decrypted && task == Tasks.Encrypt) { bytes[3] = 0x80; bytes = Lock(start, bytes, (int)instructions_count); } else { break; } reader.BaseStream.Position = next; } } } File.WriteAllBytes(luaPath, bytes); } catch (Exception e) { Utils.eLogger(string.Format("Exception detected during {0} {1}", (task == Tasks.Decrypt ? "decrypting" : "encrypting"), Path.GetFileName(lua)), e); } finally { if (File.Exists(luaPath)) { SuccessCount++; Console.Write(" <Done>\n"); } else { Console.Write(" <Failed>\n"); FailedCount++; } } }