Browse Source

* Patch from Giulio Bernardi
* ObjectBinaryToText, ObjectTextToBinary and ObjectTextToResource are
endian safe and writing and reading extended type is supported on
machines that don't have an extended type
- TStream.WriteResourceHeader, TStream.ReadResHeader,
TStream.FixupResourceHeader are endian safe

git-svn-id: trunk@9397 -

michael 17 years ago
parent
commit
b363afcd0a
1 changed files with 32 additions and 8 deletions
  1. 32 8
      rtl/objpas/classes/streams.inc

+ 32 - 8
rtl/objpas/classes/streams.inc

@@ -222,17 +222,26 @@
     end;
 
   procedure TStream.WriteResourceHeader(const ResName: string; {!!!: out} var FixupInfo: Integer);
-
+    var
+      ResType, Flags : word;
     begin
+      {$IFDEF ENDIAN_LITTLE}
+      ResType:=$000A;
+      Flags:=$1030;
+      {$ELSE}
+      ResType:=$0A00;
+      Flags:=$3010;
+      {$ENDIF}
+       { Note: This is a Windows 16 bit resource }
        { Numeric resource type }
        WriteByte($ff);
        { Application defined data }
-       WriteWord($0a);
+       WriteWord(ResType);
        { write the name as asciiz }
        WriteBuffer(ResName[1],length(ResName));
        WriteByte(0);
        { Movable, Pure and Discardable }
-       WriteWord($1030);
+       WriteWord(Flags);
        { Placeholder for the resource size }
        WriteDWord(0);
        { Return current stream position so that the resource size can be
@@ -243,35 +252,50 @@
   procedure TStream.FixupResourceHeader(FixupInfo: Integer);
 
     var
-       ResSize : Integer;
+       ResSize,TmpResSize : Integer;
 
     begin
 
       ResSize := Position - FixupInfo;
+      {$IFDEF ENDIAN_BIG}
+      TmpResSize:=SwapEndian(ResSize);
+      {$ELSE}
+      TmpResSize:=ResSize;
+      {$ENDIF}
 
       { Insert the correct resource size into the placeholder written by
         WriteResourceHeader }
       Position := FixupInfo - 4;
-      WriteDWord(ResSize);
+      WriteDWord(TmpResSize);
       { Seek back to the end of the resource }
       Position := FixupInfo + ResSize;
 
     end;
 
   procedure TStream.ReadResHeader;
-
+    var
+      ResType, Flags : word;
     begin
        try
+         { Note: This is a Windows 16 bit resource }
          { application specific resource ? }
          if ReadByte<>$ff then
            raise EInvalidImage.Create(SInvalidImage);
-         if ReadWord<>$000a then
+         ResType:=ReadWord;
+         {$IFDEF ENDIAN_BIG}
+         ResType:=SwapEndian(ResType);
+         {$ENDIF}
+         if ResType<>$000a then
            raise EInvalidImage.Create(SInvalidImage);
          { read name }
          while ReadByte<>0 do
            ;
          { check the access specifier }
-         if ReadWord<>$1030 then
+         Flags:=ReadWord;
+         {$IFDEF ENDIAN_BIG}
+         Flags:=SwapEndian(Flags);
+         {$ENDIF}
+         if Flags<>$1030 then
            raise EInvalidImage.Create(SInvalidImage);
          { ignore the size }
          ReadDWord;