Janilabo

progress [1.66]

Jun 24th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 61.85 KB | None | 0 0
  1. {=======================================================================================]
  2. |                                                                                       |
  3. |   _____ _       _          _____         _     _      _____                           |
  4. |  |   __|_|_____| |_ ___   |   __|___ ___|_|___| |_   |   __|___ ___ ___ ___ ___ ___   |
  5. |  |__   | |     | . | .'|  |__   |  _|  _| | . |  _|  |__   |  _| .'|   |   | -_|  _|  |
  6. |  |_____|_|_|_|_|___|__,|  |_____|___|_| |_|  _|_|    |_____|___|__,|_|_|_|_|___|_|    |
  7. |                                           |_|                                         |
  8. |                                                      ..by Officer Barbrady & Janilabo |
  9. [=======================================================================================}
  10.  
  11. const
  12.   SOCKET_SCAN = True; // Scan for Socket Threats?
  13.   HTTP_SCAN = True; // Scan for HTTP Threats?
  14.   WEB_SCAN = True; // Scan for Web Threats?
  15.   FILE_SCAN = True; // Scan for File Threats?
  16.   CODE_SCAN = True; // Scan for Fishy Code and Unhuman (abnormal) Code?
  17.   FILTER_COMMENTS = True; // Doesn't pay attention to stuff inside comments
  18.                           // Recommended to keep this feature enabled, a lot less false positives!
  19.   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).
  20.   FILTER_STRINGS = True; // Doesn't pay attention to stuff INSIDE string signs.
  21.                          // So, this feature still detects stuff that falls outside those '' signs! :)
  22.   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).
  23.   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).
  24.   DEBUG_SCAN_STEPS = True;
  25.   GUI_WIDTH = 800;
  26.   GUI_HEIGHT = 500;
  27.   DEFAULT = 'Times New Roman';
  28.   VERSION = 1.66; // Don't touch... Script version.
  29.   POINTS_VERY_LOW = 1;
  30.   POINTS_LOW = 2; // DON'T TOUCH!
  31.   POINTS_MEDIUM = 4; // DON'T TOUCH!
  32.   POINTS_HIGH = 6; // DON'T TOUCH!
  33.   POINTS_VERY_HIGH = 9; // DON'T TOUCH!
  34.  
  35. type
  36.   TMatchMethod = (mmAll, mmIgnoreCase, mmOverlap, mmWholeWords, mmStrictWW, mmGreedyRegex);
  37.   TMatchMethods = set of TMatchMethod;
  38.   TRegexMatch = record
  39.     position, size: Integer;
  40.     text: string;
  41.   end;
  42.   TRegexMatchArray = array of TRegexMatch;
  43.   T2DRegexMatchArray = array of TRegexMatchArray;
  44.   TRegexModifier = (rm_G, rm_I, rm_M, rm_S, rm_X, rm_R);
  45.   TRegexModifiers = set of TRegexModifier;
  46.   TRange = record
  47.     minimum, maximum: Integer;
  48.   end;
  49.   TRangeArray = array of TRange;
  50.   TRiskLevel = (rl_VeryLow, rl_Low, rl_Medium, rl_High, rl_VeryHigh);
  51.   TScanInformation = record
  52.     points: Integer;
  53.     timeStamp: string;
  54.     lineTracker: array of array[0..2] of Integer;
  55.     foundThreats, timing: Integer;
  56.     threat: array of record
  57.       name, timeStamp: string;
  58.       enabled: Boolean;
  59.       foundItems, timing: Integer;
  60.       item: array of record
  61.         caption, message, description, timeStamp: string;
  62.         riskLevel: TRiskLevel;
  63.         enabled: Boolean;
  64.         timing: Integer;
  65.         detect: record
  66.           text: string;
  67.           regex: Boolean;
  68.           methods: TMatchMethods;
  69.           requirement: record
  70.             minimum, maximum: Integer;
  71.           end;
  72.           filters: array of record
  73.             text: string;
  74.             regexTags: array of Char;
  75.             regexStrs: TStringArray;
  76.             modifiers: TRegexModifiers;
  77.             positions: TRangeArray;
  78.           end;
  79.         end;
  80.         found: array of record
  81.           timeStamp: string;
  82.           position: TRange;
  83.           line: Integer;
  84.         end;
  85.       end;
  86.     end;
  87.     script: record
  88.       original, display, filtered: string;
  89.       linePositions: TIntegerArray;
  90.     end;
  91.   end;
  92.  
  93. var
  94.   DsgnForm: TForm;
  95.   ScriptEdit: TMemo;
  96.   ScanButton, UpdateButton: TButton;
  97.   totalTiming: Integer;
  98.   pressed: Boolean;
  99.   data: TScanInformation;
  100.  
  101. procedure Append(var str: string; data: string);
  102. begin
  103.   str := (str + data);
  104. end;
  105.  
  106. function CenterEx(str: string; size: Integer; fill: Char): string;
  107. var
  108.   l, p: Integer;
  109. begin
  110.   l := Length(str);
  111.   case (l < size) of
  112.     True:
  113.     case (l = 0) of
  114.       False:
  115.       begin
  116.         p := (((size - l) div 2) + 1);
  117.         Result := (StringOfChar(fill, (p - 1)) + str + StringOfChar(fill, ((size - (p + l)) + 1)));
  118.       end;
  119.       True: Result := StringOfChar(fill, size);
  120.     end;
  121.     False: Result := str;
  122.   end;
  123. end;
  124.  
  125. function ParseTextReport: string;
  126. var
  127.   t, i, h, f, cs, ts, x, y: Integer;
  128.   r, li, kd, th: string;
  129. begin
  130.   Result := '';
  131.   Append(Result, '*************************************************' + #13#10);
  132.   Append(Result, '*        _  _  _       _  _  _  _  _ __         *' + #13#10);
  133.   Append(Result, '*       /_`/ `/_//|/  /_//_`/_// //_//          *' + #13#10);
  134.   Append(Result, '*      ._//_,/ // |  / \/_,/  /_// \/           *' + #13#10);
  135.   Append(Result, '*                                               *' + #13#10);
  136.   Append(Result, '*************************************************' + #13#10);
  137.   Append(Result, '                                                 ' + #13#10);
  138.   if DEBUG_FILTERED_SCRIPT then
  139.     if (data.script.display <> '') then
  140.     begin
  141.       Append(Result, '<===============[Filtered Script]===============>' + #13#10);
  142.       Append(Result, data.script.display + #13#10);
  143.       Append(Result, '<===============================================>' + #13#10);
  144.       Append(Result, '                                                 ' + #13#10);
  145.     end;
  146.   if DEBUG_SCAN_STEPS then
  147.   begin
  148.     for t := 0 to High(data.threat) do
  149.       if (data.threat[t].enabled) then
  150.         Inc(ts);
  151.     Append(Result, '<=================[Scan Steps]==================>' + #13#10);
  152.     Append(Result,' ┌────────────────────────────────────────────── ' + #13#10);
  153.     for t := 0 to High(data.threat) do
  154.     begin
  155.       if data.threat[t].enabled then
  156.       begin
  157.         Append(Result, (' ├─<' + data.threat[t].timeStamp + '> Step ' + IntToStr(cs + 1) + '/' + IntToStr(ts) + ' - ' + data.threat[t].name + 's [' + IntToStr(data.threat[t].timing) + ' ms.]') + #13#10);
  158.         Inc(cs);
  159.         for i := 0 to High(data.threat[t].item) do
  160.           if data.threat[t].item[i].enabled then
  161.           begin
  162.             Append(Result, (' ├───<' + data.threat[t].item[i].timeStamp + '> Scan for ' + data.threat[t].item[i].caption + ' [' + IntToStr(data.threat[t].item[i].timing) + ' ms.]') + #13#10);
  163.             h := High(data.threat[t].item[i].found);
  164.             if (h > -1) then
  165.             begin
  166.               if (h > 0) then
  167.                 Append(Result, (' ├─────<' + data.threat[t].item[i].found[0].timeStamp + '> DETECTED ' + IntToStr(h + 1) + ' THREATS:') + #13#10)
  168.               else
  169.                 Append(Result, (' ├─────<' + data.threat[t].item[i].found[0].timeStamp + '> DETECTED ' + IntToStr(h + 1) + ' THREAT:') + #13#10);
  170.               for f := 0 to h do
  171.               case (data.threat[t].item[i].found[f].line = -1) of
  172.                 True: Append(Result, (' ├───────<' + data.threat[t].item[i].found[f].timeStamp  + '> Could not find ' + data.threat[t].item[i].caption + ' @ ANY line!') + #13#10);
  173.                 False: Append(Result, (' ├───────<' + data.threat[t].item[i].found[f].timeStamp  + '> Found ' + data.threat[t].item[i].caption + ' @ line ' + IntToStr(data.threat[t].item[i].found[f].line) + '!') + #13#10);
  174.               end;
  175.             end;
  176.           end;
  177.       end;
  178.       if ((cs > 0) and (cs < ts)) then
  179.         Append(Result, ' │' + #13#10);
  180.     end;
  181.     Append(Result, ' └────────────────────────────────────────────── ' + #13#10);
  182.     Append(Result, CenterEx(('--- Scanning ' + IntToStr(Length(data.script.linePositions)) + ' lines took ' + IntToStr(data.timing) + ' ms. ---'), 49, ' ') + #13#10);
  183.     Append(Result, '<===============================================>' + #13#10);
  184.     Append(Result, '                                                 ' + #13#10);
  185.   end;
  186.   for t := 0 to High(data.threat) do
  187.     if data.threat[t].enabled then
  188.       if (data.threat[t].foundItems > 0) then
  189.       begin
  190.         Append(Result, ('<' + CenterEx(('[Messages for ' + data.threat[t].name + 's]'), 47, '=') + '>') + #13#10);
  191.         for i := 0 to High(data.threat[t].item) do
  192.         begin
  193.           h := High(data.threat[t].item[i].found);
  194.           if (h > -1) then
  195.           begin
  196.             case data.threat[t].item[i].riskLevel of
  197.               rl_VeryLow: r := 'VERY LOW';
  198.               rl_Low: r := 'LOW';
  199.               rl_Medium: r := 'MEDIUM';
  200.               rl_High: r := 'HIGH';
  201.               rl_VeryHigh: r := 'VERY HIGH';
  202.             end;
  203.             Append(Result, (' ' + data.threat[t].item[i].message + ' [Risk level: ' + r + ']') + #13#10);
  204.           end;
  205.         end;
  206.         Append(Result, '<===============================================>' + #13#10);
  207.         Append(Result, '                                                 ' + #13#10);
  208.       end;
  209.   y := Length(data.lineTracker);
  210.   if (y > 0) then
  211.   begin
  212.     Append(Result, '<=============[Lines with Threats]==============>' + #13#10);
  213.     Append(Result, ' LINE |      KIND      |        THREAT           ' + #13#10);
  214.     Append(Result, ' -----+----------------+------------------------ ' + #13#10);
  215.     for x := 0 to (y - 1) do
  216.     begin
  217.       case (data.threat[data.lineTracker[x][0]].item[data.lineTracker[x][1]].found[data.lineTracker[x][2]].line > -1) of
  218.         True: li := IntToStr(data.threat[data.lineTracker[x][0]].item[data.lineTracker[x][1]].found[data.lineTracker[x][2]].line);
  219.         False: li := 'NONE';
  220.       end;
  221.       kd := data.threat[data.lineTracker[x][0]].name;
  222.       th := data.threat[data.lineTracker[x][0]].item[data.lineTracker[x][1]].caption;
  223.       Append(Result, ' ' + (li + Padr(' ', (Length(' LINE |') - Length(li)) - 2)) + '| ' + (kd + Padr(' ', (Length('      KIND      |') - Length(kd)) - 2)) + '| ' + th + #13#10);
  224.     end;
  225.     Append(Result, '<===============================================>' + #13#10);
  226.     Append(Result, '                                                 ' + #13#10);
  227.   end;
  228.   case data.points of
  229.     0: r := 'None';
  230.     1..2: r := 'Very Low';
  231.     3..5: r := 'Low';
  232.     6..9: r := 'Medium';
  233.     10..14: r := 'High';
  234.   else
  235.     r := 'Very High';
  236.   end;
  237.   Append(Result, '<================[Scan Results]=================>' + #13#10);
  238.   for t := 0 to High(data.threat) do
  239.   begin
  240.     kd := (data.threat[t].name + 's');
  241.     Append(Result, ' ' +  kd + StringOfChar('.', (47 - (Length(kd) + Length(IntToStr(data.threat[t].foundItems))))) + IntToStr(data.threat[t].foundItems) + #13#10);
  242.   end;
  243.   Append(Result, ' -----------------------------------------------' + #13#10);
  244.   Append(Result, ' Overall threats' + StringOfChar('.', (47 - (Length('Overall threats') + Length(IntToStr(data.foundThreats))))) + IntToStr(data.foundThreats) + #13#10);
  245.   Append(Result, ' Script Risk Level' + StringOfChar('.', (47 - (Length('Script Risk Level') + Length(r)))) + r + #13#10);
  246.   Append(Result, '<===============================================>' + #13#10);
  247.   Append(Result, '                                                 ' + #13#10);
  248.   Append(Result, '<===================[FINISHED]==================>' + #13#10);
  249.   Append(Result, ' Remember to visit the thread for latest updates.' + #13#10);
  250.   Append(Result, '               Thank you for using!              ' + #13#10);
  251.   r := '~ Total Time Taken ' + IntToStr(GetSystemTime - totalTiming) + ' ms. ~';
  252.   Append(Result, StringOfChar(' ', Round((49 - Length(r)) div 2)) + r + #13#10);
  253.   Append(Result, '<===============================================>');
  254. end;
  255.  
  256. function AddThreat(var x: TScanInformation; name: string): Integer;
  257. var
  258.   l: Integer;
  259. begin
  260.   l := Length(x.threat);
  261.   SetLength(x.threat, (l + 1));
  262.   x.threat[l].name := name;
  263.   Result := l;
  264. end;
  265.  
  266. function AddItem(var x: TScanInformation; threatID: Integer; caption, message, description: string; riskLevel: TRiskLevel; detectText: string; detectRegex: Boolean; detectMethods: TMatchMethods; detectMinReq, detectMaxReq: Integer): Integer;
  267. var
  268.   l: Integer;
  269. begin
  270.   Result := -1;
  271.   if ((threatID < 0) or (High(x.threat) < threatID)) then
  272.     Exit;
  273.   l := Length(x.threat[threatID].item);
  274.   SetLength(x.threat[threatID].item, (l + 1));
  275.   x.threat[threatID].item[l].caption := caption;
  276.   x.threat[threatID].item[l].message := message;
  277.   x.threat[threatID].item[l].description := description;
  278.   x.threat[threatID].item[l].riskLevel := riskLevel;
  279.   x.threat[threatID].item[l].detect.text := detectText;
  280.   x.threat[threatID].item[l].detect.regex := detectRegex;
  281.   x.threat[threatID].item[l].detect.methods := detectMethods;
  282.   x.threat[threatID].item[l].detect.requirement.minimum := detectMinReq;
  283.   x.threat[threatID].item[l].detect.requirement.maximum := detectMaxReq;
  284.   Result := l;
  285. end;
  286.  
  287. function AddFilter( var x: TScanInformation; threatID, itemID: Integer; text: string; regexTags: array of Char; regexStrs: TStringArray; modifiers: TRegexModifiers): Integer;
  288. var
  289.   l, h, i: Integer;
  290. begin
  291.   Result := -1;
  292.   if ((threatID > -1) and (High(x.threat) >= threatID)) then
  293.     if ((itemID > -1) and (High(x.threat[threatID].item) >= itemID)) then
  294.     begin
  295.       l := Length(x.threat[threatID].item[itemID].detect.filters);
  296.       SetLength(x.threat[threatID].item[itemID].detect.filters, (l + 1));
  297.       x.threat[threatID].item[itemID].detect.filters[l].text := text;
  298.       h := Min(High(regexTags), High(regexStrs));
  299.       SetLength(x.threat[threatID].item[itemID].detect.filters[l].regexTags, (h + 1));
  300.       for i := 0 to h do
  301.         x.threat[threatID].item[itemID].detect.filters[l].regexTags[i] := regexTags[i];
  302.       SetLength(x.threat[threatID].item[itemID].detect.filters[l].regexStrs, (h + 1));
  303.       for i := 0 to h do
  304.         x.threat[threatID].item[itemID].detect.filters[l].regexStrs[i] := regexStrs[i];
  305.       x.threat[threatID].item[itemID].detect.filters[l].modifiers := TRegexModifiers(modifiers);
  306.       Result := l;
  307.     end;
  308. end;
  309.  
  310. procedure SetupThreats;
  311. var
  312.   tmp, r_tmp: TStringArray;
  313.   i, f1, f2: Integer;
  314.   ID: TIntegerArray;
  315.   rl: array of TRiskLevel;
  316. begin
  317.   {THREATS}
  318.   tmp := ['Socket Threat', 'HTTP Threat', 'Web Threat', 'File Threat', 'Fishy Code', 'Unhuman Code'];
  319.   SetLength(ID, (High(tmp) + 1));
  320.   for i := 0 to High(tmp) do
  321.     ID[i] := AddThreat(data, tmp[i]);
  322.   {SOCKET}
  323.   rl  := [rl_VeryHigh,    rl_VeryHigh,     rl_VeryHigh,  rl_High,      rl_High,         rl_High,        rl_High,      rl_High];
  324.   tmp := ['CreateSocket', 'ConnectSocket', 'SendSocket', 'RecvSocket', 'RecvSocketStr', 'RecvSocketEx', 'BindSocket', 'SocketInfo'];
  325.   for i := 0 to High(tmp) do
  326.     AddItem(data, ID[0], tmp[i], 'Found "' + tmp[i] + '"', '-', rl[i], Lowercase(tmp[i]), False, [mmAll, mmIgnoreCase, mmWholeWords], 1, -1);
  327.   {HTTP}
  328.   rl  := [rl_VeryHigh,       rl_High,   rl_High,        rl_High,          rl_Medium,       rl_Medium,          rl_Medium,     rl_High,                rl_High];
  329.   tmp := ['AddPostVariable', 'GetPage', 'PostHTTPPage', 'PostHTTPPageEx', 'GetRawHeaders', 'SetHTTPUserAgent', 'GetHTTPPage', 'InitializeHTTPClient', 'InitializeHTTPClientWrap'];
  330.   for i := 0 to High(tmp) do
  331.     AddItem(data, ID[1], tmp[i], 'Found "' + tmp[i] + '"', '-', rl[i], Lowercase(tmp[i]), False, [mmAll, mmIgnoreCase, mmWholeWords], 1, -1);
  332.   {WEB}
  333.   AddItem(data, ID[2], 'OpenWebPage', 'Found "OpenWebPage"', '-', rl_High, 'openwebpage', False, [mmAll, mmIgnoreCase, mmWholeWords], 1, -1);
  334.   {FILE}
  335.   rl  := [rl_High,      rl_High,    rl_VeryHigh,   rl_Medium,        rl_High,           rl_Medium,         rl_Medium,    rl_High,           rl_High,            rl_Medium,  rl_Medium,        rl_VeryHigh,  rl_VeryHigh,  rl_High,    rl_Low,    rl_VeryHigh];
  336.   tmp := ['CreateFile', 'OpenFile', 'RewriteFile', 'ReadFileString', 'WriteFileString', 'DirectoryExists', 'FileExists', 'CreateDirectory', 'ForceDirectories', 'GetFiles', 'GetDirectories', 'DeleteFile', 'RenameFile', 'WriteINI', 'ReadINI', 'DeleteINI'];
  337.   for i := 0 to High(tmp) do
  338.     AddItem(data, ID[3], tmp[i], 'Found "' + tmp[i] + '(*)"', '-', rl[i], Lowercase(tmp[i]), False, [mmAll, mmIgnoreCase, mmWholeWords], 1, -1);
  339.   {FISHY}
  340.   rl  := [rl_Medium, rl_VeryHigh,  rl_High];
  341.   tmp := ['Name',    'Pass',       'Pin'];
  342.   for i := 0 to High(tmp) do
  343.   case i of
  344.     0: f1 := AddItem(data, ID[4], tmp[i], 'The variable "' + tmp[i] + '" is used more then once', '-', rl[i], Lowercase(tmp[i]), False, [mmAll, mmIgnoreCase, mmWholeWords], 2, -1);
  345.     2: f2 := AddItem(data, ID[4], tmp[i], 'The variable "' + tmp[i] + '" is used more then once', '-', rl[i], Lowercase(tmp[i]), False, [mmAll, mmIgnoreCase, mmWholeWords], 2, -1);
  346.   else
  347.     AddItem(data, ID[4], tmp[i], 'The variable "' + tmp[i] + '" is used more then once', '-', rl[i], Lowercase(tmp[i]), False, [mmAll, mmIgnoreCase, mmWholeWords], 2, -1);
  348.   end;
  349.   AddFilter(data, ID[4], f1, 'font . name', [' '], ['(\s*)'], [rm_I]);
  350.   AddFilter(data, ID[4], f2, ' inpin @', [' ', '@'], ['(\s*)', '(\()(\s*)players(\s*)(\[)(\s*)\w+(\s*)(\])(\s*)(\.)(\s*)pin(\s*)(\))'], [rm_I]);
  351.   AddItem(data, ID[4], 'ToStr(Players[*])', 'Player data sent to ToStr()', '-', rl_VeryHigh, 'ToStr(\s*)(\()(\s*)players(\s*)(\[)(\s*)[a-zA-Z0-9]*(\s*)(\])(\s*)(\))', True, [mmAll, mmIgnoreCase, mmWholeWords], 1, -1);
  352.   rl  := [rl_Medium,     rl_Medium,       rl_Medium,        rl_Medium,         rl_High,       rl_High,  rl_Medium, rl_Medium];
  353.   tmp := ['TradeScreen', 'SomeoneTrades', 'GetTradersName', 'TradeScreenName', 'AcceptTrade', 'Accept', 'Waiting', 'PlayerAccepted'];
  354.   for i := 0 to High(tmp) do
  355.     AddItem(data, ID[4], tmp[i], 'Picked up trading activity command "' + tmp[i] + '" (UNUSUAL)', '-', rl[i], Lowercase(tmp[i]), False, [mmAll, mmIgnoreCase, mmWholeWords], 1, -1);
  356.   {UNHUMAN}
  357.   rl :=  [rl_Low,               rl_Low];
  358.   tmp := ['MMouse(x, y, 1, 1)', 'Mouse(x, y, 1, 1, *)'];
  359.   r_tmp := ['(\W)mmouse(\s*)(\()(\s*)x(\s*),(\s*)y(\s*),(\s*)1(\s*),(\s*)1(\s*)(\))', '(\W)mouse(\s*)(\()(\s*)x(\s*),(\s*)y(\s*),(\s*)1(\s*),(\s*)1(\s*),(.*?)(\))'];
  360.   for i := 0 to High(r_tmp) do
  361.     AddItem(data, ID[5], tmp[i], 'Found "' + tmp[i] + '" (potential ban)', '-', rl[i], Lowercase(r_tmp[i]), True, [mmAll, mmIgnoreCase], 1, -1);
  362.   AddItem(data, ID[5], 'Random[Range]', 'Couldn''t find any randomness in script (potential ban)', '-', rl_Medium, '((\W)random(\s*)|(\W)randomrange(\s*))', True, [mmAll, mmIgnoreCase, mmWholeWords], 0, 0);
  363.   SetLength(r_tmp, 0);
  364.   SetLength(tmp, 0);
  365. end;
  366.  
  367. function OpenWebsite(site: string): Boolean;
  368. begin
  369.   site := Trim(site);
  370.   Result := (Pos('.', site) > 0);
  371.   if Result then
  372.     OpenWebPage(site);
  373. end;
  374.  
  375. function TimeStamp: string;
  376. var
  377.   Hours, Minutes, Seconds, Milliseconds: Word;
  378.   tTSA: TStringArray;
  379.   i: Integer;
  380. begin
  381.   DecodeTime(Now, Hours, Minutes, Seconds, Milliseconds);
  382.   if (Hours > 23) then
  383.     Hours := 0;
  384.   tTSA := [IntToStr(Hours), IntToStr(Minutes), IntToStr(Seconds), IntToStr(Milliseconds)];
  385.   for i := 0 to 2 do
  386.     if (StrToInt(tTSA[i]) < 10) then
  387.       tTSA[i] := ('0' + string(tTSA[i]));
  388.   while (Length(tTSA[3]) < 3) do
  389.     tTSA[3] := (string(tTSA[3]) + '0');
  390.   Result := string(tTSA[0] + ':' + tTSA[1] + ':' + tTSA[2] + ':' + tTSA[3]);
  391. end;
  392.  
  393. procedure TIADelete(var TIA: TIntegerArray; x: Integer);
  394. var
  395.   i, h: Integer;
  396. begin
  397.   h := High(TIA);
  398.   if ((x > h) or (x < 0)) then
  399.     Exit;
  400.   for i := x to (h - 1) do
  401.     TIA[i] := TIA[(i + 1)];
  402.   SetLength(TIA, h);
  403. end;
  404.  
  405. procedure TIAInsert(var TIA: TIntegerArray; index: Integer; int: Integer);
  406. var
  407.   i, l: Integer;
  408. begin
  409.   l := Length(TIA);
  410.   SetLength(TIA, (l + 1));
  411.   if (index < 0) then
  412.     index := 0;
  413.   if (index > l) then
  414.     index := l;
  415.   if (l > index) then
  416.     for i := (l - 1) downto index do
  417.       TIA[(i + 1)] := Integer(TIA[i]);
  418.   TIA[index] := Integer(int);
  419. end;
  420.  
  421. {==============================================================================]
  422.   Explanation: Returns string of all TSA items binded together. Places glue between the indexes.
  423. [==============================================================================}
  424. function TSAConcatEx(TSA: TStringArray; glue: string): string;
  425. var
  426.   h, i: Integer;
  427. begin
  428.   Result := '';
  429.   h := High(TSA);
  430.   if (h > -1) then
  431.   begin
  432.     for i := 0 to (h - 1) do
  433.       Result := (Result + string(TSA[i]) + string(glue));
  434.     Result := (Result + string(TSA[i]));
  435.   end;
  436. end;
  437.  
  438. {==============================================================================]
  439.   Explanation: Explodes str with multiple separators/delimiters (d).
  440.                The importance order for d items is from left to right (=>).
  441.                So place the important ones first and then less important after those.
  442. [==============================================================================}
  443. function ExplodeMulti(d: TStringArray; str: string): TStringArray;
  444. var
  445.   p, h, i, x, o, m, l, y, z: Integer;
  446. begin
  447.   h := High(d);
  448.   if ((h > -1) and (str <> '')) then
  449.   begin
  450.     o := 1;
  451.     SetLength(Result, Length(str));
  452.     repeat
  453.       l := 0;
  454.       for x := 0 to h do
  455.       begin
  456.         p := Pos(d[x], str);
  457.         case (p < 1) of
  458.           True:
  459.           begin
  460.             z := High(d);
  461.             if ((x <= z) and (x > -1)) then
  462.             begin
  463.               for y := x to (z - 1) do
  464.                 d[y] := d[(y + 1)];
  465.               SetLength(d, z);
  466.             end;
  467.             Dec(x);
  468.             Dec(h);
  469.           end;
  470.           False:
  471.           if ((l = 0) or (p < l)) then
  472.           begin
  473.             m := x;
  474.             l := p;
  475.           end;
  476.         end;
  477.       end;
  478.       if (l > 0) then
  479.       begin
  480.         Result[i] := Copy(str, 1, (l - 1));
  481.         Delete(str, 1, ((l + Length(d[m])) - 1));
  482.         Inc(i);
  483.       end else
  484.         Result[i] := Copy(str, 1, Length(str));
  485.     until (l = 0);
  486.     SetLength(Result, (i + 1));
  487.   end else
  488.     Result := [string(str)];
  489. end;
  490.  
  491. {==============================================================================]
  492.   Explanation: Finds position from s items in str. Stores the ID of the found s item to index variable.
  493.                The importance order for d items is from left to right (=>).
  494.                So place the important ones first and then less important after those.
  495.                Contains field for offset.
  496. [==============================================================================}
  497. function PosMultiIDEx(s: TStringArray; str: string; var index: Integer; offset: Integer): Integer;
  498. var
  499.   h, i, p, t: Integer;
  500. begin
  501.   if (offset < 1) then
  502.     offset := 1;
  503.   Result := -1;
  504.   index := -1;
  505.   h := High(s);
  506.   if ((h > -1) and (str <> '')) then
  507.   begin
  508.     t := (Length(str) + 1);
  509.     Result := t;
  510.     for i := 0 to h do
  511.     begin
  512.       p := PosEx(s[i], str, offset);
  513.       if ((p > 0) and (p < Result)) then
  514.       begin
  515.         Result := p;
  516.         index := i;
  517.       end;
  518.     end;
  519.     if (Result = t) then
  520.       Result := 0;
  521.   end;
  522. end;
  523.  
  524. function PosAll(s, str: string): TIntegerArray;
  525. var
  526.   sL, strL, o, p, r: Integer;
  527. begin
  528.   sL := Length(s);
  529.   strL := Length(str);
  530.   if (sL <= strL) then
  531.   begin
  532.     SetLength(Result, strL);
  533.     repeat
  534.       p := PosEx(s, str, (o + 1));
  535.       if (p > 0) then
  536.       begin
  537.         Result[r] := p;
  538.         o := p;
  539.         Inc(r);
  540.       end;
  541.     until (p <= 0);
  542.   end;
  543.   SetLength(Result, r);
  544. end;
  545.  
  546. {==============================================================================]
  547.   Explanation: Indents str with spaces (just like the feature in SCAR, Ctrl+Shift+[I/U]).
  548.                shift is the amount of spaces. It can be positive value (indent), 0 (no change) or negative value (unindent).
  549. [==============================================================================}
  550. procedure Indentation(var str: string; shift: Integer);
  551. var
  552.   d, tmp, nl: TStringArray;
  553.   p, h, i, x, o, m, l, y, z: Integer;
  554.   s: string;
  555. begin
  556.   if ((str <> '') and (shift <> 0)) then
  557.   begin
  558.     d := [#13#10, #13, #10];
  559.     h := High(d);
  560.     o := 1;
  561.     SetLength(tmp, Length(str));
  562.     SetLength(nl, Length(str));
  563.     repeat
  564.       l := 0;
  565.       for x := 0 to h do
  566.       begin
  567.         p := Pos(d[x], str);
  568.         case (p < 1) of
  569.           True:
  570.           begin
  571.             z := High(d);
  572.             if ((x <= z) and (x > -1)) then
  573.             begin
  574.               for y := x to (z - 1) do
  575.                 d[y] := d[(y + 1)];
  576.               SetLength(d, z);
  577.             end;
  578.             Dec(x);
  579.             Dec(h);
  580.           end;
  581.           False:
  582.           if ((l = 0) or (p < l)) then
  583.           begin
  584.             m := x;
  585.             l := p;
  586.           end;
  587.         end;
  588.       end;
  589.       if (l > 0) then
  590.       begin
  591.         tmp[i] := Copy(str, 1, (l - 1));
  592.         nl[i] := string(d[m]);
  593.         Delete(str, 1, ((l + Length(d[m])) - 1));
  594.         Inc(i);
  595.       end else
  596.         tmp[i] := Copy(str, 1, Length(str));
  597.     until (l = 0);
  598.     str := '';
  599.     SetLength(tmp, (i + 1));
  600.     SetLength(nl, i);
  601.     case (shift > 0) of
  602.       True:
  603.       begin
  604.         s := StringOfChar(' ', shift);
  605.         for x := 0 to i do
  606.         begin
  607.           str  := (str + (s + tmp[x]));
  608.           if (x < i) then
  609.             str := (str + nl[x]);
  610.         end;
  611.       end;
  612.       False:
  613.       begin
  614.         shift := iAbs(shift);
  615.         for x := 0 to i do
  616.         begin
  617.           y := 0;
  618.           l := Length(tmp[x]);
  619.           while ((y < shift) and (y < l) and (tmp[x][(y + 1)] = ' ')) do
  620.             Inc(y);
  621.           if (y > 0) then
  622.             Delete(tmp[x], 1, y);
  623.           str := (str + tmp[x]);
  624.           if (x < i) then
  625.             str := (str + nl[x]);
  626.         end;
  627.       end;
  628.     end;
  629.     SetLength(tmp, 0);
  630.     SetLength(nl, 0);
  631.   end;
  632. end;
  633.  
  634. function ToRange(minimum, maximum: Integer): TRange;
  635. begin
  636.   Result.minimum := Integer(minimum);
  637.   Result.maximum := Integer(maximum);
  638. end;
  639.  
  640. {==============================================================================]
  641.   Explanation: Returns true if int is in any range from ranges of TRA.
  642. [==============================================================================}
  643. function TRAContains(TRA: TRangeArray; int: Integer): Boolean;
  644. var
  645.   h, i: Integer;
  646. begin
  647.   h := High(TRA);
  648.   case (h > -1) of
  649.     True:
  650.     begin
  651.       for i := 0 to h do
  652.         if ((int >= TRA[i].minimum) and (int <= TRA[i].maximum)) then
  653.           Break;
  654.       Result := (i <= h);
  655.     end;
  656.     False: Result := False;
  657.   end;
  658. end;
  659.  
  660. procedure TRAAppend(var TRA: TRangeArray; x: TRange);
  661. var
  662.   aL: Integer;
  663. begin
  664.   aL := (Length(TRA) + 1);
  665.   SetLength(TRA, aL);
  666.   TRA[(aL - 1)] := TRange(x);
  667. end;
  668.  
  669. procedure TRADelete(var TRA: TRangeArray; x: Integer);
  670. var
  671.   i, h: Integer;
  672. begin
  673.   h := High(TRA);
  674.   if ((x > h) or (x < 0)) then
  675.     Exit;
  676.   for i := x to (h - 1) do
  677.     TRA[i] := TRA[(i + 1)];
  678.   SetLength(TRA, h);
  679. end;
  680.  
  681. function TrackCaS(str: string; var comments, strings: TRangeArray): Boolean;
  682. var
  683.   s, i, o, e, x, l, a, ls: Integer;
  684.   t: TStringArray;
  685. begin
  686.   Result := False;
  687.   SetLength(comments, 0);
  688.   SetLength(strings, 0);
  689.   l := Length(str);
  690.   ls := -1;
  691.   if (l > 0) then
  692.   begin
  693.     o := 1;
  694.     t := ['//', '(*', '{', ''''];
  695.     repeat
  696.       s := PosMultiIDEx(t, str, i, o);
  697.       case (s <= ls) of
  698.         True: Exit;
  699.         False: ls := s;
  700.       end;
  701.       if (s > 0) then
  702.       begin
  703.         o := (s + 1);
  704.         a := 0;
  705.         case i of
  706.           0, 1, 2:
  707.           begin
  708.             case i of
  709.               0:
  710.               begin
  711.                 e := PosMultiIDEx([#13#10, #13, #10], str, x, o);
  712.                 if (x = 0) then
  713.                   a := 1;
  714.                 if (e = 0) then
  715.                   e := l;
  716.                 TRAAppend(comments, ToRange(s, e));
  717.               end;
  718.               1, 2:
  719.               begin
  720.                 case i of
  721.                   1:
  722.                   begin
  723.                     e := PosEx('*)', str, o);
  724.                     a := 1;
  725.                   end;
  726.                   2: e := PosEx('}', str, o);
  727.                 end;
  728.                 if (e = 0) then
  729.                   e := l;
  730.                 TRAAppend(comments, ToRange(s, (e + a)));
  731.               end;
  732.             end;
  733.           end;
  734.           3:
  735.           begin
  736.             e := PosMultiIDEx([#13#10, #13, #10, ''''], str, x, o);
  737.             if (x = 0) then
  738.               a := 1;
  739.             case (e = 0) of
  740.               True:
  741.               begin
  742.                 e := l;
  743.                 TRAAppend(strings, ToRange(s, e));
  744.               end;
  745.               False:
  746.               case x of
  747.                 0, 1, 2: TRAAppend(strings, ToRange(s, e));
  748.                 3: TRAAppend(strings, ToRange(s, (e + a)));
  749.               end;
  750.             end;
  751.           end;
  752.         end;
  753.         o := ((e + 1) + a);
  754.       end;
  755.     until ((s = 0) or (x = -1) or (o > l));
  756.   end;
  757. end;
  758.  
  759. {==============================================================================]
  760.   Explanation: Trims all TSA items.
  761. [==============================================================================}
  762. procedure TSATrim(var TSA: TStringArray);
  763. var
  764.   h, i: Integer;
  765. begin
  766.   h := High(TSA);
  767.   for i := 0 to h do
  768.     TSA[i] := Trim(TSA[i]);
  769. end;
  770.  
  771. {==============================================================================]
  772.   Explanation: Returns all the positions by items from s array in str. Place s items in importance order (=>)
  773.                If overlap is set to true, strings can overlap.
  774.                (['aa'], 'baaaah', False) => [2,3,4]
  775.                (['aa'], 'baaaah', True) => [2,4]
  776. [==============================================================================}
  777. function PosAllMulti(s: TStringArray; str: string; overlap: Boolean): TIntegerArray;
  778. var
  779.   h, l, p, o, x, i, t, r, y, d: Integer;
  780. begin
  781.   h := High(s);
  782.   y := Length(str);
  783.   if ((y > 0) and (h > -1)) then
  784.   begin
  785.     SetLength(Result, y);
  786.     o := 1;
  787.     repeat
  788.       p := 0;
  789.       for x := 0 to h do
  790.       begin
  791.         t := PosEx(s[x], str, (l + o));
  792.         case (t < 1) of
  793.           True:
  794.           begin
  795.             for d := x to (h - 1) do
  796.               s[d] := s[(d + 1)];
  797.             SetLength(s, h);
  798.             Dec(x);
  799.             Dec(h);
  800.           end;
  801.           False:
  802.           if ((p = 0) or (t < p)) then
  803.           begin
  804.             p := t;
  805.             i := x;
  806.           end;
  807.         end;
  808.       end;
  809.       if (p > 0) then
  810.       begin
  811.         Result[r] := p;
  812.         Inc(r);
  813.         l := p;
  814.         if not overlap then
  815.           o := Length(s[i]);
  816.       end;
  817.     until (p <= 0);
  818.   end;
  819.   SetLength(Result, r);
  820. end;
  821.  
  822. procedure FillStrRangeEx(var str: string; fillWith: Char; range: TRange; exceptions: TIntegerArray);
  823. var
  824.   i, l, c: Integer;
  825. begin
  826.   l := Length(str);
  827.   if ((l > 0) and not (range.minimum > range.maximum)) then
  828.   begin
  829.     if (range.minimum < 1) then
  830.       range.minimum := 1;
  831.     if (range.maximum > l) then
  832.       range.maximum := l;
  833.     if (range.minimum > l) then
  834.       Exit;
  835.     c := iAbs(range.maximum - range.minimum);
  836.     for i := range.minimum to range.maximum do
  837.       if not InIntArray(exceptions, i) then
  838.         str[i] := fillWith;
  839.   end;
  840. end;
  841.  
  842. function FilterScriptData(scriptData: string): string;
  843. var
  844.   h, i, l: Integer;
  845.   newLines: TIntegerArray;
  846.   comments, strings: TRangeArray;
  847.   tmp: TStringArray;
  848.   go: Boolean;
  849. begin
  850.   Result := string(scriptData);
  851.   l := Length(Result);
  852.   data.script.display := string(Result);
  853.   if (l > 0) then
  854.   begin
  855.     go := FILTER_STRINGS;
  856.     if not go then
  857.       go := FILTER_COMMENTS;
  858.     if go then
  859.     begin
  860.       newLines := PosAllMulti([#13#10, #13, #10], Result, False);
  861.       TrackCaS(scriptData, comments, strings);
  862.       h := High(comments);
  863.       if FILTER_COMMENTS then
  864.       for i := 0 to h do
  865.       begin
  866.         FillStrRangeEx(Result, '!', comments[i], newLines);
  867.         FillStrRangeEx(data.script.display, COMMENT_FILTER, comments[i], newLines);
  868.       end;
  869.       h := High(strings);
  870.       if FILTER_COMMENTS then
  871.       for i := 0 to h do
  872.       begin
  873.         FillStrRangeEx(Result, '!', strings[i], newLines);
  874.         FillStrRangeEx(data.script.display, STRING_FILTER, strings[i], newLines);
  875.       end;
  876.       SetLength(newLines, 0);
  877.       SetLength(comments, 0);
  878.       SetLength(strings, 0);
  879.       Result := ReplaceWrap(Result, '!', '', [rfReplaceAll]);
  880.     end;
  881.     tmp := ExplodeMulti([#13#10, #13, #10], Result);
  882.     TSATrim(tmp);
  883.     Result := TSAConcatEx(tmp, #13#10);
  884.     SetLength(tmp, 0);
  885.     tmp := ExplodeMulti([#13#10, #13, #10], data.script.display);
  886.     data.script.display := '';
  887.     h := High(tmp);
  888.     for i := 0 to h do
  889.       tmp[i] := (' ' + StringOfChar('0', (Length(IntToStr(h + 1)) - Length(IntToStr(i + 1)))) + IntToStr(i + 1) + '. ' + tmp[i]);
  890.     data.script.display := TSAConcatEx(tmp, #13#10);
  891.     SetLength(tmp, 0);
  892.   end;
  893. end;
  894.  
  895. {==============================================================================]
  896.   Explanation: Function for tracing findStr's from data.
  897.                Contains also custom fields for regexTags and regexStrs;
  898.                each tag performs a regex action, that is set to regexStrs, during the search.
  899. [==============================================================================}
  900. function TraceStrsEx(findStr: string; regexTags: array of Char; regexStrs: TStringArray; data: string; modifiers: TRegexModifiers): TRangeArray;
  901. var
  902.   re: TRegExp;
  903.   p, l, r, s, c, h, t: Integer;
  904.   q: string;
  905. begin
  906.   l := Length(data);
  907.   s := Length(findStr);
  908.   if ((l > 0) and (s > 0)) then
  909.   begin
  910.     h := High(regexTags);
  911.     if (High(regexStrs) < h) then
  912.       SetLength(regexStrs, (h + 1));
  913.     SetLength(Result, l);
  914.     q := '.\+*?[^]$(){}=!<>|:-';
  915.     for c := h downto 0 do
  916.     begin
  917.       t := Pos(q, regexTags[c]);
  918.       if (t > 0) then
  919.         Delete(q, t, 1);
  920.     end;
  921.     for c := s downto 1 do
  922.       if (Pos(findStr[c], q) > 0) then
  923.         Insert('\', findStr, c);
  924.     for t := 0 to h do
  925.       findStr := Replace(findStr, regexTags[t], regexStrs[t], [rfReplaceAll]);
  926.     re := TRegExp.Create;
  927.     re.ModifierI := (rm_I in modifiers);
  928.     re.ModifierG := (rm_G in modifiers);
  929.     re.ModifierM := (rm_M in modifiers);
  930.     re.ModifierS := (rm_S in modifiers);
  931.     re.ModifierX := (rm_X in modifiers);
  932.     re.ModifierR := (rm_R in modifiers);
  933.     re.Expression := findStr;
  934.     re.InputString := data;
  935.     p := 1;
  936.     if re.ExecPos(p) then
  937.     repeat
  938.       if (re.Match[0] <> '') then
  939.       begin
  940.         p := (re.MatchPos[0] + 1);
  941.         Result[r].minimum := re.MatchPos[0];
  942.         Result[r].maximum := (Result[r].minimum + (re.MatchLen[0] - 1));
  943.         Inc(r);
  944.       end;
  945.     until not re.ExecPos(p);
  946.     SetLength(Result, r);
  947.     re.Free;
  948.   end else
  949.     SetLength(Result, 0);
  950. end;
  951.  
  952. {==============================================================================]
  953.   Explanation: Returns all the positions, as TRangeArray, of found/matching strings (findStr) in text.
  954.                Uses a set of TMatchMethod (methods) for string matching.
  955.                Contains field for offset.
  956.                If regex field is set as true, then this function searches for the regex you use.
  957. [==============================================================================}
  958. function PosFindEx(text, findStr: string; methods: TMatchMethods; offset: Integer; regex: Boolean): TRangeArray;
  959. var
  960.   rmArr: TRegexMatchArray;
  961.   rmArr2D: T2DRegexMatchArray;
  962.   sb, sa: string;
  963.   r, i, l, f, p, d, o, x, y, abL, abR, abX, abP, spA, spB, spH, spL, spI, spR, spD: Integer;
  964.   re: TRegExp;
  965.   ma, mb, a, s, ol: Boolean;
  966.   c: TIntegerArray;
  967.   t: array of TRangeArray;
  968. begin
  969.   l := Length(text);
  970.   f := Length(findStr);
  971.   if ((l > 0) and (f > 0) and (offset <= l)) then
  972.   begin
  973.     if (offset < 1) then
  974.       offset := 1;
  975.     if not regex then
  976.     begin
  977.       for i := f downto 1 do
  978.         if (Pos(findStr[i], '.\+*?[^]$(){}=!<>|:-') > 0) then
  979.           Insert('\', findStr, i);
  980.       SetLength(Result, l);
  981.       re := TRegExp.Create;
  982.       re.InputString := text;
  983.       re.Expression := findStr;
  984.       if (mmIgnoreCase in methods) then
  985.         re.ModifierI := True;
  986.       re.ModifierM := True;
  987.       a := (mmAll in methods);
  988.       re.ModifierG := (mmGreedyRegex in methods);
  989.       ol := (mmOverlap in methods);
  990.       if not ol then
  991.         o := (Length(findStr) - 1);
  992.       Inc(o);
  993.       p := offset;
  994.       while re.ExecPos(p) do
  995.       begin
  996.         Result[r].minimum := re.MatchPos[0];
  997.         Result[r].maximum := (Result[r].minimum + re.MatchLen[0]);
  998.         p := (Result[r].minimum + o);
  999.         Inc(r);
  1000.       end;
  1001.       p := Offset;
  1002.       re.Free;
  1003.       SetLength(Result, r);
  1004.       if ((r > 0) and (mmWholeWords in methods)) then
  1005.       begin
  1006.         s := (mmStrictWW in methods);
  1007.         if not s then
  1008.           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
  1009.                 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
  1010.                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]; // 0-9
  1011.         case ol of
  1012.           True:
  1013.           begin
  1014.             spH := High(Result);
  1015.             if (spH > -1) then
  1016.             begin
  1017.               SetLength(t, (spH + 1));
  1018.               t[0] := [TRange(Result[0])];
  1019.               if (spH > 0) then
  1020.               begin
  1021.                 spR := 1;
  1022.                 for spI := 1 to spH do
  1023.                 begin
  1024.                   for spA := 0 to (spR - 1) do
  1025.                   begin
  1026.                     spL := Length(t[spA]);
  1027.                     for spB := 0 to (spL - 1) do
  1028.                     begin
  1029.                       spD := IAbs(Result[spI].minimum - t[spA][spB].minimum);
  1030.                       if (spD <= f) then
  1031.                       begin
  1032.                         SetLength(t[spA], (spL + 1));
  1033.                         t[spA][spL].minimum := Integer(Result[spI].minimum);
  1034.                         Break;
  1035.                       end;
  1036.                     end;
  1037.                     if (spB < spL) then
  1038.                       Break;
  1039.                   end;
  1040.                   if (spA >= spR) then
  1041.                   begin
  1042.                     t[spR] := [TRange(Result[spI])];
  1043.                     Inc(spR);
  1044.                   end;
  1045.                 end;
  1046.               end;
  1047.               SetLength(t, spR);
  1048.               spH := High(t);
  1049.               for spI := spH downto 0 do
  1050.               begin
  1051.                 spB := Low(t[spI]);
  1052.                 spA := High(t[spI]);
  1053.                 abX := 1;
  1054.                 abP := t[spI][spB].minimum;
  1055.                 abL := Length(text);
  1056.                 case ((abL > 0) and (abP > 1)) of
  1057.                   True:
  1058.                   begin
  1059.                     if ((abP - abX) < 1) then
  1060.                       abX := ((abP - abX) + (abX - 1));
  1061.                     if (abP > (abL + 1)) then
  1062.                     begin
  1063.                       abR := ((abP - abL) - 1);
  1064.                       abX := (abX - abR);
  1065.                     end;
  1066.                     sb := Copy(text, ((abP - abX) - abR), abX);
  1067.                   end;
  1068.                   False: sb := '';
  1069.                 end;
  1070.                 abX := 1;
  1071.                 abP := (t[spI][spA].minimum + f);
  1072.                 abL := Length(text);
  1073.                 case ((abL > 0) and (abP <= abL)) of
  1074.                   True:
  1075.                   begin
  1076.                     if (abP < 1) then
  1077.                     begin
  1078.                       abX := (abX - iAbs(abP - 1));
  1079.                       abP := 1;
  1080.                     end;
  1081.                     if ((abX > 0) and ((abP + abX) > abL)) then
  1082.                       abX := (abX - (((abP + abX) - abL) - 1));
  1083.                     sa := Copy(text, abP, abX);
  1084.                   end;
  1085.                   False: sa := '';
  1086.                 end;
  1087.                 case s of
  1088.                   True:
  1089.                   begin
  1090.                     mb := (sb = '');
  1091.                     if not mb then
  1092.                       mb := ((sb = ' ') or (sb = #13#10) or (sb = #13) or (sb = #10));
  1093.                     ma := (sa = '');
  1094.                     if not ma then
  1095.                       ma := ((sa = ' ') or (sa = #13#10) or (sa = #13) or (sa = #10));
  1096.                   end;
  1097.                   False:
  1098.                   begin
  1099.                     mb := (sb = '');
  1100.                     if not mb then
  1101.                       mb := not InIntArray(c, Ord(sb[1]));
  1102.                     ma := (sa = '');
  1103.                     if not ma then
  1104.                       ma := not InIntArray(c, Ord(sa[1]));
  1105.                   end;
  1106.                 end;
  1107.                 if not (mb and ma) then
  1108.                 begin
  1109.                   for spD := spI to (spH - 1) do
  1110.                     t[spD] := t[(spD + 1)];
  1111.                   SetLength(t, spH);
  1112.                   Dec(spH);
  1113.                 end;
  1114.               end;
  1115.               spH := High(t);
  1116.               if (spH > -1) then
  1117.               begin
  1118.                 for spI := 0 to spH do
  1119.                   IncEx(spR, (High(t[spI]) + 1));
  1120.                 SetLength(Result, spR);
  1121.                 spR := 0;
  1122.                 for spI := 0 to spH do
  1123.                 begin
  1124.                   spL := High(t[spI]);
  1125.                   for spA := 0 to spL do
  1126.                   begin
  1127.                     Result[spR] := TRange(t[spI][spA]);
  1128.                     Inc(spR);
  1129.                   end;
  1130.                 end;
  1131.                 SetLength(Result, spR);
  1132.               end else
  1133.                 SetLength(Result, 0);
  1134.             end else
  1135.               r := 0;
  1136.           end;
  1137.           False:
  1138.           begin
  1139.             for x := (r - 1) downto 0 do
  1140.             begin
  1141.               abX := 1;
  1142.               abP := Result[x].minimum;
  1143.               abL := Length(text);
  1144.               case ((abL > 0) and (abP > 1)) of
  1145.                 True:
  1146.                 begin
  1147.                   if ((abP - abX) < 1) then
  1148.                     abX := ((abP - abX) + (abX - 1));
  1149.                   if (abP > (abL + 1)) then
  1150.                   begin
  1151.                     abR := ((abP - abL) - 1);
  1152.                     abX := (abX - abR);
  1153.                   end;
  1154.                   sb := Copy(text, ((abP - abX) - abR), abX);
  1155.                 end;
  1156.                 False: sb := '';
  1157.               end;
  1158.               abX := 1;
  1159.               abP := (Result[x].minimum + f);
  1160.               abL := Length(text);
  1161.               case ((abL > 0) and (abP <= abL)) of
  1162.                 True:
  1163.                 begin
  1164.                   if (abP < 1) then
  1165.                   begin
  1166.                     abX := (abX - iAbs(abP - 1));
  1167.                     abP := 1;
  1168.                   end;
  1169.                   if ((abX > 0) and ((abP + abX) > abL)) then
  1170.                     abX := (abX - (((abP + abX) - abL) - 1));
  1171.                   sa := Copy(text, abP, abX);
  1172.                 end;
  1173.                 False: sa := '';
  1174.               end;
  1175.               case s of
  1176.                 True:
  1177.                 begin
  1178.                   mb := (sb = '');
  1179.                   if not mb then
  1180.                     mb := ((sb = ' ') or (sb = #13#10) or (sb = #13) or (sb = #10));
  1181.                   ma := (sa = '');
  1182.                   if not ma then
  1183.                     ma := ((sa = ' ') or (sa = #13#10) or (sa = #13) or (sa = #10));
  1184.                 end;
  1185.                 False:
  1186.                 begin
  1187.                   mb := (sb = '');
  1188.                   if not mb then
  1189.                     mb := not InIntArray(c, Ord(sb[1]));
  1190.                   ma := (sa = '');
  1191.                   if not ma then
  1192.                     ma := not InIntArray(c, Ord(sa[1]));
  1193.                 end;
  1194.               end;
  1195.               if not (mb and ma) then
  1196.               begin
  1197.                 y := (r - 1);
  1198.                 for d := x to (y - 1) do
  1199.                   Result[d] := Result[(d + 1)];
  1200.                 SetLength(Result, y);
  1201.                 Dec(r);
  1202.               end;
  1203.             end;
  1204.           end;
  1205.         end;
  1206.       end;
  1207.       if (not a and (r > 0)) then
  1208.         SetLength(Result, 1);
  1209.     end else
  1210.     begin
  1211.       SetLength(rmArr, l);
  1212.       re := TRegExp.Create;
  1213.       re.InputString := text;
  1214.       re.Expression := findStr;
  1215.       if (mmIgnoreCase in methods) then
  1216.         re.ModifierI := True;
  1217.       re.ModifierM := True;
  1218.       a := (mmAll in methods);
  1219.       re.ModifierG := (mmGreedyRegex in methods);
  1220.       ol := (mmOverlap in methods);
  1221.       p := offset;
  1222.       while re.ExecPos(p) do
  1223.       begin
  1224.         rmArr[r].position := re.MatchPos[0];
  1225.         rmArr[r].text := re.Match[0];
  1226.         rmArr[r].size := re.MatchLen[0];
  1227.         if ol then
  1228.           p := (rmArr[r].position + 1)
  1229.         else
  1230.           p := (rmArr[r].position + rmArr[r].size);
  1231.         Inc(r);
  1232.       end;
  1233.       p := Offset;
  1234.       re.Free;
  1235.       SetLength(rmArr, r);
  1236.       if ((r > 0) and (mmWholeWords in methods)) then
  1237.       begin
  1238.         s := (mmStrictWW in methods);
  1239.         if not s then
  1240.           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
  1241.                 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
  1242.                 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]; // 0-9
  1243.         case ol of
  1244.           True:
  1245.           begin
  1246.             spH := High(rmArr);
  1247.             if (spH > -1) then
  1248.             begin
  1249.               SetLength(rmArr2D, (spH + 1));
  1250.               rmArr2D[0] := [TRegexMatch(rmArr[0])];
  1251.               if (spH > 0) then
  1252.               begin
  1253.                 spR := 1;
  1254.                 for spI := 1 to spH do
  1255.                 begin
  1256.                   for spA := 0 to (spR - 1) do
  1257.                   begin
  1258.                     spL := Length(rmArr2D[spA]);
  1259.                     for spB := 0 to (spL - 1) do
  1260.                     begin
  1261.                       spD := IAbs(rmArr[spI].position - rmArr2D[spA][spB].position);
  1262.                       if (spD <= rmArr2D[spA][spB].size) then
  1263.                       begin
  1264.                         SetLength(rmArr2D[spA], (spL + 1));
  1265.                         rmArr2D[spA][spL] := TRegexMatch(rmArr[spI]);
  1266.                         Break;
  1267.                       end;
  1268.                     end;
  1269.                     if (spB < spL) then
  1270.                       Break;
  1271.                   end;
  1272.                   if (spA >= spR) then
  1273.                   begin
  1274.                     rmArr2D[spR] := [TRegexMatch(rmArr[spI])];
  1275.                     Inc(spR);
  1276.                   end;
  1277.                 end;
  1278.               end;
  1279.               SetLength(rmArr2D, spR);
  1280.               spH := High(rmArr2D);
  1281.               for spI := spH downto 0 do
  1282.               begin
  1283.                 spB := Low(rmArr2D[spI]);
  1284.                 spA := High(rmArr2D[spI]);
  1285.                 abX := 1;
  1286.                 abP := rmArr2D[spI][spB].position;
  1287.                 abL := Length(text);
  1288.                 case ((abL > 0) and (abP > 1)) of
  1289.                   True:
  1290.                   begin
  1291.                     if ((abP - abX) < 1) then
  1292.                       abX := ((abP - abX) + (abX - 1));
  1293.                     if (abP > (abL + 1)) then
  1294.                     begin
  1295.                       abR := ((abP - abL) - 1);
  1296.                       abX := (abX - abR);
  1297.                     end;
  1298.                     sb := Copy(text, ((abP - abX) - abR), abX);
  1299.                   end;
  1300.                   False: sb := '';
  1301.                 end;
  1302.                 abX := 1;
  1303.                 abP := (rmArr2D[spI][spA].position + rmArr2D[spI][spA].size);
  1304.                 abL := Length(text);
  1305.                 case ((abL > 0) and (abP <= abL)) of
  1306.                   True:
  1307.                   begin
  1308.                     if (abP < 1) then
  1309.                     begin
  1310.                       abX := (abX - iAbs(abP - 1));
  1311.                       abP := 1;
  1312.                     end;
  1313.                     if ((abX > 0) and ((abP + abX) > abL)) then
  1314.                       abX := (abX - (((abP + abX) - abL) - 1));
  1315.                     sa := Copy(text, abP, abX);
  1316.                   end;
  1317.                   False: sa := '';
  1318.                 end;
  1319.                 case s of
  1320.                   True:
  1321.                   begin
  1322.                     mb := (sb = '');
  1323.                     if not mb then
  1324.                       mb := ((sb = ' ') or (sb = #13#10) or (sb = #13) or (sb = #10));
  1325.                     ma := (sa = '');
  1326.                     if not ma then
  1327.                       ma := ((sa = ' ') or (sa = #13#10) or (sa = #13) or (sa = #10));
  1328.                   end;
  1329.                   False:
  1330.                   begin
  1331.                     mb := (sb = '');
  1332.                     if not mb then
  1333.                       mb := not InIntArray(c, Ord(sb[1]));
  1334.                     ma := (sa = '');
  1335.                     if not ma then
  1336.                       ma := not InIntArray(c, Ord(sa[1]));
  1337.                   end;
  1338.                 end;
  1339.                 if not (mb and ma) then
  1340.                 begin
  1341.                   for spD := spI to (spH - 1) do
  1342.                     rmArr2D[spD] := rmArr2D[(spD + 1)];
  1343.                   SetLength(rmArr2D, spH);
  1344.                   Dec(spH);
  1345.                 end;
  1346.               end;
  1347.               spH := High(rmArr2D);
  1348.               if (spH > -1) then
  1349.               begin
  1350.                 for spI := 0 to spH do
  1351.                   IncEx(spR, (High(rmArr2D[spI]) + 1));
  1352.                 SetLength(rmArr, spR);
  1353.                 spR := 0;
  1354.                 for spI := 0 to spH do
  1355.                 begin
  1356.                   spL := High(rmArr2D[spI]);
  1357.                   for spA := 0 to spL do
  1358.                   begin
  1359.                     rmArr[spR] := TRegexMatch(rmArr2D[spI][spA]);
  1360.                     Inc(spR);
  1361.                   end;
  1362.                 end;
  1363.                 SetLength(rmArr, spR);
  1364.                 r := spR;
  1365.               end else
  1366.                 SetLength(rmArr, 0);
  1367.             end else
  1368.               r := 0;
  1369.           end;
  1370.           False:
  1371.           begin
  1372.             for x := (r - 1) downto 0 do
  1373.             begin
  1374.               abX := 1;
  1375.               abP := rmArr[x].position;
  1376.               abL := Length(text);
  1377.               case ((abL > 0) and (abP > 1)) of
  1378.                 True:
  1379.                 begin
  1380.                   if ((abP - abX) < 1) then
  1381.                     abX := ((abP - abX) + (abX - 1));
  1382.                   if (abP > (abL + 1)) then
  1383.                   begin
  1384.                     abR := ((abP - abL) - 1);
  1385.                     abX := (abX - abR);
  1386.                   end;
  1387.                   sb := Copy(text, ((abP - abX) - abR), abX);
  1388.                 end;
  1389.                 False: sb := '';
  1390.               end;
  1391.               abX := 1;
  1392.               abP := (rmArr[x].position + rmArr[x].size);
  1393.               abL := Length(text);
  1394.               case ((abL > 0) and (abP <= abL)) of
  1395.                 True:
  1396.                 begin
  1397.                   if (abP < 1) then
  1398.                   begin
  1399.                     abX := (abX - iAbs(abP - 1));
  1400.                     abP := 1;
  1401.                   end;
  1402.                   if ((abX > 0) and ((abP + abX) > abL)) then
  1403.                     abX := (abX - (((abP + abX) - abL) - 1));
  1404.                   sa := Copy(text, abP, abX);
  1405.                 end;
  1406.                 False: sa := '';
  1407.               end;
  1408.               case s of
  1409.                 True:
  1410.                 begin
  1411.                   mb := (sb = '');
  1412.                   if not mb then
  1413.                     mb := ((sb = ' ') or (sb = #13#10) or (sb = #13) or (sb = #10));
  1414.                   ma := (sa = '');
  1415.                   if not ma then
  1416.                     ma := ((sa = ' ') or (sa = #13#10) or (sa = #13) or (sa = #10));
  1417.                 end;
  1418.                 False:
  1419.                 begin
  1420.                   mb := (sb = '');
  1421.                   if not mb then
  1422.                     mb := not InIntArray(c, Ord(sb[1]));
  1423.                   ma := (sa = '');
  1424.                   if not ma then
  1425.                     ma := not InIntArray(c, Ord(sa[1]));
  1426.                 end;
  1427.               end;
  1428.               if not (mb and ma) then
  1429.               begin
  1430.                 y := (r - 1);
  1431.                 for d := x to (y - 1) do
  1432.                   rmArr[d] := rmArr[(d + 1)];
  1433.                 SetLength(rmArr, y);
  1434.                 Dec(r);
  1435.               end;
  1436.             end;
  1437.           end;
  1438.         end;
  1439.       end;
  1440.       case (r > 0) of
  1441.         True:
  1442.         begin
  1443.           if not a then
  1444.             r := 1;
  1445.           SetLength(Result, r);
  1446.           for i := 0 to (r - 1) do
  1447.           begin
  1448.             Result[i].minimum := rmArr[i].position;
  1449.             Result[i].maximum := (Result[i].minimum + rmArr[i].size);
  1450.           end;
  1451.         end;
  1452.         False: SetLength(Result, 0);
  1453.       end;
  1454.     end;
  1455.   end else
  1456.     SetLength(Result, 0);
  1457. end;
  1458.  
  1459. function PositionToLine(position: Integer): Integer;
  1460. var
  1461.   h: Integer;
  1462. begin
  1463.   Result := 1;
  1464.   h := High(data.script.linePositions);
  1465.   if (h > -1) then
  1466.   case (h > 0) of
  1467.     True:
  1468.     for Result := 1 to (h + 1) do
  1469.       if (position < data.script.linePositions[(Result - 1)]) then
  1470.         Break;
  1471.     False:
  1472.     if (position >= data.script.linePositions[0]) then
  1473.       Result := 2;
  1474.   end;
  1475.   Dec(Result);
  1476. end;
  1477.  
  1478. procedure FindThreats;
  1479. var
  1480.   a, b, x, y, t, i, d, st, tt, it, z, l, v, o: Integer;
  1481.   f: TRangeArray;
  1482.   mx, mn, zr: Boolean;
  1483. begin
  1484.   data.timeStamp := TimeStamp;
  1485.   st := GetSystemTime;
  1486.   for t := 0 to High(data.threat) do
  1487.   begin
  1488.     data.threat[t].timeStamp := TimeStamp;
  1489.     tt := GetSystemTime;
  1490.     if data.threat[t].enabled then
  1491.     for i := 0 to High(data.threat[t].item) do
  1492.     begin
  1493.       data.threat[t].item[i].timeStamp := TimeStamp;
  1494.       it := GetSystemTime;
  1495.       if data.threat[t].item[i].enabled then
  1496.       begin
  1497.         f := PosFindEx(data.script.filtered, data.threat[t].item[i].detect.text, data.threat[t].item[i].detect.methods, 1, data.threat[t].item[i].detect.regex);
  1498.         y := High(f);
  1499.         mn := (data.threat[t].item[i].detect.requirement.minimum = -1);
  1500.         if not mn then
  1501.           mn := ((y + 1) >= data.threat[t].item[i].detect.requirement.minimum);
  1502.         mx := (data.threat[t].item[i].detect.requirement.maximum = -1);
  1503.         if not mx then
  1504.           mx := ((y + 1) <= data.threat[t].item[i].detect.requirement.maximum);
  1505.         zr := ((y = -1) and (mn and mx));
  1506.         if (mn and mx) then
  1507.         begin
  1508.           if not zr then
  1509.           begin
  1510.             b := High(data.threat[t].item[i].detect.filters);
  1511.             for a := 0 to b do
  1512.             begin
  1513.               data.threat[t].item[i].detect.filters[a].positions := TraceStrsEx(data.threat[t].item[i].detect.filters[a].text, data.threat[t].item[i].detect.filters[a].regexTags, data.threat[t].item[i].detect.filters[a].regexStrs, data.script.filtered, TRegexModifiers(data.threat[t].item[i].detect.filters[a].modifiers));
  1514.               for d := y downto 0 do
  1515.                 if (TRAContains(data.threat[t].item[i].detect.filters[a].positions, f[d].minimum) or TRAContains(data.threat[t].item[i].detect.filters[a].positions, f[d].maximum)) then
  1516.                 begin
  1517.                   TRADelete(f, d);
  1518.                   Dec(y);
  1519.                 end;
  1520.               if (y < 0) then
  1521.                 Break;
  1522.             end;
  1523.           end;
  1524.           if (zr or (y > -1)) then
  1525.           begin
  1526.             case zr of
  1527.               True:
  1528.               begin
  1529.                 z := 1;
  1530.                 IncEx(data.foundThreats, z);
  1531.                 IncEx(data.threat[t].foundItems, z);
  1532.                 SetLength(data.threat[t].item[i].found, z);
  1533.                 data.threat[t].item[i].found[0].timeStamp := TimeStamp;
  1534.                 data.threat[t].item[i].found[0].line := -1;
  1535.               end;
  1536.               False:
  1537.               begin
  1538.                 z := (y + 1);
  1539.                 IncEx(data.foundThreats, z);
  1540.                 IncEx(data.threat[t].foundItems, z);
  1541.                 SetLength(data.threat[t].item[i].found, z);
  1542.                 for x := 0 to y do
  1543.                 begin
  1544.                   data.threat[t].item[i].found[x].timeStamp := TimeStamp;
  1545.                   data.threat[t].item[i].found[x].position := TRange(f[x]);
  1546.                   data.threat[t].item[i].found[x].line := PositionToLine(f[x].minimum);
  1547.                 end;
  1548.               end;
  1549.             end;
  1550.             case data.threat[t].item[i].riskLevel of
  1551.               rl_VeryLow: IncEx(data.points, (POINTS_VERY_LOW * z));
  1552.               rl_Low: IncEx(data.points, (POINTS_LOW * z));
  1553.               rl_Medium: IncEx(data.points, (POINTS_MEDIUM * z));
  1554.               rl_High: IncEx(data.points, (POINTS_HIGH * z));
  1555.               rl_VeryHigh: IncEx(data.points, (POINTS_VERY_HIGH * z));
  1556.             end;
  1557.           end;
  1558.         end;
  1559.       end;
  1560.       data.threat[t].item[i].timing := (GetSystemTime - it);
  1561.     end;
  1562.     data.threat[t].timing := (GetSystemTime - tt);
  1563.   end;
  1564.   data.timing := (GetSystemTime - st);
  1565.   for t := 0 to High(data.threat) do
  1566.     if (data.threat[t].foundItems > 0) then
  1567.     for i := 0 to High(data.threat[t].item) do
  1568.     begin
  1569.       v := 0;
  1570.       z := High(data.threat[t].item[i].found);
  1571.       for x := 0 to z do
  1572.       begin
  1573.         l := Length(data.lineTracker);
  1574.         while (v < l) do
  1575.         begin
  1576.           if (data.threat[t].item[i].found[x].line < data.threat[data.lineTracker[v][0]].item[data.lineTracker[v][1]].found[data.lineTracker[v][2]].line) then
  1577.             Break;
  1578.           Inc(v);
  1579.         end;
  1580.         SetLength(data.lineTracker, (l + 1));
  1581.         if (l > v) then
  1582.         for o := (l - 1) downto v do
  1583.           data.lineTracker[(o + 1)] := data.lineTracker[o];
  1584.         data.lineTracker[v][0] := t;
  1585.         data.lineTracker[v][1] := i;
  1586.         data.lineTracker[v][2] := x;
  1587.       end;
  1588.     end;
  1589. end;
  1590.  
  1591. (*
  1592.   Auther: Officer Barbrady
  1593. *)
  1594. procedure Scan;
  1595. var
  1596.   a, b: Integer;
  1597. begin
  1598.   SetLength(data.lineTracker, 0);
  1599.   data.foundThreats := 0;
  1600.   data.timeStamp := '';
  1601.   for a := 0 to High(data.threat) do
  1602.   begin
  1603.     data.threat[a].foundItems := 0;
  1604.     data.threat[a].timeStamp := '';
  1605.     for b := 0 to High(data.threat[a].item) do
  1606.     begin
  1607.       data.threat[a].item[b].timeStamp := '';
  1608.       SetLength(data.threat[a].item[b].found, 0);
  1609.     end;
  1610.   end;
  1611.   data.threat[0].enabled := SOCKET_SCAN;
  1612.   data.threat[1].enabled := HTTP_SCAN;
  1613.   data.threat[2].enabled := WEB_SCAN;
  1614.   data.threat[3].enabled := FILE_SCAN;
  1615.   data.threat[4].enabled := CODE_SCAN;
  1616.   data.threat[5].enabled := CODE_SCAN;
  1617.   for a := 0 to 5 do
  1618.     for b := 0 to High(data.threat[a].item) do
  1619.       data.threat[a].item[b].enabled := True;
  1620.   FindThreats;
  1621.   WriteLn(ParseTextReport);
  1622. end;
  1623.  
  1624. (*
  1625.   Auther: Officer Barbrady
  1626. *)
  1627. procedure OpenThread(Sender: TObject);
  1628. begin
  1629.   OpenWebsite('http://villavu.com/forum/showthread.php?t=103408');
  1630. end;
  1631.  
  1632. (*
  1633.   Auther: Officer Barbrady
  1634. *)
  1635. procedure SaveFormInfo(Sender: TObject);
  1636. var
  1637.   tmp: TStringArray;
  1638. begin
  1639.   ScanButton.Caption := 'Scanning... Please wait!';
  1640.   totalTiming := GetSystemTime;
  1641.   DsgnForm.ModalResult := mrOk;
  1642.   tmp := ExplodeMulti([#13#10, #13, #10], ScriptEdit.Text);
  1643.   data.script.original := TSAConcatEx(tmp, #13#10);
  1644.   SetLength(tmp, 0);
  1645.   data.script.filtered := FilterScriptData(data.script.original);
  1646.   Indentation(data.script.filtered, 1);
  1647.   data.script.linePositions := PosAll(#13#10, data.script.filtered);
  1648.   TIAInsert(data.script.linePositions, 0, 1);
  1649.   pressed := True;
  1650.   DsgnForm.Close;
  1651. end;
  1652.  
  1653. procedure ResizeGUI(sender: TObject);
  1654. begin
  1655.   with ScriptEdit do
  1656.   begin
  1657.     Width := (DsgnForm.Width - 10);
  1658.     Height := (DsgnForm.Height - 45);
  1659.   end;
  1660.   with ScanButton do
  1661.   begin
  1662.     Left := ((DsgnForm.Width - 406) div 2);
  1663.     Top := (DsgnForm.Height - 35);
  1664.   end;
  1665.   with UpdateButton do
  1666.   begin
  1667.     Left := (ScanButton.Left + ScanButton.Width + 3);
  1668.     Top := (DsgnForm.Height - 35);
  1669.   end;
  1670. end;
  1671.  
  1672. (*
  1673.   Auther: Officer Barbrady
  1674. *)
  1675. procedure InitForm;
  1676. begin
  1677.   DsgnForm := TForm.Create(nil);
  1678.   with DsgnForm do
  1679.   begin
  1680.     Caption := ('Simba Script Scanner v' + FloatToStr(VERSION));
  1681.     Left := 377;
  1682.     Top := 380;
  1683.     Width := GUI_WIDTH;
  1684.     Height := GUI_HEIGHT;
  1685.     Font.Name := DEFAULT;
  1686.   end;
  1687.   DsgnForm.OnResize := @ResizeGUI;
  1688.   ScriptEdit := TMemo.Create(DsgnForm);
  1689.   with ScriptEdit do
  1690.   begin
  1691.     Parent := DsgnForm;
  1692.     Left := 5;
  1693.     Top := 5;
  1694.     Width := (DsgnForm.Width - 10);
  1695.     Height := (DsgnForm.Height - 45);
  1696.     Font.Name := 'Courier New';
  1697.     Font.Size := 10;
  1698.     WordWrap := False;
  1699.     with ScriptEdit.Lines do
  1700.       Add('Paste script into this box, it will look for suspicious lines of code!');
  1701.     ScrollBars := ssBoth;
  1702.   end;
  1703.   ScanButton := TButton.Create(DsgnForm);
  1704.   with ScanButton do
  1705.   begin
  1706.     Parent := DsgnForm;
  1707.     Caption := 'Scan';
  1708.     Left := ((DsgnForm.Width - 406) div 2);
  1709.     Top := (DsgnForm.Height - 35);
  1710.     Width := 200;
  1711.     Height := 30;
  1712.     Font.Size := 12;
  1713.     OnClick := @SaveFormInfo;
  1714.   end;
  1715.   UpdateButton := TButton.Create(DsgnForm);
  1716.   with UpdateButton do
  1717.   begin
  1718.     Parent := DsgnForm;
  1719.     Caption := 'Update';
  1720.     Left := (ScanButton.Left + ScanButton.Width + 3);
  1721.     Top := (DsgnForm.Height - 35);
  1722.     Width := 200;
  1723.     Height := 30;
  1724.     Font.Size := 12;
  1725.     OnClick := @OpenThread;
  1726.   end;
  1727. end;
  1728.  
  1729. procedure SafeInitForm;
  1730. var
  1731.   v: TVariantArray;
  1732. begin
  1733.   SetLength(V, 0);
  1734.   ThreadSafeCall('InitForm', v);
  1735. end;
  1736.  
  1737. procedure ShowFormModal;
  1738. begin
  1739.   DsgnForm.ShowModal;
  1740. end;
  1741.  
  1742. procedure SafeShowFormModal;
  1743. var
  1744.   v: TVariantArray;
  1745. begin
  1746.   SetLength(V, 0);
  1747.   ThreadSafeCall('ShowFormModal', v);
  1748. end;
  1749.  
  1750. begin
  1751.   ClearDebug;
  1752.   SetupThreats;
  1753.   try
  1754.     SafeInitForm;
  1755.     SafeShowFormModal;
  1756.     if pressed then
  1757.       Scan;
  1758.   except
  1759.     WriteLn('Error with form :(');
  1760.   finally
  1761.     DsgnForm.Free;
  1762.     data.script.original := '';
  1763.     data.script.filtered := '';
  1764.     data.script.display := '';
  1765.     SetLength(data.threat, 0);
  1766.     data.foundThreats := 0;
  1767.     data.timeStamp := '';
  1768.     SetLength(data.script.linePositions, 0);
  1769.     SetLength(data.lineTracker, 0);
  1770.   end;
  1771. end.
Advertisement
Add Comment
Please, Sign In to add comment