Skip to content

lxzh/SecShell

Repository files navigation

SecShell

中文说明

1. prepare sdk

  • build sdk

build the sdk to be reinforced, such as libcore

gradle libcore:build
  • unzip aar

unzip the release sdk aar in libcore/build/outputs/aar/libcore-release.aar, get the jar libcore.jar file in the aar package, copy libcore.jar to libsag/output for generating stub-sdk

  • jar to dex

transfore the jar file to dex file, because BaseDexClassLoader cannot load normal jar package, so we need to convert the jar to dex package with dx tool in android sdk:

dx --dex --output=libcore.dex libcore.jar

or d2j-jar2dex.bat:

d2j-jar2dex.bat libcore.jar -o libcore.dex

then copy libcore.dex to libmix/output generate mixed dex

2. sdk proguard

  • encrypt sdk

use libmix to encrypt sdk

gradle libmix:build

build libmix to exec encrypt task, the build script will automatically encrypt the dex and copy it to libshell/src/main/assets/

  • generate stub-sdk

To hide the key code of our sdk and ensure that users can develop properly, we provide stub-sdk for user compileOnly reference, and load the actual SDK through shell tools. In this scheme, the stub-sdk is generated based on the reflection principle of Java. Empty Java classes are generated by loading the jar/dex file in the aar package of SDK. Since the class loading process also requires loading the import package referenced in the SDK, for ordinary java-library, it relies on the Java native package and can be generated on the PC side. For android-library, it depends on android framework and needs to be generated in android. Therefore, the generation of stub-sdk provides libsag and sag two projects.The former is jar, using the URLClassLoader in Java to load the jar package, reflection generation stub; The latter is an Android app, which uses the DexClassLoader of Android to load the dex package. Meanwhile, libsag is used to parse the jar package by JarFile to extract the file structure and generate stub by reflection.

  1. use libsag to generate stub-sdk source file
gradle libsag:build

build libsag to generate stub-sdk, the build script will automatically parse the jar and write empyt java file with no mothod implementation to the corestub source folder:corestub/src/main/java/

  1. use sag to generate stub-sdk source file
gradle sag:build

build sag to perform the stub-sdk generation task, the build script will automatically the build script will automatically copy the jar package and dex package to the linked mobile phone or emulator, install the sag application and generate Java files without function implementation to /sdcard/sdkshell/sdk directory, and then pull to the corestub source code directory through adb command :corestub/src/main/java/

  • build stub sdk
gradle corestub:build

build corestub to generate corestub.aar for compileOnly use in user app, the build script will automatically copy it to demo/geetestsdk/

3. build demo

gradle demo:build

build the demo project to get example apk