Search code examples
qemu

Qemu read guest ram from host application


I have a host application which needs to access qemu physical address. For a RAM memory region. I am not able to figure out the right way to do this. Any help is appreciated.

I am currently thinking of adding a socket server to the QEMU event loop to do this. But am not able to find the documentation for this...


Solution

  • You can utilize the static inline void cpu_physical_memory_read(hwaddr addr,void *buf, hwaddr len) function in QEMU to read data from the RAM. This function is designed to read from the physical memory, making it suitable for your scenario.

    Here's a basic example of how you might use it:

    hwaddr guest_address = 0x12345678;  // Replace with the actual guest address
    size_t read_size = 100;  // Replace with the actual size you want to read
    
    // Allocate a buffer to store the read data
    uint8_t read_buffer[read_size];
    
    cpu_physical_memory_read(guest_addr, buffer, size);
    
    printf("Read data from guest RAM: ");
    for (size_t i = 0; i < 10; ++i) 
        printf("%02X ", read_buffer[i]);