Studying the source code of mobile games on Android may be needed for various reasons: from reverse engineering (reverse engineering) for educational purposes to searching for vulnerabilities or creating mods. However, the process of extracting the code is not nearly as simple as opening a text fileโgames are protected by obfuscation, encryption, and legal restrictions. In this article we will look at access to code, tools for decompilation, as well as the nuances of working with popular engines like legal methods. It is important to understand: most commercial games are protected license agreements prohibiting decompilation. We consider methods exclusively for legal ways code access, decompilation tools APK, as well as the nuances of working with popular engines like Unity And Unreal Engine.
It's important to understand that most commercial games are protected by licensing agreements that prohibit decompilation. We consider methods exclusively for personal non-commercial purposes (for example, training or testing your own projects). If you plan to modify someone else's game for publication, this violates EULA (license agreement) and may entail legal consequences.
Technically, the process depends on what language and engine the game is written in. For example, games on Java/Kotlin (typical for Android SDK) are decompiled differently than projects on C# under Unity. We will look at both cases, as well as ways to extract resources (textures, sounds, 3D models) without diving deeply into the code.
1. Preparation: what you will need to extract the code
Before you start decompiling, make sure you have:
- ๐ฑ APK file of the game โit can be downloaded from your device (via
ADBor a file manager) or from sites like APKMirror (official versions only!). - ๐ป Computer s Windows, Linux or macOS โdecompilation on the Android device itself is possible, but extremely inconvenient.
- ๐ ๏ธ Tools:
- JADX or Apktool โfor decompiling Java/Kotlincode;
- dnSpy or ILSpy โfor analysis Unitygames (C#). data-i="70">Also get ready for the fact that many games use decompilation protection
- UnityEx or AssetStudio - to extract resources from Unity;
- Ghidra or IDA Pro โ for analyzing native code (C/C++).
- ๐ ADB (Android Debug Bridge) โ to extract APK from the device (if there is no file).
Also be prepared for the fact that many games use decompilation protection:
- ๐ ProGuard or code obfuscators that replace class names with random characters; R8 โ code obfuscators that replace class names with random characters;
- ๐ก๏ธ DexGuard a commercial tool for enhanced protection;
- ๐ Native code โcritical parts of the game can be written in C++ and compiled into binary files (
.so); - ๐ Server validation โsome games check the integrity of the code at startup.
โ ๏ธ Attention: Decompilation of protected games (for example, with DexGuard or Unity IL2CPP) requires advanced skills and is often impossible without deep knowledge assembler or reverse engineering. Start with simple projects!
2. Method 1: Decompiling APK using JADX
JADX is one of the most popular tools for decompiling Androidapplications. It converts bytecode DEX (Dalvik Executable) into readable Javacode, and also extracts resources (pictures, XML files, etc.). Suitable for games written in Java/Kotlin or using Android NDK (but not for Unity or Unreal Engine).
Instructions for use:
- Download JADX from the official repository on GitHub (versions available for Windows, Linux and macOS).
- Run
jadx-gui(graphical version) or use the command line:jadx -d output_dir game.apk - Wait for the process to complete. In the folder
output_dirthe following will appear:- ๐
resourcesโ graphic files, sounds, XML markup; - ๐
sourcesโ decompiled code on Java.
- ๐
What can be found in the decompiled code:
- ๐ฎ Logic of game mechanics (for example, click processing, physics, AI);
- ๐ API keys, server URLs (if not encrypted);
- ๐ Configuration files (levels, balance, character parameters).
โ ๏ธ Attention: If the game uses ProGuard, the names of classes and methods will be replaced ona.b.c,d.e.fetc. It is almost impossible to restore the original names without mapping file (which only developers have).
โ๏ธ Preparing an APK for JADX
3. Method 2: Analyzing Unity games using dnSpy
Most mobile games are created on an engine Unitythat uses C# as the main language. A powerful tool for analyzing and editing dnSpy - a powerful tool for analysis and editing .NETassemblies is suitable for decompiling such projects. It allows you not only to view the code, but also to make changes (for example, to create mods).
How to work with dnSpy:
- Download dnSpy s GitHub (free version).
- Extract Unity-assemblies from APK:
- Rename
game.apktogame.zipand unpack; - Find the folder
assets/bin/Data/Managed- there will be files.dll; - Copy them to a separate directory.
- Rename
- Open dnSpy, drag
.dllfiles into the app window. - Examine the class tree in the left panel. The main logic is usually located in assemblies like:
Assembly-CSharp.dllโ custom code;UnityEngine.dllโ standard engine functions.
Advantages dnSpy:
- ๐ Support debugging โ you can set breakpoints and analyze execution code;
- โ๏ธ Editing โ changed assemblies can be packaged back into APK;
- ๐ Deobfuscation - copes better with encrypted strings than ILSpy.
Limitations:
- ๐ซ Does not work with games compiled through IL2CPP (a popular protection method c Unity);
- ๐ Some games encrypt
.dllfiles - additional analysis will be required.
What is IL2CPP and why does it complicate decompilation?
IL2CPP (Intermediate Language to C++) is a Unity technology that transforms C# code into native C++ before compilation. As a result, instead of readable .DLL files, you get binary code (.so), which is analyzed only through disassemblers like Ghidra or IDA Pro.
4. Method 3: Extracting resources without code (AssetStudio)
If you are not interested in algorithms, and graphics, sounds or 3D models, you can do without decompiling the code. For games on Unity a utility AssetStudio is suitable - it extracts assets (resources) from files assets and sharedassets inside APK.
Step-by-step guide:
- Extract the APK (rename to
.zipand extract the contents). - Find the files with extensions:
.assetsโcontain textures, models, audio;.resSโresources for Unity;.bundleโresource packages (used to download content over the network).
Export).What resources can be extracted:
| Resource type | Format | Usage example |
|---|---|---|
| Textures | .png, .jpg |
Character sprites, backgrounds, interface |
| 3D models | .fbx, .obj |
Characters, weapons, environments |
| Audio | .mp3, .ogg |
Music, sound effects |
| Fonts | .ttf, .otf |
Menu text, subtitles |
| Animations | .anim (Unity) |
Movements characters, cutscenes |
โ ๏ธ Attention: Some games store resources in encrypted form or download them from the server during the game. In this case, AssetStudio will not help - you will need to analyze network traffic (for example, through Fiddler or Charles Proxy).
If AssetStudio does not recognize files, try using Unity Assets Bundle Extractor (UABE) - it supports more formats and versions Unity.
5. Method 4: Analysis of native code (C/C++) via Ghidra
Many games (especially AAA projects) contain native libraries - files with the extension .so (for example, libil2cpp.so, libunity.so).They are written in C/C++ and compiled into machine code, which complicates the analysis. To study them you will need disassembler for example Ghidra (free tool from NSA).
How to work with Ghidra:
- Download and install Ghidra from the official website.
- Extract
.sofiles from the APK (they are located inlib/arm64-v8aorlib/armeabi-v7a). - Create a new project in Ghidra and import
.sofile. - Select processor
ARM 64-bit(orARM 32-bit, if the game is for older devices). - Wait for the analysis. After this, you can view assembly code and try to restore the logic.
What can be found in the native code:
- ๐ฏ Anti-cheat systems (for example, checking memory integrity);
- ๐ Physics engine logic (if the game uses Bullet or PhysX);
- ๐ Encryption algorithms (for example, to protect saves).
Difficulties:
- ๐งฉ Code on assembler requires deep knowledge of architecture ARM;
- ๐ Functions often do not have clear names (only addresses like
FUN_00123456); - ๐ Analysis takes a lot of time - even for a small game it can take several days.
Ghidra is the only free tool for analyzing native code of Android games. Alternatives (IDA Pro, Binary Ninja) are paid and require a license.
6. Method 5: Using Frida for dynamic analysis
Frida is a framework for dynamic analysis applications. Unlike decompilation, it allows intercept function calls in real time. timewhich is useful for studying the logic of the game without deep immersion in the code. For example, you can track how purchases are processed in the store or how damage is calculated.
Example of use:
- Install Frida on your computer:
pip install frida-tools - Connect your Android device via USB and run Frida-server on it:
adb push frida-server /data/local/tmp/adb shell chmod +x /data/local/tmp/frida-server
adb shell /data/local/tmp/frida-server & - Find the name of the game process:
frida-ps -U - Connect to the process and intercept the desired function. For example, to track calls
UnityPlayer.UnitySendMessage(used for interaction between C# and Java):frida -U -l hook.js -f com.game.package --no-pausewhere
hook.jsโ a script with interception logic.
Examples of tasks for Frida:
- ๐ฐ Tracking purchases in the game (calls
IabHelper); - ๐ฏ Changing values in memory (for example, the number lives);
- ๐ Logging network requests (if the game does not use HTTPS).
โ ๏ธ Attention: Many games detect Frida and block launch. To bypass the protection, you will need to patch binary files or use Frida-gadget manually.
7. Legal and Ethics
Before decompiling, please read the game's EULA. Most commercial projects prohibit: license agreement (EULA) games. Most commercial projects prohibit:
- ๐ Decompilation for any purpose other than backward compatibility;
- ๐ Modification and distribution of modified versions;
- ๐ Analysis of protected data (for example, anti-cheat algorithms).
What is allowed:
- ๐ Study of code for personal training (if the developer's rights are not violated);
- ๐ ๏ธ Creation of mods for personal use (without distribution);
- ๐ Search for vulnerabilities with notification to the developer (by rules Responsible Disclosure).
Consequences of violation:
- ๐ซ Account blocking in online games;
- โ๏ธ Claim for copyright infringement (in some countries);
- ๐ Device Ban (if the game uses Google Play Protect or SafetyNet).
If you plan to publish the results of the analysis (for example, on GitHub or on a blog), make sure that:
- ๐ You do not disclose confidential information (API keys, protection algorithms);
- ๐ Your project does not violate platform rules (for example, Google Play prohibits modified APK);
- ๐ You indicate that the code is intended for educational purposes only.
8. Alternative methods: what to do if decompilation does not work
If the game is protected DexGuard, IL2CPP or other systems, standard methods may not work. In this case, try:
- ๐ Analysis of network traffic:
- Use Fiddler or Charles Proxy to intercept requests;
- Look for
JSON/Protobufmessages with game data.
- ๐ฅ๏ธ Emulation and debugging:
- Run the game in Android Studio Emulator with a debugger attached;
- Use
ADB logcatto view logs:
adb logcat | grep com.game.package
- Check if configuration files are stored in
/data/data/com.game.package/; - Use
ADB pullto extract:
adb pull /data/data/com.game.package/
If all else fails:
- ๐ Study engine documentation (for example, Unity Manual or Unreal Engine Docs);
- ๐ค Refer to the community of reverse engineers (for example, forums XDA Developers or Guided Hacking);
- ๐ก Try to find open analogues games with similar mechanics (for example, on GitHub).
If a game uses IL2CPP, the only reliable way to analyze it is to manually reverse engineer the native code using Ghidra or IDA Pro. Automatic tools are powerless here.
FAQ: Frequently asked questions about decompiling Android games
โ Is it possible to decompile a game without it? root?
Yes, for decompilation APK root is not needed - the file itself is enough, however, to extract data from /data/data/ (for example, saves or cache) will require superuser rights or ADB with unlocked root-access.
โ How to bypass ProGuard in decompiled code?
Completely restore original class names without mapping file impossible. However, you can:
- Use JADX with the option
--deobfuscation; - Analyze string literals in the code (they often contain hints);
- Compare several versions of the game - sometimes names are repeated.
โ Is it possible to change the decompiled code and assemble it back?
Technically yes, but:
- For Javagames: after editing you need to recompile the code into
.dex(for example, via Apktool), then sign the APK; - For Unitygames: modified
.dllcan be packed back into the APK, but the game may refuse to launch due to integrity checks; - On output will turn out modified APKwhich will not pass verification Google Play Protect.
โ How to protect your game from decompilation?
If you are a developer, use:
- ProGuard/R8 for obfuscation Javacode;
- IL2CPP in Unity for conversion C# into native code;
- DexGuard or Jeb Decompiler for enhanced protection;
- Checking the integrity of files at startup;
- Encryption of critical resources (for example, through SecurePreferences).
Also regularly update protection - decompilation tools are constantly being improved.
โ Is it legal to use decompiled code in your projects?
No, even if you change the code, it will be considered copyright infringement. You can:
- Study the code for training only;
- Write similar mechanics from scratch (without copying);
- Use open libraries with similar functionality.
If in doubt, consult a lawyer for IP-law.