Skip to main content

Crate proka_exec

Crate proka_exec 

Source
Expand description

§proka-exec

Rust Nightly License: GPLv3 GitHub Stars GitHub Issues GitHub Pull Requests Documentation

Copyright (C) 2026 RainSTR Studio. Licensed under GNU GPLv3.


§Introduction

This crate provides the definitions of headers, section index, section metadata, and some utils to help you parse the executable easily.

§Structures of this executable

This executable is structured as follows:

  • PKE headers - Records the basic information of this executable;
  • Section index - Records the section header’s offset and section name’s length;
  • Section metadata- Records the section flags, data offset and its length;
  • Data - The binary content.

We can use this picture to explain their segmented structure:

[Headers] [Section Index 1] [Section Index 2] ... [Section Metadata 1] [Section Metadata 2] ... [Data]

Simultaneously, the [Section Metadata] can be separated as follows:

[Section Headers] [Section Name]

In the picture above, the [Section Headers]’s length is fixed, which is recorded in SECTION_HDR_SIZE; The section name is different - It’s dynamic, so you can store almost infinite words in it!

§Steps to use this crate

§Parsing

Before you parse it, you should do these steps:

  • Read the executable file content;
  • Make this file’s content to a slice (&[u8])
  • Use Parser to parse the executable.

After this, you can do further operations through this parser by calling its functions.

§Building

Here we provided a tool Builder to help you do building process easily.

Before parsing, make sure you have enabled feature alloc, or you can’t find where Builder is.

Then you can do these steps:

  • Set up author name (32 bytes limit);
  • Set up program name (32 bytes limit);
  • Set up the executable type (UserApp/CoreDrv);
  • Append section content (Can push multiple sections);
  • Build the executable.

§Example Usage

§Parsing

use proka_exec::Parser;
use std::path::PathBuf;

let file = PathBuf::from("tests/testbin/sample.pke");
let content = std::fs::read(file).expect("Failed to read file");
let parser = Parser::init(&content).expect("Failed to parse PKE format");
 
// More API see below

§Building

use proka_exec::{Builder, header::ExecMode};
use std::path::PathBuf;
 
static EXAMPLE_CONTENT: &[u8] = b"Hello, World!";

let mut builder = Builder::new();
builder.set_author("example");
builder.set_name("appname");
builder.set_mode(ExecMode::UserApp);
builder.append(EXAMPLE_CONTENT, ".example.section", false, false, None);    // (data, name, is_loadable, is_execable, entry)
let content = builder.build().expect("Failed to build executable");
std::fs::write("example.pke", &content).expect("Failed to write file");

§LICENSE

This crate is under license GPL-v3, and you must follow its rules.

See LICENSE file for more details.

§MSRV

This crate’s MSRV is 1.85.0 stable.

Re-exports§

pub use utils::*;

Modules§

header
The header definitions.
sections
The definitions of section entry.
utils
Utilities to parse proka exec headers.

Structs§

Builder
The builder of the proka executable.
Parser
The parser of the proka executable.

Enums§

Error
The error type of parsing header.

Constants§

HEADER_SIZE
The header size.
SECTION_HDR_SIZE
The section header size.
SECTION_INDEX_SIZE
The section entry size

Type Aliases§

Result
Generic result type in this crate