Advertisement
Guest User

PCRadio-Activator

a guest
Sep 2nd, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.05 KB | None | 0 0
  1. program Activator;
  2.  
  3. {$R RSRC.RES}
  4. {$R manifest.res}
  5.  
  6. uses
  7.   Winapi.Windows,
  8.   Winapi.Messages,
  9.   System.RegularExpressions,
  10.   System.Classes,
  11.   System.SysUtils,
  12.   IdContext,
  13.   IdCustomHTTPServer,
  14.   IdHTTPServer,
  15.   System.Win.Registry;
  16.  
  17. const
  18.   ORIGINAL_PCRADIO_EXE = 'PCRadioOrig.exe';
  19.   SubKey = 'SOFTWARE\PCRadio\PCR';
  20.   StrKey = 'keybill';
  21.  
  22. var
  23.   steps: Integer = 0;
  24.   Reg: TRegistry;
  25.   str: string;
  26.  
  27. procedure ProcessMessages;
  28. var
  29.   Msg: TMsg;
  30.  
  31.   function ProcessMsg(var Msg: TMsg): Boolean;
  32.   begin
  33.     Result := False;
  34.     if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
  35.     begin
  36.       Result := True;
  37.       if Msg.Message <> WM_QUIT then
  38.       begin
  39.         TranslateMessage(Msg);
  40.         DispatchMessage(Msg);
  41.       end
  42.       else
  43.         DispatchMessage(Msg);
  44.     end;
  45.   end;
  46.  
  47. begin
  48.   while ProcessMsg(Msg) do
  49.     ;
  50. end;
  51.  
  52. function Execute(FileName: string): boolean;
  53. var
  54.   StartupInfo: TStartupInfo;
  55.   ProcessInfo: TProcessInformation;
  56.   exitc: cardinal;
  57. begin
  58.   FillChar(StartupInfo, sizeof(StartupInfo), 0);
  59.   with StartupInfo do
  60.   begin
  61.     cb := Sizeof(StartupInfo);
  62.     dwFlags := STARTF_USESHOWWINDOW;
  63.     wShowWindow := SW_SHOW;
  64.   end;
  65.   Result := CreateProcess(nil, PChar(FileName), nil, nil, false, CREATE_NEW_CONSOLE or
  66.     NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
  67. end;
  68.  
  69. function PatchHosts(const Patch: Boolean = True): Boolean;
  70. const
  71.   subdir = '\drivers\etc\hosts';
  72.   regex0 = '^\s*127\.0\.0\.1\s+bill\.pcradi0\.ru\s*$';
  73.   site0 = '127.0.0.1 bill.pcradi0.ru';
  74. var
  75.   sysdir: array[0..MAX_PATH] of WideChar;
  76.   i: Integer;
  77.   hosts: TStringList;
  78.   r0: Boolean;
  79. begin
  80.   r0 := False;
  81.   GetSystemDirectoryW(@sysdir, Length(sysdir));
  82.   hosts := TStringList.Create;
  83.   with hosts do
  84.   try
  85.     LoadFromFile(StrPas(sysdir) + subdir);
  86.     i := 0;
  87.     while i < Count do
  88.     begin
  89.       if TRegEx.IsMatch(Strings[i], regex0) then
  90.       begin
  91.         if not Patch then
  92.           Delete(i);
  93.         r0 := True;
  94.       end;
  95.       Inc(i);
  96.     end;
  97.     if (not r0) and (Patch) then
  98.       Add(site0);
  99.     Result := (r0);
  100.     SaveToFile(StrPas(sysdir) + subdir);
  101.   except
  102.     Result := False;
  103.   end;
  104.   FreeAndNil(hosts);
  105. end;
  106.  
  107. type
  108.   TFakeServer = class
  109.   private
  110.     HttpServer: TIdHTTPServer;
  111.   public
  112.     constructor Create;
  113.     destructor Destroy; override;
  114.     procedure HttpServerCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
  115.       AResponseInfo: TIdHTTPResponseInfo);
  116.   end;
  117.  
  118. constructor TFakeServer.Create;
  119. begin
  120.   HttpServer := TIdHTTPServer.Create(nil);
  121.   HttpServer.OnCommandGet := HttpServerCommandGet;
  122.   HttpServer.Active := True;
  123. end;
  124.  
  125. destructor TFakeServer.Destroy;
  126. begin
  127.   HttpServer.Active := False;
  128.   FreeAndNil(HttpServer);
  129.   inherited;
  130. end;
  131.  
  132. procedure TFakeServer.HttpServerCommandGet(AContext: TIdContext; ARequestInfo:
  133.   TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
  134. begin
  135.   if (UpperCase(ARequestInfo.Command) = 'POST') and (LowerCase(ARequestInfo.URI) =
  136.     '/player/paywin/activation.php') then
  137.   begin
  138.     AResponseInfo.ContentText := str;
  139.     Inc(steps);
  140.   end;
  141.   if (UpperCase(ARequestInfo.Command) = 'POST') and (LowerCase(ARequestInfo.URI) =
  142.     '/player/paywin/lastdate.php') then
  143.   begin
  144.     AResponseInfo.ContentText := '0';
  145.     Inc(steps);
  146.   end;
  147. end;
  148.  
  149. function RandStr(): string;
  150. var
  151.   i: Integer;
  152. begin
  153.   Randomize;
  154.   SetLength(Result, Random(20) + 5);
  155.   for i := 1 to Length(Result) do
  156.     repeat
  157.       Result[i] := Chr(Random(256));
  158.     until CharInSet(Result[i], ['A'..'Z', 'a'..'z', '0'..'9']);
  159. end;
  160.  
  161. var
  162.   FakeServer: TFakeServer;
  163.  
  164. begin
  165.   PatchHosts(True);
  166.   Reg := TRegistry.Create;
  167.   Reg.OpenKey(SubKey, True);
  168.   str := RandStr();
  169.   Reg.WriteString(StrKey, str);
  170.   Reg.CloseKey;
  171.   FakeServer := TFakeServer.Create;
  172.   Sleep(1000);
  173.   try
  174.     Execute(ExtractFilePath(ParamStr(0)) + ORIGINAL_PCRADIO_EXE);
  175.     repeat
  176.       ProcessMessages;
  177.       Sleep(10);
  178.     until (steps = 1);
  179.   finally
  180.     FreeAndNil(FakeServer);
  181.     FreeAndNil(Reg);
  182.   end;
  183.   PatchHosts(False);
  184. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement