Skip to content

Instantly share code, notes, and snippets.

@x4fx77x4f
Created April 23, 2021 03:55
Show Gist options
  • Save x4fx77x4f/13980af30cb17caa6345189be07f4957 to your computer and use it in GitHub Desktop.
Save x4fx77x4f/13980af30cb17caa6345189be07f4957 to your computer and use it in GitHub Desktop.
Decrypt encrypted Teardown files (.tde)
#!/usr/bin/env luajit
local argparse = require('argparse')
local parser = argparse("tdedecrypt", "Decrypt encrypted Teardown files")
parser:argument("input", "Input file(s)"):args("*")
parser:option("-o --output", "Output file")
local args = parser:parse()
if args.input[2] and args.output then
parser:error("cannot use output option with multiple input files")
end
for _, input in pairs(args.input) do
local infile = io.open(input, 'rb')
if not infile then
parser:error("could not open infile")
end
local outfile = io.open(args.output or string.gsub(input, '%.tde$', ''), 'wb')
if not outfile then
parser:error("could not open outfile")
end
-- Derived from https://github.com/lyhyl/TDEDecrypt/blob/master/TDEDecrypt/main.cpp
local a = '599Cc51887A8cb0C20F9CdE34cf9e0A535E5cAd1C26c7b562596ACC207Ae9A0bfB3E3161f31af5bEf1c2f064b3628174D83BF6E0739D9D6918fD9C2Eba02D5aD\x00'
local b = '0C3b676fe8d7188Cde022F71632830F36b98b181aD48Fed160006eA59\x00'
local i = 0
while true do
local enc = infile:read(1)
if not enc then
break
end
enc = string.byte(enc)
local a2 = bit.band(i, 0x7f)+1
a2 = string.byte(string.sub(a, a2, a2))
local b2 = (i%57)+1
b2 = string.byte(string.sub(b, b2, b2))
local dec = bit.bxor(bit.bxor(enc, a2), b2)
dec = string.char(dec)
outfile:write(dec)
i = i+1
end
infile:close()
outfile:close()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment