question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rwx size is too small to hold 56 bytes backup instructions

See original GitHub issue

When trying to hook some system functions (e.g. fork, execve), I see an error in logcat that reads rwx size is too small to hold 56 bytes backup instructions, and hooking fails. Looking at https://github.com/rrrfff/And64InlineHook/blob/master/And64InlineHook.cpp the hook trampoline size seems to be limited to 50 bytes, hence the error.

Call site looks like so:

#include <jni.h>
#include <unistd.h>
#include <sys/types.h>
#include "AndHook.h"

#define AKLog(...) __android_log_print(ANDROID_LOG_INFO, "AndHook", __VA_ARGS__)

static decltype(fork) *sys_fork;

pid_t __unused hook_fork() {
    AKLog("fork called");
    pid_t child_pid = sys_fork();
    if (child_pid != 0) {
        AKLog("fork child pid: %d, parent pid: %d", static_cast<int>(child_pid), static_cast<int>(getpid()));
    }
    return child_pid;
}

extern "C" JNIEXPORT jint JNICALL __unused JNI_OnLoad(JavaVM *vm, void __unused *reserved) {
    JNIEnv *env;
    if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
        return JNI_EVERSION;
    }

    AKHookFunction(fork, hook_fork, &sys_fork);
    return JNI_VERSION_1_6;
}

My system is a OnePlus 3 running OxygenOS - Android 8.0.0, arm64-v8a.

I seem to have gotten it working by copying the A64HookFunction as a wrapper around theAKHookFunctionV exported from the .so files here, and increasing the trampoline size to 70 from 50.

Attached is libc.so pulled from my device: libc.so.zip

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
Rpropcommented, Mar 29, 2018

Yes, it may require more room if there are too many pc-relative instructions (e.g, mixed adr/adrp) that need to be relocated and aligned. I will fix it as soon as possible, thanks.

0reactions
Rpropcommented, Apr 5, 2018

Well I’m pleased to hear that😄. Close it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'Error caused by file [File path].vmdk' When tryin...
I've tried live migration, normal migration, cloning, Veeam backup & restore, downloading VMDK from the datastore, FTPing the VMDK from the ...
Read more >
heap allocation - the size of the RAM is smaller than expected.
I have to deal with 10b VGA images coming from the DMA & DCMI interface. to store it, I need a RAM bigger...
Read more >
Learn why a Redis backup file is smaller than ... - Amazon AWS
I'm using Amazon ElastiCache for Redis. Why is my Redis backup (.rdb) file always smaller than the BytesUsedForCache metric in the cluster?
Read more >
Releases :: HashBackup Server Backup
It was used mostly for small storage services like WebDAV and imap (email) that are often free but have very small and strict...
Read more >
Prepare for LPIC-1 exam 1 - topic 103.3: File and directory ...
Overview. This tutorial grounds you in the basic Linux commands for manipulating files and directories. Learn to: List directory contents; Copy, move, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found