Skip to main content

Command Palette

Search for a command to run...

Writing process memory in python

Updated
View as Markdown
A

9+ years in tech industry. I had the opportunity to work on a wide range of projects with companies both locally and remotely, including with software engineers from well-known tech firms such as Amazon, Atlassian, Google, and Microsoft.

I have a track record of taking ideas and turning them into successful software projects, and have made numerous contributions to open source.

I have experience working with a variety of languages and frameworks, and am highly adaptable and able to quickly learn and become proficient in new technologies.

Frida's writeByteArray failed with me to write in read only memory.

A quick solution was to send the bytes and the address I want to write at, to python.

Using ReadWriteMemory library it's really easy to write into process memory, also it has good documentation.

https://github.com/vsantiago113/ReadWriteMemory

import frida
from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()
process = rwm.get_process_by_id(YOUR_PROCESS_ID_HERE)
process.open()

def onmessage(message, data):
    global process
    message = json.loads(message['payload'])
    if message['type'] == "patch":
        ptr = message['address']
        for idx, byte in enumerate(message['patch']):
            process.write(ptr + idx, byte)

device = frida.get_local_device()
session = device.attach(YOUR_PROCESS_ID_HERE)
script = session.create_script(YOUR_JAVASCRIPT_CODE_STRING)
script.on("message", onmessage)
script.load()

and now in your Frida's JavaScript code, you can send a JSON like this

send(JSON.stringify({
    type: 'patch',
    address: ptr.toInt32(),
    patch: [0x90, 0x90, 0x90]
}))