I try to parse an char[] / char* from gdb.value to bytearray or a list of ints etc.
following test code in c:
int main(int argc, char *argv[])
{
char img[] = {0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF};
char* imgp = img;
return 0;
}
first try:
v = gdb.parse_and_eval("img")
print(v)
l = list(bytearray(v))
output:
~"\"\\377\\000\\377\\000\\377\\000\\377\\000\\377\\000\\377\\000\\377\\000\\377\\000\\377\\000\\377\\000\\377\\000\\377\\000\\377\\000\\377\"\n"
TypeError: 'gdb.Value' object is not iterable\n"
yay a string!? no gdb.value -> not iterable :( but index able ... ok
data = []
for i in range(0, 27):
data.append(int(v[i]))
result:
Python Exception <class 'gdb.MemoryError'> Cannot access memory at address 0x7ffc737be000:
ok lets do it the "safe" way:
v = gdb.parse_and_eval("img")
inferior = gdb.selected_inferior()
mem = inferior.read_memory(v, 27)
result:
Python Exception <class 'gdb.MemoryError'> Cannot access memory at address 0x7ffc737be000:
Okay whats wrong? How do I get this data out of the gdb.value type?