xModders

Minerva Owl Lib (for greyhack 0.7.3x)

Aug 29th, 2021 (edited)
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 31.96 KB | None | 0 0
  1. // Minerva Owl Lib Open Source Package for Grey Hack 0.7.3x, coded by Chrome https://steamcommunity.com/id/01043477120/.
  2. // The package is a bundle of many functions.You can use this script for learning , personal usage.If you add
  3. // or remove code in view to integrated it to your own public project, in this case please mention wich part belong
  4. // to my personal work and intellectual integrity.
  5.  
  6. //  /¤v¤\
  7. //  |/ \|
  8. //  |/ \|  Minerva Owl Lib 2.0.9
  9. //   ,|.
  10.  
  11. Official Documentation : https://minervaowllib.com/
  12.  
  13.  
  14. //Loading dependencies in /lib
  15. Libs = {}
  16. Libs.metaxploit = "";
  17. Libs.crypto = "";
  18. Libs.aptclient = "";
  19.  
  20. Libs.load_dependencies = function()
  21.     libFolder = get_shell.host_computer.File("/lib");
  22.     if typeof(libFolder) == "file" then
  23.         files = libFolder.get_files;
  24.         if files.len > 0 then
  25.             for i in range(0,files.len -1)
  26.                 if files[i].name == "metaxploit.so" then
  27.                     Libs.metaxploit = include_lib(files[i].path);
  28.                 else if files[i].name == "crypto.so" then
  29.                     Libs.crypto = include_lib(files[i].path);
  30.                 else if files[i].name == "aptclient.so" then
  31.                     Libs.aptclient = include_lib(files[i].path);
  32.                 end if
  33.             end for
  34.         end if
  35.     end if
  36. end function
  37.  
  38. //String header
  39. String = {};
  40. String.reserved_reverse_string = "";
  41.  
  42. //Reverse string.
  43. //Simply reverse a string.
  44. String.reverseString = function(x)
  45.     if typeof(x) != "string" then return "error : reverse string -> x expected string.";
  46.     string = [];
  47.     for i in range(0,x.len -1)
  48.         string.push(x[i]);
  49.     end for
  50.     string.reverse;
  51.     String.reserved_reverse_string = string.join("");
  52.     return String.reserved_reverse_string;
  53. end function
  54.  
  55. //String to decimal.
  56. //Simply convert a string to decimal.
  57. String.stringToDecimal = function(x)
  58.     if typeof(x) != "string" then return "error : string to decimal -> x expected string.";
  59.     decString = "";
  60.     for i in range(0,x.len -1)
  61.         decString = decString + code(x[i]);
  62.         if i < x.len -1 then decString = decString + ":";
  63.     end for
  64.     return decString;
  65. end function
  66.  
  67. //String to hex.
  68. //Simply convert a string to hex , using Math lib.
  69. String.stringToHex = function(x)
  70.     if typeof(x) != "string" then return "error : string to hex -> x expected string.";
  71.     hexString = "";
  72.     for i in range(0,x.len -1)
  73.         hexString = hexString + Math.decimalToHex(code(x[i]),"");
  74.         if i < x.len -1 then hexString = hexString + ":";
  75.     end for
  76.     return hexString;
  77. end function
  78.  
  79. //String to list.
  80. //Simply convert a string to a char list.
  81. String.stringToList = function(x)
  82.     if typeof(x) != "string" then return "error : string to list -> x expected string.";
  83.     list = [];
  84.     for i in range(0,x.len -1)
  85.         list.push(x[i]);
  86.     end for
  87.     return list;
  88. end function
  89.  
  90. String.cut = function(x,y)
  91.     if typeof(x) != "string" then return "error : string cut -> x expected string.";
  92.     if typeof(y) != "list" then return "error : string cut -> x expected vector2.";
  93.  
  94.     string = String.stringToList(x);
  95.     part1 = [];
  96.     part2 = [];
  97.     for i in range(0,string.len -1)
  98.         if i < y[0] then part1.push(string[i]);
  99.         if i > y[1] then part2.push(string[i]);
  100.     end for
  101.     cutString = [part1.join(""),part2.join("")];
  102.  
  103.     return cutString;
  104. end function
  105.  
  106. String.replace = function(x,y,z)
  107.     if typeof(x) != "string" then return "error : string replace -> x expected string.";
  108.     if typeof(y) != "list" then return "error : string replace -> y expected string.";
  109.     if typeof(z) != "string" then return "error : string replace -> z expected string.";
  110.  
  111.     string = String.stringToList(x);
  112.     part1 = [];
  113.     part2 = [];
  114.  
  115.     for i in range(0,string.len -1)
  116.         if i < y[0] then part1.push(string[i]);
  117.         if i > y[1] then part2.push(string[i]);
  118.     end for
  119.     newString = part1.join("") + z + part2.join("");
  120.  
  121.     return newString;
  122. end function
  123.  
  124. //Math Header
  125. Math = {};
  126. Math.reserved_hex_string = "";
  127. Math.reserved_binary_string = "";
  128.  
  129. //Vectors 2d, 3d, 4d.
  130. //Vectors are simple list.They act as holders, example given : the position of a point in a grid.
  131. //Well used , they can speed up some processing in math.
  132. Math.vector2 = function(x,y)
  133.     if typeof(x) != "number" then return "error : vector2 -> x not a number.";
  134.     if typeof(y) != "number" then return "error : vector2 -> y not a number.";
  135.     return [x,y];
  136. end function
  137.  
  138. Math.vector3 = function(x,y,z)
  139.     if typeof(x) != "number" then return "error : vector3 -> x not a number.";
  140.     if typeof(y) != "number" then return "error : vector3 -> y not a number.";
  141.     if typeof(z) != "number" then return "error : vector3 -> z not a number.";
  142.     return [x,y,z];
  143. end function
  144.  
  145. Math.vector4 = function(x,y,z,w)
  146.     if typeof(x) != "number" then return "error : vector4 -> x not a number.";
  147.     if typeof(y) != "number" then return "error : vector4 -> y not a number.";
  148.     if typeof(z) != "number" then return "error : vector4 -> z not a number.";
  149.     if typeof(w) != "number" then return "error : vector4 -> w not a number.";
  150.     return [x,y,z,w];
  151. end function
  152.  
  153. //Decimal to hex converter.
  154. //The function convert a decimal value to a hex into a given string.Example Math.decimalToHex(10,"") , will return the hex value of 10.
  155. //Important: If you have a decimal string, remember that this function accept one decimal at the time.
  156. Math.decimalToHex = function(x,z)
  157.     if typeof(x) != "number" then return "error : decimal to hex -> x not number.";
  158.  
  159.     remainder = x% 16;
  160.     sum = x / 16;
  161.     hex = z;
  162.  
  163.     if remainder == 10 then remainder = "A";
  164.     if remainder == 11 then remainder = "B";
  165.     if remainder == 12 then remainder = "C";
  166.     if remainder == 13 then remainder = "D";
  167.     if remainder == 14 then remainder = "E";
  168.     if remainder == 15 then remainder = "F";
  169.  
  170.     hex = hex + str(remainder);
  171.     if str(sum).indexOf(char(46)) != null then
  172.         sum = str(sum).split(char(46))[0].to_int;
  173.     end if
  174.  
  175.     if sum > 0 then
  176.         Math.decimalToHex(sum,hex);
  177.     else
  178.         Math.reserved_hex_string = String.reverseString(hex);
  179.     end if
  180.     return Math.reserved_hex_string;
  181. end function
  182.  
  183. //Percent.
  184. //This function simply return a percentage.
  185. Math.percent = function(x,y)
  186.     if typeof(x) != "number" then return "error : pourcent -> x expected int.";
  187.     if typeof(x) != "number" then return "error : pourcent -> y expected int.";
  188.     percent = (x/y) * 100;
  189.     return percent;
  190. end function
  191.  
  192. //Median.
  193. //This function return the median element of a list.
  194. Math.median = function(x)
  195.     if typeof(x) != "list" then return "error : median -> x expected list.";
  196.     n = x.len;
  197.     median = x[(n + 1)/2];
  198.     return median;
  199. end function
  200.  
  201. //Average.
  202. //This function return the average of a series of integer in a list.
  203. Math.average = function(x)
  204.     if typeof(x) != "list" then return "error : average -> x list expected.";
  205.     sum = 0;
  206.     elements = 0;
  207.     for i in range(0,x.len -1)
  208.         if typeof(x[i]) != "number" then return "error :  average -> x[i] expected integer.";
  209.         sum = sum + x[i];
  210.         elements = elements + 1;
  211.     end for
  212.  
  213.     average = sum/elements;
  214.     return average;
  215. end function
  216.  
  217. //decimalToBinary
  218. //This function convert a decimal to binary then return the result.It use the divided by 2 method.
  219. Math.decimalToBinary = function(x,y)
  220.     if typeof(x) != "number" then return "error : decimal to binary -> x int expected.";
  221.  
  222.     remainder = x% 2;
  223.     sum = x / 2;
  224.     binary = y;
  225.  
  226.     binary = binary + str(remainder);
  227.     if str(sum).indexOf(char(46)) != null then
  228.         sum = str(sum).split(char(46))[0].to_int;
  229.     end if
  230.  
  231.     if sum == 1 or sum == 0 then
  232.         if sum == 0 then binary = binary + "0";
  233.         if sum == 1 then binary = binary + "1";
  234.         Math.reserved_binary_string = String.reverseString(binary).to_int;
  235.         return Math.reserved_binary_string;
  236.     else
  237.         //Here we put a special return cause its like that.No kidding, apparently
  238.         //is due because its a recursive function.As the modo on discord say.Permit
  239.         //me to doubt of it as decimal to hex function dont use it and return normaly.
  240.         //Dont remove that return or it will bug.
  241.         return Math.decimalToBinary(sum,binary);
  242.     end if
  243. end function
  244.  
  245. //Binary to decimal.
  246. Math.binaryToDecimal = function(x)
  247.     bin = str(x);
  248.     sum = 0;
  249.     for i in range(0,bin.len -1)
  250.         sum = (sum * 2) + bin[i].to_int;
  251.     end for
  252.     return sum;
  253. end function
  254.  
  255. //Graph header
  256. Graph = {};
  257. Graph.reserved_hex_tag = "";
  258. Graph.reserved_video_buffer = {"queud":[],"lastFrame":""};
  259. Graph.reserved_video_display = {"grid":[8,8],"content":[],"bg":"<mark=#000000>x</mark>","rate":0.6}; //default 8x8
  260. Graph.reserved_video_switch = true;
  261.  
  262. //RGB.
  263. //This function return the hex tag of the given rgb value, in a vector form.
  264. //Exemple Graph.rgb(Math.vector3(135,22,55)) , this return the color to in hex format.
  265. Graph.rgb = function(x)
  266.     if typeof(x) != "list" then return "error : rgb -> x expected list.";
  267.     if x.len != 3 then return "error : rgb -> x expected 3 len."
  268.     hexTag = "";
  269.     for i in range(0,x.len -1)
  270.         if typeof(x[i]) != "number" then return "error : rgb -> x[i] not a number"
  271.         hexTag = hexTag + Math.decimalToHex(x[i],"");
  272.     end for
  273.  
  274.     if hexTag.len < 6 then
  275.         hexTag = "#0" + hexTag;
  276.     else
  277.         hexTag = "#" + hexTag;
  278.     end if
  279.  
  280.     Graph.reserved_hex_tag = hexTag;
  281.     return Graph.reserved_hex_tag;
  282. end function
  283.  
  284. //Color.
  285. //This function return the given text enquote of <color=y> </color> tags, with the given hex colors.
  286. Graph.color = function(x,y)
  287.     color = "<color=" + y + ">" + x + "</color>";
  288.     return color;
  289. end function
  290.  
  291. //Size.
  292. //This function return the given text enquote of <size=y> </size> tags, with the given size.
  293. Graph.Size = function(x,y)
  294.     if typeof(y) != "number" then return "error : size y not a number.";
  295.     return "<size=" + y + ">" + x + "</size>";
  296. end function
  297.  
  298. //Italic.
  299. //This function return the given text enquote of <italic> </italic> tags.
  300. Graph.italic = function(x)
  301.     italic = "<i>" + x + "</i>";
  302.     return italic;
  303. end function
  304.  
  305. //Bold.
  306. //This function return the given text enquote of <bold> </bold>.
  307. Graph.bold = function(x)
  308.     bold = "<b>" + x + "</b>";
  309.     return bold;
  310. end function
  311.  
  312. //Underline.
  313. //This function return the text underlined.
  314. Graph.underline = function(x)
  315.     return "<u>" + x + "</u>";
  316. end function
  317.  
  318. //drawLine.
  319. //This function draw a line with the len according to the z value.
  320. Graph.drawLine = function(x,y)
  321.     if typeof(x) != "string" then return "error : draw line -> x expected string.";
  322.     if typeof(y) != "number" then return "error : draw line -> y expected int.";
  323.     for i in range(1,y)
  324.         x = x + char(95);
  325.     end for
  326.     return Graph.underline(x) ;
  327. end function
  328.  
  329. //align.
  330. //This function align the text according to the y value.left , right & center
  331. Graph.align = function(x,y)
  332.     if y != "center" and y != "right" and y != "left" then return "error : align -> y expected left,right or center.";
  333.     return "<align=" + y + ">" + x + "</align>";
  334. end function
  335.  
  336. //spacing.
  337. //This function space the text to the z value.
  338. //Example Graph.spacing("text","1em");
  339. Graph.spacing = function(x,y)
  340.     return "<cspace=" + y + ">" + x + "</cspace>";
  341. end function
  342.  
  343. //font.
  344. //This function will apply the given font to the given text.
  345. //Here some available font found:
  346. //SourceCodePro-Regular SDF
  347. //LiberationSans SDF
  348. Graph.font = function(x,y)
  349.     return "<font=" + y + ">" + x + "</font>";
  350. end function
  351.  
  352. //Indent.
  353. //This function return the text with indented.Y take the value as a pourcentage.
  354. Graph.indent = function(x,y)
  355.     return "<indent=" + y + ">" + x + "</indent>";
  356. end function
  357.  
  358. //Margin.
  359. //This function return the text with the value of z as margin.
  360. Graph.margin = function(x,y)
  361.     return "<margin=" + y + ">" + x + "</margin>";
  362. end function
  363.  
  364. //Mark.
  365. //This function return the text marked by the hex color of the z value.
  366. Graph.mark = function(x,y)
  367.     return "<mark=" + y + ">" + x + "</mark>";
  368. end function
  369.  
  370. //Sprite.
  371. //This function is mysterious return the sprite according the given id:int.
  372. //Atm only index 0 as be found.What a mystery.
  373. Graph.sprite = function(x)
  374.     return "<sprite=" + x + ">";
  375. end function
  376.  
  377. //Strike.
  378. //This function strike the text and return it.
  379. Graph.strike = function(x)
  380.     return "<s>" + x + "</s>";
  381. end function
  382.  
  383. //The video engine.
  384. //The function manipulate a grid with black pixel in it.When you turn on a pixel.Dont forget to turn it off, if you dont want it appear in the next frame.
  385. //Its the same for the grid dont forget to reinitialize the pixels example changing a scene.
  386.  
  387.  
  388. Graph.videoEngine = function(buf,dis)
  389.     clear_screen;
  390.     while (Graph.reserved_video_buffer.queud.len != 0)
  391.         if Graph.reserved_video_display.content.len == 0 then
  392.             yaxis = [];
  393.             for i in range(1,Graph.reserved_video_display.grid[0])
  394.                 xaxis = [];
  395.                 for e in range(1,Graph.reserved_video_display.grid[1])
  396.                     xaxis.push((Graph.reserved_video_display.bg));
  397.                 end for
  398.                 yaxis.push(xaxis);
  399.             end for
  400.             Graph.reserved_video_display.content = yaxis;
  401.         end if
  402.  
  403.         Graph.reserved_video_display.content[Graph.reserved_video_buffer.queud[0].position[0] -1][Graph.reserved_video_buffer.queud[0].position[1] -1] = Graph.reserved_video_buffer.queud[0].value;
  404.         frame = "";
  405.         for i in range(0,Graph.reserved_video_display.content.len -1)
  406.             for e in range(0,Graph.reserved_video_display.content[i].len -1)
  407.                 if Graph.reserved_video_display.content[i][e] == "" then Graph.reserved_video_display.content[i][e] = Graph.reserved_video_display.bg;
  408.             end for
  409.             frame = frame + char(10) + Graph.reserved_video_display.content[i].join("");
  410.         end for
  411.         if Graph.reserved_video_buffer.queud.len == 1 then
  412.             Graph.reserved_video_buffer.lastFrame = frame;
  413.             print(frame);
  414.             wait(Graph.reserved_video_display.rate);
  415.         end if
  416.         Graph.reserved_video_buffer.queud.remove(0);
  417.     end while
  418.     return;
  419. end function
  420.  
  421. //The animator play the given animation.
  422. Graph.animator = function(x)
  423.     for i in range(0,x.len -1)
  424.         Graph.reserved_video_buffer.queud.push(x[i]);
  425.     end for
  426.     return Graph.videoEngine(Graph.reserved_video_buffer,Graph.reserved_video_display);
  427. end function
  428.  
  429. //The animation part is the variable that store the data of the pixel in the grid.If the value of a
  430. //pixel "" then the pixel become a black pixel.
  431. Graph.animationPart = function(x,y)
  432.     if typeof(x) != "string" then return "error : animation part -> x expected string.";
  433.     if typeof(y) != "list" then return "error : animation part -> y expected number.";
  434.     animationString = {};
  435.     animationString.value = x;
  436.     animationString.position = y;
  437.     return animationString;
  438. end function
  439.  
  440. //display flush, reset all pixels in the grid.
  441. Graph.displayFlush = function()
  442.     Graph.reserved_video_display.content = [];
  443.     return;
  444. end function
  445.  
  446. //The function set the default grid color, named background.
  447. Graph.bgColor = function(x)
  448.     Graph.reserved_video_display.bg = "<mark=" + x + ">x</mark>";
  449.     return;
  450. end function
  451.  
  452. //display resolution change the size of the grid , by default its 8*8.
  453. Graph.displayResolution = function(x,y)
  454.     if typeof(x) != "number" then return "error : display resolution -> x expected number.";
  455.     if typeof(y) != "number" then return "error : display resolution -> y expected number.";
  456.     Graph.reserved_video_display.grid[0] = x;
  457.     Graph.reserved_video_display.grid[1] = y;
  458.     return;
  459. end function
  460.  
  461. //return the last frame processed.
  462. Graph.lastFrame = function()
  463.     return Graph.reserved_video_buffer.lastFrame;
  464. end function
  465.  
  466. //Set the wait rate , default 0.6.
  467. Graph.displayRate = function(x)
  468.     if typeof(x) != "number" then return "error : display rate -> x expected number.";
  469.     return Graph.reserved_video_display.rate(x);
  470. end function
  471.  
  472. //FileSystem header
  473.  
  474. FileSystem = {};
  475. FileSystem.reserved_stream = {"read":false,"write":false,"file":""};
  476.  
  477. FileSystem.stream = function(x,y)
  478.     if FileSystem.reserved_stream.read == false and FileSystem.reserved_stream.write == false then
  479.         if x == "out" then FileSystem.reserved_stream.write = true;
  480.         if x == "in" then FileSystem.reserved_stream.read = true;
  481.         if FileSystem.reserved_stream.read == false and FileSystem.reserved_stream.write == false then return "error : stream unknown type , available in or out.";
  482.         FileSystem.reserved_stream.file = get_shell.host_computer.File(y);
  483.         if typeof(FileSystem.reserved_stream.file) != "file" then
  484.             if y.indexOf(char(47)) == null then
  485.                 get_shell.host_computer.touch(current_path,y);
  486.             else
  487.                 directory = "/" + y.split(char(47))[1:y.split(char(47)).len - 1].join(char(47));
  488.                 filename = y.split(char(47))[y.split(char(47)).len - 1];
  489.                 get_shell.host_computer.touch(directory,filename);
  490.             end if
  491.             if typeof(get_shell.host_computer.File(y)) != "file" then return "error : stream file -> y was unable to create the file.";
  492.             if typeof(get_shell.host_computer.File(y)) == "file" then FileSystem.reserved_stream.file = get_shell.host_computer.File(y);
  493.         end if
  494.         return;
  495.     else
  496.         return "Buffer in use.";
  497.     end if
  498. end function
  499.  
  500. //Write.
  501. //This function is used to write on the current stream.By this mean a out stream should be opened.
  502. FileSystem.write = function(x)
  503.     if FileSystem.reserved_stream.write == true then
  504.         if typeof(FileSystem.reserved_stream.file) != "file" then return "error : write -> file not exist";
  505.         FileSystem.reserved_stream.file.set_content(x);
  506.         return;
  507.     else
  508.         return "Buffer currently closed.";
  509.     end if
  510. end function
  511.  
  512. //Read.
  513. //This function is used to read the content of a in stream.
  514. FileSystem.read = function()
  515.     if FileSystem.reserved_stream.read == true then
  516.         if typeof(FileSystem.reserved_stream.file) != "file" then return "error : write -> file not exist";
  517.         return FileSystem.reserved_stream.file.get_content;
  518.     else
  519.         return "Buffer currently closed.";
  520.     end if
  521. end function
  522.  
  523. //Flush.
  524. //This function close the stream.
  525. //Important: Only one stream can live at the time.
  526. FileSystem.flush = function()
  527.     FileSystem.reserved_stream.read = false;
  528.     FileSystem.reserved_stream.write = false;
  529.     FileSystem.reserved_stream.file = "";
  530. end function
  531.  
  532. //Meta header
  533.  
  534. Meta = {};
  535.  
  536. //Dump
  537. //This function scan the lib at the given addrs/port and return all the mems and cve into list.
  538. Meta.dump = function(x,y)
  539.     m = @Libs.metaxploit
  540.     if typeof(y) != "number" then return "error : dump -> y expected number.";
  541.     target = m.net_use(x,y);
  542.     if typeof(target) != "NetSession" then return "error : dump -> net session failed.";
  543.     if typeof(Libs.metaxploit) != "MetaxploitLib" then return "error : dump metaxploit not found in /lib";
  544.     target_lib = target.dump_lib;
  545.     target_scan = m.scan(target_lib);
  546.     target_exploits = [];
  547.     for i in range(0,target_scan.len -1)
  548.         target_exploits.push({"mem":target_scan[i],"cve":m.scan_address(target_lib,target_scan[i])});
  549.     end for
  550.     return target_exploits;
  551. end function
  552.  
  553. //Decrypt
  554. //This function try to decrypt a given user:pass hash format.Example Meta.decrypt("user:hash") , this will return the pass is it succeed.
  555. Meta.decrypt = function(x)
  556.     c = @Libs.crypto;
  557.     password = c.decipher(x.split(char(58))[1]);
  558.     return password;
  559. end function
  560.  
  561. //Net header
  562.  
  563. Net = {};
  564. Net.reserved_backsession = [];
  565.  
  566. //Scan wifi.
  567. //This function scan the wifi on the given interface and store in a list.
  568. Net.scan_wifi = function(x)
  569.     networks = get_shell.host_computer.wifi_networks(x);
  570.     return networks;
  571. end function
  572.  
  573. //Ack
  574. //This function capture packets of the given wifi.It take 3 arguments as a single string.Example Net.Ack("bssid,essid,maxAck").
  575. Net.ack = function(x)
  576.     c = @Libs.crypto;
  577.     bid = x.split(char(44))[0];
  578.     eid = x.split(char(44))[1];
  579.     ack = x.split(char(44))[2].to_int;
  580.     return c.aireplay(bid,eid,ack);
  581. end function
  582.  
  583. //Interface.
  584. //This function work the same as crypto.airmon, its theres for aestetic.
  585. Net.interface = function(x,y)
  586.     c = @Libs.crypto;
  587.     return c.airmon(x,y);
  588. end function
  589.  
  590. //NetConfig
  591. //This function return info in a list about the current network information.
  592. Net.netconfig = function()
  593.     config = [get_router.essid_name,get_router.bssid_name,get_shell.host_computer.network_gateway,get_shell.host_computer.local_ip,get_shell.host_computer.public_ip,whois(get_shell.host_computer.public_ip)];
  594.     return config;
  595. end function
  596.  
  597. //toNetStr.
  598. //This function is used to convert a single element of a list returned by scan_wifi.
  599. //You can always make it manualy.
  600. Net.toNetStr = function(x,y)
  601.     data = x.split(char(32));
  602.     if data.len != 3 then return "error : net to string -> x the string format is not recognized.";
  603.     bid = data[0];
  604.     eid = data[2];
  605.     ack = y;
  606.     netString = bid + "," + eid + "," + ack;
  607.     return netString;
  608. end function
  609.  
  610. //addSession.
  611. //This function allow you to background a network session.It store it in a list as a network object.
  612. //Note: The session set is design to let the user having multiple sessions from one point.Like this
  613. //You can free up space in coding using one main variable to create connection
  614. //.It is also useful to create dynamic connections bot etc.You can also used
  615. //Net.connect(ip,user,port,pass) like connect_service. Net.connect will do all the work for you, aswell
  616. //removing the initial var.The only thing need if Net.connect is used , is to catch the session
  617. //from the backsession function.By iterating trough the data of the elements you will find your
  618. //connection.
  619. Net.addSession = function(x)
  620.     if typeof(x) != "shell" then return "error : background session -> x shell expected.";
  621.     session = new {};
  622.     session.ip = x.host_computer.public_ip;
  623.     session.lan = x.host_computer.local_ip;
  624.     session.gateway = get_router(x.host_computer.public_ip).local_ip;
  625.     session.shell = x;
  626.     session.id = Net.reserved_backsession.len ;
  627.     Net.reserved_backsession.push(session);
  628.     return;
  629. end function
  630.  
  631. //closeSession.
  632. //This function allow you to close a background session.
  633. Net.closeSession = function(x)
  634.     if typeof(x) != "number" then return "error : close session -> x int expected.";
  635.     Net.reserved_backsession.remove(x);
  636.     return;
  637. end function
  638.  
  639. //backsession.
  640. //This function return all the backgroundSession list.
  641. Net.backsessions = function()
  642.     return Net.reserved_backsession;
  643. end function
  644.  
  645. //connect.
  646. //This function is used to connect to various service.The connection is stored in backsession and are accessible in backsession function.
  647. //Net.connect(ip,port,user,pass);
  648. //Note if the connection fail, it will not appear in the backgroundSession list as no connection occured.
  649. Net.connect = function(x,y,z,w)
  650.     if typeof(y) != "number" then return "error : connect -> y int expected";
  651.     Net.addSession(get_shell.connect_service(x,y,z,w));
  652.     return;
  653. end function
  654.  
  655. //Algo header
  656.  
  657. Algo = {};
  658.  
  659. //This function is used to swap to values in a list of size two.
  660. Algo.swap =  function(x)
  661.     if typeof(x) != "list" then return "error : swap -> x list expected.";
  662.     if x.len != 2 then return "error : swap -> x len 2 expected.";
  663.     a = x[0];
  664.     b = x[1];
  665.     x[0] = b;
  666.     x[1] = a;
  667.     return x;
  668. end function
  669.  
  670. //Compare.
  671. //The compare function is use to know if x > or < or == y.
  672. Algo.compare = function(x,y)
  673.     if x > y then return ">"; //62
  674.     if x < y then return "<"; //60
  675.     if x == y then return "=="; //61
  676. end function
  677.  
  678. //Max.
  679. //This function is used to know the max of two given values.
  680. Algo.max = function(x)
  681.     if typeof(x) != "list" then return "error : max -> x list expected."
  682.     if x.len != 2 then return "error : max -> x len 2 expected."
  683.     if typeof(x[0]) == "number" and typeof(x[1]) == "number" then
  684.         max = Algo.compare(x[0],x[1]);
  685.         if max == ">" or max == "==" then return x[0];
  686.         if max == "<" then return x[1];
  687.     else if typeof(x[0]) == "string" and typeof(x[1]) == "number" then
  688.         max = Algo.compare(code(x[0]),x[1]);
  689.         if max == ">" or max == "==" then return x[0];
  690.         if max == "<" then return x[1];
  691.     else if typeof(x[0]) == "number" and typeof(x[1]) == "string" then
  692.         max = Algo.compare(x[0],code(x[1]));
  693.         if max == ">" or max == "==" then return x[0];
  694.         if max == "<" then return x[1];
  695.     else if typeof(x[0]) == "string" and typeof(x[1]) == "string" then
  696.         max = Algo.compare(code(x[0]),code(x[1]));
  697.         if max == ">" or max == "==" then return x[0];
  698.         if max == "<" then return x[1];
  699.     end if
  700.     return;
  701. end function
  702.  
  703. //Min.
  704. //This function is used to know the min of two given valuess.
  705. Algo.min = function(x)
  706.     if typeof(x) != "list" then return "error : min -> x list expected.";
  707.     if x.len != 2 then return "error : min -> x len 2 expected.";
  708.     if typeof(x[0]) == "number" and typeof(x[1]) == "number" then
  709.         min = Algo.compare(x[0],x[1]);
  710.         if min == ">" or min == "==" then return x[1];
  711.         if min == "<" then return x[0];
  712.     else if typeof(x[0]) == "string" and typeof(x[1]) == "number" then
  713.         min = Algo.compare(code(x[0]),x[1]);
  714.         if min == ">" or min == "==" then return x[1];
  715.         if min == "<" then return x[0];
  716.     else if typeof(x[0]) == "number" and typeof(x[1]) == "string" then
  717.         min = Algo.compare(x[0],code(x[1]));
  718.         if min == ">" or min == "==" then return x[1];
  719.         if min == "<" then return x[0];
  720.     else if typeof(x[0]) == "string" and typeof(x[1]) == "string" then
  721.         min = Algo.compare(code(x[0]),code(x[1]));
  722.         if min == ">" or min == "==" then return x[1];
  723.         if min == "<" then return x[0];
  724.     end if
  725.     return;
  726. end function
  727.  
  728. //Permute.
  729. //This function is used to permute strings.
  730. Algo.permute = function(x,y);
  731.     if typeof(x) != "string" then return "error : permute -> x string expected.";
  732.     if typeof(y) != "list" then return "error : permute -> y list expected.";
  733.  
  734.     s0 = String.stringToList(x);
  735.     s1 = s0[0];
  736.     s2 = s0[1:s0.len].join("");
  737.  
  738.     swap = Algo.swap([s1,s2]).join("");
  739.     revs = String.reverseString(swap);
  740.  
  741.     y.push(swap);
  742.     y.push(revs);
  743.  
  744.     if y.indexOf(y[0],1) != null then return y[1:y.len -1];
  745.     if y.indexOf(y[0],1) == null then return Algo.permute(swap,y);
  746. end function
  747.  
  748. Encryption = {}
  749.  
  750. //Encryption and decrypt rot13.
  751. Encryption.rot13 = function(x)
  752.     chars = String.stringToList(x);
  753.     for i in range(0,chars.len -1)
  754.         if code(chars[i]) >= 65 and code(chars[i]) <= 90 then
  755.             chars[i] = char(65 + (code(chars[i]) - 65+13)%26);
  756.         else if code(chars[i]) >= 97 and code(chars[i]) <= 122 then
  757.             chars[i] = char(97 + (code(chars[i]) - 97+13)%26);
  758.         end if
  759.     end for
  760.     return chars.join("");
  761. end function
  762.  
  763. //Encryption and decrypt caesar.
  764. Encryption.caesar = function(x,y)
  765.     chars = String.stringToList(x);
  766.     for i in range(0,chars.len -1)
  767.         if code(chars[i]) >= 65 and code(chars[i]) <= 90 then
  768.             chars[i] = char(65 + (code(chars[i]) - 65+y)%26);
  769.         else if code(chars[i]) >= 97 and code(chars[i]) <= 122 then
  770.             chars[i] = char(97 + (code(chars[i]) - 97+y)%26);
  771.         end if
  772.     end for
  773.     return chars.join("");
  774. end function
  775.  
  776. //Encryption and decrypt byte swap.
  777. Encryption.byteSwap = function(x)
  778.     byteString = String.stringToDecimal(x);
  779.     bytes = [];
  780.  
  781.     byte = "";
  782.     for i in  range(0,byteString.len -1)
  783.         if byteString[i] == ":" then
  784.             bin = Math.decimalToBinary(byte.to_int,"");
  785.             bytes.push(bin);
  786.             byte = "";
  787.         else
  788.             byte = byte + byteString[i];
  789.             if i == byteString.len -1 then
  790.                 bin = Math.decimalToBinary(byte.to_int,"");
  791.                 bytes.push(bin);
  792.                 byte = "";
  793.             end if
  794.         end if
  795.     end for
  796.  
  797.     for i in range(0,bytes.len -1)
  798.         byte = str(bytes[i]);
  799.         if byte.len < 7 then
  800.             bytes[i] = "00" + str(byte);
  801.         else if byte.len == 7 then
  802.             bytes[i] = "0" + str(byte);
  803.         end if
  804.     end for
  805.  
  806.     for i in range(0,bytes.len -1)
  807.         bin = [];
  808.         set = "";
  809.         for e in range(0,str(bytes[i]).len -1)
  810.             set = set + str(bytes[i])[e];
  811.             if set.len == 2 then
  812.                 newByte = Algo.swap([set[0],set[1]]);
  813.                 newByte = newByte[0] + newByte[1];
  814.                 bin.push(newByte);
  815.                 set = "";
  816.             end if
  817.  
  818.             if e == str(bytes[i]).len -1 then
  819.                 bytes[i] = bin.join("");
  820.             end if
  821.         end for
  822.     end for
  823.  
  824.     decString = [];
  825.     for i in range(0,bytes.len -1)
  826.         decString.push(Math.binaryToDecimal(bytes[i]));
  827.     end for
  828.  
  829.     string = ""
  830.     for i in range(0,decString.len -1)
  831.         string = string + char(decString[i]);
  832.     end for
  833.  
  834.     return string;
  835. end function
  836.  
  837. //Args Libs
  838. Args = {};
  839.  
  840. //The args dictionnary function, return a map of the available
  841. //commands.The list is stored in '/usr/bin/mol/args.dict'.You
  842. //have to program yourself the creation of the folder and file.
  843. //This is the template of the return : [{"arg":"arg1","childs":1},...].
  844. Args.dictionnary = function(dictpath)
  845.   config = get_shell.host_computer.File(dictpath);
  846.   if typeof(config) != "file" then return "Could not read -> '" + dictpath + "' eval(file)";
  847.   if config.get_content.len < 1 then return false;
  848.  
  849.   //arg1-2 -> e.g "mycommand -args1 1 2"
  850.   data = config.get_content.split(";");
  851.   elements = [];
  852.  
  853.   for i in range(0,data.len -1)
  854.     argstring = data[i].split("-");
  855.     if argstring.len != 2 then return str("Could not parse -> " + argstring.join("") + " in eval(list)");
  856.     if typeof(argstring[1].to_int) != "number" then str("Could not parse -> " + argstring[1].join("") + " : eval(number)");
  857.     arg = "-" + argstring[0];
  858.     argchilds = argstring[1];
  859.     elements.push({"arg":arg,"childs":argchilds.to_int});
  860.   end for
  861.  
  862.   return elements;
  863. end function
  864.  
  865. //The eval function is use to evaluate if a parameter is
  866. //Invalid or not.It is designed to work with "args.parse()".
  867. //It use a cmap "command map".Look at args.parse to know more.
  868. Args.eval = function(cmap,dictpath)
  869.   isValid = false;
  870.   errors = [];
  871.   for i in range(0,cmap.len -1)
  872.     for e in range(0,Args.dictionnary(dictpath).len -1)
  873.       template = Args.dictionnary(dictpath)[e];
  874.       command = cmap[i];
  875.  
  876.       if template.arg == command.arg then
  877.         if template.childs == command.childs.len then
  878.           isValid = true;
  879.           break;
  880.         end if
  881.       end if
  882.  
  883.     end for
  884.  
  885.     if isValid == true then
  886.       isValid = false;
  887.     else
  888.       errors.push(str("args.eval(invalid parameter : + " + cmap[i].arg + ")"));
  889.     end if
  890.   end for
  891.   if errors.len > 0 then return errors;
  892.   if errors.len == 0 then return true;
  893. end function
  894.  
  895. //Arg.parse is use to parse param map and evaluate if the
  896. //command passed is good or not.If the command fail the evaluation
  897. //the function will return a errors list with each error leaving
  898. //your plenty power on the output.In the other side if the commands
  899. //pass the evaluation the function will return map with each parameter
  900. //and their option(child).Here the template of the map when it pass then
  901. //evaluation : [{"arg":"arg1","child":["1","2"]}].
  902. Args.parse = function(command,dictpath)
  903.   cmap = [];
  904.  
  905.   //building the received line into a index map.
  906.   command = command.split(" ");
  907.   for i in range(0,command.len -1)
  908.     if command[i][0] == "-" then
  909.       map = {"arg":command[i],"childs":[]};
  910.       for e in range(i,command.len -1)
  911.         if e != i then
  912.           if command[e][0] == "-" then break;
  913.           map.childs.push(command[e]);
  914.         end if
  915.       end for
  916.       cmap.push(map);
  917.     end if
  918.   end for
  919.  
  920.   //looking if theres error in the command line received by using
  921.   //a dictionnary of templates.
  922.   evaluation = Args.eval(cmap,dictpath);
  923.     if cmap.len == 0 then return "unrecognize input.";
  924.   if evaluation == true then return cmap;
  925.   return evaluation;
  926. end function
  927.  
  928. //Language header.
  929. Language = {};
  930. Language.localization = function(locapath)
  931.     config = get_shell.host_computer.File(locapath);
  932.     if typeof(config) != "file" then return "Could not read '" + locapath + "' eval(file)";
  933.     if config.get_content.len < 0 then return false;
  934.  
  935.     //Getting the localizators - example of a peace of file format.
  936.     //spanish;french;english;myowninvented
  937.     //juego;jeu;game;engio
  938.     //krita;kri;krite;fwer
  939.  
  940.     data = config.get_content.split(char(10));
  941.     localizators = data[0].split(";");
  942.     if localizators.len < 1 then return false;
  943.  
  944.     dict = [];
  945.  
  946.     for i in range(1,data.len -1)
  947.         //get the variant string - 'juego;jeu;game;engio'
  948.         variant_string = data[i].split(";");
  949.         if data[i].len < 1 then return false;
  950.  
  951.         //if the variant string contain only the tag
  952.         //then add undefined value for each localizators
  953.         if data[i].len == 1 then
  954.             for e in range(0,localizators.len -1)
  955.                 variant_string.push("undefined");
  956.             end for
  957.         end if
  958.  
  959.         //assemble the dictionnary
  960.         map = {"word":variant_string[0],"dict":[]};
  961.  
  962.         for e in range(0,variant_string.len -1)
  963.                 if e > localizators.len then return "Cannot parse -> '" + dictpath + "' eval(file)";
  964.                 map.dict.push({localizators[e]:variant_string[e]});
  965.         end for
  966.  
  967.         dict.push(map);
  968.     end for
  969.  
  970.     return dict;
  971. end function
  972.  
  973. Language.trad = function(wor,lan,dic)
  974.     for i in range(0,dic.len -1)
  975.         if dic[i].word == wor then
  976.             for e in range(0,dic[i].dict.len -1)
  977.                 map = dic[i].dict[e];
  978.                 if map.hasIndex(lan) == true then
  979.                     return map[lan];
  980.                 end if
  981.             end for
  982.         end if
  983.     end for
  984.     return "undefined.";
  985. end function
Add Comment
Please, Sign In to add comment