# pe-library

> Node.js library for Portable Executable format

Latest version **2.0.1** (published 2025-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install pe-library
pnpm add pe-library
yarn add pe-library
bun add pe-library
```

## Health

**Score 70/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2025-11-03 |
| First published | 2021-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 138.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 28 |
| Author | jet |
| Maintainers | jet2jet |
| Keywords | javascript, library, pe, pe-executable, portable-executable, exe |

## Links

- npm: https://www.npmjs.com/package/pe-library
- Repository: https://github.com/jet2jet/pe-library-js
- Issues: https://github.com/jet2jet/pe-library-js/issues
- Funding: https://github.com/sponsors/jet2jet
- npm.io page: https://npm.io/package/pe-library

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.1 (latest) — 2025-11-03
- 2.0.0 — 2025-10-17
- 0.4.1 — 2024-08-10
- 1.0.1 — 2024-04-19
- 1.0.0 — 2023-02-23
- 0.4.0 — 2023-01-29
- 0.3.0 — 2022-05-06
- 0.2.1 — 2022-01-03
- 0.2.0 — 2022-01-03
- 0.1.3 — 2021-12-10
- 0.1.2 — 2021-12-10
- 0.1.1 — 2021-12-10
- 0.1.0 — 2021-12-10

## README

[![NPM version](https://badge.fury.io/js/pe-library.svg)](https://www.npmjs.com/package/pe-library)
[![Build Status](https://github.com/jet2jet/pe-library-js/actions/workflows/main-ci.yml/badge.svg)](https://github.com/jet2jet/pe-library-js)

# pe-library

pe-library provides parsing and generating Portable Executable (known as Windows Executables) binaries.

## Usage

```js
import * as PE from 'pe-library';
import * as fs from 'fs';

// load and parse data
let data = fs.readFileSync('MyApp.exe');
// (the Node.js Buffer instance can be specified directly to NtExecutable.from)
let exe = PE.NtExecutable.from(data);

// get section data
let exportSection = exe.getSectionByEntry(PE.Format.ImageDirectoryEntry.Export);
// read binary data stored in exportSection.data ...
// to write binary: use exe.setSectionByEntry

// write to buffer
let newBin = exe.generate();
fs.writeFileSync('MyApp_modified.exe', new Buffer(newBin));
```

### from CommonJS (using `require`)

> Starting from v1.0.0, CommonJS support is changed; you must use `pe-library/cjs` to use from CommonJS file.

```js
const { load } = require('pe-library/cjs');
const fs = require('fs');
load().then((PE) => {
  // load and parse data
  let data = fs.readFileSync('MyApp.exe');
  // (the Node.js Buffer instance can be specified directly to NtExecutable.from)
  let exe = PE.NtExecutable.from(data);

  // get section data
  let exportSection = exe.getSectionByEntry(
    PE.Format.ImageDirectoryEntry.Export
  );
  // read binary data stored in exportSection.data ...
  // to write binary: use exe.setSectionByEntry

  // write to buffer
  let newBin = exe.generate();
  fs.writeFileSync('MyApp_modified.exe', new Buffer(newBin));
});
```

#### for CommonJS-based TypeScript module

```ts
// you can use PE namespace for type-reference only
import { type PE, load } from 'pe-library/cjs';
load().then((pe: typeof PE) => {
  ...
});
```

## License

- All programs / source codes / binaries in this package, EXCEPT FOLLOWINGS, are licensed with [MIT License](./LICENSE).
- The followings are licensed with 0-BSD license:
  - [tools/dos-stub/dos-stub.asm](./tools/dos-stub/dos-stub.asm)
  - The bit code, generated from tools/dos-stub/dos-stub.asm, written in [src/main/util/generate.ts](./src/main/util/generate.ts) as `DOS_STUB_PROGRAM`

---
_Source: https://npm.io/package/pe-library · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
