Skip to content

Instantly share code, notes, and snippets.

@Kodiologist
Last active August 22, 2021 12:52
Show Gist options
  • Save Kodiologist/c5046a6d2edb75960a2e0d85f23827e3 to your computer and use it in GitHub Desktop.
Save Kodiologist/c5046a6d2edb75960a2e0d85f23827e3 to your computer and use it in GitHub Desktop.
Remove the license check from SmartTemplate4
#!/usr/bin/env python3
# (Requires Python 3.8 or later.)
#
# Remove the license check from the Thunderbird add-on SmartTemplate4:
# https://github.com/RealRaven2000/SmartTemplate4
# This script is up to date as of SmartTemplate4 version 3.7.
#
# Usage: python3 smarttemplate4_crack.py INPUT_XPI_PATH OUTPUT_PATH
import sys, re
from zipfile import ZipFile
input_path, output_path = sys.argv[1:3]
replacers = [
dict(filename = 'chrome/content/smartTemplate-overlay.js',
found = False,
string = 'if (SmartTemplate4.Util.licenseInfo.status != "Valid" && SmartTemplate4.Util.licenseInfo.trialDays<=0)',
repl = 'if (false)'),
dict(filename = 'chrome/content/smartTemplate-util.js',
found = False,
string = 'hasLicense = util.hasLicense(),',
repl = 'hasLicense = true,')]
with ZipFile(input_path, 'r') as inp, ZipFile(output_path, 'w') as out:
for item in inp.infolist():
x = inp.read(item.filename)
if replacer := next(
(r for r in replacers if r['filename'] == item.filename),
None):
replacer['found'] = True
x, n = re.subn(
re.escape(replacer['string']),
replacer['repl'],
x.decode('UTF-8'), count = 1)
if not n:
exit('No match: ' + repr(replacer))
x = x.encode('UTF-8')
out.writestr(item, x)
if not_found := next((r for r in replacers if not r['found']), None):
exit('Not found in archive: ' + not_found['filename'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment