Skip to content

Commit

Permalink
Add temporary patch to fix capstone x86-16 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Aug 13, 2015
1 parent 4275bfc commit 8293f75
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 54 deletions.
7 changes: 6 additions & 1 deletion shlr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CS_TIP=0088d2a318ff0abc37005d508692e95c2011b24e
# REVERT THIS COMMIT BECAUSE ITS WRONG
CS_REV=
#21b9b25e9dae4af0ef309d4089a54e53b8f5b479
CS_PATCHES=1

.PHONY: capstone-sync capstone-build all clean mrproper libgdbr libwind

Expand Down Expand Up @@ -203,6 +204,10 @@ capstone: capstone-sync

capstone-sync:
"$(SHELL)" capstone.sh "${CS_URL}" "${CS_BRA}" "${CS_TIP}" "${CS_REV}"
ifeq ($(CS_PATCHES),1)
cd capstone ; git reset --hard
cd capstone ; for a in ../capstone-patches/* ; do patch -p1 < $$a ; done
endif

.PHONY: capstone
else
Expand All @@ -216,7 +221,7 @@ capstone: capstone-$(CS_VER).tar.gz
tar xzvf capstone-$(CS_VER).tar.gz
rm -rf capstone
mv capstone-$(CS_VER) capstone
#cd capstone ; for a in ../capstone-patches/* ; do patch -p1 < $$a ; done
cd capstone ; for a in ../capstone-patches/* ; do patch -p1 < $$a ; done

capstone-$(CS_VER).tar.gz:
$(WGET) --no-check-certificate -O capstone-$(CS_VER).tar.gz -c $(CS_TAR)
Expand Down
52 changes: 0 additions & 52 deletions shlr/capstone-patches/0001-Avoid-c99-features.patch

This file was deleted.

32 changes: 32 additions & 0 deletions shlr/capstone-patches/fix-x86-16.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/arch/X86/X86ATTInstPrinter.c b/arch/X86/X86ATTInstPrinter.c
index 12dfdae..134e182 100644
--- a/arch/X86/X86ATTInstPrinter.c
+++ b/arch/X86/X86ATTInstPrinter.c
@@ -529,8 +529,10 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O)
SStream_concat(O, "0x%"PRIx64, imm);
} else {
// handle 16bit segment bound
- if (MI->csh->mode == CS_MODE_16)
+ if (MI->csh->mode == CS_MODE_16) {
imm = imm & 0xffff;
+ imm |= (MI->address >> 16) << 16;
+ }

if (imm > HEX_THRESHOLD)
SStream_concat(O, "0x%"PRIx64, imm);
diff --git a/arch/X86/X86IntelInstPrinter.c b/arch/X86/X86IntelInstPrinter.c
index 9854b98..9167b45 100644
--- a/arch/X86/X86IntelInstPrinter.c
+++ b/arch/X86/X86IntelInstPrinter.c
@@ -693,8 +693,10 @@ static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O)
imm = imm & 0xffffffff;
}

- if (MI->csh->mode == CS_MODE_16)
+ if (MI->csh->mode == CS_MODE_16) {
imm = imm & 0xffff;
+ imm |= (MI->address >> 16) << 16;
+ }

printImm(MI->csh->syntax, O, imm, true);

2 changes: 1 addition & 1 deletion shlr/capstone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else
if [ -n "${CS_REV}" ]; then
HEAD="`git log|grep ^commit | head -n2|tail -n1 | awk '{print $2}'`"
else
HEAD="`git log|head -n1 awk '{print $2}'`"
HEAD="`git log|head -n1 | awk '{print $2}'`"
fi
if [ "${HEAD}" = "${CS_TIP}" ]; then
echo "[capstone] Already in TIP, no need to update from git"
Expand Down

0 comments on commit 8293f75

Please sign in to comment.