-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* +vb6 bindings * vb6 bindings credits update
- Loading branch information
Showing
17 changed files
with
1,324 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
VERSION 1.0 CLASS | ||
BEGIN | ||
MultiUse = -1 'True | ||
Persistable = 0 'NotPersistable | ||
DataBindingBehavior = 0 'vbNone | ||
DataSourceBehavior = 0 'vbNone | ||
MTSTransactionMode = 0 'NotAnMTSObject | ||
END | ||
Attribute VB_Name = "CAsmResult" | ||
Attribute VB_GlobalNameSpace = False | ||
Attribute VB_Creatable = True | ||
Attribute VB_PredeclaredId = False | ||
Attribute VB_Exposed = False | ||
Option Explicit | ||
|
||
'Keystone Assembly Engine bindings for VB6 | ||
'Contributed by FireEye FLARE Team | ||
'Author: David Zimmer <david.zimmer@fireeye.com>, <dzzie@yahoo.com> | ||
'License: Apache | ||
'Copyright: FireEye 2017 | ||
|
||
'NOTE: the VB code was built and tested against the latest binary release: Keystone 0.9.1 | ||
' I will enabled the symbol resolver once it makes it into the stable release | ||
|
||
Public errMsg As String | ||
Public lastErr As ks_err | ||
Public size As Long | ||
Public count As Long | ||
Public source As String | ||
Public arch As ks_arch | ||
Public mode As ks_mode | ||
Public syntax As ks_opt_type | ||
|
||
Private b() As Byte | ||
|
||
Property Get hadErr() As Boolean | ||
If Len(errMsg) > 0 Or lastErr <> 0 Then hadErr = True | ||
End Property | ||
|
||
Property Get result() As Byte() | ||
result = b | ||
End Property | ||
|
||
Friend Property Let result(buf() As Byte) | ||
b = buf | ||
End Property | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
VERSION 5.00 | ||
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx" | ||
Begin VB.Form Form1 | ||
Caption = "Keystone Assembler Engine VB6 Bindings - Contributed by FireEye FLARE team" | ||
ClientHeight = 4680 | ||
ClientLeft = 60 | ||
ClientTop = 345 | ||
ClientWidth = 10860 | ||
LinkTopic = "Form1" | ||
ScaleHeight = 4680 | ||
ScaleWidth = 10860 | ||
StartUpPosition = 2 'CenterScreen | ||
Begin VB.CommandButton Command1 | ||
Caption = "Copy" | ||
Height = 375 | ||
Left = 4680 | ||
TabIndex = 1 | ||
Top = 4200 | ||
Width = 1695 | ||
End | ||
Begin MSComctlLib.ListView lv | ||
Height = 3975 | ||
Left = 120 | ||
TabIndex = 0 | ||
Top = 120 | ||
Width = 10695 | ||
_ExtentX = 18865 | ||
_ExtentY = 7011 | ||
View = 3 | ||
LabelEdit = 1 | ||
LabelWrap = -1 'True | ||
HideSelection = -1 'True | ||
FullRowSelect = -1 'True | ||
GridLines = -1 'True | ||
_Version = 393217 | ||
ForeColor = -2147483640 | ||
BackColor = -2147483643 | ||
BorderStyle = 1 | ||
Appearance = 1 | ||
NumItems = 3 | ||
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} | ||
Text = "arch" | ||
Object.Width = 5292 | ||
EndProperty | ||
BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} | ||
SubItemIndex = 1 | ||
Text = "asm" | ||
Object.Width = 5292 | ||
EndProperty | ||
BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} | ||
SubItemIndex = 2 | ||
Text = "bytes" | ||
Object.Width = 14111 | ||
EndProperty | ||
End | ||
End | ||
Attribute VB_Name = "Form1" | ||
Attribute VB_GlobalNameSpace = False | ||
Attribute VB_Creatable = False | ||
Attribute VB_PredeclaredId = True | ||
Attribute VB_Exposed = False | ||
Option Explicit | ||
|
||
'Keystone Assembly Engine bindings for VB6 | ||
'Contributed by FireEye FLARE Team | ||
'Author: David Zimmer <david.zimmer@fireeye.com>, <dzzie@yahoo.com> | ||
'License: Apache | ||
'Copyright: FireEye 2017 | ||
|
||
'NOTE: the VB code was built and tested against the latest binary release: Keystone 0.9.1 | ||
' I will enabled the symbol resolver once it makes it into the stable release | ||
|
||
Private Sub Form_Load() | ||
|
||
Const base As Long = 0 '&H1000 | ||
|
||
initDll | ||
If hLib <> 0 Then Me.Caption = Me.Caption & " - loaded KeyStone v" & version | ||
|
||
'MsgBox err2str(KS_ERR_ASM_SYMBOL_MISSING) | ||
|
||
' X86 | ||
'AddResult test_ks(KS_ARCH_X86, KS_MODE_32, "jmp 0x2000; nop; nop;", 0, base) | ||
AddResult test_ks(KS_ARCH_X86, KS_MODE_16, "add eax, ecx", 0, base) | ||
AddResult test_ks(KS_ARCH_X86, KS_MODE_32, "add eax, ecx", 0, base) | ||
AddResult test_ks(KS_ARCH_X86, KS_MODE_64, "add rax, rcx", 0, base) | ||
AddResult test_ks(KS_ARCH_X86, KS_MODE_32, "add %ecx, %eax", KS_OPT_SYNTAX_ATT, base) | ||
AddResult test_ks(KS_ARCH_X86, KS_MODE_64, "add %rcx, %rax", KS_OPT_SYNTAX_ATT, base) | ||
|
||
' ARM | ||
AddResult test_ks(KS_ARCH_ARM, KS_MODE_ARM, "sub r1, r2, r5", 0, base) | ||
AddResult test_ks(KS_ARCH_ARM, KS_MODE_ARM + KS_MODE_BIG_ENDIAN, "sub r1, r2, r5", 0, base) | ||
AddResult test_ks(KS_ARCH_ARM, KS_MODE_THUMB, "movs r4, #0xf0", 0, base) | ||
AddResult test_ks(KS_ARCH_ARM, KS_MODE_THUMB + KS_MODE_BIG_ENDIAN, "movs r4, #0xf0", 0, base) | ||
|
||
' ARM64 | ||
AddResult test_ks(KS_ARCH_ARM64, KS_MODE_LITTLE_ENDIAN, "ldr w1, [sp, #0x8]", 0, base) | ||
|
||
' Hexagon | ||
AddResult test_ks(KS_ARCH_HEXAGON, KS_MODE_BIG_ENDIAN, "v23.w=vavg(v11.w,v2.w):rnd", 0, base) | ||
|
||
' Mips | ||
AddResult test_ks(KS_ARCH_MIPS, KS_MODE_MIPS32, "and $9, $6, $7", 0) | ||
AddResult test_ks(KS_ARCH_MIPS, KS_MODE_MIPS32 + KS_MODE_BIG_ENDIAN, "and $9, $6, $7", 0, base) | ||
AddResult test_ks(KS_ARCH_MIPS, KS_MODE_MIPS64, "and $9, $6, $7", 0) | ||
AddResult test_ks(KS_ARCH_MIPS, KS_MODE_MIPS64 + KS_MODE_BIG_ENDIAN, "and $9, $6, $7", 0, base) | ||
|
||
' PowerPC | ||
AddResult test_ks(KS_ARCH_PPC, KS_MODE_PPC32 + KS_MODE_BIG_ENDIAN, "add 1, 2, 3", 0, base) | ||
AddResult test_ks(KS_ARCH_PPC, KS_MODE_PPC64, "add 1, 2, 3", 0) | ||
AddResult test_ks(KS_ARCH_PPC, KS_MODE_PPC64 + KS_MODE_BIG_ENDIAN, "add 1, 2, 3", 0, base) | ||
|
||
' Sparc | ||
AddResult test_ks(KS_ARCH_SPARC, KS_MODE_SPARC32 + KS_MODE_LITTLE_ENDIAN, "add %g1, %g2, %g3", 0, base) | ||
AddResult test_ks(KS_ARCH_SPARC, KS_MODE_SPARC32 + KS_MODE_BIG_ENDIAN, "add %g1, %g2, %g3", 0, base) | ||
|
||
' SystemZ | ||
AddResult test_ks(KS_ARCH_SYSTEMZ, KS_MODE_BIG_ENDIAN, "a %r0, 4095(%r15,%r1)", 0, base) | ||
|
||
' symbol resolver test (will enable once in stable release binaries not tested yet) | ||
'AddResult test_ks(KS_ARCH_X86, KS_MODE_32, "jmp _l1; nop", 0, , base, True) | ||
|
||
End Sub | ||
|
||
|
||
Public Function test_ks(arch As ks_arch, mode As ks_mode, assembly As String, Optional syntax As ks_opt_type = 0, Optional base As Long = 0, Optional withResolver As Boolean = False) As CAsmResult | ||
|
||
Dim r As New CAsmResult | ||
Dim buf As Long, size As Long, count As Long, b() As Byte | ||
Dim hKeystone As Long | ||
Dim address As Currency | ||
|
||
Set test_ks = r | ||
|
||
If hLib = 0 Then initDll r | ||
If hLib = 0 Then Exit Function | ||
|
||
r.arch = arch | ||
r.mode = mode | ||
r.syntax = syntax | ||
r.source = assembly | ||
|
||
If ks_arch_supported(arch) = 0 Then | ||
r.errMsg = "specified architecture not supported" | ||
Exit Function | ||
End If | ||
|
||
r.lastErr = ks_open(arch, mode, hKeystone) | ||
If r.lastErr <> KS_ERR_OK Then | ||
r.errMsg = err2str(r.lastErr) | ||
Exit Function | ||
End If | ||
|
||
'If withResolver Then setResolver hKeystone, AddressOf vbSymResolver | ||
If syntax <> 0 Then Call ks_option(hKeystone, KS_OPT_SYNTAX, syntax) | ||
|
||
address = lng2Cur(base) | ||
r.lastErr = ks_asm(hKeystone, assembly, address, buf, size, count) | ||
|
||
If r.lastErr = KS_ERR_OK Then | ||
ReDim b(size - 1) | ||
CopyMemory ByVal VarPtr(b(0)), ByVal buf, size | ||
ks_free buf | ||
r.result = b() | ||
r.count = count | ||
r.size = size | ||
End If | ||
|
||
ks_close hKeystone | ||
|
||
End Function | ||
|
||
Function AddResult(r As CAsmResult) | ||
|
||
Dim li As ListItem | ||
|
||
Set li = lv.ListItems.Add(, , ks_arch2str(r.arch)) | ||
li.SubItems(1) = r.source | ||
If r.hadErr Then | ||
li.SubItems(2) = "Error: " & r.errMsg | ||
Else | ||
li.SubItems(2) = b2Str(r.result) | ||
End If | ||
Set li.Tag = r | ||
|
||
End Function | ||
|
||
Private Sub Command1_Click() | ||
Clipboard.Clear | ||
Clipboard.SetText GetAllElements(lv) | ||
End Sub | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Type=Exe | ||
Form=Form1.frm | ||
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\stdole2.tlb#OLE Automation | ||
Module=mKeyStone; mKeystone.bas | ||
Module=mMisc; mMisc.bas | ||
Class=CAsmResult; CAsmResult.cls | ||
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; mscomctl.ocx | ||
IconForm="Form1" | ||
Startup="Form1" | ||
Command32="" | ||
Name="Project1" | ||
HelpContextID="0" | ||
CompatibleMode="0" | ||
MajorVer=1 | ||
MinorVer=0 | ||
RevisionVer=0 | ||
AutoIncrementVer=0 | ||
ServerSupportFiles=0 | ||
VersionCompanyName="sandsprite" | ||
CompilationType=0 | ||
OptimizationType=0 | ||
FavorPentiumPro(tm)=0 | ||
CodeViewDebugInfo=0 | ||
NoAliasing=0 | ||
BoundsCheck=0 | ||
OverflowCheck=0 | ||
FlPointCheck=0 | ||
FDIVCheck=0 | ||
UnroundedFP=0 | ||
StartMode=0 | ||
Unattended=0 | ||
Retained=0 | ||
ThreadPerObject=0 | ||
MaxNumberOfThreads=1 | ||
|
||
[MS Transaction Server] | ||
AutoRefresh=1 | ||
|
||
[fastBuild] | ||
fullPath=%ap%\bin\vbKeyStone.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Form1 = 269, 165, 1275, 826, , 22, 22, 1050, 683, C | ||
mKeyStone = 54, 17, 1321, 960, Z | ||
mMisc = 132, 132, 1160, 793, | ||
CAsmResult = 264, 264, 1270, 925, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
EXPORTS | ||
ks_arch_supported | ||
ks_asm | ||
ks_close | ||
ks_errno | ||
ks_free | ||
ks_open | ||
ks_option | ||
ks_strerror | ||
ks_version |
Binary file not shown.
Oops, something went wrong.