Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/implement bypass #1

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ captures/
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml
.idea/
.idea/codeStyles

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
Expand Down
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(NativeBypass
VERSION 1.0
LANGUAGES CXX C
)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WINDOWS TRUE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LINUX TRUE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
endif ()



# Now simply link your own targets against gtest, gmock,
# etc. as appropriate

#####################


add_subdirectory(src)
add_subdirectory(androidTest)

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# NativeRestrictionBypass
# NativeRestrictionBypass

| | Build & Test |
|---|:-----:|
|![Linux](docs/res/linux_med.png) **Linux**|[![Build & Test][linux-build-badge]][linux-build]|


[linux-build-badge]: https://dev.azure.com/ChickenHook/ChickenHook/_apis/build/status/ChickenHook.NativeRestrictionBypass
[linux-build]: https://dev.azure.com/ChickenHook/ChickenHook/_build?definitionId=4
1 change: 1 addition & 0 deletions androidTest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
34 changes: 34 additions & 0 deletions androidTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.6)




### Libraries
ADD_LIBRARY( androidTest SHARED
"src/main/cpp/interface.cpp"
)

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

include_directories(
"src/main/cpp/")
include_directories(
"../src")
include_directories(
"../src/include")

target_link_libraries( # Specifies the target library.
androidTest
${PROJECT_NAME}
# Links the target library to the log library
# included in the NDK.
${log-lib})
53 changes: 53 additions & 0 deletions androidTest/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
ndkVersion "21.3.6528147"
buildToolsVersion "30.0.0"

defaultConfig {
applicationId "com.kobil.libloader"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

externalNativeBuild {
cmake {
abiFilters 'arm64-v8a', 'x86', 'x86_64'
arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_FORCE_ARM_BUILD=ON"
cppFlags "-fexceptions", "-std=c++14"
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}


externalNativeBuild {
cmake {
path "../CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}
21 changes: 21 additions & 0 deletions androidTest/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kobil.libloader

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.kobil.libloader", appContext.packageName)
}
}
21 changes: 21 additions & 0 deletions androidTest/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kobil.libloader">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
94 changes: 94 additions & 0 deletions androidTest/src/main/cpp/interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <jni.h>
#include <android/log.h>
#include <thread>
#include <future>
#include <tools/LoggingCallback.h>
#include <include/NativeBypass/bypass.h>
#include "../../../../src/DiskLoader.h"

JavaVM *_vm;

static jint Java_loadFromStorage(
JNIEnv *env,
jclass clazz,
jstring name) {

}

static jint Java_load(
JNIEnv *env,
jclass clazz,
jstring jpath) {
jboolean isCopy;
const char *str = env->GetStringUTFChars(jpath, &isCopy);
std::string path(str);
return DiskLoader::load(path,_vm);

return 1;
}
static jlong Java_getAddr(
JNIEnv *env,
jclass clazz,
jstring library,
jstring symbol) {
jboolean isCopy;
const char *lib_cstr = env->GetStringUTFChars(library, &isCopy);
std::string lib(lib_cstr);
const char *sym_cstr = env->GetStringUTFChars(symbol, &isCopy);
std::string sym(sym_cstr);
return (long) ChickenHook::NativeBypass::Resolve::ResolveSymbol(lib,sym);

return 1;
}


static const JNINativeMethod gMethods[] = {
{"getAddr", "(Ljava/lang/String;Ljava/lang/String;)J", (void *) Java_getAddr},
{"load", "(Ljava/lang/String;)I", (void *) Java_load},
{"loadFromStorage", "(Ljava/lang/String;)I", (void *) Java_loadFromStorage}
};
static const char *classPathName = "com/kobil/libloader/NativeInterface";


static int registerNativeMethods(JNIEnv *env, const char *className,
JNINativeMethod *gMethods, int numMethods) {
jclass clazz;
clazz = env->FindClass(className);
if (clazz == nullptr) {
__android_log_print(ANDROID_LOG_DEBUG, "registerNativeMethods",
"Native registration unable to find class '%s'", className);
return JNI_FALSE;
}
if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
__android_log_print(ANDROID_LOG_DEBUG, "registerNativeMethods",
"Native registration unable to register natives...");
return JNI_FALSE;
}
return JNI_TRUE;
}


jint JNI_OnLoad(JavaVM *vm, void * /*reserved*/) {
_vm = vm;
JNIEnv *env = nullptr;
if (vm->GetEnv((void **) (&env), JNI_VERSION_1_4) != JNI_OK) {
return -1;
}


if (!registerNativeMethods(env, classPathName,
(JNINativeMethod *) gMethods,
sizeof(gMethods) / sizeof(gMethods[0]))) {
return -1;
}

setLogFunction([](const std::string &str) {
__android_log_print(ANDROID_LOG_DEBUG, "Interface", "%s", str.c_str());
});

ChickenHook::setLogFunction([](const std::string str) {
__android_log_print(ANDROID_LOG_DEBUG, "Interface", "%s", str.c_str());
});

return JNI_VERSION_1_4;
}
24 changes: 24 additions & 0 deletions androidTest/src/main/java/com/kobil/libloader/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kobil.libloader

import android.os.Bundle
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import java.security.KeyStore
import java.util.*
import javax.crypto.KeyGenerator
import kotlin.experimental.and


class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

Log.d(
"MainActivity",
"Load symbol <" + NativeInterface.getAddr("libart.so","artFindNativeMethodRunnable") + ">"
);
}
}
10 changes: 10 additions & 0 deletions androidTest/src/main/java/com/kobil/libloader/NativeInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kobil.libloader;

class NativeInterface {
static {
System.loadLibrary("androidTest");
}
public static native long getAddr(String lib, String symbol);
public static native int load(String path);
public static native int loadFromStorage(String path);
}
30 changes: 30 additions & 0 deletions androidTest/src/main/res/drawable-v24/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
Loading