Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Exploit development and reversing

Lab · Medium · 1.5 hours

Game Reversing & Modding

Byte-array signatures, script persistence, logic reversing, and packaging a simple mod.

  • game-hacking
  • reverse-engineering
  • modding
  • signature-scanning
On this page 8 sections
  1. ·Lab Setup
  2. 1Persist a patch with a Lua script
  3. 2Scan for a byte-array signature
  4. 3Reverse a game function
  5. 4Modify game logic
  6. 5Package a table as a mod
  7. ·Defence and Detection
  8. ·Check Your Work

Before you start

Modding goes beyond a one-shot memory edit. A byte-array signature finds code by its shape, so a mod survives a game update that moves addresses. A Lua script re-applies the patch each run, so the cheat persists. The same mechanics run under anti-cheat bypasses and under malware that injects into a long-running process. In this lab you write a signature scan, reverse a short function, and package a durable mod.

What You'll Learn

  • Write a Cheat Engine Lua script that re-applies a patch every time the game starts
  • Scan for a byte-array signature to find code without relying on a fixed address
  • Reverse a game function to understand its logic, not just its effect
  • Modify logic so the game behaves differently, not just ignores damage
  • Package a Cheat Engine table as a reusable mod file
  • Explain why signature scanning is more durable than a hard-coded address

Lab Setup

You continue with the same tools from Game Hacking Fundamentals. This lab adds Lua scripting and byte-pattern scanning.

ItemRequirement
Lab machineWindows 10 or 11 (a VM is fine)
Cheat EngineVersion 7.5+ with Lua scripting enabled (the default)
TargetThe Cheat Engine Tutorial (Tutorial-x86_64.exe)
OptionalA simple open-source game such as Assault Cube or Minetest for the final step

Authorised scope only. Isolated lab network. Never on production.

Step 1: Persist a patch with a Lua script

1

Persist a patch with Lua

The NOP patch from the previous lab disappears when you close the game. A Lua script in a Cheat Engine table re-applies the patch automatically, so it survives a relaunch.

Open the Cheat Engine Tutorial and attach Cheat Engine. Find the damage instruction the same way as before. Note the original bytes and the address. For this example, the damage instruction is sub [rsi+780], edx at an offset inside the module.

Open the Cheat Engine Lua engine: Table → Show Cheat Table Lua Script. Write a script that finds the instruction by module offset and patches it.

-- damage_patch.lua — NOP the damage instruction on activation
local moduleName = "Tutorial-x86_64.exe"
local offset     = 0x2B012        -- offset of sub [rsi+780], edx
local nopBytes   = "\x90\x90\x90\x90\x90\x90"
local origBytes  = "\x29\x96\x80\x07\x00\x00"

function patchDamage()
  local base = getAddress(moduleName)
  if base == nil then
    print("Module not found")
    return
  end
  local addr = base + offset
  writeBytes(addr, {0x90, 0x90, 0x90, 0x90, 0x90, 0x90})
  print(string.format("Patched %s+0x%X (%X)", moduleName, offset, addr))
end

function restoreDamage()
  local base = getAddress(moduleName)
  if base == nil then return end
  local addr = base + offset
  writeBytes(addr, {0x29, 0x96, 0x80, 0x07, 0x00, 0x00})
  print(string.format("Restored %s+0x%X", moduleName, offset))
end

Click Execute Script. Then call patchDamage() from the Lua console. The damage stops. Call restoreDamage() to put the original bytes back.

Patched Tutorial-x86_64.exe+0x2B012 (7FF6E42B012)

Save the table (File → Save As). Next time you open the tutorial, load the table and run the script. The patch applies in one click.

The important idea: a module-relative offset (base + 0x2B012) works even when ASLR moves the module. A hard-coded address does not.

Step 2: Scan for a byte-array signature

2

Module offsets change between game versions. A byte-array signature finds the instruction by its machine code pattern, which stays the same even when the binary is recompiled with a new base.

In Cheat Engine, go to Memory View → Search → Array of byte. Type the bytes of the damage instruction with some surrounding context. Use ?? for bytes that might change between versions (for example register encodings that depend on compiler choices).

Search pattern: 29 96 80 07 00 00 8B ?? ?? ?? 00 00
Found: 1 result at 7FF6E42B012

One match. The pattern is unique. Now update the Lua script to use a signature scan instead of a fixed offset.

function findDamageBySig()
  local sig = "29 96 80 07 00 00"
  local result = AOBScan(sig, "+X-C-W")  -- executable, not code cave, not writable
  if result == nil or result.Count == 0 then
    print("Signature not found")
    return nil
  end
  local addr = tonumber("0x" .. result[0])
  result.destroy()
  return addr
end

function patchBySig()
  local addr = findDamageBySig()
  if addr then
    writeBytes(addr, {0x90, 0x90, 0x90, 0x90, 0x90, 0x90})
    print(string.format("Sig-patched at %X", addr))
  end
end

Call patchBySig(). It finds and patches the instruction without knowing the module base or the offset. This technique works across game updates as long as the compiler does not change the instruction encoding.

The "+X-C-W" flags tell the scanner to search only executable memory. This skips data sections and reduces false positives.

Step 3: Reverse a game function

3

Knowing that an instruction does damage is useful. Knowing the full function — where it reads the damage amount, how it checks for shields, what it does on death — lets you change the game's rules, not just suppress one effect.

In Cheat Engine's Memory View, navigate to the damage instruction. Read the surrounding code.

7FF6E42B00A:  mov  edx, [rsi+790]      ; load attack power
7FF6E42B010:  nop  nop ...              ; (was: sub [rsi+780], edx)
7FF6E42B016:  cmp  dword ptr [rsi+780], 0
7FF6E42B01D:  jg   7FF6E42B02A         ; if health > 0, skip death
7FF6E42B01F:  mov  dword ptr [rsi+798], 1  ; set dead flag
7FF6E42B029:  ret
7FF6E42B02A:  ...                       ; continue

Read the function from top to bottom. It loads the attack value from offset +790, subtracts it from health at +780, checks if health hit zero, and sets a dead flag at +798. Each offset is a field in the game object.

Build a map of the object:

rsi + 0x780  = health (4 bytes)
rsi + 0x790  = attack power (4 bytes)
rsi + 0x798  = dead flag (4 bytes, 0 or 1)

This map is the product of reversing. With it you can write mods that do more than NOP: you can double the attack power, make health regenerate, or prevent the dead flag from ever being set.

Step 4: Modify game logic

4

Instead of removing damage, change the rule. This step replaces the subtract with an add, so every hit heals the player instead of hurting them.

The original instruction is sub [rsi+780], edx (bytes 29 96 80 07 00 00). The add equivalent is add [rsi+780], edx (bytes 01 96 80 07 00 00). Only the first byte changes: 29 (sub) becomes 01 (add).

function healOnHit()
  local addr = findDamageBySig()
  if addr then
    writeBytes(addr, {0x01})  -- change only the opcode byte
    print(string.format("Heal-on-hit at %X", addr))
  end
end

Call healOnHit(). Now click Hit me in the tutorial. The health goes up instead of down. You changed one byte of the game's logic. The function still runs, the registers still carry the same values, but the operation is reversed.

This is the difference between suppressing an effect (NOP) and changing the rules (opcode swap). Both are single-byte edits, but the second one shows that you understand the code.

Step 5: Package a table as a mod

5

A Cheat Engine table (.CT file) bundles addresses, scripts and descriptions into one file. Sharing a table lets someone else use your mod without repeating the analysis.

In Cheat Engine, add the following entries to the address list:

  1. A memory record for health (the pointer entry from the previous lab).
  2. A memory record for attack power at the same base pointer, offset +790.
  3. A script entry that runs patchBySig() when activated and restoreDamage() when deactivated.

To create a script entry: right-click the address list, choose Add Address Manually, and select Auto Assembler Script as the type. Paste:

[ENABLE]
{$lua}
patchBySig()
{$asm}

[DISABLE]
{$lua}
restoreDamage()
{$asm}

Name the entry God Mode. Tick its checkbox to activate, untick to deactivate.

Save the table as tutorial_mod.CT. The file is portable. Anyone with Cheat Engine can open it, attach to the tutorial, and toggle your mod.

tutorial_mod.CT
├── God Mode (script: sig-patch damage)
├── Health (pointer: base+18 → 4 bytes)
└── Attack Power (pointer: base+790 → 4 bytes)

A well-made table has a description for each entry, the game version it was tested on, and a note about which signatures may break on updates.

Defence and Detection

Anti-cheat engines use several layers. Signature scanning detects Cheat Engine by its window class name and driver. Code integrity checks hash the .text section periodically and crash if bytes have changed. Obfuscation moves game logic into virtual-machine bytecode that is harder to read in a disassembler. Server authority keeps the real state on the server so local edits change only the display.

From the reverse engineer's perspective, every defence is a reversing problem. The skill you practised here — scan, read the code, change one byte — is the same skill that malware analysts use to disable anti-analysis checks. The domain changes; the method does not.

Check Your Work

  • Why is a byte-array signature more durable than a hard-coded address?
AnswerASLR changes the base address on every launch, and game updates change the binary layout. A signature matches the instruction bytes, which stay the same unless the compiler changes the encoding.
  • The sub instruction byte is 29 and the add byte is 01. You changed one byte and reversed the effect. What does this tell you about x86 opcode encoding?
AnswerMany x86 instructions share the same operand encoding and differ only in the opcode byte. `sub r/m, r` and `add r/m, r` use the same ModR/M byte, so swapping the opcode changes the operation without touching the operands.
  • What is the advantage of a Lua script over a manual patch?
AnswerA script re-applies the patch automatically. It survives a game restart, can find the target by signature instead of a fixed address, and can be toggled on and off without restarting.
  • A code integrity check hashes the .text section every second. How does this detect your NOP patch?
AnswerThe NOP bytes change the content of the `.text` section. The next hash check produces a different value from the stored original, and the game detects the modification.
  • Name one defence that stops a memory edit from affecting the real game outcome, even if the client is fully compromised.
AnswerServer-authoritative design. The server holds the real health value and validates every action. A client-side edit changes only the local display.

Sign in to track progress and send feedback.

Related