Java Card Binary Parser

CAP File Analysis & Decompilation Tool

A comprehensive parser for Java Card CAP (Converted Applet) files that interprets binary structures and converts them into human-readable format according to Java Card 3.0.5 specifications.

April 2020
Python Parser
CAP Format
Header
Directory
Class
Method
Constant Pool
Applet
Import
Export
Debug

Scroll to explore

What is CAP File Conversion?

Understanding the Java Card compilation and conversion process

Java Source to Class

Java Card applications written in Java are first compiled using the standard Java compiler, which generates .class files containing bytecode.

Class to CAP Conversion

The Java Card converter transforms .class files into CAP (Converted Applet) files along with .exp (export) files of imported packages.

Smart Card Deployment

CAP files are optimized binary packages ready for deployment on Java Card-enabled smart cards with limited memory and processing power.

Understanding Binary Formats

Export File (.exp)

Contains information about the public APIs of the entire package. Used by the Java Card converter to transform a Java package into a CAP file.

CAP File Structure

Contains comprehensive information about all package items (classes, methods, fields) represented by tokens. Consists of multiple components in big-endian byte order.

CAP File Components

Detailed breakdown of each component in a Java Card CAP file

Header Component

Required

Contains general information about the CAP file including the package AID (Application Identifier), major and minor version numbers, and compilation metadata.

Applet Component

Conditional

Contains an entry for each applet defined in the package with their AIDs. Not present if no applets are defined.

Directory Component

Required

Lists the size of each component defined in the CAP file, providing an index for component navigation.

Constant Pool Component

Required

Contains entries for each class, method, and field referenced by the Method Component. Each 4-byte entry contains item tokens resolved by the VM at runtime.

Class Component

Required

Describes all classes and interfaces defined in the package with information for instance creation, method/field access, and cast checking. References Import Component for external superclasses.

Method Component

Required

Contains bytecode information for all methods defined in the package, including exception handlers representing catch and finally blocks.

Static Field Component

Conditional

Contains information to create and initialize an image of all static fields defined in the package.

Import & Export Components

Required & Conditional

Import Component: Lists imported packages identified by AIDs. Export Component: Describes classes, static functions, and fields offered to other packages.

Reference Location Component

Required

Contains lists of offsets into the Method Component's info items, which are indices into the constant pool table.

Descriptor Component

Optional

Provides sufficient information to parse and verify all elements of the CAP file, ensuring structural integrity.

Debug Component

Optional

Contains metadata necessary for debugging a package on an instrumented Java Card VM. Not required for production execution.

The Parser Tool

Python-based CAP file analyzer conforming to Java Card 3.0.5 specifications

Parser Usage

My parser script interprets Java Card binaries and converts binary data into human-readable format for analysis.

CapParser.py [option] .cap [option] 'component name'/'all'

--help

Display help information and usage instructions

--capPath / -p

Specify valid path to the CAP file for analysis

--component / -c

Component name (e.g., 'header') or 'all' to get all component info

Important Note

All options are case sensitive. Refer to Java Card 3.0.5 Specification for detailed component structures.