Cecil ignores PE header details when reading executables. #98

Closed
opened 2012-04-16 20:12:13 -05:00 by kg · 3 comments
kg commented 2012-04-16 20:12:13 -05:00 (Migrated from github.com)

Cecil ignores wide swathes of the PE header when reading executables, so if an executable differs even slightly from what it expects a CLR executable to look like, it chokes. In particular, this executable I'm trying to read doesn't have the expected number of data directories, so Cecil throws a pretty generic error at the end of ReadOptionalHeaders.

I think it would be worthwhile to at least pay attention to the NumberOfRvaAndSizes/numberOfDataDir flag in the header and skip the appropriate number of bytes so that you can deal with additional data directories in the executable. It would probably be good to at least read the header fields that contain size and offset information to ensure that you've got the right sizes/offsets - even if you don't use them, you can check that they match your expectations.

Cecil ignores wide swathes of the PE header when reading executables, so if an executable differs even slightly from what it expects a CLR executable to look like, it chokes. In particular, this executable I'm trying to read doesn't have the expected number of data directories, so Cecil throws a pretty generic error at the end of ReadOptionalHeaders. I think it would be worthwhile to at least pay attention to the NumberOfRvaAndSizes/numberOfDataDir flag in the header and skip the appropriate number of bytes so that you can deal with additional data directories in the executable. It would probably be good to at least read the header fields that contain size and offset information to ensure that you've got the right sizes/offsets - even if you don't use them, you can check that they match your expectations.
jbevain commented 2012-04-17 00:25:03 -05:00 (Migrated from github.com)

Please provide an example of such a PE file.

Please provide an example of such a PE file.
kg commented 2012-04-17 00:27:29 -05:00 (Migrated from github.com)

It turned out to actually be a CLR executable with a corrupted header, so I addressed the issue with the person who created the executable. Reading the right number of data directories is still a good idea, though. Do you want me to provide you with the corrupt executable, or do you not care about handling corrupt files?

It turned out to actually be a CLR executable with a corrupted header, so I addressed the issue with the person who created the executable. Reading the right number of data directories is still a good idea, though. Do you want me to provide you with the corrupt executable, or do you not care about handling corrupt files?
jbevain commented 2012-04-17 01:03:36 -05:00 (Migrated from github.com)

Let's do the work when we'll have a valid file which Cecil can't read.

Let's do the work when we'll have a valid file which Cecil can't read.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil#98
No description provided.