https://github.com/jet2jet/pe-library-js
Provides parsing and generating Portable Executable binaries
https://github.com/jet2jet/pe-library-js
javascript javascript-library nodejs pe pe-format portable-executable
Last synced: 5 days ago
JSON representation
Provides parsing and generating Portable Executable binaries
- Host: GitHub
- URL: https://github.com/jet2jet/pe-library-js
- Owner: jet2jet
- License: mit
- Created: 2021-12-10T11:28:34.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-12-22T10:46:10.000Z (about 1 month ago)
- Last Synced: 2025-12-23T21:50:45.720Z (about 1 month ago)
- Topics: javascript, javascript-library, nodejs, pe, pe-format, portable-executable
- Language: TypeScript
- Homepage:
- Size: 376 KB
- Stars: 26
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/pe-library)
[](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 Node.js v20.19.0 or later, or use `pe-library/cjs` to use from CommonJS file.
For CommonJS with Node.js v20.19.0 or later:
```js
const PE = require('pe-library');
...
```
For CommonJS with using `pe-library/cjs`:
```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`