Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 5fede76

Browse files
author
mattifestation
committed
Capstone module now incorporates framework 2.0RC1
* I also moved the contents of Get-CSDisassembly.ps1 into Capstone.psm1
1 parent 4f5faf6 commit 5fede76

10 files changed

+176
-127
lines changed

Capstone/Capstone.psd1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ModuleToProcess = 'Capstone.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '1.0.0.0'
7+
ModuleVersion = '2.0.0.0'
88

99
# ID used to uniquely identify this module
1010
GUID = 'bc335667-02fd-46c4-a3d9-0a5113c9c03b'
@@ -13,7 +13,7 @@ GUID = 'bc335667-02fd-46c4-a3d9-0a5113c9c03b'
1313
Author = 'Matthew Graeber'
1414

1515
# Copyright statement for this module
16-
Copyright = 'BSD 3-Clause'
16+
Copyright = 'see LICENSE.TXT'
1717

1818
# Description of the functionality provided by this module
1919
Description = 'Capstone Disassembly Framework Binding Module'
@@ -39,9 +39,10 @@ ModuleList = @(@{ModuleName = 'Capstone'; ModuleVersion = '1.0.0.0'; GUID = 'bc3
3939
# List of all files packaged with this module
4040
FileList = 'Capstone.psm1',
4141
'Capstone.psd1',
42-
'Get-CSDisassembly.ps1',
43-
'Usage.md',
42+
'Get-CSDisassembly.format.ps1xml',
43+
'LICENSE.TXT',
44+
'README',
4445
'lib/capstone.dll',
45-
'lib/libcapstone.dll'
46-
46+
'lib/x86/libcapstone.dll',
47+
'lib/x64/libcapstone.dll'
4748
}

Capstone/Capstone.psm1

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,168 @@
1-
Get-ChildItem (Join-Path $PSScriptRoot *.ps1) | % { . $_.FullName}
1+
#Requires -Modules Capstone
2+
3+
function Get-CSDisassembly
4+
{
5+
<#
6+
.SYNOPSIS
7+
8+
Disassembles a byte array using the Capstone Engine disassembly framework.
9+
10+
PowerSploit Function: Get-CSDisassembly
11+
Author: Matthew Graeber (@mattifestation)
12+
License: See LICENSE.TXT
13+
Required Dependencies: lib\capstone.dll, lib\[x86|x64]\libcapstone.dll
14+
Optional Dependencies: None
15+
16+
.DESCRIPTION
17+
18+
Get-CSDisassembly is compatible on 32 and 64-bit.
19+
20+
.PARAMETER Architecture
21+
22+
Specifies the architecture of the code to be disassembled.
23+
24+
.PARAMETER Mode
25+
26+
Specifies the mode in which to disassemble code. For example, to disassemble Amd64 code, architecture is set to 'X86' and Mode is set to 'MODE_64'.
27+
28+
.PARAMETER Code
29+
30+
A byte array consisting of the code to be disassembled.
31+
32+
.PARAMETER Offset
33+
34+
Specifies the starting address of the disassembly listing.
35+
36+
.PARAMETER Count
37+
38+
Specifies the maximum number of instructions to disassemble.
39+
40+
.PARAMETER Syntax
41+
42+
Specifies the syntax flavor to be used (INTEL vs. ATT).
43+
44+
.PARAMETER DetailOn
45+
46+
Specifies that detailed parsing should be performed - i.e. provide detailed information for each disassembled instruction.
47+
48+
.PARAMETER Verstion
49+
50+
Prints the running Capstone Framework version.
51+
52+
.EXAMPLE
53+
54+
$Bytes = [Byte[]] @( 0x8D, 0x4C, 0x32, 0x08, 0x01, 0xD8, 0x81, 0xC6, 0x34, 0x12, 0x00, 0x00 )
55+
Get-CSDisassembly -Architecture X86 -Mode Mode16 -Code $Bytes -Offset 0x1000
56+
57+
$Bytes = [Byte[]] @( 0x8D, 0x4C, 0x32, 0x08, 0x01, 0xD8, 0x81, 0xC6, 0x34, 0x12, 0x00, 0x00 )
58+
Get-CSDisassembly -Architecture X86 -Mode Mode32 -Code $Bytes
59+
60+
$Bytes = [Byte[]] @( 0x8D, 0x4C, 0x32, 0x08, 0x01, 0xD8, 0x81, 0xC6, 0x34, 0x12, 0x00, 0x00 )
61+
Get-CSDisassembly -Architecture X86 -Mode Mode32 -Code $Bytes -Syntax ATT
62+
63+
$Bytes = [Byte[]] @( 0x55, 0x48, 0x8b, 0x05, 0xb8, 0x13, 0x00, 0x00 )
64+
Get-CSDisassembly -Architecture X86 -Mode Mode64 -Code $Bytes -DetailOn
65+
66+
$Bytes = [Byte[]] @( 0xED, 0xFF, 0xFF, 0xEB, 0x04, 0xe0, 0x2d, 0xe5, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x83, 0x22, 0xe5, 0xf1, 0x02, 0x03, 0x0e, 0x00, 0x00, 0xa0, 0xe3, 0x02, 0x30, 0xc1, 0xe7, 0x00, 0x00, 0x53, 0xe3 )
67+
Get-CSDisassembly -Architecture Arm -Mode Arm -Code $Bytes
68+
69+
$Bytes = [Byte[]] @( 0x4f, 0xf0, 0x00, 0x01, 0xbd, 0xe8, 0x00, 0x88, 0xd1, 0xe8, 0x00, 0xf0 )
70+
Get-CSDisassembly -Architecture Arm -Mode Thumb -Code $Bytes
71+
72+
$Bytes = [Byte[]] @( 0x10, 0xf1, 0x10, 0xe7, 0x11, 0xf2, 0x31, 0xe7, 0xdc, 0xa1, 0x2e, 0xf3, 0xe8, 0x4e, 0x62, 0xf3 )
73+
Get-CSDisassembly -Architecture Arm -Mode Arm -Code $Bytes
74+
75+
$Bytes = [Byte[]] @( 0x70, 0x47, 0xeb, 0x46, 0x83, 0xb0, 0xc9, 0x68 )
76+
Get-CSDisassembly -Architecture Arm -Mode Thumb -Code $Bytes -DetailOn
77+
78+
$Bytes = [Byte[]] @( 0x21, 0x7c, 0x02, 0x9b, 0x21, 0x7c, 0x00, 0x53, 0x00, 0x40, 0x21, 0x4b, 0xe1, 0x0b, 0x40, 0xb9 )
79+
Get-CSDisassembly -Architecture Arm64 -Mode Arm -Code $Bytes
80+
81+
$Bytes = [Byte[]] @( 0x0C, 0x10, 0x00, 0x97, 0x00, 0x00, 0x00, 0x00, 0x24, 0x02, 0x00, 0x0c, 0x8f, 0xa2, 0x00, 0x00, 0x34, 0x21, 0x34, 0x56 )
82+
Get-CSDisassembly -Architecture Mips -Mode 'Mode32, BigEndian' -Code $Bytes
83+
84+
$Bytes = [Byte[]] @( 0x56, 0x34, 0x21, 0x34, 0xc2, 0x17, 0x01, 0x00 )
85+
Get-CSDisassembly -Architecture Mips -Mode 'Mode64, LittleEndian' -Code $Bytes
86+
87+
$Bytes = [Byte[]] @( 0x80, 0x20, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x10, 0x43, 0x23, 0x0e, 0xd0, 0x44, 0x00, 0x80, 0x4c, 0x43, 0x22, 0x02, 0x2d, 0x03, 0x00, 0x80, 0x7c, 0x43, 0x20, 0x14, 0x7c, 0x43, 0x20, 0x93, 0x4f, 0x20, 0x00, 0x21, 0x4c, 0xc8, 0x00, 0x21 )
88+
Get-CSDisassembly -Architecture PPC -Mode BigEndian -Code $Bytes
89+
90+
.INPUTS
91+
92+
None
93+
94+
You cannot pipe objects to Get-CSDisassembly.
95+
96+
.OUTPUTS
97+
98+
Capstone.Instruction[]
99+
100+
Get-CSDisassembly returns an array of Instruction objects.
101+
#>
102+
103+
[OutputType([Capstone.Instruction])]
104+
[CmdletBinding(DefaultParameterSetName = 'Disassemble')]
105+
Param (
106+
[Parameter(Mandatory, ParameterSetName = 'Disassemble')]
107+
[Capstone.Architecture]
108+
$Architecture,
109+
110+
[Parameter(Mandatory, ParameterSetName = 'Disassemble')]
111+
[Capstone.Mode]
112+
$Mode,
113+
114+
[Parameter(Mandatory, ParameterSetName = 'Disassemble')]
115+
[ValidateNotNullOrEmpty()]
116+
[Byte[]]
117+
$Code,
118+
119+
[Parameter( ParameterSetName = 'Disassemble' )]
120+
[UInt64]
121+
$Offset = 0,
122+
123+
[Parameter( ParameterSetName = 'Disassemble' )]
124+
[UInt32]
125+
$Count = 0,
126+
127+
[Parameter( ParameterSetName = 'Disassemble' )]
128+
[ValidateSet('Intel', 'ATT')]
129+
[String]
130+
$Syntax,
131+
132+
[Parameter( ParameterSetName = 'Disassemble' )]
133+
[Switch]
134+
$DetailOn,
135+
136+
[Parameter( ParameterSetName = 'Version' )]
137+
[Switch]
138+
$Version
139+
)
140+
141+
if ($PsCmdlet.ParameterSetName -eq 'Version')
142+
{
143+
$Disassembly = New-Object Capstone.Capstone([Capstone.Architecture]::X86, [Capstone.Mode]::Mode16)
144+
$Disassembly.Version
145+
146+
return
147+
}
148+
149+
$Disassembly = New-Object Capstone.Capstone($Architecture, $Mode)
150+
151+
if ($Syntax)
152+
{
153+
switch ($Syntax)
154+
{
155+
'Intel' { $SyntaxMode = [Capstone.OptionValue]::SyntaxIntel }
156+
'ATT' { $SyntaxMode = [Capstone.OptionValue]::SyntaxATT }
157+
}
158+
159+
$Disassembly.SetSyntax($SyntaxMode)
160+
}
161+
162+
if ($DetailOn)
163+
{
164+
$Disassembly.SetDetail($True)
165+
}
166+
167+
$Disassembly.Disassemble($Code, $Offset, $Count)
168+
}

Capstone/Get-CSDisassembly.ps1

Lines changed: 0 additions & 119 deletions
This file was deleted.

Capstone/lib/capstone.dll

10 KB
Binary file not shown.

Capstone/lib/place_capstone.dll_here

Whitespace-only changes.

Capstone/lib/x64/libcapstone.dll

-2.57 MB
Binary file not shown.

Capstone/lib/x64/place_64-bit_libcapstone.dll_here

Whitespace-only changes.

Capstone/lib/x86/libcapstone.dll

-2.58 MB
Binary file not shown.

Capstone/lib/x86/place_32-bit_libcapstone.dll_here

Whitespace-only changes.

ReverseEngineering/Get-ILDisassembly.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-335.pdf
198198

199199
$Instruction = @{
200200
Position = $InstructionPostion
201-
Instruction = $Op.Name
201+
Instruction = $Op
202202
Operand = $Operand
203203
MetadataToken = $OpInt
204204
}

0 commit comments

Comments
 (0)