Janilabo

Simba Script Scanner v1.56

Jun 11th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 43.94 KB | None | 0 0
  1. {=======================================================================================]
  2. |                                                                                       |
  3. |   _____ _       _          _____         _     _      _____                           |
  4. |  |   __|_|_____| |_ ___   |   __|___ ___|_|___| |_   |   __|___ ___ ___ ___ ___ ___   |
  5. |  |__   | |     | . | .'|  |__   |  _|  _| | . |  _|  |__   |  _| .'|   |   | -_|  _|  |
  6. |  |_____|_|_|_|_|___|__,|  |_____|___|_| |_|  _|_|    |_____|___|__,|_|_|_|_|___|_|    |
  7. |                                           |_|                                         |
  8. |                                                                                       |
  9. [=======================================================================================}
  10.  
  11. const
  12.   VERSION = 1.56; // Don't touch... Script version.
  13.   HTTP_SCAN = True; // Scan for HTTP Threats?
  14.   WEB_SCAN = True; // Scan for Web Threats?
  15.   CODE_SCAN = True; // Scan for Fishy Code and Unhuman/Abnormal Code?
  16.   FILTER_COMMENTS = True; // Doesn't pay attention to stuff inside comments
  17.                           // Recommended to keep this feature enabled, a lot less false positives!
  18.   COMMENT_FILTER = '@'; // CHAR, NOT STRING! Used in debug box for displaying the filtered comments (doesn't effect scan, as these will be empty chars in filteredScriptText for scan).
  19.   FILTER_STRINGS = True; // Doesn't pay attention to stuff INSIDE string signs.
  20.                          // So, this feature still detects stuff that falls outside those '' signs! :)
  21.   STRING_FILTER = '%'; // CHAR, NOT STRING! Used in debug box for displaying the filtered strings (doesn't effect scan, these will be empty chars in filteredScriptText for scan).
  22.   DEBUG_FILTERED_SCRIPT = True; // Debug the script, that was filtered (used for most script parts), before scan statistics (displays empty chars with COMMENT_FILTER & STRING_FILTER).
  23.   DEFAULT = 'Times New Roman';
  24.  
  25. type
  26.   TMatchMethod = (mmAll, mmIgnoreCase, mmOverlap, mmWholeWords, mmStrictWW, mmGreedyRegex);
  27.   TMatchMethods = set of TMatchMethod;
  28.   TRegexMatch = record
  29.     position, size: Integer;
  30.     text: string;
  31.   end;
  32.   TRegexMatchArray = array of TRegexMatch;
  33.   T2DRegexMatchArray = array of TRegexMatchArray;
  34.   TRange = record
  35.     minimum, maximum: Integer;
  36.   end;
  37.   TRangeArray = array of TRange;
  38.   TThreat = record
  39.     line: Integer;
  40.     threat: string;
  41.     kind: (tk_HTTP, tk_Web, tk_Fishy, tk_Bad);
  42.   end;
  43.   TThreatArray = array of TThreat;
  44.  
  45. var
  46.   DsgnForm: TForm;
  47.   ScriptEdit: TMemo;
  48.   TitleLabel: TLabel;
  49.   ScanButton, UpdateButton: TButton;
  50.   originalScriptText, filteredScriptText, displayScriptText: string;
  51.   HTTPThreats, WebThreats, BadCode, threats, FishyCode, scanTimer, currentStep, totalSteps: Integer;
  52.   msgHTTP, msgWeb, msgBad, msgFishy, steps: string;
  53.   pressed: Boolean;
  54.   _threats: TThreatArray;
  55.   linePositions: TIntegerArray;
  56.  
  57. (*
  58.   Auther: Officer Barbrady
  59. *)
  60. procedure PrintReport;
  61. var
  62.   Points: Integer;
  63.   h, i: Integer;
  64.   li, th, kd: string;
  65. begin
  66.   WriteLn('*************************************************');
  67.   WriteLn('*        _  _  _       _  _  _  _  _ __         *');
  68.   WriteLn('*       /_`/ `/_//|/  /_//_`/_// //_//          *');
  69.   WriteLn('*      ._//_,/ // |  / \/_,/  /_// \/           *');
  70.   WriteLn('*                                               *');
  71.   WriteLn('*************************************************');
  72.   WriteLn('                                                 ');
  73.   if DEBUG_FILTERED_SCRIPT then
  74.   begin
  75.     WriteLn('=================Filtered Script=================');
  76.     if (displayScriptText <> '') then
  77.       WriteLn(displayScriptText);
  78.     WriteLn('=================================================');
  79.     WriteLn('                                                 ');
  80.   end;
  81.   if (steps <> '') then
  82.   begin
  83.     WriteLn('===================Scan Steps====================');
  84.     WriteLn(steps);
  85.     WriteLn('=================================================');
  86.     WriteLn('                                                 ');
  87.   end;
  88.   if HTTP_SCAN then
  89.   begin
  90.     WriteLn('============Messages for HTTP Threats============');
  91.     if (msgHTTP <> '') then
  92.       WriteLn(msgHTTP);
  93.     WriteLn('=================================================');
  94.     WriteLn('                                                 ');
  95.   end;
  96.   if WEB_SCAN then
  97.   begin
  98.     WriteLn('=============Messages for Web Threats============');
  99.     if (msgWeb <> '') then
  100.       WriteLn(msgWeb);
  101.     WriteLn('=================================================');
  102.     WriteLn('                                                 ');
  103.   end;
  104.   if CODE_SCAN then
  105.   begin
  106.     WriteLn('=============Messages for Fishy Code=============');
  107.     if (msgFishy <> '') then
  108.       WriteLn(msgFishy);
  109.     WriteLn('=================================================');
  110.     WriteLn('                                                 ');
  111.     WriteLn('==============Messages for Bad Code==============');
  112.     if (msgBad <> '') then
  113.       WriteLn(msgBad);
  114.     WriteLn('=================================================');
  115.     WriteLn('                                                 ');
  116.   end;
  117.   h := High(_threats);
  118.   if (h > -1) then
  119.   begin
  120.     WriteLn('===============Lines with Threats================');
  121.     WriteLn(' LINE |      KIND      |        THREAT         ');
  122.     WriteLn('-------------------------------------------------');
  123.     for i := 0 to h do
  124.     begin
  125.       li := IntToStr(_threats[i].line);
  126.       case _threats[i].kind of
  127.         tk_Bad: kd := 'Bad Code';
  128.         tk_Fishy: kd := 'Fishy Code';
  129.         tk_HTTP: kd := 'HTTP Threat';
  130.         tk_Web: kd := 'Web Threat';
  131.       end;
  132.       th := _threats[i].threat;
  133.       WriteLn(' ' + (li + Padr(' ', (Length(' LINE |') - Length(li)) - 2)) + '| ' + (kd + Padr(' ', (Length('      KIND      |') - Length(kd)) - 2)) + '| ' + th);
  134.     end;
  135.   end;
  136.   Points := (HTTPthreats + WebThreats + BadCode + FishyCode);
  137.   WriteLn('=================================================');
  138.   WriteLn('                                                 ');
  139.   WriteLn('==================Scan Results===================');
  140.   WriteLn(' HTTP threats: ' + ToStr(HTTPThreats));
  141.   WriteLn(' Web threats: ' + ToStr(WebThreats));
  142.   WriteLn(' Fishy code: ' + ToStr(FishyCode));
  143.   WriteLn(' Bad code: ' + ToStr(BadCode));
  144.   WriteLn(' Overall threats: ' + ToStr(Points))
  145.   case threats of
  146.     0:    WriteLn(' Script Risk Level: None');
  147.     1..2: WriteLn(' Script Risk Level: Low');
  148.     3:    WriteLn(' Script Risk Level: Medium');
  149.     4..8: WriteLn(' Script Risk Level: High');
  150.   end;
  151.   WriteLn('=================================================');
  152.   WriteLn('                                                 ');
  153.   WriteLn('=====================FINISHED====================');
  154.   WriteLn(' Remember to visit the thread for latest updates.');
  155.   WriteLn('               Thank you for using!              ');
  156.   WriteLn('=================================================');
  157. end;
  158.  
  159. procedure NewThreat(var TTA: TThreatArray; line: Integer; threat: string; kind: (tk_HTTP, tk_Web, tk_Fishy, tk_Bad));
  160. var
  161.   index, i, l: Integer;
  162. begin
  163.   l := Length(TTA);
  164.   while (index < l) do
  165.   begin
  166.     if (line < TTA[index].line) then
  167.       Break;
  168.     Inc(index);
  169.   end;
  170.   SetLength(TTA, (l + 1));
  171.   if (l > index) then
  172.     for i := (l - 1) downto index do
  173.       TTA[(i + 1)] := TTA[i];
  174.   TTA[index].line := line;
  175.   TTA[index].threat := threat;
  176.   TTA[index].kind := kind;
  177. end;
  178.  
  179. procedure TIAInsert(var TIA: TIntegerArray; index: Integer; int: Integer);
  180. var
  181.   i, l: Integer;
  182. begin
  183.   l := Length(TIA);
  184.   SetLength(TIA, (l + 1));
  185.   if (index < 0) then
  186.     index := 0;
  187.   if (index > l) then
  188.     index := l;
  189.   if (l > index) then
  190.     for i := (l - 1) downto index do
  191.       TIA[(i + 1)] := Integer(TIA[i]);
  192.   TIA[index] := Integer(int);
  193. end;
  194.  
  195. {==============================================================================]
  196.   Explanation: Returns string of all TSA items binded together. Places glue between the indexes.
  197. [==============================================================================}
  198. function TSAConcatEx(TSA: TStringArray; glue: string): string;
  199. var
  200.   h, i: Integer;
  201. begin
  202.   Result := '';
  203.   h := High(TSA);
  204.   if (h > -1) then
  205.   begin
  206.     for i := 0 to (h - 1) do
  207.       Result := (Result + string(TSA[i]) + string(glue));
  208.     Result := (Result + string(TSA[i]));
  209.   end;
  210. end;
  211.  
  212. {==============================================================================]
  213.   Explanation: Explodes str with multiple separators/delimiters (d).
  214.                The importance order for d items is from left to right (=>).
  215.                So place the important ones first and then less important after those.
  216. [==============================================================================}
  217. function ExplodeMulti(d: TStringArray; str: string): TStringArray;
  218. var
  219.   p, h, i, x, o, m, l, y, z: Integer;
  220. begin
  221.   h := High(d);
  222.   if ((h > -1) and (str <> '')) then
  223.   begin
  224.     o := 1;
  225.     SetLength(Result, Length(str));
  226.     repeat
  227.       l := 0;
  228.       for x := 0 to h do
  229.       begin
  230.         p := Pos(d[x], str);
  231.         case (p < 1) of
  232.           True:
  233.           begin
  234.             z := High(d);
  235.             if ((x <= z) and (x > -1)) then
  236.             begin
  237.               for y := x to (z - 1) do
  238.                 d[y] := d[(y + 1)];
  239.               SetLength(d, z);
  240.             end;
  241.             Dec(x);
  242.             Dec(h);
  243.           end;
  244.           False:
  245.           if ((l = 0) or (p < l)) then
  246.           begin
  247.             m := x;
  248.             l := p;
  249.           end;
  250.         end;
  251.       end;
  252.       if (l > 0) then
  253.       begin
  254.         Result[i] := Copy(str, 1, (l - 1));
  255.         Delete(str, 1, ((l + Length(d[m])) - 1));
  256.         Inc(i);
  257.       end else
  258.         Result[i] := Copy(str, 1, Length(str));
  259.     until (l = 0);
  260.     SetLength(Result, (i + 1));
  261.   end else
  262.     Result := [string(str)];
  263. end;
  264.  
  265. {==============================================================================]
  266.   Explanation: Finds position from s items in str. Stores the ID of the found s item to index variable.
  267.                The importance order for d items is from left to right (=>).
  268.                So place the important ones first and then less important after those.
  269.                Contains field for offset.
  270. [==============================================================================}
  271. function PosMultiIDEx(s: TStringArray; str: string; var index: Integer; offset: Integer): Integer;
  272. var
  273.   h, i, p, t: Integer;
  274. begin
  275.   if (offset < 1) then
  276.     offset := 1;
  277.   Result := -1;
  278.   index := -1;
  279.   h := High(s);
  280.   if ((h > -1) and (str <> '')) then
  281.   begin
  282.     t := (Length(str) + 1);
  283.     Result := t;
  284.     for i := 0 to h do
  285.     begin
  286.       p := PosEx(s[i], str, offset);
  287.       if ((p > 0) and (p < Result)) then
  288.       begin
  289.         Result := p;
  290.         index := i;
  291.       end;
  292.     end;
  293.     if (Result = t) then
  294.       Result := 0;
  295.   end;
  296. end;
  297.  
  298. function PosAll(s, str: string): TIntegerArray;
  299. var
  300.   sL, strL, o, p, r: Integer;
  301. begin
  302.   sL := Length(s);
  303.   strL := Length(str);
  304.   if (sL <= strL) then
  305.   begin
  306.     SetLength(Result, strL);
  307.     repeat
  308.       p := PosEx(s, str, (o + 1));
  309.       if (p > 0) then
  310.       begin
  311.         Result[r] := p;
  312.         o := p;
  313.         Inc(r);
  314.       end;
  315.     until (p <= 0);
  316.   end;
  317.   SetLength(Result, r);
  318. end;
  319.  
  320. function ToRange(minimum, maximum: Integer): TRange;
  321. begin
  322.   Result.minimum := Integer(minimum);
  323.   Result.maximum := Integer(maximum);
  324. end;
  325.  
  326. procedure TRAAppend(var TRA: TRangeArray; x: TRange);
  327. var
  328.   aL: Integer;
  329. begin
  330.   aL := (Length(TRA) + 1);
  331.   SetLength(TRA, aL);
  332.   TRA[(aL - 1)] := TRange(x);
  333. end;
  334.  
  335. function TrackCaS(str: string; var comments, strings: TRangeArray): Boolean;
  336. var
  337.   s, i, o, e, x, l, a, ls: Integer;
  338.   t: TStringArray;
  339. begin
  340.   Result := False;
  341.   SetLength(comments, 0);
  342.   SetLength(strings, 0);
  343.   l := Length(str);
  344.   ls := -1;
  345.   if (l > 0) then
  346.   begin
  347.     o := 1;
  348.     t := ['//', '(*', '{', ''''];
  349.     repeat
  350.       s := PosMultiIDEx(t, str, i, o);
  351.       case (s <= ls) of
  352.         True: Exit;
  353.         False: ls := s;
  354.       end;
  355.       if (s > 0) then
  356.       begin
  357.         o := (s + 1);
  358.         a := 0;
  359.         case i of
  360.           0, 1, 2:
  361.           begin
  362.             case i of
  363.               0:
  364.               begin
  365.                 e := PosMultiIDEx([#13#10, #13, #10], str, x, o);
  366.                 if (x = 0) then
  367.                   a := 1;
  368.                 if (e = 0) then
  369.                   e := l;
  370.                 TRAAppend(comments, ToRange(s, e));
  371.               end;
  372.               1, 2:
  373.               begin
  374.                 case i of
  375.                   1:
  376.                   begin
  377.                     e := PosEx('*)', str, o);
  378.                     a := 1;
  379.                   end;
  380.                   2: e := PosEx('}', str, o);
  381.                 end;
  382.                 if (e = 0) then
  383.                   e := l;
  384.                 TRAAppend(comments, ToRange(s, (e + a)));
  385.               end;
  386.             end;
  387.           end;
  388.           3:
  389.           begin
  390.             e := PosMultiIDEx([#13#10, #13, #10, ''''], str, x, o);
  391.             if (x = 0) then
  392.               a := 1;
  393.             case (e = 0) of
  394.               True:
  395.               begin
  396.                 e := l;
  397.                 TRAAppend(strings, ToRange(s, e));
  398.               end;
  399.               False:
  400.               case x of
  401.                 0, 1, 2: TRAAppend(strings, ToRange(s, e));
  402.                 3: TRAAppend(strings, ToRange(s, (e + a)));
  403.               end;
  404.             end;
  405.           end;
  406.         end;
  407.         o := ((e + 1) + a);
  408.       end;
  409.     until ((s = 0) or (x = -1) or (o > l));
  410.   end;
  411. end;
  412.  
  413. {==============================================================================]
  414.   Explanation: Trims all TSA items.
  415. [==============================================================================}
  416. procedure TSATrim(var TSA: TStringArray);
  417. var
  418.   h, i: Integer;
  419. begin
  420.   h := High(TSA);
  421.   for i := 0 to h do
  422.     TSA[i] := Trim(TSA[i]);
  423. end;
  424.  
  425. {==============================================================================]
  426.   Explanation: Returns all the positions by items from s array in str. Place s items in importance order (=>)
  427.                If overlap is set to true, strings can overlap.
  428.                (['aa'], 'baaaah', False) => [2,3,4]
  429.                (['aa'], 'baaaah', True) => [2,4]
  430. [==============================================================================}
  431. function PosAllMulti(s: TStringArray; str: string; overlap: Boolean): TIntegerArray;
  432. var
  433.   h, l, p, o, x, i, t, r, y, d: Integer;
  434. begin
  435.   h := High(s);
  436.   y := Length(str);
  437.   if ((y > 0) and (h > -1)) then
  438.   begin
  439.     SetLength(Result, y);
  440.     o := 1;
  441.     repeat
  442.       p := 0;
  443.       for x := 0 to h do
  444.       begin
  445.         t := PosEx(s[x], str, (l + o));
  446.         case (t < 1) of
  447.           True:
  448.           begin
  449.             for d := x to (h - 1) do
  450.               s[d] := s[(d + 1)];
  451.             SetLength(s, h);
  452.             Dec(x);
  453.             Dec(h);
  454.           end;
  455.           False:
  456.           if ((p = 0) or (t < p)) then
  457.           begin
  458.             p := t;
  459.             i := x;
  460.           end;
  461.         end;
  462.       end;
  463.       if (p > 0) then
  464.       begin
  465.         Result[r] := p;
  466.         Inc(r);
  467.         l := p;
  468.         if not overlap then
  469.           o := Length(s[i]);
  470.       end;
  471.     until (p <= 0);
  472.   end;
  473.   SetLength(Result, r);
  474. end;
  475.  
  476. procedure FillStrRangeEx(var str: string; fillWith: Char; range: TRange; exceptions: TIntegerArray);
  477. var
  478.   i, l, c: Integer;
  479. begin
  480.   l := Length(str);
  481.   if ((l > 0) and not (range.minimum > range.maximum)) then
  482.   begin
  483.     if (range.minimum < 1) then
  484.       range.minimum := 1;
  485.     if (range.maximum > l) then
  486.       range.maximum := l;
  487.     if (range.minimum > l) then
  488.       Exit;
  489.     c := iAbs(range.maximum - range.minimum);
  490.     for i := range.minimum to range.maximum do
  491.       if not InIntArray(exceptions, i) then
  492.         str[i] := fillWith;
  493.   end;
  494. end;
  495.  
  496. function FilterScriptData(data: string): string;
  497. var
  498.   h, i, l: Integer;
  499.   newLines: TIntegerArray;
  500.   comments, strings: TRangeArray;
  501.   tmp: TStringArray;
  502. begin
  503.   Result := string(data);
  504.   displayScriptText := string(Result);
  505.   l := Length(Result);
  506.   if (Result <> '') then
  507.   begin
  508.     if (FILTER_STRINGS or FILTER_COMMENTS) then
  509.     begin
  510.       newLines := PosAllMulti([#13, #10], Result, False);
  511.       TrackCaS(data, comments, strings);
  512.       h := High(comments);
  513.       if FILTER_COMMENTS then
  514.       for i := 0 to h do
  515.       begin
  516.         FillStrRangeEx(Result, '!', comments[i], newLines);
  517.         FillStrRangeEx(displayScriptText, COMMENT_FILTER, comments[i], newLines);
  518.       end;
  519.       h := High(strings);
  520.       if FILTER_COMMENTS then
  521.       for i := 0 to h do
  522.       begin
  523.         FillStrRangeEx(Result, '!', strings[i], newLines);
  524.         FillStrRangeEx(displayScriptText, STRING_FILTER, strings[i], newLines);
  525.       end;
  526.       SetLength(newLines, 0);
  527.       SetLength(comments, 0);
  528.       SetLength(strings, 0);
  529.       Result := ReplaceWrap(Result, '!', '', [rfReplaceAll]);
  530.     end;
  531.     tmp := ExplodeMulti([#13#10, #13, #10], Result);
  532.     TSATrim(tmp);
  533.     Result := TSAConcatEx(tmp, #13#10);
  534.     SetLength(tmp, 0);
  535.   end;
  536. end;
  537.  
  538. {==============================================================================]
  539.   Explanation: Returns all the positions of found/matching strings (findStr) in text.
  540.                Uses a set of TMatchMethod (methods) for string matching.
  541.                Contains field for offset.
  542.                If regex field is set as true, then this function searches for the regex you use.
  543. [==============================================================================}
  544. function FindEx(text, findStr: string; methods: TMatchMethods; offset: Integer; regex: Boolean): TIntegerArray;
  545. var
  546.   rmArr: TRegexMatchArray;
  547.   rmArr2D: T2DRegexMatchArray;
  548.   sb, sa: string;
  549.   r, i, l, f, p, d, o, x, y, abL, abR, abX, abP, spA, spB, spH, spL, spI, spR, spD: Integer;
  550.   re: TRegExp;
  551.   ma, mb, a, s, ol: Boolean;
  552.   c: TIntegerArray;
  553.   t: T2DIntegerArray;
  554. begin
  555.   l := Length(text);
  556.   f := Length(findStr);
  557.   if ((l > 0) and (f > 0) and (offset <= l)) then
  558.   begin
  559.     if (offset < 1) then
  560.       offset := 1;
  561.     if not regex then
  562.     begin
  563.       for i := f downto 1 do
  564.         if (Pos(findStr[i], '.\+*?[^]$(){}=!<>|:-') > 0) then
  565.           Insert('\', findStr, i);
  566.       SetLength(Result, l);
  567.       re := TRegExp.Create;
  568.       re.InputString := text;
  569.       re.Expression := findStr;
  570.       if (mmIgnoreCase in methods) then
  571.         re.ModifierI := True;
  572.       re.ModifierM := True;
  573.       a := (mmAll in methods);
  574.       re.ModifierG := (mmGreedyRegex in methods);
  575.       ol := (mmOverlap in methods);
  576.       if not ol then
  577.         o := (Length(findStr) - 1);
  578.       Inc(o);
  579.       p := offset;
  580.       while re.ExecPos(p) do
  581.       begin
  582.         Result[r] := re.MatchPos[0];
  583.         p := (Result[r] + o);
  584.         Inc(r);
  585.       end;
  586.       p := Offset;
  587.       re.Free;
  588.       SetLength(Result, r);
  589.       if ((r > 0) and (mmWholeWords in methods)) then
  590.       begin
  591.         s := (mmStrictWW in methods);
  592.         if not s then
  593.           c := [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, // A-Z
  594.                 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, // a-z
  595.                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]; // 0-9
  596.         case ol of
  597.           True:
  598.           begin
  599.             spH := High(Result);
  600.             if (spH > -1) then
  601.             begin
  602.               SetLength(t, (spH + 1));
  603.               t[0] := [Integer(Result[0])];
  604.               if (spH > 0) then
  605.               begin
  606.                 spR := 1;
  607.                 for spI := 1 to spH do
  608.                 begin
  609.                   for spA := 0 to (spR - 1) do
  610.                   begin
  611.                     spL := Length(t[spA]);
  612.                     for spB := 0 to (spL - 1) do
  613.                     begin
  614.                       spD := IAbs(Result[spI] - t[spA][spB]);
  615.                       if (spD <= f) then
  616.                       begin
  617.                         SetLength(t[spA], (spL + 1));
  618.                         t[spA][spL] := Integer(Result[spI]);
  619.                         Break;
  620.                       end;
  621.                     end;
  622.                     if (spB < spL) then
  623.                       Break;
  624.                   end;
  625.                   if (spA >= spR) then
  626.                   begin
  627.                     t[spR] := [Integer(Result[spI])];
  628.                     Inc(spR);
  629.                   end;
  630.                 end;
  631.               end;
  632.               SetLength(t, spR);
  633.               spH := High(t);
  634.               for spI := spH downto 0 do
  635.               begin
  636.                 spB := Low(t[spI]);
  637.                 spA := High(t[spI]);
  638.                 abX := 1;
  639.                 abP := t[spI][spB];
  640.                 abL := Length(text);
  641.                 case ((abL > 0) and (abP > 1)) of
  642.                   True:
  643.                   begin
  644.                     if ((abP - abX) < 1) then
  645.                       abX := ((abP - abX) + (abX - 1));
  646.                     if (abP > (abL + 1)) then
  647.                     begin
  648.                       abR := ((abP - abL) - 1);
  649.                       abX := (abX - abR);
  650.                     end;
  651.                     sb := Copy(text, ((abP - abX) - abR), abX);
  652.                   end;
  653.                   False: sb := '';
  654.                 end;
  655.                 abX := 1;
  656.                 abP := (t[spI][spA] + f);
  657.                 abL := Length(text);
  658.                 case ((abL > 0) and (abP <= abL)) of
  659.                   True:
  660.                   begin
  661.                     if (abP < 1) then
  662.                     begin
  663.                       abX := (abX - iAbs(abP - 1));
  664.                       abP := 1;
  665.                     end;
  666.                     if ((abX > 0) and ((abP + abX) > abL)) then
  667.                       abX := (abX - (((abP + abX) - abL) - 1));
  668.                     sa := Copy(text, abP, abX);
  669.                   end;
  670.                   False: sa := '';
  671.                 end;
  672.                 case s of
  673.                   True:
  674.                   begin
  675.                     mb := ((sb = '') or (sb = ' ') or (sb = #13#10) or (sb = #13) or (sb = #10));
  676.                     ma := ((sa = '') or (sa = ' ') or (sa = #13#10) or (sa = #13) or (sa = #10));
  677.                   end;
  678.                   False:
  679.                   begin
  680.                     mb := ((sb = '') or not InIntArray(c, Ord(sb[1])));
  681.                     ma := ((sa = '') or not InIntArray(c, Ord(sa[1])));
  682.                   end;
  683.                 end;
  684.                 if not (mb and ma) then
  685.                 begin
  686.                   for spD := spI to (spH - 1) do
  687.                     t[spD] := t[(spD + 1)];
  688.                   SetLength(t, spH);
  689.                   Dec(spH);
  690.                 end;
  691.               end;
  692.               spH := High(t);
  693.               if (spH > -1) then
  694.               begin
  695.                 for spI := 0 to spH do
  696.                   IncEx(spR, (High(t[spI]) + 1));
  697.                 SetLength(Result, spR);
  698.                 spR := 0;
  699.                 for spI := 0 to spH do
  700.                 begin
  701.                   spL := High(t[spI]);
  702.                   for spA := 0 to spL do
  703.                   begin
  704.                     Result[spR] := Integer(t[spI][spA]);
  705.                     Inc(spR);
  706.                   end;
  707.                 end;
  708.                 SetLength(Result, spR);
  709.               end else
  710.                 SetLength(Result, 0);
  711.             end else
  712.               r := 0;
  713.           end;
  714.           False:
  715.           begin
  716.             for x := (r - 1) downto 0 do
  717.             begin
  718.               abX := 1;
  719.               abP := Result[x];
  720.               abL := Length(text);
  721.               case ((abL > 0) and (abP > 1)) of
  722.                 True:
  723.                 begin
  724.                   if ((abP - abX) < 1) then
  725.                     abX := ((abP - abX) + (abX - 1));
  726.                   if (abP > (abL + 1)) then
  727.                   begin
  728.                     abR := ((abP - abL) - 1);
  729.                     abX := (abX - abR);
  730.                   end;
  731.                   sb := Copy(text, ((abP - abX) - abR), abX);
  732.                 end;
  733.                 False: sb := '';
  734.               end;
  735.               abX := 1;
  736.               abP := (Result[x] + f);
  737.               abL := Length(text);
  738.               case ((abL > 0) and (abP <= abL)) of
  739.                 True:
  740.                 begin
  741.                   if (abP < 1) then
  742.                   begin
  743.                     abX := (abX - iAbs(abP - 1));
  744.                     abP := 1;
  745.                   end;
  746.                   if ((abX > 0) and ((abP + abX) > abL)) then
  747.                     abX := (abX - (((abP + abX) - abL) - 1));
  748.                   sa := Copy(text, abP, abX);
  749.                 end;
  750.                 False: sa := '';
  751.               end;
  752.               case s of
  753.                 True:
  754.                 begin
  755.                   mb := ((sb = '') or (sb = ' ') or (sb = #13#10) or (sb = #13) or (sb = #10));
  756.                   ma := ((sa = '') or (sa = ' ') or (sa = #13#10) or (sa = #13) or (sa = #10));
  757.                 end;
  758.                 False:
  759.                 begin
  760.                   mb := ((sb = '') or not InIntArray(c, Ord(sb[1])));
  761.                   ma := ((sa = '') or not InIntArray(c, Ord(sa[1])));
  762.                 end;
  763.               end;
  764.               if not (mb and ma) then
  765.               begin
  766.                 y := (r - 1);
  767.                 for d := x to (y - 1) do
  768.                   Result[d] := Result[(d + 1)];
  769.                 SetLength(Result, y);
  770.                 Dec(r);
  771.               end;
  772.             end;
  773.           end;
  774.         end;
  775.       end;
  776.       if (not a and (r > 0)) then
  777.         SetLength(Result, 1);
  778.     end else
  779.     begin
  780.       SetLength(rmArr, l);
  781.       re := TRegExp.Create;
  782.       re.InputString := text;
  783.       re.Expression := findStr;
  784.       if (mmIgnoreCase in methods) then
  785.         re.ModifierI := True;
  786.       re.ModifierM := True;
  787.       a := (mmAll in methods);
  788.       re.ModifierG := (mmGreedyRegex in methods);
  789.       ol := (mmOverlap in methods);
  790.       p := offset;
  791.       while re.ExecPos(p) do
  792.       begin
  793.         rmArr[r].position := re.MatchPos[0];
  794.         rmArr[r].text := re.Match[0];
  795.         rmArr[r].size := re.MatchLen[0];
  796.         if ol then
  797.           p := (rmArr[r].position + 1)
  798.         else
  799.           p := (rmArr[r].position + rmArr[r].size);
  800.         Inc(r);
  801.       end;
  802.       p := Offset;
  803.       re.Free;
  804.       SetLength(rmArr, r);
  805.       if ((r > 0) and (mmWholeWords in methods)) then
  806.       begin
  807.         s := (mmStrictWW in methods);
  808.         if not s then
  809.           c := [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, // A-Z
  810.                 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, // a-z
  811.                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]; // 0-9
  812.         case ol of
  813.           True:
  814.           begin
  815.             spH := High(rmArr);
  816.             if (spH > -1) then
  817.             begin
  818.               SetLength(rmArr2D, (spH + 1));
  819.               rmArr2D[0] := [TRegexMatch(rmArr[0])];
  820.               if (spH > 0) then
  821.               begin
  822.                 spR := 1;
  823.                 for spI := 1 to spH do
  824.                 begin
  825.                   for spA := 0 to (spR - 1) do
  826.                   begin
  827.                     spL := Length(rmArr2D[spA]);
  828.                     for spB := 0 to (spL - 1) do
  829.                     begin
  830.                       spD := IAbs(rmArr[spI].position - rmArr2D[spA][spB].position);
  831.                       if (spD <= rmArr2D[spA][spB].size) then
  832.                       begin
  833.                         SetLength(rmArr2D[spA], (spL + 1));
  834.                         rmArr2D[spA][spL] := TRegexMatch(rmArr[spI]);
  835.                         Break;
  836.                       end;
  837.                     end;
  838.                     if (spB < spL) then
  839.                       Break;
  840.                   end;
  841.                   if (spA >= spR) then
  842.                   begin
  843.                     rmArr2D[spR] := [TRegexMatch(rmArr[spI])];
  844.                     Inc(spR);
  845.                   end;
  846.                 end;
  847.               end;
  848.               SetLength(rmArr2D, spR);
  849.               spH := High(rmArr2D);
  850.               for spI := spH downto 0 do
  851.               begin
  852.                 spB := Low(rmArr2D[spI]);
  853.                 spA := High(rmArr2D[spI]);
  854.                 abX := 1;
  855.                 abP := rmArr2D[spI][spB].position;
  856.                 abL := Length(text);
  857.                 case ((abL > 0) and (abP > 1)) of
  858.                   True:
  859.                   begin
  860.                     if ((abP - abX) < 1) then
  861.                       abX := ((abP - abX) + (abX - 1));
  862.                     if (abP > (abL + 1)) then
  863.                     begin
  864.                       abR := ((abP - abL) - 1);
  865.                       abX := (abX - abR);
  866.                     end;
  867.                     sb := Copy(text, ((abP - abX) - abR), abX);
  868.                   end;
  869.                   False: sb := '';
  870.                 end;
  871.                 abX := 1;
  872.                 abP := (rmArr2D[spI][spA].position + rmArr2D[spI][spA].size);
  873.                 abL := Length(text);
  874.                 case ((abL > 0) and (abP <= abL)) of
  875.                   True:
  876.                   begin
  877.                     if (abP < 1) then
  878.                     begin
  879.                       abX := (abX - iAbs(abP - 1));
  880.                       abP := 1;
  881.                     end;
  882.                     if ((abX > 0) and ((abP + abX) > abL)) then
  883.                       abX := (abX - (((abP + abX) - abL) - 1));
  884.                     sa := Copy(text, abP, abX);
  885.                   end;
  886.                   False: sa := '';
  887.                 end;
  888.                 case s of
  889.                   True:
  890.                   begin
  891.                     mb := ((sb = '') or (sb = ' ') or (sb = #13#10) or (sb = #13) or (sb = #10));
  892.                     ma := ((sa = '') or (sa = ' ') or (sa = #13#10) or (sa = #13) or (sa = #10));
  893.                   end;
  894.                   False:
  895.                   begin
  896.                     mb := ((sb = '') or not InIntArray(c, Ord(sb[1])));
  897.                     ma := ((sa = '') or not InIntArray(c, Ord(sa[1])));
  898.                   end;
  899.                 end;
  900.                 if not (mb and ma) then
  901.                 begin
  902.                   for spD := spI to (spH - 1) do
  903.                     rmArr2D[spD] := rmArr2D[(spD + 1)];
  904.                   SetLength(rmArr2D, spH);
  905.                   Dec(spH);
  906.                 end;
  907.               end;
  908.               spH := High(rmArr2D);
  909.               if (spH > -1) then
  910.               begin
  911.                 for spI := 0 to spH do
  912.                   IncEx(spR, (High(rmArr2D[spI]) + 1));
  913.                 SetLength(rmArr, spR);
  914.                 spR := 0;
  915.                 for spI := 0 to spH do
  916.                 begin
  917.                   spL := High(rmArr2D[spI]);
  918.                   for spA := 0 to spL do
  919.                   begin
  920.                     rmArr[spR] := TRegexMatch(rmArr2D[spI][spA]);
  921.                     Inc(spR);
  922.                   end;
  923.                 end;
  924.                 SetLength(rmArr, spR);
  925.                 r := spR;
  926.               end else
  927.                 SetLength(rmArr, 0);
  928.             end else
  929.               r := 0;
  930.           end;
  931.           False:
  932.           begin
  933.             for x := (r - 1) downto 0 do
  934.             begin
  935.               abX := 1;
  936.               abP := rmArr[x].position;
  937.               abL := Length(text);
  938.               case ((abL > 0) and (abP > 1)) of
  939.                 True:
  940.                 begin
  941.                   if ((abP - abX) < 1) then
  942.                     abX := ((abP - abX) + (abX - 1));
  943.                   if (abP > (abL + 1)) then
  944.                   begin
  945.                     abR := ((abP - abL) - 1);
  946.                     abX := (abX - abR);
  947.                   end;
  948.                   sb := Copy(text, ((abP - abX) - abR), abX);
  949.                 end;
  950.                 False: sb := '';
  951.               end;
  952.               abX := 1;
  953.               abP := (rmArr[x].position + rmArr[x].size);
  954.               abL := Length(text);
  955.               case ((abL > 0) and (abP <= abL)) of
  956.                 True:
  957.                 begin
  958.                   if (abP < 1) then
  959.                   begin
  960.                     abX := (abX - iAbs(abP - 1));
  961.                     abP := 1;
  962.                   end;
  963.                   if ((abX > 0) and ((abP + abX) > abL)) then
  964.                     abX := (abX - (((abP + abX) - abL) - 1));
  965.                   sa := Copy(text, abP, abX);
  966.                 end;
  967.                 False: sa := '';
  968.               end;
  969.               case s of
  970.                 True:
  971.                 begin
  972.                   mb := ((sb = ' ') or (sb = '') or (sb = #13#10) or (sb = #13) or (sb = #10));
  973.                   ma := ((sa = ' ') or (sa = '') or (sa = #13#10) or (sa = #13) or (sa = #10));
  974.                 end;
  975.                 False:
  976.                 begin
  977.                   mb := ((sb = '') or not InIntArray(c, Ord(sb[1])));
  978.                   ma := ((sa = '') or not InIntArray(c, Ord(sa[1])));
  979.                 end;
  980.               end;
  981.               if not (mb and ma) then
  982.               begin
  983.                 y := (r - 1);
  984.                 for d := x to (y - 1) do
  985.                   rmArr[d] := rmArr[(d + 1)];
  986.                 SetLength(rmArr, y);
  987.                 Dec(r);
  988.               end;
  989.             end;
  990.           end;
  991.         end;
  992.       end;
  993.       case (r > 0) of
  994.         True:
  995.         begin
  996.           if not a then
  997.             r := 1;
  998.           SetLength(Result, r);
  999.           for i := 0 to (r - 1) do
  1000.             Result[i] := rmArr[i].position;
  1001.         end;
  1002.         False: SetLength(Result, 0);
  1003.       end;
  1004.     end;
  1005.   end else
  1006.     SetLength(Result, 0);
  1007. end;
  1008.  
  1009. function CountString(s, str: string): Integer;
  1010. begin
  1011.   Result := Length(FindEx(str, s, [mmAll, mmIgnoreCase, mmWholeWords], 1, False));
  1012. end;
  1013.  
  1014. function CountStringEx(s, str: string; regex: Boolean): Integer;
  1015. begin
  1016.   Result := Length(FindEx(str, s, [mmAll, mmIgnoreCase, mmWholeWords], 1, regex));
  1017. end;
  1018.  
  1019. function CountStringMulti(s: TStringArray; str: string): Integer;
  1020. var
  1021.   tmp, all: TIntegerArray;
  1022.   h, i, l, f, a: Integer;
  1023. begin
  1024.   h := High(s);
  1025.   if ((str <> '') and (h > -1)) then
  1026.   begin
  1027.     for i := 0 to h do
  1028.     begin
  1029.       tmp := FindEx(str, s[i], [mmAll, mmIgnoreCase, mmWholeWords], 1, False);
  1030.       f := High(tmp);
  1031.       if (h > -1) then
  1032.       begin
  1033.         l := Length(all);
  1034.         SetLength(all, (l + (f + 1)));
  1035.         for a := 0 to f do
  1036.           all[(a + l)] := Integer(tmp[a]);
  1037.         SetLength(tmp, 0);
  1038.       end;
  1039.     end;
  1040.     ClearSameIntegers(all);
  1041.     Result := Length(all);
  1042.     SetLength(all, 0);
  1043.   end;
  1044. end;
  1045.  
  1046. function CountStringMultiEx(s: TStringArray; str: string; regex: Boolean): Integer;
  1047. var
  1048.   tmp, all: TIntegerArray;
  1049.   h, i, l, f, a: Integer;
  1050. begin
  1051.   h := High(s);
  1052.   if ((str <> '') and (h > -1)) then
  1053.   begin
  1054.     for i := 0 to h do
  1055.     begin
  1056.       tmp := FindEx(str, s[i], [mmAll, mmIgnoreCase, mmWholeWords], 1, regex);
  1057.       f := High(tmp);
  1058.       if (h > -1) then
  1059.       begin
  1060.         l := Length(all);
  1061.         SetLength(all, (l + (f + 1)));
  1062.         for a := 0 to f do
  1063.           all[(a + l)] := Integer(tmp[a]);
  1064.         SetLength(tmp, 0);
  1065.       end;
  1066.     end;
  1067.     ClearSameIntegers(all);
  1068.     Result := Length(all);
  1069.     SetLength(all, 0);
  1070.   end;
  1071. end;
  1072.  
  1073. function PositionToLine(position: Integer): Integer;
  1074. var
  1075.   h: Integer;
  1076. begin
  1077.   Result := 1;
  1078.   h := High(linePositions);
  1079.   if (h > -1) then
  1080.   case (h > 0) of
  1081.     True:
  1082.     for Result := 1 to (h + 1) do
  1083.       if (position < linePositions[(Result - 1)]) then
  1084.         Break;
  1085.     False:
  1086.     if (position >= linePositions[0]) then
  1087.       Result := 2;
  1088.   end;
  1089.   Dec(Result);
  1090. end;
  1091.  
  1092. procedure AddMessage(var msgs: string; msg: string);
  1093. begin
  1094.   case (msgs <> '') of
  1095.     True: msgs := (msgs + #13#10 + msg);
  1096.     False: msgs := msg;
  1097.   end;
  1098. end;
  1099.  
  1100. (*
  1101.   Auther: Officer Barbrady
  1102. *)
  1103. procedure FindHTTPThreats;
  1104. var
  1105.   ht: TStringArray;
  1106.   h, i, x, t: Integer;
  1107.   tmp: TIntegerArray;
  1108. begin
  1109.   msgHTTP := '';
  1110.   Inc(currentStep);
  1111.   t := GetSystemTime;
  1112.   ht := ['AddPostVariable', 'GetPage', 'PostHTTPPage', 'PostHTTPPageEx'];
  1113.   for x := 0 to 3 do
  1114.   begin
  1115.     tmp := FindEx(filteredScriptText, (Lowercase(ht[x]) + ReplaceWrap(' (\()(.*?)(\))', ' ', '(\s*)', [rfReplaceAll])), [mmAll, mmIgnoreCase, mmWholeWords], 1, True);
  1116.     h := High(tmp);
  1117.     if (h > -1) then
  1118.     begin
  1119.       for i := 0 to h do
  1120.         NewThreat(_threats, PositionToLine(tmp[i]), (ht[x] + '(*)'), tk_HTTP);
  1121.       IncEx(HTTPThreats, (h + 1));
  1122.       AddMessage(msgHTTP, (' Found "' + ht[x] + '" [Risk level: HIGH]'));
  1123.       IncEx(threats, 4);
  1124.     end;
  1125.     SetLength(tmp, 0);
  1126.   end;
  1127.   steps := (steps + (' Step ' + IntToStr(currentStep) + '/' + IntToStr(totalSteps) + ' - HTTP Threats [' + IntToStr(GetSystemTime - t) + ' ms.]') + #13#10);
  1128.   SetLength(ht, 0);
  1129. end;
  1130.  
  1131. (*
  1132.   Auther: Officer Barbrady
  1133. *)
  1134. procedure FindWebThreats;
  1135. var
  1136.   h, i, t: Integer;
  1137.   tmp: TIntegerArray;
  1138. begin
  1139.   msgWeb := '';
  1140.   Inc(currentStep);
  1141.   t := GetSystemTime;
  1142.   tmp := FindEx(filteredScriptText, ('openwebpage' + ReplaceWrap(' (\()(.*?)(\))', ' ', '(\s*)', [rfReplaceAll])), [mmAll, mmIgnoreCase, mmWholeWords], 1, True);
  1143.   h := High(tmp);
  1144.   if (h > -1) then
  1145.   begin
  1146.     for i := 0 to h do
  1147.       NewThreat(_threats, PositionToLine(tmp[i]), 'OpenWebPage(*)', tk_Web);
  1148.     IncEx(WebThreats, (h + 1));
  1149.     AddMessage(msgWeb, ' Found "OpenWebPage" [Risk level: HIGH]');
  1150.     IncEx(threats, 4);
  1151.     SetLength(tmp, 0);
  1152.   end;
  1153.   steps := (steps + (' Step ' + IntToStr(currentStep) + '/' + IntToStr(totalSteps) + ' - Web Threats [' + IntToStr(GetSystemTime - t) + ' ms.]') + #13#10);
  1154. end;
  1155.  
  1156. (*
  1157.   Auther: Officer Barbrady
  1158. *)
  1159. procedure FindBadCode;
  1160. var
  1161.   h, i, x, t: Integer;
  1162.   ac, bc: TStringArray;
  1163.   tmp: TIntegerArray;
  1164.   s: string;
  1165. begin
  1166.   msgFishy := '';
  1167.   Inc(currentStep);
  1168.   ac := ['Name', 'Pass', 'Pin'];
  1169.   t := GetSystemTime;
  1170.   for x := 0 to 2 do
  1171.   begin
  1172.     tmp := FindEx(filteredScriptText, ReplaceWrap(('players (\[) [a-zA-Z0-9]* (\]) (\.) ' + Lowercase(ac[x])), ' ', '(\s*)', [rfReplaceAll]), [mmAll, mmIgnoreCase, mmWholeWords], 1, True);
  1173.     h := High(tmp);
  1174.     if (h > 0) then
  1175.     begin
  1176.       for i := 0 to h do
  1177.         NewThreat(_threats, PositionToLine(tmp[i]), ('Players[*].' + ac[x]), tk_Fishy);
  1178.       IncEx(FishyCode, (h + 1));
  1179.       AddMessage(msgFishy, (' The variable "' + ac[x] + '" is used more then once [Risk level: MEDIUM]'));
  1180.       Inc(threats);
  1181.     end;
  1182.     SetLength(tmp, 0);
  1183.   end;
  1184.   tmp := FindEx(filteredScriptText, ReplaceWrap('ToStr (\() players (\[) [a-zA-Z0-9]* (\]) (\))', ' ', '(\s*)', [rfReplaceAll]), [mmAll, mmIgnoreCase, mmWholeWords], 1, True);
  1185.   h := High(tmp);
  1186.   if (h > -1) then
  1187.   begin
  1188.     for i := 0 to h do
  1189.       NewThreat(_threats, PositionToLine(tmp[i]), 'ToStr(Players[*])', tk_Fishy);
  1190.     IncEx(FishyCode, (h + 1));
  1191.     AddMessage(msgFishy, ' Player data sent to ToStr() [Risk level: MEDIUM]');
  1192.     Inc(threats);
  1193.     SetLength(tmp, 0);
  1194.   end;
  1195.   steps := (steps + (' Step ' + IntToStr(currentStep) + '/' + IntToStr(totalSteps) + ' - Fishy Code [' + IntToStr(GetSystemTime - t) + ' ms.]') + #13#10);
  1196.   SetLength(ac, 0);
  1197.   msgBad := '';
  1198.   Inc(currentStep);
  1199.   t := GetSystemTime;
  1200.   bc := ['mmouse (\() x , y , 1 , 1 (\))', 'mouse (\() x , y , 1 , 1 ,(.*?)(\))'];
  1201.   for x := 0 to 1 do
  1202.   begin
  1203.     tmp := FindEx(filteredScriptText, ReplaceWrap(bc[x], ' ', '(\s*)', [rfReplaceAll]), [mmAll, mmIgnoreCase, mmWholeWords], 1, True);
  1204.     h := High(tmp);
  1205.     if (h > -1) then
  1206.     begin
  1207.       case x of
  1208.         0: s := 'MMouse(x, y, 1, 1)';
  1209.         1: s := 'Mouse(x, y, 1, 1, *)';
  1210.       end;
  1211.       for i := 0 to h do
  1212.         NewThreat(_threats, PositionToLine(tmp[i]), s, tk_Bad);
  1213.       AddMessage(msgBad, (' Found "' + s + '" [Risk level: MEDIUM], potential ban.'));
  1214.       Inc(BadCode);
  1215.       threats := (threats + 1);
  1216.       SetLength(tmp, 0);
  1217.     end;
  1218.   end;
  1219.   tmp := FindEx(filteredScriptText, ReplaceWrap('(random (\()(.*)(\))|randomrange (\()(.*)(\)))', ' ', '(\s*)', [rfReplaceAll]), [mmAll, mmIgnoreCase, mmWholeWords], 1, True);
  1220.   h := High(tmp);
  1221.   case (h = -1) of
  1222.     True:
  1223.     begin
  1224.       AddMessage(msgBad, ' Couldn''t find any randomness in script [Risk level: MEDIUM], potential ban.');
  1225.       Inc(BadCode)
  1226.       Inc(threats);
  1227.     end;
  1228.     False: SetLength(tmp, 0);
  1229.   end;
  1230.   steps := (steps + (' Step ' + IntToStr(currentStep) + '/' + IntToStr(totalSteps) + ' - Unhuman/Abnormal Code [' + IntToStr(GetSystemTime - t) + ' ms.]') + #13#10);
  1231.   SetLength(bc, 0);
  1232. end;
  1233.  
  1234. (*
  1235.   Auther: Officer Barbrady
  1236. *)
  1237. procedure Scan;
  1238. var
  1239.   tmp: string;
  1240. begin
  1241.   totalSteps := 0;
  1242.   currentStep := 0;
  1243.   steps := '';
  1244.   if HTTP_SCAN then
  1245.     Inc(totalSteps);
  1246.   if WEB_SCAN then
  1247.     Inc(totalSteps);
  1248.   if CODE_SCAN then
  1249.     IncEx(totalSteps, 2);
  1250.   scanTimer := GetSystemTime;
  1251.   if HTTP_SCAN then
  1252.     FindHTTPThreats;
  1253.   if WEB_SCAN then
  1254.     FindWebThreats;
  1255.   if CODE_SCAN then
  1256.     FindBadCode;
  1257.   tmp := '--- Scanning ' + IntToStr(Length(linePositions)) + ' lines took ' + IntToStr(GetSystemTime - scanTimer) + ' ms. ---';
  1258.   steps := (steps + StringOfChar(' ', Round((49 - Length(tmp)) div 2)) + tmp);
  1259.   PrintReport;
  1260. end;
  1261.  
  1262. (*
  1263.   Auther: Officer Barbrady
  1264. *)
  1265. procedure OpenThread(Sender: TObject);
  1266. begin
  1267.   OpenWebPage('http://villavu.com/forum/showthread.php?t=103408');
  1268. end;
  1269.  
  1270. (*
  1271.   Auther: Officer Barbrady
  1272. *)
  1273. procedure SaveFormInfo(Sender: TObject);
  1274. var
  1275.   tmp: TStringArray;
  1276. begin
  1277.   DsgnForm.ModalResult := mrOk;
  1278.   tmp := ExplodeMulti([#13#10, #13, #10], ScriptEdit.Text);
  1279.   originalScriptText := TSAConcatEx(tmp, #13#10);
  1280.   SetLength(tmp, 0);
  1281.   filteredScriptText := FilterScriptData(originalScriptText);
  1282.   linePositions := PosAll(#13#10, filteredScriptText);
  1283.   TIAInsert(linePositions, 0, 1);
  1284.   pressed := True;
  1285.   DsgnForm.Close;
  1286. end;
  1287.  
  1288. (*
  1289.   Auther: Officer Barbrady
  1290. *)
  1291. procedure InitForm;
  1292. begin
  1293.   DsgnForm := TForm.Create(nil);
  1294.   with DsgnForm do
  1295.   begin
  1296.     Caption := ('Simba Script Scanner v' + FloatToStr(VERSION));
  1297.     Left := 377;
  1298.     Top := 380;
  1299.     Width := 750;
  1300.     Height := 460;
  1301.     Font.Name := default;
  1302.     Font.Color := clDefault;
  1303.     Font.Size := 0;
  1304.   end;
  1305.   ScriptEdit := TMemo.Create(DsgnForm);
  1306.   with ScriptEdit do
  1307.   begin
  1308.     Parent := DsgnForm;
  1309.     Left := 120;
  1310.     Top := 80;
  1311.     Width := 481;
  1312.     Height := 177;
  1313.     Font.Name := default;
  1314.     with ScriptEdit.Lines do
  1315.       Add('Paste script into this box, it will look for suspicious lines of code!');
  1316.     ScrollBars := ssBoth;
  1317.     TabOrder := 0;
  1318.   end;
  1319.   TitleLabel := TLabel.Create(DsgnForm);
  1320.   with TitleLabel do
  1321.   begin
  1322.     Parent := DsgnForm;
  1323.     Caption := ('Simba Script Scanner v' + FloatToStr(VERSION));
  1324.     Left := 225;
  1325.     Top := 20;
  1326.     Width := 43;
  1327.     Height := 14;
  1328.     Font.Name := default;
  1329.     Font.Color := clDefault;
  1330.     Font.Size := 17;
  1331.   end;
  1332.   ScanButton := TButton.Create(DsgnForm);
  1333.   with ScanButton do
  1334.   begin
  1335.     Parent := DsgnForm;
  1336.     Caption := 'Scan';
  1337.     Left := 175;
  1338.     Top := 300;
  1339.     Width := 150;
  1340.     Height := 25;
  1341.     Font.Size := 12;
  1342.     OnClick := @SaveFormInfo;
  1343.   end;
  1344.   UpdateButton := TButton.Create(DsgnForm);
  1345.   with UpdateButton do
  1346.   begin
  1347.     Parent := DsgnForm;
  1348.     Caption := 'Update';
  1349.     Left := 400;
  1350.     Top := 300;
  1351.     Width := 150;
  1352.     Height := 25;
  1353.     Font.Size := 12;
  1354.     OnClick := @OpenThread;
  1355.   end;
  1356. end;
  1357.  
  1358. procedure SafeInitForm;
  1359. var
  1360.   v: TVariantArray;
  1361. begin
  1362.   SetLength(V, 0);
  1363.   ThreadSafeCall('InitForm', v);
  1364. end;
  1365.  
  1366. procedure ShowFormModal;
  1367. begin
  1368.   DsgnForm.ShowModal;
  1369. end;
  1370.  
  1371. procedure SafeShowFormModal;
  1372. var
  1373.   v: TVariantArray;
  1374. begin
  1375.   SetLength(V, 0);
  1376.   ThreadSafeCall('ShowFormModal', v);
  1377. end;
  1378.  
  1379. begin
  1380.   ClearDebug;
  1381.   try
  1382.     SafeInitForm;
  1383.     SafeShowFormModal;
  1384.     if pressed then
  1385.       Scan;
  1386.   except
  1387.     WriteLn('Error with form :(');
  1388.   finally
  1389.     DsgnForm.Free;
  1390.     originalScriptText := '';
  1391.     filteredScriptText := '';
  1392.     displayScriptText := '';
  1393.     SetLength(linePositions, 0);
  1394.   end;
  1395. end.
Advertisement
Add Comment
Please, Sign In to add comment