Hi guys,
I wrote a test program to try out the write APIs and they do not work even though I get VMI_SUCCESS after the execution.
I have two issues:
First, when I try to extract EIP and ESP (on a 32 machine) I always get the same values - which is weird.
This is the code I'm using:
reg_t esp, eip, cr3;
status_t retVal = vmi_get_vcpureg(vmi, &esp, RSP, 0);
printf("After esp %8lx %d\n", (unsigned long) esp, retVal);
retVal = vmi_get_vcpureg(vmi, &eip, RIP, 0);
printf("After eip %8lx %d\n", (unsigned long) eip, retVal);
vmi_pid_t current_pid = -1;
retVal = vmi_get_vcpureg(vmi, &cr3, CR3, 0);
printf("After cr3 %8lx %d\n", (unsigned long) cr3, retVal);
current_pid = vmi_dtb_to_pid(vmi, cr3);
Second, when I try to write to memory, it does not change the memory.
Code Sample:
uint32_t value;
addr_t test_addr = esp - 4;
status_t result = vmi_read_32_va(vmi, test_addr, current_pid, &value);
printf("Reading the value: %8x with result %d\n", value, (int) result);
value +=1;
result = vmi_write_32_va(vmi, test_addr, current_pid, &value);
printf("Value that was written %8x with result %d\n", value, (int) result);
value = 0;
result = vmi_read_32_va(vmi, test_addr, current_pid, &value);
printf("Read the value again: %8x with result %d\n", value, (int) result);
The value of both reads is the same.
What am I doing wrong? (I have initialized with VMI_INIT_COMPLETE).
Is it because I'm trying to write to the stack?
Here is the output without debug:
Process listing for VM ubuntu32 (id=5)
Beginning of the execute process
After esp c1a75f70 0
After eip c10588f5 0
After cr3 33ba1280 0
Reading the value: f71b34c0 with result 0
l_��4
Value that was written f71b34c1 with result 0
Read the value again: f71b34c0 with result 0
finished vm4
(I'm not sure why I get the nonsense in the middle)
The full output with the debug prints is attached.
Thank you!
Sofia