Advertisement
DOGGYWOOF

DOGGY SECURE FLASH RECOVERY

Apr 11th, 2024 (edited)
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. local function main()
  2. local ci = component.invoke
  3. local computer = computer or require("computer")
  4.  
  5. local bi = function(a, m, ...)
  6. local r = table.pack(pcall(ci, a, m, ...))
  7. if not r[1] then return nil, r[2] else return table.unpack(r, 2, r.n) end
  8. end
  9.  
  10. local e = component.list("eeprom")()
  11. computer.getBootAddress = function() return bi(e, "getData") end
  12. computer.setBootAddress = function(a) return bi(e, "setData", a) end
  13.  
  14. do
  15. local s, g = component.list("screen")(), component.list("gpu")()
  16. if g and s then bi(g, "bind", s) end
  17. end
  18.  
  19. local function tryLoad(a)
  20. local h, r = bi(a, "open", "/init.lua")
  21. if not h then return nil, "Failed to open /init.lua: " .. tostring(r) end
  22. local b = ""
  23. repeat
  24. local d, r = bi(a, "read", h, math.maxinteger or math.huge)
  25. if not d and r then
  26. bi(a, "close", h)
  27. return nil, "Failed to read /init.lua: " .. tostring(r)
  28. end
  29. b = b .. (d or "")
  30. until not d
  31. bi(a, "close", h)
  32. local i, l = load(b, "=init")
  33. if not i then return nil, "Failed to load /init.lua: " .. tostring(l) end
  34. return i
  35. end
  36.  
  37. local function flashEEPROM(address)
  38. local h, r = bi(address, "open", "/DOGGY.ROM")
  39. if not h then return false, "Failed to open DOGGY.ROM: " .. tostring(r) end
  40. local totalSize = bi(address, "size", "/DOGGY.ROM")
  41. local pageSize = 64 -- Example EEPROM page size
  42. local chunkSize = math.min(totalSize, pageSize * 2) -- Choose a chunk size that is a multiple of page size, e.g., 128 bytes
  43. local data, chunk = "", ""
  44. local progressWidth = 20 -- Width of the progress bar
  45. repeat
  46. chunk = bi(address, "read", h, chunkSize)
  47. if chunk then
  48. bi(e, "set", data .. chunk) -- Write chunk to EEPROM
  49. data = data .. chunk
  50. local progress = #data / totalSize
  51. local progressBar = string.rep("=", math.floor(progress * progressWidth)) .. string.rep(" ", progressWidth - math.floor(progress * progressWidth))
  52. bi(component.list("gpu")(), "set", 1, 1, "Flashing: [" .. progressBar .. "] " .. math.floor(progress * 100) .. "%")
  53. end
  54. computer.pullSignal(6) -- Wait for 6 seconds
  55. until not chunk
  56. bi(address, "close", h)
  57. return true
  58. end
  59.  
  60. local l = {}
  61. for a in component.list("filesystem") do
  62. local b = bi(a, "getLabel") or "Unnamed Drive"
  63. if b ~= "tmpfs" then
  64. table.insert(l, { address = a, label = b })
  65. end
  66. end
  67.  
  68. -- Check for DOGGY.ROM and flash it to EEPROM if found
  69. for _, drive in ipairs(l) do
  70. local hasDoggyRom, err = bi(drive.address, "exists", "/DOGGY.ROM")
  71. if hasDoggyRom then
  72. local success, flashError = flashEEPROM(drive.address)
  73. if success then
  74. computer.beep(800, 0.2)
  75. computer.beep(800, 0.2)
  76. computer.beep(800, 0.2)
  77. bi(component.list("gpu")(), "set", 1, 1, "Flash complete!")
  78. computer.beep(800, 1) -- Beep once to indicate flash completion
  79. else
  80. bi(component.list("gpu")(), "set", 1, 1, "Flash failed: " .. flashError)
  81. computer.beep(800, 0.1)
  82. computer.beep(800, 0.1)
  83. computer.beep(800, 0.1)
  84. computer.beep(800, 1) -- Beep to indicate failure
  85. computer.shutdown(true) -- Halt the system
  86. end
  87. break
  88. end
  89. end
  90.  
  91. local function displayError(errorMessage)
  92. -- Implementation remains the same
  93. end
  94.  
  95. local function displayMenu(sI)
  96. -- Implementation remains the same
  97. end
  98.  
  99. local sI = math.ceil(#l / 2)
  100. displayMenu(sI)
  101. while true do
  102. local e = { computer.pullSignal() }
  103. if e[1] == "key_down" then
  104. -- Implementation remains the same
  105. end
  106. end
  107. end
  108.  
  109. main()
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement