知乎 Android 团队使用的 Java 库静态代码检查工具,支持目录、.jar、.aar 格式,可通过配置文件添加检查策略

Related tags

Tools SimpleWalker
Overview

SimpleWalker

知乎 Android 团队使用的 Java 库静态代码检查工具,支持目录、.zip、.aar 格式,可通过配置文件添加检查策略。 主要用于检查 Android 应用的三方依赖是否有调用隐私接口。

使用方法

项目工程中 release/ 目录下是最新版本的可执行文件,help 输出如下:

zkw@zkw-mint: java -jar ./SimpleWalker-1.0.jar
Usage: SimpleWalker(一个简单的静态代码扫描工具,可通过文件配置,支持目录、jar、aar 格式) [options]
  Options:
    -h, --help

  * -i, --input
      被扫描的文件,支持 jar、aar 和存放这些文件的目录
    -o, --output
      Json 报告输出文件名,默认为当前目录的 result.json
      Default: ./result.json
  * -p, --policy
      规则配置文件,根据规则进行扫描

根据参数制定输入文件和策略配置文件:

zkw@zkw-mint: java -jar ./release/SimpleWalker-1.0.jar -i ~/jars/ -p ./release/policy                                                                               SIGINT(2) ↵  8711  16:55:48
报告文件:/home/zkw/my_project/SimpleWalker/result.json

其中默认配置文件 policy 的内容如下:

#每行代表一个策略,以 ',' 分隔,含义分别是:指令类型,类名,方法名/属性名,描述
#以第一行策略为例,其含义是当源码中有通过指令 invokevirtual 调用 TelephonyManager 的任意方法时触发策略
invokevirtual,android.telephony.TelephonyManager,all,获取手机 ID 信息
invokespecial,dalvik.system.DexClassLoader,
   
    ,可能是热更新
invokevirtual,java.lang.Runtime,exec,执行外部命令
invokevirtual,android.accounts.AccountManager,getAccounts,获取帐号列表
invokevirtual,android.content.pm.PackageManager,getInstalled,获取已安装应用列表
invokevirtual,android.content.pm.PackageManager,queryIntentActivit,获取已安装取应用列表
invokevirtual,android.bluetooth.BluetoothAdapter,all,获取蓝牙信息
getstatic,android.provider.ContactsContract$Contacts,CONTENTURI,获取联系人信息
invokevirtual,android.net.wifi.WifiInfo,getMacAddress,获取 MAC 地址
invokevirtual,java.net.NetworkInterface,getNetworkInterfaces,获取 MAC 地址
invokevirtual,android.nfc.NfcAdapter,all,获取 NFC 信息
invokevirtual,android.app.ActivityManager,getRunningAppProcesses,获取正在运行的应用列表
invokevirtual,android.hardware.SensorManager,all,获取传感器信息
invokevirtual,android.net.wifi.WifiManager,getConnectionInfo,获取 WIFI 信息

   

每行代表一个策略,以 ',' 分隔,含义分别是:指令类型,类名,方法名/属性名,描述。 以第一行策略为例,其含义是当源码中有通过指令 invokevirtual 调用 TelephonyManager 的任意方法时触发策略。

成功的话会输出报告文件 result.json,报告文件的内容格式如下:

(),可能是热更新" ], "java/net/NetworkInterface 获取 MAC 地址": [], "android/nfc/NfcAdapter 获取 NFC 信息": [], "android/app/ActivityManager 获取正在运行的应用列表": [ "文件 pushxxx.aar 中的 com/sdk/PushManager.e() 方法调用了 ActivityManager.getRunningAppProcesses(),获取正在运行的应用列表", "文件 bccxxx.aar 中的 com/smartlink/util/a.b() 方法调用了 ActivityManager.getRunningAppProcesses(),获取正在运行的应用列表" ], "android/bluetooth/BluetoothAdapter 获取蓝牙信息": [], "android/hardware/SensorManager 获取传感器信息": [ "文件 location.jar 中的 com/ds. () 方法调用了 SensorManager.getDefaultSensor(),获取传感器信息" ], "android/telephony/TelephonyManager 获取手机 ID 信息": [ "文件 osdk.aar 中的 com/common/utils/Utils.getOperatorName() 方法调用了 TelephonyManager.getSimOperator(),获取手机 ID 信息", "文件 bccxxx.aar 中的 com/smartlink/util/a.a() 方法调用了 TelephonyManager.getDeviceId(),获取手机 ID 信息" ], "android/content/pm/PackageManager 获取已安装应用列表": [], "java/lang/Runtime 执行外部命令": [ "文件 pushxxx.aar 中的 com/push/core/e.a() 方法调用了 Runtime.exec(),执行外部命令" ], "android/accounts/AccountManager 获取帐号列表": [], "android/content/pm/PackageManager 获取已安装取应用列表": [], "android/net/wifi/WifiInfo 获取 MAC 地址": [ "文件 location.jar 中的 com/n.m() 方法调用了 WifiInfo.getMacAddress(),获取 MAC 地址", "文件 xunnnnn.aar 中的 com/voiceads/utils/k.b() 方法调用了 WifiInfo.getMacAddress(),获取 MAC 地址" ] } ">
{
  "android/net/wifi/WifiManager 获取 WIFI 信息": [
    "文件 location.jar 中的 com/dw.c() 方法调用了 WifiManager.getConnectionInfo(),获取 WIFI 信息",
    "文件 adxxx.aar 中的 com/cpu/d.f() 方法调用了 WifiManager.getConnectionInfo(),获取 WIFI 信息",
    "文件 facccc.aar 中的 com/apo/l.a() 方法调用了 WifiManager.getConnectionInfo(),获取 WIFI 信息"
  ],
  "android/provider/ContactsContract$Contacts 获取联系人信息": [],
  "dalvik/system/DexClassLoader 可能是热更新": [
    "文件 adxxx.aar 中的 com/xda.permissionClick() 方法调用了 DexClassLoader.
    
     (),可能是热更新
     "
    
  ],
  "java/net/NetworkInterface 获取 MAC 地址": [],
  "android/nfc/NfcAdapter 获取 NFC 信息": [],
  "android/app/ActivityManager 获取正在运行的应用列表": [
    "文件 pushxxx.aar 中的 com/sdk/PushManager.e() 方法调用了 ActivityManager.getRunningAppProcesses(),获取正在运行的应用列表",
    "文件 bccxxx.aar 中的 com/smartlink/util/a.b() 方法调用了 ActivityManager.getRunningAppProcesses(),获取正在运行的应用列表"
  ],
  "android/bluetooth/BluetoothAdapter 获取蓝牙信息": [],
  "android/hardware/SensorManager 获取传感器信息": [
    "文件 location.jar 中的 com/ds.
    
     () 方法调用了 SensorManager.getDefaultSensor(),获取传感器信息
     "
    
  ],
  "android/telephony/TelephonyManager 获取手机 ID 信息": [
    "文件 osdk.aar 中的 com/common/utils/Utils.getOperatorName() 方法调用了 TelephonyManager.getSimOperator(),获取手机 ID 信息",
    "文件 bccxxx.aar 中的 com/smartlink/util/a.a() 方法调用了 TelephonyManager.getDeviceId(),获取手机 ID 信息"
  ],
  "android/content/pm/PackageManager 获取已安装应用列表": [],
  "java/lang/Runtime 执行外部命令": [
    "文件 pushxxx.aar 中的 com/push/core/e.a() 方法调用了 Runtime.exec(),执行外部命令"
  ],
  "android/accounts/AccountManager 获取帐号列表": [],
  "android/content/pm/PackageManager 获取已安装取应用列表": [],
  "android/net/wifi/WifiInfo 获取 MAC 地址": [
    "文件 location.jar 中的 com/n.m() 方法调用了 WifiInfo.getMacAddress(),获取 MAC 地址",
    "文件 xunnnnn.aar 中的 com/voiceads/utils/k.b() 方法调用了 WifiInfo.getMacAddress(),获取 MAC 地址"
  ]
}

从报告中可以看到 jar 或 aar 包中的 class 中对敏感函数的调用关系,使用者可以根据此报告对第三方 SDK 做简单判断。

You might also like...
Automated-build-android-app-with-github-action - CI/CD Automated Build Android App Bundle / APK / Signed With Github Action
Automated-build-android-app-with-github-action - CI/CD Automated Build Android App Bundle / APK / Signed With Github Action

Automated Build Android With Using Github Action Project Github Action Script Us

proguard resource for Android by wechat team

AndResGuard Read this in other languages: English, 简体中文. AndResGuard is a tooling for reducing your apk size, it works like the ProGuard for Java sour

A super fast build tool for Android, an alternative to Instant Run
A super fast build tool for Android, an alternative to Instant Run

Freeline Freeline is a super fast build tool for Android and an alternative to Instant Run. Caching reusable class files and resource indices, it enab

Command-line tool to count per-package methods in Android .dex files

dex-method-counts Simple tool to output per-package method counts in an Android DEX executable grouped by package, to aid in getting under the 65,536

View Inspection Toolbar for Android Development
View Inspection Toolbar for Android Development

View Inspector Plugin View inspection toolbar for android development. Features Boundary show outlines show margins show paddings Layer Scalpel featur

Make Android screenshots of scrollable screen content
Make Android screenshots of scrollable screen content

scrollscreenshot Make Android screenshots of scrollable screen content - brought to you by PGS Software SA This tool makes a number of screenshots, sc

🍼Debug Bottle is an Android runtime debug / develop tools written using kotlin language.
🍼Debug Bottle is an Android runtime debug / develop tools written using kotlin language.

🇨🇳 中文 / 🇯🇵 日本語 / 🇬🇧 English 🍼 Debug Bottle An Android debug / develop tools written using Kotlin language. All the features in Debug bottle are

[] Dissect layout traversals on Android
[] Dissect layout traversals on Android

Probe Dissect layout traversals on Android. Features Intercept View methods. onMeasure(int, int) onLayout(boolean, int, int, int, int) draw(Canvas) an

Android Library Finder
Android Library Finder

alfi Android Library Finder Search through thousands of android libraries that can help you scale your projects elegantly Usage Search for something a

Comments
  • "main" d2j.api.DexException: not support magic.

    java -jar SimpleWalker-1.3.jar -i hello.apk -p policy Exception in thread "main" d2j.api.DexException: not support magic. at d2j.reader.DexFileReader.(DexFileReader.java:169) at d2j.reader.DexFileReader.(DexFileReader.java:267) at d2j.reader.DexFileReader.(DexFileReader.java:285) at com.zhihu.walker.ext_walker.WalkerForD2J.accept$SimpleWalker(WalkerForD2J.kt:24) at com.zhihu.walker.ext_walker.ApkWalker.walk(ApkWalker.kt:20) at com.zhihu.walker.Main$Companion.doWalk(Main.kt:88) at com.zhihu.walker.Main$Companion.main(Main.kt:49) at com.zhihu.walker.Main.main(Main.kt)

    opened by hanbaokun 0
Owner
zkw周柯文
zkw周柯文
Remote script to create a maven compatible release of an android library (aar)

release-android-library ?? Deprecated ?? This script is deprecated in favour of: novoda/bintray-release Remote script to create a maven compatible rel

Paul Blundell 144 Dec 13, 2022
Modulearchive - Improve the efficiency of compiling Android.Package module as AAR and cache it

ModuleArchive 一个可以提升Android编译效率的Gradle小插件 在多module工程下,大多数情况我们若干子module是不会变动的 但是在当前gradle版本偶尔会触发联动编译进而影响编译效率。 本插件会自动缓存编译后的子模块生产物(xxx.aar),且会自动替换依赖为aar依

JackFan 3 Feb 11, 2022
Java 7 features backported to Android 2.2+

Using Java 7 & 8 Features on Android Feeling like you're stuck in 2006 while developing apps and libraries for Android? Don't worry, you're not alone.

Wes Lanning 87 Nov 25, 2022
An easy to use translation / localization api written in Kotlin that can be used with Java and Kotlin

KTranslate KTranslate is an easy to use TranslationAPI written in Kotlin, with currently 26 supported languages. It is very easy to use in Kotlin and

Felix Beinssen 0 Sep 2, 2022
A tool to install components of the Android SDK into a Maven repository or repository manager to use with the Android Maven Plugin, Gradle and other tools.

Maven Android SDK Deployer Original author including numerous fixes and changes: Manfred Moser [email protected] at simpligility technologies i

simpligility 1.4k Dec 27, 2022
A simple utility to remove unused resources in your Android app to lower the size of the APK. It's based on the Android lint tool output.

android-resource-remover android-resource-remover is utility that removes unused resources reported by Android Lint from your project. The goal is to

Keepsafe 1.3k Dec 16, 2022
This is a Android Studio/ IntelliJ IDEA plugin to localize your Android app, translate your string resources automactically.

#Android Localizationer This is a Android Studio/ IntelliJ IDEA plugin to localize your Android app, translate your string resources automactically. T

Wesley Lin 822 Dec 8, 2022
A tool to install components of the Android SDK into a Maven repository or repository manager to use with the Android Maven Plugin, Gradle and other tools.

Maven Android SDK Deployer Original author including numerous fixes and changes: Manfred Moser [email protected] at simpligility technologies i

simpligility 1.4k Dec 27, 2022