diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..61f7f67
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.suo
+*/bin/*
+*/obj/*
+.vs/*
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index cde4ac6..824551d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,10 +1,5 @@
-This is free and unencumbered software released into the public domain.
+All code is hereby entered into the Public Domain
-Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
-In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and
-successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-For more information, please refer to
+- Abolish Interlectual Property -
diff --git a/McCrypt/Crypto.cs b/McCrypt/Crypto.cs
new file mode 100644
index 0000000..901a33a
--- /dev/null
+++ b/McCrypt/Crypto.cs
@@ -0,0 +1,73 @@
+using System;
+using System.IO;
+using System.Security.Cryptography;
+
+namespace McCrypt
+{
+ internal class Crypto
+ {
+ internal static byte[] Sha256(byte[] data)
+ {
+ SHA256 sha256 = SHA256.Create();
+ byte[] hash = sha256.ComputeHash(data);
+ sha256.Dispose();
+ return hash;
+ }
+ internal static byte[] Aes256CfbEncrypt(byte[] key, byte[] iv, byte[] data)
+ {
+ Aes aes = Aes.Create();
+ aes.Mode = CipherMode.CFB;
+ aes.Padding = PaddingMode.None;
+ aes.BlockSize = 128;
+ aes.KeySize = 256;
+
+ ICryptoTransform aesEncryptor = aes.CreateEncryptor(key, iv);
+ using (MemoryStream msEncrypt = new MemoryStream())
+ {
+ using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, aesEncryptor, CryptoStreamMode.Write))
+ {
+ csEncrypt.Write(data, 0, data.Length);
+
+ long totalWritten = data.Length;
+ while ((totalWritten % 16 != 0))
+ {
+ csEncrypt.WriteByte(0);
+ totalWritten++;
+ }
+
+ msEncrypt.Seek(0x00, SeekOrigin.Begin);
+ return msEncrypt.ToArray();
+ }
+ }
+ }
+
+ internal static byte[] Aes256CfbDecrypt(byte[] key, byte[] iv, byte[] data)
+ {
+ Aes aes = Aes.Create();
+ aes.Mode = CipherMode.CFB;
+ aes.Padding = PaddingMode.Zeros;
+ aes.BlockSize = 128;
+ aes.KeySize = 256;
+
+ ICryptoTransform aesDecryptor = aes.CreateDecryptor(key, iv);
+ using (MemoryStream msDecrypt = new MemoryStream())
+ {
+ msDecrypt.Write(data, 0, data.Length);
+
+ while (msDecrypt.Length % 16 != 0)
+ msDecrypt.WriteByte(0);
+
+ msDecrypt.Seek(0x00, SeekOrigin.Begin);
+ using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, aesDecryptor, CryptoStreamMode.Read))
+ {
+ byte[] plaintext = new byte[msDecrypt.Length];
+ csDecrypt.Read(plaintext, 0x00, plaintext.Length);
+
+ Array.Copy(plaintext, data, data.Length);
+ return data;
+ }
+ }
+ }
+
+ }
+}
diff --git a/McCrypt/Keys.cs b/McCrypt/Keys.cs
new file mode 100644
index 0000000..2c48f80
--- /dev/null
+++ b/McCrypt/Keys.cs
@@ -0,0 +1,302 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace McCrypt
+{
+ public class Keys
+ {
+ private static Random rng = new Random();
+ public static string KeyDbFile = "";
+ internal struct content
+ {
+ public string FriendlyId;
+ public byte[] ContentKey;
+ }
+ public struct keysJsonStruct
+ {
+ public string id;
+ public string contentKey;
+ }
+
+ public static string lastTitleAccountId = "";
+ public static string lastMinecraftId = "";
+
+ private static string lastDeviceId = "";
+ private static List contentList = new List();
+ public static string ExportKeysJson()
+ {
+ List keysJson = new List();
+ foreach (content key in contentList.ToArray())
+ {
+ string ckey = Encoding.UTF8.GetString(key.ContentKey);
+ if (ckey == "s5s5ejuDru4uchuF2drUFuthaspAbepE")
+ continue;
+
+ keysJsonStruct kjs = new keysJsonStruct();
+ kjs.id = key.FriendlyId;
+ kjs.contentKey = ckey;
+ keysJson.Add(kjs);
+ }
+
+ return JsonConvert.SerializeObject(keysJson);
+ }
+ private static byte[] deriveUserKey(string UserId, string DeviceId)
+ {
+ byte[] userBytes = Encoding.Unicode.GetBytes(UserId);
+ byte[] deviceBytes = Encoding.Unicode.GetBytes(DeviceId);
+
+ int kLen = userBytes.Length;
+ if (deviceBytes.Length < kLen)
+ kLen = deviceBytes.Length;
+
+ byte[] key = new byte[kLen];
+
+ for (int i = 0; i < kLen; i++)
+ {
+ key[i] = (byte)(deviceBytes[i] ^ userBytes[i]);
+ }
+
+ return key;
+ }
+ internal static string GenerateKey()
+ {
+ string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
+ string key = "";
+ for (int i = 0; i < 32; i++)
+ {
+ key += allowedChars[rng.Next(0, allowedChars.Length)];
+ }
+ return key;
+ }
+
+ private static byte[] deriveEntKey(byte[] versionkey, byte[] titleaccountId)
+ {
+ int kLen = versionkey.Length;
+ if (titleaccountId.Length < kLen)
+ kLen = titleaccountId.Length;
+
+ byte[] key = new byte[versionkey.Length];
+
+ for (int i = 0; i < kLen; i++)
+ {
+ key[i] = (byte)(versionkey[i] ^ titleaccountId[i]);
+ }
+
+ return key;
+ }
+
+ private static byte[] deriveContentKey(byte[] UserKey, byte[] ContentKey)
+ {
+ int kLen = UserKey.Length;
+ if (ContentKey.Length < kLen)
+ kLen = ContentKey.Length;
+
+ byte[] key = new byte[kLen];
+
+ for (int i = 0; i < kLen; i++)
+ {
+ key[i] = (byte)(UserKey[i] ^ ContentKey[i]);
+ }
+
+ int ckLen = kLen / 2;
+ byte[] contentKey = new byte[ckLen];
+
+ for (int i = 0; i < kLen; i += 2)
+ {
+ contentKey[i / 2] = key[i];
+ }
+
+ return contentKey;
+ }
+
+ public static void AddKey(string FriendlyId, byte[] ContentKey, bool addToKeyCache = true)
+ {
+ if (LookupKey(FriendlyId) != null)
+ return;
+
+ string keyCacheEntry = FriendlyId + "=" + Encoding.UTF8.GetString(ContentKey);
+
+ if (addToKeyCache && KeyDbFile != "")
+ File.AppendAllText(KeyDbFile, keyCacheEntry + "\n");
+
+ content content = new content();
+ content.FriendlyId = FriendlyId;
+ content.ContentKey = ContentKey;
+
+ contentList.Add(content);
+ }
+
+ private static void readReceipt(string receiptData)
+ {
+ dynamic recData = Utils.JsonDecodeCloserToMinecraft(receiptData);
+ string userId = recData.Receipt.EntityId;
+ string deviceId = "";
+
+ if (recData.Receipt.ReceiptData != null)
+ deviceId = recData.Receipt.ReceiptData.DeviceId;
+
+ if (deviceId == "" || deviceId == null)
+ deviceId = lastDeviceId;
+
+ if (deviceId == "" || deviceId == null)
+ return;
+
+ lastDeviceId = deviceId;
+
+ byte[] userKey = deriveUserKey(userId, deviceId);
+
+ // Derive content keys
+ int totalEntitlements = recData.Receipt.Entitlements.Count;
+
+ for (int i = 0; i < totalEntitlements; i++)
+ {
+ try
+ {
+ string friendlyId = recData.Receipt.Entitlements[i].FriendlyId;
+ string contentKeyB64 = recData.Receipt.Entitlements[i].ContentKey;
+ if (contentKeyB64 == null)
+ continue;
+
+ byte[] contentKey = Utils.ForceDecodeBase64(contentKeyB64);
+ byte[] realContentKey = deriveContentKey(userKey, contentKey);
+
+ AddKey(friendlyId, realContentKey);
+
+ }
+ catch (Exception) { continue; }
+ }
+
+ }
+
+ public static void ReadOptionsTxt(string optionsTxtPath)
+ {
+ string[] optionsTxt = File.ReadAllLines(optionsTxtPath);
+ foreach (string option in optionsTxt)
+ {
+ string opt = option.Replace("\r", "").Replace("\n", "").Trim();
+
+ string[] kvpair = opt.Split(':');
+ if (kvpair.Length >= 2)
+ {
+ if (kvpair[0].Trim() == "last_minecraft_id")
+ {
+ lastMinecraftId = kvpair[1].Trim().ToUpper();
+ }
+
+ if (kvpair[0].Trim() == "last_title_account_id")
+ {
+ lastTitleAccountId = kvpair[1].Trim().ToUpper();
+ }
+
+ }
+ }
+ }
+
+ private static string padLastTileAccountId(string lastTitleAccountId)
+ {
+ StringBuilder deriveText = new StringBuilder();
+
+ for (int i = 0; i < 32; i++)
+ deriveText.Append(lastTitleAccountId[i % lastTitleAccountId.Length]);
+
+ return deriveText.ToString();
+ }
+
+ private static string decryptEntitlementFile(string encryptedEnt)
+ {
+ int version = Int32.Parse(encryptedEnt.Substring(7, 1));
+ byte[] versionkey;
+ switch (version)
+ {
+ case 2:
+ default:
+ versionkey = Encoding.UTF8.GetBytes("X(nG*ejm&E8)m+8c;-SkLTjF)*QdN6_Y");
+ break;
+ }
+
+
+
+ string deriveText = padLastTileAccountId(lastTitleAccountId);
+ byte[] entKey = deriveEntKey(versionkey, Encoding.UTF8.GetBytes(deriveText));
+
+ string entBase64 = encryptedEnt.Substring(8);
+ byte[] entCiphertext = Utils.ForceDecodeBase64(entBase64);
+
+ byte[] entPlaintext = Marketplace.decryptEntitlementBuffer(entCiphertext, entKey);
+
+ return Encoding.UTF8.GetString(entPlaintext);
+ }
+ public static void ReadEntitlementFile(string entPath)
+ {
+ string jsonData = File.ReadAllText(entPath);
+
+
+ if(jsonData.StartsWith("Version")) // Thanks mojang, this was a fun challange <3
+ {
+ jsonData = decryptEntitlementFile(jsonData);
+ }
+ dynamic entData;
+ try
+ {
+ entData = Utils.JsonDecodeCloserToMinecraft(jsonData);
+ }
+ catch (Exception) { return; }
+
+ string receiptB64 = entData.Receipt;
+
+ if (receiptB64 == null)
+ return;
+
+ if (receiptB64.Split('.').Length <= 1)
+ return;
+
+ string receiptData = Encoding.UTF8.GetString(Utils.ForceDecodeBase64(receiptB64.Split('.')[1]));
+ readReceipt(receiptData);
+ int totalItems = entData.Items.Count;
+ for (int i = 0; i < totalItems; i++)
+ {
+ string b64Data = entData.Items[i].Receipt;
+
+ if (b64Data == null)
+ continue;
+
+ if (b64Data.Split('.').Length <= 1)
+ continue;
+
+ string recept = Encoding.UTF8.GetString(Utils.ForceDecodeBase64(b64Data.Split('.')[1]));
+ readReceipt(recept);
+ }
+ }
+ public static void ReadKeysDb(string keyFile)
+ {
+ KeyDbFile = keyFile;
+ string[] keyList = File.ReadAllLines(keyFile);
+ foreach (string key in keyList)
+ {
+ if (key.Contains('='))
+ {
+ string[] keys = key.Split('=');
+ if (keys.Length >= 2)
+ {
+ string friendlyId = keys[0];
+ byte[] contentKey = Encoding.UTF8.GetBytes(keys[1]);
+ AddKey(friendlyId, contentKey, false);
+ }
+ }
+ }
+ }
+ public static byte[] LookupKey(string FriendlyId)
+ {
+ foreach (content content in contentList)
+ {
+ if (content.FriendlyId == FriendlyId)
+ return content.ContentKey;
+ }
+ return null;
+ }
+ }
+}
diff --git a/McCrypt/LibMcCrypt.csproj b/McCrypt/LibMcCrypt.csproj
new file mode 100644
index 0000000..d4a6c1d
--- /dev/null
+++ b/McCrypt/LibMcCrypt.csproj
@@ -0,0 +1,59 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {4BEF6F52-6545-4BB9-8053-50335A1C6789}
+ Library
+ Properties
+ McCrypt
+ LibMcCrypt
+ v4.8
+ 512
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ none
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/McCrypt/Manifest.cs b/McCrypt/Manifest.cs
new file mode 100644
index 0000000..1b2f228
--- /dev/null
+++ b/McCrypt/Manifest.cs
@@ -0,0 +1,125 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Newtonsoft.Json;
+using System.IO;
+using System.Text;
+
+namespace McCrypt
+{
+ public class Manifest
+ {
+ private struct signatureBlock
+ {
+ public string hash;
+ public string path;
+ }
+
+ public static string SignManifestString(string manifestJson, string setPath)
+ {
+ signatureBlock signBlock = new signatureBlock();
+ signBlock.path = setPath;
+ signBlock.hash = Convert.ToBase64String(Crypto.Sha256(Encoding.UTF8.GetBytes(manifestJson)));
+
+ List signatureData = new List();
+ signatureData.Add(signBlock);
+
+ string signatureJson = JsonConvert.SerializeObject(signatureData);
+ return signatureJson;
+ }
+
+ public static void SignManifest(string basePath)
+ {
+ string manifestPath = Path.Combine(basePath, "manifest.json");
+
+ signatureBlock signBlock = new signatureBlock();
+ signBlock.path = manifestPath.Remove(0, basePath.Length + 1);
+ signBlock.hash = Convert.ToBase64String(Crypto.Sha256(File.ReadAllBytes(manifestPath)));
+
+ List signatureData = new List();
+ signatureData.Add(signBlock);
+
+ string signatureJson = JsonConvert.SerializeObject(signatureData);
+ string signaturesJsonFile = Path.Combine(basePath, "signatures.json");
+ File.WriteAllText(signaturesJsonFile, signatureJson);
+ }
+ public static string ReadName(string manifestFile)
+ {
+ string defaultName = Path.GetFileName(Path.GetDirectoryName(manifestFile));
+ if (!File.Exists(manifestFile))
+ return Utils.TrimName(defaultName);
+
+ string manifestStr = File.ReadAllText(manifestFile);
+ dynamic manifestData = JsonConvert.DeserializeObject(manifestStr);
+ if (manifestData.header != null)
+ {
+ if (manifestData.header.name != null)
+ {
+ string name = manifestData.header.name;
+ string englishLanguageFile = Path.Combine(Path.GetDirectoryName(manifestFile), "texts", "en_US.lang");
+
+ if (File.Exists(englishLanguageFile))
+ {
+ string[] lines = File.ReadAllLines(englishLanguageFile);
+ foreach (string line in lines)
+ {
+ if (!line.Contains('='))
+ continue;
+
+ string[] values = line.Split('=');
+
+ // How tf does this work??!!
+
+ if (values.Length <= 0)
+ continue;
+
+ if (values[0] == name)
+ return Utils.TrimName(values[1]);
+
+ if (values[0] == "pack.name")
+ return Utils.TrimName(values[1]);
+
+ if (values[0].Contains('.'))
+ {
+ string[] values2 = values[0].Split('.');
+ if (values2.Length <= 0)
+ return Utils.TrimName(defaultName);
+
+ if (values[0].Split('.').Last() == name)
+ return Utils.TrimName(values[1]);
+
+ if (values2[0] == "skinpack")
+ return Utils.TrimName(values[1]);
+
+ }
+
+ if (values[0].Contains(name))
+ return Utils.TrimName(values[1]);
+ }
+ if (name.Contains("."))
+ return Utils.TrimName(defaultName);
+ else
+ return Utils.TrimName(name);
+ }
+ else
+ return Utils.TrimName(defaultName);
+
+ }
+ }
+
+ return Utils.TrimName(defaultName);
+ }
+ public static string ReadUUID(string manifestPath)
+ {
+ dynamic manifest = JsonConvert.DeserializeObject(File.ReadAllText(manifestPath));
+ return manifest.header.uuid.ToString();
+ }
+
+ public static void ChangeUUID(string manifestPath, string newUUID)
+ {
+ dynamic manifest = JsonConvert.DeserializeObject(File.ReadAllText(manifestPath));
+ manifest.header.uuid = newUUID;
+ File.WriteAllText(manifestPath, JsonConvert.SerializeObject(manifest));
+ }
+ }
+}
diff --git a/McCrypt/Marketplace.cs b/McCrypt/Marketplace.cs
new file mode 100644
index 0000000..4537768
--- /dev/null
+++ b/McCrypt/Marketplace.cs
@@ -0,0 +1,329 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Text;
+using System.Threading;
+
+namespace McCrypt
+{
+ public class Marketplace
+ {
+ // Hi mojang <3
+ // https://www.youtube.com/watch?v=jIM6dN3ogbk
+ // https://www.youtube.com/watch?v=mnnYCJNhw7w
+
+ private static string[] dontEncrypt = new string[] { "manifest.json", "contents.json", "texts", "pack_icon.png", "ui"};
+ private struct contentsJson
+ {
+ public int version;
+ public List