# velocidex/go-pe architecture

> Architecture diagram of the GitHub repository velocidex/go-pe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/velocidex/go-pe
- Repository: https://github.com/velocidex/go-pe

## Overview

Project Type: This is a specialized open-source tool for parsing PE files (Windows executable format), focusing on extracting specific metadata and information from PE files.

##### Core Parser Components
- Reader Module (reader.go)
- Headers Parser (headers.go)
- Resource Parser (resources.go)
- GUID Parser (guid.go)
- Time Parser (time.go)

##### Specialized Parsers
- Authenticode Parser (authenticode.go, pkcs7.go)
- Imports Parser (imports.go)
- Exports Parser (exports.go)
- RVA Handler (rva.go)

##### Command-Line Interface
- Authenticode Command
- Cat Command
- PEInfo Command
- Messages Command

##### Support Systems
- Auxiliary components:
- Constants Manager
- Debug Utilities
- Options Handler
- Utility Functions

##### Use a layered architecture approach
- Top Layer: CLI Interface
- Middle Layer: Core Parser Components
- Bottom Layer: Support Systems and Utilities

##### Component Relationships
- Blue: Core parsing components
- Green: CLI components
- Yellow: Support utilities
- Gray: External interfaces

##### Processing Flow
- Flow from PE file input through the parsing pipeline:
1. File Input
2. Reader Processing
3. Specialized Parser Processing
4. Information Extraction
5. Output Generation

Specific Design Elements:

##### Input/Output
- Left side: Show PE file input
- Right side: Show extracted information output (RSDS GUID, PDB files, Version Information)

##### Parser Pipeline
- Decision points for different types of parsing (authenticode, imports, etc.)

##### Component Interfaces
- Clear boundaries between components
- Public interfaces and internal connections

Additional Considerations:

##### Testing Infrastructure
- A note about test fixtures and test data
- Relationship to the main components

##### Build and CI/CD
- A small section showing GitHub Actions workflow
- Makefile relationships

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        PE[PE File Input]
    end

    subgraph "CLI Layer"
        CLI[CLI Interface]
        AC["Authenticode Command"]:::cli
        CC["Cat Command"]:::cli
        PI["PEInfo Command"]:::cli
        MC["Messages Command"]:::cli
    end

    subgraph "Core Parser Layer"
        PC[PE Parser Core]
        RM["Reader Module"]:::core
        HP["Headers Parser"]:::core
        RP["Resource Parser"]:::core
        GP["GUID Parser"]:::core
        TP["Time Parser"]:::core
    end

    subgraph "Specialized Parsers"
        ACP["Authenticode Parser"]:::parser
        IP["Imports Parser"]:::parser
        EP["Exports Parser"]:::parser
        RVA["RVA Handler"]:::parser
    end

    subgraph "Support Systems"
        CM["Constants Manager"]:::support
        DU["Debug Utilities"]:::support
        OH["Options Handler"]:::support
        UF["Utility Functions"]:::support
    end

    subgraph "Testing & CI/CD"
        TF["Test Fixtures"]:::test
        TD["Test Data"]:::test
        PT["Parser Tests"]:::test
        GH["GitHub Actions"]:::cicd
    end

    subgraph Output
        EI[Extracted Information]
    end

    %% Relationships
    PE --> CLI
    CLI --> |Commands| AC
    CLI --> |Commands| CC
    CLI --> |Commands| PI
    CLI --> |Commands| MC

    AC & CC & PI & MC --> PC
    PC --> RM
    PC --> HP
    PC --> RP
    PC --> GP
    PC --> TP

    PC --> ACP
    PC --> IP
    PC --> EP
    PC --> RVA

    ACP & IP & EP & RVA --> CM
    ACP & IP & EP & RVA --> DU
    ACP & IP & EP & RVA --> OH
    ACP & IP & EP & RVA --> UF

    PC --> EI

    %% Testing Relationships
    TF --> PT
    TD --> PT
    PT --> PC
    GH --> |CI/CD| PC

    %% Styles
    classDef core fill:#2374ab
    classDef parser fill:#048ba8
    classDef cli fill:#16db93
    classDef support fill:#efea5a
    classDef test fill:#f29e4c
    classDef cicd fill:#c73e1d

    %% Click Events
    click RM "https://github.com/Velocidex/go-pe/blob/master/reader.go"
    click HP "https://github.com/Velocidex/go-pe/blob/master/headers.go"
    click RP "https://github.com/Velocidex/go-pe/blob/master/resources.go"
    click GP "https://github.com/Velocidex/go-pe/blob/master/guid.go"
    click TP "https://github.com/Velocidex/go-pe/blob/master/time.go"
    click ACP "https://github.com/Velocidex/go-pe/blob/master/authenticode.go"
    click IP "https://github.com/Velocidex/go-pe/blob/master/imports.go"
    click EP "https://github.com/Velocidex/go-pe/blob/master/exports.go"
    click RVA "https://github.com/Velocidex/go-pe/blob/master/rva.go"
    click AC "https://github.com/Velocidex/go-pe/blob/master/cmd/authenticode.go"
    click CC "https://github.com/Velocidex/go-pe/blob/master/cmd/cat.go"
    click PI "https://github.com/Velocidex/go-pe/blob/master/cmd/peinfo.go"
    click MC "https://github.com/Velocidex/go-pe/blob/master/cmd/messages.go"
    click CM "https://github.com/Velocidex/go-pe/blob/master/constants.go"
    click DU "https://github.com/Velocidex/go-pe/blob/master/debug.go"
    click OH "https://github.com/Velocidex/go-pe/blob/master/options.go"
    click UF "https://github.com/Velocidex/go-pe/blob/master/utils.go"
    click TF "https://github.com/Velocidex/go-pe/tree/master/fixtures/"
    click TD "https://github.com/Velocidex/go-pe/tree/master/testdata/"
    click PT "https://github.com/Velocidex/go-pe/blob/master/parser_test.go"
    click GH "https://github.com/Velocidex/go-pe/blob/master/.github/workflows/go.yml"
```
