Delphiz

by Delphiz on December 23rd, 2010
No notes
Syntax: No syntax
Show lines - Hide lines - Show in textbox - Download
unction DecryptServerResponse(const nMode : Integer; const cData: AnsiString; var cOut : AnsiString) : Integer;
var
  table : Array [0..14] of AnsiChar = ( Chr(0), ' ', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', Chr(13) );
  bBuffer : Array of Byte;
  offset, len : Integer;
  i, size, b, c : Byte;
  s: AnsiString;
 
begin
 
  Result := -1;
  cOut := '';
  s := HexStrCodeToStr(cData);
  len := Length(s);
 
  // nMode = 255
  // non in game, allora usa il decrypt semplice
  if (nMode = $ff) then
  begin
    for I := 1 to Length(s)  do
    begin
         c := Byte(s[I]);
         c := Byte(c - $f);
         cOut := cOut + Chr(c);
    end;
    Exit;
  end;
 
  offset := 0;
  SetLength(bBuffer, len);
  Move(Pointer(s), bBuffer[0], len);
 
  try
     while ((len > 0) and (bBuffer[offset] <> $FF)) do
     begin
          size := bBuffer[offset];
          Inc(offset);
          if ((size and $80) = 0) then
          begin
               for i := 0 to size-1 do
               begin
                   cOut := cOut + Chr(bBuffer[offset] xor $FF);
                   Inc(offset);
               end;
          end
          else
          begin
               size := size and $7f;
               i := 0;
               while (i < size) do
               begin
 
                   c := bBuffer[offset];
                   Inc(Offset);
                   cOut := cOut + Chr(Ord(table[(c and $F0) shr 4]));
 
                   if (Ord(table[(c and $0F)]) <> $00) then
                      cOut := cOut + Chr(Ord(table[(c and $0F)]));
 
                    i := i + 2;
               end;
          end;
          len := len - size;
     end;
 
     if ((offset > 0) and (bBuffer[offset] = $FF)) then
     begin
          Inc(offset);
          cOut := cOut + Chr($ff);
     end;
 
     Result := offset;
  except
  begin
       Result :=-1;
  end;
 
end;

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS