Advertisement
DOGGYWOOF

Untitled

Sep 24th, 2024
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. --[[
  2. RedNet Sniffer
  3. by kyle1elyk
  4. --]]
  5. _RNSV = 4.2 -- RedNet Sniffer Version
  6.  
  7. function DEC_HEX(IN)
  8. --http://lua-users.org/lists/lua-l/2004-09/msg00054.html
  9. local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
  10. while IN>0 do
  11. I=I+1
  12. IN,D=math.floor(IN/B),(IN%B)+1
  13. OUT=string.sub(K,D,D)..OUT
  14. end
  15. if OUT=="" then OUT = "0" end
  16. return OUT
  17. end
  18.  
  19. function deepcopy(orig)
  20. --http://lua-users.org/wiki/CopyTable
  21. local orig_type = type(orig)
  22. local copy
  23. if orig_type == 'table' then
  24. copy = {}
  25. for orig_key, orig_value in next, orig, nil do
  26. copy[deepcopy(orig_key)] = deepcopy(orig_value)
  27. end
  28. setmetatable(copy, deepcopy(getmetatable(orig)))
  29. else -- number, string, boolean, etc
  30. copy = orig
  31. end
  32. return copy
  33. end
  34.  
  35. -- Removed the mobile version check
  36. paused = false
  37. w,h = term.getSize()
  38. local modem = peripheral.wrap("back")
  39. modem.open(65533)
  40. hasMsg = false
  41. modemSide, sC, rC, msg, sDist = nil
  42. savedMsg = {}
  43. for i=1,16 do
  44. savedMsg[i] = {}
  45. end
  46. local backColor, labelColor, secLabelColor = colors.gray, colors.lime, colors.green
  47. local re = "Resend Last Message"
  48. term.setBackgroundColor(backColor)
  49. term.setCursorPos(1,1)
  50. term.clear()
  51.  
  52. function pKV(k,v,tempColor)
  53. term.setTextColor(labelColor)
  54. write(k..": ")
  55. term.setTextColor(tempColor or colors.white)
  56. print(v)
  57. term.setTextColor(colors.white)
  58. end
  59.  
  60. function displayMsg(msg, sC, rC)
  61. paintutils.drawFilledBox(1,2,w,h-3)
  62. term.setBackgroundColor(backColor)
  63. term.setCursorPos(1,3)
  64. pKV("Message", "\n"..textutils.serialize(msg))
  65. pKV("SenderChannel",sC)
  66. pKV("ReplyChannel",rC)
  67. end
  68.  
  69. function header(msg)
  70. term.setBackgroundColor(labelColor)
  71. paintutils.drawLine(1,1,w,1)
  72. term.setCursorPos(1,1)
  73. write(msg)
  74. term.setBackgroundColor(backColor)
  75. end
  76.  
  77. print("Sniffer Running v".._RNSV.."\nkyle1elyk\n")
  78. pKV("L-CLICK","VIEW")
  79. pKV("R-CLICK","SAVE")
  80. pKV("M-CLICK","SEND")
  81. term.setCursorPos(1,2)
  82.  
  83. while true do
  84. if hasMsg then
  85. term.setBackgroundColor(labelColor)
  86. paintutils.drawLine(1,h-1,w,h-1)
  87. term.setCursorPos(1,h-1)
  88.  
  89. write("Save:")
  90. term.setCursorPos(w-16,h-1)
  91. term.setBackgroundColor(labelColor)
  92. write(" ")
  93. for k,v in ipairs(savedMsg) do
  94. if next(v) == nil then
  95. term.setTextColor(colors.gray)
  96. else
  97. term.setTextColor(colors.white)
  98. end
  99. write(DEC_HEX(k-1))
  100. end
  101. term.setCursorPos(1,h)
  102. term.setTextColor(colors.white)
  103. write(re)
  104. for i=1, w-string.len(re)-1 do
  105. write(" ")
  106. end
  107. if paused then
  108. term.setBackgroundColor(colors.red)
  109. write("P")
  110. else
  111. term.setBackgroundColor(colors.green)
  112. write(" ")
  113. end
  114. term.setBackgroundColor(backColor)
  115. term.setCursorPos(1,2)
  116. end
  117.  
  118. local event, arg1, arg2, arg3, arg4, arg5 = os.pullEvent()
  119. if not paused and event == "modem_message" then
  120. term.clear()
  121. modemSide, sC, rC, msg, sDist = arg1, arg2, arg3, arg4, arg5
  122. displayMsg(msg,sC,rC)
  123. local tC
  124. if sDist < 10 then tC = colors.red
  125. elseif sDist < 20 then tC = colors.orange
  126. elseif sDist < 30 then tC = colors.yellow
  127. else tC = colors.white end
  128. print()
  129. pKV("SenderDistance",sDist,tC)
  130.  
  131. hasMsg = true
  132. elseif event == "mouse_click" and hasMsg then
  133. w,h = term.getSize()
  134. btn, x, y = arg1, arg2, arg3
  135. if y == h and x < w-2 then
  136. -- Resend last message
  137. term.setCursorPos(1,h)
  138. term.setTextColor(labelColor)
  139. term.setBackgroundColor(colors.white)
  140. write(re)
  141. for i=1, w-string.len(re)-1 do
  142. write(" ")
  143. end
  144. term.setBackgroundColor(backColor)
  145. term.setTextColor(colors.white)
  146. sendTo = 65533
  147. if msg.nMessageID ~= nil then
  148. msg.nMessageID = math.random(1, 2147483647)
  149. end
  150. if msg.nRecipient ~= nil then
  151. sendTo = msg.nRecipient
  152. end
  153. term.setCursorPos(1,1)
  154. modem.transmit(sendTo,rC,msg)
  155. header("SENT LAST")
  156. sleep(0.1)
  157. elseif y == h and x >= w-1 then
  158. paused = not paused
  159. elseif y == h-1 and x >= w-15 then
  160. key = x - (w-16)
  161. if btn == 3 then
  162. if next(savedMsg[key]) == nil then
  163. term.setCursorPos(1,1)
  164. header("NO ENTRY IN "..DEC_HEX(key-1))
  165. else
  166. sendTo = 65533
  167. if savedMsg[key].msg.nMessageID ~= nil then
  168. savedMsg[key].msg.nMessageID = math.random(1, 2147483647)
  169. end
  170. if savedMsg[key].msg.nRecipient ~= nil then
  171. sendTo = savedMsg[key].msg.nRecipient
  172. end
  173. term.setCursorPos(1,1)
  174. modem.transmit(sendTo,rC,savedMsg[key].msg)
  175. header("SENT "..DEC_HEX(key-1))
  176. displayMsg(savedMsg[key].msg,savedMsg[key].sC,savedMsg[key].rC)
  177. end
  178. elseif btn == 1 then
  179. if next(savedMsg[key]) == nil then
  180. term.setCursorPos(1,1)
  181. header("NO ENTRY IN "..DEC_HEX(key-1))
  182. else
  183. term.setCursorPos(1,1)
  184. header("VIEW "..DEC_HEX(key-1))
  185. displayMsg(savedMsg[key].msg,savedMsg[key].sC,savedMsg[key].rC)
  186. end
  187. else
  188. if next(savedMsg[key]) == nil then
  189. savedMsg[key].sC = sC
  190. savedMsg[key].rC = rC
  191. savedMsg[key].msg = deepcopy(msg)
  192. term.setCursorPos(1,1)
  193. header("SAVED IN "..DEC_HEX(key-1))
  194. displayMsg(savedMsg[key].msg,savedMsg[key].sC,savedMsg[key].rC)
  195. else
  196. savedMsg[key].sC = sC
  197. savedMsg[key].rC = rC
  198. savedMsg[key].msg = deepcopy(msg)
  199. term.setCursorPos(1,1)
  200. header("OVERWROTE "..DEC_HEX(key-1))
  201. end
  202. end
  203. end
  204. end
  205. end
  206.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement