Reputation: 13
I'm trying to understand how to modify a Windows executable using Nim to write NOPs in specific locations of the file. In Python I do this as follows:
with open('file.exe', 'r+b') as f:
f.seek(0x0014bc0f)
f.write(binascii.unhexlify('9090'))
f.seek(0x0014bc18)
f.write(binascii.unhexlify('9090'))
But in Nim I can't find the necessary methods to accomplish the seeking to a specific address and how to input these op-codes properly. I'm pretty new to Nim and the different file operation possibilities are a little confusing.
Upvotes: 1
Views: 239
Reputation: 1598
the docs for io are quite good, but to start you off:
let f = open("file.exe",fmReadWriteExisting)
with
here, to make sure to close the file on any error:defer: f.close
f.setFilePos(0x014bc0f)
f.write("\x90\x90")
check out the documentation for each proc for more options
Upvotes: 1