Advertisement
Guest User

GMLicenseSigner

a guest
Mar 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.19 KB | None | 0 0
  1. /*
  2.  * In GMS2 they made the GMAssetCompiler verify your license file
  3.  * It uses RSA to do it
  4.  * ... and then they added the option to specify your own keys
  5.  * good fucking job
  6.  */
  7.  
  8. using Org.BouncyCastle.Crypto.Encodings;
  9. using Org.BouncyCastle.Crypto.Engines;
  10. using Org.BouncyCastle.Crypto.Parameters;
  11. using Org.BouncyCastle.Math;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Security.Cryptography;
  17. using System.Text;
  18. using System.Xml;
  19. using System.Xml.Linq;
  20.  
  21. namespace GMLicense
  22. {
  23.     class Keys
  24.     {
  25.         public const String Modulus = "AEFD4A9B137D5EC3D80B11094948770D342E87CBF81E418A54FB61BBCDB8D40F241E242822C50327E20003EE57CCA877BF35A2A55A0EB06537F369B722C9DAAB943F33593CC458A7055C0D80CAE9112FD0F4BBC53AD1FEE67C83DDED354216F30EA7126200DE83FAEB7A9880647BFE16B9A0406C7B90D20315F011CCBB85070B";
  26.         public const String PublicExponent = "03";
  27.         public const String PrivateExponent = "74A8DC6762539482900760B0DB85A4B3781F0532A5698106E3524127DE7B380A1814181AC1D8ACC5415557F43A88704FD4CE6C6E3C09CAEE254CF124C1DBE71BF2B1BD2C550A95AEC64E1859444BD879815A820CD22A66E50C6B0658C475FEB83DB423101295BE269315353DFD2B5515A827C4C43C7FF28EDB13ECDA76EF125B";
  28.         public const String Prime1 = "E1E58992501733C45719035DBC615326809E41B49D46A838A1EAAD0807B8866D4206DAEB7DE63BE374D73F9A560393BF9B1884B8CDFEDE9D6BCD0B245CDCA677";
  29.         public const String Prime2 = "C64F0E046D1D445C84CDE59D2815F9530E4EB6FD624BBC5647F8A76006D89271701202DE6717AADD9A03890912B76AB6A24C148D52D2078F61852360AC41C50D";
  30.         public const String Exponent1 = "969906618ABA2282E4BB5793D2EB8CC455BED67868D9C57B169C735AAFD0599E2C0491F253EED297A33A2A66E402627FBCBB0325DEA9E9BE47DE076D933DC44F";
  31.         public const String Exponent2 = "8434B402F368D83DADDE9913700EA6375EDF24A8EC327D8EDAA5C4EAAF3B0C4BA00C01E99A0FC73E66AD06060C7A47246C32B85E3736AFB4EBAE1795C82BD8B3";
  32.         public const String Coefficent = "2659d9ec51d4886df62574301fbce9b18d8479b36f33e8961ba6179395bb73dcf019c641c4efb4d88f10fdf2351117744fe65a1a9b7a45e63dfc9ce135bec994";
  33.  
  34.         public static RsaKeyParameters GetPublicKey()
  35.         {
  36.             return new RsaKeyParameters(false, new BigInteger(Modulus, 16), new BigInteger(PublicExponent, 16));
  37.         }
  38.  
  39.         public static RsaPrivateCrtKeyParameters GetPrivateKey()
  40.         {
  41.             return new RsaPrivateCrtKeyParameters(new BigInteger(Modulus, 16), new BigInteger(PublicExponent, 16), new BigInteger(PrivateExponent, 16), new BigInteger(Prime1, 16), new BigInteger(Prime2, 16), new BigInteger(Exponent1, 16), new BigInteger(Exponent2, 16), new BigInteger(Coefficent, 16));
  42.         }
  43.     }
  44.  
  45.     class Crypto
  46.     {
  47.         public static String SignData(RsaPrivateCrtKeyParameters PrivateKey, String ToBeSigned)
  48.         {
  49.             byte[] Data = Encoding.UTF8.GetBytes(ToBeSigned);
  50.             byte[] sha1Hash = SHA1.Create().ComputeHash(Data);
  51.  
  52.             Pkcs1Encoding pkcs1Encoding = new Pkcs1Encoding(new RsaEngine());
  53.             pkcs1Encoding.Init(true, PrivateKey);
  54.             int inputBlockSize = pkcs1Encoding.GetInputBlockSize();
  55.            
  56.             byte[] EncryptedData  = pkcs1Encoding.ProcessBlock(sha1Hash, 0, sha1Hash.Length);
  57.  
  58.             var signedString = Convert.ToBase64String(EncryptedData);
  59.             return signedString;
  60.         }
  61.     }
  62.  
  63.     class LicenseFormat
  64.     {
  65.         private static Dictionary<string, string> Parse_Plist(string string_36)
  66.         {
  67.             StringBuilder stringBuilder = new StringBuilder();
  68.             using (StringReader stringReader = new StringReader(string_36))
  69.             {
  70.                 string text;
  71.                 while ((text = stringReader.ReadLine()) != null)
  72.                 {
  73.                     if (!text.Contains("DOCTYPE") || !text.Contains("DTD"))
  74.                     {
  75.                         stringBuilder.Append(text);
  76.                     }
  77.                 }
  78.             }
  79.             string s = stringBuilder.ToString();
  80.             Dictionary<string, string> dictionary = new Dictionary<string, string>();
  81.             XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
  82.             xmlReaderSettings.IgnoreComments = true;
  83.             xmlReaderSettings.ProhibitDtd = true;
  84.             using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(s)))
  85.             {
  86.                 using (XmlReader xmlReader = XmlReader.Create(memoryStream, xmlReaderSettings))
  87.                 {
  88.                     XmlDocument xmlDocument = new XmlDocument();
  89.                     xmlDocument.XmlResolver = null;
  90.                     xmlDocument.Load(xmlReader);
  91.                     XmlNode xmlNode = xmlDocument.SelectSingleNode("plist/dict");
  92.                     for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
  93.                     {
  94.                         if (xmlNode.ChildNodes[i].Name == "key")
  95.                         {
  96.                             dictionary.Add(xmlNode.ChildNodes[i].InnerText, xmlNode.ChildNodes[i + 1].InnerText);
  97.                             i++;
  98.                         }
  99.                     }
  100.                 }
  101.             }
  102.             return dictionary;
  103.         }
  104.  
  105.         private static string createLicenseString(string plist)
  106.         {
  107.             Dictionary<string, string> PlistDict = Parse_Plist(plist);
  108.             List<string> PlistEntryList = PlistDict.Keys.ToList<string>();
  109.             PlistEntryList.Sort();
  110.             StringBuilder stringBuilder = new StringBuilder();
  111.             foreach (string PlistEntry in PlistEntryList)
  112.             {
  113.                 string value = PlistDict[PlistEntry];
  114.                 if (string.Compare(PlistEntry, "Signature", true) != 0)
  115.                 {
  116.                     stringBuilder.Append(value);
  117.                 }
  118.             }
  119.             return stringBuilder.ToString();
  120.         }
  121.  
  122.         public static String CreateLicense(String AllowedPlatforms, RsaPrivateCrtKeyParameters PrivateKey)
  123.         {
  124.             String PlistFile = new XElement("plist",
  125.                             new XElement("dict",
  126.                             new XElement("key", "Signature"),
  127.                             new XElement("data", "---SIGNATURE GOES HERE---"),
  128.                             new XElement("key", "public_key"), //Thanks yoyo 4 backdoor lol
  129.                             new XElement("string", Keys.Modulus),
  130.                             new XElement("key", "components"),
  131.                             new XElement("string", AllowedPlatforms),
  132.                             new XElement("key", "expiry_date"),
  133.                             new XElement("string", DateTime.UtcNow.AddDays(3).ToString("yyyy-mm-dd HH:mm:ss UTC")),
  134.                             new XElement("key", "id"),
  135.                             new XElement("string", "1337"),
  136.                             new XElement("key", "email"),
  137.                             new XElement("string", "girls@dying.moe"))).ToString();
  138.            
  139.             //Sign license with your private key
  140.             string licenseString = createLicenseString(PlistFile);
  141.             string signature = Crypto.SignData(PrivateKey, licenseString);
  142.             return PlistFile.Replace("---SIGNATURE GOES HERE---",signature);
  143.         }
  144.  
  145.  
  146.  
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement