As per the title I need help with writing to a specific byte in a dump file. So far I'm able to read 512 byte with the following code :
sectorcount = 0;
bytecount= 0;
with open('a2.dump', 'rb') as f:
for chunk in iter(lambda: f.read(16), b''):
#16 bytes per chunk aka 32 characters
item = chunk.encode('hex')
#to filter display output so it shows 2 character per array element
filtered_item= [item[i:i+2] for i in range(0, len(item), 2)]
#to display in "hex" form
#filtered_item[0] = "E5"
print ' '.join(filtered_item)
sectorcount = sectorcount +1
#to display 1 sector use the value 32. adjust accordingly"
if sectorcount ==32:
break
The result shown were
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 77 8a 1c 22 00 00 00 21
03 00 83 37 ee fb 00 08 00 00 00 b8 3d 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa
As you can see I would need help in editing one of those values in the results (e.g. changing the value of "77" to maybe "E1")
I tried opening the file as with open('a2.dump', 'wb') as f:
but my dump file got nulled. I believe i need to use the write operation to the file but unsure how to do it in Hex aka binary form in Python.
Appreciate any help in advance ! Thanks !
EDIT: As per James Sebastian request the I created a .dump file and edited them in HexEdit with my results shown above.
I then execute the code print repr(open('input.dump', 'rb').read())
Results as shown are:
'\x00w\x8a\x1c"\x00'
The corresponding expected output (the result after the replacements):
'\x00\xe1\x8a\x1c"\x00'