How to replace a hex value in a file with other hex values using python script? -


i have hex values in file named hex_values.txt in format:

0x52 0x49 0x46 0x46 0x62 0x9b 0x04 0x00 0x57 0x41 0x56 0x45 0x66  0x6d 0x74 0x20 0x10 0x00 0x00 0x00 0x01 0x00 0x01 0x00 0x40 0x1f  0x00 0x00 0x80 0x3e 0x00 0x00 0x02 0x00 0x10 0x00 0x64 0x61 0x74  0x61 0x3e 0x9b 0x04 0x00 0xe8 0x01 0xf9 0x01**  

i want change first few values 0x00.

i have replace values 0xaa. copy contents of file1 file2 , replace values.

how can done?

note: file1 contains hexadecimal values.

i tried using:

file1 = open("hex_values.txt", "r"); #opening hex_values.txt file read1 = file1.read();  #copying content of hex_values.txt file2 file2 = open("file2.txt", "w"); file2.write(read1);  in range(0,10):          #ranging first 10 values          file2.seek(i)     file2.write('0x00')        #replacing hex value 0x00 

am doing wrong?

problem facing is, contents of file1 being copied file2 not able replace values.

the solution expecting shown below:

0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x56 0x45 0x66 0x6d 0x74 0x20 0x10 0x00 0x00 0x00 0x01 0x00 0x01 0x00 0x40 0x1f 0x00 0x00 0x80 0x3e 0x00 0x00 0x02 0x00 0x10 0x00 0x64 0x61 0x74 0x61 0x3e 0x9b 0x04 0x00 0xe8 0x01 0xf9 0x01


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -