From ce8b81b70a9056d9933511a8060866dce80e1a7d Mon Sep 17 00:00:00 2001 From: Paul_GD Date: Tue, 28 Sep 2021 19:14:32 +0200 Subject: [PATCH] Update to v0.3 --- LiberatingMarsCLI/Program.cs | 55 ++++++++++++++++++++++++++++-------- README.md | 9 +++--- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/LiberatingMarsCLI/Program.cs b/LiberatingMarsCLI/Program.cs index 43cd5c5..e28e47c 100644 --- a/LiberatingMarsCLI/Program.cs +++ b/LiberatingMarsCLI/Program.cs @@ -36,7 +36,7 @@ public static void Main(string[] args) { chituLocation = args[0]; - Console.WriteLine("\n> LiberatingMars CLI v0.2 <"); + Console.WriteLine("\n> LiberatingMars CLI v0.3 <"); if (isWindows) Console.WriteLine("> Detected OS: Windows <"); else if (isLinux) @@ -65,6 +65,8 @@ public static void translateHeader() oldH.Magic = binRead.ReadUInt32(); oldH.Version = binRead.ReadUInt32(); + if (oldH.Version > 3) + skip(); oldH.BedSizeX = binRead.ReadSingle(); oldH.BedSizeY = binRead.ReadSingle(); @@ -508,16 +510,24 @@ public static void translateLayers() public static void saveNewCtb() { - sign(); - encrypt(); - save(); + sign(false); + encrypt(false); + save(false); } - public static void sign() + public static void sign(bool skip) { crypto.pullCrypto(chituLocation); byte[] signature = new byte[newH.SignatureSize]; - BinaryReader read = new BinaryReader(File.Open(headerTempLoc, FileMode.Open)); + String loc; + + if (skip) + loc = ctbLocation; + else + loc = headerTempLoc; + + BinaryReader read = new(File.Open(loc, FileMode.Open)); + read.BaseStream.Position = 0x30; SHA256 hash = SHA256.Create(); @@ -531,15 +541,22 @@ public static void sign() var EncHash = AES.AesCryptBytes(hashed8Bytes, true, chituLocation); encryptedHashed = EncHash; - BinaryWriter write = new BinaryWriter(File.Open(headerTempLoc, FileMode.Append)); + BinaryWriter write = new BinaryWriter(File.Open(loc, FileMode.Append)); write.Write(encryptedHashed); write.Close(); } - public static void encrypt() + public static void encrypt(bool skip) { + String loc; + + if (skip) + loc = ctbLocation; + else + loc = headerTempLoc; + crypto.pullCrypto(chituLocation); - BinaryReader read = new BinaryReader(File.Open(headerTempLoc, FileMode.Open)); + BinaryReader read = new BinaryReader(File.Open(loc, FileMode.Open)); read.BaseStream.Position = newH.HeaderOffset; byte[] header = new byte[newH.HeaderSize]; byte[] encHeader = new byte[newH.HeaderSize]; @@ -547,16 +564,30 @@ public static void encrypt() encHeader = AES.AesCryptBytes(header, true, chituLocation); read.Close(); - BinaryWriter write = new BinaryWriter(File.Open(headerTempLoc, FileMode.Open)); + BinaryWriter write = new BinaryWriter(File.Open(loc, FileMode.Open)); write.BaseStream.Position = newH.HeaderOffset; write.Write(encHeader); write.Close(); } - public static void save() + public static void save(bool skip) { - File.Copy(headerTempLoc, ctbLocation.Replace(".ctb", "_MARS3.ctb"), true); + String loc; + + if (skip) + loc = ctbLocation; + else + loc = headerTempLoc; + + File.Copy(loc, ctbLocation.Replace(".ctb", "_MARS3.ctb"), true); Console.WriteLine("> File saved at: " + ctbLocation.Replace(".ctb", "_MARS3.ctb") + " <"); } + + public static void skip() + { + sign(true); + encrypt(true); + save(true); + } } } diff --git a/README.md b/README.md index a25989e..f14456d 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,11 @@ **We don't want to be forced into which Slicer we use. Let's change that.** ### Usage: -LiberatingMarsCLI(.exe) [path to ChiTuBox 1.9.0] [path to legacy CTBv2 file] +LiberatingMarsCLI(.exe) [path to ChiTuBox 1.9.0] [path to legacy CTB file] ### Output: -[legacy CTBv2 file name]_MARS3.ctb +[file name]_MARS3.ctb -- LiberatingMarsCLI will switch to CTBv3 input once available. -- Layer specific settings and TSMC are not implemented yet. +- Layer specific settings and TSMC are not implemented. -We hope this will help the community to avoid ChiTu's SDK, which is not the solution we hoped for or expected. +We hope this will help the community to avoid ChiTu's SDK, which is not the solution we hoped for or expected. \ No newline at end of file