Added commands for xorring regions of memory (#164)

xor: xor a region of memory with a key
    memfrob: frobnicate a memory area (https://linux.die.net/man/3/memfrob)
pull/172/head
blendin 9 years ago committed by Zach Riggle
parent faaaee7efd
commit eeaab5ec44

@ -5,15 +5,46 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import gdb
import six
import pwndbg.commands
import pwndbg.memory
def xor_memory(address, key, count):
"""
Helper function for xorring memory in gdb
"""
mem = pwndbg.memory.read(address, count, partial=True)
for index, byte in enumerate(mem):
key_index = index % len(key)
mem[index] = byte ^ ord(key[key_index])
return mem
@pwndbg.commands.Command
@pwndbg.commands.OnlyWhenRunning
def xor(self, address, key, count):
def xor(address, key, count):
'''xor(address, key, count)
XOR ``count`` bytes at ``address`` with the key ``key``.
'''
print(address,key,count)
if not isinstance(address, six.integer_types):
address = int(address, 16)
xorred_memory = xor_memory(address, key, count)
pwndbg.memory.write(address, xorred_memory)
@pwndbg.commands.Command
@pwndbg.commands.OnlyWhenRunning
def memfrob(address, count):
'''memfrob(address, count)
Run the memfrob command on a region of memory
'''
if not isinstance(address, six.integer_types):
address = int(address, 16)
xorred_memory = xor_memory(address, '*', count)
pwndbg.memory.write(address, xorred_memory)

Loading…
Cancel
Save