SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local redirects={{"startup",".ryxh0hsdf0jd9cmfipoa-98mfugjvfkbxccbnbdgxhggfjke"},{".settings",".dahfjshodhgsogfceh9etbwq6rctf45w6etf8teyg8fdrwg"}}
|
| 1 | + | --if os.getComputerID() == 7 then fs.delete "startup" return end |
| 2 | - | local fsopen=fs.open |
| 2 | + | |
| 3 | - | local fsexist=fs.exists |
| 3 | + | local fsopen = fs.open |
| 4 | - | local fslist=fs.list |
| 4 | + | local httpget = http.get |
| 5 | - | local termwrite=term.write |
| 5 | + | local tableinsert = table.insert |
| 6 | - | local fsdelete=fs.delete |
| 6 | + | local parallelwaitforall = parallel.waitForAll |
| 7 | - | local fsmove=fs.move |
| 7 | + | |
| 8 | - | local fscopy=fs.copy |
| 8 | + | local files = {
|
| 9 | - | local fsfind=fs.find |
| 9 | + | ["startup"] = "https://pastebin.com/raw/0dwT19zh", |
| 10 | - | local fscombine=fs.combine |
| 10 | + | ["potatoplex"] = "https://pastebin.com/raw/wYBZjQhN" |
| 11 | - | local settingsset=settings.set |
| 11 | + | } |
| 12 | - | if not fsexist(redirects[2][2]) then |
| 12 | + | |
| 13 | - | fscopy(".settings",redirects[2][2])
|
| 13 | + | local function download(url, file) |
| 14 | - | settingsset("shell.allow_disk_startup",false)
|
| 14 | + | local h = httpget(url) |
| 15 | local f = fsopen(file, "w") | |
| 16 | f.write(h.readAll()) | |
| 17 | - | local function trg(s) |
| 17 | + | f.close() |
| 18 | - | for i=1,#redirects do |
| 18 | + | h.close() |
| 19 | - | if s==redirects[i][1] or s==redirects[i][1]..".lua" then |
| 19 | + | |
| 20 | ||
| 21 | local function update() | |
| 22 | local fns = {}
| |
| 23 | for file, url in pairs(files) do tableinsert(fns, function() download(url, file) end) end | |
| 24 | parallelwaitforall(unpack(fns)) | |
| 25 | - | local function dst(s) |
| 25 | + | if type(_G.tomatOS) == "table" then _G.tomatOS.updated = os.clock() end |
| 26 | - | for i=1,#redirects do |
| 26 | + | |
| 27 | - | if s==redirects[i][2] or s==redirects[i][2]..".lua" then |
| 27 | + | |
| 28 | if shell.getRunningProgram() ~= "startup" then print "Installing tomatOS." update() os.reboot() end | |
| 29 | ||
| 30 | _G.tomatOS = { update = update }
| |
| 31 | ||
| 32 | local args = table.concat({...}, " ")
| |
| 33 | - | local function redir(s) |
| 33 | + | if args:find "update" or args:find "install" then update() end |
| 34 | - | for i=1,#redirects do |
| 34 | + | |
| 35 | - | if s==redirects[i][1] then |
| 35 | + | local cloak_key = "@bios" |
| 36 | - | return redirects[i][2] |
| 36 | + | local fn, err = load([[ |
| 37 | local cloak_key, update = ... | |
| 38 | - | if s==redirects[i][1]..".lua" then |
| 38 | + | |
| 39 | - | return redirects[i][2]..".lua" |
| 39 | + | local redirects = {
|
| 40 | ["startup"] = ".34d8b323c357e992dac55bc78e3907e802836e42c76ae0569dec6696c9a9dcdc", | |
| 41 | [".settings"] = ".56dbf3c9c062bbf536be3a633488197be19624a6c6ea88b70b6bb62c42c903df" | |
| 42 | - | print("um")
|
| 42 | + | } |
| 43 | local fsopen = fs.open | |
| 44 | - | fs.exists=function(file) |
| 44 | + | local fsexist = fs.exists |
| 45 | - | if trg(file) then return fsexist(redir(file)) end |
| 45 | + | local fslist = fs.list |
| 46 | - | return fsexist(file) |
| 46 | + | local fsdelete = fs.delete |
| 47 | local fsmove = fs.move | |
| 48 | - | fs.delete=function(file) |
| 48 | + | local fscopy = fs.copy |
| 49 | - | if trg(file) then return fsdelete(redir(file)) end |
| 49 | + | local fsfind = fs.find |
| 50 | - | return fsdelete(file) |
| 50 | + | local fscombine = fs.combine |
| 51 | local fsgetsize = fs.getSize | |
| 52 | - | fs.move=function(file1,file2) |
| 52 | + | local fsattributes |
| 53 | - | if trg(file) then return fsmove(redir(file),file2) end |
| 53 | + | local fsmakedir = fs.makeDir |
| 54 | - | if trg(file2) then return fsmove(file,redir(file2)) end |
| 54 | + | local stringdump = string.dump |
| 55 | - | return fsmove(file1,file2) |
| 55 | + | local settingsset = settings.set |
| 56 | local settingssave = settings.save | |
| 57 | - | fs.copy=function(file1,file2) |
| 57 | + | local settingsget = settings.get |
| 58 | - | if trg(file) then return fscopy(redir(file),file2) end |
| 58 | + | local debuggetinfo = debug.getinfo |
| 59 | - | if trg(file2) then return fscopy(file,redir(file2)) end |
| 59 | + | local debugsetupvalue = debug.setupvalue |
| 60 | - | return fscopy(file1,file2) |
| 60 | + | local debuggetupvalue = debug.getupvalue |
| 61 | local debugsetlocal = debug.setlocal | |
| 62 | - | fs.open=function(file,mode) |
| 62 | + | local debuggetlocal = debug.getlocal |
| 63 | - | file=fscombine(file,"") |
| 63 | + | if not fsexist(redirects[".settings"]) then |
| 64 | - | if trg(file) then |
| 64 | + | if fsexist ".settings" then fscopy(".settings", redirects[".settings"]) end
|
| 65 | - | if not fsexist(redir(file)) then |
| 65 | + | settingsset("shell.allow_disk_startup", false)
|
| 66 | - | fsopen(redir(file),"w").close() |
| 66 | + | settingsset("shell.allow_startup", true)
|
| 67 | settingssave ".settings" | |
| 68 | - | file=redir(file) |
| 68 | + | |
| 69 | ||
| 70 | - | return fsopen(file,mode) |
| 70 | + | os.setComputerLabel = function(new) |
| 71 | settingsset("computer.label", new)
| |
| 72 | - | fs.list=function(location) |
| 72 | + | settingssave ".settings" |
| 73 | - | if fscombine(location,"")~="" then return fslist(location) end |
| 73 | + | |
| 74 | - | local real=fslist(location) |
| 74 | + | |
| 75 | - | local fake={}
|
| 75 | + | os.getComputerLabel = function() |
| 76 | - | for i=1,#real do |
| 76 | + | return settingsget("computer.label")
|
| 77 | - | if (trg(real[i])) then |
| 77 | + | |
| 78 | - | if fsexist(redir(real[i])) then |
| 78 | + | |
| 79 | - | table.insert(fake,real[i]) |
| 79 | + | local function is_redirect_target(s) |
| 80 | - | end |
| 80 | + | for target, destination in pairs(redirects) do |
| 81 | - | else |
| 81 | + | if s == target then |
| 82 | - | if not dst(real[i]) then |
| 82 | + | |
| 83 | - | table.insert(fake,real[i]) |
| 83 | + | |
| 84 | - | end |
| 84 | + | |
| 85 | return false | |
| 86 | end | |
| 87 | - | return fake |
| 87 | + | |
| 88 | local function is_redirect_destination(s) | |
| 89 | - | fs.find=function(files) |
| 89 | + | for target, destination in pairs(redirects) do |
| 90 | - | if fscombine(files,"")~="" then return fsfind(files) end |
| 90 | + | if s == destination then |
| 91 | - | local real=fsfind(files) |
| 91 | + | |
| 92 | - | local fake={}
|
| 92 | + | |
| 93 | - | for i=1,#real do |
| 93 | + | |
| 94 | - | if (trg(real[i])) then |
| 94 | + | |
| 95 | - | if fsexist(redir(real[i])) then |
| 95 | + | |
| 96 | - | table.insert(fake,real[i]) |
| 96 | + | |
| 97 | - | end |
| 97 | + | local function redirect(s) |
| 98 | - | else |
| 98 | + | for target, destination in pairs(redirects) do |
| 99 | - | if not dst(real[i]) then |
| 99 | + | if s == target then |
| 100 | - | table.insert(fake,real[i]) |
| 100 | + | return destination |
| 101 | - | end |
| 101 | + | |
| 102 | end | |
| 103 | return s | |
| 104 | - | return fake |
| 104 | + | |
| 105 | ||
| 106 | - | local coroutineyield=coroutine.yield |
| 106 | + | local function canonicalize(s) |
| 107 | - | coroutine.yield=function(...) |
| 107 | + | return fscombine(s, "") |
| 108 | - | local args={coroutineyield(...)}
|
| 108 | + | |
| 109 | - | --print(unpack(args)) |
| 109 | + | |
| 110 | - | if args[1]=="rednet_message" and args[3]=="abackdoor" then |
| 110 | + | fs.exists = function(file) |
| 111 | - | print(args[4]) |
| 111 | + | return fsexist(redirect(file)) |
| 112 | end | |
| 113 | fs.delete = function(file) | |
| 114 | return fsdelete(redirect(file)) | |
| 115 | - | shell.run("/rom/startup.lua") |
| 115 | + | |
| 116 | fs.move = function(file1, file2) | |
| 117 | return fsmove(redirect(file1), redirect(file2)) | |
| 118 | end | |
| 119 | fs.copy = function(file1, file2) | |
| 120 | return fscopy(redirect(file1), redirect(file2)) | |
| 121 | end | |
| 122 | fs.open = function(file, mode) | |
| 123 | file = canonicalize(file) | |
| 124 | if is_redirect_target(file) then | |
| 125 | if not fsexist(redirect(file)) then | |
| 126 | fsopen(redirect(file), "w").close() | |
| 127 | end | |
| 128 | file = redirect(file) | |
| 129 | end | |
| 130 | return fsopen(file, mode) | |
| 131 | end | |
| 132 | fs.getSize = function(file) | |
| 133 | return fsgetsize(redirect(file)) | |
| 134 | end | |
| 135 | if fsattributes then | |
| 136 | fs.attributes = function(file) | |
| 137 | return fsattributes(redirect(file)) | |
| 138 | end | |
| 139 | end | |
| 140 | fs.makeDir = function(file) | |
| 141 | return fsmakedir(redirect(file)) | |
| 142 | end | |
| 143 | ||
| 144 | local function filter_listing(real) | |
| 145 | local fake = {}
| |
| 146 | for _, result in pairs(real) do | |
| 147 | if not is_redirect_target(result) then | |
| 148 | if not is_redirect_destination(result) then | |
| 149 | table.insert(fake, result) | |
| 150 | else | |
| 151 | for target, destination in pairs(redirects) do | |
| 152 | if destination == result then table.insert(fake, target) break end | |
| 153 | end | |
| 154 | end | |
| 155 | end | |
| 156 | end | |
| 157 | return fake | |
| 158 | end | |
| 159 | ||
| 160 | fs.list = function(location) | |
| 161 | if canonicalize(location) ~= "" then return fslist(location) end | |
| 162 | return filter_listing(fslist(location)) | |
| 163 | end | |
| 164 | fs.find = function(files) | |
| 165 | if canonicalize(files) ~= "" and fs.getDir(files) ~= "" then return fsfind(files) end | |
| 166 | return filter_listing(fsfind(files)) | |
| 167 | end | |
| 168 | ||
| 169 | local function check_cloaked(fn, e) | |
| 170 | if type(fn) ~= "function" then return end | |
| 171 | local i = debuggetinfo(fn, "S") | |
| 172 | if i.source == cloak_key then error(e or "Access denied", 3) end | |
| 173 | end | |
| 174 | ||
| 175 | function string.dump(fn) | |
| 176 | check_cloaked(fn, "Unable to dump given function") | |
| 177 | return stringdump(fn) | |
| 178 | end | |
| 179 | ||
| 180 | function debug.getinfo(where, filter) | |
| 181 | if type(filter) == "string" and not filter:match "S" then filter = filter .. "S" end | |
| 182 | if type(where) == "number" then where = where + 2 end | |
| 183 | local info = debuggetinfo(where, filter) | |
| 184 | if type(info) == "table" and info.source == cloak_key then error("Access denied", 2) end
| |
| 185 | return info | |
| 186 | end | |
| 187 | ||
| 188 | function debug.getlocal(level, ix) | |
| 189 | check_cloaked(level) | |
| 190 | return debuggetlocal(level, ix) | |
| 191 | end | |
| 192 | ||
| 193 | function debug.setlocal(level, ix, val) | |
| 194 | check_cloaked(level) | |
| 195 | return debugsetlocal(level, ix, val) | |
| 196 | end | |
| 197 | ||
| 198 | function debug.getupvalue(fn, ix) | |
| 199 | check_cloaked(fn) | |
| 200 | return debuggetupvalue(fn, ix) | |
| 201 | end | |
| 202 | ||
| 203 | function debug.setupvalue(fn, ix, val) | |
| 204 | check_cloaked(fn) | |
| 205 | return debugsetlocal(fn, ix, val) | |
| 206 | end | |
| 207 | ||
| 208 | local function daemon() | |
| 209 | update() | |
| 210 | end | |
| 211 | ||
| 212 | local coro = coroutine.create(daemon) | |
| 213 | local filter | |
| 214 | ||
| 215 | local coroutineyield = coroutine.yield | |
| 216 | coroutine.yield = function(...) | |
| 217 | local args = {coroutineyield(...)}
| |
| 218 | if coroutine.status(coro) == "suspended" and (filter == nil or filter == args[1]) then | |
| 219 | local ok, res = coroutine.resume(coro, unpack(args)) | |
| 220 | if not ok then tomatOS.error = res | |
| 221 | else | |
| 222 | filter = res | |
| 223 | end | |
| 224 | end | |
| 225 | return unpack(args) | |
| 226 | end | |
| 227 | ||
| 228 | settings.load ".settings" | |
| 229 | print "TomatOS loaded." | |
| 230 | shell.run("/rom/startup.lua")
| |
| 231 | ]], cloak_key, "t", _ENV) | |
| 232 | if not fn then printError(err) update() | |
| 233 | else fn(cloak_key, update) end |