简体   繁体   中英

Is it possible to hide strings from Lua compiled code?

I have a path for a file specified as a string in my code, and I don't want to be visible after luac conversion. Is it possible obfuscate somehow the line? My code is:

DIR1 = '../../../files/file1.txt'

Thank you!

Yes.

Example:

local Key53 = 8186484168865098
local Key14 = 4887

function decode(str)
   local K, F = Key53, 16384 + Key14
   return (str:gsub('%x%x',
      function(c)
         local L = K % 274877906944   -- 2^38
         local H = (K - L) / 274877906944
         local M = H % 128
         c = tonumber(c, 16)
         local m = (c + (H - M) / 128) * (2*M + 1) % 256
         K = L * F + H + c + m
         return string.char(m)
      end
   ))
end

local path = decode"beb81858c47a5fc7e11721921fb7f58ceeb530c4e74034df"
print(path)  -->  ../../../files/file1.txt

How to encode your own text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM