DmBel 1 year ago
parent
commit
e92fd4434f
4 changed files with 120 additions and 123 deletions
  1. 15 16
      blcksock.pas
  2. 4 0
      smtpsend.pas
  3. 87 87
      synacode.pas
  4. 14 20
      synautil.pas

+ 15 - 16
blcksock.pas

@@ -323,9 +323,9 @@ type
     FNonBlockMode: Boolean;
     FMaxLineLength: Integer;
     FMaxSendBandwidth: Integer;
-    FNextSend: UInt32;
+    FNextSend: FixedUInt;
     FMaxRecvBandwidth: Integer;
-    FNextRecv: UInt32;
+    FNextRecv: FixedUInt;
     FConvertLineEnd: Boolean;
     FLastCR: Boolean;
     FLastLF: Boolean;
@@ -377,7 +377,7 @@ type
     procedure DoMonitor(Writing: Boolean; const Buffer: TMemory; Len: Integer);
     procedure DoCreateSocket;
     procedure DoHeartbeat;
-    procedure LimitBandwidth(Length: Integer; MaxB: integer; var Next: UInt32);
+    procedure LimitBandwidth(Length: Integer; MaxB: integer; var Next: FixedUInt);
     procedure SetBandwidth(Value: Integer);
     function TestStopFlag: Boolean;
     procedure InternalSendStream(const Stream: TStream; WithSize, Indy: boolean); virtual;
@@ -1509,9 +1509,9 @@ type
     TTL: Byte;
     Protocol: Byte;
     CheckSum: Word;
-    SourceIp: UInt32;
-    DestIp: UInt32;
-    Options: UInt32;
+    SourceIp: FixedUInt;
+    DestIp: FixedUInt;
+    Options: FixedUInt;
   end;
 
   {:@abstract(Parent class of application protocol implementations.)
@@ -1858,8 +1858,7 @@ procedure TBlockSocket.DelayedOption(const Value: TSynaOption);
 begin
   if FSocket = INVALID_SOCKET then
   begin
-    SetLength(FDelayedOptions, Length(FDelayedOptions) + 1);
-    FDelayedOptions[High(FDelayedOptions)] := Value;
+    FDelayedOptions := FDelayedOptions + [Value];
   end
   else
     SetDelayedOption(Value);
@@ -2113,10 +2112,10 @@ begin
   MaxRecvBandwidth := Value;
 end;
 
-procedure TBlockSocket.LimitBandwidth(Length: Integer; MaxB: integer; var Next: UInt32);
+procedure TBlockSocket.LimitBandwidth(Length: Integer; MaxB: integer; var Next: FixedUInt);
 var
-  x: UInt32;
-  y: UInt32;
+  x: FixedUInt;
+  y: FixedUInt;
   n: integer;
 begin
   if FStopFlag then
@@ -2356,7 +2355,7 @@ function TBlockSocket.RecvBufferEx(Buffer: TMemory; Len: Integer;
 var
   s: TSynaBytes;
   rl, l: integer;
-  ti: UInt32;
+  ti: FixedUInt;
 {$IFDEF CIL}
   n: integer;
   b: TMemory;
@@ -2444,7 +2443,7 @@ begin
   begin
     {$IFDEF MSWINDOWS}
     //not drain CPU on large downloads...
-    Sleep(0);
+    Sleep(10{0});
     {$ENDIF}
     x := WaitingData;
     if x > 0 then
@@ -2529,7 +2528,7 @@ var
   CorCRLF: Boolean;
   t: string;
   tl: integer;
-  ti: UInt32;
+  ti: FixedUInt;
 begin
   ResetLastError;
   Result := '';
@@ -3507,7 +3506,7 @@ begin
           ;
         2:
           begin
-            buf := #1 + Char(Length(FSocksUsername)) + FSocksUsername +
+            Buf := #1 + Char(Length(FSocksUsername)) + FSocksUsername +
               Char(Length(FSocksPassword)) + FSocksPassword;
             SendString(Buf);
             Buf := RecvBufferStr(2, FSocksTimeout);
@@ -3531,7 +3530,7 @@ end;
 function TSocksBlockSocket.SocksRequest(Cmd: Byte;
   const IP, Port: string): Boolean;
 var
-  buf: string;
+  Buf: string;
 begin
   FBypassFlag := True;
   try

+ 4 - 0
smtpsend.pas

@@ -923,6 +923,7 @@ begin
   Result := False;
   SMTP := TSMTPSend.Create;
   try
+  try
 // if you need SOCKS5 support, uncomment next lines:
     // SMTP.Sock.SocksIP := '127.0.0.1';
     // SMTP.Sock.SocksPort := '1080';
@@ -956,6 +957,9 @@ begin
   finally
     SMTP.Free;
   end;
+  except
+   Exit(False);
+  end;
 end;
 
 function SendToEx(const MailFrom, MailTo, Subject, SMTPHost: string;

+ 87 - 87
synacode.pas

@@ -130,110 +130,110 @@ const
 
 {:Decodes triplet encoding with a given character delimiter. It is used for
  decoding quoted-printable or URL encoding.}
-function DecodeTriplet(const Value: String; Delimiter: Char): String;
+function DecodeTriplet(const Value: AnsiString; Delimiter: AnsiChar): AnsiString;
 
 {:Decodes a string from quoted printable form. (also decodes triplet sequences
  like '=7F')}
-function DecodeQuotedPrintable(const Value: String): String;
+function DecodeQuotedPrintable(const Value: AnsiString): AnsiString;
 
 {:Decodes a string of URL encoding. (also decodes triplet sequences like '%7F')}
-function DecodeURL(const Value: String): String;
+function DecodeURL(const Value: AnsiString): AnsiString;
 
 {:Performs triplet encoding with a given character delimiter. Used for encoding
  quoted-printable or URL encoding.}
-function EncodeTriplet(const Value: String; Delimiter: Char;
-  Specials: TSpecials): String;
+function EncodeTriplet(const Value: AnsiString; Delimiter: AnsiChar;
+  Specials: TSpecials): AnsiString;
 
 {:Encodes a string to triplet quoted printable form. All @link(NonAsciiChar)
  are encoded.}
-function EncodeQuotedPrintable(const Value: String): String;
+function EncodeQuotedPrintable(const Value: AnsiString): AnsiString;
 
 {:Encodes a string to triplet quoted printable form. All @link(NonAsciiChar) and
  @link(SpecialChar) are encoded.}
-function EncodeSafeQuotedPrintable(const Value: String): String;
+function EncodeSafeQuotedPrintable(const Value: AnsiString): AnsiString;
 
 {:Encodes a string to URL format. Used for encoding data from a form field in
  HTTP, etc. (Encodes all critical characters including characters used as URL
  delimiters ('/',':', etc.)}
-function EncodeURLElement(const Value: String): String;
+function EncodeURLElement(const Value: AnsiString): AnsiString;
 
 {:Encodes a string to URL format. Used to encode critical characters in all
  URLs.}
-function EncodeURL(const Value: String): String;
+function EncodeURL(const Value: AnsiString): AnsiString;
 
 {:Decode 4to3 encoding with given table. If some element is not found in table,
  first item from table is used. This is good for buggy coded items by Microsoft
  Outlook. This software sometimes using wrong table for UUcode, where is used
  ' ' instead '`'.}
-function Decode4to3(const Value, Table: String): String;
+function Decode4to3(const Value, Table: AnsiString): AnsiString;
 
 {:Decode 4to3 encoding with given REVERSE table. Using this function with
 reverse table is much faster then @link(Decode4to3). This function is used
 internally for Base64, UU or XX decoding.}
-function Decode4to3Ex(const Value, Table: String): String;
+function Decode4to3Ex(const Value, Table: AnsiString): AnsiString;
 
 {:Encode by system 3to4 (used by Base64, UU coding, etc) by given table.}
-function Encode3to4(const Value, Table: String): String;
+function Encode3to4(const Value, Table: AnsiString): AnsiString;
 
 {:Decode string from base64 format.}
-function DecodeBase64(const Value: String): String;
+function DecodeBase64(const Value: AnsiString): AnsiString;
 
 {:Encodes a string to base64 format.}
-function EncodeBase64(const Value: String): String;
+function EncodeBase64(const Value: AnsiString): AnsiString;
 
 {:Decode string from modified base64 format. (used in IMAP, for example.)}
-function DecodeBase64mod(const Value: String): String;
+function DecodeBase64mod(const Value: AnsiString): AnsiString;
 
 {:Encodes a string to  modified base64 format. (used in IMAP, for example.)}
-function EncodeBase64mod(const Value: String): String;
+function EncodeBase64mod(const Value: AnsiString): AnsiString;
 
 {:Decodes a string from UUcode format.}
-function DecodeUU(const Value: String): String;
+function DecodeUU(const Value: AnsiString): AnsiString;
 
 {:encode UUcode. it encode only datas, you must also add header and footer for
  proper encode.}
-function EncodeUU(const Value: String): String;
+function EncodeUU(const Value: AnsiString): AnsiString;
 
 {:Decodes a string from XXcode format.}
-function DecodeXX(const Value: String): String;
+function DecodeXX(const Value: AnsiString): AnsiString;
 
 {:decode line with Yenc code. This code is sometimes used in newsgroups.}
-function DecodeYEnc(const Value: String): String;
+function DecodeYEnc(const Value: AnsiString): AnsiString;
 
 {:Returns a new CRC32 value after adding a new byte of data.}
 function UpdateCrc32(Value: Byte; Crc32: Cardinal): Cardinal;
 
 {:return CRC32 from a value string.}
-function Crc32(const Value: String): Cardinal;
+function Crc32(const Value: AnsiString): Cardinal;
 
 {:Returns a new CRC16 value after adding a new byte of data.}
 function UpdateCrc16(Value: Byte; Crc16: Word): Word;
 
 {:return CRC16 from a value string.}
-function Crc16(const Value: String): Word;
+function Crc16(const Value: AnsiString): Word;
 
 {:Returns a binary string with a RSA-MD5 hashing of "Value" string.}
-function MD5(const Value: String): String;
+function MD5(const Value: AnsiString): AnsiString;
 
 {:Returns a binary string with HMAC-MD5 hash.}
-function HMAC_MD5(const Text: String; Key: String): String;
+function HMAC_MD5(Text, Key: AnsiString): AnsiString;
 
 {:Returns a binary string with a RSA-MD5 hashing of string what is constructed
  by repeating "value" until length is "Len".}
-function MD5LongHash(const Value: String; Len: integer): String;
+function MD5LongHash(const Value: AnsiString; Len: integer): AnsiString;
 
 {:Returns a binary string with a SHA-1 hashing of "Value" string.}
-function SHA1(const Value: String): String;
+function SHA1(const Value: AnsiString): AnsiString;
 
 {:Returns a binary string with HMAC-SHA1 hash.}
-function HMAC_SHA1(const Text: String; Key: String): String;
+function HMAC_SHA1(Text, Key: AnsiString): AnsiString;
 
 {:Returns a binary string with a SHA-1 hashing of string what is constructed
  by repeating "value" until length is "Len".}
-function SHA1LongHash(const Value: String; Len: integer): String;
+function SHA1LongHash(const Value: AnsiString; Len: integer): AnsiString;
 
 {:Returns a binary string with a RSA-MD4 hashing of "Value" string.}
-function MD4(const Value: String): String;
+function MD4(const Value: AnsiString): AnsiString;
 
 implementation
 
@@ -400,10 +400,10 @@ type
 
 {==============================================================================}
 
-function DecodeTriplet(const Value: String; Delimiter: Char): String;
+function DecodeTriplet(const Value: AnsiString; Delimiter: AnsiChar): AnsiString;
 var
   x, l, lv: Integer;
-  c: Char;
+  c: AnsiChar;
   b: Byte;
   bad: Boolean;
 begin
@@ -460,7 +460,7 @@ begin
             else
             begin
               Inc(x, 2);
-              Result[l] := Char(b);
+              Result[l] := AnsiChar(b);
               Inc(l);
             end;
           end;
@@ -475,26 +475,26 @@ end;
 
 {==============================================================================}
 
-function DecodeQuotedPrintable(const Value: String): String;
+function DecodeQuotedPrintable(const Value: AnsiString): AnsiString;
 begin
   Result := DecodeTriplet(Value, '=');
 end;
 
 {==============================================================================}
 
-function DecodeURL(const Value: String): String;
+function DecodeURL(const Value: AnsiString): AnsiString;
 begin
   Result := DecodeTriplet(Value, '%');
 end;
 
 {==============================================================================}
 
-function EncodeTriplet(const Value: String; Delimiter: Char;
-  Specials: TSpecials): String;
+function EncodeTriplet(const Value: AnsiString; Delimiter: AnsiChar;
+  Specials: TSpecials): AnsiString;
 var
   n, l: Integer;
-  s: String;
-  c: Char;
+  s: AnsiString;
+  c: AnsiChar;
 begin
   SetLength(Result, Length(Value) * 3);
   l := 1;
@@ -523,35 +523,35 @@ end;
 
 {==============================================================================}
 
-function EncodeQuotedPrintable(const Value: String): String;
+function EncodeQuotedPrintable(const Value: AnsiString): AnsiString;
 begin
   Result := EncodeTriplet(Value, '=',  ['='] + NonAsciiChar);
 end;
 
 {==============================================================================}
 
-function EncodeSafeQuotedPrintable(const Value: String): String;
+function EncodeSafeQuotedPrintable(const Value: AnsiString): AnsiString;
 begin
   Result := EncodeTriplet(Value, '=', SpecialChar + NonAsciiChar);
 end;
 
 {==============================================================================}
 
-function EncodeURLElement(const Value: String): String;
+function EncodeURLElement(const Value: AnsiString): AnsiString;
 begin
   Result := EncodeTriplet(Value, '%', URLSpecialChar + URLFullSpecialChar);
 end;
 
 {==============================================================================}
 
-function EncodeURL(const Value: String): String;
+function EncodeURL(const Value: AnsiString): AnsiString;
 begin
   Result := EncodeTriplet(Value, '%', URLSpecialChar);
 end;
 
 {==============================================================================}
 
-function Decode4to3(const Value, Table: String): String;
+function Decode4to3(const Value, Table: AnsiString): AnsiString;
 var
   x, y, n, l: Integer;
   d: array[0..3] of Byte;
@@ -574,15 +574,15 @@ begin
       end;
       Inc(x);
     end;
-    Result[l] := Char((D[0] and $3F) shl 2 + (D[1] and $30) shr 4);
+    Result[l] := AnsiChar((D[0] and $3F) shl 2 + (D[1] and $30) shr 4);
     Inc(l);
     if d[2] <> 64 then
     begin
-      Result[l] := Char((D[1] and $0F) shl 4 + (D[2] and $3C) shr 2);
+      Result[l] := AnsiChar((D[1] and $0F) shl 4 + (D[2] and $3C) shr 2);
       Inc(l);
       if d[3] <> 64 then
       begin
-        Result[l] := Char((D[2] and $03) shl 6 + (D[3] and $3F));
+        Result[l] := AnsiChar((D[2] and $03) shl 6 + (D[3] and $3F));
         Inc(l);
       end;
     end;
@@ -592,7 +592,7 @@ begin
 end;
 
 {==============================================================================}
-function Decode4to3Ex(const Value, Table: String): String;
+function Decode4to3Ex(const Value, Table: AnsiString): AnsiString;
 var
   x, y, lv: Integer;
   d: integer;
@@ -620,11 +620,11 @@ begin
     dec(dl);
     if dl <> 0 then
       continue;
-    Result[p] := Char((d shr 16) and $ff);
+    Result[p] := AnsiChar((d shr 16) and $ff);
     inc(p);
-    Result[p] := Char((d shr 8) and $ff);
+    Result[p] := AnsiChar((d shr 8) and $ff);
     inc(p);
-    Result[p] := Char(d and $ff);
+    Result[p] := AnsiChar(d and $ff);
     inc(p);
     d := 0;
     dl := 4;
@@ -633,15 +633,15 @@ begin
     1:
       begin
         d := d shr 2;
-        Result[p] := Char((d shr 8) and $ff);
+        Result[p] := AnsiChar((d shr 8) and $ff);
         inc(p);
-        Result[p] := Char(d and $ff);
+        Result[p] := AnsiChar(d and $ff);
         inc(p);
       end;
     2:
       begin
         d := d shr 4;
-        Result[p] := Char(d and $ff);
+        Result[p] := AnsiChar(d and $ff);
         inc(p);
       end;
   end;
@@ -650,7 +650,7 @@ end;
 
 {==============================================================================}
 
-function Encode3to4(const Value, Table: String): String;
+function Encode3to4(const Value, Table: AnsiString): AnsiString;
 var
   c: Byte;
   n, l: Integer;
@@ -703,38 +703,38 @@ end;
 
 {==============================================================================}
 
-function DecodeBase64(const Value: String): String;
+function DecodeBase64(const Value: AnsiString): AnsiString;
 begin
   Result := Decode4to3Ex(Value, ReTableBase64);
 end;
 
 {==============================================================================}
 
-function EncodeBase64(const Value: String): String;
+function EncodeBase64(const Value: AnsiString): AnsiString;
 begin
   Result := Encode3to4(Value, TableBase64);
 end;
 
 {==============================================================================}
 
-function DecodeBase64mod(const Value: String): String;
+function DecodeBase64mod(const Value: AnsiString): AnsiString;
 begin
   Result := Decode4to3(Value, TableBase64mod);
 end;
 
 {==============================================================================}
 
-function EncodeBase64mod(const Value: String): String;
+function EncodeBase64mod(const Value: AnsiString): AnsiString;
 begin
   Result := Encode3to4(Value, TableBase64mod);
 end;
 
 {==============================================================================}
 
-function DecodeUU(const Value: String): String;
+function DecodeUU(const Value: AnsiString): AnsiString;
 var
-  s: String;
-  uut: String;
+  s: AnsiString;
+  uut: AnsiString;
   x: Integer;
 begin
   Result := '';
@@ -764,7 +764,7 @@ end;
 
 {==============================================================================}
 
-function EncodeUU(const Value: String): String;
+function EncodeUU(const Value: AnsiString): AnsiString;
 begin
   Result := '';
   if Length(Value) < Length(TableUU) then
@@ -773,9 +773,9 @@ end;
 
 {==============================================================================}
 
-function DecodeXX(const Value: String): String;
+function DecodeXX(const Value: AnsiString): AnsiString;
 var
-  s: String;
+  s: AnsiString;
   x: Integer;
 begin
   Result := '';
@@ -803,7 +803,7 @@ end;
 
 {==============================================================================}
 
-function DecodeYEnc(const Value: String): String;
+function DecodeYEnc(const Value: AnsiString): AnsiString;
 var
   C : Byte;
   i: integer;
@@ -821,7 +821,7 @@ begin
       Dec(c, 64);
     end;
     Dec(C, 42);
-    Result := Result + Char(C);
+    Result := Result + AnsiChar(C);
   end;
 end;
 
@@ -835,7 +835,7 @@ end;
 
 {==============================================================================}
 
-function Crc32(const Value: String): Cardinal;
+function Crc32(const Value: AnsiString): Cardinal;
 var
   n: Integer;
 begin
@@ -855,7 +855,7 @@ end;
 
 {==============================================================================}
 
-function Crc16(const Value: String): Word;
+function Crc16(const Value: AnsiString): Word;
 var
   n: Integer;
 begin
@@ -994,7 +994,7 @@ begin
 end;
 
 //fixed by James McAdams
-procedure MDUpdate(var MDContext: TMDCtx; const Data: String; transform: TMDTransform);
+procedure MDUpdate(var MDContext: TMDCtx; const Data: AnsiString; transform: TMDTransform);
 var
   Index, partLen, InputLen, I: integer;
 {$IFDEF SYNACODE_NATIVE}
@@ -1050,7 +1050,7 @@ begin
   end
 end;
 
-function MDFinal(var MDContext: TMDCtx; transform: TMDTransform): String;
+function MDFinal(var MDContext: TMDCtx; transform: TMDTransform): AnsiString;
 var
   Cnt: Word;
   P: Byte;
@@ -1094,14 +1094,14 @@ begin
 //    Move(State, Digest, 16);
     Result := '';
     for i := 0 to 15 do
-      Result := Result + Char(digest[i]);
+      Result := Result + AnsiChar(digest[i]);
   end;
 //  FillChar(MD5Context, SizeOf(TMD5Ctx), #0)
 end;
 
 {==============================================================================}
 
-function MD5(const Value: String): String;
+function MD5(const Value: AnsiString): AnsiString;
 var
   MDContext: TMDCtx;
 begin
@@ -1112,9 +1112,9 @@ end;
 
 {==============================================================================}
 
-function HMAC_MD5(const Text: String; Key: String): String;
+function HMAC_MD5(Text, Key: AnsiString): AnsiString;
 var
-  ipad, opad, s: String;
+  ipad, opad, s: AnsiString;
   n: Integer;
   MDContext: TMDCtx;
 begin
@@ -1124,8 +1124,8 @@ begin
   opad := StringOfChar(HMAC_MD5_OPAD_CHAR, 64);
   for n := 1 to Length(Key) do
   begin
-    ipad[n] := Char(Byte(ipad[n]) xor Byte(Key[n]));
-    opad[n] := Char(Byte(opad[n]) xor Byte(Key[n]));
+    ipad[n] := AnsiChar(Byte(ipad[n]) xor Byte(Key[n]));
+    opad[n] := AnsiChar(Byte(opad[n]) xor Byte(Key[n]));
   end;
   MDInit(MDContext);
   MDUpdate(MDContext, ipad, @MD5Transform);
@@ -1139,7 +1139,7 @@ end;
 
 {==============================================================================}
 
-function MD5LongHash(const Value: String; Len: integer): String;
+function MD5LongHash(const Value: AnsiString; Len: integer): AnsiString;
 var
   cnt, rest: integer;
   l: integer;
@@ -1270,7 +1270,7 @@ begin
 end;
 
 //******************************************************************************
-procedure SHA1Update(var Context: TSHA1Ctx; const Data: String);
+procedure SHA1Update(var Context: TSHA1Ctx; const Data: AnsiString);
 var
   Len: integer;
   n: integer;
@@ -1297,7 +1297,7 @@ begin
 end;
 
 //******************************************************************************
-function SHA1Final(var Context: TSHA1Ctx): String;
+function SHA1Final(var Context: TSHA1Ctx): AnsiString;
 type
   Pinteger = ^integer;
 var
@@ -1326,10 +1326,10 @@ begin
   ArrLongToByte(Context.Hash, Context.HashByte);
   Result := '';
   for i := 0 to 19 do
-    Result := Result + Char(Context.HashByte[i]);
+    Result := Result + AnsiChar(Context.HashByte[i]);
 end;
 
-function SHA1(const Value: String): String;
+function SHA1(const Value: AnsiString): AnsiString;
 var
   SHA1Context: TSHA1Ctx;
 begin
@@ -1340,9 +1340,9 @@ end;
 
 {==============================================================================}
 
-function HMAC_SHA1(const Text: String; Key: String): String;
+function HMAC_SHA1(Text, Key: AnsiString): AnsiString;
 var
-  ipad, opad, s: String;
+  ipad, opad, s: AnsiString;
   n: Integer;
   SHA1Context: TSHA1Ctx;
 begin
@@ -1352,8 +1352,8 @@ begin
   opad := StringOfChar(HMAC_SHA1_OPAD_CHAR, 64);
   for n := 1 to Length(Key) do
   begin
-    ipad[n] := Char(Byte(ipad[n]) xor Byte(Key[n]));
-    opad[n] := Char(Byte(opad[n]) xor Byte(Key[n]));
+    ipad[n] := AnsiChar(Byte(ipad[n]) xor Byte(Key[n]));
+    opad[n] := AnsiChar(Byte(opad[n]) xor Byte(Key[n]));
   end;
   SHA1Init(SHA1Context);
   SHA1Update(SHA1Context, ipad);
@@ -1367,7 +1367,7 @@ end;
 
 {==============================================================================}
 
-function SHA1LongHash(const Value: String; Len: integer): String;
+function SHA1LongHash(const Value: AnsiString; Len: integer): AnsiString;
 var
   cnt, rest: integer;
   l: integer;
@@ -1459,7 +1459,7 @@ end;
 
 {==============================================================================}
 
-function MD4(const Value: String): String;
+function MD4(const Value: AnsiString): AnsiString;
 var
   MDContext: TMDCtx;
 begin

+ 14 - 20
synautil.pas

@@ -76,7 +76,7 @@ uses
 {$ELSE MSWINDOWS}
   {$IFDEF ULTIBO}
     Ultibo,
-  {$ELSE} 
+  {$ELSE}
     {$IFDEF FPC}
       {$IFDEF OS2}
       Dos, TZUtil,
@@ -96,13 +96,12 @@ uses
 {$IFDEF CIL}
   System.IO,
 {$ENDIF}
-  SysUtils, Classes, SynaFpc, synabyte;
+  Math, SysUtils, Classes, SynaFpc, synabyte;
 
 {$IFDEF VER100}
 type
   int64 = integer;
 {$ENDIF}
-
 {$IFDEF POSIX}
 type
   TTimeVal = Posix.SysTime.timeval;
@@ -182,11 +181,11 @@ function SetUTTime(Newdt: TDateTime): Boolean;
 
 {:Return current value of system timer with precizion 1 millisecond. Good for
  measure time difference.}
-function GetTick: UInt32;
+function GetTick: FixedUInt;
 
 {:Return difference between two timestamps. It working fine only for differences
  smaller then maxint. (difference must be smaller then 24 days.)}
-function TickDelta(TickOld, TickNew: UInt32): UInt32;
+function TickDelta(TickOld, TickNew: FixedUInt): FixedUInt;
 
 {:Return two characters, which ordinal values represents the value in byte
  format. (High-endian)}
@@ -340,7 +339,7 @@ procedure ListToHeaders(const Value: TStrings);
 function SwapBytes(Value: integer): integer;
 
 {:read string with requested length form stream.}
-function ReadStrFromStream(const Stream: TStream; len: integer): string;
+function ReadStrFromStream(const Stream: TStream; len: integer): ansistring;
 
 {:write string to stream.}
 procedure WriteStrToStream(const Stream: TStream; const Value: string); {$IFDEF UNICODE} overload;{$ENDIF}
@@ -911,7 +910,7 @@ end;
 {==============================================================================}
 
 {$IFNDEF MSWINDOWS}
-function GetTick: UInt32;
+function GetTick: FixedUInt;
 var
   Stamp: TTimeStamp;
 begin
@@ -919,7 +918,7 @@ begin
   Result := Stamp.Time;
 end;
 {$ELSE}
-function GetTick: UInt32;
+function GetTick: FixedUInt;
 var
   tick, freq: TLargeInteger;
 {$IFDEF VER100}
@@ -933,7 +932,7 @@ begin
     x.QuadPart := (tick.QuadPart / freq.QuadPart) * 1000;
     Result := x.LowPart;
 {$ELSE}
-    Result := Trunc((tick / freq) * 1000) and High(UInt32)
+    Result := Trunc((tick / freq) * 1000) and High(FixedUInt)
 {$ENDIF}
   end
   else
@@ -943,7 +942,7 @@ end;
 
 {==============================================================================}
 
-function TickDelta(TickOld, TickNew: UInt32): UInt32;
+function TickDelta(TickOld, TickNew: FixedUInt): FixedUInt;
 begin
 //if DWord is signed type (older Deplhi),
 // then it not work properly on differencies larger then maxint!
@@ -952,8 +951,8 @@ begin
   begin
     if TickNew < TickOld then
     begin
-      TickNew := TickNew + UInt32(MaxInt) + 1;
-      TickOld := TickOld + UInt32(MaxInt) + 1;
+      TickNew := TickNew + FixedUInt(MaxInt) + 1;
+      TickOld := TickOld + FixedUInt(MaxInt) + 1;
     end;
     Result := TickNew - TickOld;
     if TickNew < TickOld then
@@ -1812,15 +1811,10 @@ end;
 
 {==============================================================================}
 
-function ReadStrFromStream(const Stream: TStream; len: integer): string;
-var
-  x: integer;
-  Buf: TBytes;
+function ReadStrFromStream(const Stream: TStream; len: integer): ansistring;
 begin
-  Setlength(Buf, Len);
-  x := Stream.Read(Buf, Len);
-  Setlength(Buf, x);
-  Result := StringOf(Buf);
+  SetLength(Result, Min(len, Stream.Size));
+  Stream.ReadBuffer(Result[1], Length(Result));
 end;
 
 {==============================================================================}