-
Notifications
You must be signed in to change notification settings - Fork 541
Fix undeclared next_section_virtual_address usage #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nightlark
merged 2 commits into
erocarrera:master
from
gdesmar:undeclared_next_section_virtual_address
Apr 1, 2026
+18
−14
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1145,6 +1145,7 @@ def __init__(self, *args, **kwargs): | |
| self.VirtualAddress_adj = None | ||
| self.section_min_addr = None | ||
| self.section_max_addr = None | ||
| self.index_in_file = None | ||
|
|
||
| def get_PointerToRawData_adj(self): | ||
| if self.PointerToRawData_adj is None and self.PointerToRawData is not None: | ||
|
|
@@ -3679,20 +3680,8 @@ def parse_sections(self, offset, max_offset=0x10000000): | |
| # Set the section's flags according to the Characteristics member | ||
| set_flags(section, section.Characteristics, section_flags) | ||
|
|
||
| if section.__dict__.get( | ||
| "IMAGE_SCN_MEM_WRITE", False | ||
| ) and section.__dict__.get("IMAGE_SCN_MEM_EXECUTE", False): | ||
| if section.Name.rstrip(b"\x00") == b"PAGE" and self.is_driver(): | ||
| # Drivers can have a PAGE section with those flags set without | ||
| # implying that it is malicious | ||
| pass | ||
| else: | ||
| self.__warnings.append( | ||
| f"Suspicious flags set for section {i}. " | ||
| "Both IMAGE_SCN_MEM_WRITE and IMAGE_SCN_MEM_EXECUTE are set. " | ||
| "This might indicate a packed executable." | ||
| ) | ||
|
|
||
| # Set the section's original index as it may change after being sorted by VirtualAddress | ||
| section.index_in_file = i | ||
| self.sections.append(section) | ||
|
|
||
| # Sort the sections by their VirtualAddress and add a field to each of them | ||
|
|
@@ -3707,6 +3696,21 @@ def parse_sections(self, offset, max_offset=0x10000000): | |
| idx + 1 | ||
| ].VirtualAddress | ||
|
|
||
| for section in self.sections: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may be able to use
Better outside of this PR as is not just in this function. |
||
| if section.__dict__.get( | ||
| "IMAGE_SCN_MEM_WRITE", False | ||
| ) and section.__dict__.get("IMAGE_SCN_MEM_EXECUTE", False): | ||
| if section.Name.rstrip(b"\x00") == b"PAGE" and self.is_driver(): | ||
| # Drivers can have a PAGE section with those flags set without | ||
| # implying that it is malicious | ||
| pass | ||
| else: | ||
| self.__warnings.append( | ||
| f"Suspicious flags set for section {section.index_in_file}. " | ||
| "Both IMAGE_SCN_MEM_WRITE and IMAGE_SCN_MEM_EXECUTE are set. " | ||
| "This might indicate a packed executable." | ||
| ) | ||
|
|
||
| if self.FILE_HEADER.NumberOfSections > 0 and self.sections: | ||
| return ( | ||
| offset + self.sections[0].sizeof() * self.FILE_HEADER.NumberOfSections | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the Microsoft official documentation:
Due to us not doing, this is fine for this PR. After this PR could look into whether we need to change to one indexing or just add a comment to explain we use zero indexing. Check what PE-bear or similar does?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment saying we use zero indexing would be good. The output has been zero indexed for long enough that I don't think we want to change it at this time (it would also be a change that would be good to get thoughts from @erocarrera)