mirror of
https://github.com/dobin/avred
synced 2026-06-08 13:54:13 +00:00
250 lines
13 KiB
Python
250 lines
13 KiB
Python
"""
|
|
Part of dotnetfile
|
|
|
|
Copyright (c) 2016, 2021-2022 - Bob Jung, Yaron Samuel, Dominik Reichel
|
|
"""
|
|
|
|
MAX_DOTNET_STRING_LENGTH = 1024
|
|
|
|
TABLE_ROW_VARIABLE_LENGTH_FIELDS = {
|
|
'TypeDefOrRef': ['TypeDef', 'TypeRef', 'TypeSpec'],
|
|
'HasConstant': ['Field', 'Param', 'Property'],
|
|
'HasCustomAttribute': ['MethodDef', 'Field', 'TypeRef', 'TypeDef', 'Param', 'InterfaceImpl', 'MemberRef',
|
|
'Module', 'Permission', 'Property', 'Event', 'StandAloneSig', 'ModuleRef', 'TypeSpec',
|
|
'Assembly', 'AssemblyRef', 'File', 'ExportedType', 'ManifestResource', 'GenericParam',
|
|
'GenericParamConstraint', 'MethodSpec'],
|
|
'HasFieldMarshal': ['Field', 'Param'],
|
|
'HasDeclSecurity': ['TypeDef', 'MethodDef', 'Assembly'],
|
|
'MemberRefParent': ['TypeDef', 'TypeRef', 'ModuleRef', 'MethodDef', 'TypeSpec'],
|
|
'HasSemantics': ['Event', 'Property'],
|
|
'MethodDefOrRef': ['MethodDef', 'MemberRef'],
|
|
'MemberForwarded': ['Field', 'MethodDef'],
|
|
'Implementation': ['File', 'AssemblyRef', 'ExportedType'],
|
|
'CustomAttributeType': ['MethodDef', 'MethodDef', 'MethodDef', 'MemberRef', 'MethodDef'],
|
|
'ResolutionScope': ['Module', 'ModuleRef', 'AssemblyRef', 'TypeRef'],
|
|
'TypeOrMethodDef': ['TypeDef', 'MethodDef']
|
|
}
|
|
|
|
METADATA_TABLE_INDEXES = {
|
|
0: 'Module',
|
|
1: 'TypeRef',
|
|
2: 'TypeDef',
|
|
3: 'FieldPtr',
|
|
4: 'Field',
|
|
5: 'MethodPtr',
|
|
6: 'MethodDef',
|
|
7: 'ParamPtr',
|
|
8: 'Param',
|
|
9: 'InterfaceImpl',
|
|
10: 'MemberRef',
|
|
11: 'Constant',
|
|
12: 'CustomAttribute',
|
|
13: 'FieldMarshal',
|
|
14: 'DeclSecurity',
|
|
15: 'ClassLayout',
|
|
16: 'FieldLayout',
|
|
17: 'StandAloneSig',
|
|
18: 'EventMap',
|
|
19: 'EventPtr',
|
|
20: 'Event',
|
|
21: 'PropertyMap',
|
|
22: 'PropertyPtr',
|
|
23: 'Property',
|
|
24: 'MethodSemantics',
|
|
25: 'MethodImpl',
|
|
26: 'ModuleRef',
|
|
27: 'TypeSpec',
|
|
28: 'ImplMap',
|
|
29: 'FieldRVA',
|
|
30: 'EncLog',
|
|
31: 'EncMap',
|
|
32: 'Assembly',
|
|
33: 'AssemblyProcessor',
|
|
34: 'AssemblyOS',
|
|
35: 'AssemblyRef',
|
|
36: 'AssemblyRefProcessor',
|
|
37: 'AssemblyRefOS',
|
|
38: 'File',
|
|
39: 'ExportedType',
|
|
40: 'ManifestResource',
|
|
41: 'NestedClass',
|
|
42: 'GenericParam',
|
|
43: 'MethodSpec',
|
|
44: 'GenericParamConstraint',
|
|
48: 'Document',
|
|
49: 'MethodDebugInformation',
|
|
50: 'LocalScope',
|
|
51: 'LocalVariable',
|
|
52: 'LocalConstant',
|
|
53: 'ImportScope',
|
|
54: 'StateMachineMethod',
|
|
55: 'CustomDebugInformation'
|
|
}
|
|
|
|
METADATA_TABLE_FLAGS = {
|
|
1: 'Module',
|
|
2: 'TypeRef',
|
|
4: 'TypeDef',
|
|
8: 'FieldPtr',
|
|
16: 'Field',
|
|
32: 'MethodPtr',
|
|
64: 'MethodDef',
|
|
128: 'ParamPtr',
|
|
256: 'Param',
|
|
512: 'InterfaceImpl',
|
|
1024: 'MemberRef',
|
|
2048: 'Constant',
|
|
4096: 'CustomAttribute',
|
|
8192: 'FieldMarshal',
|
|
16384: 'DeclSecurity',
|
|
32768: 'ClassLayout',
|
|
65536: 'FieldLayout',
|
|
131072: 'StandAloneSig',
|
|
262144: 'EventMap',
|
|
524288: 'EventPtr',
|
|
1048576: 'Event',
|
|
2097152: 'PropertyMap',
|
|
4194304: 'PropertyPtr',
|
|
8388608: 'Property',
|
|
16777216: 'MethodSemantics',
|
|
33554432: 'MethodImpl',
|
|
67108864: 'ModuleRef',
|
|
134217728: 'TypeSpec',
|
|
268435456: 'ImplMap',
|
|
536870912: 'FieldRVA',
|
|
1073741824: 'EncLog',
|
|
2147483648: 'EncMap',
|
|
4294967296: 'Assembly',
|
|
8589934592: 'AssemblyProcessor',
|
|
17179869184: 'AssemblyOS',
|
|
34359738368: 'AssemblyRef',
|
|
68719476736: 'AssemblyRefProcessor',
|
|
137438953472: 'AssemblyRefOS',
|
|
274877906944: 'File',
|
|
549755813888: 'ExportedType',
|
|
1099511627776: 'ManifestResource',
|
|
2199023255552: 'NestedClass',
|
|
4398046511104: 'GenericParam',
|
|
8796093022208: 'MethodSpec',
|
|
17592186044416: 'GenericParamConstraint',
|
|
35184372088832: 'Document',
|
|
70368744177664: 'MethodDebugInformation',
|
|
140737488355328: 'LocalScope',
|
|
281474976710656: 'LocalVariable',
|
|
562949953421312: 'LocalConstant',
|
|
1125899906842624: 'ImportScope',
|
|
2251799813685248: 'StateMachineMethod',
|
|
4503599627370496: 'CustomDebugInformation'
|
|
}
|
|
|
|
RESOURCE_TYPE_CODES = {
|
|
'Null': 0,
|
|
'String': 1,
|
|
'Boolean': 2,
|
|
'Char': 3,
|
|
'Byte': 4,
|
|
'SByte': 5,
|
|
'Int16': 6,
|
|
'UInt16': 7,
|
|
'Int32': 8,
|
|
'UInt32': 9,
|
|
'Int64': 10,
|
|
'UInt64': 11,
|
|
'Single': 12,
|
|
'Double': 13,
|
|
'Decimal': 14,
|
|
'DateTime': 15,
|
|
'Timespan': 16,
|
|
'ByteArray': 32,
|
|
'Stream': 33,
|
|
'UserType': 64
|
|
}
|
|
|
|
BLOB_SIGNATURES = {
|
|
b'\x06\x05': {'hasthis': False, 'return': 'System.Byte', 'parameter': ()},
|
|
b'\x06\x07': {'hasthis': False, 'return': 'System.UInt16', 'parameter': ()},
|
|
b'\x06\x08': {'hasthis': False, 'return': 'System.Int32', 'parameter': ()},
|
|
b'\x06\x09': {'hasthis': False, 'return': 'System.UInt32', 'parameter': ()},
|
|
b'\x06\x0B': {'hasthis': False, 'return': 'System.UInt64', 'parameter': ()},
|
|
b'\x00\x00\x01': {'hasthis': False, 'return': 'System.Void', 'parameter': ()},
|
|
b'\x00\x00\x02': {'hasthis': False, 'return': 'System.Boolean', 'parameter': ()},
|
|
b'\x00\x00\x0E': {'hasthis': False, 'return': 'System.String', 'parameter': ()},
|
|
b'\x06\x0F\x05': {'hasthis': False, 'return': 'System.Byte*', 'parameter': ()},
|
|
b'\x06\x0F\x09': {'hasthis': False, 'return': 'System.UInt32*', 'parameter': ()},
|
|
b'\x20\x00\x01': {'hasthis': True, 'return': 'System.Void', 'parameter': ()},
|
|
b'\x20\x00\x02': {'hasthis': True, 'return': 'System.Boolean', 'parameter': ()},
|
|
b'\x20\x00\x08': {'hasthis': True, 'return': 'System.Int32', 'parameter': ()},
|
|
b'\x20\x00\x0A': {'hasthis': True, 'return': 'System.Int64', 'parameter': ()},
|
|
b'\x20\x00\x0E': {'hasthis': True, 'return': 'System.String', 'parameter': ()},
|
|
b'\x00\x01\x01\x08': {'hasthis': False, 'return': 'System.Void', 'parameter': 'System.Int32'},
|
|
b'\x00\x01\x01\x18': {'hasthis': False, 'return': 'System.Void', 'parameter': 'System.IntPtr'},
|
|
b'\x00\x01\x01\x1C': {'hasthis': False, 'return': 'System.Void', 'parameter': 'System.Object'},
|
|
b'\x00\x01\x07\x07': {'hasthis': False, 'return': 'System.UInt16', 'parameter': 'System.UInt16'},
|
|
b'\x00\x01\x08\x09': {'hasthis': False, 'return': 'System.Int32', 'parameter': 'System.UInt32'},
|
|
b'\x00\x01\x08\x0A': {'hasthis': False, 'return': 'System.Int32', 'parameter': 'System.Int64'},
|
|
b'\x00\x01\x09\x02': {'hasthis': False, 'return': 'System.UInt32', 'parameter': 'System.Boolean'},
|
|
b'\x00\x01\x18\x08': {'hasthis': False, 'return': 'System.IntPtr', 'parameter': 'System.Int32'},
|
|
b'\x00\x01\x18\x09': {'hasthis': False, 'return': 'System.IntPtr', 'parameter': 'System.UInt32'},
|
|
b'\x20\x00\x0F\x01': {'hasthis': True, 'return': 'System.Void*', 'parameter': ()},
|
|
b'\x20\x01\x01\x02': {'hasthis': True, 'return': 'System.Void', 'parameter': 'System.Boolean'},
|
|
b'\x20\x01\x01\x08': {'hasthis': True, 'return': 'System.Void', 'parameter': 'System.Int32'},
|
|
b'\x20\x01\x01\x0A': {'hasthis': True, 'return': 'System.Void', 'parameter': 'System.Int64'},
|
|
b'\x20\x01\x01\x0E': {'hasthis': True, 'return': 'System.Void', 'parameter': 'System.String'},
|
|
b'\x20\x01\x03\x08': {'hasthis': True, 'return': 'System.Char', 'parameter': 'System.Int32'},
|
|
b'\x00\x00\x20\x39\x02': {'hasthis': False, 'return': 'System.Boolean', 'parameter': ()},
|
|
b'\x00\x01\x01\x1D\x0E': {'hasthis': False, 'return': 'System.Void', 'parameter': 'System.String[]'},
|
|
b'\x00\x01\x08\x1D\x05': {'hasthis': False, 'return': 'System.Int32', 'parameter': 'System.Byte[]'},
|
|
b'\x00\x01\x09\x0F\x05': {'hasthis': False, 'return': 'System.UInt32', 'parameter': 'System.Byte*'},
|
|
b'\x00\x01\x0E\x1D\x0E': {'hasthis': False, 'return': 'System.String', 'parameter': 'System.String[]'},
|
|
b'\x00\x01\x0F\x01\x18': {'hasthis': False, 'return': 'System.Void*', 'parameter': 'System.IntPtr'},
|
|
b'\x00\x01\x12\x51\x0E': {'hasthis': False, 'return': 'System.IO.FileStream', 'parameter': 'System.String'},
|
|
b'\x00\x01\x1D\x05\x0E': {'hasthis': False, 'return': 'System.Byte[]', 'parameter': 'System.String'},
|
|
b'\x00\x02\x01\x09\x18': {'hasthis': False, 'return': 'System.Void',
|
|
'parameter': ('System.UInt32', 'System.InPtr')},
|
|
b'\x00\x02\x08\x08\x0E': {'hasthis': False, 'return': 'System.Int32',
|
|
'parameter': ('System.Int32', 'System.String')},
|
|
b'\x20\x01\x01\x0F\x01': {'hasthis': True, 'return': 'System.Void', 'parameter': 'System.Void*'},
|
|
b'\x20\x01\x01\x11\x1D': {'hasthis': True, 'return': 'System.Void',
|
|
'parameter': 'System.Security.Permissions.SecurityAction'},
|
|
b'\x20\x01\x01\x11\x6D': {'hasthis': True, 'return': 'System.Void',
|
|
'parameter': 'System.Runtime.InteropServices.LayoutKind'},
|
|
b'\x20\x01\x09\x12\x11': {'hasthis': True, 'return': 'System.UInt32', 'parameter': 'System.IAsyncResult'},
|
|
b'\x20\x02\x01\x0E\x0E': {'hasthis': True, 'return': 'System.Void',
|
|
'parameter': ('System.String', 'System.String')},
|
|
b'\x20\x02\x01\x1C\x18': {'hasthis': True, 'return': 'System.Void',
|
|
'parameter': ('System.Object', 'System.IntPtr')},
|
|
b'\x00\x01\x12\x41\x11\x45': {'hasthis': False, 'return': 'System.Type', 'parameter': 'System.RuntimeTypeHandle'},
|
|
b'\x00\x02\x02\x0E\x0F\x05': {'hasthis': False, 'return': 'System.Boolean',
|
|
'parameter': ('System.String', 'System.Byte*')},
|
|
b'\x00\x02\x09\x09\x0F\x05': {'hasthis': False, 'return': 'System.UInt32',
|
|
'parameter': ('System.UInt32', 'System.Byte*')},
|
|
b'\x00\x03\x08\x09\x09\x09': {'hasthis': False, 'return': 'System.Int32',
|
|
'parameter': ('System.UInt32', 'System.UInt32', 'System.UInt32')},
|
|
b'\x20\x02\x01\x12\x41\x08': {'hasthis': True, 'return': 'System.Void',
|
|
'parameter': ('System.Type', 'System.Int32')},
|
|
b'\x20\x03\x01\x08\x08\x08': {'hasthis': True, 'return': 'System.Void',
|
|
'parameter': ('System.Int32', 'System.Int32', 'System.Int32')},
|
|
b'\x20\x03\x09\x09\x09\x09': {'hasthis': True, 'return': 'System.UInt32',
|
|
'parameter': ('System.UInt32', 'System.UInt32', 'System.UInt32')},
|
|
b'\x00\x02\x01\x12\x61\x11\x65': {'hasthis': False, 'return': 'System.Void',
|
|
'parameter': ('System.Array', 'System.RuntimeFieldHandle')},
|
|
b'\x00\x02\x12\x49\x18\x12\x41': {'hasthis': False, 'return': 'System.Delegate',
|
|
'parameter': ('System.IntPtr', 'System.Type')},
|
|
b'\x00\x03\x01\x0F\x05\x05\x09': {'hasthis': False, 'return': 'System.Void',
|
|
'parameter': ('System.Byte*', 'System.Byte', 'System.UInt32')},
|
|
b'\x00\x04\x09\x09\x09\x09\x09': {'hasthis': False, 'return': 'System.UInt32', 'parameter': (
|
|
'System.UInt32', 'System.UInt32', 'System.UInt32', 'System.UInt32')},
|
|
b'\x20\x03\x08\x1D\x05\x08\x08': {'hasthis': True, 'return': 'System.Int32',
|
|
'parameter': ('System.Byte[]', 'System.Int32', 'System.Int32')},
|
|
b'\x20\x03\x09\x08\x08\x08\x0D': {'hasthis': True, 'return': 'System.UInt32',
|
|
'parameter': ('System.Int32', 'System.Int32', 'System.Int32')},
|
|
b'\x00\x03\x01\x0F\x05\x0F\x05\x09': {'hasthis': False, 'return': 'System.Void',
|
|
'parameter': ('System.Byte*', 'System.Byte*', 'System.UInt32')},
|
|
b'\x00\x03\x0F\x05\x0F\x05\x09\x09': {'hasthis': False, 'return': 'System.Byte*',
|
|
'parameter': ('System.Byte*', 'System.UInt32', 'System.UInt32')},
|
|
b'\x00\x04\x08\x09\x09\x09\x0F\x09': {'hasthis': False, 'return': 'System.Int32',
|
|
'parameter': ('System.UInt32', 'System.UInt32', 'System.UInt32*')},
|
|
b'\x20\x05\x12\x11\x09\x09\x09\x12\x15\x1C': {'hasthis': True, 'return': 'System.IAsyncResult', 'parameter': (
|
|
'System.UInt32', 'System.UInt32', 'System.UInt32', 'System.AsyncCallback', 'System.Object')},
|
|
}
|