Decided to do a complete remake of the question. Hexedit in its default settings displays hex in the center window and ansi text in the right window. The below is the current code:

patlst = [line.strip() for line in open(patch,'rb',1)] #Read Patch start
if alphex == 'h' :
    old = patlst[patlst.index('OLD:')+1] #get old data str
    new = patlst[patlst.index('NEW:')+1] #get new data str
    old = old.lower();old = ''.join(old.split())
    new = new.lower();new = ''.join(new.split())
pircwd = os.chdir('..'); pircwd = os.getcwd() ##DIR change
with open(tar, 'rb') as f:
    data = binascii.hexlify(f.read(160))
with open(tar+'BAK', 'wb') as f:
    f.write(data.replace(b'old',b'new'))

Original hexedit view unaltered: This is the original hexedit

Desired result:

This is the desired result

Actual result:

enter image description here

I believe this requires the pack and unpack function to work properly? Or is there a better way all in all to do this?

有帮助吗?

解决方案

To convert from (ASCII-encoded) hex to binary, you can use binascii.unhexlify().

其他提示

Ok lost ALL my login info. And the registered email account is dead. Parks Banyon is the secret identity of Gary Washington. I'm going to repost the question in a different context, titled "python print data to stout in the format python sees. IE raw.

Basically this particular question was looking at 3 problems and hopefully a single solution. Apparently this is not the case. As such I will refer to the following stackoverflow question as a partial answer (Why does Python print unicode characters when the default encoding is ASCII?) and vote Dan Getz' reply as the workable solution. I will repost the problems as 3 individual questions and hope the answers do not conflict.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top