Technical Analysis

ClashFarmer Reverse Engineering

Laporan analisis teknis lengkap dari ClashFarmer v2.4 RC18 — struktur installer, teknologi, computer vision, konfigurasi, dan landscape bot CoC.

File Overview

ClashFarmer v2.4 RC18 adalah PE32 executable berukuran ~58.9 MB yang dibungkus dengan Nullsoft Installer (NSIS v3.09). File utama ClashFarmer.exe adalah PyInstaller one-file executable yang berisi Python 3.10 runtime, OpenCV, PyQt6, dan PyArmor obfuscation.

Technology Stack

Bot ini dibangun dengan Python 3.10, GUI framework PyQt6, computer vision OpenCV (cv2), image processing Pillow, numerical computing NumPy, dan bundling PyInstaller. Obfuscation menggunakan PyArmor modern mode (v7.x/v8.x) yang melindungi source code dari static analysis.

Configuration Database

Konfigurasi disimpan dalam SQLite database (config.db) dengan schema sederhana: id, key_type, key (BLOB), dan value (BLOB). Keys dan values di-serialize menggunakan Python pickle. Konfigurasi mencakup troop counts, deployment speeds, hero activation, resource thresholds, dan Telegram/Pushbullet integration.

Computer Vision

Folder images/ berisi template library untuk OpenCV matchTemplate(). Terdapat kategori: buttons, armyCampTroops, barracksTroops, battleTroops, buildingFont, lootScreenFont, deadBaseIndicators, walls, THs, dan lainnya. Bot menggunakan classical template matching untuk UI interaction dan base analysis.

Network & Communication

Libraries cryptography, M2Crypto, dan OpenSSL runtime menunjukkan kemampuan HTTPS/TLS encryption. Config keys untuk telegram_token_key dan pushbullet_api_key mengindikasikan dukungan notifikasi eksternal via Telegram Bot API dan Pushbullet.

Anti-Detection Measures

Bot mengimplementasikan image-based automation (bukan memory injection), human-like delays dengan configurable troop_deploy_speed dan wave_deploy_speed, randomized behavior, background mode untuk BlueStacks, PyArmor obfuscation, scheduled timeouts, dan chat humanization.

Reverse Engineering Assessment

Extract installer: Easy. Identify tech stack: Easy. Modify config: Medium (perlu SQLite + pickle). Replace templates: Medium (harus match resolusi). Extract source code: Very Hard (PyArmor modern). Add features: Nearly Impossible tanpa rewrite.

Recommendations

Untuk modifikasi aman: edit config.db dengan SQLite + pickle, ganti template images (preserve dimensions), dan adjust scheduling timeouts. Untuk fitur baru: build bot baru menggunakan Python 3.10+, PyQt6, OpenCV, dan reuse template naming conventions.

ClashFarmer v2.4 RC18 — Technical Analysis Report

Disclaimer: This document is a technical analysis for educational and research purposes only.
All trademarks, product names, and assets mentioned belong to their respective owners (ClashFarmer.com / Supercell).
No proprietary binaries, assets, or extracted files are included in this repository.


1. File Overview

AttributeValue
Original FilenameClashFarmer_24_RC18__Installer_f52029.exe
File TypePE32 executable (GUI) Intel 80386
PackagingNullsoft Installer (NSIS v3.09) — Self-extracting archive
File Size~58.9 MB (58,999,785 bytes)

2. Installer Structure (NSIS)

The executable is a Nullsoft Scriptable Install System (NSIS) self-extracting archive. Silent extraction is possible via:

ClashFarmer_Installer.exe /S /D="C:\Output\Path"

Post-Extraction Layout

extracted/
├── ClashFarmer.exe              # Main entry point (PyInstaller one-file)
├── python310.dll                # Python 3.10 runtime
├── python3.dll
├── base_library.zip             # Compiled Python stdlib (.pyc files)
├── config.db                    # SQLite database (bot configuration)
├── pyarmor_runtime_000000/      # PyArmor obfuscation runtime
│   └── pyarmor_runtime.pyd      # PyArmor C extension
├── images/                      # Computer vision template library
│   ├── buttons/
│   ├── armyCampTroops/
│   ├── barracksTroops/
│   ├── battleTroops/
│   ├── buildingFont/
│   ├── deadBaseIndicators/
│   ├── donationTroops/
│   ├── indicators/
│   ├── lootCart/
│   ├── walls/
│   └── ...
├── PyQt6/                       # Qt6 bindings for Python GUI
├── cv2/                         # OpenCV computer vision
├── numpy/                       # Numerical computing
├── PIL/                         # Image processing (Pillow)
├── cryptography/                # Crypto libraries
├── M2Crypto/                    # OpenSSL wrapper
├── Crypto/                      # PyCryptodome
├── tcl/, tk/                    # Tcl/Tk for GUI elements
└── ... (Windows DLLs, .pyd extensions)

3. Runtime & Technology Stack

LayerTechnologyVersion / Detail
LanguagePython3.10
GUI FrameworkPyQt6Qt6 bindings
Image RecognitionOpenCV (cv2)Template matching
Image ProcessingPillow (PIL)Template preprocessing
Math/ArraysNumPyArray operations for CV
BundlingPyInstaller2.1+ (one-file mode)
ObfuscationPyArmorModern (observed: PY000000 header signature)
InstallerNSISv3.09
Emulator Interfacelibusb-1.0.dllLikely for BlueStacks USB/adb bridge
SchedulingAPScheduler3.10.4 (observed in dist-info)
Timezonespytz / tzdata / tzlocalFor bot scheduling logic

4. Main Executable Analysis

4.1 PyInstaller Archive

ClashFarmer.exe is a PyInstaller one-file executable containing an embedded CArchive.

Archive Signatures Detected:

SignatureOffsetDescription
_MEIPASS2175,920PyInstaller temp folder env var
PyInstaller archive175,980CArchive header string
PYZ\x00336,371Python Zlib archive (compiled modules)
PYZ-00.pyz7,089,037PYZ entry in CArchive TOC
PY000000311,792PyArmor payload signature

Extraction Stats:

  • CArchive entries: 18 files (bootloaders, runtime hooks, entry point)
  • PYZ archive entries: 1,341 compiled Python modules
  • Entry point module: qt_gui.pyc

4.2 Entry Point — qt_gui.pyc

The decompiled entry point is a PyArmor loader stub, not actual application logic:

# Reconstructed from bytecode analysis
from pyarmor_runtime_000000 import __pyarmor__
__pyarmor__(__name__, __file__, b'PY000000\x00\x03\n\x00...')

Key Observations:

  • The .pyc file contains a minimal wrapper (28 bytes of bytecode)
  • Real application logic is encrypted/obfuscated inside the PyArmor payload
  • The payload is decrypted at runtime by pyarmor_runtime.pyd
  • This is consistent with PyArmor modern mode (v7.x or v8.x)

4.3 PyArmor Runtime

AttributeDetail
Runtime Filepyarmor_runtime_000000/pyarmor_runtime.pyd
Size~634 KB (634,368 bytes)
TypePython C extension (CPython 3.10, amd64)
FunctionDecrypts and executes obfuscated Python bytecode at runtime
Protection LevelHigh — modern PyArmor uses dynamic code generation + C-extension binding

Deobfuscation Feasibility:

  • ❌ Static extraction of source code: Not feasible with current public tools
  • ⚠️ Dynamic analysis (memory dump): Theoretically possible but requires advanced reverse engineering
  • ⚠️ PyArmor version detection: Inconclusive without runtime hooking; payload structure suggests v7+ or v8

5. Configuration Analysis — config.db

5.1 Database Schema

ColumnTypePurpose
idINTEGERRow identifier
key_typeINTEGERCategory / namespace of config
keyBLOBPickle-serialized config key
valueBLOBPickle-serialized config value

5.2 Observed Configuration Keys (Row 1, key_type=0)

The bot stores its entire configuration as a single pickled Python dict. Observed keys include:

Config KeySample ValuePurpose
save_atleast_gold"1000000"Minimum gold to keep
minimum_elixir"100000"Minimum elixir threshold
troop_deploy_speed"7"Attack deployment speed
wave_deploy_speed"8"Wave deployment speed
hero_activation_method"time"Hero activation trigger
barracks_1_troop"Archer"Troop trained in barracks 1
find_deadbases1Enable dead base search
maximum_townhall_search"10"Max TH level to attack
collect-gold"1"Auto-collect gold
enable_telegram"0"Telegram notifications
use_king1Use Barbarian King
use_queen1Use Archer Queen

5.3 Config Data Format

Both keys and values are serialized using Python's pickle protocol.


6. Computer Vision Template Library

The images/ directory contains the bot's "eyes" — template images used for OpenCV matchTemplate() operations.

6.1 Template Categories

FolderPurposeDetection Method
buttons/UI buttons (Attack, Next, End Battle, etc.)Template matching
armyCampTroops/Troop icons in army campOCR / template matching
barracksTroops/Troop training iconsTemplate matching
battleTroops/Deployable troops during battleTemplate matching
buildingFont/Building level numbersOCR
lootScreenFont/Resource digits on loot screenOCR
deadBaseIndicators/Signs of inactive basesTemplate matching
walls/Wall segment templatesTemplate matching
THs/Town Hall levelsTemplate matching

7. Network & Communication

Observed libraries that suggest external communication capabilities:

LibraryPurpose
cryptographyHTTPS/TLS encryption
M2CryptoAdditional SSL/OpenSSL bindings
requestsHTTP client
_ssl.pyd, libssl-1_1.dllOpenSSL runtime

Telegram Bot Integration: Config keys exist for telegram_token_key.

Pushbullet Integration: Config keys exist for pushbullet_api_key.


8. Anti-Detection Measures

TechniqueEvidence
Image-based automationUses OpenCV template matching instead of memory injection
Human-like delaysConfigurable troop_deploy_speed, wave_deploy_speed
Randomizationwave_delay and multiple zoom detection templates
Background modeReferences to BlueStacks minimization; PyQt6 GUI can run detached
PyArmor obfuscationProtects bot logic from static analysis
Scheduled timeoutsbot_timeout_at_* configs allow human-like offline periods

9. Reverse Engineering Difficulty Assessment

ObjectiveDifficultyNotes
Extract installer contents✅ EasyNSIS silent install works
Identify tech stack✅ EasyStandard tools
Modify config parameters🟡 MediumRequires SQLite + pickle knowledge
Replace template images🟡 MediumMust match exact resolution/format
Extract source code🔴 Very HardPyArmor modern blocks static extraction
Add new logic/features🔴 Nearly ImpossibleRequires source code or full rewrite

10. Open-Source Bot Landscape

Comparative Feature Matrix

FeatureClashFarmerClAsHbOtMBRpyAutoYoloCOCcoc-attack-bot
LanguagePythonAutoItAutoItPythonPython
CV MethodTemplate MatchingTemplate MatchingPixel/OCRYOLOv11Coordinate-based
Background Mode
Auto Train
Auto Attack
Dead Base Filter
Donation✅ Configurable
Hero Ability✅ Time-based
Anti-Detection✅ PyArmor + delays
Active Maintenance✅ Commercial❌ 20162025🟡 2024🟡 2025
Open Source❌ ObfuscatedGPL v3

Report compiled for private research purposes. No proprietary files or copyrighted assets are distributed herein.