gpt4 book ai didi

python - 项目分配给字节对象?

转载 作者:太空狗 更新时间:2023-10-29 22:01:30 25 4
gpt4 key购买 nike

GAHH,无法运行的代码确实是错误的代码!

  in RemoveRETNs
toOutput[currentLoc - 0x00400000] = b'\xCC' TypeError: 'bytes' object does not support item assignment

我该如何解决这个问题?

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'\xC3\xCC\xCC\xCC\xCC', 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, '\xC3\xCC\xCC\xCC\xCC'))
RemoveRETNs(offsets, fileContents, patchedFile)

我做错了什么,我该如何解决?代码示例?

最佳答案

GetFileContentsreturn语句改成

return bytearray(fileContents)

其余的应该工作。您需要使用 bytearray 而不是 bytes 只是因为前者是可变的(读/写),后者(这是您现在使用的)是不可变的(读- 仅)。

关于python - 项目分配给字节对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1934624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com