VlaD00m

srcreate.lua

Sep 16th, 2020
951
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[ SecuROM Creator.
  2. Program for creating Password-secured Lua BIOS EEPROM for OpenComputers
  3. Author: Bs()Dd
  4. ]]
  5.  
  6. local function confirm(msg)
  7.     print(msg)
  8.     print("Type `y` to start or `n` to exit.")
  9.     repeat
  10.       local response = io.read()
  11.       if response and response:lower():sub(1, 1) == "n" then
  12.         os.exit()
  13.       end
  14.     until response and response:lower():sub(1, 1) == "y"
  15.   return true
  16. end
  17.  
  18. local component = require('component')
  19. print('SecuROM Lua BIOS Creator v 1.1')
  20. print('2020 (c) Compys Security Software\n')
  21. confirm("Do You want to set password on Your BIOS?")
  22. print('\nEnter password:')
  23. local passw = io.read()
  24. if confirm("\nAre You ready to flash EEPROM?") then
  25.      code= [=[local init
  26. do
  27. local component_invoke = component.invoke
  28. local function boot_invoke(address, method, ...)
  29. local result = table.pack(pcall(component_invoke, address, method, ...))
  30. if not result[1] then
  31. return nil, result[2]
  32. else
  33. return table.unpack(result, 2, result.n)
  34. end
  35. end
  36. local eeprom = component.list("eeprom")()
  37. computer.getBootAddress = function()
  38. return boot_invoke(eeprom, "getData")
  39. end
  40. computer.setBootAddress = function(address)
  41. return boot_invoke(eeprom, "setData", address)
  42. end
  43. do
  44. local screen = component.list("screen")()
  45. local gpu = component.list("gpu")()
  46. if gpu and screen then
  47. boot_invoke(gpu, "bind", screen)
  48. end
  49. end
  50. local function tryLoadFrom(address)
  51. local handle, reason = boot_invoke(address, "open", "/init.lua")
  52. if not handle then
  53. return nil, reason
  54. end
  55. local buffer = ""
  56. repeat
  57. local data, reason = boot_invoke(address, "read", handle, math.huge)
  58. if not data and reason then
  59. return nil, reason
  60. end
  61. buffer = buffer .. (data or "")
  62. until not data
  63. boot_invoke(address, "close", handle)
  64. return load(buffer, "=init")
  65. end
  66. local reason
  67. if computer.getBootAddress() then
  68. init, reason = tryLoadFrom(computer.getBootAddress())
  69. end
  70. if not init then
  71. computer.setBootAddress()
  72. for address in component.list("filesystem") do
  73. init, reason = tryLoadFrom(address)
  74. if init then
  75. computer.setBootAddress(address)
  76. break
  77. end
  78. end
  79. end
  80. if not init then
  81. error("no bootable medium found" .. (reason and (": " .. tostring(reason)) or ""), 0)
  82. end
  83. computer.beep(1000, 0.2)
  84. end
  85. function pull(...)
  86. local args = table.pack(...)
  87. if type(args[1]) == "string" then
  88. return pullFiltered(createPlainFilter(...))
  89. else
  90. checkArg(1, args[1], "number", "nil")
  91. checkArg(2, args[2], "string", "nil")
  92. return pullFiltered(args[1], createPlainFilter(select(2, ...)))
  93. end
  94. end
  95. function pullFiltered(...)
  96. local args = table.pack(...)
  97. local seconds, filter = math.huge
  98. if type(args[1]) == "function" then
  99. filter = args[1]
  100. else
  101. checkArg(1, args[1], "number", "nil")
  102. checkArg(2, args[2], "function", "nil")
  103. seconds = args[1]
  104. filter = args[2]
  105. end
  106. repeat
  107. local signal = table.pack(computer.pullSignal(seconds))
  108. if signal.n > 0 then
  109. if not (seconds or filter) or filter == nil or filter(table.unpack(signal, 1, signal.n)) then
  110. return table.unpack(signal, 1, signal.n)
  111. end
  112. end
  113. until signal.n == 0
  114. end
  115. function createPlainFilter(name, ...)
  116. local filter = table.pack(...)
  117. if name == nil and filter.n == 0 then
  118. return nil
  119. end
  120. return function(...)
  121. local signal = table.pack(...)
  122. if name and not (type(signal[1]) == "string" and signal[1]:match(name)) then
  123. return false
  124. end
  125. for i = 1, filter.n do
  126. if filter[i] ~= nil and filter[i] ~= signal[i + 1] then
  127. return false
  128. end
  129. end
  130. return true
  131. end
  132. end
  133. function check()
  134. if inp == password then
  135. computer.beep(1000, 0.5)
  136. init()
  137. else
  138. vid.fill(10, 3, mx, 1, " ")
  139. vid.set(1,4, "Incorrect Password!")
  140. inp = ""
  141. pos = 1
  142. computer.beep(500,1)
  143. vid.fill(1, 4, mx, 1, " ")
  144. end
  145. end
  146. vid=component.proxy(component.list("gpu")())
  147. mx, my = vid.getResolution()
  148. vid.fill(1, 1, mx, my, " ")
  149. vid.set(1,1, "SecuROM Lua BIOS v1.0.2")
  150. vid.set(1,2, "2020 (c) Compys Security Software")
  151. computer.beep(2000,0.5)
  152. computer.beep(2000,0.5)
  153. vid.set(1,3, "Password: ")
  154. password = "%s"
  155. inp = ""
  156. pos = 1
  157. while true do
  158.   _, _, key = pull("key_up")
  159.   if key == 8 then
  160.     if pos == 1 then pos = 2 end
  161.     pos= pos-1
  162.     inp = inp:sub(1,pos-1)
  163.     vid.set(pos+10,3, ' ')
  164.   elseif key == 13 then
  165.     check()
  166.   elseif key == 0 or key == 9 or key == 127 then
  167.   else
  168.     pos = pos+1
  169.     inp = inp..unicode.char(key)
  170.     vid.set(pos+9,3, "*")
  171.   end
  172. end]=]
  173.      local chip = component.eeprom
  174.      chip.set(string.format(code, passw))
  175.      chip.setLabel('SecuROM Lua BIOS')
  176.      print('\nPassword set!')
  177.    end
RAW Paste Data