Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Tool:DJGPP

From ReverseEngineering.wiki
Tool
On this wiki Facts · Code · Notes · Topics

DJGPP is the DOS port of GCC: its programs are 32-bit COFF images behind a small real-mode stub (go32 stub) that loads a DPMI server such as CWSDPMI if none is present and passes a 'go32stub' info block to the program.

What a DJGPP program looks like

A DJGPP v2 .EXE is an MZ file (Format:DOS MZ executable) whose DOS image is the stub (stub.asm, about 2 KB) and whose COFF image (i386 COFF, machine 0x014C) begins right after the end of the DOS image as computed from the MZ header (bytes in last page and 512-byte page count). The stub can also be run on a bare COFF file; it checks the first word for 0x014C (COFF) or 0x5A4D (MZ) and otherwise reports that the file is not an EXE. Quake's DOS build is a known DJGPP program.

Stub info block

The start of the stub's data segment is the stubinfo structure, given in Fact:DJGPP/struct/go32stub info block: the first 8 bytes are always go32stub (the rest of the 16-byte magic holds the version, for example ", v 2.05"). Its presence marks a DJGPP v2 executable. The default DPMI server name stored in it is CWSDPMI.EXE; the stub scans the environment for PATH and the stub's own full name (stub.asm around line 160) and adds CWSDPMI to a path ending (around line 736) when no DPMI host is running.

Reversing notes

  • To get at the program, skip to the COFF header at the end of the MZ image; section headers give .text, .data and .bss; the stub loads the text and data sections by their file offsets.
  • Many DJGPP games are also compressed (UPX handles go32 COFF; see Tool:UPX). Unverified: UPX's DJGPP COFF format name and whether it keeps the go32stub block intact.

Code & repositories

  • https://github.com/jwt27/djgpp-cvs @ 896d54a48b4f54802ba63aa9849b5011f1e51645 · license: unknown
    Git mirror of the DJGPP CVS tree; src/stub/stub.asm is the real-mode go32 stub that defines the stubinfo block, finds the COFF image after the MZ image and loads CWSDPMI.
    Tested on: source read, not run: Read src/stub/stub.asm at this commit; nothing built or run. · checked 2026-10-19