From 388e173640a1c2fedeca00b2571d54b2211b5b93 Mon Sep 17 00:00:00 2001
From: Ryan Hileman <lunixbochs@gmail.com>
Date: Mon, 6 Jun 2016 21:09:20 -0700
Subject: [PATCH] fix go bindings with system-installed keystone

---
 bindings/const_generator.py              |  12 +-
 bindings/go/README.md                    |   6 -
 bindings/go/keystone/arm64_const.go      |   6 +-
 bindings/go/keystone/arm_const.go        |   6 +-
 bindings/go/keystone/hexagon_const.go    |   6 +-
 bindings/go/keystone/keystone-binding.c  |   5 -
 bindings/go/keystone/keystone-binding.go |   5 +-
 bindings/go/keystone/keystone-binding.h  |   7 -
 bindings/go/keystone/keystone.go         |   2 +-
 bindings/go/keystone/keystone_const.go   | 168 +++++++++++------------
 bindings/go/keystone/mips_const.go       |   6 +-
 bindings/go/keystone/ppc_const.go        |   6 +-
 bindings/go/keystone/sparc_const.go      |   6 +-
 bindings/go/keystone/systemz_const.go    |   6 +-
 bindings/go/keystone/x86_const.go        |   6 +-
 15 files changed, 117 insertions(+), 136 deletions(-)
 delete mode 100644 bindings/go/keystone/keystone-binding.c
 delete mode 100644 bindings/go/keystone/keystone-binding.h

diff --git a/bindings/const_generator.py b/bindings/const_generator.py
index c8f1f43..af0d07e 100644
--- a/bindings/const_generator.py
+++ b/bindings/const_generator.py
@@ -112,41 +112,41 @@ template = {
                 {
                     'regex': r'(API)_.*',
                     'pre': 'const (\n',
-                    'line_format': '\t\t{0} = {1}\n',
+                    'line_format': '\t{0} = {1}\n',
                     'fn': (lambda x: x),
                     'post': ')\n',
                 },
                 {   'regex': r'MODE_.*',
                     'pre': 'const (\n',
-                    'line_format': '\t\t{0} Mode = {1}\n',
+                    'line_format': '\t{0} Mode = {1}\n',
                     'fn': (lambda x: x),
                     'post': ')\n',
                 },
                 {
                     'regex': r'ARCH_.*',
                     'pre': 'const (\n',
-                    'line_format': '\t\t{0} Architecture = {1}\n',
+                    'line_format': '\t{0} Architecture = {1}\n',
                     'fn': (lambda x: x),
                     'post': ')\n',
                 },
                 {
                     'regex': r'OPT_([A-Z]+)$',
                     'pre': 'const (\n',
-                    'line_format': '\t\t{0} OptionType = {1}\n',
+                    'line_format': '\t{0} OptionType = {1}\n',
                     'fn': (lambda x: x),
                     'post': ')\n',
                 },
                 {
                     'regex': r'OPT_([A-Z]+\_)+[A-Z]+',
                     'pre': 'const (\n',
-                    'line_format': '\t\t{0} OptionValue = {1}\n',
+                    'line_format': '\t{0} OptionValue = {1}\n',
                     'fn': (lambda x: x),
                     'post': ')\n',
                 },
                 {
                     'regex': r'ERR_.*',
                     'pre': 'const (\n',
-                    'line_format': '\t\t{0} Error = {1}\n',
+                    'line_format': '\t{0} Error = {1}\n',
                     'fn': (lambda x: x),
                     'post': ')\n',
                 },
diff --git a/bindings/go/README.md b/bindings/go/README.md
index 66dacc6..a82147e 100644
--- a/bindings/go/README.md
+++ b/bindings/go/README.md
@@ -1,12 +1,6 @@
 # keystone 
 Go bindings for the [keystone](http://www.keystone-engine.org/) engine.
 
-## Configuration
-```
-export CGO_CFLAGS -I../../../include/keystone/
-export CGO_LDFLAGS "-L../../../build/llvm/lib/ -lkeystone"
-```
-
 ## Sample
 ```go
 package main
diff --git a/bindings/go/keystone/arm64_const.go b/bindings/go/keystone/arm64_const.go
index 004af4d..971a3ff 100644
--- a/bindings/go/keystone/arm64_const.go
+++ b/bindings/go/keystone/arm64_const.go
@@ -2,8 +2,8 @@ package keystone
 // For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [arm64_const.go]
 
 const (
-		ERR_ASM_ARM64_INVALIDOPERAND Error = 512
-		ERR_ASM_ARM64_MISSINGFEATURE Error = 513
-		ERR_ASM_ARM64_MNEMONICFAIL Error = 514
+	ERR_ASM_ARM64_INVALIDOPERAND Error = 512
+	ERR_ASM_ARM64_MISSINGFEATURE Error = 513
+	ERR_ASM_ARM64_MNEMONICFAIL Error = 514
 )
 
diff --git a/bindings/go/keystone/arm_const.go b/bindings/go/keystone/arm_const.go
index 90d3efe..154949d 100644
--- a/bindings/go/keystone/arm_const.go
+++ b/bindings/go/keystone/arm_const.go
@@ -2,8 +2,8 @@ package keystone
 // For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [arm_const.go]
 
 const (
-		ERR_ASM_ARM_INVALIDOPERAND Error = 512
-		ERR_ASM_ARM_MISSINGFEATURE Error = 513
-		ERR_ASM_ARM_MNEMONICFAIL Error = 514
+	ERR_ASM_ARM_INVALIDOPERAND Error = 512
+	ERR_ASM_ARM_MISSINGFEATURE Error = 513
+	ERR_ASM_ARM_MNEMONICFAIL Error = 514
 )
 
diff --git a/bindings/go/keystone/hexagon_const.go b/bindings/go/keystone/hexagon_const.go
index a0fc92d..a9e814e 100644
--- a/bindings/go/keystone/hexagon_const.go
+++ b/bindings/go/keystone/hexagon_const.go
@@ -2,8 +2,8 @@ package keystone
 // For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [hexagon_const.go]
 
 const (
-		ERR_ASM_HEXAGON_INVALIDOPERAND Error = 512
-		ERR_ASM_HEXAGON_MISSINGFEATURE Error = 513
-		ERR_ASM_HEXAGON_MNEMONICFAIL Error = 514
+	ERR_ASM_HEXAGON_INVALIDOPERAND Error = 512
+	ERR_ASM_HEXAGON_MISSINGFEATURE Error = 513
+	ERR_ASM_HEXAGON_MNEMONICFAIL Error = 514
 )
 
diff --git a/bindings/go/keystone/keystone-binding.c b/bindings/go/keystone/keystone-binding.c
deleted file mode 100644
index 8498366..0000000
--- a/bindings/go/keystone/keystone-binding.c
+++ /dev/null
@@ -1,5 +0,0 @@
-// Copyright © 2015, Keylocker. All rights reserved.
-
-// +build darwin,linux,cgo
-
-#include <keystone.h>
diff --git a/bindings/go/keystone/keystone-binding.go b/bindings/go/keystone/keystone-binding.go
index a6b20ab..8530f35 100644
--- a/bindings/go/keystone/keystone-binding.go
+++ b/bindings/go/keystone/keystone-binding.go
@@ -5,9 +5,8 @@
 // +build darwin,linux,cgo
 package keystone
 
-// #cgo linux LDFLAGS:-lkeystone
-// #include "keystone-binding.h"
-// #include "keystone.h"
+// #cgo LDFLAGS: -lkeystone
+// #include <keystone/keystone.h>
 import "C"
 import "unsafe"
 
diff --git a/bindings/go/keystone/keystone-binding.h b/bindings/go/keystone/keystone-binding.h
deleted file mode 100644
index 3bbc3f1..0000000
--- a/bindings/go/keystone/keystone-binding.h
+++ /dev/null
@@ -1,7 +0,0 @@
-/* Keystone Assembler Engine (www.keystone-engine.org) */
-/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2016 */
-/* Golang bindings by Remco Verhoef <remco@dutchcoders.io>, 2016 */
-
-// #include <keystone.h>
-
-
diff --git a/bindings/go/keystone/keystone.go b/bindings/go/keystone/keystone.go
index 18305c5..8bdf372 100644
--- a/bindings/go/keystone/keystone.go
+++ b/bindings/go/keystone/keystone.go
@@ -4,7 +4,7 @@
 
 package keystone
 
-// #include "keystone.h"
+// #include <keystone/keystone.h>
 import "C"
 
 type Architecture uint
diff --git a/bindings/go/keystone/keystone_const.go b/bindings/go/keystone/keystone_const.go
index 664d4af..25934b1 100644
--- a/bindings/go/keystone/keystone_const.go
+++ b/bindings/go/keystone/keystone_const.go
@@ -2,104 +2,104 @@ package keystone
 // For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [keystone_const.go]
 
 const (
-		API_MAJOR = 0
-		API_MINOR = 9
+	API_MAJOR = 0
+	API_MINOR = 9
 )
 
 const (
-		MODE_LITTLE_ENDIAN Mode = 0
-		MODE_BIG_ENDIAN Mode = 1073741824
-		MODE_ARM Mode = 1
-		MODE_THUMB Mode = 16
-		MODE_V8 Mode = 64
-		MODE_MICRO Mode = 16
-		MODE_MIPS3 Mode = 32
-		MODE_MIPS32R6 Mode = 64
-		MODE_MIPS32 Mode = 4
-		MODE_MIPS64 Mode = 8
-		MODE_16 Mode = 2
-		MODE_32 Mode = 4
-		MODE_64 Mode = 8
-		MODE_PPC32 Mode = 4
-		MODE_PPC64 Mode = 8
-		MODE_QPX Mode = 16
-		MODE_SPARC32 Mode = 4
-		MODE_SPARC64 Mode = 8
-		MODE_V9 Mode = 16
+	MODE_LITTLE_ENDIAN Mode = 0
+	MODE_BIG_ENDIAN Mode = 1073741824
+	MODE_ARM Mode = 1
+	MODE_THUMB Mode = 16
+	MODE_V8 Mode = 64
+	MODE_MICRO Mode = 16
+	MODE_MIPS3 Mode = 32
+	MODE_MIPS32R6 Mode = 64
+	MODE_MIPS32 Mode = 4
+	MODE_MIPS64 Mode = 8
+	MODE_16 Mode = 2
+	MODE_32 Mode = 4
+	MODE_64 Mode = 8
+	MODE_PPC32 Mode = 4
+	MODE_PPC64 Mode = 8
+	MODE_QPX Mode = 16
+	MODE_SPARC32 Mode = 4
+	MODE_SPARC64 Mode = 8
+	MODE_V9 Mode = 16
 )
 
 const (
-		ARCH_ARM Architecture = 1
-		ARCH_ARM64 Architecture = 2
-		ARCH_MIPS Architecture = 3
-		ARCH_X86 Architecture = 4
-		ARCH_PPC Architecture = 5
-		ARCH_SPARC Architecture = 6
-		ARCH_SYSTEMZ Architecture = 7
-		ARCH_HEXAGON Architecture = 8
-		ARCH_MAX Architecture = 9
+	ARCH_ARM Architecture = 1
+	ARCH_ARM64 Architecture = 2
+	ARCH_MIPS Architecture = 3
+	ARCH_X86 Architecture = 4
+	ARCH_PPC Architecture = 5
+	ARCH_SPARC Architecture = 6
+	ARCH_SYSTEMZ Architecture = 7
+	ARCH_HEXAGON Architecture = 8
+	ARCH_MAX Architecture = 9
 )
 
 const (
-		OPT_SYNTAX OptionType = 1
+	OPT_SYNTAX OptionType = 1
 )
 
 const (
-		OPT_SYNTAX_INTEL OptionValue = 1
-		OPT_SYNTAX_ATT OptionValue = 2
-		OPT_SYNTAX_NASM OptionValue = 4
-		OPT_SYNTAX_MASM OptionValue = 8
-		OPT_SYNTAX_GAS OptionValue = 16
+	OPT_SYNTAX_INTEL OptionValue = 1
+	OPT_SYNTAX_ATT OptionValue = 2
+	OPT_SYNTAX_NASM OptionValue = 4
+	OPT_SYNTAX_MASM OptionValue = 8
+	OPT_SYNTAX_GAS OptionValue = 16
 )
 
 const (
-		ERR_ASM Error = 128
-		ERR_ASM_ARCH Error = 512
-		ERR_OK Error = 0
-		ERR_NOMEM Error = 1
-		ERR_ARCH Error = 2
-		ERR_HANDLE Error = 3
-		ERR_MODE Error = 4
-		ERR_VERSION Error = 5
-		ERR_OPT_INVALID Error = 6
-		ERR_ASM_EXPR_TOKEN Error = 128
-		ERR_ASM_DIRECTIVE_VALUE_RANGE Error = 129
-		ERR_ASM_DIRECTIVE_ID Error = 130
-		ERR_ASM_DIRECTIVE_TOKEN Error = 131
-		ERR_ASM_DIRECTIVE_STR Error = 132
-		ERR_ASM_DIRECTIVE_COMMA Error = 133
-		ERR_ASM_DIRECTIVE_RELOC_NAME Error = 134
-		ERR_ASM_DIRECTIVE_RELOC_TOKEN Error = 135
-		ERR_ASM_DIRECTIVE_FPOINT Error = 136
-		ERR_ASM_DIRECTIVE_UNKNOWN Error = 137
-		ERR_ASM_DIRECTIVE_EQU Error = 138
-		ERR_ASM_DIRECTIVE_INVALID Error = 139
-		ERR_ASM_VARIANT_INVALID Error = 140
-		ERR_ASM_EXPR_BRACKET Error = 141
-		ERR_ASM_SYMBOL_MODIFIER Error = 142
-		ERR_ASM_SYMBOL_REDEFINED Error = 143
-		ERR_ASM_SYMBOL_MISSING Error = 144
-		ERR_ASM_RPAREN Error = 145
-		ERR_ASM_STAT_TOKEN Error = 146
-		ERR_ASM_UNSUPPORTED Error = 147
-		ERR_ASM_MACRO_TOKEN Error = 148
-		ERR_ASM_MACRO_PAREN Error = 149
-		ERR_ASM_MACRO_EQU Error = 150
-		ERR_ASM_MACRO_ARGS Error = 151
-		ERR_ASM_MACRO_LEVELS_EXCEED Error = 152
-		ERR_ASM_MACRO_STR Error = 153
-		ERR_ASM_MACRO_INVALID Error = 154
-		ERR_ASM_ESC_BACKSLASH Error = 155
-		ERR_ASM_ESC_OCTAL Error = 156
-		ERR_ASM_ESC_SEQUENCE Error = 157
-		ERR_ASM_ESC_STR Error = 158
-		ERR_ASM_TOKEN_INVALID Error = 159
-		ERR_ASM_INSN_UNSUPPORTED Error = 160
-		ERR_ASM_FIXUP_INVALID Error = 161
-		ERR_ASM_LABEL_INVALID Error = 162
-		ERR_ASM_FRAGMENT_INVALID Error = 163
-		ERR_ASM_INVALIDOPERAND Error = 512
-		ERR_ASM_MISSINGFEATURE Error = 513
-		ERR_ASM_MNEMONICFAIL Error = 514
+	ERR_ASM Error = 128
+	ERR_ASM_ARCH Error = 512
+	ERR_OK Error = 0
+	ERR_NOMEM Error = 1
+	ERR_ARCH Error = 2
+	ERR_HANDLE Error = 3
+	ERR_MODE Error = 4
+	ERR_VERSION Error = 5
+	ERR_OPT_INVALID Error = 6
+	ERR_ASM_EXPR_TOKEN Error = 128
+	ERR_ASM_DIRECTIVE_VALUE_RANGE Error = 129
+	ERR_ASM_DIRECTIVE_ID Error = 130
+	ERR_ASM_DIRECTIVE_TOKEN Error = 131
+	ERR_ASM_DIRECTIVE_STR Error = 132
+	ERR_ASM_DIRECTIVE_COMMA Error = 133
+	ERR_ASM_DIRECTIVE_RELOC_NAME Error = 134
+	ERR_ASM_DIRECTIVE_RELOC_TOKEN Error = 135
+	ERR_ASM_DIRECTIVE_FPOINT Error = 136
+	ERR_ASM_DIRECTIVE_UNKNOWN Error = 137
+	ERR_ASM_DIRECTIVE_EQU Error = 138
+	ERR_ASM_DIRECTIVE_INVALID Error = 139
+	ERR_ASM_VARIANT_INVALID Error = 140
+	ERR_ASM_EXPR_BRACKET Error = 141
+	ERR_ASM_SYMBOL_MODIFIER Error = 142
+	ERR_ASM_SYMBOL_REDEFINED Error = 143
+	ERR_ASM_SYMBOL_MISSING Error = 144
+	ERR_ASM_RPAREN Error = 145
+	ERR_ASM_STAT_TOKEN Error = 146
+	ERR_ASM_UNSUPPORTED Error = 147
+	ERR_ASM_MACRO_TOKEN Error = 148
+	ERR_ASM_MACRO_PAREN Error = 149
+	ERR_ASM_MACRO_EQU Error = 150
+	ERR_ASM_MACRO_ARGS Error = 151
+	ERR_ASM_MACRO_LEVELS_EXCEED Error = 152
+	ERR_ASM_MACRO_STR Error = 153
+	ERR_ASM_MACRO_INVALID Error = 154
+	ERR_ASM_ESC_BACKSLASH Error = 155
+	ERR_ASM_ESC_OCTAL Error = 156
+	ERR_ASM_ESC_SEQUENCE Error = 157
+	ERR_ASM_ESC_STR Error = 158
+	ERR_ASM_TOKEN_INVALID Error = 159
+	ERR_ASM_INSN_UNSUPPORTED Error = 160
+	ERR_ASM_FIXUP_INVALID Error = 161
+	ERR_ASM_LABEL_INVALID Error = 162
+	ERR_ASM_FRAGMENT_INVALID Error = 163
+	ERR_ASM_INVALIDOPERAND Error = 512
+	ERR_ASM_MISSINGFEATURE Error = 513
+	ERR_ASM_MNEMONICFAIL Error = 514
 )
 
diff --git a/bindings/go/keystone/mips_const.go b/bindings/go/keystone/mips_const.go
index ffa9bce..da42fd0 100644
--- a/bindings/go/keystone/mips_const.go
+++ b/bindings/go/keystone/mips_const.go
@@ -2,8 +2,8 @@ package keystone
 // For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [mips_const.go]
 
 const (
-		ERR_ASM_MIPS_INVALIDOPERAND Error = 512
-		ERR_ASM_MIPS_MISSINGFEATURE Error = 513
-		ERR_ASM_MIPS_MNEMONICFAIL Error = 514
+	ERR_ASM_MIPS_INVALIDOPERAND Error = 512
+	ERR_ASM_MIPS_MISSINGFEATURE Error = 513
+	ERR_ASM_MIPS_MNEMONICFAIL Error = 514
 )
 
diff --git a/bindings/go/keystone/ppc_const.go b/bindings/go/keystone/ppc_const.go
index 995c9f0..fd4cd19 100644
--- a/bindings/go/keystone/ppc_const.go
+++ b/bindings/go/keystone/ppc_const.go
@@ -2,8 +2,8 @@ package keystone
 // For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [ppc_const.go]
 
 const (
-		ERR_ASM_PPC_INVALIDOPERAND Error = 512
-		ERR_ASM_PPC_MISSINGFEATURE Error = 513
-		ERR_ASM_PPC_MNEMONICFAIL Error = 514
+	ERR_ASM_PPC_INVALIDOPERAND Error = 512
+	ERR_ASM_PPC_MISSINGFEATURE Error = 513
+	ERR_ASM_PPC_MNEMONICFAIL Error = 514
 )
 
diff --git a/bindings/go/keystone/sparc_const.go b/bindings/go/keystone/sparc_const.go
index 0852618..0360571 100644
--- a/bindings/go/keystone/sparc_const.go
+++ b/bindings/go/keystone/sparc_const.go
@@ -2,8 +2,8 @@ package keystone
 // For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [sparc_const.go]
 
 const (
-		ERR_ASM_SPARC_INVALIDOPERAND Error = 512
-		ERR_ASM_SPARC_MISSINGFEATURE Error = 513
-		ERR_ASM_SPARC_MNEMONICFAIL Error = 514
+	ERR_ASM_SPARC_INVALIDOPERAND Error = 512
+	ERR_ASM_SPARC_MISSINGFEATURE Error = 513
+	ERR_ASM_SPARC_MNEMONICFAIL Error = 514
 )
 
diff --git a/bindings/go/keystone/systemz_const.go b/bindings/go/keystone/systemz_const.go
index f33c772..57404ee 100644
--- a/bindings/go/keystone/systemz_const.go
+++ b/bindings/go/keystone/systemz_const.go
@@ -2,8 +2,8 @@ package keystone
 // For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [systemz_const.go]
 
 const (
-		ERR_ASM_SYSTEMZ_INVALIDOPERAND Error = 512
-		ERR_ASM_SYSTEMZ_MISSINGFEATURE Error = 513
-		ERR_ASM_SYSTEMZ_MNEMONICFAIL Error = 514
+	ERR_ASM_SYSTEMZ_INVALIDOPERAND Error = 512
+	ERR_ASM_SYSTEMZ_MISSINGFEATURE Error = 513
+	ERR_ASM_SYSTEMZ_MNEMONICFAIL Error = 514
 )
 
diff --git a/bindings/go/keystone/x86_const.go b/bindings/go/keystone/x86_const.go
index 5e5ccef..cc7fc89 100644
--- a/bindings/go/keystone/x86_const.go
+++ b/bindings/go/keystone/x86_const.go
@@ -2,8 +2,8 @@ package keystone
 // For Keystone Engine. AUTO-GENERATED FILE, DO NOT EDIT [x86_const.go]
 
 const (
-		ERR_ASM_X86_INVALIDOPERAND Error = 512
-		ERR_ASM_X86_MISSINGFEATURE Error = 513
-		ERR_ASM_X86_MNEMONICFAIL Error = 514
+	ERR_ASM_X86_INVALIDOPERAND Error = 512
+	ERR_ASM_X86_MISSINGFEATURE Error = 513
+	ERR_ASM_X86_MNEMONICFAIL Error = 514
 )
 
-- 
GitLab