(format)
| 899 | |
| 900 | @lru_cache(maxsize=2048, copy=True) |
| 901 | def 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 | |
| 944 | class Structure: |
no test coverage detected