GAHH, code not working is bad code indeed!
in RemoveRETNs
toOutput[currentLoc - 0x00400000] = b'xCC' TypeError: 'bytes' object does not support item assignment
How can I fix this?
inputFile = 'original.exe'
outputFile = 'output.txt'
patchedFile = 'original_patched.exe'
def GetFileContents(filename):
f = open(filename, 'rb')
fileContents = f.read()
f.close()
return fileContents
def FindAll(fileContents, strToFind):
found = []
lastOffset = -1
while True:
lastOffset += 1
lastOffset = fileContents.find(b'xC3xCCxCCxCCxCC', lastOffset)
if lastOffset != -1:
found.append(lastOffset)
else:
break
return found
def FixOffsets(offsetList):
for current in range(0, len(offsetList)):
offsetList[current] += 0x00400000
return offsetList
def AbsentFromList(toFind, theList):
for i in theList:
if i == toFind:
return True
return False
# Outputs the original file with all RETNs replaced with INT3s.
def RemoveRETNs(locationsOfRETNs, oldFilesContents, newFilesName):
target = open(newFilesName, 'wb')
toOutput = oldFilesContents
for currentLoc in locationsOfRETNs:
toOutput[currentLoc - 0x00400000] = b'xCC'
target.write(toOutput)
target.close()
fileContents = GetFileContents(inputFile)
offsets = FixOffsets(FindAll(fileContents, 'xC3xCCxCCxCCxCC'))
RemoveRETNs(offsets, fileContents, patchedFile)
What am I doing wrong, and what can I do to fix it? Code sample?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…