• Hello
Search Results for

    Show / Hide Table of Contents

    07 - Protecting an Android build (Pro)

    Goal: You will learn how to notice a shared or edited copy of your Android app, and how to turn those checks on.

    This guide needs the Pro version. The genuine check in Step 2 also works in the Free version.

    The problem

    Android apps are easy to download, edit, and share again. Someone takes your app, changes it, and builds it again. That is called repacking. The changed copy gives free coins, removes ads, or unlocks paid content.

    That hurts your game. You lose sales, and honest players compete against people with a cheated copy.

    A repacked app differs from yours in a few ways. It may no longer carry your app id. It often comes from another place than your store. Its file is different. It is signed by someone else. Or it has an extra library with the cheat code inside.

    The solution

    Three detectors look for those differences:

    • The Mobile Genuine Detector checks that the app is still yours.
    • The Install Source Detector checks which store installed the app.
    • The Android Package Cheating Detector checks the app file, the signature, and the libraries.

    You turn each check on in the project settings. Each step below is one check. You can use one, some, or all of them.

    Step 1: Make sure the detectors are there

    The predefined Anti-Cheat-Monitor prefab already includes all three detectors and their monitors. If you use it, you have nothing to do here.

    If you use your own monitor prefab, add the Mobile Genuine Detector, the Install Source Detector, and the Android Package Cheating Detector prefabs to it. Drag them onto the monitor in your prefab so they become children.

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

    The settings for the store, hash, signature, and library checks are in Edit > Project Settings > GuardingPearSoftware > AntiCheat, on 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.

    Step 2: Check that the app is still yours

    The Mobile Genuine Detector asks Unity if the running app is genuine. A copy that was changed and published under another app id fails this check. The app id is the package name of your app, such as com.company.game.

    You have nothing to set up. The detector checks once when the game starts.

    You can also run the check yourself:

    var detector = AntiCheatMonitor.Instance.GetDetector<MobileGenuineDetector>();
    
    if (detector != null && !detector.ManualGenuineCheck())
    {
        // The app is not genuine.
    }
    

    This check does not catch every kind of edit. The next steps cover the rest.

    Step 3: Allow only the stores you trust

    Cheaters often share an edited app as a direct download. This check reads which store installed the app.

    Go to Android - App Store - Settings.

    Image 2: The allowed install sources.

    Setting What it does
    Allow all installation sources On: every store is allowed. Off: only the stores below are allowed. Off by default
    Allow following sources The stores you trust, such as Google Play. Tick the ones you ship on
    Allow custom sources A store that is not in the list. Enter its package name, the id of the store app

    Android Package Installer is the system installer. It is used when the app was installed from a file, not from a store. Unknown is any source that is not in the list. Leave both off unless you ship that way.

    Step 4: Check that the app file was not changed

    A hash is a short code made from the whole app file. If one byte of the file changes, the hash changes.

    After each Android build, Anti-Cheat writes the hash of your app to the Unity Console. You put that text on a server. When the app starts, it downloads the text and compares it with the hash of the app on the device.

    Image 3: The app hash in the Console after a build.

    Go to Android - App Hash - Settings.

    Image 4: The hash settings.

    Setting What it does
    Verify app hash Turns the check on. Off by default
    Used hash algorithm How the hash is made. SHA-256 is the recommended choice
    Remote hash location A web address that returns only the hash text. {version} is replaced with Application.version

    You set Application.version in Edit > Project Settings > Player.

    Image 5: The version of your app in the Player settings.

    Important

    The hash changes with every build, even when the game looks the same. Your server must return the hash of the build you shipped. Use {version} in the address when more than one version is online.

    The answer of the server is only the hash text. A small example server:

    app.get('/hash', (req, res) => {
        if (req.query.version === '0.2') {
          res.send('00:E4:C4:13:2F:09:91:4A:...');
          return;
        }
        res.send('Unknown version');
    });
    

    Step 5: Check who signed the app

    Every Android app is signed with a key. Your key is in your keystore, the file Unity uses to sign the build. Someone who repacks your app does not have your key, so their copy has a different signature. The fingerprint is a short text made from the signature.

    This check needs no server. The fingerprint stays the same as long as you keep your key.

    Go to Android - App Fingerprint - Settings.

    Image 6: The fingerprint settings.

    Setting What it does
    Verify app fingerprint Turns the check on. Off by default
    Used hash algorithm How the fingerprint is made. SHA-256 is the recommended choice
    Fingerprint The fingerprint text from your keystore

    You find your keystore under Edit > Project Settings > Player > Publishing Settings.

    Image 7: The Android publishing key.

    Read the fingerprint from the keystore with this command:

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

    Image 8: Copy the SHA-256 fingerprint into the Anti-Cheat settings.

    Note

    If Google Play signs your app for you (Play App Signing), the app in the store carries Google's key, not your upload key. Use the fingerprint of the app signing key from the Play Console.

    Step 6: Watch for extra libraries

    A library is a file with built code inside the app. A common mod adds a new library and leaves your code alone. You list the libraries that belong in your app, and the ones you want to reject.

    Go to Android - App Library - Settings.

    Image 9: The library allow list and block list.

    Setting What it does
    White-/Blacklist libraries Turns both lists on. Off means every library is allowed. On by default
    Whitelisted libraries The libraries that may be in the app. Anything else is reported
    Blacklisted libraries The libraries that must not be in the app

    The shipped allow list holds common Unity libraries. Check it against your own build. Open the built app in a zip tool, look in the library folder, and enter each file name with its extension.

    Image 10: The libraries inside a built Android app.

    Step 7: Try it

    Open the demo scene Assets/GUPS/AntiCheat/Demos/Demo_Android/Scenes/Title/Title.unity and build it for Android. It is a small jump-and-run. Play it once without and once with Anti-Cheat. A failed check turns a part of the game off. The demo folder has its own ReadMe.

    The result

    A repacked app fails one or more of these checks:

    • It no longer carries your app id.
    • It was installed from a place you did not allow.
    • Its file does not match the hash on your server.
    • It was signed with another key.
    • It has a library that does not belong.

    Each find raises the threat score of the Anti-Cheat Monitor.

    Note

    The predefined monitor prefab has no punisher. A find raises the threat score, but nothing more happens to the player until you react yourself or add a punisher.

    Settings reference: Mobile genuine detector, Install source detector, and Android package tampering.

    Next steps

    • Reacting to detected cheating shows how to run your own logic when a check fails.
    • Punishing cheaters shows how to react automatically.

    Next guide: 08 - Cheat apps on Android (Pro).

    Back to the Guides overview.

    In This Article
    Back to top GuardingPearSoftware documentation