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 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 Clean(string fileName) { try { if (File.Exists(PathMgr.Temp(fileName))) { File.Delete(PathMgr.Temp(fileName)); } if (Directory.Exists(PathMgr.Lua(fileName).Replace($"\\{DirName}", ""))) { Utils.Rmdir(PathMgr.Lua(fileName).Replace($"\\{DirName}", "")); } foreach (var mod in ListOfMod.Keys) { var modName = "scripts-" + mod.ToString().ToLower().Replace("_", "-"); if (File.Exists(PathMgr.Temp(modName))) { File.Delete(PathMgr.Temp(modName)); } if (Directory.Exists(PathMgr.Lua(modName).Replace($"\\{DirName}", ""))) { Utils.Rmdir(PathMgr.Lua(modName).Replace($"\\{DirName}", "")); } } } catch (Exception e) { Utils.LogException("Exception detected during cleaning", e); } }
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"); } }
private static void Clean(string fileName) { try { 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", "")); } foreach (var mod in ListOfMod) { if (File.Exists(PathMgr.Temp(mod))) { File.Delete(PathMgr.Temp(mod)); } if (Directory.Exists(PathMgr.Lua(mod).Replace("\\CAB-android", ""))) { Utils.Rmdir(PathMgr.Lua(mod).Replace("\\CAB-android", "")); } } } catch (Exception e) { Utils.eLogger("Exception detected during cleaning", e); } }
private static void Execute(string path, Tasks task) { Utils.LogInfo("{0} {1}...", true, false, task == Tasks.Unpack ? "Unpacking" : "Repacking", Path.GetFileName(path)); Utils.Command($"UnityEX.exe {(task == Tasks.Unpack ? "export" : "import")} \"{path}\"", PathMgr.Thirdparty("unityex")); Utils.Write(" <done>", false, true); }
internal static void Command(string argument) { using (var process = new Process()) { process.StartInfo.FileName = "cmd"; process.StartInfo.Arguments = $"/c {argument}"; process.StartInfo.WorkingDirectory = PathMgr.Thirdparty(); 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 Clean(string fileName) { if (File.Exists(PathMgr.Temporary(fileName))) { File.Delete(PathMgr.Temporary(fileName)); } if (Directory.Exists(PathMgr.Lua(fileName).Replace("\\CAB-android", ""))) { Utils.DeleteDirectory(PathMgr.Lua(fileName).Replace("\\CAB-android", "")); } foreach (var mod in ConfigMgr.ListOfMod) { if (File.Exists(PathMgr.Temporary(mod))) { File.Delete(PathMgr.Temporary(mod)); } if (Directory.Exists(PathMgr.Lua(mod).Replace("\\CAB-android", ""))) { Utils.DeleteDirectory(PathMgr.Lua(mod).Replace("\\CAB-android", "")); } } }
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) { Console.WriteLine(@"Invalid argument, usage: Azurlane.exe <path-to-scripts>"); return; } else if (args.Length < 1) { using (var openFileDialog = new OpenFileDialog()) { openFileDialog.Title = @"Open a scripts file..."; openFileDialog.Filter = @"Azurlane AssetBundle|scripts*"; openFileDialog.CheckFileExists = true; openFileDialog.Multiselect = true; openFileDialog.ShowDialog(); if (File.Exists(openFileDialog.FileName)) { args = new[] { openFileDialog.FileName } } ; else { Console.WriteLine(@"Please open a scripts file..."); Console.ReadKey(); return; } } } if (!File.Exists(args[0])) { Console.WriteLine(Directory.Exists(args[0]) ? $"{args[0]} is a directory, please input a file..." : $"{args[0]} doesn't exists..."); return; } var filePath = Path.GetDirectoryName(args[0]); var fileName = Path.GetFileName(args[0]); var listOfLua = new string[] { "aircraft_template.lua.txt", "enemy_data_statistics.lua.txt", "weapon_property.lua.txt" }; var listOfMod = new string[] { "weakenemy", "godmode", "godmode-cd", "godmode-dmg", "godmode-dmg-cd", "godmode-weakenemy" }; for (var i = 0; i < listOfMod.Length; i++) { listOfMod[i] = string.Format("{0}-{1}", fileName, listOfMod[i]); } if (File.Exists(PathMgr.Temp(fileName))) { File.Delete(PathMgr.Temp(fileName)); } if (Directory.Exists(Path.Combine(PathMgr.Temp("Unity_Assets_Files"), fileName))) { Utils.DeleteDirectory(Path.Combine(PathMgr.Temp("Unity_Assets_Files"), fileName)); } foreach (var mod in listOfMod) { if (File.Exists(PathMgr.Temp(mod))) { File.Delete(PathMgr.Temp(mod)); } if (Directory.Exists(Path.Combine(PathMgr.Temp("Unity_Assets_Files"), mod))) { Utils.DeleteDirectory(Path.Combine(PathMgr.Temp("Unity_Assets_Files"), mod)); } } try { var index = 1; Console.Write("[+] Copying AssetBundle to temp workspace..."); File.Copy(args[0], PathMgr.Temp(fileName), true); Console.Write(" <done>"); Console.WriteLine(); Console.Write("[+] Decrypting and Unpacking AssetBundle..."); AssetBundle.Run(PathMgr.Temp(fileName), Tasks.Decrypt); AssetBundle.Run(PathMgr.Temp(fileName), Tasks.Unpack); Console.Write(" <done>"); Console.WriteLine(); Console.Write($"[+] Decrypting and Decompiling Lua..."); foreach (var lua in listOfLua) { Console.Write($" {index}/{listOfLua.Length}"); Lua.Run(PathMgr.Lua(fileName, lua), Tasks.Decrypt); Lua.Run(PathMgr.Lua(fileName, lua), Tasks.Decompile); if (index == listOfLua.Length) { Console.Write(" <done>"); } index++; } Console.WriteLine(); index = 1; Console.Write($"[+] Cloning Lua and AssetBundle..."); foreach (var mod in listOfMod) { Console.Write($" {index}/{listOfMod.Length}"); try { 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); } } catch (Exception e) { Utils.ExceptionLogger("Exception detected during cloning lua and assetbundle", e); } File.Copy(PathMgr.Temp(fileName), PathMgr.Temp(mod), true); if (index == listOfMod.Length) { Console.Write(" <done>"); } index++; } Console.WriteLine(); index = 1; Console.Write("[+] Rewriting Lua..."); foreach (var mod in listOfMod) { Console.Write($" {index}/{listOfMod.Length}"); foreach (var lua in listOfLua) { if (mod.Contains("godmode-weakenemy")) { Write.GodMode(PathMgr.Lua(mod, lua)); Write.WeakEnemy(PathMgr.Lua(mod, lua), 20); } else if (mod.Contains("godmode-dmg-cd")) { Write.GodMode(PathMgr.Lua(mod, lua)); Write.Damage(PathMgr.Lua(mod, lua), 325); Write.Cooldown(PathMgr.Lua(mod, lua), 100); } else if (mod.Contains("godmode-dmg")) { Write.GodMode(PathMgr.Lua(mod, lua)); Write.Damage(PathMgr.Lua(mod, lua), 325); } else if (mod.Contains("godmode-cd")) { Write.GodMode(PathMgr.Lua(mod, lua)); Write.Cooldown(PathMgr.Lua(mod, lua), 100); } else if (mod.Contains("godmode")) { Write.GodMode(PathMgr.Lua(mod, lua)); } else if (mod.Contains("weakenemy")) { Write.WeakEnemy(PathMgr.Lua(mod, lua), 10); } } if (index == listOfMod.Length) { Console.Write(" <done>"); } index++; } Console.WriteLine(); index = 1; Console.Write("[+] Recompiling and Encypting Lua..."); foreach (var mod in listOfMod) { Console.Write($" {index}/{listOfMod.Length}"); foreach (var lua in listOfLua) { Lua.Run(PathMgr.Lua(mod, lua), Tasks.Recompile); Lua.Run(PathMgr.Lua(mod, lua), Tasks.Encrypt); } if (index == listOfMod.Length) { Console.Write(" <done>"); } index++; } Console.WriteLine(); index = 1; Console.Write("[+] Repacking & encrypting assetbundle..."); foreach (var mod in listOfMod) { Console.Write($" {index}/{listOfMod.Length}"); AssetBundle.Run(PathMgr.Temp(mod), Tasks.Repack); AssetBundle.Run(PathMgr.Temp(mod), Tasks.Encrypt); if (index == listOfMod.Length) { Console.Write(" <done>"); } index++; } Console.WriteLine(); index = 1; Console.Write("[+] Cleaning..."); foreach (var mod in listOfMod) { if (File.Exists(Path.Combine(filePath, mod))) { File.Delete(Path.Combine(filePath, mod)); } File.Copy(PathMgr.Temp(mod), Path.Combine(filePath, mod), true); } if (File.Exists(PathMgr.Temp(fileName))) { File.Delete(PathMgr.Temp(fileName)); } if (Directory.Exists(Path.Combine(PathMgr.Temp("Unity_Assets_Files"), fileName))) { Utils.DeleteDirectory(Path.Combine(PathMgr.Temp("Unity_Assets_Files"), fileName)); } foreach (var mod in listOfMod) { if (File.Exists(PathMgr.Temp(mod))) { File.Delete(PathMgr.Temp(mod)); } if (Directory.Exists(Path.Combine(PathMgr.Temp("Unity_Assets_Files"), mod))) { Utils.DeleteDirectory(Path.Combine(PathMgr.Temp("Unity_Assets_Files"), mod)); } } Console.Write(" <done>\n"); Console.WriteLine(); } finally { if (ExceptionCount != 0) { Console.WriteLine("Exception Detected, please check Logs.txt"); } Console.WriteLine("Press any key to exit."); Console.ReadLine(); } }
private static void CheckDependencies() { var missingCount = 0; var pythonVersion = 0.0; try { using (var process = new Process()) { process.StartInfo.FileName = "python"; process.StartInfo.Arguments = "--version"; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.Start(); var result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); if (result.Contains("Python")) { pythonVersion = Convert.ToDouble(result.Split(' ')[1].Remove(3)); } else { pythonVersion = -0.0; } } } catch { // Empty } if (pythonVersion.Equals(0.0) || pythonVersion.Equals(-0.0)) { Utils.LogDebug("No python detected", true, true); Utils.LogInfo(Properties.Resources.SolutionPythonMessage, true, true); missingCount++; } else if (pythonVersion < 3.7) { Utils.LogDebug("Detected Python version {0}.x - expected 3.7.x or newer", true, true, pythonVersion); Utils.LogInfo(Properties.Resources.SolutionPythonMessage, true, true); missingCount++; } if (!Directory.Exists(PathMgr.Thirdparty("ljd"))) { Utils.LogDebug(Properties.Resources.LuajitNotFoundMessage, true, true); Utils.LogInfo(Properties.Resources.SolutionReferMessage, true, true); missingCount++; } if (!Directory.Exists(PathMgr.Thirdparty("luajit"))) { Utils.LogDebug(Properties.Resources.LjdNotFoundMessage, true, true); Utils.LogInfo(Properties.Resources.SolutionReferMessage, true, true); missingCount++; } if (!Directory.Exists(PathMgr.Thirdparty("unityex"))) { Utils.LogDebug(Properties.Resources.UnityExNotFoundMessage, true, true); Utils.LogInfo(Properties.Resources.SolutionReferMessage, true, true); missingCount++; } if (missingCount > 0) { Abort = true; } }
private static void Main(string[] args) { Initialize(); if (Abort) { return; } 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 { Utils.Write(@"Please open an AssetBundle...", true, true); goto END; } } } else if (args.Length > 1) { Utils.Write(@"Invalid argument, usage: Azurlane.exe <path-to-assetbundle>", true, true); goto END; } var filePath = Path.GetFullPath(args[0]); var fileDirectoryPath = Path.GetDirectoryName(filePath); var fileName = Path.GetFileName(filePath); if (!File.Exists(filePath)) { Utils.Write(Directory.Exists(fileDirectoryPath) ? $"{args[0]} is a directory, please input a file..." : $"{args[0]} does not exists...", true, true); goto END; } if (!AssetBundleMgr.CheckAssetBundle(filePath)) { Utils.Write("Not a valid AssetBundle file...", true, true); goto END; } Clean(fileName); if (!Directory.Exists(PathMgr.Temp())) { Directory.CreateDirectory(PathMgr.Temp()); } var startTime = DateTime.Now; var index = 1; if (_listOfAction == null) { _listOfAction = new List <Action>() { () => { try { Utils.LogInfo("Copying AssetBundle to tmp workspace...", true, false); File.Copy(filePath, PathMgr.Temp(fileName), true); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during copying AssetBundle to tmp workspace", e); } }, () => { try { Utils.LogInfo("Decrypting AssetBundle...", true, false); Utils.Command($"Azcli.exe --dev --decrypt \"{PathMgr.Temp(fileName)}\""); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during decrypting AssetBundle", e); } }, () => { try { Utils.LogInfo("Unpacking AssetBundle...", true, false); Utils.Command($"Azcli.exe --dev --unpack \"{PathMgr.Temp(fileName)}\""); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during unpacking AssetBundle", e); } }, () => { try { var showDoneMessage = true; Utils.LogInfo("Decrypting Lua...", true, false); foreach (var lua in ListOfLua) { Utils.Command($"Azcli.exe --dev --unlock \"{PathMgr.Lua(fileName, lua)}\""); if (LuaMgr.CheckLuaState(PathMgr.Lua(fileName, lua)) != LuaMgr.State.Encrypted) { break; } Console.WriteLine(); Utils.LogDebug($"Failed to decrypt {Path.GetFileName(lua)}", true, true); showDoneMessage = false; } if (showDoneMessage) { Utils.Write(" <done>", false, true); } } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during decrypting Lua", e); } }, () => { try { Utils.LogInfo("Decompiling Lua...", true, false); var tasks = new List <Task>(); foreach (var lua in ListOfLua) { tasks.Add(Task.Factory.StartNew(() => { Utils.Command($"Azcli.exe --dev --decompile \"{PathMgr.Lua(fileName, lua)}\""); Utils.Write($@" {index}/{ListOfLua.Count}", false, false); index++; })); } Task.WaitAll(tasks.ToArray()); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during decompiling Lua", e); } }, () => { try { Utils.LogInfo("Cloning Lua & AssetBundle", true, false); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); if (!Directory.Exists(PathMgr.Lua(modName))) { Directory.CreateDirectory(PathMgr.Lua(modName)); } foreach (var lua in ListOfLua) { if (File.Exists(PathMgr.Lua(fileName, lua))) { File.Copy(PathMgr.Lua(fileName, lua), PathMgr.Lua(modName, lua), true); } } if (File.Exists(PathMgr.Temp(fileName))) { File.Copy(PathMgr.Temp(fileName), PathMgr.Temp(modName), true); } } } Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during cloning lua & assetbundle", e); } }, () => { try { Utils.LogInfo("Cleaning...", true, false); if (File.Exists(PathMgr.Temp(fileName))) { File.Delete(PathMgr.Temp(fileName)); } if (Directory.Exists(PathMgr.Lua(fileName).Replace($"\\{DirName}", ""))) { Utils.Rmdir(PathMgr.Lua(fileName).Replace($"\\{DirName}", "")); } Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during cleaning", e); } }, () => { try { Utils.LogInfo("Rewriting Lua...", true, false); Utils.Command("Azrewriter.exe"); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during rewriting Lua", e); } }, () => { try { Utils.LogInfo("Recompiling Lua...", true, false); var tasks = new List <Task>(); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); foreach (var lua in ListOfLua) { tasks.Add(Task.Factory.StartNew(() => { })); } } } Task.WaitAll(tasks.ToArray()); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during recompiling Lua", e); } }, () => { try { var showDoneMessage = true; Utils.LogInfo("Encrypting Lua...", true, false); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); foreach (var lua in ListOfLua) { Utils.Command($"Azcli.exe --dev --lock \"{PathMgr.Lua(modName, lua)}\""); if (LuaMgr.CheckLuaState(PathMgr.Lua(modName, lua)) != LuaMgr.State.Decrypted) { break; } Console.WriteLine(); Utils.LogDebug($"Failed to encrypt {mod}/{Path.GetFileName(lua)}...", true, true); showDoneMessage = false; } } } if (showDoneMessage) { Utils.Write(" <done>", false, true); } } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during encrypting Lua", e); } }, DevMode, () => { try { Utils.LogInfo("Repacking AssetBundle...", true, false); var tasks = new List <Task>(); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); tasks.Add(Task.Factory.StartNew(() => { Utils.Command($"Azcli.exe --dev --repack \"{PathMgr.Temp(modName)}\""); Utils.Write($@" {index}/{ListOfMod.Count(x => x.Value)}", false, false); index++; })); } } Task.WaitAll(tasks.ToArray()); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during repacking AssetBundle", e); } }, () => { try { Utils.LogInfo("Encrypting AssetBundle...", true, false); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); Utils.Command($"Azcli.exe --dev --encrypt \"{PathMgr.Temp(modName)}\""); } } Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during encrypting AssetBundle", e); } }, () => { try { Utils.LogInfo("Copying modified AssetBundle to original location...", true, false); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); if (File.Exists(Path.Combine(fileDirectoryPath, modName))) { File.Delete(Path.Combine(fileDirectoryPath, modName)); } File.Copy(PathMgr.Temp(modName), Path.Combine(fileDirectoryPath, modName)); } } Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during copying modified AssetBundle to original location", e); } } }; } try { foreach (var action in _listOfAction) { if (Abort) { break; } index = 1; action.Invoke(); } } finally { Utils.LogInfo("Cleaning...", true, true); Clean(fileName); Console.WriteLine(); Utils.Write("Finished.", true, true); var endTime = DateTime.Now; TimeSpan timeSpan = endTime - startTime; Utils.Write("Started at {0} - Ended at {1}", true, true, startTime.ToString("HH:mm"), endTime.ToString("HH:mm")); Utils.Write("{0} seconds elapsed.", true, true, timeSpan.TotalSeconds.ToString()); Console.WriteLine(); // Please don't delete this lol Utils.Write("Good work (even though you have done nothing at all).", true, true); } END: Utils.Write("Press any key to exit...", true, true); Console.ReadKey(); }
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++; } } }
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(); }
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} doesn't 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 < ConfigMgr.ListOfMod.Count; i++) { ConfigMgr.ListOfMod[i] = string.Format("{0}-{1}", fileName, ConfigMgr.ListOfMod[i]); } Clean(fileName); var index = 1; var listOfAction = new List <Action>() { { () => { Console.Write("[+] Copying AssetBundle to temporary workspace..."); File.Copy(filePath, PathMgr.Temporary(fileName), true); } }, { () => { Console.Write("[+] Decrypting AssetBundle..."); AssetBundleMgr.Execute(PathMgr.Temporary(fileName), Tasks.Decrypt); } }, { () => { Console.Write("[+] Unpacking AssetBundle..."); AssetBundleMgr.Execute(PathMgr.Temporary(fileName), Tasks.Unpack); } }, { () => { Console.Write("[+] Decrypting Lua..."); foreach (var lua in ConfigMgr.ListOfLua) { LuaMgr.Execute(PathMgr.Lua(fileName, lua), Tasks.Decrypt); } } }, { () => { Console.Write("[+] Decompiling Lua..."); foreach (var lua in ConfigMgr.ListOfLua) { Console.Write($" {index}/{ConfigMgr.ListOfLua.Count}"); LuaMgr.Execute(PathMgr.Lua(fileName, lua), Tasks.Decompile); index++; } } }, { () => { Console.Write("[+] Creating a copy of Lua & AssetBundle..."); foreach (var mod in ConfigMgr.ListOfMod) { if (!Directory.Exists(PathMgr.Lua(mod))) { Directory.CreateDirectory(PathMgr.Lua(mod)); } foreach (var lua in ConfigMgr.ListOfLua) { File.Copy(PathMgr.Lua(fileName, lua), PathMgr.Lua(mod, lua), true); } File.Copy(PathMgr.Temporary(fileName), PathMgr.Temporary(mod), true); } } }, { () => { Console.Write("[+] Rewriting Lua..."); foreach (var mod in ConfigMgr.ListOfMod) { foreach (var lua in ConfigMgr.ListOfLua) { RewriteMgr.Execute(mod, PathMgr.Lua(mod, lua)); } } } }, { () => { Console.Write("[+] Recompiling Lua..."); foreach (var mod in ConfigMgr.ListOfMod) { foreach (var lua in ConfigMgr.ListOfLua) { LuaMgr.Execute(PathMgr.Lua(mod, lua), Tasks.Recompile); } } } }, { () => { Console.Write("[+] Encrypting Lua..."); foreach (var mod in ConfigMgr.ListOfMod) { foreach (var lua in ConfigMgr.ListOfLua) { LuaMgr.Execute(PathMgr.Lua(mod, lua), Tasks.Encrypt); } } } }, { () => { Console.Write("[+] Repacking AssetBundle..."); foreach (var mod in ConfigMgr.ListOfMod) { Console.Write($" {index}/{ConfigMgr.ListOfMod.Count}"); AssetBundleMgr.Execute(PathMgr.Temporary(mod), Tasks.Repack); index++; } } }, { () => { Console.Write("[+] Encrypting AssetBundle..."); foreach (var mod in ConfigMgr.ListOfMod) { AssetBundleMgr.Execute(PathMgr.Temporary(mod), Tasks.Encrypt); } } }, { () => { Console.Write("[+] Copying modified AssetBundle to original location..."); foreach (var mod in ConfigMgr.ListOfMod) { if (File.Exists(Path.Combine(fileDirectoryPath, mod))) { File.Delete(Path.Combine(fileDirectoryPath, mod)); } File.Copy(PathMgr.Temporary(mod), Path.Combine(fileDirectoryPath, mod)); } } } }; try { foreach (var action in listOfAction) { try { if (index != 1) { index = 1; } action.Invoke(); } catch (Exception e) { Utils.Log("Exception detected", e); } Console.Write(" <Done>\n"); } } finally { Console.Write("[!] Cleaning..."); Clean(fileName); Console.Write(" <Done>\n"); Console.WriteLine(); Console.WriteLine(string.Format("[!] We're done, {0}", ExceptionCount != 0 ? "exception detected... please check Logs.txt" : "horray!")); } 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); } } }
internal static void Run(string path, Tasks task) { var bytes = File.ReadAllBytes(path); Console.Write(string.Format("[+] Checking {0}...", Path.GetFileName(path))); if (bytes[3] == 0x80) { Console.Write(" <Encrypted>\n"); if (task == Tasks.Encrypt) { Console.WriteLine(string.Format("[+] {0} is already encrypted... <Aborted>", Path.GetFileName(path))); return; } else if (task == Tasks.Decompile || task == Tasks.Recompile) { Console.WriteLine("[+] You cannot decompile an encrypted lua... <Aborted>"); return; } } else if (bytes[3] == 0x02) { Console.Write(" <Decrypted>\n"); if (task == Tasks.Decrypt) { Console.WriteLine(string.Format("[+] {0} is already decrypted... <Aborted>", Path.GetFileName(path))); return; } } else if (task != Tasks.Recompile) { Console.Write(" <Unknown>\n"); Console.WriteLine("[+] Not a valid or damaged lua file... <Aborted>"); return; } else { Console.Write(" <OK>\n"); } Console.Write($"[+] {(task == Tasks.Decrypt ? "Decrypting" : task == Tasks.Encrypt ? "Encrypting" : task == Tasks.Decompile ? "Decompiling" : "Recompiling")} {Path.GetFileName(path)}..."); var luaPath = Path.Combine(PathMgr.Environment(task == Tasks.Decrypt ? "Decrypted_lua" : task == Tasks.Encrypt ? "Encrypted_lua" : task == Tasks.Decompile ? "Decompiled_lua" : "Recompiled_lua"), Path.GetFileName(path)); if (File.Exists(luaPath)) { File.Delete(luaPath); } try { if (task == Tasks.Decrypt || task == Tasks.Encrypt) { using (var reader = new BinaryReader(new MemoryStream(bytes))) { 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 (task == Tasks.Encrypt) { bytes[3] = 0x80; bytes = Lock(start, bytes, (int)instructions_count); } else { bytes[3] = 2; bytes = Unlock(start, bytes, (int)instructions_count); } reader.BaseStream.Position = next; } } File.WriteAllBytes(luaPath, bytes); } else if (task == Tasks.Decompile || task == Tasks.Recompile) { Utils.Command(task == Tasks.Decompile ? $"python main.py -f \"{path}\" -o \"{luaPath}\"" : $"luajit.exe -b \"{path}\" \"{luaPath}\""); } Program.isInvalid = false; } catch (Exception e) { Utils.ExceptionLogger($"Exception detected during {(task == Tasks.Decrypt ? "decrypting" : task == Tasks.Encrypt ? "encrypting" : task == Tasks.Decompile ? "decompiling" : "recompiling")} {Path.GetFileName(path)}", e); } finally { if (File.Exists(luaPath)) { SuccessCount++; Console.Write("<done>\n"); } else { Console.Write("<failed>\n"); FailedCount++; } } }
internal static void Initialize(string lua, Tasks tasks) { try { Console.Write($"[+] {(tasks == Tasks.Decrypt ? "Decrypting" : tasks == Tasks.Encrypt ? "Encrypting" : tasks == Tasks.Decompile ? "Decompiling" : "Recompiling")} {Path.GetFileName(lua)}..."); var luaPath = Path.Combine(PathMgr.Environment(tasks == Tasks.Decrypt ? "Decrypted_lua" : tasks == Tasks.Encrypt ? "Encrypted_lua" : tasks == Tasks.Decompile ? "Decompiled_lua" : "Recompiled_lua"), Path.GetFileName(lua)); if (tasks == Tasks.Decrypt || tasks == Tasks.Encrypt) { var bytes = File.ReadAllBytes(lua); var reader = new BinaryReader(new MemoryStream(bytes)); 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; start += 4; var v2 = 0; do { if (tasks == Tasks.Encrypt) { bytes[3] = 0x80; var v3 = bytes[start - 4]; start += 4; var v4 = bytes[start - 7] ^ v2++; bytes[start - 8] = (byte)(Properties.Resources.Lock[v3] ^ v4); } else { bytes[3] = 2; var v3 = bytes[start - 4]; start += 4; var v4 = bytes[start - 7] ^ v3 ^ (v2++ & 0xFF); bytes[start - 8] = Properties.Resources.Unlock[v4]; } }while (v2 != (int)instructions_count); reader.BaseStream.Position = next; } if (File.Exists(luaPath)) { File.Delete(luaPath); } File.WriteAllBytes(luaPath, bytes); } else if (tasks == Tasks.Decompile || tasks == Tasks.Recompile) { Utils.Command(tasks == Tasks.Decompile ? $"python main.py -f \"{lua}\" -o \"{luaPath}\"" : $"luajit.exe -b \"{lua}\" \"{luaPath}\""); } Console.Write("<done>"); Console.WriteLine(); } catch (Exception e) { Console.Write("<exception-detected>"); } }