forked from ArduPilot/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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) |