Giter VIP home page Giter VIP logo

dlfunc's Introduction

dlfunc

Build Status Maven

Introduction

Dynamic linking functions(dlopen, dlsym) in recent Android versions are restricted with caller address checked. This project can be used as a workaround by forging caller address.

The basic idea is to simply set dlopen/dlsym as JNI functions, which are actually called by trampoline code in libart.so and can be used to trick the linker.

In this way, neither /proc/self/maps file nor ELF parsing is needed, and hopefully symbol hash table could be utilized during resolution for faster symbol lookup.

Setup

The library is built with the new feature of Android Gradle Plugin for native code dependency, which would add prefab modules into the .aar file.

To use the library, first make sure that Android Gradle Plugin version 4.0+ is used. Then add the library as a dependency:

implementation 'io.github.rk700:dlfunc:0.1.1'

Put the following lines into the android block of the module's build.gradle file to enable prefab:

    buildFeatures {
        prefab true
    }

In CMakeLists.txt file, add the following lines to expose the dlfunc library to native code:

find_package(dlfunc REQUIRED CONFIG)

target_link_libraries( # Specifies the target library.
                       app

                       # Links the dlfunc library to the target library.
                       dlfunc::dlfunc
)

Android NDK sample for prefab also provides an example for importing a prefab library.

Usage

First, include the header file dlfunc.h in the native code:

#include "dlfunc.h"

Then run the function dlfunc_init for initialization.

    if(dlfunc_init(env) != JNI_OK) {
        LOGE("dlfunc init failed");
        return;
    }

Now just call dlfunc_dlopen and dlfunc_dlsym simply as calling dlopen/dlsym, except that the JNIEnv *env is passed in as the first argument:

    void *handle = dlfunc_dlopen(env, "libart.so", RTLD_LAZY);
    LOGI("libart handle is %p", handle);
    if(handle != NULL) {
        void *ptr = dlfunc_dlsym(env, handle, "MterpCheckBefore");
        LOGI("MterpCheckBefore is at %p", ptr);
    }

License

dlfunc is distributed under Apache License 2.0.

dlfunc's People

Contributors

rk700 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.