37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""计算 Generator struct 关键字段偏移,验证 this_adjust=536 是否正确。"""
|
|
import re
|
|
|
|
f = r'D:\Users\TermiNexus\Desktop\TransPyC\TransPyV\output\e1ea7eaf63a9c3d1.ll'
|
|
elems = []
|
|
with open(f, encoding='utf-8', errors='replace') as fh:
|
|
for ln in fh:
|
|
if 'e1ea7eaf63a9c3d1.Generator" = type' in ln:
|
|
body = ln.split('= type {')[1].rstrip().rstrip('}')
|
|
elems = [x.strip() for x in body.split(',')]
|
|
break
|
|
|
|
off = 0
|
|
offs = []
|
|
for t in elems:
|
|
align = 4 if t == 'i32' else 8
|
|
sz = 4 if t == 'i32' else 8
|
|
if off % align:
|
|
off += align - (off % align)
|
|
offs.append(off)
|
|
off += sz
|
|
print('struct 元素数:', len(elems))
|
|
for idx in (89, 90, 105, 108):
|
|
print(f'struct[{idx}]={elems[idx]} 偏移={offs[idx]}')
|
|
|
|
# ClassGenBase 独立 struct 前 26 元素字节偏移(ExceptionNames 块内偏移)
|
|
CGB = ['i8*','i8*','i32','i64*','i64*','i64*','i64*','i32','i64*','i64*','i64*','i64*','i64*','i32',
|
|
'i64*','i64*','i32','i32*','i8*','i8*','i32','i32','i8*','i8*','i64*','i32']
|
|
c = 0
|
|
for t in CGB:
|
|
a = 4 if t == 'i32' else 8
|
|
s = 4 if t == 'i32' else 8
|
|
if c % a: c += a - (c % a)
|
|
c += s
|
|
print('ClassGenBase ExceptionNames 块内偏移:', c)
|
|
print('this_adjust(536) + 块内偏移 =', 536 + c, ' vs struct[90] ExceptionNames 偏移', offs[90] if len(offs) > 90 else 'N/A')
|