Skip to content

Instantly share code, notes, and snippets.

@gythialy
Last active June 13, 2022 02:50
Show Gist options
  • Save gythialy/8429157 to your computer and use it in GitHub Desktop.
Save gythialy/8429157 to your computer and use it in GitHub Desktop.
remove license validation of MarkdownPad 2 by Mono Cecil
// MarkdownPad2.Core.StartupHelper
public StartupResult Check(string key, string email)
{
Mod mod = new Mod();
bool flag = false;
try
{
flag = mod.Verify(key, email);
}
catch (Exception)
{
}
if (flag)
{
this._name = mod.get_Args().get_Name();
this.IsProcessed = true;
return StartupResult.Mod;
}
LicenseEngine licenseEngine = new LicenseEngine();
bool flag2 = licenseEngine.VerifyLicense(key, email);
if (flag2)
{
this._name = licenseEngine.License.Name;
this.IsProcessed = true;
return StartupResult.Oem;
}
return StartupResult.None;
}
public bool VerifyLicense(string licenseKey, string email)
{
if (string.IsNullOrEmpty(licenseKey) || string.IsNullOrEmpty(email))
{
return false;
}
try
{
this.License = this.Decrypt(licenseKey);
this.LicenseProcessed = true;
}
catch (System.FormatException exception)
{
LicenseEngine._logger.ErrorException("Bad license format", exception);
MessageBoxHelper.ShowWarningMessageBox(LocalizationProvider.GetLocalizedString("License_BadFormat", false, "MarkdownPadStrings") + StringUtilities.GetNewLines(2) + LocalizationProvider.GetLocalizedString("License_PleaseVerify", false, "MarkdownPadStrings"), LocalizationProvider.GetLocalizedString("License_ErrorTitle", false, "MarkdownPadStrings"));
bool result = false;
return result;
}
catch (OpenSslException exception2)
{
LicenseEngine._logger.ErrorException("Error decrypting license", exception2);
MessageBoxHelper.ShowWarningMessageBox(LocalizationProvider.GetLocalizedString("License_ErrorMessage", false, "MarkdownPadStrings") + StringUtilities.GetNewLines(2) + LocalizationProvider.GetLocalizedString("License_PleaseVerify", false, "MarkdownPadStrings"), LocalizationProvider.GetLocalizedString("License_ErrorTitle", false, "MarkdownPadStrings"));
bool result = false;
return result;
}
catch (System.Exception exception3)
{
LicenseEngine._logger.ErrorException("Error processing license: " + licenseKey, exception3);
MessageBoxHelper.ShowErrorMessageBox(LocalizationProvider.GetLocalizedString("License_ErrorMessage", false, "MarkdownPadStrings") + StringUtilities.GetNewLines(2) + LocalizationProvider.GetLocalizedString("License_PleaseVerify", false, "MarkdownPadStrings"), LocalizationProvider.GetLocalizedString("License_ErrorTitle", false, "MarkdownPadStrings"), exception3, "");
bool result = false;
return result;
}
if (this.License == null || this.License.Email == null || this.License.Product == null)
{
return false;
}
bool flag = this.License.Email == email;
bool flag2 = this.License.Product == "MarkdownPad2";
return flag && flag2;
}
// MarkdownPad2.Licensing.LicenseEngine
private License Decrypt(string payload)
{
return new License
{
Name = "MarkdownPad2 Cracker",
Email = "[email protected]"
};
}
// MarkdownPad2.Licensing.LicenseEngine
public bool VerifyLicense(string licenseKey, string email)
{
this.License = this.Decrypt(licenseKey);
this.LicenseProcessed = true;
return true;
}
using System.Diagnostics;
using System.IO;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
namespace MarkdownpadCracker
{
internal class Program
{
private static void Main(string[] args)
{
var name = "MarkdownPad2.exe";
if (args != null && args.Length == 1)
{
name = args[0];
}
var target = string.Format("{0}_bak.exe", name.Substring(0, name.LastIndexOf('.')));
if (File.Exists(target))
{
File.Delete(target);
Debug.WriteLine("remove " + target);
}
File.Copy(name, target);
Debug.WriteLine("read assembly from " + name);
var asm = AssemblyDefinition.ReadAssembly(name);
const string TypeName = "LicenseEngine";
const string DecryptName = "Decrypt";
const string SetLicenseName = "set_License";
var licenseEngine = asm.MainModule.Types.First(type => type.Name == TypeName);
Debug.WriteLine(licenseEngine.FullName);
var decrypt = licenseEngine.Methods.First(method => method.Name == DecryptName);
var setLicense = licenseEngine.Methods.First(method => method.Name == SetLicenseName);
const string LicenseName = "License";
const string SetName = "set_Name";
const string SetEmail = "set_Email";
var license = asm.MainModule.Types.First(type => type.Name == LicenseName);
Debug.WriteLine(license.FullName);
var nameMethod = license.Methods.First(method => method.Name == SetName);
Debug.WriteLine("method >>> " + nameMethod.Name);
var emailMethod = license.Methods.First(method => method.Name == SetEmail);
Debug.WriteLine("method >>> " + emailMethod.Name);
var processor = decrypt.Body.GetILProcessor();
var ins = decrypt.Body.Instructions;
var i = 0;
ins.Insert(i, processor.Create(OpCodes.Nop));
i++;
const string licenseFullName = "MarkdownPad2.Licensing.License";
Debug.WriteLine("try to load {0}", licenseFullName);
var tdLicense = asm.Modules.Select(module => module.Types.First(type => type.IsPublic && type.FullName == licenseFullName)).FirstOrDefault();
var licenseConstructor = tdLicense.GetConstructors().First();
var constructorRef = licenseConstructor.GetElementMethod();
ins.Insert(i, processor.Create(OpCodes.Newobj, constructorRef));
i++;
ins.Insert(i, processor.Create(OpCodes.Stloc_1));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldloc_1));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldstr, "Ur Name"));
i++;
ins.Insert(i, processor.Create(OpCodes.Callvirt, nameMethod));
i++;
ins.Insert(i, processor.Create(OpCodes.Nop));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldloc_1));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldstr, "[email protected]"));
i++;
ins.Insert(i, processor.Create(OpCodes.Callvirt, emailMethod));
i++;
ins.Insert(i, processor.Create(OpCodes.Nop));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldloc_1));
i++;
ins.Insert(i, processor.Create(OpCodes.Stloc_0));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldloc_0));
i++;
ins.Insert(i, processor.Create(OpCodes.Stloc_2));
i++;
// ins.Insert(i, processor.Create(OpCodes.Br_S));
// i++;
ins.Insert(i, processor.Create(OpCodes.Ldloc_2));
i++;
ins.Insert(i, processor.Create(OpCodes.Ret));
const string verifyName = "VerifyLicense";
const string processName = "set_LicenseProcessed";
var licenseType = asm.MainModule.Types.First(type => type.Name == TypeName);
Debug.WriteLine(licenseType.FullName);
var process = licenseType.Methods.First(method => method.Name == processName);
var verify = licenseType.Methods.First(method => method.Name == verifyName);
Debug.WriteLine("method >>> " + verify.Name);
processor = verify.Body.GetILProcessor();
ins = verify.Body.Instructions;
// ins.Clear();
i = 0;
ins.Insert(i, processor.Create(OpCodes.Nop));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldarg_0));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldarg_0));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldarg_1));
i++;
ins.Insert(i, processor.Create(OpCodes.Call, decrypt));
i++;
ins.Insert(i, processor.Create(OpCodes.Call, setLicense));
i++;
ins.Insert(i, processor.Create(OpCodes.Nop));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldarg_0));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldc_I4_1));
i++;
ins.Insert(i, processor.Create(OpCodes.Call, process));
i++;
ins.Insert(i, processor.Create(OpCodes.Nop));
i++;
ins.Insert(i, processor.Create(OpCodes.Ldc_I4_1));
i++;
ins.Insert(i, processor.Create(OpCodes.Stloc_0));
i++;
// ins.Insert(i, processor.Create(OpCodes.Br_S));
// i++;
ins.Insert(i, processor.Create(OpCodes.Ldloc_0));
i++;
ins.Insert(i, processor.Create(OpCodes.Ret));
asm.Write(name);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment