Jump to content

teaDecode, engineLoadDFF, engineLoadTXD


srslyyyy

Recommended Posts

  • Scripting Moderators

Hey. I was doing some stuff with encoding .dff and .txd files. Nearly everything works, i wanna avoid those warnings in script, if decoding failed. (incorrect key)

client.lua:83: Bad file path @ 'engineLoadDFF' [Ž°É‡"·:YÖîa´OúŚôaR]
client.lua:84: Bad file path @ 'engineLoadTXD' [ĄEk]

Probably i miss somewhere additional condition, but i am not sure.

Link to comment

You'll probably need to use base64Encode and base64Decode (this will inflate file size to about 133% [difference is higher with very small sizes like single character being inflated to 4 characters, 300% increase] of the original) for the files, as it appears the data is not tea-encrypted properly (somewhat known issue with teaEncode/teaDecode and encoding control characters 0-30 and others, so keep it to being strictly alphanumeric [base64 is a good candidate]); this in turn causes the function to interpret the input as a filepath rather than raw (decrypted) data.

Another option is encodeString/decodeString; these functions have worked more reliably for me at least with non-alphanumeric content.

Edited by Investor
  • Like 1
Link to comment
  • Scripting Moderators
3 hours ago, Investor said:

You'll probably need to use base64Encode and base64Decode (this will inflate file size to about 133% [difference is higher with very small sizes like single character being inflated to 4 characters, 300% increase] of the original) for the files, as it appears the data is not tea-encrypted properly (somewhat known issue with teaEncode/teaDecode and encoding control characters 0-30 and others, so keep it to being strictly alphanumeric [base64 is a good candidate]); this in turn causes the function to interpret the input as a filepath rather than raw (decrypted) data.

Another option is encodeString/decodeString; these functions have worked more reliably for me at least with non-alphanumeric content.

local dffFile = fileOpen("files/"..file_dff)
local dffData = fileRead(dffFile, fileGetSize(dffFile))
dffData = base64Decode(teaDecode(dffData, file_key))
fileClose(dffFile)

local txdFile = fileOpen("files/"..file_txd)
local txdData = fileRead(txdFile, fileGetSize(txdFile))
txdData = base64Decode(teaDecode(txdData, file_key))
fileClose(txdFile)

 

And later after that loading. Importing TXD and replacing DFF. 

local dff = engineLoadDFF(dffData) -- in case of incorrect key, shows warning here
local txd = engineLoadTXD(txdData) -- and here. (bad path)

So is there any way to avoid this? I know that it's only warning, but i want to keep debugscript 3 without errors/warnings.

Link to comment

You could perhaps do a hash check. Get the SHA256 (or MD5 but it's not considered secure nowadays) hash of the decrypted data and compare it against the hash that you know it should be, and only if they match proceed to engineLoadDFF/engineLoadTXD.

E.g.

local dffFile = fileOpen("files/"..file_dff)
local dffData = fileRead(dffFile, fileGetSize(dffFile))
dffData = base64Decode(teaDecode(dffData, file_key))
fileClose(dffFile)

local txdFile = fileOpen("files/"..file_txd)
local txdData = fileRead(txdFile, fileGetSize(txdFile))
txdData = base64Dec

if hash("sha256", dffData) ~= "enter_the_SHA256_hash_that_the_dff_data_should_have" then return false end -- abort function if hashes mismatch after decryption
if hash("sha256", txdData) ~= "enter_the_SHA256_hash_that_the_txd_data_should_have" then return false end -- ditto

-- ...
  
local dff = engineLoadDFF(dffData) -- in case of incorrect key, shows warning here
local txd = engineLoadTXD(txdData) -- and here. (bad path)

 

  • Like 1
Link to comment
  • Scripting Moderators
On 21/04/2019 at 12:57, Investor said:

You could perhaps do a hash check. Get the SHA256 (or MD5 but it's not considered secure nowadays) hash of the decrypted data and compare it against the hash that you know it should be, and only if they match proceed to engineLoadDFF/engineLoadTXD.

E.g.


local dffFile = fileOpen("files/"..file_dff)
local dffData = fileRead(dffFile, fileGetSize(dffFile))
dffData = base64Decode(teaDecode(dffData, file_key))
fileClose(dffFile)

local txdFile = fileOpen("files/"..file_txd)
local txdData = fileRead(txdFile, fileGetSize(txdFile))
txdData = base64Dec

if hash("sha256", dffData) ~= "enter_the_SHA256_hash_that_the_dff_data_should_have" then return false end -- abort function if hashes mismatch after decryption
if hash("sha256", txdData) ~= "enter_the_SHA256_hash_that_the_txd_data_should_have" then return false end -- ditto

-- ...
  
local dff = engineLoadDFF(dffData) -- in case of incorrect key, shows warning here
local txd = engineLoadTXD(txdData) -- and here. (bad path)

 

Works well. Thank you.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...