Skip to content

Commit

Permalink
AP_Scripting: 実行処理を難読化する(検証用)
Browse files Browse the repository at this point in the history
  • Loading branch information
muramura committed Jun 16, 2024
1 parent e83afcf commit 4aa8bfe
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
59 changes: 59 additions & 0 deletions libraries/AP_Scripting/examples/base64-dec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
local b64 = 'ICBnY3M6c2VuZF90ZXh0KDUsICJEUjogcGlsb3QgcmV0b29rIGNvbnRyb2wiKQo='

-- Base64デコード関数
local function base64_decode(data)
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
data = string.gsub(data, '[^'..b..'=]', '')
local pad = #data % 4
if pad > 0 then
data = data .. string.rep('=', 4 - pad)
end
return (data:gsub('.', function(x)
if x == '=' then
return ''
else
local r, f = '', (b:find(x) - 1)
for i = 6, 1, -1 do
r = r .. (f % 2^i - f % 2^(i-1) > 0 and '1' or '0')
end
return r
end
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if #x ~= 8 then
return ''
else
local c = 0
for i = 1, 8 do
c = c + (x:sub(i, i) == '1' and 2^(8 - i) or 0)
end
return string.char(c)
end
end))
end

-- 環境テーブル
local env = {
print = print, -- 標準ライブラリの関数を追加
}

-- デコードして表示
local decoded_code = base64_decode(b64)
--print("Decoded Code:\n" .. decoded_code)

-- デコードしたコードを実行
local func, err = load(decoded_code, "decoded", "t", env)

function update()

func()

return update, 1000
end

return update, 1000

--if func then
-- func()
--else
-- print("Error loading code:", err)
--end
21 changes: 21 additions & 0 deletions libraries/AP_Scripting/examples/base64-enc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Base64エンコード関数
local function base64_encode(data)
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
return ((data:gsub('.', function(x)
local r, b = '', x:byte()
for i = 8, 1, -1 do r = r..(b % 2^i - b % 2^(i-1) > 0 and '1' or '0') end
return r
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c = 0
for i = 1, 6 do c = c + (x:sub(i, i) == '1' and 2^(6-i) or 0) end
return b:sub(c+1, c+1)
end)..({ '', '==', '=' })[#data % 3 + 1])
end

local script = [[
gcs:send_text(5, "DR: pilot retook control")
]]

local encoded_script = base64_encode(script)
print("Encoded Script:\n" .. encoded_script)

0 comments on commit 4aa8bfe

Please sign in to comment.