Skip to content
ngagesdkPublic

About

Unpacks, packs and repacks compressed executables.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

ngpack

Unpacks, packs and repacks compressed N-Gage / Symbian 6.x executables. In these files, a small E32 loader stub carries the real program as a gzip-compressed "LXCE" image, which a shared loader DLL (ecstb.dll) runs. Several N-Gage games ship their .exe and .app files in this form.

  • unpack turns a packed executable into an ordinary Symbian E32 image, which opens in E32 tools like any other application.
  • pack and repack turn an E32 image (or a raw LXCE image) back into the packed form.

Written in C99. The only dependency is zlib.

Build

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release

CMake uses a system zlib if it finds one. You can point it at one with -DZLIB_ROOT=..., or use vcpkg. Otherwise it downloads zlib 1.3.1 and links it statically, which is what normally happens on a plain Windows/MSVC setup. To always use the downloaded copy, pass -DNGPACK_FETCH_ZLIB=ON.

Usage

ngpack info   <file>...                   describe packed, E32 or LXCE files
ngpack unpack <packed> [-o <out>]         write a plain E32 image (default <name>_unpacked.<ext>)
ngpack unpack <packed> --raw [-o <base>]  write <base>.stub and <base>.lxce (raw container parts)
ngpack pack   <in> <stub> <out>           pack an E32 or LXCE image; <stub> is a packed original
                                          or a .stub file
ngpack repack <packed> <out> [-p <in>]    recompress, keeping the original stub; -p swaps in an
                                          edited E32 or LXCE image

-l <1-9>   compression level (default 9)
-f         pack even if consistency checks fail

Typical patch workflow:

ngpack unpack game.exe                      # -> game_unpacked.exe (E32)
# ...inspect / patch game_unpacked.exe in your E32 tools...
ngpack repack game.exe game_patched.exe -p game_unpacked.exe

info tells you whether a file is packed. A packed file ends with a 4-byte offset that points at a gzip header (1f 8b 08) directly after the E32 stub.

Every conversion is checked before anything is written. The result is read back and must describe the same program as the input. You don't need to fix checksums after editing an E32 image: pack and repack recompute everything.

The packed format

Offset Contents
0 E32 loader stub (about 1 KB)
payloadOffset gzip member containing an LXCE image
size - 4 u32 payloadOffset (little-endian)

The stub does no unpacking itself. It loads e:\system\libs\ecstb.dll and e:\system\libs\whichservice.dll and passes them its own path. Those DLLs read the gzip stream and run the LXCE image. The stub does not store the payload's size or checksum, and stubs of the same type (EXE or DLL) differ only in their UIDs, so any stub can carry any payload of the same type.

LXCE is a flattened ARM PE image, as produced by the Symbian 6.x arm-epoc-pe toolchain:

Offset Field
0x00 "LXCE"
0x04 version (1)
0x08 image base (import/relocation RVAs are relative to it)
0x0C entry point: EXE startup code, or a DLL's export ordinal 1
0x10 5 × {u32 vaddr, u32 size}: text, bss, data, imports, relocs
0x38 raw data for each section except bss, in that order

The import section holds standard PE import descriptors, all by ordinal (for example EUSER[100039e5].DLL). The reloc section holds standard PE base-relocation blocks.

How the E32 conversion works

The E32 output uses the same header flavour as the loader stubs (Symbian 6.x / EKA1, 0x7C-byte header). UIDs, flags, heap/stack sizes, priority, CPU, tool version and timestamp are copied from the stub. The code section is the LXCE text, followed by the import address table (ordinals) and, for DLLs, a one-entry export directory. Relocations are written as inferred (type 3) entries, like the stubs use. The UID, code and data checksums are computed.

For DLLs such as .app files, the E32 entry point is the start of the text (the E32Dll stub), and the LXCE entry point becomes export ordinal 1 (for an .app, NewApplication).

Some details of the conversion:

  • E32 relocates code and data separately; the LXCE loader moves the whole image as one block. If the import table would push the code into the data section, the data is moved up to the next 4 KB boundary, and every pointer into it is adjusted.
  • A relocated value can point outside every section, for example a computed address used as a bound. Such values are relocated with the data section, which is what the Symbian loader does with any value outside the code. unpack prints a note when it finds them.
  • When converting back, the LXCE import and relocation sections are rebuilt from scratch, so a repacked file has a slightly different layout and size from the original. It describes the same program: the same bytes, the same relocation targets and the same imports.

What is not supported, and is reported as an error:

  • PE imports by name (only ordinal imports are converted)
  • PE relocation types other than HIGHLOW
  • DLLs with more than one export (an LXCE image can carry only one)

Caveats

  • Symbian 6.x refuses to load a DLL that has writable static data on its own. A packed original with data works only because the stub's loader takes care of it. The E32 form of such a DLL is fine for inspection and patching, but repack it before putting it on a device. unpack warns when this applies.
  • The E32 images are checked structurally but have not been run on hardware. The LXCE code is built as a normal Symbian program, but the stub's loader could set something up that the program relies on (stack size, for example: the E32 keeps the stub's value).
  • Plain E32 images, such as the DLLs in system/libs, are not packed. info reports them as plain E32 images.

Tested with

Tony Hawk's Pro Skater (N-Gage, v2.8): tonyhawk.exe, tonyhawk.app and gsbapp.app. All three unpack to valid E32 images and repack to the same programs. Other games that use the same ecstb.dll loader should work. If one doesn't, ngpack info and the error message should show which part of the format differs.

About

Unpacks, packs and repacks compressed executables.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages