From 7a3adf65c1bfc84aca89b857b446b820c1859799 Mon Sep 17 00:00:00 2001 From: blshkv Date: Wed, 19 Dec 2018 08:47:54 +0800 Subject: [PATCH] capstone: remove radare2 patches, confirmed with @aquynh --- ...tone-4.0.ebuild => capstone-4.0-r1.ebuild} | 29 --- dev-libs/capstone/files/capstone-calloc.patch | 60 ----- dev-libs/capstone/files/fix-m68k-oob.patch | 24 -- .../capstone/files/fix-underflow-tms.patch | 28 --- dev-libs/capstone/files/fix-x86-16.patch | 30 --- dev-libs/capstone/files/pull939.patch | 215 ------------------ dev-libs/capstone/files/sparc-crash.patch | 14 -- dev-libs/capstone/files/sstream-null.patch | 14 -- 8 files changed, 414 deletions(-) rename dev-libs/capstone/{capstone-4.0.ebuild => capstone-4.0-r1.ebuild} (50%) delete mode 100644 dev-libs/capstone/files/capstone-calloc.patch delete mode 100644 dev-libs/capstone/files/fix-m68k-oob.patch delete mode 100644 dev-libs/capstone/files/fix-underflow-tms.patch delete mode 100644 dev-libs/capstone/files/fix-x86-16.patch delete mode 100644 dev-libs/capstone/files/pull939.patch delete mode 100644 dev-libs/capstone/files/sparc-crash.patch delete mode 100644 dev-libs/capstone/files/sstream-null.patch diff --git a/dev-libs/capstone/capstone-4.0.ebuild b/dev-libs/capstone/capstone-4.0-r1.ebuild similarity index 50% rename from dev-libs/capstone/capstone-4.0.ebuild rename to dev-libs/capstone/capstone-4.0-r1.ebuild index 030d4698b..d8c12cb38 100644 --- a/dev-libs/capstone/capstone-4.0.ebuild +++ b/dev-libs/capstone/capstone-4.0-r1.ebuild @@ -19,32 +19,3 @@ PDEPEND="python? ( >=dev-python/capstone-python-${PV} )" RDEPEND="" DEPEND="${RDEPEND}" #TODO: add java and ocaml bindings - -PATCHES=( -# "${FILESDIR}/capstone-calloc.patch" -# "${FILESDIR}/fix-m68k-oob.patch" -# "${FILESDIR}/fix-underflow-tms.patch" - "${FILESDIR}/fix-x86-16.patch" - "${FILESDIR}/sparc-crash.patch" - "${FILESDIR}/sstream-null.patch" -) - -#src_configure() { -# { -# cat <<-EOF -# # Gentoo overrides: -# # verbose build -# V = 1 -# # toolchain -# AR = $(tc-getAR) -# CC = $(tc-getCC) -# RANLIB = $(tc-getRANLIB) -# # toolchain flags -# CFLAGS = ${CFLAGS} -# LDFLAGS = ${LDFLAGS} -# # libs -# LIBDIRARCH = $(get_libdir) -# EOF -# } >> config.mk || die - -#} diff --git a/dev-libs/capstone/files/capstone-calloc.patch b/dev-libs/capstone/files/capstone-calloc.patch deleted file mode 100644 index 08191862f..000000000 --- a/dev-libs/capstone/files/capstone-calloc.patch +++ /dev/null @@ -1,60 +0,0 @@ -diff --git a/MCInst.c b/MCInst.c -index cc062d00..3f75de3b 100644 ---- a/MCInst.c -+++ b/MCInst.c -@@ -16,15 +16,7 @@ - - void MCInst_Init(MCInst *inst) - { -- inst->Opcode = 0; -- inst->OpcodePub = 0; -- inst->size = 0; -- inst->has_imm = false; -- inst->op1_size = 0; -- inst->writeback = false; -- inst->ac_idx = 0; -- inst->popcode_adjust = 0; -- inst->assembly[0] = '\0'; -+ memset (inst, 0, sizeof (MCInst)); - } - - void MCInst_clear(MCInst *inst) -diff --git a/cs.c b/cs.c -index 449b1da5..fe87a318 100644 ---- a/cs.c -+++ b/cs.c -@@ -641,7 +641,7 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64 - size_org = size; - - total_size = sizeof(cs_insn) * cache_size; -- total = cs_mem_malloc(total_size); -+ total = cs_mem_calloc(1, total_size); - if (total == NULL) { - // insufficient memory - handle->errnum = CS_ERR_MEM; -@@ -659,7 +659,7 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64 - - if (handle->detail) { - // allocate memory for @detail pointer -- insn_cache->detail = cs_mem_malloc(sizeof(cs_detail)); -+ insn_cache->detail = cs_mem_calloc(1, sizeof(cs_detail)); - } else { - insn_cache->detail = NULL; - } -@@ -747,6 +747,7 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64 - if (f == cache_size) { - // full cache, so expand the cache to contain incoming insns - cache_size = cache_size * 8 / 5; // * 1.6 ~ golden ratio -+ unsigned int old_size = total_size; - total_size += (sizeof(cs_insn) * cache_size); - tmp = cs_mem_realloc(total, total_size); - if (tmp == NULL) { // insufficient memory -@@ -761,7 +762,7 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64 - handle->errnum = CS_ERR_MEM; - return 0; - } -- -+ memset (total + (sizeof(cs_insn) * old_size), 0, (total_size - old_size)); - total = tmp; - // continue to fill in the cache after the last instruction - insn_cache = (cs_insn *)((char *)total + sizeof(cs_insn) * c); diff --git a/dev-libs/capstone/files/fix-m68k-oob.patch b/dev-libs/capstone/files/fix-m68k-oob.patch deleted file mode 100644 index d52a965a2..000000000 --- a/dev-libs/capstone/files/fix-m68k-oob.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/arch/M68K/M68KInstPrinter.c b/arch/M68K/M68KInstPrinter.c -index c545115..aec6a05 100644 ---- a/arch/M68K/M68KInstPrinter.c -+++ b/arch/M68K/M68KInstPrinter.c -@@ -28,7 +28,8 @@ - #ifndef CAPSTONE_DIET - static const char* s_spacing = " "; - --static const char* s_reg_names[] = { -+#define S_REG_NAMES_COUNT 47 -+static const char* s_reg_names[S_REG_NAMES_COUNT] = { - "invalid", - "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", - "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", -@@ -326,6 +327,9 @@ const char* M68K_reg_name(csh handle, unsigned int reg) - #ifdef CAPSTONE_DIET - return NULL; - #else -+ if (reg >= S_REG_NAMES_COUNT) { -+ return NULL; -+ } - return s_reg_names[(int)reg]; - #endif - } diff --git a/dev-libs/capstone/files/fix-underflow-tms.patch b/dev-libs/capstone/files/fix-underflow-tms.patch deleted file mode 100644 index 7eab2ae5e..000000000 --- a/dev-libs/capstone/files/fix-underflow-tms.patch +++ /dev/null @@ -1,28 +0,0 @@ -diff --git a/arch/TMS320C64x/TMS320C64xInstPrinter.c b/arch/TMS320C64x/TMS320C64xInstPrinter.c -index fa57893..d6e9896 100644 ---- a/arch/TMS320C64x/TMS320C64xInstPrinter.c -+++ b/arch/TMS320C64x/TMS320C64xInstPrinter.c -@@ -70,15 +70,14 @@ void TMS320C64x_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci) - if((p != NULL) && (((p2 = strchr(p, '[')) != NULL) || ((p2 = strchr(p, '(')) != NULL))) { - while((p2 > p) && ((*p2 != 'A') && (*p2 != 'B'))) - p2--; -- if(p2 == p) { -- strcpy(insn_asm, "Invalid!"); -- return; -- } else { -- if(*p2 == 'A') -- strcpy(tmp, "1T"); -- else -- strcpy(tmp, "2T"); -- } -+ if(p2 <= p) { -+ strcpy(insn_asm, "Invalid!"); -+ return; -+ } -+ if(*p2 == 'A') -+ strcpy(tmp, "1T"); -+ else -+ strcpy(tmp, "2T"); - } else { - tmp[0] = '\0'; - } diff --git a/dev-libs/capstone/files/fix-x86-16.patch b/dev-libs/capstone/files/fix-x86-16.patch deleted file mode 100644 index ef24b51ac..000000000 --- a/dev-libs/capstone/files/fix-x86-16.patch +++ /dev/null @@ -1,30 +0,0 @@ -diff --git a/arch/X86/X86ATTInstPrinter.c b/arch/X86/X86ATTInstPrinter.c -index 7e19b4e..062eef8 100644 ---- a/arch/X86/X86ATTInstPrinter.c -+++ b/arch/X86/X86ATTInstPrinter.c -@@ -576,6 +576,10 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O) - if (MI->Opcode == X86_CALLpcrel16 || MI->Opcode == X86_JMP_2) - imm = imm & 0xffff; - -+ if (MI->csh->mode == CS_MODE_16) { -+ imm |= (MI->address >> 16) << 16; -+ } -+ - if (imm < 0) { - SStream_concat(O, "0x%"PRIx64, imm); - } else { -diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c -index c455725..eb60586 100644 ---- a/arch/X86/X86IntelInstPrinter.c -+++ b/arch/X86/X86IntelInstPrinter.c -@@ -756,6 +756,10 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O) - if (MI->Opcode == X86_CALLpcrel16 || MI->Opcode == X86_JMP_2) - imm = imm & 0xffff; - -+ if (MI->csh->mode == CS_MODE_16) { -+ imm |= (MI->address >> 16) << 16; -+ } -+ - printImm(MI->csh->syntax, O, imm, true); - - if (MI->csh->detail) { diff --git a/dev-libs/capstone/files/pull939.patch b/dev-libs/capstone/files/pull939.patch deleted file mode 100644 index c45f7a174..000000000 --- a/dev-libs/capstone/files/pull939.patch +++ /dev/null @@ -1,215 +0,0 @@ -From 711a9ee48751fcdd2826591df043e6867f425f0c Mon Sep 17 00:00:00 2001 -From: mrmacete -Date: Wed, 31 May 2017 09:27:08 +0200 -Subject: [PATCH] Add CS_MODE_MIPS2 to opt-in for COP3 instructions - ---- - arch/Mips/MipsDisassembler.c | 2 +- - arch/Mips/MipsModule.c | 3 ++- - bindings/java/capstone/Capstone.java | 1 + - bindings/ocaml/capstone.ml | 1 + - bindings/ocaml/ocaml.c | 22 ++++++++++++++-------- - bindings/python/capstone/__init__.py | 2 ++ - include/capstone/capstone.h | 1 + - tests/test_mips.c | 23 +++++++++++++++++++---- - 8 files changed, 41 insertions(+), 14 deletions(-) - -diff --git a/arch/Mips/MipsDisassembler.c b/arch/Mips/MipsDisassembler.c -index 846115f72..dfc07eed3 100644 ---- a/arch/Mips/MipsDisassembler.c -+++ b/arch/Mips/MipsDisassembler.c -@@ -451,7 +451,7 @@ static DecodeStatus MipsDisassembler_getInstruction(int mode, MCInst *instr, - - readInstruction32((unsigned char*)code, &Insn, isBigEndian, false); - -- if (((mode & CS_MODE_MIPS32) == 0) && ((mode & CS_MODE_MIPS3) == 0)) { -+ if ((mode & CS_MODE_MIPS2) && ((mode & CS_MODE_MIPS3) == 0)) { - // DEBUG(dbgs() << "Trying COP3_ table (32-bit opcodes):\n"); - Result = decodeInstruction(DecoderTableCOP3_32, instr, Insn, Address, MRI, mode); - if (Result != MCDisassembler_Fail) { -diff --git a/arch/Mips/MipsModule.c b/arch/Mips/MipsModule.c -index 0b4a60f40..b74c27055 100644 ---- a/arch/Mips/MipsModule.c -+++ b/arch/Mips/MipsModule.c -@@ -15,7 +15,8 @@ static cs_err init(cs_struct *ud) - - // verify if requested mode is valid - if (ud->mode & ~(CS_MODE_LITTLE_ENDIAN | CS_MODE_32 | CS_MODE_64 | -- CS_MODE_MICRO | CS_MODE_MIPS32R6 | CS_MODE_BIG_ENDIAN)) -+ CS_MODE_MICRO | CS_MODE_MIPS32R6 | CS_MODE_BIG_ENDIAN | -+ CS_MODE_MIPS2 | CS_MODE_MIPS3)) - return CS_ERR_MODE; - - mri = cs_mem_malloc(sizeof(*mri)); -diff --git a/bindings/java/capstone/Capstone.java b/bindings/java/capstone/Capstone.java -index 2d49f9121..19fbd8a08 100644 ---- a/bindings/java/capstone/Capstone.java -+++ b/bindings/java/capstone/Capstone.java -@@ -336,6 +336,7 @@ public NativeLong cs_disasm(NativeLong handle, byte[] code, NativeLong code_len, - public static final int CS_MODE_MICRO = 1 << 4; // MicroMips mode (Mips arch) - public static final int CS_MODE_MIPS3 = 1 << 5; // Mips III ISA - public static final int CS_MODE_MIPS32R6 = 1 << 6; // Mips32r6 ISA -+ public static final int CS_MODE_MIPS2 = 1 << 7; // Mips II ISA - public static final int CS_MODE_BIG_ENDIAN = 1 << 31; // big-endian mode - public static final int CS_MODE_V9 = 1 << 4; // SparcV9 mode (Sparc arch) - public static final int CS_MODE_MIPS32 = CS_MODE_32; // Mips32 ISA -diff --git a/bindings/ocaml/capstone.ml b/bindings/ocaml/capstone.ml -index 6da4cba88..a81b90dd6 100644 ---- a/bindings/ocaml/capstone.ml -+++ b/bindings/ocaml/capstone.ml -@@ -35,6 +35,7 @@ type mode = - | CS_MODE_MICRO (* MicroMips mode (MIPS architecture) *) - | CS_MODE_MIPS3 (* Mips3 mode (MIPS architecture) *) - | CS_MODE_MIPS32R6 (* Mips32-R6 mode (MIPS architecture) *) -+ | CS_MODE_MIPS2 (* Mips2 mode (MIPS architecture) *) - | CS_MODE_V9 (* SparcV9 mode (Sparc architecture) *) - | CS_MODE_BIG_ENDIAN (* big-endian mode *) - | CS_MODE_MIPS32 (* Mips32 mode (for Mips) *) -diff --git a/bindings/ocaml/ocaml.c b/bindings/ocaml/ocaml.c -index 038daf8b7..4e2644162 100644 ---- a/bindings/ocaml/ocaml.c -+++ b/bindings/ocaml/ocaml.c -@@ -700,18 +700,21 @@ CAMLprim value ocaml_cs_disasm(value _arch, value _mode, value _code, value _add - mode |= CS_MODE_MIPS32R6; - break; - case 11: -- mode |= CS_MODE_V9; -+ mode |= CS_MODE_MIPS2; - break; - case 12: -- mode |= CS_MODE_BIG_ENDIAN; -+ mode |= CS_MODE_V9; - break; - case 13: -- mode |= CS_MODE_MIPS32; -+ mode |= CS_MODE_BIG_ENDIAN; - break; - case 14: -- mode |= CS_MODE_MIPS64; -+ mode |= CS_MODE_MIPS32; - break; - case 15: -+ mode |= CS_MODE_MIPS64; -+ break; -+ case 16: - mode |= CS_MODE_QPX; - break; - default: -@@ -831,18 +834,21 @@ CAMLprim value ocaml_open(value _arch, value _mode) - mode |= CS_MODE_MIPS32R6; - break; - case 11: -- mode |= CS_MODE_V9; -+ mode |= CS_MODE_MIPS2; - break; - case 12: -- mode |= CS_MODE_BIG_ENDIAN; -+ mode |= CS_MODE_V9; - break; - case 13: -- mode |= CS_MODE_MIPS32; -+ mode |= CS_MODE_BIG_ENDIAN; - break; - case 14: -- mode |= CS_MODE_MIPS64; -+ mode |= CS_MODE_MIPS32; - break; - case 15: -+ mode |= CS_MODE_MIPS64; -+ break; -+ case 16: - mode |= CS_MODE_QPX; - break; - default: -diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py -index 592b0eae6..a7c1453ab 100644 ---- a/bindings/python/capstone/__init__.py -+++ b/bindings/python/capstone/__init__.py -@@ -46,6 +46,7 @@ - 'CS_MODE_MICRO', - 'CS_MODE_MIPS3', - 'CS_MODE_MIPS32R6', -+ 'CS_MODE_MIPS2', - 'CS_MODE_V8', - 'CS_MODE_V9', - 'CS_MODE_QPX', -@@ -151,6 +152,7 @@ - CS_MODE_MICRO = (1 << 4) # MicroMips mode (MIPS architecture) - CS_MODE_MIPS3 = (1 << 5) # Mips III ISA - CS_MODE_MIPS32R6 = (1 << 6) # Mips32r6 ISA -+CS_MODE_MIPS2 = (1 << 7) # Mips II ISA - CS_MODE_V9 = (1 << 4) # Sparc V9 mode (for Sparc) - CS_MODE_QPX = (1 << 4) # Quad Processing eXtensions mode (PPC) - CS_MODE_M68K_000 = (1 << 1) # M68K 68000 mode -diff --git a/include/capstone/capstone.h b/include/capstone/capstone.h -index fc06307cb..e6a90b5fd 100644 ---- a/include/capstone/capstone.h -+++ b/include/capstone/capstone.h -@@ -109,6 +109,7 @@ typedef enum cs_mode { - CS_MODE_MICRO = 1 << 4, // MicroMips mode (MIPS) - CS_MODE_MIPS3 = 1 << 5, // Mips III ISA - CS_MODE_MIPS32R6 = 1 << 6, // Mips32r6 ISA -+ CS_MODE_MIPS2 = 1 << 7, // Mips II ISA - CS_MODE_V9 = 1 << 4, // SparcV9 mode (Sparc) - CS_MODE_QPX = 1 << 4, // Quad Processing eXtensions mode (PPC) - CS_MODE_M68K_000 = 1 << 1, // M68K 68000 mode -diff --git a/tests/test_mips.c b/tests/test_mips.c -index 9e2927c2b..2a7948b8c 100644 ---- a/tests/test_mips.c -+++ b/tests/test_mips.c -@@ -82,36 +82,51 @@ static void test() - #define MIPS_CODE2 "\x56\x34\x21\x34\xc2\x17\x01\x00" - #define MIPS_32R6M "\x00\x07\x00\x07\x00\x11\x93\x7c\x01\x8c\x8b\x7c\x00\xc7\x48\xd0" - #define MIPS_32R6 "\xec\x80\x00\x19\x7c\x43\x22\xa0" -+#define MIPS_64SD "\x70\x00\xb2\xff" - - struct platform platforms[] = { - { - CS_ARCH_MIPS, -- (cs_mode)(CS_MODE_MIPS32 + CS_MODE_BIG_ENDIAN), -+ (cs_mode)(CS_MODE_MIPS32 | CS_MODE_BIG_ENDIAN), - (unsigned char *)MIPS_CODE, - sizeof(MIPS_CODE) - 1, - "MIPS-32 (Big-endian)" - }, - { - CS_ARCH_MIPS, -- (cs_mode)(CS_MODE_MIPS64 + CS_MODE_LITTLE_ENDIAN), -+ (cs_mode)(CS_MODE_MIPS64 | CS_MODE_LITTLE_ENDIAN), - (unsigned char *)MIPS_CODE2, - sizeof(MIPS_CODE2) - 1, - "MIPS-64-EL (Little-endian)" - }, - { - CS_ARCH_MIPS, -- (cs_mode)(CS_MODE_MIPS32R6 + CS_MODE_MICRO + CS_MODE_BIG_ENDIAN), -+ (cs_mode)(CS_MODE_MIPS32R6 | CS_MODE_MICRO + CS_MODE_BIG_ENDIAN), - (unsigned char*)MIPS_32R6M, - sizeof(MIPS_32R6M) - 1, - "MIPS-32R6 | Micro (Big-endian)" - }, - { - CS_ARCH_MIPS, -- (cs_mode)(CS_MODE_MIPS32R6 + CS_MODE_BIG_ENDIAN), -+ (cs_mode)(CS_MODE_MIPS32R6 | CS_MODE_BIG_ENDIAN), - (unsigned char*)MIPS_32R6, - sizeof(MIPS_32R6) - 1, - "MIPS-32R6 (Big-endian)" - }, -+ { -+ CS_ARCH_MIPS, -+ (cs_mode)(CS_MODE_MIPS64 | CS_MODE_MIPS2 | CS_MODE_LITTLE_ENDIAN), -+ (unsigned char *)MIPS_64SD, -+ sizeof(MIPS_64SD) - 1, -+ "MIPS-64-EL + Mips II (Little-endian)" -+ }, -+ { -+ CS_ARCH_MIPS, -+ (cs_mode)(CS_MODE_MIPS64 | CS_MODE_LITTLE_ENDIAN), -+ (unsigned char *)MIPS_64SD, -+ sizeof(MIPS_64SD) - 1, -+ "MIPS-64-EL (Little-endian)" -+ }, - }; - - uint64_t address = 0x1000; diff --git a/dev-libs/capstone/files/sparc-crash.patch b/dev-libs/capstone/files/sparc-crash.patch deleted file mode 100644 index 8651b3923..000000000 --- a/dev-libs/capstone/files/sparc-crash.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/arch/Sparc/SparcGenAsmWriter.inc b/arch/Sparc/SparcGenAsmWriter.inc -index 9ed9760..9694d05 100644 ---- a/arch/Sparc/SparcGenAsmWriter.inc -+++ b/arch/Sparc/SparcGenAsmWriter.inc -@@ -1202,6 +1202,9 @@ static char *getRegisterName(unsigned RegNo) - //for (i = 0; i < sizeof(RegAsmOffset)/2; i++) - // printf("%s = %u\n", AsmStrs+RegAsmOffset[i], i + 1); - //printf("*************************\n"); -+if (RegNo < 1 || RegNo > sizeof (RegAsmOffset) / sizeof (*RegAsmOffset)) { -+ return NULL; -+} - return AsmStrs+RegAsmOffset[RegNo-1]; - #else - return NULL; diff --git a/dev-libs/capstone/files/sstream-null.patch b/dev-libs/capstone/files/sstream-null.patch deleted file mode 100644 index eddd8930f..000000000 --- a/dev-libs/capstone/files/sstream-null.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/SStream.c b/SStream.c -index c90cf1a..1686d5d 100644 ---- a/SStream.c -+++ b/SStream.c -@@ -28,6 +28,9 @@ void SStream_Init(SStream *ss) - void SStream_concat0(SStream *ss, char *s) - { - #ifndef CAPSTONE_DIET -+ if (!ss || !s) { -+ return; -+ } - unsigned int len = (unsigned int) strlen(s); - - memcpy(ss->buffer + ss->index, s, len);