Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MSP430 support #392

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*.github.io
_*.diff

.idea/
cmake-build-debug

build*/
samples/sample
_sample*.txt
Expand Down
1 change: 1 addition & 0 deletions CREDITS.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ David Zimmer: VB6 binding.
Michael Mohr: Debian packaging.
Jämes Ménétrey (ZenLulz): Java binding.
Philippe Antoine (Catena cyber): fuzzing.
Trey Keown: MSP430 support.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Keystone Engine
Keystone is a lightweight multi-platform, multi-architecture assembler framework.
It offers some unparalleled features:

- Multi-architecture, with support for Arm, Arm64 (AArch64/Armv8), Ethereum Virtual Machine, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86 (include 16/32/64bit).
- Multi-architecture, with support for Arm, Arm64 (AArch64/Armv8), Ethereum Virtual Machine, Hexagon, Mips, MSP430, PowerPC, Sparc, SystemZ & X86 (include 16/32/64bit).
- Clean/simple/lightweight/intuitive architecture-neutral API.
- Implemented in C/C++ languages, with bindings for Java, Masm, C#, PowerShell, Perl, Python, NodeJS, Ruby, Go, Rust, Haskell, VB6 & OCaml available.
- Native support for Windows & \*nix (with Mac OSX, Linux, \*BSD & Solaris confirmed).
Expand Down
5 changes: 5 additions & 0 deletions bindings/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DIFF = diff -u -w
SAMPLE_ARM = $(TMPDIR)/sample_arm
SAMPLE_ARM64 = $(TMPDIR)/sample_arm64
SAMPLE_MIPS = $(TMPDIR)/sample_mips
SAMPLE_MSP430 = $(TMPDIR)/sample_msp430
SAMPLE_M68K = $(TMPDIR)/sample_m68k
SAMPLE_SPARC = $(TMPDIR)/sample_sparc
SAMPLE_X86 = $(TMPDIR)/sample_x86
Expand All @@ -20,6 +21,7 @@ all:
python const_generator.py go
cd ruby && $(MAKE) gen_const
python const_generator.py powershell
python const_generator.py csharp

samples: expected python

Expand All @@ -31,6 +33,7 @@ expected:
../samples/sample_arm > $(SAMPLE_ARM)_e
../samples/sample_arm64 > $(SAMPLE_ARM64)_e
../samples/sample_mips > $(SAMPLE_MIPS)_e
../samples/sample_msp430 > $(SAMPLE_MSP430)_e
../samples/sample_sparc > $(SAMPLE_SPARC)_e
../samples/sample_m68k > $(SAMPLE_M68K)_e
../samples/sample_x86 > $(SAMPLE_X86)_e
Expand All @@ -40,6 +43,7 @@ python: FORCE
python python/sample_arm.py > $(SAMPLE_ARM)_o
python python/sample_arm64.py > $(SAMPLE_ARM64)_o
python python/sample_mips.py > $(SAMPLE_MIPS)_o
python python/sample_msp430.py > $(SAMPLE_MSP430)_o
python python/sample_sparc.py > $(SAMPLE_SPARC)_o
python python/sample_m68k.py > $(SAMPLE_M68K)_o
python python/sample_x86.py > $(SAMPLE_X86)_o
Expand All @@ -64,6 +68,7 @@ sample_diff: FORCE
$(DIFF) $(SAMPLE_ARM)_e $(SAMPLE_ARM)_o
$(DIFF) $(SAMPLE_ARM64)_e $(SAMPLE_ARM64)_o
$(DIFF) $(SAMPLE_MIPS)_e $(SAMPLE_MIPS)_o
$(DIFF) $(SAMPLE_MSP430)_e $(SAMPLE_MSP430)_o
$(DIFF) $(SAMPLE_SPARC)_e $(SAMPLE_SPARC)_o
$(DIFF) $(SAMPLE_M68K)_e $(SAMPLE_M68K)_o
$(DIFF) $(SAMPLE_X86)_e $(SAMPLE_X86)_o
Expand Down
55 changes: 30 additions & 25 deletions bindings/const_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# NOTE: this reflects the value of KS_ERR_ASM_xxx in keystone.h
ks_err_val = { 'KS_ERR_ASM': '128', 'KS_ERR_ASM_ARCH': '512' }

include = [ 'arm.h', 'arm64.h', 'mips.h', 'x86.h', 'sparc.h', 'ppc.h', 'systemz.h', 'hexagon.h', 'evm.h', 'keystone.h' ]
include = [ 'arm.h', 'arm64.h', 'mips.h', 'x86.h', 'sparc.h', 'ppc.h', 'systemz.h', 'hexagon.h', 'evm.h', 'msp430.h', 'keystone.h' ]

def CamelCase(s):
# return re.sub(r'(\w)+\_?', lambda m:m.group(0).capitalize(), s)
Expand All @@ -35,15 +35,16 @@ def CamelCase(s):
'header': "#![allow(non_camel_case_types)]\n// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%s_const.rs]\nuse libc;\n",
'footer': "",
# prefixes for constant filenames of all archs - case sensitive
'arm.h': 'keystone',
'arm64.h': 'keystone',
'mips.h': 'keystone',
'x86.h': 'keystone',
'sparc.h': 'keystone',
'systemz.h': 'keystone',
'ppc.h': 'keystone',
'hexagon.h': 'keystone',
'evm.h': 'keystone',
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'msp430.h': 'msp430',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
'ppc.h': 'ppc',
'hexagon.h': 'hexagon',
'evm.h': 'evm',
'keystone.h': 'keystone',
'comment_open': '/*',
'comment_close': '*/',
Expand Down Expand Up @@ -110,6 +111,7 @@ def CamelCase(s):
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'msp430.h': 'msp430',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
Expand Down Expand Up @@ -172,6 +174,7 @@ def CamelCase(s):
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'msp430.h': 'msp430',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
Expand All @@ -197,6 +200,7 @@ def CamelCase(s):
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'msp430.h': 'msp430',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
Expand All @@ -222,6 +226,7 @@ def CamelCase(s):
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'msp430.h': 'msp430',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
Expand All @@ -240,34 +245,34 @@ def CamelCase(s):
]
},
'csharp': {
'header': "// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%sConstants.cs]\nnamespace KeystoneNET\n{",
'header': "// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [%sConstants.cs]\nnamespace Keystone\n{",
'footer': "}",
'out_file': './csharp/KeystoneNET/KeystoneNET/Constants/%sConstants.cs',
'out_file': './csharp/Keystone.NET/Constants/%sConstants.cs',
# prefixes for constant filenames of all archs - case sensitive
'keystone.h': 'keystone',
'arm.h': 'arm',
'arm64.h': 'arm64',
'mips.h': 'mips',
'x86.h': 'x86',
'sparc.h': 'sparc',
'systemz.h': 'systemz',
'ppc.h': 'ppc',
'hexagon.h': 'hexagon',
'evm.h': 'evm',
'keystone.h': 'keystone',
'keystone.h': 'Keystone',
'arm.h': 'ARM',
'arm64.h': 'ARM64',
'mips.h': 'Mips',
'msp430.h': 'MSP430',
'x86.h': 'X86',
'sparc.h': 'SPARC',
'systemz.h': 'SystemZ',
'ppc.h': 'PPC',
'hexagon.h': 'Hexagon',
'evm.h': 'EVM',
'comment_open': '//',
'comment_close': '',
'rules': [
{
'regex': r'(ARCH)_.*',
'pre': '\n\tpublic enum KeystoneArchitecture : int\n\t{{\n',
'pre': '\n\tpublic enum Architecture : int\n\t{{\n',
'post': '\t}',
'line_format': '\t\tKS_{0} = {1},\n',
'fn': (lambda x: x),
},
{
'regex': r'(MODE)_.*',
'pre': '\n\tpublic enum KeystoneMode : uint\n\t{{\n',
'pre': '\n\tpublic enum Mode : uint\n\t{{\n',
'post': '\t}',
'line_format': '\t\tKS_{0} = {1},\n',
'fn': (lambda x: x),
Expand Down
2 changes: 1 addition & 1 deletion bindings/csharp/Keystone.Net/Constants/ARM64Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [arm64Constants.cs]
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [ARM64Constants.cs]
namespace Keystone
{
public enum Arm64Error : short
Expand Down
2 changes: 1 addition & 1 deletion bindings/csharp/Keystone.Net/Constants/ARMConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [armConstants.cs]
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [ARMConstants.cs]
namespace Keystone
{
public enum ArmError : short
Expand Down
10 changes: 10 additions & 0 deletions bindings/csharp/Keystone.Net/Constants/EVMConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [EVMConstants.cs]
namespace Keystone
{
public enum EvmError : short
{
KS_ERR_ASM_EVM_INVALIDOPERAND = 512,
KS_ERR_ASM_EVM_MISSINGFEATURE = 513,
KS_ERR_ASM_EVM_MNEMONICFAIL = 514,
}
}
2 changes: 1 addition & 1 deletion bindings/csharp/Keystone.Net/Constants/HexagonConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [hexagonConstants.cs]
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [HexagonConstants.cs]
namespace Keystone
{
public enum HexagonError : short
Expand Down
80 changes: 41 additions & 39 deletions bindings/csharp/Keystone.Net/Constants/KeystoneConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,40 @@ namespace Keystone
{
public enum Architecture : int
{
ARM = 1,
ARM64 = 2,
MIPS = 3,
X86 = 4,
PPC = 5,
SPARC = 6,
SYSTEMZ = 7,
HEXAGON = 8,
MAX = 9,
KS_ARCH_ARM = 1,
KS_ARCH_ARM64 = 2,
KS_ARCH_MIPS = 3,
KS_ARCH_X86 = 4,
KS_ARCH_PPC = 5,
KS_ARCH_SPARC = 6,
KS_ARCH_SYSTEMZ = 7,
KS_ARCH_HEXAGON = 8,
KS_ARCH_EVM = 9,
KS_ARCH_MSP430 = 10,
KS_ARCH_MAX = 11,
}

public enum Mode : uint
{
LITTLE_ENDIAN = 0,
BIG_ENDIAN = 1073741824,
ARM = 1,
THUMB = 16,
V8 = 64,
MICRO = 16,
MIPS3 = 32,
MIPS32R6 = 64,
MIPS32 = 4,
MIPS64 = 8,
X16 = 2,
X32 = 4,
X64 = 8,
PPC32 = 4,
PPC64 = 8,
QPX = 16,
SPARC32 = 4,
SPARC64 = 8,
V9 = 16,
KS_MODE_LITTLE_ENDIAN = 0,
KS_MODE_BIG_ENDIAN = 1073741824,
KS_MODE_ARM = 1,
KS_MODE_THUMB = 16,
KS_MODE_V8 = 64,
KS_MODE_MICRO = 16,
KS_MODE_MIPS3 = 32,
KS_MODE_MIPS32R6 = 64,
KS_MODE_MIPS32 = 4,
KS_MODE_MIPS64 = 8,
KS_MODE_16 = 2,
KS_MODE_32 = 4,
KS_MODE_64 = 8,
KS_MODE_PPC32 = 4,
KS_MODE_PPC64 = 8,
KS_MODE_QPX = 16,
KS_MODE_SPARC32 = 4,
KS_MODE_SPARC64 = 8,
KS_MODE_V9 = 16,
}

public enum KeystoneError : short
Expand Down Expand Up @@ -86,22 +88,22 @@ public enum KeystoneError : short
KS_ERR_ASM_FRAGMENT_INVALID = 163,
KS_ERR_ASM_INVALIDOPERAND = 512,
KS_ERR_ASM_MISSINGFEATURE = 513,
KS_ERR_ASM_MNEMONICFAIL = 514
KS_ERR_ASM_MNEMONICFAIL = 514,
}

public enum OptionType : int
public enum KeystoneOptionType : short
{
SYNTAX = 1,
SYM_RESOLVER = 2,
KS_OPT_SYNTAX = 1,
KS_OPT_SYM_RESOLVER = 2,
}

public enum OptionValue : short
public enum KeystoneOptionValue : short
{
SYNTAX_INTEL = 1,
SYNTAX_ATT = 2,
SYNTAX_NASM = 4,
SYNTAX_MASM = 8,
SYNTAX_GAS = 16,
SYNTAX_RADIX16 = 32
KS_OPT_SYNTAX_INTEL = 1,
KS_OPT_SYNTAX_ATT = 2,
KS_OPT_SYNTAX_NASM = 4,
KS_OPT_SYNTAX_MASM = 8,
KS_OPT_SYNTAX_GAS = 16,
KS_OPT_SYNTAX_RADIX16 = 32,
}
}
10 changes: 10 additions & 0 deletions bindings/csharp/Keystone.Net/Constants/MSP430Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [MSP430Constants.cs]
namespace Keystone
{
public enum Msp430Error : short
{
KS_ERR_ASM_MSP430_INVALIDOPERAND = 512,
KS_ERR_ASM_MSP430_MISSINGFEATURE = 513,
KS_ERR_ASM_MSP430_MNEMONICFAIL = 514,
}
}
2 changes: 1 addition & 1 deletion bindings/csharp/Keystone.Net/Constants/MipsConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [mipsConstants.cs]
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [MipsConstants.cs]
namespace Keystone
{
public enum MipsError : short
Expand Down
2 changes: 1 addition & 1 deletion bindings/csharp/Keystone.Net/Constants/PPCConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [ppcConstants.cs]
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [PPCConstants.cs]
namespace Keystone
{
public enum PpcError : short
Expand Down
2 changes: 1 addition & 1 deletion bindings/csharp/Keystone.Net/Constants/SPARCConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [sparcConstants.cs]
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [SPARCConstants.cs]
namespace Keystone
{
public enum SparcError : short
Expand Down
2 changes: 1 addition & 1 deletion bindings/csharp/Keystone.Net/Constants/SystemZConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [systemzConstants.cs]
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [SystemZConstants.cs]
namespace Keystone
{
public enum SystemzError : short
Expand Down
2 changes: 1 addition & 1 deletion bindings/csharp/Keystone.Net/Constants/X86Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [x86Constants.cs]
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [X86Constants.cs]
namespace Keystone
{
public enum X86Error : short
Expand Down
3 changes: 2 additions & 1 deletion bindings/go/keystone/keystone_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const (
ARCH_SYSTEMZ Architecture = 7
ARCH_HEXAGON Architecture = 8
ARCH_EVM Architecture = 9
ARCH_MAX Architecture = 10
ARCH_MSP430 Architecture = 10
ARCH_MAX Architecture = 11
)

const (
Expand Down
9 changes: 9 additions & 0 deletions bindings/go/keystone/msp430_const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package keystone
// For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [msp430_const.go]

const (
ERR_ASM_MSP430_INVALIDOPERAND Error = 512
ERR_ASM_MSP430_MISSINGFEATURE Error = 513
ERR_ASM_MSP430_MNEMONICFAIL Error = 514
)

1 change: 1 addition & 0 deletions bindings/haskell/keystone.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ library
Keystone.CPU.Arm
Keystone.CPU.Hexagon
Keystone.CPU.Mips
Keystone.CPU.Msp430
Keystone.CPU.Ppc
Keystone.CPU.Sparc
Keystone.CPU.SystemZ
Expand Down
3 changes: 3 additions & 0 deletions bindings/haskell/samples/Sample.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ main = do

-- SystemZ
testKs ArchSystemz [ModeBigEndian] ["a %r0, 4095(%r15,%r1)"] Nothing

-- MSP430
testKs ArchMsp430 [ModeLittleEndian] ["and r12, r13"] Nothing
Loading