← Back to Writeups
CUSTOMMediumReversing

46 - Простая геометрия (Simple Geometry)

XESXOR9/2/20265 min read
#reversing#custom#medium#angle_computation#dot_product_calculation#euclidean_distance#static_binary_analysis#vector_operations

46 - Простая геометрия (Simple Geometry)

Platform: CUSTOM | Category: Reversing | Type: Challenge | Difficulty: Medium | OS: N/A | **Author: XESXOR Techniques: angle_computation, dot_product_calculation, euclidean_distance, static_binary_analysis, vector_operations

Summary

Walkthrough of the CUSTOM Reversing 46 - Простая геометрия (Simple Geometry). Task: Reverse engineer a binary that validates geometric properties of 6 points in 2D space. Solution: Analyze the binary to identify perpendicularity check (dot product = 0) and distance constraints

Description

A reverse engineering challenge involving a binary called simple_geo that validates geometric properties of points in 2D space. The binary accepts 6 points (p1 through p6), each with x and y coordinates, and verifies specific geometric relationships between them.

Analysis

Binary Structure

The challenge requires inputting 6 points in 2D space (12 coordinates total). The binary constructs 3 line segments from pairs of points:

  • Line 1: from p1 to p2
  • Line 2: from p3 to p4
  • Line 3: from p5 to p6 ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Key Validation Conditions

The binary implements geometric checks with the following requirements:

  1. Perpendicularity Check: The angle between Line 1 and Line 2 must be exactly 90 degrees

    • Calculated using the dot product of direction vectors
    • Formula: (dot_product / (length1 * length2)) = 0 (for perpendicular vectors)
  2. Distance Constraints:

    • Length of Line 1 must be exactly 4.0
    • Length of Line 2 must be exactly 5.0
    • Length of Line 3 must be exactly 4.0

Key Functions in Binary

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

fcn.00001199 - Distance Calculator

Calculates Euclidean distance between two points:

distance = sqrt((x2 - x1)^2 + (y2 - y1)^2)

fcn.0000123a - Dot Product

Computes the dot product of two vectors:

dot_product = v1.x * v2.x + v1.y * v2.y

fcn.000012e8 - Angle Computation

Calculates the absolute cosine of the angle between two line segments:

cos_angle = abs(dot_product / (length1 * length2))

For perpendicular lines, this returns 0.

Solution

Mathematical Approach

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

To satisfy the constraints:

  1. Create two perpendicular lines of lengths 4.0 and 5.0
  2. Create a third line of length 4.0

A simple solution uses axis-aligned vectors:

  • Line 1 (horizontal): p1 = (0, 0) to p2 = (4, 0)

    • Direction: (4, 0)
    • Length: 4.0
  • Line 2 (vertical): p3 = (0, 0) to p4 = (0, 5)

    • Direction: (0, 5)
    • Length: 5.0
    • Dot product with Line 1: 40 + 05 = 0 ✓ (perpendicular)
  • Line 3: p5 = (0, 0) to p6 = (4, 0)

    • Length: 4.0

Python Solution

python
#!/usr/bin/env python3
import math
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

# Define the points that satisfy all geometric constraints
points = [
    (0, 0),      # p1
    (4, 0),      # p2 - Line 1 length = 4.0
    (0, 0),      # p3
    (0, 5),      # p4 - Line 2 length = 5.0, perpendicular to Line 1
    (0, 0),      # p5
    (4, 0)       # p6 - Line 3 length = 4.0
]

def distance(p1, p2):
    """Calculate Euclidean distance between two points."""
    return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)

def dot_product(v1, v2):
    """Calculate dot product of two vectors."""
    return v1[0] * v2[0] + v1[1] * v2[1]
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

def verify_solution(points):
    """Verify that the solution meets all constraints."""
    p1, p2, p3, p4, p5, p6 = points

    # Create direction vectors
    line1_dir = (p2[0] - p1[0], p2[1] - p1[1])
    line2_dir = (p4[0] - p3[0], p4[1] - p3[1])
    line3_dir = (p6[0] - p5[0], p6[1] - p5[1])

    # Calculate lengths
    len1 = distance(p1, p2)
    len2 = distance(p3, p4)
    len3 = distance(p5, p6)

    # Check dot product (should be 0 for perpendicular)
    dot = dot_product(line1_dir, line2_dir)

    print(f"Line 1 length: {len1} (expected 4.0)")
    print(f"Line 2 length: {len2} (expected 5.0)")
    print(f"Line 3 length: {len3} (expected 4.0)")
    print(f"Dot product (Line 1 × Line 2): {dot} (expected 0 for perpendicular)")
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

    # Verify constraints
    assert abs(len1 - 4.0) < 0.0001, f"Line 1 length must be 4.0, got {len1}"
    assert abs(len2 - 5.0) < 0.0001, f"Line 2 length must be 5.0, got {len2}"
    assert abs(len3 - 4.0) < 0.0001, f"Line 3 length must be 4.0, got {len3}"
    assert abs(dot) < 0.0001, f"Lines must be perpendicular, dot product: {dot}"

    print("\nAll constraints satisfied!")
    return True

# Verify the solution
verify_solution(points)

# Output for use with the binary
print("\nInput coordinates for the binary:")
for i, (x, y) in enumerate(points, 1):
    print(f"p{i}: {x} {y}")

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Interactive Input

When running the binary, provide the following sequence of coordinates:

0 0 4 0 0 0 0 5 0 0 4 0

Or when prompted individually for each point:

  • p1: 0 0
  • p2: 4 0
  • p3: 0 0
  • p4: 0 5
  • p5: 0 0
  • p6: 4 0

Techniques and Concepts

Vector Mathematics

  • Dot Product: For checking perpendicularity, if dot product = 0, vectors are perpendicular
  • Euclidean Distance: Standard 2D distance formula
  • Vector Normalization: Used implicitly in angle calculations

Geometric Constraints

  • Axis-aligned vectors simplify calculations (fewer rounding errors)
  • Perpendicular vectors can be generated by swapping coordinates and negating one
  • Distance constraints are verified exactly using the Euclidean formula ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Alternative Solutions

While the simple axis-aligned solution works, other valid inputs could include:

  • Any two perpendicular vectors with magnitudes 4.0 and 5.0
  • Example: (3, 0) to (7, 0) for a horizontal line of length 4.0
  • Example: (2, 0) to (2, 5) for a vertical line of length 5.0

The key is maintaining exact distances and perpendicularity through floating-point calculations. ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Key Takeaways / Lessons

  • Mastering angle_computation, dot_product_calculation, euclidean_distance, static_binary_analysis, vector_operations was key to this challenge.
  • Always check for common misconfigurations and verify assumptions.

Crafted by XESXOR Research • 2026-01-09 • CUSTOM • 46 - Простая геометрия (Simple Geometry) • Difficulty: Medium