arm64: fix immediate number in detail mode. see #860
diff --git a/arch/AArch64/AArch64Disassembler.c b/arch/AArch64/AArch64Disassembler.c
index ee2cbdc..56a14a8 100644
--- a/arch/AArch64/AArch64Disassembler.c
+++ b/arch/AArch64/AArch64Disassembler.c
@@ -1006,7 +1006,7 @@
 	bool IsFP;
 	unsigned Rt = fieldFromInstruction(insn, 0, 5);
 	unsigned Rn = fieldFromInstruction(insn, 5, 5);
-	int32_t offset = fieldFromInstruction(insn, 12, 9);
+	int64_t offset = fieldFromInstruction(insn, 12, 9);
 
 	// offset is a 9-bit signed immediate, so sign extend it to
 	// fill the unsigned.
@@ -1269,7 +1269,7 @@
 	unsigned Rt = fieldFromInstruction(insn, 0, 5);
 	unsigned Rn = fieldFromInstruction(insn, 5, 5);
 	unsigned Rt2 = fieldFromInstruction(insn, 10, 5);
-	int32_t offset = fieldFromInstruction(insn, 15, 7);
+	int64_t offset = fieldFromInstruction(insn, 15, 7);
 	bool IsLoad = fieldFromInstruction(insn, 22, 1) != 0;
 	unsigned Opcode = MCInst_getOpcode(Inst);
 	bool NeedsDisjointWritebackTransfer = false;
@@ -1547,8 +1547,7 @@
 		uint64_t Addr, void *Decoder)
 {
 	unsigned Rd = fieldFromInstruction(insn, 0, 5);
-	int32_t imm = fieldFromInstruction(insn, 5, 19) << 2;
-
+	int64_t imm = fieldFromInstruction(insn, 5, 19) << 2;
 	imm |= fieldFromInstruction(insn, 29, 2);
 
 	// Sign-extend the 21-bit immediate.
@@ -1601,7 +1600,7 @@
 		uint64_t Addr,
 		void *Decoder)
 {
-	int32_t imm = fieldFromInstruction(insn, 0, 26);
+	int64_t imm = fieldFromInstruction(insn, 0, 26);
 
 	// Sign-extend the 26-bit immediate.
 	if (imm & (1 << (26 - 1)))
@@ -1617,11 +1616,11 @@
 		uint32_t insn, uint64_t Addr,
 		void *Decoder)
 {
-	uint32_t op1 = fieldFromInstruction(insn, 16, 3);
-	uint32_t op2 = fieldFromInstruction(insn, 5, 3);
-	uint32_t crm = fieldFromInstruction(insn, 8, 4);
+	uint64_t op1 = fieldFromInstruction(insn, 16, 3);
+	uint64_t op2 = fieldFromInstruction(insn, 5, 3);
+	uint64_t crm = fieldFromInstruction(insn, 8, 4);
 	bool ValidNamed;
-	uint32_t pstate_field = (op1 << 3) | op2;
+	uint64_t pstate_field = (op1 << 3) | op2;
 
 	MCOperand_CreateImm0(Inst, pstate_field);
 	MCOperand_CreateImm0(Inst, crm);
@@ -1634,9 +1633,9 @@
 static DecodeStatus DecodeTestAndBranch(MCInst *Inst, uint32_t insn,
 		uint64_t Addr, void *Decoder)
 {
-	uint32_t Rt = fieldFromInstruction(insn, 0, 5);
-	uint32_t bit = fieldFromInstruction(insn, 31, 1) << 5;
-	int32_t dst = fieldFromInstruction(insn, 5, 14);
+	uint64_t Rt = fieldFromInstruction(insn, 0, 5);
+	uint64_t bit = fieldFromInstruction(insn, 31, 1) << 5;
+	int64_t dst = fieldFromInstruction(insn, 5, 14);
 
 	bit |= fieldFromInstruction(insn, 19, 5);
 
diff --git a/arch/AArch64/AArch64InstPrinter.c b/arch/AArch64/AArch64InstPrinter.c
index 123e69b..fa99f97 100644
--- a/arch/AArch64/AArch64InstPrinter.c
+++ b/arch/AArch64/AArch64InstPrinter.c
@@ -136,8 +136,8 @@
 		if (MCOperand_isImm(Op2) && MCOperand_isImm(Op3)) {
 			char *AsmMnemonic = NULL;
 			int shift = 0;
-			int immr = (int)MCOperand_getImm(Op2);
-			int imms = (int)MCOperand_getImm(Op3);
+			int64_t immr = MCOperand_getImm(Op2);
+			int64_t imms = MCOperand_getImm(Op3);
 
 			if (Opcode == AArch64_UBFMWri && imms != 0x1F && ((imms + 1) == immr)) {
 				AsmMnemonic = "lsl";
@@ -207,7 +207,7 @@
 				MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (Is64Bit ? 64 : 32) - (int)MCOperand_getImm(Op2);
 				MI->flat_insn->detail->arm64.op_count++;
 				MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
-				MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)MCOperand_getImm(Op3) + 1;
+				MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op3) + 1;
 				MI->flat_insn->detail->arm64.op_count++;
 			}
 
@@ -232,10 +232,10 @@
 			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op1);
 			MI->flat_insn->detail->arm64.op_count++;
 			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
-			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)MCOperand_getImm(Op2);
+			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op2);
 			MI->flat_insn->detail->arm64.op_count++;
 			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
-			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)MCOperand_getImm(Op3) - (int)MCOperand_getImm(Op2) + 1;
+			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op3) - MCOperand_getImm(Op2) + 1;
 			MI->flat_insn->detail->arm64.op_count++;
 		}
 
@@ -631,7 +631,7 @@
 	SStream_concat(O, "#%#llx", MCOperand_getImm(Op));
 	if (MI->csh->detail) {
 		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
-		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)MCOperand_getImm(Op);
+		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op);
 		MI->flat_insn->detail->arm64.op_count++;
 	}
 }
@@ -687,7 +687,7 @@
 	SStream_concat(O, "c%u", MCOperand_getImm(Op));
 	if (MI->csh->detail) {
 		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_CIMM;
-		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)MCOperand_getImm(Op);
+		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op);
 		MI->flat_insn->detail->arm64.op_count++;
 	}
 }
@@ -715,14 +715,14 @@
 
 static void printLogicalImm32(MCInst *MI, unsigned OpNum, SStream *O)
 {
-	int64_t Val = (int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
+	int64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
 
 	Val = AArch64_AM_decodeLogicalImmediate(Val, 32);
 	printUInt32Bang(O, (int)Val);
 
 	if (MI->csh->detail) {
 		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
-		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)Val;
+		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val;
 		MI->flat_insn->detail->arm64.op_count++;
 	}
 }
@@ -750,7 +750,7 @@
 
 	if (MI->csh->detail) {
 		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
-		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)Val;
+		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val;
 		MI->flat_insn->detail->arm64.op_count++;
 	}
 }
@@ -974,10 +974,10 @@
 
 	if (MI->csh->detail) {
 		if (MI->csh->doing_mem) {
-			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = (int)val;
+			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = val;
 		} else {
 			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
-			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)val;
+			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = val;
 			MI->flat_insn->detail->arm64.op_count++;
 		}
 	}
@@ -992,10 +992,10 @@
 		printInt64Bang(O, val);
 		if (MI->csh->detail) {
 			if (MI->csh->doing_mem) {
-				MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = (int)val;
+				MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = val;
 			} else {
 			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
-			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)val;
+			MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = val;
 			MI->flat_insn->detail->arm64.op_count++;
 			}
 		}
@@ -1375,7 +1375,7 @@
 	SStream_concat(O, "#%#016llx", Val);
 	if (MI->csh->detail) {
 		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
-		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)Val;
+		MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val;
 		MI->flat_insn->detail->arm64.op_count++;
 	}
 }
diff --git a/arch/ARM/ARMInstPrinter.c b/arch/ARM/ARMInstPrinter.c
index 8e34dec..69d2b88 100644
--- a/arch/ARM/ARMInstPrinter.c
+++ b/arch/ARM/ARMInstPrinter.c
@@ -1466,7 +1466,7 @@
 {
 	MCOperand *Op = MCInst_getOperand(MI, OpNum);
 	unsigned SpecRegRBit = (unsigned)MCOperand_getImm(Op) >> 4;
-	unsigned Mask = MCOperand_getImm(Op) & 0xf;
+	unsigned Mask = (unsigned)MCOperand_getImm(Op) & 0xf;
 	unsigned reg;
 
 	if (ARM_getFeatureBits(MI->csh->mode) & ARM_FeatureMClass) {