Skip to content
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

Handle "empty" sections with raw pointer and size set to 0x0 #1

Open
matouskozak opened this issue Feb 16, 2024 · 0 comments
Open

Handle "empty" sections with raw pointer and size set to 0x0 #1

matouskozak opened this issue Feb 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@matouskozak
Copy link
Owner

Problem with the case where a section only has a virtual size and virtual address, but the raw data pointer and raw data size are set to 0x0. The function returns a lot of free space, so it removes a lot of important parts of the binary.

def get_available_space_size(pe, section_idx):
num_sections = len(pe.sections)
if section_idx >= num_sections:
return 0
section = pe.sections[section_idx]
available_space_size = 0
# Last section
if section_idx == num_sections - 1:
overlay_offset = pe.get_overlay_data_start_offset()
if overlay_offset == None:
available_space_size = section.SizeOfRawData - section.Misc_VirtualSize
else:
available_space_size = overlay_offset - section.PointerToRawData - section.Misc_VirtualSize
else:
available_space_size = pe.sections[section_idx + 1].PointerToRawData - section.PointerToRawData - section.Misc_VirtualSize
return available_space_size

@matouskozak matouskozak added the bug Something isn't working label Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant