Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
Update to v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulGD03 committed Sep 28, 2021
1 parent 0d24eba commit ce8b81b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
55 changes: 43 additions & 12 deletions LiberatingMarsCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand All @@ -531,32 +541,53 @@ 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];
header = read.ReadBytes((int)newH.HeaderSize);
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);
}
}
}
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit ce8b81b

Please sign in to comment.