def freeze_python(base, dest_dir, include_dir):
files = collect_files_for_internment(base)
frozen_file = os.path.join(dest_dir, 'python-lib.bypy.frozen')
index_data = {}
with open(frozen_file, 'wb') as frozen_file:
for name, path in files.items():
raw = open(path, 'rb').read()
index_data[name] = frozen_file.tell(), len(raw)
frozen_file.write(raw)
if len(index_data) > 9999:
raise ValueError(
'Too many files in python-lib have to switch'
' hash function to IntSaltHash and change C'
' template accordingly.')
perfect_hash, code_to_get_index = get_c_code(index_data)
values = []
for k in sorted(index_data.keys(), key=perfect_hash):
v = index_data[k]
values.append(f'{{ {v[0]}u, {v[1]}u }}')
vals = ','.join(values)
tree = '\n'.join(bin_to_c(as_tree(index_data.keys())))
header = code_to_get_index + f'''
static void
get_value_for_hash_index(int index, unsigned long *offset, unsigned long *size)
{{
typedef struct {{ unsigned long offset, size; }} Item;
static const Item values[{len(values)}] = {{ {vals} }};
if (index >= 0 && index < {len(values)}) {{
*offset = values[index].offset; *size = values[index].size;
}} else {{
*offset = 0; *size = 0;
}}
}}
static const char filesystem_tree[] = {{ {tree} }};
'''
with open(os.path.join(include_dir, 'bypy-data-index.h'), 'w') as f:
f.write(header)
在阅读了https://github.com/kovidgoyal/calibre 中的几个关键提交
和 https://github.com/kovidgoyal/bypy中的
后 在 bypy/freeze/init.py中发现了关键函数
它看起来是抛弃了旧版本将pyc压缩成压缩包的方法 而是直接将pyc文件已二进制依次存入 \bin\python-lib.bypy.frozen 中
在我以16进制打开该文件后 也找到了 对应的方法名
但现在的问题是 我不知道如何寻找并修改frozen文件以取消核心函数(通过python3.9编译的原代码和修改后的代码均和存档存在细微差异 以至于我很难寻找到二进制文件准确修改位置(或许是python版本的问题
想问问作者有什么办法来解决