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

Remove "OC Patch" comments #408

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions pefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,6 @@ def __unpack__(self, data):
if len(data) > self.__format_length__:
data = data[: self.__format_length__]

# OC Patch:
# Some malware have incorrect header lengths.
# Fail gracefully if this occurs
# Buggy malware: a29b0118af8b7408444df81701ad5a7f
Expand Down Expand Up @@ -3078,7 +3077,6 @@ def __parse__(self, fname, data, fast_load):
if not self.DOS_HEADER or self.DOS_HEADER.e_magic != IMAGE_DOS_SIGNATURE:
raise PEFormatError("DOS Header magic not found.")

# OC Patch:
# Check for sane value in e_lfanew
#
if self.DOS_HEADER.e_lfanew > len(self.__data__):
Expand All @@ -3094,7 +3092,6 @@ def __parse__(self, fname, data, fast_load):

# We better check the signature right here, before the file screws
# around with sections:
# OC Patch:
# Some malware will cause the Signature value to not exist at all
if not self.NT_HEADERS or not self.NT_HEADERS.Signature:
raise PEFormatError("NT Headers not found.")
Expand Down Expand Up @@ -3216,7 +3213,6 @@ def __parse__(self, fname, data, fast_load):
if not self.FILE_HEADER:
raise PEFormatError("File Header missing")

# OC Patch:
# Die gracefully if there is no OPTIONAL_HEADER field
# 975440f5ad5e2e4a92c4d9a5f22f75c1
if self.OPTIONAL_HEADER is None:
Expand Down Expand Up @@ -3312,7 +3308,6 @@ def __parse__(self, fname, data, fast_load):

offset = self.parse_sections(sections_offset)

# OC Patch:
# There could be a problem if there are no raw data sections
# greater than 0
# fc91013eb72529da005110a3403541b6 example
Expand Down Expand Up @@ -3727,8 +3722,6 @@ def parse_data_directories(
directories = [directories]

for entry in directory_parsing:
# OC Patch:
#
try:
directory_index = DIRECTORY_ENTRY[entry[0]]
dir_entry = self.OPTIONAL_HEADER.DATA_DIRECTORY[directory_index]
Expand Down Expand Up @@ -3936,7 +3929,7 @@ def parse_directory_bound_imports(self, rva, size):
self.__data__[rva : rva + bnd_descr_size],
file_offset=rva,
)
# OC Patch:

if not bnd_frwd_ref:
raise PEFormatError("IMAGE_BOUND_FORWARDER_REF cannot be read")
rva += bnd_frwd_ref.sizeof()
Expand Down Expand Up @@ -4265,7 +4258,6 @@ def parse_image_base_relocation_list(self, rva, size, fmt=None):

relocations = []
while rva < end:
# OC Patch:
# Malware that has bad RVA entries will cause an error.
# Just continue on after an exception
#
Expand Down Expand Up @@ -4594,7 +4586,6 @@ def parse_resources_directory(self, rva, size=0, base_rva=None, level=0, dirs=No
are available as its attributes.
"""

# OC Patch:
if dirs is None:
dirs = [rva]

Expand Down Expand Up @@ -4741,8 +4732,6 @@ def parse_resources_directory(self, rva, size=0, base_rva=None, level=0, dirs=No
)

if res.DataIsDirectory:
# OC Patch:
#
# One trick malware can do is to recursively reference
# the next directory. This causes hilarity to ensue when
# trying to parse everything correctly.
Expand Down Expand Up @@ -5971,7 +5960,6 @@ def parse_imports(
# bound.
iat = self.get_import_table(first_thunk, max_length, contains_addresses)

# OC Patch:
# Would crash if IAT or ILT had None type
if (not iat or len(iat) == 0) and (not ilt or len(ilt) == 0):
self.__warnings.append(
Expand Down Expand Up @@ -7228,7 +7216,6 @@ def dump_dict(self):

return dump_dict

# OC Patch
def get_physical_by_rva(self, rva):
"""Gets the physical address in the PE file from an RVA value."""
try:
Expand Down
Loading