欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

利用python批处理替换文件内容

程序员文章站 2022-06-19 08:31:04
...
import binascii
import sys

replace_data = '41505f031'
target_data  = '41505f131'
file_name = './xx.bin'
src_file_name = './xx11.bin'

def gen(target_data_t,replace_data_t,src_file_name_t,file_name_t):
    f = open(src_file_name_t,'rb')
    a = f.read()
    temp_data = binascii.b2a_hex(a)
    str_src_data = str(temp_data)

    str_target_data = str_src_data.replace(target_data_t,replace_data_t)
    target_bin = bytearray.fromhex(str_target_data[0:])
    
    f1 = open(file_name_t,'wb')
    f1.write(target_bin)
    f1.close()
    f.close()

if __name__ == "__main__":
    for i in range(1,10)
        file_name = './xx'+str(i)+'.bin'
        replace_data = '41505f031'+ str(30 + i)
        gen(target_data,replace_data,src_file_name,file_name

 

相关标签: 软件相关