keystone-engine 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e12313098bec81cc9d176bcfe0e6dea4886f825
4
+ data.tar.gz: 83df6a1a369e4611d03c92b0efbfcc86863a9e19
5
+ SHA512:
6
+ metadata.gz: 190a6ea3b49d9f302a54fdbf3ad73ac3d5b9407a22641c6e97bd7902107330435fa0f8ad11be1ac79675b84be2b3eaa04790e596374dfff85196c0fca32504dd
7
+ data.tar.gz: c828d56ca92f0d03ffb23c443949d6d56ba7a2f12512d89e848cbe8aada8843f99fb5057a0fd3e8217dc57ce53a0d9a44b965fd9ad78c8c05ca19a19211f7857
@@ -0,0 +1,77 @@
1
+ # Ruby bindings for the Keystone Engine
2
+ #
3
+ # Copyright(c) 2017 Sascha Schirra
4
+ #
5
+ # This program is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License
7
+ # version 2 as published by the Free Software Foundation.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
+
18
+
19
+ require "ffi"
20
+ require "objspace"
21
+
22
+
23
+ module KeystoneEngine extend FFI::Library
24
+ ffi_lib "keystone"
25
+
26
+ class IntPtr < FFI::Struct
27
+ layout :value, :size_t
28
+ end
29
+ class KsEnginePtr < FFI::Struct
30
+ layout :value, :pointer
31
+ end
32
+ class StringPtr < FFI::Struct
33
+ layout :value, :pointer
34
+ end
35
+
36
+ attach_function :ks_open, [:int, :int, KsEnginePtr], :int
37
+ attach_function :ks_close, [:pointer], :int
38
+ attach_function :ks_errno, [:pointer], :int
39
+ attach_function :ks_strerror, [:int], :pointer
40
+ attach_function :ks_asm, [:pointer, :pointer, :uint64, StringPtr, IntPtr, IntPtr], :int
41
+
42
+ class KsError < StandardError
43
+ end
44
+
45
+ class Ks
46
+ private
47
+ attr_accessor :ks
48
+
49
+ public
50
+ def initialize(arch, mode)
51
+ _ks = KsEnginePtr.new
52
+ err = KeystoneEngine::ks_open(arch, mode, _ks)
53
+ if err != KS_ERR_OK
54
+ raise KsError, KeystoneEngine::ks_strerror(err).read_string
55
+ end
56
+ @ks = _ks[:value]
57
+
58
+ ObjectSpace.define_finalizer(self, proc{ KeystoneEngine::ks_close(ks) })
59
+ end
60
+
61
+ def asm(instructions, address=0)
62
+ inst = FFI::MemoryPointer.from_string(instructions)
63
+ bytes = StringPtr.new
64
+ size = IntPtr.new
65
+ count = IntPtr.new
66
+ err = KeystoneEngine::ks_asm(ks, inst, address, bytes, size, count)
67
+
68
+ if err != KS_ERR_OK
69
+ raise KsError, KeystoneEngine::ks_strerror(err).read_string
70
+ end
71
+
72
+ return [bytes[:value].read_string(size[:value]), count[:value]]
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module KeystoneEngine
3
+ KS_ERR_ASM_ARM64_INVALIDOPERAND = 512
4
+ KS_ERR_ASM_ARM64_MISSINGFEATURE = 513
5
+ KS_ERR_ASM_ARM64_MNEMONICFAIL = 514
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module KeystoneEngine
3
+ KS_ERR_ASM_ARM_INVALIDOPERAND = 512
4
+ KS_ERR_ASM_ARM_MISSINGFEATURE = 513
5
+ KS_ERR_ASM_ARM_MNEMONICFAIL = 514
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module KeystoneEngine
3
+ KS_ERR_ASM_HEXAGON_INVALIDOPERAND = 512
4
+ KS_ERR_ASM_HEXAGON_MISSINGFEATURE = 513
5
+ KS_ERR_ASM_HEXAGON_MNEMONICFAIL = 514
6
+ end
@@ -0,0 +1,92 @@
1
+
2
+ module KeystoneEngine
3
+ KS_API_MAJOR = 0
4
+ KS_API_MINOR = 9
5
+ KS_VERSION_MAJOR = 0
6
+ KS_VERSION_MINOR = 9
7
+ KS_VERSION_EXTRA = 1
8
+ KS_ARCH_ARM = 1
9
+ KS_ARCH_ARM64 = 2
10
+ KS_ARCH_MIPS = 3
11
+ KS_ARCH_X86 = 4
12
+ KS_ARCH_PPC = 5
13
+ KS_ARCH_SPARC = 6
14
+ KS_ARCH_SYSTEMZ = 7
15
+ KS_ARCH_HEXAGON = 8
16
+ KS_ARCH_MAX = 9
17
+ KS_MODE_LITTLE_ENDIAN = 0
18
+ KS_MODE_BIG_ENDIAN = 1073741824
19
+ KS_MODE_ARM = 1
20
+ KS_MODE_THUMB = 16
21
+ KS_MODE_V8 = 64
22
+ KS_MODE_MICRO = 16
23
+ KS_MODE_MIPS3 = 32
24
+ KS_MODE_MIPS32R6 = 64
25
+ KS_MODE_MIPS32 = 4
26
+ KS_MODE_MIPS64 = 8
27
+ KS_MODE_16 = 2
28
+ KS_MODE_32 = 4
29
+ KS_MODE_64 = 8
30
+ KS_MODE_PPC32 = 4
31
+ KS_MODE_PPC64 = 8
32
+ KS_MODE_QPX = 16
33
+ KS_MODE_SPARC32 = 4
34
+ KS_MODE_SPARC64 = 8
35
+ KS_MODE_V9 = 16
36
+ KS_ERR_ASM = 128
37
+ KS_ERR_ASM_ARCH = 512
38
+ KS_ERR_OK = 0
39
+ KS_ERR_NOMEM = 1
40
+ KS_ERR_ARCH = 2
41
+ KS_ERR_HANDLE = 3
42
+ KS_ERR_MODE = 4
43
+ KS_ERR_VERSION = 5
44
+ KS_ERR_OPT_INVALID = 6
45
+ KS_ERR_ASM_EXPR_TOKEN = 128
46
+ KS_ERR_ASM_DIRECTIVE_VALUE_RANGE = 129
47
+ KS_ERR_ASM_DIRECTIVE_ID = 130
48
+ KS_ERR_ASM_DIRECTIVE_TOKEN = 131
49
+ KS_ERR_ASM_DIRECTIVE_STR = 132
50
+ KS_ERR_ASM_DIRECTIVE_COMMA = 133
51
+ KS_ERR_ASM_DIRECTIVE_RELOC_NAME = 134
52
+ KS_ERR_ASM_DIRECTIVE_RELOC_TOKEN = 135
53
+ KS_ERR_ASM_DIRECTIVE_FPOINT = 136
54
+ KS_ERR_ASM_DIRECTIVE_UNKNOWN = 137
55
+ KS_ERR_ASM_DIRECTIVE_EQU = 138
56
+ KS_ERR_ASM_DIRECTIVE_INVALID = 139
57
+ KS_ERR_ASM_VARIANT_INVALID = 140
58
+ KS_ERR_ASM_EXPR_BRACKET = 141
59
+ KS_ERR_ASM_SYMBOL_MODIFIER = 142
60
+ KS_ERR_ASM_SYMBOL_REDEFINED = 143
61
+ KS_ERR_ASM_SYMBOL_MISSING = 144
62
+ KS_ERR_ASM_RPAREN = 145
63
+ KS_ERR_ASM_STAT_TOKEN = 146
64
+ KS_ERR_ASM_UNSUPPORTED = 147
65
+ KS_ERR_ASM_MACRO_TOKEN = 148
66
+ KS_ERR_ASM_MACRO_PAREN = 149
67
+ KS_ERR_ASM_MACRO_EQU = 150
68
+ KS_ERR_ASM_MACRO_ARGS = 151
69
+ KS_ERR_ASM_MACRO_LEVELS_EXCEED = 152
70
+ KS_ERR_ASM_MACRO_STR = 153
71
+ KS_ERR_ASM_MACRO_INVALID = 154
72
+ KS_ERR_ASM_ESC_BACKSLASH = 155
73
+ KS_ERR_ASM_ESC_OCTAL = 156
74
+ KS_ERR_ASM_ESC_SEQUENCE = 157
75
+ KS_ERR_ASM_ESC_STR = 158
76
+ KS_ERR_ASM_TOKEN_INVALID = 159
77
+ KS_ERR_ASM_INSN_UNSUPPORTED = 160
78
+ KS_ERR_ASM_FIXUP_INVALID = 161
79
+ KS_ERR_ASM_LABEL_INVALID = 162
80
+ KS_ERR_ASM_FRAGMENT_INVALID = 163
81
+ KS_ERR_ASM_INVALIDOPERAND = 512
82
+ KS_ERR_ASM_MISSINGFEATURE = 513
83
+ KS_ERR_ASM_MNEMONICFAIL = 514
84
+ KS_OPT_SYNTAX = 1
85
+ KS_OPT_SYM_RESOLVER = 2
86
+ KS_OPT_SYNTAX_INTEL = 1
87
+ KS_OPT_SYNTAX_ATT = 2
88
+ KS_OPT_SYNTAX_NASM = 4
89
+ KS_OPT_SYNTAX_MASM = 8
90
+ KS_OPT_SYNTAX_GAS = 16
91
+ KS_OPT_SYNTAX_RADIX16 = 32
92
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module KeystoneEngine
3
+ KS_ERR_ASM_MIPS_INVALIDOPERAND = 512
4
+ KS_ERR_ASM_MIPS_MISSINGFEATURE = 513
5
+ KS_ERR_ASM_MIPS_MNEMONICFAIL = 514
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module KeystoneEngine
3
+ KS_ERR_ASM_PPC_INVALIDOPERAND = 512
4
+ KS_ERR_ASM_PPC_MISSINGFEATURE = 513
5
+ KS_ERR_ASM_PPC_MNEMONICFAIL = 514
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module KeystoneEngine
3
+ KS_ERR_ASM_SPARC_INVALIDOPERAND = 512
4
+ KS_ERR_ASM_SPARC_MISSINGFEATURE = 513
5
+ KS_ERR_ASM_SPARC_MNEMONICFAIL = 514
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module KeystoneEngine
3
+ KS_ERR_ASM_SYSTEMZ_INVALIDOPERAND = 512
4
+ KS_ERR_ASM_SYSTEMZ_MISSINGFEATURE = 513
5
+ KS_ERR_ASM_SYSTEMZ_MNEMONICFAIL = 514
6
+ end
@@ -0,0 +1,3 @@
1
+ module KeystoneEngine
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module KeystoneEngine
3
+ KS_ERR_ASM_X86_INVALIDOPERAND = 512
4
+ KS_ERR_ASM_X86_MISSINGFEATURE = 513
5
+ KS_ERR_ASM_X86_MNEMONICFAIL = 514
6
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keystone-engine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Sascha Schirra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ description: Ruby binding for Keystone <Keystone-engine.org>
42
+ email:
43
+ - sashs@scoding.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/keystone_engine.rb
49
+ - lib/keystone_engine/arm64_const.rb
50
+ - lib/keystone_engine/arm_const.rb
51
+ - lib/keystone_engine/hexagon_const.rb
52
+ - lib/keystone_engine/keystone_const.rb
53
+ - lib/keystone_engine/mips_const.rb
54
+ - lib/keystone_engine/ppc_const.rb
55
+ - lib/keystone_engine/sparc_const.rb
56
+ - lib/keystone_engine/systemz_const.rb
57
+ - lib/keystone_engine/version.rb
58
+ - lib/keystone_engine/x86_const.rb
59
+ homepage: https://keystone-engine.org
60
+ licenses:
61
+ - GPL-2.0
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.13
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Ruby binding for Keystone
83
+ test_files: []