Click here to Skip to main content
15,888,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a file inside it with values ​​like this:

55 02 00 00 04 29 00 00 69 00 00 00 14 00 00 00 46 31 35 39 42 37 38 44 41 36 34 35 35 34 36 44 5f 23 23 00 00 00 00 00 14 00 00 00 38 43 36 30 31 31 35 33 43 44 33 35 44 32 42 33 5f 23 23 00 07 00 00 00 33 30 31 30 35 30

I want it to change to this:

55 02 00 00 05 29 00 00 69 00 00 00 14 00 00 00 46 31 35 39 42 37 38 44 41 36 34 35 35 34 36 44 5f 23 23 00 01 00 00 00 14 00 00 00 38 43 36 30 31 31 35 33 43 44 33 35 44 32 42 33 5f 23 23 00 07 00 00 00 33 30 31 30 35 30

Here is my file structure: https://drive.google.com/file/d/11XiZejh0OQtzBoOIVuktuMZ7VKBjoj35/view?usp=share_link
Try it and I hope the answer to my problem


What I have tried:

I tried like this but it doesn't seem to work:

import os
ori = input("Enter the hex value to be replaced: ")
mod = input('Enter the hex value you want to replace:')
oriconvert = bytes(ori,'utf-8')
modconvert = bytes(mod,'utf-8')
with open('hero.bytes','rb') as test:
test = test.read()
test = test.replace(oriconvert,modconvert)
with open('hero.bytes', 'wb') as file:
file.write(test)
Posted
Comments
Richard MacCutchan 12-Nov-22 10:14am    
The file you uploaded is empty. But in any case your question is unclear. Do you want all bytes replaced or just the first occurrence of specific values? And reading the file in binary format probably means that whatever values you enter at the console will not match any of the file's content.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900