dump windows PE files using ruby
…A pure ruby implementation of win32 PE binary files dumper.
Supported formats:
Can dump:
gem install pedump# pedump -h
Usage: pedump [options]
--version Print version information and exit
-v, --verbose Run verbosely
(can be used multiple times)
-q, --quiet Silent any warnings
(can be used multiple times)
-F, --force Try to dump by all means
(can cause exceptions & heavy wounds)
-f, --format FORMAT Output format: bin,c,dump,hex,inspect,json,table,yaml
(default: table)
--clr a shortcut for --clr_header, --clr_readytorun, --clr_metadata, --clr_streams, --clr_strings, --clr_tables
--clr-header clr_header
--clr-metadata clr_metadata
--clr-readytorun clr_readytorun
--clr-streams clr_streams
--clr-strings clr_strings
--clr-tables [TABLES] clr_tables
--data-directory data_directory
--dos-stub dos_stub
-E, --exports exports
--imphash imphash
-I, --imports imports
--mz mz
--ne ne
--packer packer
--pe pe
--resource-directory resource_directory
-R, --resources resources
--rich rich
-S, --sections sections
--security security
-s, --strings strings
--tail tail
--te te
--tls tls
-V, --version-info version_info
--tokens Show CLR tokens
--deep packer deep scan, significantly slower
-P, --packer-only packer/compiler detect only,
mimics 'file' command output
-r, --recursive recurse dirs in packer detect
--all Dump all but resource-directory (default)
--extract ID Extract a resource/section/data_dir
ID: datadir:EXPORT - datadir by type
ID: resource:0x98478 - resource by offset
ID: resource:ICON/#1 - resource by type & name
ID: section:.text - section by name
ID: section:rva/0x1000 - section by RVA
ID: section:raw/0x400 - section by RAW_PTR
ID: tail - file tail
ID: tail:c00 - file tail + 0xc00 offset
--va2file VA Convert VA to file offset
--file2va OFFSET Convert file offset to VA
--rva2file RVA Convert RVA to file offset
--file2rva OFFSET Convert file offset to RVA
--set-os-version VER Patch OS version in PE header
--set-dll-char X Patch IMAGE_OPTIONAL_HEADER32.DllCharacteristics
-W, --web Uploads files to a https://pedump.me
for a nice HTML tables with image previews,
candies & stuff
-C, --console opens IRB console with specified file loaded# pedump --mz calc.exe
=== MZ Header ===
signature: "MZ"
bytes_in_last_block: 144 90
blocks_in_file: 3
num_relocs: 0
header_paragraphs: 4
min_extra_paragraphs: 0
max_extra_paragraphs: 65535 ffff
ss: 0
sp: 184 b8
checksum: 0
ip: 0
cs: 0
reloc_table_offset: 64 40
overlay_number: 0
reserved0: 0
oem_id: 0
oem_info: 0
reserved2: 0
reserved3: 0
reserved4: 0
reserved5: 0
reserved6: 0
lfanew: 232 e8# pedump --dos-stub calc.exe
=== DOS STUB ===
00000000: 0e 1f ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68 |.... ...!..L.!Th|
00000010: 69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f |is program canno|
00000020: 74 20 62 65 20 72 75 6e 20 69 6e 20 44 4f 53 20 |t be run in DOS |
00000030: 6d 6f 64 65 2e 0d 0d 0a 24 00 00 00 00 00 00 00 |mode....$ |# pedump --rich calc.exe
=== RICH Header ===
ID VER COUNT DESCRIPTION
95 521e 9 [ASM] VS2008 build 21022
1 0 367 [---] Unmarked objects
93 521e 29 [IMP] VS2008 build 21022
84 521e 129 [C++] VS2008 build 21022
83 521e 25 [ C ] VS2008 build 21022
94 521e 1 [RES] VS2008 build 21022
91 521e 1 [LNK] VS2008 build 21022# pedump --pe calc.exe
=== PE Header ===
signature: "PE\x00\x00"
# IMAGE_FILE_HEADER:
Machine: 332 14c x86
NumberOfSections: 4
TimeDateStamp: "2008-09-14 07:28:52"
PointerToSymbolTable: 0
NumberOfSymbols: 0
SizeOfOptionalHeader: 224 e0
Characteristics: 258 102 EXECUTABLE_IMAGE, 32BIT_MACHINE
# IMAGE_OPTIONAL_HEADER32:
Magic: 267 10b 32-bit executable
LinkerVersion: 9.0
SizeOfCode: 305664 4aa00
SizeOfInitializedData: 340480 53200
SizeOfUninitializedData: 0
AddressOfEntryPoint: 230155 3830b
BaseOfCode: 4096 1000
BaseOfData: 311296 4c000
ImageBase: 16777216 1000000
SectionAlignment: 4096 1000
FileAlignment: 512 200
OperatingSystemVersion: 5.1
ImageVersion: 5.256
SubsystemVersion: 5.1
Reserved1: 0
SizeOfImage: 659456 a1000
SizeOfHeaders: 1024 400
CheckSum: 690555 a897b
Subsystem: 2 WINDOWS_GUI
DllCharacteristics: 33088 8140 DYNAMIC_BASE, NX_COMPAT, TERMINAL_SERVER_AWARE
SizeOfStackReserve: 262144 40000
SizeOfStackCommit: 8192 2000
SizeOfHeapReserve: 1048576 100000
SizeOfHeapCommit: 4096 1000
LoaderFlags: 0
NumberOfRvaAndSizes: 16 10# pedump --rva2file 0x4c000 calc.exe
rva2file(0x4c000) = 0x4ae00 (306688)
# pedump --file2rva 0x4ae00 calc.exe
file2rva(0x4ae00) = 0x4c000 (311296)
# pedump --va2file 0x104c000 calc.exe
va2file(0x104c000) = 0x4ae00 (306688)
# pedump --file2va 0x4ae00 calc.exe
file2va(0x4ae00) = 0x104c000 (17088512)
# pedump --file2va 0x4ae00 calc.exe --format hex
104c000# pedump --data-directory calc.exe
=== DATA DIRECTORY ===
EXPORT rva:0x 0 size:0x 0
IMPORT rva:0x 49c1c size:0x 12c
RESOURCE rva:0x 51000 size:0x 4ab07
EXCEPTION rva:0x 0 size:0x 0
SECURITY rva:0x 0 size:0x 0
BASERELOC rva:0x 9c000 size:0x 3588
DEBUG rva:0x 1610 size:0x 1c
ARCHITECTURE rva:0x 0 size:0x 0
GLOBALPTR rva:0x 0 size:0x 0
TLS rva:0x 0 size:0x 0
LOAD_CONFIG rva:0x 3d78 size:0x 40
Bound_IAT rva:0x 280 size:0x 12c
IAT rva:0x 1000 size:0x 594
Delay_IAT rva:0x 49bac size:0x 40
CLR_Header rva:0x 0 size:0x 0
rva:0x 0 size:0x 0# pedump --sections calc.exe
=== SECTIONS ===
NAME RVA VSZ RAW_SZ RAW_PTR nREL REL_PTR nLINE LINE_PTR FLAGS
.text 1000 4a99a 4aa00 400 0 0 0 0 60000020 R-X CODE
.data 4c000 431c 3000 4ae00 0 0 0 0 c0000040 RW- IDATA
.rsrc 51000 4ab07 4ac00 4de00 0 0 0 0 40000040 R-- IDATA
.reloc 9c000 41f6 4200 98a00 0 0 0 0 42000040 R-- IDATA DISCARDABLE# pedump --resources calc.exe
=== RESOURCES ===
FILE_OFFSET CP LANG SIZE TYPE NAME
0x4ec84 0 0x409 7465 IMAGE #157
0x509b0 0 0x409 4086 IMAGE #165
0x519a8 0 0x409 4234 IMAGE #170
0x52a34 0 0x409 4625 IMAGE #175
0x53c48 0 0x409 4873 IMAGE #180
0x54f54 0 0x409 3048 IMAGE #204
0x55b3c 0 0x409 3052 IMAGE #208
0x56728 0 0x409 32No open issues yet, or sync has not completed.