Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Feb 25, 2014
2 parents d8d574b + 4ef1668 commit 2311893
Show file tree
Hide file tree
Showing 100 changed files with 375,961 additions and 2,145,731 deletions.
2 changes: 1 addition & 1 deletion CONFIG
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package version

#define PKG_MAJOR 2
#define PKG_MINOR 0
#define PKG_MINOR 1


1 change: 1 addition & 0 deletions LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
This is the software license for Capstone disassembly framework.
Capstone has been designed & implemented by Nguyen Anh Quynh <[email protected]>

See http://www.capstone-engine.org for further information.

Copyright (c) 2013, COSEINC.
Expand Down
1 change: 0 additions & 1 deletion MCInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ struct MCInst {
cs_insn_flat flat_insn; // insn to be exposed to public
unsigned OpcodePub;
int insn_size; // instruction size
int x86_segment; // remove when segment mem ref hack is redundant.
uint64_t address; // address of this insn
cs_struct *csh; // save the main csh
};
Expand Down
8 changes: 5 additions & 3 deletions MCRegisterInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ static uint16_t DiffListIterator_getVal(DiffListIterator *d)

static bool DiffListIterator_next(DiffListIterator *d)
{
MCPhysReg D;

if (d->List == 0)
return false;

MCPhysReg D = *d->List;
D = *d->List;
d->List++;
d->Val += D;

Expand All @@ -89,7 +91,7 @@ unsigned MCRegisterInfo_getMatchingSuperReg(MCRegisterInfo *RI, unsigned Reg, un
return 0;
}

DiffListIterator_init(&iter, Reg, RI->DiffLists + RI->Desc[Reg].SuperRegs);
DiffListIterator_init(&iter, (MCPhysReg)Reg, RI->DiffLists + RI->Desc[Reg].SuperRegs);
DiffListIterator_next(&iter);

while(DiffListIterator_isValid(&iter)) {
Expand All @@ -108,7 +110,7 @@ unsigned MCRegisterInfo_getSubReg(MCRegisterInfo *RI, unsigned Reg, unsigned Idx
DiffListIterator iter;
uint16_t *SRI = RI->SubRegIndices + RI->Desc[Reg].SubRegIndices;

DiffListIterator_init(&iter, Reg, RI->DiffLists + RI->Desc[Reg].SubRegs);
DiffListIterator_init(&iter, (MCPhysReg)Reg, RI->DiffLists + RI->Desc[Reg].SubRegs);
DiffListIterator_next(&iter);

while(DiffListIterator_isValid(&iter)) {
Expand Down
34 changes: 29 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,19 @@ endif
LIBOBJ += MCInst.o

UNAME_S := $(shell uname -s)
PKGCFCGDIR = $(LIBDIR)/pkgconfig

# OSX?
ifeq ($(UNAME_S),Darwin)
EXT = dylib
AR_EXT = a
# By default, suppose that Brew is installed & use Brew path for pkgconfig file
PKGCFCGDIR = /usr/local/lib/pkgconfig
# is Macport installed instead?
ifneq (,$(wildcard /opt/local/bin/port))
# then correct the path for pkgconfig file
PKGCFCGDIR = /opt/local/lib/pkgconfig
endif
else
# Cygwin?
IS_CYGWIN := $(shell $(CC) -dumpmachine | grep -i cygwin | wc -l)
Expand Down Expand Up @@ -126,15 +135,30 @@ PKGCFGF = $(LIBNAME).pc

VERSION=$(shell echo `grep -e PKG_MAJOR -e PKG_MINOR CONFIG | grep -v = | awk '{print $$3}'` | awk '{print $$1"."$$2}')

.PHONY: all clean install uninstall
.PHONY: all clean install uninstall diet dist

all: $(LIBRARY) $(ARCHIVE) $(PKGCFGF)
$(MAKE) -C tests
$(INSTALL_DATA) lib$(LIBNAME).$(EXT) tests

$(LIBRARY): $(LIBOBJ)
$(LIBRARY): diet $(LIBOBJ)
$(CC) $(LDFLAGS) $(LIBOBJ) -o $(LIBRARY)

# generate include/diet.h
diet:
@echo "#ifndef CAPSTONE_DIET_H" > include/diet.h
@echo "#define CAPSTONE_DIET_H" >> include/diet.h
@echo "" >> include/diet.h
@echo "// File auto-generated by Makefile for Capstone framework. DO NOT MODIFY!" >> include/diet.h
@echo "" >> include/diet.h
ifneq (,$(findstring yes,$(CAPSTONE_DIET)))
@echo "#define CAPSTONE_DIET" >> include/diet.h
else
@echo "#undef CAPSTONE_DIET" >> include/diet.h
endif
@echo "" >> include/diet.h
@echo "#endif" >> include/diet.h

$(ARCHIVE): $(LIBOBJ)
rm -f $(ARCHIVE)
$(AR) q $(ARCHIVE) $(LIBOBJ)
Expand All @@ -156,14 +180,14 @@ install: $(PKGCFGF) $(ARCHIVE) $(LIBRARY)
$(INSTALL_DATA) lib$(LIBNAME).$(AR_EXT) $(LIBDIR)
mkdir -p $(INCDIR)/$(LIBNAME)
$(INSTALL_DATA) include/*.h $(INCDIR)/$(LIBNAME)
mkdir -p $(LIBDIR)/pkgconfig
$(INSTALL_DATA) $(PKGCFGF) $(LIBDIR)/pkgconfig/
mkdir -p $(PKGCFCGDIR)
$(INSTALL_DATA) $(PKGCFGF) $(PKGCFCGDIR)/

uninstall:
rm -rf $(INCDIR)/$(LIBNAME)
rm -f $(LIBDIR)/lib$(LIBNAME).$(EXT)
rm -f $(LIBDIR)/lib$(LIBNAME).$(AR_EXT)
rm -f $(LIBDIR)/pkgconfig/$(LIBNAME).pc
rm -f $(PKGCFCGDIR)/$(LIBNAME).pc

clean:
rm -f $(LIBOBJ) lib$(LIBNAME).*
Expand Down
11 changes: 8 additions & 3 deletions MathExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ static inline unsigned CountLeadingZeros_64(uint64_t Value) {
#endif
Count = __builtin_clzll(Value);
#else
if (sizeof(long) == sizeof(int64_t)) {
#ifndef _MSC_VER
if (sizeof(long) == sizeof(int64_t))
{
if (!Value) return 64;
Count = 0;
// bisection method for count leading zeros
Expand All @@ -143,7 +145,10 @@ static inline unsigned CountLeadingZeros_64(uint64_t Value) {
Count |= Shift;
}
}
} else {
}
else
#endif
{
// get hi portion
uint32_t Hi = Hi_32(Value);

Expand Down Expand Up @@ -250,7 +255,7 @@ static inline unsigned CountPopulation_64(uint64_t Value) {
uint64_t v = Value - ((Value >> 1) & 0x5555555555555555ULL);
v = (v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL);
v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL;
return unsigned((uint64_t)(v * 0x0101010101010101ULL) >> 56);
return (uint64_t)((v * 0x0101010101010101ULL) >> 56);
#endif
}

Expand Down
10 changes: 0 additions & 10 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
Version 2.0 has a known X86 issue: if you disassemble a buffer of instructions
that having the first byte as a prefix (LOCK, REP, REPNE), and you only
get 1 instruction (passing 1 as value for the 'count' argument), then only
the prefix will be returned as instruction.

An work-around is to disassemble the whole buffer & get out the first
instruction, then this instruction would properly include both prefix and
the next instruction.

This issue will be fixed in the next version.
2 changes: 2 additions & 0 deletions SStream.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ void SStream_Init(SStream *ss)

void SStream_concat(SStream *ss, const char *fmt, ...)
{
#ifndef CAPSTONE_DIET
va_list ap;

va_start(ap, fmt);
int ret = cs_vsnprintf(ss->buffer + ss->index, sizeof(ss->buffer) - (ss->index + 1), fmt, ap);
va_end(ap);
ss->index += ret;
#endif
}

/*
Expand Down
4 changes: 2 additions & 2 deletions arch/AArch64/AArch64BaseInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static bool compare_lower_str(char *s1, char *s2)
{
char *lower = cs_strdup(s2), *c;
for (c = lower; *c; c++)
*c = tolower((int) *c);
*c = (char)tolower((int) *c);

bool res = (strcmp(s1, lower) == 0);
cs_mem_free(lower);
Expand All @@ -60,7 +60,7 @@ uint32_t NamedImmMapper_fromString(NamedImmMapper *N, char *Name, bool *Valid)
}

*Valid = false;
return -1;
return (uint32_t)-1;
}

bool NamedImmMapper_validImm(NamedImmMapper *N, uint32_t Value)
Expand Down
Loading

0 comments on commit 2311893

Please sign in to comment.