DEV Community

Cover image for pedumper: A new tool for dumping PE files
Chihiro Hasegawa
Chihiro Hasegawa

Posted on

pedumper: A new tool for dumping PE files

Summary

I have published a new tool for dumping PE files in the target memory on Windows🎉
The tool name is pedumper. Here is a link for the tool.
https://github.com/owlinux1000/pedumper

Installation

You can easily install pedumper by pip.

pip install pedumper
Enter fullscreen mode Exit fullscreen mode

How to use

pedumper is a very simple interface as follows. You have to pass an argument which is a PID of the target process.

how to use

If the tool can find a valid PE file, the file is saved on the disk. The filename is used by the memory address.

How to create pedumper?

When I create this tool, I have to learn two things.

1. ctypes

ctypes is a standard library of python. To use this library, we can execute Win32 API on Python like this.

def read_process_memory(hProcess: int, offset: int, size: ctypes.c_size_t) -> bytes:
    buf = ctypes.create_string_buffer(size)
    ctypes.windll.kernel32.ReadProcessMemory(
        ctypes.cast(hProcess, ctypes.c_void_p),
        ctypes.cast(offset, ctypes.c_void_p),
        ctypes.cast(buf, ctypes.c_wchar_p),
        size,
        None,
    )
Enter fullscreen mode Exit fullscreen mode

2. Memory Basic Information of Windows

On Windows, a memory of the process is defined by MEMORY_BASIC_INFORMAION structure. Here is a definition from Microsoft Official document. I have learned some fileds of the structure through implementing pedumper.

typedef struct _MEMORY_BASIC_INFORMATION {
  PVOID  BaseAddress;
  PVOID  AllocationBase;
  DWORD  AllocationProtect;
  WORD   PartitionId;
  SIZE_T RegionSize;
  DWORD  State;
  DWORD  Protect;
  DWORD  Type;
} MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
Enter fullscreen mode Exit fullscreen mode

Conclusion

I introduced pedumper created by myself. If you are interested in the tool, please use it and tell me feedback😄

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay