I was trying to use this project https://github.com/Chainfire/injectvm-binderjack to inject a shared library in the system server, using ptrace(). The problem is, that every attempt of writing memory (using PTRACE_POKETEXT) fails with errno 5 (Input/Output Error). What could be causing this? Every other ptrace operation works and the jni library doing the injection runs as root.
This is the function used to write remotely:
static bool remote_write(const char* debug, size_t dest, unsigned char *src, size_t blen) {
remote_stop(); // suspend the target process
size_t i = 0;
long ret;
// make sure the buffer is word aligned
char *ptr = (char *) malloc(blen + blen % sizeof(size_t));
memcpy(ptr, src, blen);
for (i = 0; i < blen; i += sizeof(size_t)) {
ret = trace( debug, PTRACE_POKETEXT, (void *) (dest + i), *(size_t *) &ptr[i] );
if (ret == -1) {
free(ptr);
return false;
}
}
free(ptr);
return true;
}
I tested this in a device with Android 11 arm x64