AsmActualCombat

repository·master·Indexed 43 days ago

https://github.com/peakmain/asmactualcombat

An Android instrumentation tool using ASM for automated full-point event tracking and advanced debugging. Features include automated tracking of app starts, exits, screen views, and clicks, as well as method timing, parameter logging, and the ability to intercept or replace sensitive system API calls for privacy protection. Version 1.2.0 provides a Gradle plugin and SDK for integration.

Tokens
2.3K
Snippets
6
Records
7
Agent score
5%

What's inside AsmActualCombat

  1. Overview of AsmActualCombat features

    master

    AsmActualCombat provides automated instrumentation (ASM full tracking) and debugging utilities for Android applications.

    ASM Full Tracking (全埋点)

    Automatically tracks the following events:

    • AppStart: Application startup.
    • AppEnd: Application exit.
    • AppViewScreen: Page/Screen browsing.
    • AppClick: View clicks (e.g., ImageView, Button, Dialog). Includes built-in protection against multiple clicks and supports intercepting setOnClickListener calls.
    • Privacy Method Handling: Can replace privacy method bodies with custom implementations.

    Auxiliary Debugging Features

    • Measure method execution time.
    • Print method parameters and return values.
    • Print method stack frames.
    • Dynamically enable or disable the plugin.
  2. Install AsmActualCombat using the old version method

    master

    If you are using an older Gradle configuration, follow these steps:

    1. Configure the ASM Plugin

    Add the following to your root build.gradle at the end of the repositories block:

    buildscript {
      repositories {
        maven {
          url "https://plugins.gradle.org/m2/"
        }
      }
      dependencies {
        classpath "io.github.peakmain:plugin:1.2.0"
      }
    }
    
    apply plugin: "com.peakmain.plugin"

    2. Configure the SDK Dependency

    First, add the JitPack repository to your root build.gradle:

    allprojects {
        repositories {
            ... 
            maven { url 'https://jitpack.io' }
        }
    }

    Then, add the dependency to your module's build.gradle:

    dependencies {
        implementation 'com.github.Peakmain:AsmActualCombat:1.2.0'
    }
  3. Install AsmActualCombat using the new version method

    master

    For modern Gradle setups, follow these steps to configure the plugin and the SDK.

    1. Configure settings.gradle

    Add the necessary repositories for both the plugin and the SDK in your settings.gradle file:

    pluginManagement {
        repositories {
            // Plugin repository
            maven {
                url "https://plugins.gradle.org/m2/"
            }
        }
    }
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            // SDK repository
            maven { url 'https://jitpack.io' }
        }
    }

    2. Add the Plugin to build.gradle

    In your root build.gradle file, declare the plugin:

    plugins {
        // Plugin ID and version
        id "io.github.peakmain" version "1.2.0" apply false
    }

    3. Add the SDK dependency

    In your module-level build.gradle file, add the implementation dependency:

    implementation 'com.github.Peakmain:AsmActualCombat:1.2.0'
    pluginManagement {
        repositories {
            maven {
                url "https://plugins.gradle.org/m2/"
            }
        }
    }
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            maven { url 'https://jitpack.io' }
        }
    }
  4. Configure the monitorPlugin for privacy method handling

    master

    The monitorPlugin block allows you to configure how the ASM plugin handles privacy method calls and logging. You can use it to replace privacy method bodies with your own implementation.

    Configuration Options

    • whiteList: A list of classes/packages to exclude from processing.
    • methodStatus: Controls method body replacement. Setting this to 1 enables method body replacement; other values result in normal behavior.
    • enableLog: A boolean to enable or disable log printing (defaults to false).
    monitorPlugin {
        whiteList = [
                "com.peakmain.asmactualcombat.utils.TestUtils",
                "com.peakmain.plugin"
        ]
        methodStatus = 1 // 1 enables method body replacement
        enableLog = true // Enables log printing
    }
    monitorPlugin {
        whiteList = [
                "com.peakmain.asmactualcombat.utils.TestUtils",
                "com.peakmain.plugin"
        ]
        methodStatus = 1
        enableLog = true
    }
  5. Initialize the ASM tracking SDK

    master

    To use the ASM tracking capabilities, you must initialize the SensorsDataAPI within your Application.onCreate() method. This SDK allows you to manage user agreements, monitor data upload states, and intercept/replace sensitive system method calls (like device ID or WiFi information retrieval) via listeners.

    @Override
    public void onCreate() {
        super.onCreate();
        // Initialize JPush
        JPushInterface.init(this);
        
        // Initialize SensorsDataAPI
        SensorsDataAPI.init(this);
        
        // Set user agreement policy (return true to accept)
        SensorsDataAPI.getInstance().setOnUserAgreementListener(() -> true);
    }
  6. Monitor sensor data upload states

    master

    Use SensorsDataAPI.getInstance().setOnUploadSensorsDataListener to intercept and react to sensor data being uploaded. The listener provides a state and the data payload. Common states are defined in SensorsDataConstants:

    • SensorsDataConstants.APP_START_EVENT_STATE
    • SensorsDataConstants.APP_END__EVENT_STATE
    • SensorsDataConstants.APP_VIEW_SCREEN__EVENT_STATE
    SensorsDataAPI.getInstance().setOnUploadSensorsDataListener((state, data) -> {
        switch (state) {
            case SensorsDataConstants.APP_START_EVENT_STATE:
            case SensorsDataConstants.APP_END__EVENT_STATE:
            case SensorsDataConstants.APP_VIEW_SCREEN__EVENT_STATE:
                // Handle specific event data
                break;
            default:
                // Handle other states
                break;
        }
    });
  7. Intercept and replace sensitive system methods

    master

    The OnReplaceMethodListener interface allows you to intercept calls to sensitive Android system APIs and return custom values. This is useful for privacy protection or testing. You can implement the following methods:

    • onReplaceMethodListener(int telephoneState, TelephonyManager manager, int slotIndex): Intercepts device identifiers. Supported telephoneState constants include:
      • SensorsDataConstants.GET_DEVICE_ID
      • SensorsDataConstants.GET_MEID
      • SensorsDataConstants.GET_IMEI
      • SensorsDataConstants.GET_SUBSCRIBER_ID
      • SensorsDataConstants.GET_SIM_SERIAL_NUMBER
    • onReplaceMethodListener(WifiManager wifiManager): Intercepts WifiInfo requests.
    • onReplaceWifiManagerMethodListener(WifiManager wifiManager): Intercepts WiFi scan results.
    • onReplaceMethodListener(SubscriptionInfo subscriptionInfo): Intercepts subscription information.
    • onReplaceMethodListener(PackageManager manager): Intercepts package information.
    • onReplaceMethodListener(ContentResolver resolver, String name): Intercepts content resolver requests.
    SensorsDataAPI.getInstance().setOnReplaceMethodListener(new OnReplaceMethodListener() {
        @Override
        public String onReplaceMethodListener(int telephoneState, TelephonyManager manager, int slotIndex) {
            // Return a fake or empty ID to protect privacy
            return "";
        }
    
        @Override
        public WifiInfo onReplaceMethodListener(WifiManager wifiManager) {
            return null; // Return null to mask WiFi info
        }
    
        @Override
        public List<ScanResult> onReplaceWifiManagerMethodListener(WifiManager wifiManager) {
            return new ArrayList<>(); // Return empty scan results
        }
    
        @Override
        public String onReplaceMethodListener(SubscriptionInfo subscriptionInfo) {
            return "";
        }
    
        @Override
        public List<PackageInfo> onReplaceMethodListener(PackageManager manager) {
            return new ArrayList<>();
        }
    
        @Override
        public String onReplaceMethodListener(ContentResolver resolver, String name) {
            return "onReplaceMethodListener";
        }
    });