I want to do the following in Python 2.7.13:
- Convert int-value to hex (
58829405413336430should becomed101085402656e) - Add a "payload" (Simple string like c1234) to the created hex
- Write pure hex to a file
My code currently looks like this:
mime=58829405413336430
payload="c9999"
fw_file=open('testhex', 'wb')
fw_file.write("%x" % mime)
fw_file.write(str(payload).encode("hex"))
fw_file.close()
And I get the following file (Using xxd on Debian):
xxd HACKEDTOGETHER
00000000: 6431 3031 3038 3534 3032 3635 3665 3633 d101085402656e63
00000010: 3339 3339 3339 3339 39393939
which is not what i need. I need a file that looks like this:
xxd WORKING
00000000: d101 0854 0265 6e63 3939 3939 ...T.enc9999
My understanding is the following:
"%x" % mime converted my int to hex, but it was written as a String. encode did it correctly, but that doesn't work with integers. How can I circumvent this behavior and write "pure" hex to my file? If it is not possible to do it in Python 2 i can also use Python 3.
As this is my first question on StackOverflow please tell me if I should do anything different.