ground up refactor!

This commit is contained in:
Neo Anderson committed 2020-03-29 23:54:41 -07:00
1 parent 6a2ab0d873
commit 7c2960e1d7
19 files changed
+3534 -3444

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace FrappeMocha.Keygen
{
public abstract class KeygenBase
{
public const string CompanyLicense = "Company License";
public const string SingleUserLicense = "Single User License";
protected string Platform;
protected int ByteEncoding = 0;
public List<KeygenProduct> Products = new List<KeygenProduct>();
public abstract string Generate(int type, string paramCompany, LicenseTypes license);
public abstract bool Check(string paramLicenseKey, string paramCompany, LicenseTypes license);
public virtual List<string> GenerateLicencetypes(KeygenProduct p)
{
List<string> licenses = new List<string>();
licenses.Add(CompanyLicense);
licenses.Add(SingleUserLicense);
return licenses;
}
public override string ToString()
{
return Platform;
}
public byte[] StrToByteArray(string str)
{
try
{
return Encoding.GetEncoding(this.ByteEncoding).GetBytes(str);
}
catch (Exception)
{
try
{
return Encoding.GetEncoding(0).GetBytes(str);
}
catch (Exception)
{
return new byte[1] { (byte)63 };
}
}
}
public string ByteArrayToStr(byte[] barr, int index, int length)
{
try
{
return Encoding.GetEncoding(this.ByteEncoding).GetString(barr, index, length);
}
catch (Exception)
{
try
{
return Encoding.GetEncoding(0).GetString(barr, index, length);
}
catch (Exception)
{
return "?";
}
}
}
}
}
+35
View File
@@ -0,0 +1,35 @@
using System.Collections.Generic;
namespace FrappeMocha.Keygen
{
public class KeygenProduct
{
public LicenseTypes Licence;
public string Description;
public KeygenProduct(LicenseTypes licence, string description, string platform)
{
Licence = licence;
Description = description + " for " + platform;
}
public override string ToString()
{
return Description;
}
public override bool Equals(object obj)
{
return obj is KeygenProduct product && Description == product.Description ||
obj is string description && description == Description;
}
public override int GetHashCode()
{
var hashCode = -1651123971;
hashCode = hashCode * -1521134295 + Licence.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Description);
return hashCode;
}
}
}
+30
View File
@@ -0,0 +1,30 @@
namespace FrappeMocha.Keygen
{
public enum LicenseTypes
{
Windows3270 = 0x8c,
Windows5250 = 0x80,
Windows3812 = 0xa0,
WindowsTelnet = 0x9b,
Java3270 = 0x1b + 2,
Java5250 = 0x1b + 2,
JavaTelnet = 0x1b,
Mac3270 = 0x5d,
Mac5250 = 0x16,
Mac3812 = 0x22,
MacTelnet = 0x5e,
MacKeyboard = 0xa5,
JavaScript3270 = 0xb3,
JavaScript5250 = 0xb2,
JavaScriptTelnet = 0xb4,
Android3270 = 0x94,
Android5250 = 0x91,
AndroidTelnet = 0x96,
AndroidVnc = 0x92,
AndroidBarcode = 0x9c,
}
}
+101
View File
@@ -0,0 +1,101 @@
using System;
namespace FrappeMocha.Keygen.Platforms
{
public class PlatformAndroid : KeygenBase
{
public PlatformAndroid()
{
Platform = "Android";
Products.Add(new KeygenProduct(LicenseTypes.Android3270, "TN3270", Platform));
Products.Add(new KeygenProduct(LicenseTypes.Android5250, "TN5250", Platform));
Products.Add(new KeygenProduct(LicenseTypes.AndroidTelnet, "TN3812", Platform));
Products.Add(new KeygenProduct(LicenseTypes.AndroidVnc, "VNC", Platform));
Products.Add(new KeygenProduct(LicenseTypes.AndroidBarcode, "Barcode", Platform));
}
/**
* This was also a piece of cake since PlatformJava is the underlying tech on PlatformAndroid
* The Dex object engine keept pretty good tabs on the types and var names as well!
*/
public override string Generate(int itype, string paramCompany, LicenseTypes license)
{
char type = (char)(itype + '0');
string paramLicencekey = type.ToString();
long sum = 0;
byte[] byteArray = StrToByteArray(paramCompany);
for (int index = 0; index < byteArray.Length; ++index)
{
if ((long)byteArray[index] >= 'A' && (long)byteArray[index] <= 'Z')
byteArray[index] += 32; // this is basically str.toLower()
}
for (int index = 0; index < byteArray.Length; ++index)
{
if ((ulong)byteArray[index] >= 'A' && (ulong)byteArray[index] <= 'z')
{
sum += byteArray[index] + (uint)license;
}
}
sum = sum * paramLicencekey[0];
sum = sum * (sum & byte.MaxValue) & ushort.MaxValue;
if (sum < 100U)
sum = 2728U;
paramLicencekey = (paramLicencekey[0].ToString() + sum) + '-' +
(Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
return paramLicencekey;
}
/**
* Straight outta da Dex
*/
public override bool Check(string paramLicenseKey, string paramCompany, LicenseTypes license)
{
byte[] bArr = new byte[255];
byte[] bArr2 = new byte[255];
if (paramCompany.Length < 2 || paramLicenseKey.Length < 2)
{
return false;
}
for (int i = 0; i < paramLicenseKey.Length; i++)
{
bArr2[i] = (byte)paramLicenseKey[i];
}
for (int i2 = 0; i2 < paramCompany.Length; i2++)
{
bArr[i2] = (byte)paramCompany[i2];
if (paramCompany[i2] >= 'A' && paramCompany[i2] <= 'Z')
{
bArr[i2] = (byte)(bArr[i2] + 32);
}
}
long j = 0;
for (int i3 = 0; i3 < paramCompany.Length; i3++)
{
if (bArr[i3] >= 65 && bArr[i3] <= 122)
{
j += (bArr[i3] + (long)license);
}
}
long j2 = j * bArr2[0];
long j3 = (j2 * (j2 & 255)) & 65535;
if (j3 < 100)
{
j3 = 2728;
}
string sb = "";
sb += paramLicenseKey[0];
sb += (object)j3;
if (paramLicenseKey.StartsWith(sb))
{
// lictype = bArr2[0] - 48;
// is_lite2 = false;
return true;
}
// lictype = -1;
return false;
}
}
}
+94
View File
@@ -0,0 +1,94 @@
using System.Collections.Generic;
namespace FrappeMocha.Keygen.Platforms
{
public class PlatformJava : KeygenBase
{
public PlatformJava()
{
Platform = "Java";
Products.Add(new KeygenProduct(LicenseTypes.Java3270, "TN3270", Platform));
Products.Add(new KeygenProduct(LicenseTypes.Java5250, "TN5250", Platform));
Products.Add(new KeygenProduct(LicenseTypes.JavaTelnet, "Telnet", Platform));
}
public override List<string> GenerateLicencetypes(KeygenProduct p)
{
List<string> types = new List<string>();
for (int i = 0; i < 5; i++)
{
types.Add(((char)(i + 'A')).ToString());
}
return types;
}
/**
* Pretty stright forward implementation as well
* .NET is just a copy of PlatformJava afterall
*/
public override string Generate(int itype, string paramCompany, LicenseTypes license)
{
char type = (char)(itype + 'A');
string paramLicencekey = type.ToString() + '@';
int sum = 0;
int i = 0;
while (i < paramCompany.Length)
{
if (paramCompany[i] > ' ')
{
// 3270 and 5250 have a hardcoded 0x1b+2 here, we've just added it to the enum
sum += paramCompany[i] + (int)license;
}
++i;
}
sum = sum * paramLicencekey[0];
sum = sum * (sum & byte.MaxValue) & ushort.MaxValue;
paramLicencekey += sum.ToString();
return paramLicencekey;
}
/**
* Straight outta da JAR
*/
public override bool Check(string paramLicenseKey, string paramCompany, LicenseTypes license)
{
int i = 0;
int n = 0;
while (i < paramCompany.Length)
{
if (paramCompany[i] > ' ')
{
// 3270 and 5250 have a hardcoded 0x1b+2 here, we've just added it to the enum
n += paramCompany[i] + (int)license;
}
++i;
}
if (paramLicenseKey.Length > 0)
{
switch (paramLicenseKey[0])
{
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
break;
default:
return false;
}
int n2 = n * paramLicenseKey[0];
n2 = n2 * (n2 & 0xFF) & 0xFFFF;
string check = paramLicenseKey[0].ToString() + paramLicenseKey[1].ToString() + n2.ToString();
if (paramLicenseKey[1] == '@' && check == paramLicenseKey)
{
return true;
}
}
return false;
}
}
}
+83
View File
@@ -0,0 +1,83 @@
using System;
namespace FrappeMocha.Keygen.Platforms
{
public class PlatformJavaScript : KeygenBase
{
public PlatformJavaScript()
{
Platform = "Google Chrome";
Products.Add(new KeygenProduct(LicenseTypes.JavaScript3270, "TN3270", Platform));
Products.Add(new KeygenProduct(LicenseTypes.JavaScript5250, "TN5250", Platform));
Products.Add(new KeygenProduct(LicenseTypes.JavaScriptTelnet, "Telnet", Platform));
}
/**
* This one was fun as well
* Found out that the license must end with "45" in order to validate
*/
public override string Generate(int itype, string paramCompany, LicenseTypes license)
{
char type = (char)(itype + '0');
string param_lickey = type.ToString();
ulong sum = 0;
byte[] byteArray = StrToByteArray(paramCompany);
for (int index = 0; index < byteArray.Length; ++index)
{
if (byteArray[index] >= 'A' && byteArray[index] <= 'Z')
byteArray[index] += 32; // ASCII 'Space'
}
for (int index = 0; index < byteArray.Length; ++index)
{
if ((ulong)byteArray[index] >= 'A' && (ulong)byteArray[index] <= 'z')
{
sum += byteArray[index] + (uint)license;
}
}
sum = sum * param_lickey[0];
sum = sum * (sum & byte.MaxValue) & ushort.MaxValue;
if (sum < 100U)
sum = 2728U;
param_lickey = (param_lickey[0].ToString() + sum) + '-' +
(Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds
+ "45"; // a little salt, as a treat
return param_lickey;
}
/**
* Straight outta da JS
*/
public override bool Check(string paramLicenseKey, string paramCompany, LicenseTypes license)
{
ulong sum = 0;
byte[] byteArray = this.StrToByteArray(paramCompany);
for (int index = 0; index < byteArray.Length; ++index)
{
if ((ulong)byteArray[index] >= 65 && (ulong)byteArray[index] <= 90)
byteArray[index] += 32;
}
for (int index = 0; index < byteArray.Length; ++index)
{
if ((ulong)byteArray[index] >= 65 && (ulong)byteArray[index] <= 122)
{
sum += byteArray[index] + (uint)license;
}
}
sum = sum * paramLicenseKey[0];
sum = sum * (sum & byte.MaxValue) & ushort.MaxValue;
if (sum < 100U)
sum = 2728U;
if (!paramLicenseKey.StartsWith(paramLicenseKey[0].ToString() + sum) || !paramLicenseKey.EndsWith("45"))
{
return false;
}
return true;
}
}
}
+140
View File
@@ -0,0 +1,140 @@
using System.Collections.Generic;
namespace FrappeMocha.Keygen.Platforms
{
public class PlatformMac : KeygenBase
{
public PlatformMac()
{
Platform = "MacOSX";
Products.Add(new KeygenProduct(LicenseTypes.Mac3270, "TN3270", Platform));
Products.Add(new KeygenProduct(LicenseTypes.Mac5250, "TN5250", Platform));
Products.Add(new KeygenProduct(LicenseTypes.Mac3812, "TN3812", Platform));
Products.Add(new KeygenProduct(LicenseTypes.MacTelnet, "Telnet", Platform));
Products.Add(new KeygenProduct(LicenseTypes.MacKeyboard, "Keyboard", Platform));
}
public override List<string> GenerateLicencetypes(KeygenProduct p)
{
if (p.Licence != LicenseTypes.Mac3812 &&
p.Licence != LicenseTypes.MacTelnet &&
p.Licence != LicenseTypes.MacKeyboard)
{
return base.GenerateLicencetypes(p);
}
List<string> types = new List<string>();
types.Add("0");
return types;
}
public override string Generate(int type, string paramCompany, LicenseTypes license)
{
switch (license)
{
// Prefix Num
case LicenseTypes.Mac3270:
case LicenseTypes.Mac5250:
return GeneratePrefixNumber(type, paramCompany, license);
// Prefix Alpha
case LicenseTypes.Mac3812:
case LicenseTypes.MacTelnet:
case LicenseTypes.MacKeyboard:
return GeneratePrefixAlpha(type, paramCompany, license);
}
return "";
}
/**
* @todo: write some sanity checks
* I doubt I'll be able to get something straight outta da Ghidra here...
*/
public override bool Check(string paramLicenseKey, string paramCompany, LicenseTypes license)
{
switch (license)
{
// Prefix Num
case LicenseTypes.Mac3270:
case LicenseTypes.Mac5250:
return true;
// Prefix Alpha
case LicenseTypes.Mac3812:
case LicenseTypes.MacTelnet:
case LicenseTypes.MacKeyboard:
return true;
}
return false;
}
/**
* Now the fun stuff..
*
* Beware! the PlatformMac versions rely on datatype truncation
* It's a real pain in the ass to make sure the datatypes are all accurate
*/
public string GeneratePrefixAlpha(int itype, string param_company, LicenseTypes license)
{
// must start with an 'a' or 'b;
char type = (char)(itype + (int)'a');
string param_lickey = type.ToString();
ushort sum = 0;
for (int b = 0; b < param_company.Length; b++)
{
if (param_company[b] >= 0x21)
sum += (ushort)(param_company[b] + license);
}
sum = (ushort)(sum * (short)param_lickey[0]);
param_lickey += (ushort)((sum & byte.MaxValue) * sum);
return param_lickey;
}
/**
* Beware! the PlatformMac versions rely on datatype truncation
* It's a real pain in the ass to make sure the datatypes are all accurate
*
* There's a special case for the MacKeyboard as it deviates from the rest of the algoritm
* The (byte) cast is extmely important
*/
public string GeneratePrefixNumber(int itype, string param_company, LicenseTypes license)
{
char type = (char)(itype + (int)'0');
string param_lickey = type.ToString();
uint num1 = 0;
byte[] byteArray = StrToByteArray(param_company);
for (int index = 0; index < byteArray.Length; ++index)
{
if (license == LicenseTypes.MacKeyboard && (byte)(byteArray[index] + 0xbf) < 0x1a)
{
byteArray[index] += 32;
}
else if (license != LicenseTypes.MacKeyboard && byteArray[index] + 0xbf < 0x1a)
{
byteArray[index] += 32;
}
}
for (int index = 0; index < byteArray.Length; ++index)
{
if (byteArray[index] >= 0x41) // 'A'
num1 += byteArray[index] + (uint)license;
}
uint num2 = (uint)(num1 * (int)param_lickey[0]);
num2 = (num2 * (num2 & byte.MaxValue) & ushort.MaxValue);
ulong num3 = 0xaa8;
if (99 < num2)
{
num3 = num2;
}
param_lickey = param_lickey[0].ToString() + num3;
return param_lickey;
}
}
}
+81
View File
@@ -0,0 +1,81 @@
using System;
namespace FrappeMocha.Keygen.Platforms
{
public class PlatformWindows : KeygenBase
{
public PlatformWindows()
{
Platform = "Windows";
Products.Add(new KeygenProduct(LicenseTypes.Windows3270, "TN3270", Platform));
Products.Add(new KeygenProduct(LicenseTypes.Windows5250, "TN5250", Platform));
Products.Add(new KeygenProduct(LicenseTypes.Windows3812, "TN3812", Platform));
Products.Add(new KeygenProduct(LicenseTypes.WindowsTelnet, "Telnet", Platform));
}
public override string Generate(int type, string paramCompany, LicenseTypes license)
{
string licenseKey = type.ToString();
uint sum = 0;
byte[] byteArray = StrToByteArray(paramCompany);
for (int index = 0; index < byteArray.Length; ++index)
{
if (byteArray[index] >= 'A' && byteArray[index] <= 'Z')
byteArray[index] += 32; // ASCII 'Space'
}
for (int index = 0; index < byteArray.Length; ++index)
{
if (byteArray[index] >= 'A')
sum += byteArray[index] + (uint)license;
}
sum = sum * licenseKey[0];
sum = (uint)((int)sum * ((int)sum & byte.MaxValue) & ushort.MaxValue);
if (sum < 100U)
sum = 2728U;
licenseKey = (licenseKey[0].ToString() + sum) + '-' +
(Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
return licenseKey;
}
/**
* Straight outta da Assembley
*/
public override bool Check(string paramLicenseKey, string paramCompany, LicenseTypes license)
{
uint num1 = 0;
if (paramCompany == null || paramCompany.Length < 2)
return false;
byte[] byteArray = this.StrToByteArray(paramCompany);
if (paramLicenseKey == null || paramLicenseKey.Length < 6)
return false;
for (int index = 0; index < byteArray.Length; ++index)
{
// >= 'A' && <= 'Z'
if ((int)byteArray[index] >= 65 && (int)byteArray[index] <= 90)
byteArray[index] += (byte)32;
}
for (int index = 0; index < byteArray.Length; ++index)
{
if ((int)byteArray[index] >= 65) // 'A'
num1 += (uint)byteArray[index] + (uint)license;
}
uint num2 = num1 * (uint)paramLicenseKey[0];
uint num3 = (uint)((int)num2 * ((int)num2 & (int)byte.MaxValue) & (int)ushort.MaxValue);
if (num3 < 100U)
num3 = 2728U;
if (paramLicenseKey.StartsWith((paramLicenseKey[0].ToString() ?? "") + (object)num3))
{
//this.aa = param_lickey.Substring(0, 1);
return true;
}
//this.aa = "";
return false;
}
}
}