param([int]$TargetPid = 0, [string]$OutDir = "") $t = "C:\Users\nicot\AppData\Local\Temp\opencode" if (-not $TargetPid) { $TargetPid = [int](Get-Content "$t\mcgame\pid.txt") } if (-not $OutDir) { $OutDir = "$t\dump" } "dumping unpacked regions of pid $TargetPid to $OutDir..." Add-Type @' using System; using System.Runtime.InteropServices; public class Mem2 { [DllImport("kernel32.dll")] public static extern IntPtr OpenProcess(uint a, bool b, int pid); [DllImport("kernel32.dll")] public static extern bool ReadProcessMemory(IntPtr h, IntPtr addr, byte[] buf, IntPtr size, out IntPtr read); [DllImport("kernel32.dll")] public static extern IntPtr CloseHandle(IntPtr h); [StructLayout(LayoutKind.Explicit)] public struct MBI { [FieldOffset(0)] public IntPtr BaseAddress; [FieldOffset(8)] public IntPtr AllocationBase; [FieldOffset(16)] public uint AllocationProtect; [FieldOffset(24)] public IntPtr RegionSize; [FieldOffset(32)] public uint State; [FieldOffset(36)] public uint Protect; [FieldOffset(40)] public uint Type; } [DllImport("kernel32.dll")] public static extern IntPtr VirtualQueryEx(IntPtr h, IntPtr addr, ref MBI mbi, IntPtr len); } '@ $h = [Mem2]::OpenProcess(0x0410, $false, $TargetPid) if ($h -eq [IntPtr]::Zero) { "OpenProcess FAILED"; exit 1 } New-Item -ItemType Directory -Force $OutDir | Out-Null $addr = [IntPtr]::Zero $total = 0; $files = 0 while ($true) { $mbi = New-Object Mem2+MBI $r = [Mem2]::VirtualQueryEx($h, $addr, [ref]$mbi, [IntPtr]::new([System.Runtime.InteropServices.Marshal]::SizeOf([type][Mem2+MBI]))) if ($r -eq [IntPtr]::Zero) { break } $base = [long]$mbi.BaseAddress $size = [long]$mbi.RegionSize if ($size -le 0) { break } $prot = $mbi.Protect -band 0xFF $interesting = ($mbi.State -eq 0x1000) -and ($mbi.Type -eq 0x20000) -and ($prot -eq 0x02 -or $prot -eq 0x04 -or $prot -eq 0x20 -or $prot -eq 0x40) -and ($base -ge 0x1000000) -and ($base -lt 0x100000000) -and ($size -ge 4096) if ($interesting) { $cap = [Math]::Min($size, 64MB) $buf = New-Object byte[] $cap $read = [IntPtr]::Zero if ([Mem2]::ReadProcessMemory($h, $mbi.BaseAddress, $buf, [IntPtr]$cap, [ref]$read) -and [long]$read -gt 4096) { $p = switch ($prot) { 0x02 { "r" } 0x04 { "rw" } 0x20 { "rx" } 0x40 { "rwx" } default { "p$prot" } } $fn = "{0}\{1:X12}_{2}_{3}.bin" -f $OutDir, $base, $p, [int]$read [System.IO.File]::WriteAllBytes($fn, $buf[0..([int]$read-1)]) "saved {0} ({1} bytes)" -f $fn, [int]$read $total += [int]$read; $files++ } } $addr = [IntPtr]($base + $size) if ($addr -eq [IntPtr]::Zero) { break } } [Mem2]::CloseHandle($h) | Out-Null "done: $files regions, $([Math]::Round($total/1MB)) MB"