|
@@ -172,8 +172,9 @@ interface
|
|
|
|
|
|
TCoffObjInput = class(tObjInput)
|
|
TCoffObjInput = class(tObjInput)
|
|
private
|
|
private
|
|
- FCoffsyms,
|
|
|
|
- FCoffStrs : tdynamicarray;
|
|
|
|
|
|
+ FCoffsyms : tdynamicarray;
|
|
|
|
+ FCoffStrs : PChar;
|
|
|
|
+ FCoffStrSize: longword;
|
|
{ Convert symidx -> TObjSymbol }
|
|
{ Convert symidx -> TObjSymbol }
|
|
FSymTbl : ^TObjSymbolArray;
|
|
FSymTbl : ^TObjSymbolArray;
|
|
{ Convert secidx -> TObjSection }
|
|
{ Convert secidx -> TObjSection }
|
|
@@ -1567,7 +1568,8 @@ const pemagic : array[0..3] of byte = (
|
|
destructor TCoffObjInput.destroy;
|
|
destructor TCoffObjInput.destroy;
|
|
begin
|
|
begin
|
|
FCoffSyms.free;
|
|
FCoffSyms.free;
|
|
- FCoffStrs.free;
|
|
|
|
|
|
+ if assigned(FCoffStrs) then
|
|
|
|
+ freemem(FCoffStrs);
|
|
if assigned(FSymTbl) then
|
|
if assigned(FSymTbl) then
|
|
freemem(FSymTbl);
|
|
freemem(FSymTbl);
|
|
if assigned(FSecTbl) then
|
|
if assigned(FSecTbl) then
|
|
@@ -1590,12 +1592,9 @@ const pemagic : array[0..3] of byte = (
|
|
|
|
|
|
function TCoffObjInput.Read_str(strpos:longword):string;
|
|
function TCoffObjInput.Read_str(strpos:longword):string;
|
|
begin
|
|
begin
|
|
- FCoffStrs.Seek(strpos-4);
|
|
|
|
- FCoffStrs.Read(result[1],255);
|
|
|
|
- result[255]:=#0;
|
|
|
|
- result[0]:=chr(strlen(@result[1]));
|
|
|
|
- if result='' then
|
|
|
|
|
|
+ if (FCoffStrs=nil) or (strpos>=FCoffStrSize) or (FCoffStrs[strpos]=#0) then
|
|
Internalerror(200205172);
|
|
Internalerror(200205172);
|
|
|
|
+ result:=string(PChar(@FCoffStrs[strpos]));
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -1822,7 +1821,6 @@ const pemagic : array[0..3] of byte = (
|
|
function TCoffObjInput.ReadObjData(AReader:TObjectreader;objdata:TObjData):boolean;
|
|
function TCoffObjInput.ReadObjData(AReader:TObjectreader;objdata:TObjData):boolean;
|
|
var
|
|
var
|
|
secalign : shortint;
|
|
secalign : shortint;
|
|
- strsize,
|
|
|
|
strpos,
|
|
strpos,
|
|
i : longint;
|
|
i : longint;
|
|
code : longint;
|
|
code : longint;
|
|
@@ -1837,7 +1835,6 @@ const pemagic : array[0..3] of byte = (
|
|
InputFileName:=AReader.FileName;
|
|
InputFileName:=AReader.FileName;
|
|
result:=false;
|
|
result:=false;
|
|
FCoffSyms:=TDynamicArray.Create(SymbolMaxGrow);
|
|
FCoffSyms:=TDynamicArray.Create(SymbolMaxGrow);
|
|
- FCoffStrs:=TDynamicArray.Create(StrsMaxGrow);
|
|
|
|
with TCoffObjData(objdata) do
|
|
with TCoffObjData(objdata) do
|
|
begin
|
|
begin
|
|
{ Read COFF header }
|
|
{ Read COFF header }
|
|
@@ -1862,15 +1859,23 @@ const pemagic : array[0..3] of byte = (
|
|
exit;
|
|
exit;
|
|
end;
|
|
end;
|
|
{ Strings }
|
|
{ Strings }
|
|
- if not AReader.Read(strsize,4) then
|
|
|
|
|
|
+ if not AReader.Read(FCoffStrSize,4) then
|
|
begin
|
|
begin
|
|
InputError('Error reading COFF string table');
|
|
InputError('Error reading COFF string table');
|
|
exit;
|
|
exit;
|
|
end;
|
|
end;
|
|
- if (strsize>4) and not AReader.ReadArray(FCoffStrs,Strsize-4) then
|
|
|
|
|
|
+ if (FCoffStrSize>4) then
|
|
begin
|
|
begin
|
|
- InputError('Error reading COFF string table');
|
|
|
|
- exit;
|
|
|
|
|
|
+ { allocate an extra byte and null-terminate }
|
|
|
|
+ GetMem(FCoffStrs,FCoffStrSize+1);
|
|
|
|
+ FCoffStrs[FCoffStrSize]:=#0;
|
|
|
|
+ for i:=0 to 3 do
|
|
|
|
+ FCoffStrs[i]:=#0;
|
|
|
|
+ if not AReader.Read(FCoffStrs[4],FCoffStrSize-4) then
|
|
|
|
+ begin
|
|
|
|
+ InputError('Error reading COFF string table');
|
|
|
|
+ exit;
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
{ Section headers }
|
|
{ Section headers }
|
|
{ Allocate SecIdx -> TObjSection table, secidx is 1-based }
|
|
{ Allocate SecIdx -> TObjSection table, secidx is 1-based }
|
|
@@ -1907,14 +1912,14 @@ const pemagic : array[0..3] of byte = (
|
|
end;
|
|
end;
|
|
if (Length(secname)>3) and (secname[2] in ['e','f','i','p','r']) then
|
|
if (Length(secname)>3) and (secname[2] in ['e','f','i','p','r']) then
|
|
begin
|
|
begin
|
|
- if (Copy(secname,1,6)='.edata') or
|
|
|
|
- (Copy(secname,1,5)='.rsrc') or
|
|
|
|
|
|
+ if (Pos('.edata',secname)=1) or
|
|
|
|
+ (Pos('.rsrc',secname)=1) or
|
|
{$ifndef x86_64}
|
|
{$ifndef x86_64}
|
|
- (Copy(secname,1,6)='.pdata') or
|
|
|
|
|
|
+ (Pos('.pdata',secname)=1) or
|
|
{$endif}
|
|
{$endif}
|
|
- (Copy(secname,1,4)='.fpc') then
|
|
|
|
|
|
+ (Pos('.fpc',secname)=1) then
|
|
include(secoptions,oso_keep);
|
|
include(secoptions,oso_keep);
|
|
- if (Copy(secname,1,6)='.idata') then
|
|
|
|
|
|
+ if (Pos('.idata',secname)=1) then
|
|
begin
|
|
begin
|
|
{ TODO: idata keep can maybe replaced with grouping of text and idata}
|
|
{ TODO: idata keep can maybe replaced with grouping of text and idata}
|
|
include(secoptions,oso_keep);
|
|
include(secoptions,oso_keep);
|
|
@@ -1938,7 +1943,8 @@ const pemagic : array[0..3] of byte = (
|
|
{ Relocs }
|
|
{ Relocs }
|
|
ObjSectionList.ForEachCall(@objsections_read_relocs,nil);
|
|
ObjSectionList.ForEachCall(@objsections_read_relocs,nil);
|
|
end;
|
|
end;
|
|
- FCoffStrs.Free;
|
|
|
|
|
|
+ if assigned(FCoffStrs) then
|
|
|
|
+ freemem(FCoffStrs);
|
|
FCoffStrs:=nil;
|
|
FCoffStrs:=nil;
|
|
FCoffSyms.Free;
|
|
FCoffSyms.Free;
|
|
FCoffSyms:=nil;
|
|
FCoffSyms:=nil;
|