mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 08:19:22 +02:00
* 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 -
This commit is contained in:
parent
02c714aec1
commit
b363afcd0a
@ -222,17 +222,26 @@
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TStream.WriteResourceHeader(const ResName: string; {!!!: out} var FixupInfo: Integer);
|
procedure TStream.WriteResourceHeader(const ResName: string; {!!!: out} var FixupInfo: Integer);
|
||||||
|
var
|
||||||
|
ResType, Flags : word;
|
||||||
begin
|
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 }
|
{ Numeric resource type }
|
||||||
WriteByte($ff);
|
WriteByte($ff);
|
||||||
{ Application defined data }
|
{ Application defined data }
|
||||||
WriteWord($0a);
|
WriteWord(ResType);
|
||||||
{ write the name as asciiz }
|
{ write the name as asciiz }
|
||||||
WriteBuffer(ResName[1],length(ResName));
|
WriteBuffer(ResName[1],length(ResName));
|
||||||
WriteByte(0);
|
WriteByte(0);
|
||||||
{ Movable, Pure and Discardable }
|
{ Movable, Pure and Discardable }
|
||||||
WriteWord($1030);
|
WriteWord(Flags);
|
||||||
{ Placeholder for the resource size }
|
{ Placeholder for the resource size }
|
||||||
WriteDWord(0);
|
WriteDWord(0);
|
||||||
{ Return current stream position so that the resource size can be
|
{ Return current stream position so that the resource size can be
|
||||||
@ -243,35 +252,50 @@
|
|||||||
procedure TStream.FixupResourceHeader(FixupInfo: Integer);
|
procedure TStream.FixupResourceHeader(FixupInfo: Integer);
|
||||||
|
|
||||||
var
|
var
|
||||||
ResSize : Integer;
|
ResSize,TmpResSize : Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
ResSize := Position - FixupInfo;
|
ResSize := Position - FixupInfo;
|
||||||
|
{$IFDEF ENDIAN_BIG}
|
||||||
|
TmpResSize:=SwapEndian(ResSize);
|
||||||
|
{$ELSE}
|
||||||
|
TmpResSize:=ResSize;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ Insert the correct resource size into the placeholder written by
|
{ Insert the correct resource size into the placeholder written by
|
||||||
WriteResourceHeader }
|
WriteResourceHeader }
|
||||||
Position := FixupInfo - 4;
|
Position := FixupInfo - 4;
|
||||||
WriteDWord(ResSize);
|
WriteDWord(TmpResSize);
|
||||||
{ Seek back to the end of the resource }
|
{ Seek back to the end of the resource }
|
||||||
Position := FixupInfo + ResSize;
|
Position := FixupInfo + ResSize;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TStream.ReadResHeader;
|
procedure TStream.ReadResHeader;
|
||||||
|
var
|
||||||
|
ResType, Flags : word;
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
|
{ Note: This is a Windows 16 bit resource }
|
||||||
{ application specific resource ? }
|
{ application specific resource ? }
|
||||||
if ReadByte<>$ff then
|
if ReadByte<>$ff then
|
||||||
raise EInvalidImage.Create(SInvalidImage);
|
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);
|
raise EInvalidImage.Create(SInvalidImage);
|
||||||
{ read name }
|
{ read name }
|
||||||
while ReadByte<>0 do
|
while ReadByte<>0 do
|
||||||
;
|
;
|
||||||
{ check the access specifier }
|
{ 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);
|
raise EInvalidImage.Create(SInvalidImage);
|
||||||
{ ignore the size }
|
{ ignore the size }
|
||||||
ReadDWord;
|
ReadDWord;
|
||||||
|
Loading…
Reference in New Issue
Block a user