com.xmobitea.changx.antimod
v1.5.0
Published
XmobiTea Unity Toolkit packages
Readme
XmobiTea AntiMod
Build-time checksum and integrity validation package for Unity Android/iOS builds.
AI Quick Contract
- Main runtime API:
await CheckSumChecker.TryValidate() - Main settings asset:
Resources/XmobiTea AntiModSettings.asset - This package depends heavily on editor-time generation and post-build hooks
- Runtime validation is meaningful mainly on
AndroidandiOS - In
UNITY_EDITOR, validation always returns success - On non-Android/non-iOS player targets, runtime currently falls back to the editor checker and also returns success
- Android build flow can require a rebuild because
integrity.jsonis generated in post-process after the build output already exists - iOS unknown-framework detection currently contains a runtime bug: it can return
isValid = trueeven when it reports unknown files
What This Package Provides
AntiModSettings: resource-backed config plus encoded secret fieldsCheckSumChecker: runtime entry pointCheckSumUtils: hashing, signature, AES encode/decode helpersCheckSumGenerateEditor: post-build integrity generation and platform injectionAntiModSettingsEditor: editor workflow for generating encoded settings
Exact Runtime Behavior
CheckSumChecker.TryValidate()
TryValidate() behaves like this:
- In
UNITY_EDITOR, it immediately returnsnew CheckSumResult(true, null). - On device, it resolves the integrity file name from
CheckSumUtils.GetOriginNameIntegrityJsonFile(). - It loads that file from
StreamingAssets. - It deserializes
integrity.jsonintoCheckSumData. - It recomputes the signature over
entriesand compares it with the stored signature. - It dispatches to:
AndroidCheckSumCheckerInternaliOSCheckSumCheckerInternal- fallback
EditorCheckSumCheckerInternalon other runtime targets
Important consequence: this package is not a generic desktop anti-tamper solution. Outside Android/iOS, current runtime behavior is effectively permissive.
Android Runtime Validation
Android validation:
- finds installed
.apkfiles in the app install directory - detects whether the current install is
arm64orarmeabi-v7a - decrypts each stored path from
integrity.json - searches that path inside the installed APK files
- computes SHA-256 and compares it with the stored hash
If any required entry is missing or mismatched, validation fails.
iOS Runtime Validation
iOS validation:
- resolves the
.appinstall root - decrypts each stored path from
integrity.json - reads each file from the installed app bundle
- compares SHA-256 with the stored hash
- optionally validates
UnityFrameworkwheniOSCheckSumUnityFrameworkis enabled - optionally validates allowed framework names when
iOSCheckKnownFileInFrameworksis enabled
Current quirk:
the "unknown files in Frameworks" branch returns new CheckSumResult(true, "...") instead of failing. That is current runtime behavior, not intended design.
AntiModSettings
AntiModSettings is loaded from:
Resources/XmobiTea AntiModSettings.assetIt contains:
- toggle flags for iOS checks
- XOR keys for encoded fields
- encoded secret data used at runtime
Editor-only localSecretKeySettings is loaded from:
Assets/XmobiTea-constant/AntiMod_localSecretKeySettings.jsonThat JSON file is not the runtime source of truth. Runtime uses the encoded fields stored inside the asset.
Editor Workflow
Open/Create Settings
Menu:
XmobiTea Tools/AntiMod/Open SettingsIf the resource asset does not exist, editor code creates it automatically.
Generate Encoded Secret Fields
Inspector button:
Fetch Encode Secret Key SettingsThis action:
- writes
Assets/XmobiTea-constant/AntiMod_localSecretKeySettings.json - XOR-encodes the configured secret strings
- AES-encodes the integrity file name and framework allowlist entries
- writes the encoded byte arrays back into
AntiModSettings
This step is required before runtime validation can work correctly.
Post-Build Hook
CheckSumGenerateEditor.OnPostprocessBuild(...) runs after build.
It:
- computes hashes for configured important files
- generates
integrity.json - writes that file into
Assets/StreamingAssets/ - then performs platform-specific follow-up
Android follow-up:
- checks whether the built APK/AAB already contains the generated integrity file
- if not, it logs
need rebuild
Practical consequence: Android workflow may require building again after the first generation pass.
iOS follow-up:
- copies
integrity.jsonintoData/Raw/ - optionally injects an Xcode shell script that generates
ufsignature.txt
Required Setup
- Create/open
Resources/XmobiTea AntiModSettings.asset. - Configure local secret values and important file lists in the custom inspector.
- Click
Fetch Encode Secret Key Settings. - Build the app so post-process generation can produce integrity data.
- On Android, be prepared to rebuild after the first pass if the tool reports missing integrity data.
- Call
await CheckSumChecker.TryValidate()early at app startup on device.
Basic Usage
using System.Threading.Tasks;
using UnityEngine;
using XmobiTea.AntiMod;
public sealed class AntiModBootstrap : MonoBehaviour
{
private async void Start()
{
var result = await CheckSumChecker.TryValidate();
if (!result.isValid)
{
Debug.LogError("[AntiMod] Validation failed: " + result.error);
Application.Quit();
}
}
}Do / Don't
Do
- Do treat this package as a build-time plus runtime workflow.
- Do generate encoded settings before relying on runtime validation.
- Do call
TryValidate()on real device builds, not just in editor. - Do expect Android and iOS to behave differently.
- Do keep the important file lists aligned with the actual built output.
Don't
- Don't assume editor validation proves anything about a real build.
- Don't assume desktop or other non-mobile targets are meaningfully protected by the current runtime.
- Don't edit encoded runtime fields by hand.
- Don't forget that Android may need a rebuild after integrity generation.
- Don't assume the iOS known-framework check is currently reliable.
Common Mistakes
Mistake 1: Using editor success as real validation
In editor, TryValidate() always returns success.
Mistake 2: Forgetting to generate encoded settings
If Fetch Encode Secret Key Settings was never run, runtime secrets and file name decoding can be invalid.
Mistake 3: Expecting Android first build to already contain integrity.json
Current workflow generates that file in post-process, so the first Android build can legitimately ask for a rebuild.
Mistake 4: Assuming all player targets are protected
Current non-Android/non-iOS runtime path falls back to the permissive editor checker.
Namespace
using XmobiTea.AntiMod;Package Metadata
- Package name:
com.xmobitea.changx.antimod - Version:
1.5.0 - Unity version:
2022.3+ - License:
Apache-2.0
