* Rewrite io_ptrace{read|write} to fix bugs on OpenBSD-amd64 debugger
- New code is shorter, more readable and bugs-free * Added 'install' target for r2-bindings/gir
This commit is contained in:
parent
ac38d02ccf
commit
ac0748de51
|
@ -37,23 +37,17 @@ static int __waitpid(int pid) {
|
||||||
#define debug_write_raw(x,y,z) ptrace(PTRACE_POKEDATA, x, y, z)
|
#define debug_write_raw(x,y,z) ptrace(PTRACE_POKEDATA, x, y, z)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int debug_os_read_at(int pid, void *buf, int sz, ut64 addr) {
|
static int debug_os_read_at(int pid, ut32 *buf, int sz, ut64 addr) {
|
||||||
unsigned long words = sz / sizeof (long);
|
ut32 words = sz / sizeof (ut32);
|
||||||
unsigned long last = sz % sizeof (long);
|
ut32 last = sz % sizeof (ut32);
|
||||||
long x, lr, s = 0;
|
ut32 x, lr, *at = (int*)(size_t)addr;
|
||||||
|
if (sz<1 || addr==UT64_MAX)
|
||||||
if (sz<0 || addr==-1)
|
|
||||||
return -1;
|
return -1;
|
||||||
for (x=0; x<words; x++) {
|
for (x=0; x<words; x++)
|
||||||
((long *)buf)[x] = debug_read_raw (pid,
|
buf[x] = debug_read_raw (pid, (void*)(at++));
|
||||||
(void *)(&((long*)(long)addr)[x]));
|
|
||||||
s += sizeof (s);
|
|
||||||
}
|
|
||||||
if (last) {
|
if (last) {
|
||||||
lr = debug_read_raw (pid, &((long*)(long)addr)[x]);
|
lr = debug_read_raw (pid, at);
|
||||||
if (lr == -1) // && errno)
|
memcpy (buf+x, &lr, last) ;
|
||||||
return s;
|
|
||||||
memcpy (&((long *)buf)[x], &lr, last) ;
|
|
||||||
}
|
}
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
@ -61,26 +55,24 @@ static int debug_os_read_at(int pid, void *buf, int sz, ut64 addr) {
|
||||||
static int __read(struct r_io_t *io, RIODesc *fd, ut8 *buf, int len) {
|
static int __read(struct r_io_t *io, RIODesc *fd, ut8 *buf, int len) {
|
||||||
ut64 addr = io->off;
|
ut64 addr = io->off;
|
||||||
memset (buf, '\xff', len); // TODO: only memset the non-readed bytes
|
memset (buf, '\xff', len); // TODO: only memset the non-readed bytes
|
||||||
return debug_os_read_at (RIOPTRACE_PID (fd), buf, len, addr);
|
return debug_os_read_at (RIOPTRACE_PID (fd), (ut32*)buf, len, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ptrace_write_at(int pid, const ut8 *buf, int sz, ut64 addr) {
|
static int ptrace_write_at(int pid, const ut32 *buf, int sz, ut64 addr) {
|
||||||
long words = sz / sizeof(long);
|
ut32 words = sz / sizeof (ut32);
|
||||||
long last = (sz - words*sizeof(long)) * 8;
|
ut32 last = sz % sizeof (ut32);
|
||||||
long x, lr;
|
ut32 x, lr, *at = (int*)(size_t)addr;
|
||||||
|
if (sz<1 || addr==UT64_MAX)
|
||||||
|
return -1;
|
||||||
for (x=0; x<words; x++)
|
for (x=0; x<words; x++)
|
||||||
if (debug_write_raw (pid, &((long *)(long)addr)[x], ((long *)buf)[x]))
|
debug_write_raw (pid, (void*)(at++), buf[x]);
|
||||||
goto err;
|
|
||||||
if (last) {
|
if (last) {
|
||||||
lr = debug_read_raw (pid, &((long *)(long)addr)[x]);
|
lr = debug_read_raw (pid, (void*)at);
|
||||||
lr = ((lr&(-1L<<last))|(((long *)buf)[x]&(~(-1L<<last))));
|
memcpy (&lr, buf+x, last);
|
||||||
if (debug_write_raw (pid, (void*)((long)addr+(x*sizeof(void*))), (void*)lr))
|
if (debug_write_raw (pid, (void*)at, (void*)lr))
|
||||||
goto err;
|
return sz-last;
|
||||||
}
|
}
|
||||||
return sz;
|
return sz;
|
||||||
err:
|
|
||||||
return --x * sizeof(long) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) {
|
static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) {
|
||||||
|
@ -138,13 +130,13 @@ static int __close(RIODesc *fd) {
|
||||||
return ptrace (PTRACE_DETACH, pid, 0, 0);
|
return ptrace (PTRACE_DETACH, pid, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __system(struct r_io_t *io, RIODesc *fd, const char *cmd) {
|
static int __system(RIO *io, RIODesc *fd, const char *cmd) {
|
||||||
RIOPtrace *iop = (RIOPtrace*)fd->data;
|
RIOPtrace *iop = (RIOPtrace*)fd->data;
|
||||||
//printf("ptrace io command (%s)\n", cmd);
|
//printf("ptrace io command (%s)\n", cmd);
|
||||||
/* XXX ugly hack for testing purposes */
|
/* XXX ugly hack for testing purposes */
|
||||||
if (!strcmp (cmd, "mem")) {
|
if (!strcmp (cmd, "mem")) {
|
||||||
char b[128];
|
char b[128];
|
||||||
int ret = debug_os_read_at (iop->pid, b, 128, 0x8048500);
|
int ret = debug_os_read_at (iop->pid, (ut32*)b, 128, 0x8048500);
|
||||||
printf ("ret = %d , pid = %d\n", ret, iop->pid);
|
printf ("ret = %d , pid = %d\n", ret, iop->pid);
|
||||||
printf ("%x %x %x %x\n", b[0], b[1], b[2], b[3]);
|
printf ("%x %x %x %x\n", b[0], b[1], b[2], b[3]);
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -15,8 +15,13 @@ ifeq ($(HAVE_VALABIND),1)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
install:
|
install:
|
||||||
cp r_asm.typelib /usr/lib/girepository-1.0/
|
rm -f /usr/lib/girepository-1.0/RAsm-1.0.*
|
||||||
cp r_asm.gir /usr/share/gir-1.0/
|
rm -f /usr/lib/girepository-1.0/r_asm-1.0.*
|
||||||
|
rm -f /usr/share/gir-1.0/RAsm-1.0.*
|
||||||
|
rm -f /usr/share/gir-1.0/r_asm-1.0.*
|
||||||
|
cp r_asm.typelib /usr/lib/girepository-1.0/r_asm-1.0.typelib
|
||||||
|
cp r_asm.gir /usr/share/gir-1.0/r_asm-1.0.gir
|
||||||
|
gjs test.js
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -f *.gir *.typelib
|
@rm -f *.gir *.typelib
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
/* This is not working */
|
||||||
|
const r = imports.gi.r_asm.Radare;
|
||||||
|
var b = new r.RAsm ();
|
||||||
|
for (var a in r) {
|
||||||
|
print (a);
|
||||||
|
}
|
Loading…
Reference in New Issue