@@ -51,7 +51,7 @@ function TPEResourcesParser.LogInvalidResourceSizesTraverse(
5151begin
5252 if Node.IsLeaf then
5353 if not TResourceTreeLeafNode(Node).ValidSize then
54- TPEImage(FPE).Msg.Write(' Bad size of resource (probably packed): %s' , [Node.GetPath]);
54+ TPEImage(FPE).Msg.Write(SCategoryResources, ' Bad size of resource (probably packed): %s' , [Node.GetPath]);
5555
5656 Result := True;
5757end ;
@@ -66,6 +66,7 @@ function TPEResourcesParser.Parse: TParserResult;
6666 // Check if directory present.
6767 if not Img.DataDirectories.Get(DDIR_RESOURCE, @dir) then
6868 exit(PR_OK);
69+
6970 if dir.IsEmpty then
7071 exit(PR_OK);
7172
@@ -108,7 +109,15 @@ function TPEResourcesParser.ReadEntry(
108109 if not (Img.SeekRVA(RVA + Index * SizeOf(Entry)) and
109110 Img.ReadEx(@Entry, SizeOf(Entry))) then
110111 begin
111- Img.Msg.Write(' Bad resource entry.' );
112+ Img.Msg.Write(SCategoryResources, ' Bad resource entry.' );
113+ exit;
114+ end ;
115+
116+ // Check if RVA is correct.
117+ DataRVA := Entry.DataEntryRVA + FBaseRVA;
118+ if not Img.RVAExists(DataRVA) then
119+ begin
120+ Img.Msg.Write(SCategoryResources, ' Bad entry RVA.' );
112121 exit;
113122 end ;
114123
@@ -119,7 +128,7 @@ function TPEResourcesParser.ReadEntry(
119128 DataRVA := Entry.DataEntryRVA + FBaseRVA;
120129 if not (Img.SeekRVA(DataRVA) and Img.ReadEx(@DataEntry, SizeOf(DataEntry))) then
121130 begin
122- Img.Msg.Write(' Bad resource leaf node.' );
131+ Img.Msg.Write(SCategoryResources, ' Bad resource leaf node.' );
123132 exit;
124133 end ;
125134 LeafNode := TResourceTreeLeafNode.CreateFromEntry(FPE, DataEntry);
@@ -159,7 +168,7 @@ function TPEResourcesParser.ReadEntry(
159168 NameRVA := Entry.NameRVA + FBaseRVA;
160169 if not Img.SeekRVA(NameRVA) then
161170 begin
162- Img.Msg.Write(' Failed to read resource name.' );
171+ Img.Msg.Write(SCategoryResources, ' Failed to read resource name.' );
163172 exit(nil );
164173 end ;
165174 Result.Name := Img.ReadUnicodeStringLenPfx2;
@@ -190,7 +199,7 @@ function TPEResourcesParser.ReadNode(
190199 // Read Directory Table.
191200 if not (Img.SeekRVA(RVA) and Img.ReadEx(@RDT, SizeOf(RDT))) then
192201 begin
193- Img.Msg.Write(' Failed to read resource directory table.' );
202+ Img.Msg.Write(SCategoryResources, ' Failed to read resource directory table.' );
194203 exit(PR_ERROR);
195204 end ;
196205
@@ -201,14 +210,18 @@ function TPEResourcesParser.ReadNode(
201210 // Read named entries.
202211 for i := 1 to RDT.NumberOfNameEntries do
203212 begin
204- ReadEntry(ParentNode, RVA, n, EK_NAME, @RDT);
213+ if ReadEntry(ParentNode, RVA, n, EK_NAME, @RDT) = nil then
214+ exit(PR_ERROR);
215+
205216 inc(n);
206217 end ;
207218
208219 // Read Id entries.
209220 for i := 1 to RDT.NumberOfIDEntries do
210221 begin
211- ReadEntry(ParentNode, RVA, n, EK_ID, @RDT);
222+ if ReadEntry(ParentNode, RVA, n, EK_ID, @RDT) = nil then
223+ exit(PR_ERROR);
224+
212225 inc(n);
213226 end ;
214227
0 commit comments