Skip to content
Adam Omar Saleh

TVX CTF 2026 placeholder badge (unofficial)TVX CTF 2026Reverse Engineering

Ending

A 10 KB .NET executable compares input against a flag that it computes at runtime by running hidden bytecode on a tiny virtual machine.

Competition
TVX CTF 2026 placeholder badge (unofficial)TVX CTF 2026
Category
Reverse EngineeringMedium · estimated
Source status
Locally verified · challenge binary accepted
Document
PDF edition5 min read

Brief

The challenge

Competition
TVX CTF 2026
Category
Reverse Engineering
Difficulty
Medium — estimated, not an official rating
Points
100
Solves
63 on the challenge card when captured
Challenge author
notsaad
Verification
Locally verified: the challenge binary printed “accepted” (recorded in source)

Difficulty: Medium (estimated). TVX CTF 2026 did not publish difficulty ratings; the challenge cards show only points and solve counts. The .NET layer decompiles cleanly, but the flag is produced by a custom register VM whose bytecode is Base64, gzip and byte-transform encoded. The VM has to be understood and emulated. It is small and does not depend on input, which keeps it below Hard. The card showed 63 solves when captured.

01

Overview

What has beginnings Has endings, And What Has code, has Flags.

Challenge page
Challenge page

A 10 KB .NET executable compares input against a flag that it computes at runtime by running hidden bytecode on a tiny virtual machine.

Solution path in brief

Ending.exe is a 10 KB .NET assembly. It contains a gzipped, base64-encoded bytecode blob, decodes each byte with a rotate-right and XOR, then runs it on a tiny register VM. The VM writes the 31-byte flag into a buffer, and Main compares your input against it. Nothing depends on user input, so emulating the VM prints the flag:

Text
base64 → gunzip → ror(b, i%5+1) ^ (199 + 91·i) → VM → flag

02

Initial investigation

Triage identified the file type before any decompilation.

Triage

The PE has .text, .rsrc and .reloc sections and imports only mscoree.dll, so it's .NET. ilspycmd Ending.exe -o src -p decompiles it to near-original C# in src/Program.cs.

03

Tools used

  • ILSpy / ilspycmd (.NET decompilation)

  • Python 3 (base64, gzip, custom VM emulator in solve.py)

04

Step-by-step process

Step 1: Reading Main

C#
string text = Run();Console.Write("flag> ");string text2 = Console.ReadLine() ?? string.Empty;Console.WriteLine((text2 == text) ? "accepted" : "rejected");

The flag is computed by Run() before any input is read. It never touches user input.

Step 2: Unpacking the bytecode

Unpack() base64-decodes the package constant, gunzips it (958 bytes), and decodes every byte:

C#
array[i] = (byte)(Ror(array[i], i % 5 + 1) ^ ((199 + i * 91) & 0xFF));

Step 3: The VM

Run() has 4 × 16-bit registers, 128 words of memory, and a 31-byte output buffer. Instructions:

OpcodeMeaning
0x10r[a] = imm16
0x11 / 0x12r[a] ^= imm16 / r[a] += imm16
0x13r[a] = rol16(r[a], n)
0x14 / 0x15r[a] = mem[b] / mem[a] = r[b]
0x16 / 0x17 / 0x18r[a] ^=, +=, -= r[b]
0x19r[a] = ~r[a]
0x1Ar[a] = mem[r[b]]
0x30if r[a] != 0: ip += off (signed 8-bit)
0x31ip += off
0x40append r[a] & 0xFF to the output
0xFFhalt, return output as ASCII

The program starts by filling memory with constants (10 02 a3 60 15 00 02 … means r2 = 0x60a3; mem[0] = r2, and so on). It then runs a loop that mixes them through the arithmetic ops and writes out one character at a time.

Step 4: Emulating

solve.py reimplements Unpack() and the VM in Python, using 16-bit wraparound and the same operand order as the C# code:

Text
$ python solve.pybytecode: 958 bytesTVX{S0me_1nt2r2st1ng_t2xt_h2r2}

05

Commands and code

Full source: solve.py: unpack and emulate the VM

Python
import base64, gzip, re​src = open("src/Program.cs", encoding="utf-8").read()package = re.search(r'package = "([^"]+)"', src).group(1)​​def ror(v, c):    return ((v >> c) | (v << (8 - c))) & 0xFF​​def unpack():    data = bytearray(gzip.decompress(base64.b64decode(package)))    for i in range(len(data)):        data[i] = ror(data[i], i % 5 + 1) ^ ((199 + i * 91) & 0xFF)    return bytes(data)​​def run(prog):    r = [0] * 4    mem = [0] * 128    out = bytearray()    ip = 0    M = 0xFFFF​    def byte():        nonlocal ip        v = prog[ip]        ip += 1        return v​    def word():        nonlocal ip        v = prog[ip] | (prog[ip + 1] << 8)        ip += 2        return v​    def sbyte():        v = byte()        return v - 256 if v > 127 else v​    while True:        op = byte()        if op == 16:            a = byte(); r[a] = word()        elif op == 17:            a = byte(); r[a] ^= word()        elif op == 18:            a = byte(); r[a] = (r[a] + word()) & M        elif op == 19:            a = byte(); n = byte()            r[a] = ((r[a] << n) | (r[a] >> (16 - n))) & M        elif op == 20:            a = byte(); b = byte(); r[a] = mem[b]        elif op == 21:            a = byte(); b = byte(); mem[a] = r[b]        elif op == 22:            a = byte(); b = byte(); r[a] ^= r[b]        elif op == 23:            a = byte(); b = byte(); r[a] = (r[a] + r[b]) & M        elif op == 24:            a = byte(); b = byte(); r[a] = (r[a] - r[b]) & M        elif op == 25:            a = byte(); r[a] = ~r[a] & M        elif op == 26:            a = byte(); b = byte(); r[a] = mem[r[b]]        elif op == 48:            a = byte(); off = sbyte()            if r[a] != 0:                ip += off        elif op == 49:            off = sbyte(); ip += off        elif op == 64:            out.append(r[byte()] & 0xFF)        elif op == 255:            return bytes(out)        else:            raise ValueError(f"bad opcode {op} at {ip - 1}")​​prog = unpack()open("bytecode.bin", "wb").write(prog)print(f"bytecode: {len(prog)} bytes")print(run(prog).decode("ascii"))

06

Technical explanation

The bytecode is stored as Base64 of a gzip stream. After decompression, each byte is rotated right by i % 5 + 1 and XORed with (199 + 91·i) & 0xFF. The VM has four 16-bit registers, 128 words of memory, arithmetic and rotate opcodes, conditional and unconditional relative jumps, and an output opcode. Reimplementing the opcode table in Python and running the program prints the 31-byte flag without executing the original binary's logic.

Key lessons

  • With .NET, decompile first. ILSpy gives you almost the original source, VM included.

  • If a custom VM doesn't take input, there's no need to disassemble the bytecode. Emulate it, or set a breakpoint after Run() returns.

  • Don't "correct" a flag that looks odd. Check it against the binary.

07

Flag

Flag

TVX{S0me_1nt2r2st1ng_t2xt_h2r2}

Locally verified · challenge binary accepted

08

Verification status

Status: Locally verified: the challenge binary printed “accepted” (recorded in source).

The source records the challenge binary printing accepted for the recovered flag and rejected for the more “natural” leetspeak spelling. Platform acceptance is not documented.

Evidence recorded in the source

Text
> "TVX{S0me_1nt2r2st1ng_t2xt_h2r2}" | .\Ending.exeflag> accepted

The "normal" leetspeak version, TVX{S0me_1nt3r3st1ng_t3xt_h3r3}, is rejected. In this flag the es really are 2s.

Source evidence in the archive: WRITEUP.md, solve.py, images/00_challenge.png.

09

Conclusion

A small but complete VM-based crackme. Emulating the VM is more reliable than reversing its algorithm, because the program does not depend on input.

Prepared by Adam Omar Saleh from the archived solve notes in ending/. Commands, code, output and screenshots are reproduced from the source; no results were added. Difficulty is an estimate.

PDF edition

Writeup PDF

Formatted edition of this walkthrough, built from my source notes · 5 pages.