MCPcopy Create free account
hub / github.com/ELMERIKH/PyinMemoryPE / set_format

Function set_format

pythonmemorymodule/pefile.py:901–941  ·  view source on GitHub ↗
(format)

Source from the content-addressed store, hash-verified

899
900@lru_cache(maxsize=2048, copy=True)
901def set_format(format):
902
903 __format__ = "<"
904 __unpacked_data_elms__ = []
905 __field_offsets__ = {}
906 __keys__ = []
907 __format_length__ = 0
908
909 offset = 0
910 for elm in format:
911 if "," in elm:
912 elm_type, elm_name = elm.split(",", 1)
913 __format__ += elm_type
914 __unpacked_data_elms__.append(None)
915
916 elm_names = elm_name.split(",")
917 names = []
918 for elm_name in elm_names:
919 if elm_name in __keys__:
920 search_list = [x[: len(elm_name)] for x in __keys__]
921 occ_count = search_list.count(elm_name)
922 elm_name = "{0}_{1:d}".format(elm_name, occ_count)
923 names.append(elm_name)
924 __field_offsets__[elm_name] = offset
925
926 offset += sizeof_type(elm_type)
927
928 # Some PE header structures have unions on them, so a certain
929 # value might have different names, so each key has a list of
930 # all the possible members referring to the data.
931 __keys__.append(names)
932
933 __format_length__ = struct.calcsize(__format__)
934
935 return (
936 __format__,
937 __unpacked_data_elms__,
938 __field_offsets__,
939 __keys__,
940 __format_length__,
941 )
942
943
944class Structure:

Callers 2

__init__Method · 0.85
set_bitfields_formatFunction · 0.85

Calls 2

sizeof_typeFunction · 0.85
countMethod · 0.45

Tested by

no test coverage detected