From 5cfaa29c732d85d15c98b35f64f1d559a6d17a51 Mon Sep 17 00:00:00 2001 From: GToad <34957641+GToad@users.noreply.github.com> Date: Mon, 24 Dec 2018 11:45:18 +0800 Subject: [PATCH] first commit --- AntiDebug/.gitignore | 9 + AntiDebug/.idea/gradle.xml | 18 + AntiDebug/.idea/misc.xml | 33 ++ AntiDebug/.idea/modules.xml | 9 + AntiDebug/.idea/runConfigurations.xml | 12 + AntiDebug/app/.gitignore | 1 + AntiDebug/app/CMakeLists.txt | 44 ++ AntiDebug/app/build.gradle | 38 ++ AntiDebug/app/proguard-rules.pro | 21 + .../antidebug/ExampleInstrumentedTest.java | 26 + AntiDebug/app/src/main/AndroidManifest.xml | 24 + AntiDebug/app/src/main/cpp/native-lib.cpp | 469 ++++++++++++++++++ .../com/sec/gtoad/antidebug/MainActivity.java | 117 +++++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++ .../res/drawable/ic_launcher_background.xml | 170 +++++++ .../app/src/main/res/layout/activity_main.xml | 89 ++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes AntiDebug/app/src/main/res/values/colors.xml | 6 + AntiDebug/app/src/main/res/values/strings.xml | 3 + AntiDebug/app/src/main/res/values/styles.xml | 11 + .../sec/gtoad/antidebug/ExampleUnitTest.java | 17 + AntiDebug/build.gradle | 27 + AntiDebug/gradle.properties | 18 + AntiDebug/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + AntiDebug/gradlew | 160 ++++++ AntiDebug/gradlew.bat | 90 ++++ AntiDebug/settings.gradle | 1 + 39 files changed, 1463 insertions(+) create mode 100644 AntiDebug/.gitignore create mode 100644 AntiDebug/.idea/gradle.xml create mode 100644 AntiDebug/.idea/misc.xml create mode 100644 AntiDebug/.idea/modules.xml create mode 100644 AntiDebug/.idea/runConfigurations.xml create mode 100644 AntiDebug/app/.gitignore create mode 100644 AntiDebug/app/CMakeLists.txt create mode 100644 AntiDebug/app/build.gradle create mode 100644 AntiDebug/app/proguard-rules.pro create mode 100644 AntiDebug/app/src/androidTest/java/com/sec/gtoad/antidebug/ExampleInstrumentedTest.java create mode 100644 AntiDebug/app/src/main/AndroidManifest.xml create mode 100644 AntiDebug/app/src/main/cpp/native-lib.cpp create mode 100644 AntiDebug/app/src/main/java/com/sec/gtoad/antidebug/MainActivity.java create mode 100644 AntiDebug/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 AntiDebug/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 AntiDebug/app/src/main/res/layout/activity_main.xml create mode 100644 AntiDebug/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 AntiDebug/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 AntiDebug/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 AntiDebug/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 AntiDebug/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 AntiDebug/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 AntiDebug/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 AntiDebug/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 AntiDebug/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 AntiDebug/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 AntiDebug/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 AntiDebug/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 AntiDebug/app/src/main/res/values/colors.xml create mode 100644 AntiDebug/app/src/main/res/values/strings.xml create mode 100644 AntiDebug/app/src/main/res/values/styles.xml create mode 100644 AntiDebug/app/src/test/java/com/sec/gtoad/antidebug/ExampleUnitTest.java create mode 100644 AntiDebug/build.gradle create mode 100644 AntiDebug/gradle.properties create mode 100644 AntiDebug/gradle/wrapper/gradle-wrapper.jar create mode 100644 AntiDebug/gradle/wrapper/gradle-wrapper.properties create mode 100644 AntiDebug/gradlew create mode 100644 AntiDebug/gradlew.bat create mode 100644 AntiDebug/settings.gradle diff --git a/AntiDebug/.gitignore b/AntiDebug/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/AntiDebug/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/AntiDebug/.idea/gradle.xml b/AntiDebug/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/AntiDebug/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/AntiDebug/.idea/misc.xml b/AntiDebug/.idea/misc.xml new file mode 100644 index 0000000..3963879 --- /dev/null +++ b/AntiDebug/.idea/misc.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/AntiDebug/.idea/modules.xml b/AntiDebug/.idea/modules.xml new file mode 100644 index 0000000..5298da7 --- /dev/null +++ b/AntiDebug/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/AntiDebug/.idea/runConfigurations.xml b/AntiDebug/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/AntiDebug/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/AntiDebug/app/.gitignore b/AntiDebug/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/AntiDebug/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/AntiDebug/app/CMakeLists.txt b/AntiDebug/app/CMakeLists.txt new file mode 100644 index 0000000..f8e6e8b --- /dev/null +++ b/AntiDebug/app/CMakeLists.txt @@ -0,0 +1,44 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html + +# Sets the minimum version of CMake required to build the native library. + +cmake_minimum_required(VERSION 3.4.1) + +# Creates and names a library, sets it as either STATIC +# or SHARED, and provides the relative paths to its source code. +# You can define multiple libraries, and CMake builds them for you. +# Gradle automatically packages shared libraries with your APK. + +add_library( # Sets the name of the library. + native-lib + + # Sets the library as a shared library. + SHARED + + # Provides a relative path to your source file(s). + src/main/cpp/native-lib.cpp ) + +# Searches for a specified prebuilt library and stores the path as a +# variable. Because CMake includes system libraries in the search path by +# default, you only need to specify the name of the public NDK library +# you want to add. CMake verifies that the library exists before +# completing its build. + +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. + +target_link_libraries( # Specifies the target library. + native-lib + + # Links the target library to the log library + # included in the NDK. + ${log-lib} ) \ No newline at end of file diff --git a/AntiDebug/app/build.gradle b/AntiDebug/app/build.gradle new file mode 100644 index 0000000..b3e5a93 --- /dev/null +++ b/AntiDebug/app/build.gradle @@ -0,0 +1,38 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + defaultConfig { + applicationId "com.sec.gtoad.antidebug" + minSdkVersion 15 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + externalNativeBuild { + cmake { + cppFlags "" + } + } + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + path "CMakeLists.txt" + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.2' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} diff --git a/AntiDebug/app/proguard-rules.pro b/AntiDebug/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/AntiDebug/app/proguard-rules.pro @@ -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 diff --git a/AntiDebug/app/src/androidTest/java/com/sec/gtoad/antidebug/ExampleInstrumentedTest.java b/AntiDebug/app/src/androidTest/java/com/sec/gtoad/antidebug/ExampleInstrumentedTest.java new file mode 100644 index 0000000..609df72 --- /dev/null +++ b/AntiDebug/app/src/androidTest/java/com/sec/gtoad/antidebug/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.sec.gtoad.antidebug; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.sec.gtoad.antidebug", appContext.getPackageName()); + } +} diff --git a/AntiDebug/app/src/main/AndroidManifest.xml b/AntiDebug/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..58f80f5 --- /dev/null +++ b/AntiDebug/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AntiDebug/app/src/main/cpp/native-lib.cpp b/AntiDebug/app/src/main/cpp/native-lib.cpp new file mode 100644 index 0000000..1f5022f --- /dev/null +++ b/AntiDebug/app/src/main/cpp/native-lib.cpp @@ -0,0 +1,469 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "android/log.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG_TAG "GToad" +#define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##args); +#define K 1024 +#define WRITELEN (128*K) +#define MAX (128*K) + + +extern "C" + + + + unsigned long getLibAddr (const char *lib) +{ + puts ("Enter getLibAddr"); + unsigned long addr = 0; + char lineBuf[256]; + + snprintf (lineBuf, 256-1, "/proc/%d/maps", getpid ()); + FILE *fp = fopen (lineBuf, "r"); + if (fp == NULL) { + perror ("fopen failed"); + goto bail; + } + while (fgets (lineBuf, sizeof(lineBuf), fp)) { + if (strstr (lineBuf, lib)) { + char *temp = strtok (lineBuf, "-"); + addr = strtoul (temp, NULL, 16); + break; + } + } + bail: + fclose(fp); + return addr; +} + +bool checkBreakPoint () +{ + __android_log_print(ANDROID_LOG_INFO,"JNI","13838438"); + int i, j; + unsigned int base, offset, pheader; + Elf32_Ehdr *elfhdr; + Elf32_Phdr *ph_t; + + base = getLibAddr ("libnative-lib.so"); + + if (base == 0) { + LOGI ("getLibAddr failed"); + return false; + } + __android_log_print(ANDROID_LOG_INFO,"JNI","13838439"); + + elfhdr = (Elf32_Ehdr *) base; + pheader = base + elfhdr->e_phoff; + + for (i = 0; i < elfhdr->e_phnum; i++) { + ph_t = (Elf32_Phdr*)(pheader + i * sizeof(Elf32_Phdr)); // traverse program header + + if ( !(ph_t->p_flags & 1) ) continue; + offset = base + ph_t->p_vaddr; + offset += sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * elfhdr->e_phnum; + + char *p = (char*)offset; + for (j = 0; j < ph_t->p_memsz; j++) { + if(*p == 0x01 && *(p+1) == 0xde) { + LOGI ("Find thumb bpt %p", p); + return true; + } else if (*p == 0xf0 && *(p+1) == 0xf7 && *(p+2) == 0x00 && *(p+3) == 0xa0) { + LOGI ("Find thumb2 bpt %p", p); + return true; + } else if (*p == 0x01 && *(p+1) == 0x00 && *(p+2) == 0x9f && *(p+3) == 0xef) { + LOGI ("Find arm bpt %p", p); + return true; + } + p++; + } + } + return false; +} + +extern "C" +JNIEXPORT jstring + +JNICALL +Java_com_sec_gtoad_antidebug_MainActivity_stringFromJNI( + JNIEnv *env, + jobject /* this */) { + std::string hello = "Hello from C++"; + return env->NewStringUTF(hello.c_str()); +} + +extern "C" +JNIEXPORT jstring + +JNICALL +Java_com_sec_gtoad_antidebug_MainActivity_stringFromTime( + JNIEnv *env, + jobject /* this */) { + long start,end; + start = clock(); + std::string hello = "Hello from time"; + end = clock(); + if(end-start>10000){ + hello = "Debug from time"; + } + return env->NewStringUTF(hello.c_str()); +} + +extern "C" +JNIEXPORT jstring + +JNICALL +Java_com_sec_gtoad_antidebug_MainActivity_stringFromFile( + JNIEnv *env, + jobject /* this */) { + std::string hello; + std::stringstream stream; + int pid = getpid(); + int fd; + stream << pid; + stream >> hello; + hello = "/proc/" + hello + "/status"; + //LOGI(hello); + char* pathname = new char[30]; + strcpy(pathname,hello.c_str()); + char* buf = new char[500]; + int flag = O_RDONLY; + fd = open(pathname, flag); + read(fd, buf, 500); + char* c; + char* tra = "TracerPid"; + c = strstr(buf, tra); + char* d; + d = strstr(c,"\n"); + int length = d-c; + strncpy(buf,c+11,length-11); + buf[length-11]='\0'; + hello = buf; + if (strcmp(buf,"0")){ + hello = "Debug from file"; + } + else{ + hello = "Hello from file"; + } + close(fd); + + return env->NewStringUTF(hello.c_str()); +} + +extern "C" +JNIEXPORT jstring + +JNICALL +Java_com_sec_gtoad_antidebug_MainActivity_stringFromTrick( + JNIEnv *env, + jobject /* this */) { + std::string hello = "Hello from trick"; + return env->NewStringUTF(hello.c_str()); +} + +extern "C" +JNIEXPORT jstring + +JNICALL +Java_com_sec_gtoad_antidebug_MainActivity_stringFromVm( + JNIEnv *env, + jobject /* this */) { + std::string hello = "Hello from vm"; + return env->NewStringUTF(hello.c_str()); +} + +extern "C" +JNIEXPORT jstring + +JNICALL +Java_com_sec_gtoad_antidebug_MainActivity_stringFromPtrace( + JNIEnv *env, + jobject /* this */) { + int check = ptrace(PTRACE_TRACEME,0 ,0 ,0); + LOGI("ret of ptrace : %d",check); + std::string hello = "Hello from ptrace"; + if(check != 0){ + hello = "Debug from ptrace"; + } + return env->NewStringUTF(hello.c_str()); +} + +extern "C" +JNIEXPORT jstring + +JNICALL +Java_com_sec_gtoad_antidebug_MainActivity_stringFromBkpt( + JNIEnv *env, + jobject /* this */) { + std::string hello = "Hello from bkpt"; + if(checkBreakPoint()) + hello = "Debug from bkpt"; + return env->NewStringUTF(hello.c_str()); +} + +char dynamic_ccode[] = {0x1f,0xb4, //push {r0-r4} + 0x01,0xde, //breakpoint + 0x1f,0xbc, //pop {r0-r4} + 0xf7,0x46};//mov pc,lr + +char *g_addr = 0; + +void my_sigtrap(int sig){ + LOGI("my_sigtrap\n"); + + char change_bkp[] = {0x00,0x46}; //mov r0,r0 + memcpy(g_addr+2,change_bkp,2); + __builtin___clear_cache(g_addr,(g_addr+8)); // need to clear cache + LOGI("chang bpk to nop\n"); + +} + +void anti4(){//SIGTRAP + + int ret,size; + char *addr,*tmpaddr; + + signal(SIGTRAP,my_sigtrap); + + addr = (char*)malloc(PAGE_SIZE*2); + + memset(addr,0,PAGE_SIZE*2); + g_addr = (char *)(( (long)addr + PAGE_SIZE-1) & ~(PAGE_SIZE-1)); + + LOGI("addr: %p ,g_addr : %p\n",addr,g_addr); + + ret = mprotect(g_addr,PAGE_SIZE,PROT_READ|PROT_WRITE|PROT_EXEC); + if(ret!=0) + { + LOGI("mprotect error\n"); + return ; + } + + size = 8; + memcpy(g_addr,dynamic_ccode,size); + + __builtin___clear_cache(g_addr,(g_addr+size)); // need to clear cache + LOGI("start stub\n"); + + __asm__("push {r5}\n\t" + "push {r0-r4,lr}\n\t" + "mov r0,pc\n\t" //此时pc指向后两条指令 + "add r0,r0,#6\n\t"//cjh:这里的add是add.w,所以会占32位,因此需要+6才对。 原文:+4 是的lr 地址为 pop{r0-r5} + "mov lr,r0\n\t" + "mov pc,%0\n\t" + "pop {r0-r5}\n\t" + "mov lr,r5\n\t" //恢复lr + "pop {r5}\n\t" + : + :"r"(g_addr) + :); + + LOGI("hi, i'm here\n"); + free(addr); + LOGI("hi, i'm here2\n"); + +} + +extern "C" +JNIEXPORT jstring + +JNICALL +Java_com_sec_gtoad_antidebug_MainActivity_stringFromSignal( + JNIEnv *env, + jobject /* this */) { + anti4(); + std::string hello = "Hello from signal"; + return env->NewStringUTF(hello.c_str()); +} + +//------------------------------------------------fork--------------------------------------------------------------------- +int pipefd[2]; +int childpid; + +void *anti3_thread(void *){ + + int statue=-1,alive=1,count=0; + + close(pipefd[1]); + + while(read(pipefd[0],&statue,4)>0) + break; + sleep(1); + + //这里改为非阻塞 + fcntl(pipefd[0], F_SETFL, O_NONBLOCK); //enable fd的O_NONBLOCK + + LOGI("pip-->read = %d", statue); + + while(true) { + + LOGI("pip--> statue = %d", statue); + read(pipefd[0], &statue, 4); + sleep(1); + + LOGI("pip--> statue2 = %d", statue); + if (statue != 0) { + kill(childpid,SIGKILL); + kill(getpid(), SIGKILL); + return NULL; + } + statue = -1; + } +} + +void anti3(){ + int pid,p; + FILE *fd; + char filename[MAX]; + char line[MAX]; + + pid = getpid(); + sprintf(filename,"/proc/%d/status",pid);// 读取proc/pid/status中的TracerPid + p = fork(); + if(p==0) //child + { + LOGI("Child"); + close(pipefd[0]); //关闭子进程的读管道 + int pt,alive=0; + pt = ptrace(PTRACE_TRACEME, 0, 0, 0); //子进程反调试 + while(true) + { + fd = fopen(filename,"r"); + while(fgets(line,MAX,fd)) + { + if(strstr(line,"TracerPid") != NULL) + { + LOGI("line %s",line); + int statue = atoi(&line[10]); + LOGI("########## tracer pid:%d", statue); + write(pipefd[1],&statue,4);//子进程向父进程写 statue值 + + fclose(fd); + + if(statue != 0) + { + LOGI("########## tracer pid:%d", statue); + return ; + } + + break; + } + } + sleep(1); + + } + }else{ + LOGI("Father"); + childpid = p; + } +} + +extern "C" +JNIEXPORT jstring + +JNICALL +Java_com_sec_gtoad_antidebug_MainActivity_stringFromFork( + JNIEnv *env, + jobject /* this */) { + std::string hello = "Hello from fork"; + pthread_t id_0; + id_0 = pthread_self(); + pipe(pipefd); + pthread_create(&id_0,NULL,anti3_thread,(void*)NULL); + LOGI("Start"); + anti3(); + /* + pid_t pid; + int result = -1; + int fd[2]; + int nbytes; + char string[WRITELEN] = "Hello my pipe 2018!"; + char readbuffer[10*K]; + + int *write_fd = &fd[1]; + int *read_fd = &fd[0]; + + result = pipe(fd); + if(result==-1) + { + LOGI("Fail to create pipe\n"); + hello = "Debug from fork"; + } + + pid = fork(); + + if(pid == -1) + { + LOGI("Fail to fork"); + hello = "Debug from fork"; + } + + if(pid == 0) + { + LOGI("SON"); + int write_size = WRITELEN; + result = 0; + close(*read_fd); + while(write_size>=0) + { + result = write(*write_fd,string,write_size); + if(result>0){ + write_size -= result; + LOGI("Write %d bytes data, the rest is %d bytes",result, write_size); + } + else + { + sleep(10); + } + } + return env->NewStringUTF(hello.c_str()); + } + else + { + LOGI("FATHER"); + close(*write_fd); + while(1) + { + nbytes = read(*read_fd,readbuffer,sizeof(readbuffer)); + if(nbytes<=0) + { + LOGI("No data to write."); + break; + } + LOGI("receive %d bytes data : %s",nbytes,readbuffer); + } + return env->NewStringUTF(hello.c_str()); + }*/ + + return env->NewStringUTF(hello.c_str()); +} + + diff --git a/AntiDebug/app/src/main/java/com/sec/gtoad/antidebug/MainActivity.java b/AntiDebug/app/src/main/java/com/sec/gtoad/antidebug/MainActivity.java new file mode 100644 index 0000000..ce1e06a --- /dev/null +++ b/AntiDebug/app/src/main/java/com/sec/gtoad/antidebug/MainActivity.java @@ -0,0 +1,117 @@ +package com.sec.gtoad.antidebug; + +import android.content.Context; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +public class MainActivity extends AppCompatActivity { + + // Used to load the 'native-lib' library on application startup. + static { + System.loadLibrary("native-lib"); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + //final Context context = getApplicationContext(); + + Button time_button = (Button)findViewById(R.id.time_button); + Button file_button = (Button)findViewById(R.id.file_button); + Button trick_button = (Button)findViewById(R.id.trick_button); + Button vm_button = (Button)findViewById(R.id.vm_button); + Button ptrace_button = (Button)findViewById(R.id.ptrace_button); + Button bkpt_button = (Button)findViewById(R.id.bkpt_button); + Button fork_button = (Button)findViewById(R.id.fork_button); + Button signal_button = (Button)findViewById(R.id.signal_button); + + time_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Context context = getApplicationContext(); + Toast.makeText(context, stringFromTime(),Toast.LENGTH_LONG).show(); + } + }); + + file_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Context context = getApplicationContext(); + Toast.makeText(context, stringFromFile(),Toast.LENGTH_LONG).show(); + } + }); + + trick_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Context context = getApplicationContext(); + Toast.makeText(context, stringFromTrick(),Toast.LENGTH_LONG).show(); + } + }); + + vm_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Context context = getApplicationContext(); + if(android.os.Debug.isDebuggerConnected()){ + Toast.makeText(context, "Debug from vm",Toast.LENGTH_LONG).show(); + } + else{ + Toast.makeText(context, "Hello from vm",Toast.LENGTH_LONG).show(); + } + } + }); + + ptrace_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Context context = getApplicationContext(); + Toast.makeText(context, stringFromPtrace(),Toast.LENGTH_LONG).show(); + } + }); + + bkpt_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Context context = getApplicationContext(); + Toast.makeText(context, stringFromBkpt(),Toast.LENGTH_LONG).show(); + } + }); + + fork_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Context context = getApplicationContext(); + Toast.makeText(context, stringFromFork(),Toast.LENGTH_LONG).show(); + } + }); + + signal_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Context context = getApplicationContext(); + Toast.makeText(context, stringFromSignal(),Toast.LENGTH_LONG).show(); + } + }); + } + + /** + * A native method that is implemented by the 'native-lib' native library, + * which is packaged with this application. + */ + public native String stringFromJNI(); + public native String stringFromTime(); + public native String stringFromFile(); + public native String stringFromTrick(); + public native String stringFromVm(); + public native String stringFromPtrace(); + public native String stringFromBkpt(); + public native String stringFromFork(); + public native String stringFromSignal(); +} diff --git a/AntiDebug/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/AntiDebug/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/AntiDebug/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/AntiDebug/app/src/main/res/drawable/ic_launcher_background.xml b/AntiDebug/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..d5fccc5 --- /dev/null +++ b/AntiDebug/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AntiDebug/app/src/main/res/layout/activity_main.xml b/AntiDebug/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..04c8ba4 --- /dev/null +++ b/AntiDebug/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,89 @@ + + + +