take a look at this:
fc = '0x'
for i in b[0x15c:0x15f]:
fc += hex(ord(i))[2:]
Lets say this code found the hex 00 04 0f , instead of writing it that way , it removes the first 0 , and writes : 04f
any help?
解决方案
This is happening because hex() will not include any leading zeros, for example:
>>> hex(15)[2:]
'f'
To make sure you always get two characters, you can use str.zfill() to add a leading zero when necessary:
>>> hex(15)[2:].zfill(2)
'0f'
Here is what it would look like in your code:
fc = '0x'
for i in b[0x15c:0x15f]:
fc += hex(ord(i))[2:].zfill(2)