Advertisement
MC403

SJNAVK main

Jun 29th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.28 KB | None | 0 0
  1. -- SJNAVK for SJNOS and more by MC403
  2.  
  3. local tArgs = {...}
  4. local color = term.isColor()
  5.  
  6. if color then
  7.     term.setTextColor(colors.red)
  8. else
  9.  
  10. end
  11.  
  12. local keywords = ""
  13. local pastebin = ""
  14. local text = ""
  15.  
  16. if #tArgs == 1 then
  17.     --Check program
  18.     local path = tArgs[1]
  19.     if fs.exists(path) then
  20.         term.setCursorPos(1,1)
  21.        
  22.         -------------------------------------------------
  23.         --Declaration
  24.         local check_RES_result = false
  25.         local check_RES_keywords = 0
  26.         local check_RES_pastebin = 0
  27.         local check_RES_text = ""
  28.  
  29.         --Get Keys
  30.         if fs.exists("SJNAVK/key") then fs.delete("SJNAVK/key") end
  31.         shell.run("pastebin","get","Cp5tyw2c","SJNOS/key")
  32.         local h = fs.open("SJNOS/key","r")
  33.         local check_LOC_keys = {}
  34.         local finished = false
  35.         while not finished do
  36.             local c = h.readLine()
  37.             if not c == nil then
  38.                 table.insert(check_LOC_keys,c)
  39.             else
  40.                 finished = true
  41.             end
  42.         end
  43.         h.close()
  44.         fs.delete("SJNAVK/key")
  45.  
  46.         --Get File
  47.         local h = fs.open(path)
  48.         local check_LOC_file = h.readAll()
  49.  
  50.         --Comparing Keys with File Content
  51.  
  52.         for i=1, #check_LOC_keys do
  53.             local check_LOC_result = string.find(check_LOC_file,check_LOC_keys[i])
  54.             if not check_LOC_result == nil then
  55.                 check_RES_keywords = check_RES_keywords + 1
  56.                 if check_LOC_keys[i] == "pastebin" then
  57.                     RESULT_pastebin = RESULT_pastebin + 1
  58.                 end
  59.             end
  60.         end
  61.  
  62.         --Calculate Result
  63.         if RESULT_keywords >= 20 then
  64.             RESULT_result = true
  65.             RESULT_text = "WARNING: VERY DANGEROUS! IF YOU DON'T TRUST THE DEVELOPERS, YOU SHOULD DELETE THIS FILE!"
  66.         elseif RESULT_keywords >= 15 then
  67.             RESULT_result = true
  68.             RESULT_text = "WARNING: DANGEROUS!"
  69.         elseif RESULT_keywords >= 10 then
  70.             RESULT_result = true
  71.             RESULT_text = "WARNING: VERY UNSAFE"
  72.         elseif RESULT_keywords >= 5 then
  73.             RESULT_result = true
  74.             RESULT_text = "Warning: UNSAFE"
  75.         elseif Result_keywords > 0 then
  76.             RESULT_result = true
  77.             RESULT_text = "This program can be a virus, but is pretty safe. You can debug it."
  78.         else
  79.             RESULT_result = false
  80.             RESULT_text = "This program is not dangerous :)"
  81.         end
  82.         -------------------------------------------------
  83.        
  84.        
  85.        
  86.         if result then
  87.             --Virus
  88.             if color then
  89.                 local function colormenu()
  90.                     term.setBackgroundColor(colors.black)
  91.                     term.setTextColor(colors.red)
  92.                     print("SJNAVK: ["..path.."]")
  93.                     term.setCursorPos(51,1)
  94.                     term.setTextColor(colors.black)
  95.                     term.setBackgroundColor(colors.gray)
  96.                     print("X")
  97.                    
  98.                     term.setTextColor(colors.black)
  99.                     term.setBackgroundColor(colors.red)
  100.                     term.setCursorPos(1,3)
  101.                     print("Keywords: "..keywords)
  102.                     term.setCursorPos(40,3)
  103.                     term.setTextColor(colors.black)
  104.                     term.setBackgroundColor(colors.gray)
  105.                     print("See them")
  106.                    
  107.                     term.setTextColor(colors.black)
  108.                     term.setBackgroundColor(colors.red)
  109.                     term.setCursorPos(1,4)
  110.                     print("Pastebin: "..pastebin)
  111.                     term.setCursorPos(40,4)
  112.                     term.setTextColor(colors.black)
  113.                     term.setBackgroundColor(colors.gray)
  114.                     print("See them")
  115.                    
  116.                     term.setTextColor(colors.black)
  117.                     term.setBackgroundColor(colors.red)
  118.                     print("")
  119.                     print(text)
  120.                     print("")
  121.                    
  122.                     local x, y = term.getCursorPos()
  123.                     term.setCursorPos(1,y)
  124.                 end
  125.                 colormenu()
  126.             else
  127.                 --No color
  128.                 local function nocolormenu()
  129.                     print("SJNAVK")
  130.                     print("Keywords: "..keywords)
  131.                     print("Pastebin: "..pastebin)
  132.                     print("")
  133.                     print(text)
  134.                     print("")
  135.                     print("> Edit Code")
  136.                     print("  Remove File")
  137.                     print("  Run File")
  138.                     print("  Save Debug")
  139.                     print("  Reboot")
  140.                     print("  SJNAVK")
  141.                    
  142.                     local x, y = term.getCursorPos()
  143.                     local solved = false
  144.                     local selected = 1
  145.                     local maxnr = 6
  146.                     local linenr = y-maxnr
  147.                     while not solved do
  148.                         for i=1,maxnr do
  149.                             term.setCursorPos(1,i+linenr)
  150.                             if i==selected then
  151.                                 print(">")
  152.                             else
  153.                                 print(" ")
  154.                             end
  155.                         end
  156.                         local event, button = os.pullEvent("key")
  157.                         if button==208 then
  158.                             if selected<maxnr then
  159.                                 selected = selected + 1
  160.                             else
  161.                                 selected = 1
  162.                             end
  163.                         elseif button==200 then
  164.                             if selected>1 then
  165.                                 selected = selected - 1
  166.                             else
  167.                                 selected = maxnr
  168.                             end
  169.                         elseif button==28 then
  170.                             solved = true
  171.                         end
  172.                     end
  173.                     if selected == 1 then
  174.                         --Edit code
  175.                         shell.run("edit",path)
  176.                     elseif selected == 2 then
  177.                         --Remove File
  178.                         fs.delete(path)
  179.                         print("File has been deleted!")
  180.                     elseif selected == 3 then
  181.                         --Run File
  182.                         term.clear()
  183.                         term.setCursorPos(1,1)
  184.                         print("ARE YOU SURE TO RUN THIS FILE ("..path..") ?")
  185.                         print("> Yes")
  186.                         print("  No")
  187.                         local done = false
  188.                         local select = 1
  189.                        
  190.                         while not done do
  191.                             local event, button = os.pullEvent("key")
  192.                             if button == 208 or button == 200 then
  193.                                 if select == 1 then select = 2
  194.                                 else select = 1 end
  195.                                 term.setCursorPos(1,2)
  196.                                 if selected == 2 then
  197.                                     print("  Yes")
  198.                                     print("> No")
  199.                                 else
  200.                                     print("> Yes")
  201.                                     print("  No")
  202.                                 end
  203.                             elseif button == 28 then
  204.                                 done = true
  205.                             end
  206.                         end
  207.                         if select == 1 then
  208.                             for i=15, 0, -1 do
  209.                                 term.clear()
  210.                                 term.setCursorPos(1,1)
  211.                                 print("You have "..i.." Seconds to press Strg+T for 4 seconds to terminate, then then "..path.." will run!")
  212.                                 sleep(1)
  213.                             end
  214.                             shell.run(path)
  215.                         else
  216.                             nocolormenu()
  217.                         end
  218.                        
  219.                     elseif selected == 4 then
  220.                         --Save Debug
  221.                         function saveDebug(path)
  222.                             print("SAVEDEBUG is not written yet.")
  223.                         end
  224.                         nocolormenu()
  225.                     elseif selected == 5 then
  226.                         --Reboot
  227.                         term.clear()
  228.                         term.setCursorPos(1,1)
  229.                         textutils.slowPrint("Thanks for using SJNOS")
  230.                         textutils.slowPrint("Rebooting...")
  231.                         sleep(0.5)
  232.                         os.reboot()
  233.                     elseif selected == 6 then
  234.                         --SJNAVK
  235.                         shell.run(shell.getRunningProgram())
  236.                     end
  237.                 end
  238.                 nocolormenu()
  239.             end
  240.         else
  241.             --No Virus
  242.             if color then
  243.                 print("COLOR")
  244.             else
  245.                 term.clear()
  246.                 term.setCursorPos(1,1)
  247.                 print("SJNAVK")
  248.                 print("No Virus detected, "..keywords.." Keywords, "..pastebin.." Pastebin, Text: "..text.." !")
  249.                 print("")
  250.                 print("> SJNAVK")
  251.                 print("  Exit")
  252.                 local done = false
  253.                 local select = 1
  254.                 while not done do
  255.                     local event, button = os.pullEvent("key")
  256.                     if button == 208 or button == 200 then
  257.                         if select == 1 then select = 2
  258.                         else select = 1 end
  259.                         term.setCursorPos(1,4)
  260.                         if select == 2 then
  261.                             print("  SJNAVK")
  262.                             print("> Exit")
  263.                         else
  264.                             print("> SJNAVK")
  265.                             print("  Exit")
  266.                         end
  267.                     elseif button == 28 then
  268.                         done = true
  269.                     end
  270.                 end
  271.                
  272.                 if select == 1 then
  273.                     shell.run(shell.getRunningProgram())
  274.                 else
  275.                     print("The program will end in 5 seconds.")
  276.                 end
  277.             end
  278.         end
  279.     else
  280.         print("The path '"..path.."' does not exist!")
  281.     end
  282. else
  283.     --Normal Program
  284.     print("NORMAL SJNAVK")
  285. end
  286.  
  287. if color then
  288.     term.setTextColor(colors.cyan)
  289.     term.setBackgroundColor(colors.white)
  290.     sleep(1)
  291. end
  292. term.clear()
  293. term.setCursorPos(1,1)
  294. textutils.slowPrint("Thanks for using SJNAVK!!! (by MC403)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement