@@ -365,6 +365,57 @@ C:\PS> Subvert-PE -Path C:\Path\To\PE.exe -Write
365365
366366## Utility
367367
368+ ### Invoke-Keystone
369+
370+ Powershell wrapper for Keystone (using inline C#).
371+
372+ In effect the function directly parses the Keystone dll so it can support any
373+ features implemented by Keystone so long as function calls are prototyped in C#.
374+
375+ ```
376+ # Keystone DLL not in %tmp%
377+ PS C:\> Invoke-Keystone -Architecture X86 -Mode 32 -Code "nop;nop;div ebx"
378+
379+ [!] Keystone DLL not found in %tmp%, creating it..
380+ [+] 32-bit Keystone DLL: C:\Users\b33f\AppData\Local\Temp\keystone.dll
381+
382+ Bytes : 4
383+ Instructions : 3
384+ PSArray : {0x90, 0x90, 0xF7, 0xF3}
385+ CArray : {\x90, \x90, \xF7, \xF3}
386+ RawArray : {90, 90, F7, F3}
387+
388+ # Support for multi-line code blocks
389+ PS C:\> $Code = @"
390+ >> sub esp, 200
391+ >> pop eax
392+ >> pop ecx
393+ >> ret
394+ >> "@
395+ PS C:\> Invoke-Keystone -Architecture X86 -Mode 32 -Code $Code
396+
397+ Bytes : 9
398+ Instructions : 4
399+ PSArray : {0x81, 0xEC, 0xC8, 0x00...}
400+ CArray : {\x81, \xEC, \xC8, \x00...}
401+ RawArray : {81, EC, C8, 00...}
402+
403+ # Invoke-Keystone emits objects
404+ PS C:\> $Code = @"
405+ >> sub esp, 200
406+ >> pop eax
407+ >> pop ecx
408+ >> ret
409+ >> "@
410+ PS C:\> $Object = Invoke-Keystone -Architecture X86 -Mode 32 -Code $Code
411+ PS C:\> $Object.RawArray -join ""
412+ 81ECC80000005859C3
413+ PS C:\> $Object.CArray -join ""
414+ \x81\xEC\xC8\x00\x00\x00\x58\x59\xC3
415+ PS C:\> "`$Shellcode = {" + $($Object.PSArray -join ", ") + "}"
416+ $Shellcode = {0x81, 0xEC, 0xC8, 0x00, 0x00, 0x00, 0x58, 0x59, 0xC3}
417+ ```
418+
368419### Invoke-Capstone
369420
370421Powershell wrapper for Capstone v3 (using inline C#). The only Capstone feature
0 commit comments