forked from llccd/RDPWrapOffsetFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpe_image.py
More file actions
28 lines (21 loc) · 740 Bytes
/
pe_image.py
File metadata and controls
28 lines (21 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from __future__ import annotations
from dataclasses import dataclass
import pefile
@dataclass(frozen=True)
class MemoryImage:
pe: pefile.PE
image_base: int
image: bytes
is_64: bool
def load_memory_image(pe: pefile.PE) -> MemoryImage:
size = int(pe.OPTIONAL_HEADER.SizeOfImage)
img = bytearray(b"\x00" * size)
for sec in pe.sections:
va = int(sec.VirtualAddress)
raw = sec.get_data()
vsz = int(sec.Misc_VirtualSize)
copy_len = min(len(raw), vsz)
img[va:va + copy_len] = raw[:copy_len]
image_base = int(pe.OPTIONAL_HEADER.ImageBase)
is_64 = pe.OPTIONAL_HEADER.Magic == 0x20B
return MemoryImage(pe=pe, image_base=image_base, image=bytes(img), is_64=is_64)