Skip to content

jacksonsalopek/zarc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zarc - DARC Archive Tool

A modern reimplementation of darctool in Zig 0.15 for extracting and building 3DS DARC archive files.

Overview

DARC (Data ARChive) is an archive format used by Nintendo 3DS. This tool allows you to:

  • Extract DARC archives to a directory
  • Build DARC archives from a directory

Features

  • ✅ Full DARC format support (extraction and building)
  • ✅ UTF-16LE filename handling
  • ✅ Recursive directory processing
  • ✅ Clean, modular codebase following DRY principles
  • ✅ Memory-safe implementation in Zig
  • ✅ Cross-platform support

Architecture

The project is organized into several modules for maintainability:

src/
├── main.zig        # CLI interface and argument parsing
├── root.zig        # Module exports and public API
├── types.zig       # Core data structures (DarcHeader, DarcTableEntry)
├── extractor.zig   # Archive extraction functionality
├── builder.zig     # Archive building functionality
└── utils.zig       # Utility functions (UTF conversion, file I/O)

Key Components

  • DarcHeader: Archive header with magic number, BOM, version, and metadata
  • DarcTableEntry: File/directory entry with name offset, data offset, and size
  • DarcExtractor: Handles archive extraction with recursive directory support
  • DarcBuilder: Constructs archives from filesystem directories
  • Utils: Common utilities for UTF-16LE conversion and file operations

Building

Requires Zig 0.15.2 or later.

zig build

The executable will be generated in zig-out/bin/zarc.

Usage

Extract an archive

zarc --extract <archive.arc> <output_directory>

Example:

zarc --extract game.arc extracted/

Build an archive

zarc --build <output.arc> <input_directory>

Example:

zarc --build modified.arc source_files/

DARC Format

The DARC archive format consists of:

  1. Header (0x1c bytes):

    • Magic: "darc" (0x63726164)
    • BOM: 0xfeff (little-endian)
    • Header length: 0x1c
    • Version: 0x01000000
    • File size, table offset/size, filedata offset
  2. Table entries (12 bytes each):

    • Filename offset (24-bit) + directory flag (bit 24)
    • Data offset (for files) or unused (for directories)
    • File size (for files) or end index (for directories)
  3. Filename table: UTF-16LE null-terminated strings

  4. File data: Raw file contents

Testing

Run the test suite:

zig build test

Standard Library Optimizations

This implementation efficiently leverages Zig's standard library:

  • std.mem.indexOfScalar: Fast null terminator search in UTF-16 data
  • std.fs.path.join: Proper cross-platform path handling
  • std.fs.File.readToEndAlloc: Optimized file reading with proper memory allocation
  • std.unicode: Built-in UTF-16LE ↔ UTF-8 conversion
  • std.fs.cwd().makePath: Recursive directory creation

Differences from Original

This reimplementation improves upon the original C version:

  • Type safety: Zig's strong type system prevents common bugs
  • Memory safety: Automatic memory leak detection in debug builds
  • Better error handling: Explicit error propagation with Zig's error system
  • Modular design: Separated concerns with dedicated modules
  • Modern tooling: Built-in build system and package manager
  • Standard library usage: Efficient use of built-in path, file I/O, and string utilities

Notes

  • When building archives, file order may differ from the original due to filesystem iteration order
  • Archives may have different sizes due to alignment differences
  • Both differences are normal and don't affect functionality
  • Compressed archives must be decompressed before extraction

License

This is a reimplementation of the original darctool. The original tool's files (utils.c/h, types.h) from yellows8/darctool were used as reference.

Credits

  • Original darctool by yellows8
  • Zig reimplementation by the zarc project

About

Zig-based darc builder/extractor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages