Created
November 16, 2023 22:45
-
-
Save x4fx77x4f/28080a7c0c8d3a83c8c76b70b79828f3 to your computer and use it in GitHub Desktop.
Decrypt Teardown ".tde" files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env luajit | |
local argparse = require("argparse") -- https://github.com/mpeterv/argparse | |
local parser = argparse("./tdetool2.lua", "Decrypt and reencrypt Teardown's \".tde\" files.") | |
parser:argument("input", "Input file(s)."):args("+") | |
parser:option("-o --output", "Output file.") | |
parser:option("--working-directory"):hidden(true) | |
local args = parser:parse() | |
if #args.input > 1 and args.output ~= nil then | |
parser:error("cannot use output option with more than one input argument") | |
end | |
local keys = { | |
"599Cc51887A8cb0C20F9CdE34cf9e0A535E5cAd1C26c7b562596ACC207Ae9A0bfB3E3161f31af5bEf1c2f064b3628174D83BF6E0739D9D6918fD9C2Eba02D5aD", | |
"0C3b676fe8d7188Cde022F71632830F36b98b181aD48Fed160006eA59", | |
} | |
local root = args.working_directory | |
if root == nil then | |
root = "" | |
else | |
root = root.."/" | |
end | |
for i=1, #args.input do | |
local inpath = args.input[i] | |
local infile = assert(io.open(root..inpath, "rb")) | |
local outpath = args.output | |
if outpath == inpath then | |
parser:error("cannot output to same path as input path") | |
elseif outpath == nil then | |
if inpath:sub(-4) == ".tde" then | |
outpath = inpath:gsub("%.tde$", "") | |
else | |
outpath = inpath..".tde" | |
end | |
end | |
local outfile = assert(io.open(root..outpath, "wb")) | |
local length = infile:seek("end", 0) | |
infile:seek("set", 0) | |
for i=0, length-1 do | |
local byte = infile:read(1):byte() | |
for j=1, #keys do | |
local key = keys[j] | |
local k = i%#key+1 | |
byte = bit.bxor(byte, key:byte(k, k)) | |
end | |
outfile:write(string.char(byte)) | |
end | |
infile:close() | |
outfile:close() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment