File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ use crate::container;
33
33
use crate :: error;
34
34
use crate :: pe:: utils:: pad;
35
35
use crate :: strtab;
36
+ use options:: ParseMode ;
36
37
37
38
use scroll:: { ctx, Pwrite } ;
38
39
@@ -264,15 +265,19 @@ impl<'a> PE<'a> {
264
265
if let Some ( & certificate_table) =
265
266
optional_header. data_directories . get_certificate_table ( )
266
267
{
267
- certificates = certificate_table:: enumerate_certificates (
268
+ let certificates_result = certificate_table:: enumerate_certificates (
268
269
bytes,
269
270
certificate_table. virtual_address ,
270
271
certificate_table. size ,
271
- )
272
- . unwrap_or_else ( |err| {
273
- warn ! ( "Cannot parse CertificateTable: {:?}" , err) ;
274
- Default :: default ( )
275
- } ) ;
272
+ ) ;
273
+
274
+ certificates = match opts. parse_mode {
275
+ ParseMode :: Strict => certificates_result?,
276
+ ParseMode :: Permissive => certificates_result. unwrap_or_else ( |err| {
277
+ warn ! ( "Cannot parse CertificateTable: {:?}" , err) ;
278
+ Default :: default ( )
279
+ } ) ,
280
+ } ;
276
281
277
282
certificate_table. size as usize
278
283
} else {
@@ -529,6 +534,7 @@ impl<'a> TE<'a> {
529
534
let opts = & options:: ParseOptions {
530
535
resolve_rva : false ,
531
536
parse_attribute_certificates : false ,
537
+ parse_mode : ParseMode :: Strict ,
532
538
} ;
533
539
534
540
let mut offset = 0 ;
Original file line number Diff line number Diff line change @@ -8,6 +8,16 @@ pub struct ParseOptions {
8
8
/// memory](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#other-contents-of-the-file).
9
9
/// For on-disk representations, leave as true. Default: true
10
10
pub parse_attribute_certificates : bool ,
11
+ /// Whether or not to end with an error in case of incorrect data or continue parsing if able. Default: ParseMode::Strict
12
+ pub parse_mode : ParseMode ,
13
+ }
14
+
15
+ #[ derive( Debug , Copy , Clone ) ]
16
+ pub enum ParseMode {
17
+ /// Always end with error on incorrect data
18
+ Strict ,
19
+ /// Incorrect data will not cause to end with error if possible
20
+ Permissive ,
11
21
}
12
22
13
23
impl ParseOptions {
@@ -16,6 +26,7 @@ impl ParseOptions {
16
26
ParseOptions {
17
27
resolve_rva : true ,
18
28
parse_attribute_certificates : true ,
29
+ parse_mode : ParseMode :: Strict ,
19
30
}
20
31
}
21
32
}
You can’t perform that action at this time.
0 commit comments