Advertisement
DOGGYWOOF

CFW Checker

Jul 24th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. -- Define the key elements to check for in the startup scripts
  2. local requiredElements = {
  3. "local requiredFiles = {", -- Definition of the requiredFiles table
  4. "/disk/bootloader/VA11-ILLA.lua", -- Specific file path
  5. "/disk/os/home.lua", -- Specific file path
  6. "/disk/os/lock.lua", -- Specific file path
  7. "/disk/boot/boot-animation", -- Specific file path
  8. "/disk/error/BSOD.lua", -- Specific file path
  9. "os.pullEvent = os.pullEventRaw", -- Overriding os.pullEvent
  10. "local function checkFiles()", -- Definition of checkFiles function
  11. "local missingFiles = {}", -- Initialization of missingFiles table
  12. "for _, fileName in ipairs(requiredFiles) do", -- Loop through requiredFiles
  13. "if not fs.exists(fileName) then", -- Check for file existence
  14. "table.insert(missingFiles, fileName)", -- Inserting missing files
  15. "return missingFiles", -- Return missing files
  16. "local function main()", -- Definition of main function
  17. "local missing = checkFiles()", -- Call checkFiles function
  18. "if #missing > 0 then", -- Check if any files are missing
  19. "shell.run(\"no-os\")", -- Run no-os script
  20. "else", -- Else branch for file existence
  21. "shell.run(\"/disk/boot/CFW-check.lua\")", -- Run start-check.lua
  22. "end", -- End of if-else block
  23. "main()" -- Call the main function
  24. }
  25.  
  26. -- Function to read a file's content
  27. local function readFile(path)
  28. if not fs.exists(path) then
  29. return nil
  30. end
  31.  
  32. local file = fs.open(path, "r")
  33. local content = file.readAll()
  34. file.close()
  35. return content
  36. end
  37.  
  38. -- Function to check for the presence of key elements in a script
  39. local function checkForElements(content, elements)
  40. if not content then
  41. return false
  42. end
  43.  
  44. for _, element in ipairs(elements) do
  45. if not string.find(content, element, 1, true) then
  46. return false
  47. end
  48. end
  49.  
  50. return true
  51. end
  52.  
  53. -- Main function to compare the contents of `startup` and `startup.lua`
  54. local function compareStartupFiles()
  55. local startupContent = readFile("/startup")
  56. local startupLuaContent = readFile("/startup.lua")
  57.  
  58. if checkForElements(startupContent, requiredElements) or checkForElements(startupLuaContent, requiredElements) then
  59. -- All required elements are present; run the start-check.lua script
  60. shell.run("/disk/boot/start-check.lua")
  61. else
  62. -- Required elements are missing; show fatal error
  63. print("Error: The startup script does not contain all required elements.")
  64. showFatalError()
  65. end
  66. end
  67.  
  68. -- Function to clear the screen and display a fixed error message
  69. local function showFatalError()
  70. term.clear()
  71. term.setBackgroundColor(colors.black)
  72. term.setTextColor(colors.white)
  73. term.clear()
  74.  
  75. local width, height = term.getSize()
  76.  
  77. local function centerText(y, text, textColor)
  78. local x = math.floor((width - #text) / 2)
  79. term.setCursorPos(x, y)
  80. term.setTextColor(textColor)
  81. term.write(text)
  82. end
  83.  
  84. local fatalArt = {
  85. " |\\_/| ",
  86. " | X X ",
  87. " | <> _ ",
  88. " | _/\\------____ ((| |))",
  89. " | `--' | ",
  90. " _____|_ ___| |___. ",
  91. "/_/_____/____/_______| "
  92. }
  93.  
  94. term.setTextColor(colors.red)
  95. local startLine = math.floor((height - #fatalArt - 4) / 2) -- Adjust start line for ASCII art
  96.  
  97. for i, line in ipairs(fatalArt) do
  98. centerText(startLine + i, line, colors.red)
  99. end
  100.  
  101. term.setTextColor(colors.white)
  102. centerText(startLine + #fatalArt + 2, "Error:", colors.white) -- Position adjusted
  103. centerText(startLine + #fatalArt + 3, "CFW Verification Error", colors.white) -- Position adjusted
  104. centerText(height - 2, "Please contact support.", colors.white) -- Added back at the bottom
  105.  
  106. while true do
  107. sleep(1)
  108. end
  109. end
  110.  
  111. -- Run the comparison function with error handling
  112. local success, _ = pcall(compareStartupFiles)
  113. if not success then
  114. showFatalError()
  115. end
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement