https://github.com/vweevers/pe-coff
Parse the COFF file header of a PE.
https://github.com/vweevers/pe-coff
Last synced: 4 months ago
JSON representation
Parse the COFF file header of a PE.
- Host: GitHub
- URL: https://github.com/vweevers/pe-coff
- Owner: vweevers
- License: mit
- Created: 2016-12-19T22:14:53.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-12-11T17:48:56.000Z (over 5 years ago)
- Last Synced: 2025-09-29T14:18:46.247Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# pe-coff
**Parse the COFF file header of a [PE](https://en.wikipedia.org/wiki/Portable_Executable). As specified by [Microsoft PE and COFF Specification 9.3](https://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-d599bac8184a/pecoff_v83.docx) [doc], section 3.3.**
[](https://www.npmjs.org/package/pe-coff) [](https://www.npmjs.org/package/pe-coff) [](http://travis-ci.org/vweevers/pe-coff) [](https://ci.appveyor.com/project/vweevers/pe-coff) [](https://david-dm.org/vweevers/pe-coff)
## example
```js
const pecoff = require('pe-coff')
pecoff('file.exe', function (err, header, location) {
console.log(header)
console.log(location)
})
```
The `header` has these properties:
```json
{
"machineType": "i386",
"machineDescription": "Intel 386 or later processors and compatible processors",
"numberOfSections": 3,
"timeDateStamp": 1480757919,
"pointerToSymbolTable": 0,
"numberOfSymbols": 0,
"sizeOfOptionalHeader": 224,
"characteristics": 258
}
```
And `location` contains the offset and length of the header in bytes:
```json
{
"offset": 132,
"length": 20
}
```
## `pecoff(mixed, [limit], callback)`
Where `mixed` is either a filename or a file descriptor. Use `limit` (the number of bytes to read) if you only need the first (few) fields:
```js
pecoff('file.exe', pecoff.NUMBER_OF_SECTIONS, function (err, header) {
// Will have machineType, machineDescription, numberOfSections
console.log(header)
})
pecoff('file.exe', pecoff.MACHINE_TYPE, function (err, header) {
// Will have machineType, machineDescription
console.log(header)
})
```
## related
- [pe-signature](https://github.com/vweevers/pe-signature)
- [pe-signature-offset](https://github.com/vweevers/pe-signature-offset)
- [pe-machine-type-descriptor](https://github.com/vweevers/pe-machine-type-descriptor])
## install
With [npm](https://npmjs.org) do:
```
npm install pe-coff
```
## license
[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers