Advertisement
Guest User

NetBIOS

a guest
May 16th, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. function component.isAvailable(target)
  2. return component.list(target)() ~= nil
  3. end
  4.  
  5. function computer.getBootAddress()
  6. return __BIOS_DATA:sub(1, 36)
  7. end
  8.  
  9. setmetatable(component, {
  10. ["__index"] = function(_, key)
  11. if component.isAvailable(key) then
  12. return component.proxy(component.list(key)())
  13. end
  14. end
  15. })
  16.  
  17. local eeprom = component.eeprom
  18.  
  19. __BIOS_PXE = component.modem ~= nil
  20. __BIOS_TARGET = ""
  21. __BIOS_SERVER = ""
  22. __BIOS_DATA = eeprom.getData()
  23. __BIOS_LEGACY = (__BIOS_DATA ~= "" and type(__BIOS_DATA == "string")) and #__BIOS_DATA == 36
  24.  
  25. event = {}
  26. local stack = {}
  27. local listeners = {}
  28. function event.pull(filter)
  29. if not filter then return table.remove(stack,1)
  30. else
  31. for _,v in pairs(stack) do
  32. if v == filter then
  33. return v
  34. end
  35. end
  36. repeat
  37. t=table.pack(computer.pullSignal())
  38. evtype = table.remove(t,1)
  39. if listeners[evtype] ~= nil then
  40. for k,v in pairs(listeners[evtype]) do
  41. local evt = pcall(v,evtype,table.unpack(t))
  42. end
  43. end
  44. until evtype == filter
  45. return evtype, table.unpack(t)
  46. end
  47. end
  48.  
  49. if __BIOS_DATA:sub(37, 41) == ":http" then
  50. if component.isAvailable("internet") then
  51. local url = __BIOS_DATA:sub(38, #__BIOS_DATA)
  52. local internet = component.internet
  53. local req = internet.request(url)
  54. repeat
  55. local success, connected = pcall(req.finishConnect)
  56. until success and connected
  57. __BIOS_TARGET = req.read()
  58. __BIOS_PXE = false
  59. end
  60.  
  61. if __BIOS_DATA:sub(37, 38) == ":/" or (__BIOS_LEGACY and __BIOS_PXE) then
  62. local targetAddr = __BIOS_DATA:sub(1, 36)
  63. local targetFile = __BIOS_DATA:sub(38, #__BIOS_DATA)
  64.  
  65. __BIOS_ROOT = component.proxy(targetAddr)
  66. local handle = __BIOS_ROOT.open(targetFile or __BIOS_LEGACY and "/init.lua")
  67. __BIOS_TARGET = __BIOS_ROOT.read(handle, math.huge)
  68. __BIOS_PXE = false
  69. end
  70. end
  71.  
  72. if __BIOS_PXE then
  73. local modem = component.modem
  74.  
  75. local function status(msg, ...)
  76. modem.broadcast(2412, msg, ...)
  77. end
  78.  
  79. modem.open(2412)
  80. status("PXE_READY")
  81.  
  82. repeat
  83. local _, _, addr, _, _, status = event.pull("modem_message")
  84. __PXE_SERVER = addr
  85. until status == "PXE_CONNECT"
  86. status = nil
  87.  
  88. repeat
  89. local _, _, from, _, _, partial = event.pull("modem_message")
  90. if (from ~= __PXE_SERVER) then
  91. do break end
  92. end
  93. __BIOS_TARGET = __BIOS_TARGET .. partial
  94. until partial == ""
  95. end
  96.  
  97. return load(__BIOS_TARGET)()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement