Skip to content
techlinnPublic

About

Windows PE memory dumper and rebuilder for loaded and manually mapped EXEs and DLLs

Resources

Stars

134 stars

Watchers

1 watching

Forks

Repository files navigation

MemPE banner

Pull every EXE and DLL out of a running Windows process and get back PE files your tools can actually open.

CI Latest release Downloads Windows x86 and x64 MIT license

Download · Usage · Packers · Limitations


Packers can hide a program on disk all they want. The moment it runs, the real thing has to be sitting in memory, and that's where mempe grabs it.

Give it a packed file and it starts it, lets the packer do its work and stops at the original entry point. Or point it at a process that's already running. Either way it takes every module in the process, lays each one back out the way a file on disk expects, rebuilds the imports, and writes PE files that IDA, Ghidra or your favorite debugger will open without complaining. If it knows the packer, it goes a step further and hands you the original program back.

Here it is on a UPX-packed crackme:

> mempe.exe upx_crackme.exe
mempe 0.9.0
[*] stopped at oep 0x00002700 (50 ms)
[*] upx_crackme.exe pid 29380 x64
[+] detected UPX 5.30
[+] restored headers, oep, imports, relocations, resources, debug dir
[+] dumped to .\mempe\upx_crackme.exe
[+] done

UPX0 and UPX1 are gone. What comes out is the program as it was compiled, with its real entry point and import table. If something can't be recovered, mempe says so instead of quietly handing you a broken dump, and -d shows everything it found and did as key=value lines.

What you get

  • Every EXE and DLL in an x86 or x64 process, rebuilt from its in-memory layout into a normal PE file
  • Imports put back together, even when the packer trashed the import table or swapped every call for a stub
  • PEs that were mapped by hand or stashed in random memory, the kind the module list never shows you
  • Packers undone when mempe knows them (see the table)
  • A report that tells you what it couldn't recover, so a broken dump never passes itself off as a good one

How it works

flowchart TB
    file(["Packed file"]) --> launch["Start it, stop at<br/>the original entry point"]
    process(["Running process"]) --> capture
    launch --> capture["Snapshot memory and<br/>find every PE in it"]
    capture --> known{"Known packer?"}
    known -- yes --> module["Packer module puts<br/>the original back"]
    known -- no --> repair["Headers repaired<br/>from memory evidence"]
    module --> rebuild["Rebuild layout, imports<br/>and directories"]
    repair --> rebuild
    rebuild --> output(["PE files + report"])

    classDef endpoint fill:#2f81f71a,stroke:#2f81f7,stroke-width:2px
    classDef step fill:#8b949e1a,stroke:#8b949e,stroke-width:1px
    classDef decision fill:#d299221a,stroke:#d29922,stroke-width:2px
    classDef packer fill:#3fb9501a,stroke:#3fb950,stroke-width:2px
    class file,process,output endpoint
    class launch,capture,repair,rebuild step
    class known decision
    class module packer
    linkStyle default stroke:#8b949e,stroke-width:2px
Loading

When mempe starts a file, it runs it under a debugger that hides itself from the usual anti-debug checks, takes execute rights away from the program's code, and stops on the first instruction that runs there. VMProtect asks the kernel directly whether it's being debugged, so for those files mempe puts a small exception handler in the process instead.

From there it snapshots the process, finds every module plus any PE hiding in non-image memory, and checks each one against its packer modules. A packer it knows gets undone properly, with its own decompressors and an x86/x64 emulator for the stubs that hide imports. Anything else is repaired from what the memory shows. Either way, the image is rebuilt into file layout, its imports are recovered, and you get a PE file plus a report.

Supported packers

Name Status Versions
UPX Supported Every release from 3.91 to 5.3.0
ASPack Supported 1.07b, 2.11, 2.12, 2.2, 2.24, 2.28, 2.29, 2.43
MPRESS Supported 1.05, 1.27, 2.05, 2.19
PECompact Supported 2.3, 2.67 and 3.11, plus five other 2.x builds from 2005 and 2006
FSG Supported 1.0, 1.1, 1.2, 1.3, 1.31, 1.33, 2.0 and modified stubs
MEW Supported 5, 10, 11 SE 1.2 and modified stubs
Themida / WinLicense Supported 3.1.8 and 3.2.4, x86 and x64
VMProtect Supported 3.9.4, 3.9.6 and 3.10.4, x86 and x64
Code Virtualizer Supported 3.1.4 and 4.0.1, x86 and x64
Anything else Generic dump Any

Anything missing? Open an issue and I'll add it.

Usage

Grab mempe-windows-x86_64.zip from the latest release. It's one exe with nothing to install, and it handles 32-bit and 64-bit targets alike.

Start a packed file and dump it at its entry point (DLLs work too):

mempe.exe target.exe

Dump a running process by PID (hex works too, like 0x1078):

mempe.exe -p 4216

Or have mempe wait for a program to launch and grab it once it has settled:

mempe.exe -w target.exe
Option What it does
-e, --entry-point <rva> You already found the OEP? Give its RVA in hex and mempe uses that
--only <name or base> Only write the images you care about. Everything is still captured, so imports resolve the same
--raw-regions Also save executable memory with no PE in it, like shellcode
-o, --output <folder> Write somewhere other than the mempe folder
-d, --debug Print what was detected and done as key=value lines
--timeout <seconds> How long a started file gets to reach its entry point (60 by default)
-h, --help Shows the help

Everything lands in a mempe folder in the current directory.

A dump keeps the data exactly as it was while the program ran. It is made to be read in a disassembler, not to be started again.

To build it yourself, you need Windows 10 or later and stable Rust:

cargo build --release

Caution

When mempe starts a file, the packer's code runs. With -p and -w the whole program has already run. If it's malware, do this in a VM.

Limitations

  • With -p and -w, let the program unpack itself before you dump it. Go too early and you'll get the packed bytes back, though mempe will warn you when a section looks like it was never decrypted.
  • Only x86 and x64 Windows PE files are supported.
  • mempe needs permission to read the target. Elevated targets need an elevated terminal, and protected processes can still say no.
  • Heavy API hashing or custom loaders can leave some imports unresolved. mempe counts those instead of dropping them quietly.
  • Dumps are for static analysis. They are not meant to run.

When to reach for something else

mempe is about getting clean files out of a process. If you want to sweep processes for injected or modified code, pe-sieve and hollows_hunter are built for exactly that. If you're already stepping through a target in x64dbg, its built-in Scylla is the quickest way to fix imports by hand at the point you stopped.

Exit codes

Code Meaning
0 Done
1 Invalid arguments, or you cancelled
2 Nothing was written
3 Something was written, but not everything; the last line says what's missing

Issues and contributing

Hit a bug, a dump that came out wrong, or a packer mempe should know about? Open an issue and I'll take a look. If you're reporting a bad dump, the output of -d helps a lot, and so does the packer the target was built with.

Pull requests are welcome too. A new packer is a good place to start, since each one lives in its own file or folder under src/packers/.

MIT licensed. See LICENSE.

About

Windows PE memory dumper and rebuilder for loaded and manually mapped EXEs and DLLs

Resources

Stars

134 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages