• Hello
Search Results for

    Show / Hide Table of Contents

    Android - App Hash - Monitor (Pro)

    A hash is a short code calculated from the whole app file. If one byte of the file changes, the hash changes. Compare the hash on the device with the hash of the app you built. If they differ, the app file was changed.

    This monitor only calculates the hash. The Android package tampering detector compares it.

    This monitor needs the Pro version.

    Walkthrough: Protecting an Android build.

    Note

    The hash of your build has to be stored somewhere the app can download it, such as your server. That is why this check takes more setup than the signature check.

    Do you need to add it?

    Most of the time, no. The Android Package Cheating Detector prefab already includes this monitor. That prefab is part of the predefined Anti-Cheat-Monitor prefab.

    Add the AndroidPackageHashMonitor component (namespace GUPS.AntiCheat.Monitor.Android) by hand only if you build your own setup, or if you only want the raw reading. Put it on the same GameObject as its detector. The detector looks for it there.

    Add the AndroidPackageHashMonitor component.

    What it reports

    The monitor calculates the hash once, when it starts. It then sends one AndroidHashStatus:

    public struct AndroidHashStatus : IAndroidStatus
    {
        // True if the hash could not be calculated.
        public bool FailedToRetrieveData { get; }
    
        // The hash method that was used.
        public string Algorithm { get; }
    
        // The hash of the running app, as hex text.
        public string Hash { get; }
    }
    
    • FailedToRetrieveData: The hash could not be calculated. The other values are not valid.
    • Algorithm: Which hash method was used. See the table below.
    • Hash: The hash of the whole app.

    Settings

    The monitor has one field in the Inspector:

    • Is Active (isActive, bool, default true): Turns the monitor on or off.

    The hash method is set in the project settings. Open Edit > Project Settings > GuardingPearSoftware > AntiCheat, select the Android tab and go to Android - App Hash - Settings.

    Hash settings.

    • Verify app hash: Off by default. Turn it on to use this check.
    • Used hash algorithm: The hash method. The default is SHA256.
    • Remote hash location: Where the detector downloads the expected hash from. The detector page explains it.

    Anti-Cheat can use these methods:

    Method Notes
    None No hash is calculated
    MD5 Not recommended
    SHA1 Not recommended
    SHA256 Recommended
    SHA384 Stronger than SHA-256
    SHA512 Stronger than SHA-256

    Good to know

    • Not in the Editor: The monitor only calculates the hash on an Android device. In the Editor it sends nothing and logs a warning.
    • Development builds: Verify development builds is off by default. While it is off, the detector does not judge development builds. Turn it on while you test.

    Turn on Verify development builds to also check development builds.

    Platforms and requirements

    Android only. Android 4.4 (API level 19) or newer.

    The Android plugin com.gups.anticheat ships with the package in Assets/GUPS/AntiCheat/Plugins/Android/.

    Read it in code

    You can listen to the monitor yourself. Subscribe returns an IDisposable. Dispose it when you want to stop.

    using System;
    using GUPS.AntiCheat.Core.Watch;
    using GUPS.AntiCheat.Monitor.Android;
    using UnityEngine;
    
    public class AndroidHashStatusLogger : MonoBehaviour, IObserver<IWatchedSubject>
    {
        private void Start()
        {
            var monitor = GetComponentInChildren<AndroidPackageHashMonitor>();
            monitor.Subscribe(this);
        }
    
        public void OnNext(IWatchedSubject subject)
        {
            if (subject is AndroidHashStatus status)
            {
                if (status.FailedToRetrieveData)
                {
                    Debug.LogWarning("Could not calculate the app hash.");
                    return;
                }
    
                Debug.Log($"App hash ({status.Algorithm}): {status.Hash}");
            }
        }
    
        public void OnError(Exception error) { }
        public void OnCompleted() { }
    }
    

    Detect a changed app file

    To compare the hash with the one of your build, use the Android package tampering detector.


    Back to the Monitor overview.

    In This Article
    Back to top GuardingPearSoftware documentation