DOGGYWOOF

Doggy OS HW ID check on boot

Nov 19th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. -- Function to read the hashed ID from the JSON-like config file
  2. local function readHashedID()
  3. if not fs.exists("HardwareID.cfg") then
  4. return nil
  5. end
  6.  
  7. local file = fs.open("HardwareID.cfg", "r")
  8. local content = file.readAll()
  9. file.close()
  10.  
  11. -- Extract the HashedID from the JSON-like content
  12. local hashedID = content:match('"HashedID"%s*:%s*(%d+)')
  13. return hashedID and tonumber(hashedID)
  14. end
  15.  
  16. -- Reversible hash function to encode/decode the computer ID
  17. local function generateHash(id)
  18. return (id * 12345 + 67890) % 1000000
  19. end
  20.  
  21. -- Function to "unhash" the hashed ID to get the original ID
  22. local function unhashID(hashedID)
  23. for possibleID = 0, 10000 do -- Assuming a reasonable range for computer IDs
  24. if generateHash(possibleID) == hashedID then
  25. return possibleID
  26. end
  27. end
  28. return nil -- If no valid ID is found
  29. end
  30.  
  31. -- Function to display the error screen
  32. local function showErrorScreen()
  33. -- Clear the screen and set up colors
  34. term.clear()
  35. term.setBackgroundColor(colors.black)
  36. term.setTextColor(colors.white)
  37. term.clear()
  38.  
  39. -- Define the width and height of the screen
  40. local width, height = term.getSize()
  41.  
  42. -- Helper function to center text on the screen
  43. local function centerText(y, text, textColor)
  44. local x = math.floor((width - #text) / 2)
  45. term.setCursorPos(x, y)
  46. term.setTextColor(textColor)
  47. term.write(text)
  48. end
  49.  
  50. -- Display the dog ASCII art with red Xes for eyes
  51. local dogArt = {
  52. " |\\_/| ",
  53. " | X X HARDWARE ERROR!",
  54. " | <> _ ",
  55. " | _/\\------____ ((| |))",
  56. " | `--' | ",
  57. " _____|_ ___| |___. ",
  58. "/_/_____/____/_______| "
  59. }
  60.  
  61. local startLine = math.floor((height - #dogArt) / 2) - 2
  62.  
  63. -- Display the dog ASCII art with red Xes for eyes in red
  64. term.setTextColor(colors.red)
  65. for i, line in ipairs(dogArt) do
  66. centerText(startLine + i, line, colors.red)
  67. end
  68.  
  69. -- Display error message below the dog ASCII art in white
  70. term.setTextColor(colors.white)
  71. centerText(startLine + #dogArt + 2, "HARDWARE ID ERROR", colors.white)
  72. centerText(startLine + #dogArt + 3, "Error: ACCESS DENIED", colors.white)
  73.  
  74. -- Move "Please contact support." to the bottom in white
  75. centerText(height - 2, "Please contact support.", colors.white)
  76.  
  77. -- Keep the screen static with the error message
  78. while true do
  79. sleep(1)
  80. end
  81. end
  82.  
  83. -- Read the hashed ID from the config file
  84. local hashedID = readHashedID()
  85. if not hashedID then
  86. showErrorScreen()
  87. return
  88. end
  89.  
  90. -- Retrieve the real computer ID
  91. local currentID = os.getComputerID()
  92.  
  93. -- Unhash the hashed ID to get the original ID
  94. local unhashedID = unhashID(hashedID)
  95.  
  96. -- Check if the real computer ID matches the unhashed ID
  97. if currentID == unhashedID then
  98. print("Computer ID verified successfully. Access granted.")
  99.  
  100. -- Run the /disk/boot/CFW-check.lua script if verification passes
  101. if fs.exists("/disk/boot/CFW-check.lua") then
  102. shell.run("/disk/boot/CFW-check.lua")
  103. else
  104. print("Error: /disk/boot/CFW-check.lua not found.")
  105. end
  106. else
  107. showErrorScreen()
  108. end
  109.  
Add Comment
Please, Sign In to add comment