Skip to content

Commit ef046fa

Browse files
first commit
1 parent e03697a commit ef046fa

40 files changed

+952
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle.kts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
}
4+
5+
android {
6+
namespace = "com.test.uprobechecker"
7+
compileSdk = 35
8+
9+
defaultConfig {
10+
applicationId = "com.test.uprobechecker"
11+
minSdk = 29
12+
targetSdk = 35
13+
versionCode = 1
14+
versionName = "1.0"
15+
16+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
isMinifyEnabled = false
22+
proguardFiles(
23+
getDefaultProguardFile("proguard-android-optimize.txt"),
24+
"proguard-rules.pro"
25+
)
26+
}
27+
}
28+
compileOptions {
29+
sourceCompatibility = JavaVersion.VERSION_11
30+
targetCompatibility = JavaVersion.VERSION_11
31+
}
32+
externalNativeBuild {
33+
cmake {
34+
path = file("src/main/cpp/CMakeLists.txt")
35+
version = "3.22.1"
36+
}
37+
}
38+
buildFeatures {
39+
viewBinding = true
40+
}
41+
}
42+
43+
dependencies {
44+
45+
implementation(libs.appcompat)
46+
implementation(libs.material)
47+
implementation(libs.constraintlayout)
48+
testImplementation(libs.junit)
49+
androidTestImplementation(libs.ext.junit)
50+
androidTestImplementation(libs.espresso.core)
51+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.test.uprobechecker;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.test.uprobechecker", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.UprobeChecker"
14+
tools:targetApi="31">
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>

app/src/main/cpp/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# For more information about using CMake with Android Studio, read the
2+
# documentation: https://d.android.com/studio/projects/add-native-code.html.
3+
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
4+
5+
# Sets the minimum CMake version required for this project.
6+
cmake_minimum_required(VERSION 3.22.1)
7+
8+
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
9+
# Since this is the top level CMakeLists.txt, the project name is also accessible
10+
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
11+
# build script scope).
12+
project("uprobechecker")
13+
14+
# Creates and names a library, sets it as either STATIC
15+
# or SHARED, and provides the relative paths to its source code.
16+
# You can define multiple libraries, and CMake builds them for you.
17+
# Gradle automatically packages shared libraries with your APK.
18+
#
19+
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
20+
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
21+
# is preferred for the same purpose.
22+
#
23+
# In order to load a library into your app from Java/Kotlin, you must call
24+
# System.loadLibrary() and pass the name of the library defined here;
25+
# for GameActivity/NativeActivity derived applications, the same library name must be
26+
# used in the AndroidManifest.xml file.
27+
add_library(${CMAKE_PROJECT_NAME} SHARED
28+
# List C/C++ source files with relative paths to this CMakeLists.txt.
29+
native-lib.cpp)
30+
31+
# Specifies libraries CMake should link to your target library. You
32+
# can link libraries from various origins, such as libraries defined in this
33+
# build script, prebuilt third-party libraries, or Android system libraries.
34+
target_link_libraries(${CMAKE_PROJECT_NAME}
35+
# List libraries link to the target library
36+
android
37+
log)

app/src/main/cpp/log.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <android/log.h>
2+
3+
#define LOG_TAG "Test-Log"
4+
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
5+
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
6+
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
7+
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)

app/src/main/cpp/native-lib.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <jni.h>
2+
#include <string>
3+
#include <unistd.h>
4+
#include <sys/mman.h>
5+
#include "log.h"
6+
7+
8+
bool is_address_accessible(void* addr) {
9+
unsigned char vec;
10+
long page_size = sysconf(_SC_PAGESIZE);
11+
void* page_start = (void*)((long)addr & ~(page_size - 1));
12+
13+
return mincore(page_start, page_size, &vec) == 0;
14+
}
15+
16+
extern "C"
17+
JNIEXPORT jboolean JNICALL
18+
Java_com_test_uprobechecker_MainActivity_is_1find_1upobes(JNIEnv *env, jobject thiz) {
19+
bool uprobe_flag = false;
20+
const int bufsize = 1024;
21+
char filename[bufsize];
22+
char line[bufsize];
23+
FILE* fd = fopen("/proc/self/maps", "r");
24+
if (fd != nullptr) {
25+
while (fgets(line, bufsize, fd)) {
26+
if (strstr(line, "[uprobes]")) {
27+
uprobe_flag = true;
28+
break;
29+
}
30+
}
31+
fclose(fd);
32+
}
33+
34+
if(uprobe_flag){
35+
return true;
36+
}
37+
38+
uprobe_flag = is_address_accessible((void *)0x7ffffff000);
39+
return uprobe_flag;
40+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.test.uprobechecker;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.widget.TextView;
7+
8+
import com.test.uprobechecker.databinding.ActivityMainBinding;
9+
10+
import java.util.Timer;
11+
import java.util.TimerTask;
12+
13+
public class MainActivity extends AppCompatActivity {
14+
15+
// Used to load the 'uprobechecker' library on application startup.
16+
static {
17+
System.loadLibrary("uprobechecker");
18+
}
19+
20+
private ActivityMainBinding binding;
21+
boolean uprobe_flag = false;
22+
23+
@Override
24+
protected void onCreate(Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
27+
binding = ActivityMainBinding.inflate(getLayoutInflater());
28+
setContentView(binding.getRoot());
29+
30+
// Example of a call to a native method
31+
TextView tv = binding.sampleText;
32+
33+
Timer timer = new Timer();
34+
TimerTask task = new TimerTask() {
35+
@Override
36+
public void run() {
37+
uprobe_flag = is_find_upobes();
38+
// 后台线程执行的任务
39+
runOnUiThread(() -> {
40+
if(uprobe_flag){
41+
tv.setText("Find uprobe");
42+
}else {
43+
tv.setText("Not found uprobe");
44+
}
45+
46+
});
47+
}
48+
};
49+
50+
timer.schedule(task, 1000, 1000);
51+
}
52+
53+
54+
public native boolean is_find_upobes();
55+
}

0 commit comments

Comments
 (0)