maximumdrive Posted June 16, 2018 Share Posted June 16, 2018 (edited) Hi, I'm now trying to base64+teaEncode some of my models, the Wiki says that engineLoadDff can load not only DFFs, but the file buffer too. As a result, engineReplaceModel fails returning "false". So I have written some code to encode-decode the model data. Am I right with my understanding of "raw data" needed to give to engineLoadDff as an argument? P.S. I was looking for issue using forumsearch etc. for a long time, but I haven't found any analogues, everybody uses engineLoadDFF only with filename as argument. addEventHandler('onClientResourceStart', resourceRoot, function() local buffer local hFile = fileOpen("model.dff") -- attempt to open the file if hFile then -- check if it was successfully opened while not fileIsEOF(hFile) do -- as long as we're not at the end of the file... buffer = fileRead(hFile, 500) -- ... read the next 500 bytes... -- ... and output them to the console end fileClose(hFile) -- close the file once we're done with it else outputConsole("Unable to open the model file") end local enBuffer = teaEncode( base64Encode( buffer ), "xTN5#Gqm=sKn**dF" ) local deBuffer = base64Decode( teaDecode( enBuffer, "xTN5#Gqm=sKn**dF" ) ) local txd = engineLoadTXD('tex.txd',true) engineImportTXD(txd, 596) local dff = engineLoadDFF(deBuffer) engineReplaceModel(dff, 596) end ) Edited June 16, 2018 by maximumdrive Link to comment
maximumdrive Posted June 16, 2018 Author Share Posted June 16, 2018 (edited) Didn't notice my fail while filling the 'buffer' LOL Then the question: how can I do it correctly? Debug swears on "glueing" the filefragments done in the next way. How can I attach binary bytesets into a complete raw data? while not fileIsEOF(hFile) do -- as long as we're not at the end of the file... buffer = buffer..fileRead(hFile, 500) -- ... read the next 500 bytes... -- ... and output them to the console end fileClose(hFile) Edited June 16, 2018 by maximumdrive Link to comment
Discord Moderators Pirulax Posted June 16, 2018 Discord Moderators Share Posted June 16, 2018 Jeez... Try to use print("Enbuffer", enBuffer) print("Debuffer", deBuffer) enbuffer should print base64 but bebuffer should print some binary text(Or idk, never have tried to print out binary in Lua) Or maybe it fails because of the modelid, try to use other modelid, like 587 Link to comment
JustinMTA Posted June 18, 2018 Share Posted June 18, 2018 https://forum.multitheftauto.com/topic/88661-abcompiler-21-dfftxd-compiler-updated-1-sept-2k16/ Link to comment
MIKI785 Posted June 18, 2018 Share Posted June 18, 2018 (edited) On 6/16/2018 at 15:19, maximumdrive said: Didn't notice my fail while filling the 'buffer' LOL Then the question: how can I do it correctly? Debug swears on "glueing" the filefragments done in the next way. How can I attach binary bytesets into a complete raw data? while not fileIsEOF(hFile) do -- as long as we're not at the end of the file... buffer = buffer..fileRead(hFile, 500) -- ... read the next 500 bytes... -- ... and output them to the console end fileClose(hFile) Are you asking how to dump the whole file in one go? Just use fileGetSize like so: buffer = fileRead(hFile, fileGetSize(hFile)) Edited June 18, 2018 by MIKI785 Link to comment
XaskeL Posted June 19, 2018 Share Posted June 19, 2018 (edited) On 18.06.2018 at 04:11, JustinMTA said: https://forum.multitheftauto.com/topic/88661-abcompiler-21-dfftxd-compiler-updated-1-sept-2k16/ 5$, very userful soft Encryption models, shaders, images Edited June 19, 2018 by XaskeL Link to comment
Discord Moderators Pirulax Posted June 22, 2018 Discord Moderators Share Posted June 22, 2018 Thats so cheeky to sell a 10 line script that uses TEA+base64... Really.. It should be working. Link to comment
Discord Moderators Pirulax Posted June 23, 2018 Discord Moderators Share Posted June 23, 2018 (edited) I'll want to do an encoder anyway, so if I'll finish it I'll post it here. Edited June 23, 2018 by Pirulax 1 Link to comment
Discord Moderators Pirulax Posted August 5, 2018 Discord Moderators Share Posted August 5, 2018 (edited) function File.encode(path, key) local uncf = File.open(path) if (uncf) then local encf = File(path..".encoded") encf:write(teaEncode(base64Encode(uncf:read(uncf:getSize())), key)) encf:close() uncf:close() end end function File.readEncoded(path, key) local encf = File.open(path..".encoded") if (encf) then local decoded = base64Decode(teaDecode(encf:read(encf:getSize()), key)) encf:close() return decoded end end Note: You need to have OOP enabled in meta.xml(<oop>true</oop>) Edited August 5, 2018 by Pirulax 1 Link to comment
Discord Moderators Pirulax Posted August 5, 2018 Discord Moderators Share Posted August 5, 2018 (edited) Actually, maybe I realized what's the problem with the script that @maxiumdrive posted. addEventHandler('onClientResourceStart', resourceRoot, function() local buffer local hFile = fileOpen("model.dff") -- attempt to open the file if hFile then -- check if it was successfully opened while not fileIsEOF(hFile) do -- as long as we're not at the end of the file... buffer = buffer..base64Encode(fileRead(hFile, 500))-- ... read the next 500 bytes... end fileClose(hFile) -- close the file once we're done with it else outputConsole("Unable to open the model file") end local enBuffer = teaEncode(buffer, "xTN5#Gqm=sKn**dF") local deBuffer = base64Decode(teaDecode(enBuffer, "xTN5#Gqm=sKn**dF")) engineImportTXD(engineLoadTXD('tex.txd',true) , 596) engineReplaceModel(engineLoadDFF(deBuffer) , 596) end ) Edited August 5, 2018 by Pirulax Link to comment
Addlibs Posted August 5, 2018 Share Posted August 5, 2018 (edited) It's actually better to use encodeString and decodeString (added as of 1.5.5 r11849) as these functions allow you to avoid converting Base64 which is less efficient in terms of data storage - length of data n turns into a length of 4*(n/3) in Base64 (33% data increase), plus padding (=) this can add up to even 36.55% increased data use (16000 bytes is 21848 bytes of base64) encodeString("tea", DATA_TO_ENCODE, {key="your key"}) decodeString("tea", DATA_TO_DECODE, {key="your key"}) -- The following code can be used to test local f = File.open("some_model.dff", true) local data = f:read(f.size) -- read all data f:close() local key = "xTN5#Gqm=sKn**dF" local opt1 = teaEncode(base64Encode(data), key) local opt2 = teaEncode(data, key) local opt3 = encodeString("tea", base64Encode(data), {key = key}) local opt4 = encodeString("tea", data, {key = key}) outputChatBox("teaEncode with base64: " .. (base64Decode(teaDecode(opt1, key)) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt1) outputChatBox("teaEncode without base64: " .. (teaDecode(opt2, key) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt2) outputChatBox("encodeString with base64: " .. (base64Decode(decodeString("tea", opt3, {key = key})) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt3) outputChatBox("encodeString without base64: " .. (decodeString("tea", opt4, {key = key}) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt4) Edited August 5, 2018 by MrTasty 1 Link to comment
XaskeL Posted August 5, 2018 Share Posted August 5, 2018 7 hours ago, MrTasty said: It's actually better to use encodeString and decodeString (added as of 1.5.5 r11849) as these functions allow you to avoid converting Base64 which is less efficient in terms of data storage - length of data n turns into a length of 4*(n/3) in Base64 (33% data increase), plus padding (=) this can add up to even 36.55% increased data use (16000 bytes is 21848 bytes of base64) encodeString("tea", DATA_TO_ENCODE, {key="your key"}) decodeString("tea", DATA_TO_DECODE, {key="your key"}) -- The following code can be used to test local f = File.open("some_model.dff", true) local data = f:read(f.size) -- read all data f:close() local key = "xTN5#Gqm=sKn**dF" local opt1 = teaEncode(base64Encode(data), key) local opt2 = teaEncode(data, key) local opt3 = encodeString("tea", base64Encode(data), {key = key}) local opt4 = encodeString("tea", data, {key = key}) outputChatBox("teaEncode with base64: " .. (base64Decode(teaDecode(opt1, key)) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt1) outputChatBox("teaEncode without base64: " .. (teaDecode(opt2, key) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt2) outputChatBox("encodeString with base64: " .. (base64Decode(decodeString("tea", opt3, {key = key})) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt3) outputChatBox("encodeString without base64: " .. (decodeString("tea", opt4, {key = key}) == data and "[OK]" or "[FAIL INTEGRITY TEST]") .. "; Encoded length: " .. #opt4) base64Decode(teaEncode(...)) it's so easy? Link to comment
Addlibs Posted August 6, 2018 Share Posted August 6, 2018 (edited) 11 hours ago, XaskeL said: base64Decode(teaEncode(...)) it's so easy? It might be easy, but it takes up CPU during encoding and decoding, and takes up more space in memory (buffer), on disk (when saved) and in transit (downloading). decodeString("tea", data_to_decode, {key = "your key"}) is just as easy, and also more efficient. Edited August 6, 2018 by MrTasty Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now