使用 Python 在指定文件第 977 行插入代码
在 Python 中,你可以使用 fileinput 模块来修改文件内容。下面是一个示例代码,演示如何在指定文件的第 977 行首插入代码:
import fileinput
# 指定文件路径
file_path = r'D:\c0de\09184100\aegisshield\src\DexUnshellTool\jni\Loader\Egis.cpp'
# 要插入的代码
insert_code = '''
if((g_icustom_new_flag >> 28)%2 == 1) {
TFD_LOGI('[*] we need no minicap');
nativeSecurityEntry(env, newApp, 'com/jiagu/payegis/minicap/Minicap', 'checkMinicap', NULL);
}
'''
# 打开文件并插入代码
with fileinput.FileInput(file_path, inplace=True) as file:
for i, line in enumerate(file):
# 在第 977 行前插入代码
if i == 976:
print(insert_code)
print(line, end='')
请将 file_path 变量的值替换为你要修改的文件路径。运行以上代码后,会在指定文件的第 977 行前插入所需代码。
原文地址: http://www.cveoy.top/t/topic/b33K 著作权归作者所有。请勿转载和采集!