• Hello
Search Results for

    Show / Hide Table of Contents

    Android - App Tampering - Detector (Pro)

    Players can download an Android app, change it, and share that copy. This detector compares three things with what you expect: the app file, the signature, and the libraries packed in the app.

    This detector needs the Pro version.

    Walkthrough: Protecting an Android build.

    What it does

    AndroidPackageTamperingDetector (namespace GUPS.AntiCheat.Detector.Android) runs up to three checks. Each check uses its own monitor:

    Check What it compares Monitor
    App hash The hash of the whole app file with the hash on your server. A hash is a short code that changes when the file changes AndroidPackageHashMonitor
    Signature The certificate the app was signed with, against yours. It shows who built the app AndroidPackageFingerprintMonitor
    Libraries The code libraries in the app with your allow list and block list AndroidPackageLibraryMonitor

    Which store installed the app is a separate check. That is the install source detector.

    Do you need to add it?

    No, if you use the predefined Anti-Cheat-Monitor prefab. It already includes this detector and its three monitors.

    If you use your own monitor prefab, drag the Android Package Cheating Detector prefab onto the monitor so it becomes a child. The prefab holds the detector and the monitors together.

    The detector prefabs in Assets/GUPS/AntiCheat/Resources/Prefabs/Detectors.

    Note

    The monitors must be on the same GameObject as the detector. A missing monitor turns that one check off.

    You still have to turn the checks on and fill in your values. See Set up the checks below.

    Settings

    The AndroidPackageTamperingDetector settings.

    • Is Active (isActive, bool, default true): Turns the detector on or off.
    • Threat Rating (threatRating, default 500): How much one find adds to the threat score. It is high because a false alarm is very unlikely and a changed app matters a lot.
    • On Cheating Detection Event (OnCheatingDetectionEvent): Methods to call on every find.

    The expected hash, the expected signature, and the library lists are set in the project settings.

    Set up the checks

    Open Edit > Project Settings > GuardingPearSoftware > AntiCheat and select the Android tab.

    Note

    Verify development builds is off by default. While it is off, these checks skip the Unity Editor and development builds. Turn it on while you test.

    Check the app hash

    The hash shows whether the app file was changed in any way. That includes a new package name, edited code, or other changed files. This check needs a server, because the app must download the hash you expect.

    Go to Android - App Hash - Settings.

    Hash settings.

    • Verify app hash (off by default): Turns the check on.
    • Used hash algorithm (default SHA-256): The method used to build the hash. SHA-256 is recommended.
    • Remote hash location: A web address that returns only the hash as text. {version} is replaced with Application.version. For example https://yourserver.com/yourapp/hash?version={version}.

    How to set it up:

    1. Build your Android app. Anti-Cheat prints the hash in the Console.
    2. Put that hash on your server. The server returns it as plain text for a GET request.
    3. Enter the address in Remote hash location.

    The app hash in the Console after a build.

    Note

    The hash changes with every build, even when the game looks the same. Return the hash of the build you shipped. Use {version} in the address if you keep more than one version online. You set the version under Edit > Project Settings > Player.

    Set the version under Player settings.

    A small server example:

    import express from 'express';
    
    const app = express();
    
    app.get('/hash', (req, res) => {
        if(req.query.version === '0.2') {
          res.send('00:E4:C4:13:2F:09:91:4A:B5:A0:D6:64:AC:38:FD:50:82:02:3C:45:5E:64:69:B1:F7:0E:43:04:14:1C:1A:3A');
          return;
        }
        res.send('Unknown version');
    });
    
    app.listen(4000, () => {
      console.log(`server running on port 4000`);
    });
    

    Check the signature

    The signature shows the app was signed with your key. If someone else builds your game again, the signature changes. This check needs no server.

    Go to Android - App Fingerprint - Settings.

    Fingerprint settings.

    • Verify app fingerprint (off by default): Turns the check on.
    • Used hash algorithm (default SHA-256): SHA-256 is recommended.
    • Fingerprint: Your signature, as text.

    You sign your app with a keystore. That is the file that holds your key. You set it under Edit > Project Settings > Player > Publishing Settings.

    The Android publishing key.

    Read the fingerprint from the keystore with this command:

    keytool -list -v -keystore "[Project]\user.keystore"
    

    Copy the SHA-256 fingerprint into the Anti-Cheat settings.

    Paste the SHA-256 line into Fingerprint. You do this only once, as long as you keep the same keystore.

    Check the libraries

    Editing your built code is hard. A common mod adds a new library to the app instead.

    Go to Android - App Library - Settings.

    Library allow and block lists.

    • White-/Blacklist libraries (on in the shipped settings): Turns both lists on. Off means every library is allowed.
    • Whitelisted libraries: Libraries that may be in the app. Anything else is reported. The shipped list holds Unity's own libraries.
    • Blacklisted libraries: Libraries that must not be in the app.

    To find the names, open your built app in a zip tool. Look in the library folder, for example lib\armeabi-v7a\. Enter each file name with its extension.

    Libraries inside a built Android app.

    Important

    If your game uses plugins with their own libraries, add them to the allow list. Otherwise your own app is reported.

    What it reports

    On a find, the detector sends an AndroidCheatingDetectionStatus:

    public struct AndroidCheatingDetectionStatus : IAndroidCheatingDetectionStatus
    {
        // The kind of cheat. Here: ECheatType.Tampering.
        public ECheatType CheatType { get; }
    
        // How likely this find is a false alarm, from 0 to 1.
        public float PossibilityOfFalsePositive { get; }
    
        // How much this find adds to the threat score.
        public uint ThreatRating { get; }
    
        // Which check failed.
        public EAndroidCheatingType AndroidCheatingType { get; }
    
        // True if the monitor could not read its data.
        public bool MonitorFailedToRetrieveData { get; }
    }
    

    AndroidCheatingType tells you which check failed:

    • PACKAGE_HASH: the app hash does not match the one on your server.
    • PACKAGE_FINGERPRINT: the signature does not match yours.
    • PACKAGE_LIBRARY: a library is not allowed.

    Good to know

    • The flag stays. PossibleCheatingDetected stays true after the first find.
    • A failed read is also reported. If a monitor could not read its data, for example on an old device, the detector still sends a find. The chance of a false alarm is then 0.75, not 0.01, so it adds much less to the score. MonitorFailedToRetrieveData is true.
    • Each check reports on its own. A changed app can cause up to three finds.
    • The checks run once. The monitors read their data when the game starts.

    Platforms and requirements

    Android only.

    • Android 4.4 (API level 19) or newer. Unity's Minimum API Level decides which devices can install the app.
    • The plugin com.gups.anticheat. It ships with the package in Assets/GUPS/AntiCheat/Plugins/Android/.

    React to a find

    Every find is added to the threat score of the Anti-Cheat Monitor. The predefined monitor prefab has no punisher. So nothing more happens to the player until you react yourself or add a punisher.

    In the Inspector. Add a method to On Cheating Detection Event. It runs on every find.

    Inspector callbacks on a detector.

    In code. Ask the detector:

    var detector = AntiCheatMonitor.Instance.GetDetector<AndroidPackageTamperingDetector>();
    
    if (detector != null && detector.PossibleCheatingDetected)
    {
        // The app was changed.
    }
    

    Or listen, so your code runs at the moment of the find. Subscribe returns an IDisposable. Dispose it when you want to stop.

    using System;
    using GUPS.AntiCheat;
    using GUPS.AntiCheat.Core.Detector;
    using GUPS.AntiCheat.Detector.Android;
    using UnityEngine;
    
    public class AndroidPackageDetectionLogger : MonoBehaviour, IObserver<IDetectorStatus>
    {
        private void Start()
        {
            var detector = AntiCheatMonitor.Instance.GetDetector<AndroidPackageTamperingDetector>();
            detector.Subscribe(this);
        }
    
        public void OnNext(IDetectorStatus status)
        {
            if (status is AndroidCheatingDetectionStatus android)
            {
                Debug.LogWarning($"App tampering found: {android.AndroidCheatingType}");
            }
        }
    
        public void OnError(Exception error) { }
        public void OnCompleted() { }
    }
    

    Back to the Detector overview.

    In This Article
    Back to top GuardingPearSoftware documentation