diff --git a/.gitignore b/.gitignore index e9062f2b1c..170529961b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ clang-log/ *.sdb *.dylib *.dll +*.lib +*.obj +*.ilk *.dSYM supported.* config.mk @@ -17,6 +20,9 @@ langs.cfg .*.swp .*.swo *.un~ +*.pdb +*.lib +*.ilk binr/r2agent/r2agent binr/r2agent/r2agent.exe binr/rabin2/rabin2 @@ -46,7 +52,6 @@ libr/config.h libr/include/r_userconf.h libr/include/r_version.h libr/include/r_version.h.tmp -shlr/grub/libgrubfs.lib shlr/java/out shlr/java/out.exe shlr/sdb/sdb @@ -58,7 +63,6 @@ shlr/sdb/src/.sdb.exe shlr/sdb/src/sdb-version.h shlr/sdb/src/sdb_version.h shlr/sdb/src/libsdb.so* -shlr/sdb/src/libsdb.lib shlr/spp/config.h shlr/capstone/ sys/.mark_python-deps diff --git a/binr/rules.mk b/binr/rules.mk index fdc515cbce..7a47347d15 100644 --- a/binr/rules.mk +++ b/binr/rules.mk @@ -23,7 +23,7 @@ BEXE=${BIN}${EXT_EXE} ifeq ($(WITHNONPIC),1) ## LDFLAGS+=$(addsuffix /lib${BINDEPS}.a,$(addprefix ../../libr/,$(subst r_,,$(BINDEPS)))) -LDFLAGS+=$(shell for a in ${BINDEPS} ; do b=`echo $$a |sed -e s,r_,,g`; echo ../../libr/$$b/lib$$a.a ; done ) +LDFLAGS+=$(shell for a in ${BINDEPS} ; do b=`echo $$a |sed -e s,r_,,g`; echo ../../libr/$$b/lib$$a.${EXT_AR} ; done ) LDFLAGS+=../../shlr/sdb/src/libsdb.a LDFLAGS+=../../shlr/grub/libgrubfs.a LDFLAGS+=../../shlr/gdb/lib/libgdbr.a @@ -33,13 +33,17 @@ LDFLAGS+=../../shlr/java/libr_java.a LDFLAGS+=../../libr/util/libr_util.a ifneq (${ANDROID},1) ifneq (${OSTYPE},linux) +ifneq ($(CC),cccl) LDFLAGS+=-lpthread endif endif +endif ifneq (${OSTYPE},haiku) +ifneq ($(CC),cccl) LDFLAGS+=-lm endif endif +endif LDFLAGS+=${DL_LIBS} LDFLAGS+=${LINK} diff --git a/configure b/configure index 5204570d6e..0339ace1b3 100755 --- a/configure +++ b/configure @@ -434,7 +434,6 @@ if [ $? = 0 ]; then echo yes; HAVE_PKGCFG_CAPSTONE=1; CAPSTONE_LDFLAGS=$tmp; fi; fi if [ 11 = "$WITH_CAPSTONE$HAVE_PKGCFG_CAPSTONE" ]; then - USE_CAPSTONE="1" else USE_CAPSTONE="0"; fi diff --git a/libr/Makefile b/libr/Makefile index 619bd86354..c1f29d49fb 100644 --- a/libr/Makefile +++ b/libr/Makefile @@ -34,7 +34,7 @@ all: ${MAKE} $(LIBS6) ${MAKE} $(LIBS7) ifeq (${WITHNONPIC},1) - ${MAKE} libr.a + ${MAKE} libr.${EXT_AR} endif # looks hacky :D @@ -42,10 +42,10 @@ endif S=$ B=` -libr.a: +libr.${EXT_AR}: rm -rf .libr mkdir .libr - for FILE in */libr_*.a ../shlr/*/*.a ; do \ + for FILE in */libr_*.${EXT_AR} ../shlr/*/*.${EXT_AR} ; do \ F=${B}basename $$FILE${B} ; \ Q=${B}dirname $$FILE${B} ; \ D=${B}basename $$Q${B} ; \ @@ -55,11 +55,11 @@ libr.a: (cd .libr/$$D && ${AR} x $$F || true ) ; \ done echo lets ar - cd .libr ; ${AR} qv libr.a `find * -iname *.o 2> /dev/null` + cd .libr ; ${AR} qv libr.${EXT_AR} `find * -iname *.${EXT_AR} 2> /dev/null` echo lets m - mv .libr/libr.a libr.a + mv .libr/libr.${EXT_AR} libr.${EXT_AR} echo ranlibin - ${RANLIB} libr.a + ${RANLIB} libr.${EXT_AR} rm -rf .libr __AR=xcrun --sdk iphoneos ar @@ -67,21 +67,21 @@ __RANLIB=xcrun --sdk iphoneos ranlib a: rm -rf .libr mkdir .libr - for FILE in */libr_*.a ; do \ + for FILE in */libr_*.${EXT_AR} ; do \ mkdir -p .libr/$$FILE ; \ cp -f $$FILE .libr/$$FILE ; \ - (cd .libr/$$FILE ; ${__AR} x *.a ; rm -f *.a ) ; \ + (cd .libr/$$FILE ; ${__AR} x *.${EXT_AR} ; rm -f *.${EXT_AR} ) ; \ done - cd .libr ; ${__AR} qv libr.a `find * -iname *.o` - mv .libr/libr.a libr.a - ${__RANLIB} libr.a - lipo -info libr.a + cd .libr ; ${__AR} qv libr.${EXT_AR} `find * -iname *.o` + mv .libr/libr.${EXT_AR} libr.${EXT_AR} + ${__RANLIB} libr.${EXT_AR} + lipo -info libr.${EXT_AR} rm -rf .libr -gnu_libr.a: $(shell ls */libr_*.a 2>/dev/null) - rm -f libr.a - echo CREATE libr.a > libr.m - for FILE in */libr_*.a ; do echo ADDLIB $$FILE >> libr.m ; done +gnu_libr.${EXT_AR}: $(shell ls */libr_*.${EXT_AR} 2>/dev/null) + rm -f libr. + echo CREATE libr.${EXT_AR} > libr.m + for FILE in */libr_*.${EXT_AR} ; do echo ADDLIB $$FILE >> libr.m ; done echo SAVE >> libr.m # ar -M is a gnu-ism .. try to find a proper portable way to do that ${CC_AR} -M < libr.m @@ -158,7 +158,7 @@ install: install-includes install-pkgconfig ( cd "${DESTDIR}${LIBDIR}" ; ln -fs "$(call libpath-to-name-version,$(lib),${LIBVERSION})" "$(call libpath-to-name,$(lib))" ) ; \ ) # object archives - @for FILE in `find * -type f -iname "*.a" | grep -v fs/p` ; do \ + @for FILE in `find * -type f -iname "*.${EXT_AR}" | grep -v fs/p` ; do \ echo " ${DESTDIR}${LIBDIR}/$$FILE"; ${INSTALL_DATA} $$FILE "${DESTDIR}${LIBDIR}" ; done || true # plugins @${INSTALL_DIR} "${DESTDIR}${LIBDIR}/radare2/${VERSION}" @@ -176,7 +176,7 @@ deinstall uninstall: FILE=`echo $$FILE | awk -F / '{ print $$NF; }'`; \ echo "${DESTDIR}${LIBDIR}/$$FILE" ; rm -f "${DESTDIR}${LIBDIR}/$$FILE" ; done # object archives - -@for FILE in `find * | grep -e '\.a$$'` ; do \ + -@for FILE in `find * | grep -e '\.${EXT_AR}$$'` ; do \ FILE=`echo $$FILE | awk -F / '{ print $$NF; }'`; \ echo "${DESTDIR}${LIBDIR}/$$FILE" ; rm -f "${DESTDIR}${LIBDIR}/$$FILE" ; done # includes @@ -203,11 +203,11 @@ deinstall uninstall: rm -rf "${DESTDIR}${LIBDIR}/libr_*.so.${LIBVERSION}" rm -rf "${DESTDIR}${LIBDIR}/libr_*.so.0" rm -rf "${DESTDIR}${LIBDIR}/libr_*.so" - rm -rf "${DESTDIR}${LIBDIR}/libr_*.a" + rm -rf "${DESTDIR}${LIBDIR}/libr_*.${EXT_AR}" rm -rf "${DESTDIR}${LIBDIR}/libr2.so"* - rm -rf "${DESTDIR}${LIBDIR}/libr2.a" + rm -rf "${DESTDIR}${LIBDIR}/libr2.${EXT_AR}" rm -rf "${DESTDIR}${LIBDIR}/libr.so"* - rm -rf "${DESTDIR}${LIBDIR}/libr.a" + rm -rf "${DESTDIR}${LIBDIR}/libr.${EXT_AR}" rm -rf "${DESTDIR}${DATADIR}/doc/radare2" @echo libr aka radare2 has been uninstalled from PREFIX=${DESTDIR}${PREFIX} diff --git a/libr/anal/esil.c b/libr/anal/esil.c index 75a51a8b97..00b293a22a 100644 --- a/libr/anal/esil.c +++ b/libr/anal/esil.c @@ -1685,8 +1685,8 @@ static int esil_poke_some(RAnalEsil *esil) { int regsize; ut64 ptr, regs = 0, tmp; char *count, *dst = r_anal_esil_pop (esil); + const int bytes = 64; if (dst && r_anal_esil_get_parm_size (esil, dst, &tmp, ®size)) { - ut8 bytes = regsize / 8; // reg isregornum (esil, dst, &ptr); count = r_anal_esil_pop (esil); diff --git a/libr/anal/fcn.c b/libr/anal/fcn.c index ab5fbf4958..2b1a78d565 100644 --- a/libr/anal/fcn.c +++ b/libr/anal/fcn.c @@ -29,8 +29,8 @@ #define MAX_JMPTBL_JMP 10000 #define DB a->sdb_fcns -#define EXISTS(x, y ...) snprintf (key, sizeof(key) - 1, x, ## y), sdb_exists (DB, key) -#define SETKEY(x, y ...) snprintf (key, sizeof (key) - 1, x, ## y); +#define EXISTS(x, ...) snprintf (key, sizeof(key) - 1, x, ## __VA_ARGS__), sdb_exists (DB, key) +#define SETKEY(x, ...) snprintf (key, sizeof (key) - 1, x, ## __VA_ARGS__); #define VERBOSE_DELAY if (0) diff --git a/libr/anal/hint.c b/libr/anal/hint.c index 6d37049111..614e765078 100644 --- a/libr/anal/hint.c +++ b/libr/anal/hint.c @@ -3,7 +3,7 @@ #include #define DB a->sdb_hints -#define setf(x,y...) snprintf(x,sizeof(x)-1,##y) +#define setf(x,...) snprintf(x,sizeof(x)-1,##__VA_ARGS__) R_API void r_anal_hint_clear(RAnal *a) { sdb_reset (a->sdb_hints); diff --git a/libr/anal/p/anal_avr.c b/libr/anal/p/anal_avr.c index aa939b941f..1254eb313d 100644 --- a/libr/anal/p/anal_avr.c +++ b/libr/anal/p/anal_avr.c @@ -1090,8 +1090,14 @@ INST_HANDLER (reti) { // RETI INST_HANDLER (rjmp) { // RJMP k op->jump = (op->addr +#ifdef _MSC_VER +#pragma message ("anal_avr.c: WARNING: Probably broken on windows") + + ((((( buf[1] & 0xf) << 9) | (buf[0] << 1))) + | (buf[1] & 0x8 ? ~(0x1fff) : 0)) +#else + ((((( (typeof (op->jump)) buf[1] & 0xf) << 9) | ((typeof (op->jump)) buf[0] << 1))) | (buf[1] & 0x8 ? ~((typeof (op->jump)) 0x1fff) : 0)) +#endif + 2) & CPU_PC_MASK (cpu); ESIL_A ("%"PFMT64d",pc,=,", op->jump); } diff --git a/libr/anal/p/anal_m68k_cs.c b/libr/anal/p/anal_m68k_cs.c index 03d2dad181..615f2c6144 100644 --- a/libr/anal/p/anal_m68k_cs.c +++ b/libr/anal/p/anal_m68k_cs.c @@ -8,8 +8,12 @@ #define CAPSTONE_HAS_M68K 1 #else #define CAPSTONE_HAS_M68K 0 +#ifdef _MSC_VER +#pragma message ("Cannot find capstone-m68k support") +#else #warning Cannot find capstone-m68k support #endif +#endif #if CAPSTONE_HAS_M68K #include diff --git a/libr/anal/p/anal_ppc_cs.c b/libr/anal/p/anal_ppc_cs.c index 7baa6fbf1c..eed03d3bf2 100644 --- a/libr/anal/p/anal_ppc_cs.c +++ b/libr/anal/p/anal_ppc_cs.c @@ -18,7 +18,7 @@ struct Getarg { int bits; }; -#define esilprintf(op, fmt, arg...) r_strbuf_appendf (&op->esil, fmt, ##arg) +#define esilprintf(op, fmt, ...) r_strbuf_appendf (&op->esil, fmt, ##__VA_ARGS__) #define INSOPS insn->detail->ppc.op_count #define INSOP(n) insn->detail->ppc.operands[n] #define IMM(x) (ut64)(insn->detail->ppc.operands[x].imm) diff --git a/libr/anal/p/anal_sparc_cs.c b/libr/anal/p/anal_sparc_cs.c index 9894c7090c..581e6bf0d7 100644 --- a/libr/anal/p/anal_sparc_cs.c +++ b/libr/anal/p/anal_sparc_cs.c @@ -9,7 +9,7 @@ #error Old Capstone not supported #endif -#define esilprintf(op, fmt, arg...) r_strbuf_setf (&op->esil, fmt, ##arg) +#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) #define INSOP(n) insn->detail->sparc.operands[n] #define INSCC insn->detail->sparc.cc diff --git a/libr/anal/p/anal_sysz.c b/libr/anal/p/anal_sysz.c index aa37986652..e07ca30ed7 100644 --- a/libr/anal/p/anal_sysz.c +++ b/libr/anal/p/anal_sysz.c @@ -10,7 +10,7 @@ #error Old Capstone not supported #endif -#define esilprintf(op, fmt, arg...) r_strbuf_setf (&op->esil, fmt, ##arg) +#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) #define INSOP(n) insn->detail->sysz.operands[n] static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { diff --git a/libr/anal/p/anal_x86_cs.c b/libr/anal/p/anal_x86_cs.c index 8f9976c069..efe4e3131c 100644 --- a/libr/anal/p/anal_x86_cs.c +++ b/libr/anal/p/anal_x86_cs.c @@ -32,8 +32,8 @@ call = 4 #error Old Capstone not supported #endif -#define esilprintf(op, fmt, arg...) r_strbuf_setf (&op->esil, fmt, ##arg) -#define opexprintf(op, fmt, arg...) r_strbuf_setf (&op->opex, fmt, ##arg) +#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) +#define opexprintf(op, fmt, ...) r_strbuf_setf (&op->opex, fmt, ##__VA_ARGS__) #define INSOP(n) insn->detail->x86.operands[n] #define INSOPS insn->detail->x86.op_count #define ISIMM(x) insn->detail->x86.operands[x].type == X86_OP_IMM diff --git a/libr/anal/p/anal_xcore_cs.c b/libr/anal/p/anal_xcore_cs.c index 8dcdf60f51..778f1c17e1 100644 --- a/libr/anal/p/anal_xcore_cs.c +++ b/libr/anal/p/anal_xcore_cs.c @@ -9,7 +9,7 @@ #error Old Capstone not supported #endif -#define esilprintf(op, fmt, arg...) r_strbuf_setf (&op->esil, fmt, ##arg) +#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) #define INSOP(n) insn->detail->xcore.operands[n] static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { diff --git a/libr/anal/p/esil.h b/libr/anal/p/esil.h index eee5e32101..20a3cb1927 100644 --- a/libr/anal/p/esil.h +++ b/libr/anal/p/esil.h @@ -3,7 +3,7 @@ #include "udis86/extern.h" /* This may be useful for other architectures */ -#define esilprintf(op, fmt, arg...) r_strbuf_setf (&op->esil, fmt, ##arg) +#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) #define UDIS86_ESIL_ARGUMENTS const UDis86OPInfo *info, RAnalOp *op, const char *dst, const char *src, const char *src2 @@ -28,7 +28,7 @@ typedef struct udis86_esil_t { #define UDIS86_ESIL_HANDLER(name) JOIN (JOIN (__x86_, name), _to_esil) #define UDIS86_ESIL_PROTO(name) void UDIS86_ESIL_HANDLER (name) (UDIS86_ESIL_ARGUMENTS) -#define UDIS86_ESIL(name, fmt, arg...) UDIS86_ESIL_PROTO (name) { esilprintf (op, fmt, ##arg); } +#define UDIS86_ESIL(name, fmt, ...) UDIS86_ESIL_PROTO (name) { esilprintf (op, fmt, ##__VA_ARGS__); } UDis86Esil *udis86_esil_get_handler (enum ud_mnemonic_code); diff --git a/libr/anal/p/gb.mk b/libr/anal/p/gb.mk index ece3efbac1..5021f0a2f6 100644 --- a/libr/anal/p/gb.mk +++ b/libr/anal/p/gb.mk @@ -5,7 +5,7 @@ TARGET_GB=anal_gb.${EXT_SO} ALL_TARGETS+=${TARGET_GB} -CFLAGS += -I arch/gb/ +CFLAGS += -Iarch/gb/ ${TARGET_GB}: ${OBJ_GB} ${CC} $(call libname,anal_gb) ${LDFLAGS} ${CFLAGS} \ diff --git a/libr/anal/var.c b/libr/anal/var.c index 9b13a8118e..aa9d363472 100644 --- a/libr/anal/var.c +++ b/libr/anal/var.c @@ -16,10 +16,10 @@ struct VarType { #define SDB_VARTYPE_FMT "czdz" -#define EXISTS(x, y ...) snprintf (key, sizeof (key) - 1, x, ## y), sdb_exists (DB, key) -#define SETKEY(x, y ...) snprintf (key, sizeof (key) - 1, x, ## y); -#define SETKEY2(x, y ...) snprintf (key2, sizeof (key) - 1, x, ## y); -#define SETVAL(x, y ...) snprintf (val, sizeof (val) - 1, x, ## y); +#define EXISTS(x, ...) snprintf (key, sizeof (key) - 1, x, ## __VA_ARGS__), sdb_exists (DB, key) +#define SETKEY(x, ...) snprintf (key, sizeof (key) - 1, x, ## __VA_ARGS__); +#define SETKEY2(x, ...) snprintf (key2, sizeof (key) - 1, x, ## __VA_ARGS__); +#define SETVAL(x, ...) snprintf (val, sizeof (val) - 1, x, ## __VA_ARGS__); R_API bool r_anal_var_display(RAnal *anal, int delta, char kind, const char *type) { char *fmt = r_anal_type_format (anal, type); RRegItem *i; diff --git a/libr/asm/arch/arm/aarch64/aarch64-dis.c b/libr/asm/arch/arm/aarch64/aarch64-dis.c index d87c07fd6f..a5bbaf1052 100644 --- a/libr/asm/arch/arm/aarch64/aarch64-dis.c +++ b/libr/asm/arch/arm/aarch64/aarch64-dis.c @@ -32,6 +32,8 @@ #define INSNLEN 4 +#define SIZE 128 + /* Cached mapping symbol state. */ enum map_type { @@ -726,15 +728,12 @@ aarch64_ext_limm (const aarch64_operand *self ATTRIBUTE_UNUSED, } else { - switch (S) - { - case 0x00 ... 0x1f: /* 0xxxxx */ simd_size = 32; break; - case 0x20 ... 0x2f: /* 10xxxx */ simd_size = 16; S &= 0xf; break; - case 0x30 ... 0x37: /* 110xxx */ simd_size = 8; S &= 0x7; break; - case 0x38 ... 0x3b: /* 1110xx */ simd_size = 4; S &= 0x3; break; - case 0x3c ... 0x3d: /* 11110x */ simd_size = 2; S &= 0x1; break; - default: return 0; - } + if (S >= 0x00 && S <= 0x1f) { simd_size = 32; } + else if (S >= 0x20 && S <= 0x2f) { simd_size = 16; S &= 0xf; } + else if (S >= 0x30 && S <= 0x37) { simd_size = 8; S &= 0x7; } + else if (S >= 0x38 && S <= 0x3b) { simd_size = 4; S &= 0x3; } + else if (S >= 0x3c && S <= 0x3d) { simd_size = 2; S &= 0x1; } + else { return 0; } mask = (1ull << simd_size) - 1; /* Top bits are IGNORED. */ R &= simd_size - 1; @@ -2052,8 +2051,7 @@ print_operands (bfd_vma pc, const aarch64_opcode *opcode, int i, pcrel_p, num_printed; for (i = 0, num_printed = 0; i < AARCH64_MAX_OPND_NUM; ++i) { - const size_t size = 128; - char str[size]; + char str[SIZE]; /* We regard the opcode operand info more, however we also look into the inst->operands to support the disassembling of the optional operand. @@ -2064,7 +2062,7 @@ print_operands (bfd_vma pc, const aarch64_opcode *opcode, break; /* Generate the operand string in STR. */ - aarch64_print_operand (str, size, pc, opcode, opnds, i, &pcrel_p, + aarch64_print_operand (str, SIZE, pc, opcode, opnds, i, &pcrel_p, &info->target); /* Print the delimiter (taking account of omitted operand(s)). */ diff --git a/libr/asm/arch/arm/aarch64/aarch64-opc-2.c b/libr/asm/arch/arm/aarch64/aarch64-opc-2.c index 08010eb454..8dfbf046da 100644 --- a/libr/asm/arch/arm/aarch64/aarch64-opc-2.c +++ b/libr/asm/arch/arm/aarch64/aarch64-opc-2.c @@ -35,8 +35,8 @@ const struct aarch64_operand aarch64_operands[] = {AARCH64_OPND_CLASS_INT_REG, "Rt_SYS", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rt}, "an integer register"}, {AARCH64_OPND_CLASS_INT_REG, "Rd_SP", OPD_F_MAYBE_SP | OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rd}, "an integer or stack pointer register"}, {AARCH64_OPND_CLASS_INT_REG, "Rn_SP", OPD_F_MAYBE_SP | OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rn}, "an integer or stack pointer register"}, - {AARCH64_OPND_CLASS_MODIFIED_REG, "Rm_EXT", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an integer register with optional extension"}, - {AARCH64_OPND_CLASS_MODIFIED_REG, "Rm_SFT", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an integer register with optional shift"}, + {AARCH64_OPND_CLASS_MODIFIED_REG, "Rm_EXT", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an integer register with optional extension"}, + {AARCH64_OPND_CLASS_MODIFIED_REG, "Rm_SFT", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an integer register with optional shift"}, {AARCH64_OPND_CLASS_FP_REG, "Fd", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rd}, "a floating-point register"}, {AARCH64_OPND_CLASS_FP_REG, "Fn", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rn}, "a floating-point register"}, {AARCH64_OPND_CLASS_FP_REG, "Fm", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rm}, "a floating-point register"}, @@ -55,20 +55,20 @@ const struct aarch64_operand aarch64_operands[] = {AARCH64_OPND_CLASS_SIMD_ELEMENT, "En", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rn}, "a SIMD vector element"}, {AARCH64_OPND_CLASS_SIMD_ELEMENT, "Em", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rm}, "a SIMD vector element"}, {AARCH64_OPND_CLASS_SIMD_REGLIST, "LVn", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rn}, "a SIMD vector register list"}, - {AARCH64_OPND_CLASS_SIMD_REGLIST, "LVt", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a SIMD vector register list"}, - {AARCH64_OPND_CLASS_SIMD_REGLIST, "LVt_AL", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a SIMD vector register list"}, - {AARCH64_OPND_CLASS_SIMD_REGLIST, "LEt", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a SIMD vector element list"}, + {AARCH64_OPND_CLASS_SIMD_REGLIST, "LVt", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a SIMD vector register list"}, + {AARCH64_OPND_CLASS_SIMD_REGLIST, "LVt_AL", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a SIMD vector register list"}, + {AARCH64_OPND_CLASS_SIMD_REGLIST, "LEt", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a SIMD vector element list"}, {AARCH64_OPND_CLASS_CP_REG, "Cn", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_CRn}, "a 4-bit opcode field named for historical reasons C0 - C15"}, {AARCH64_OPND_CLASS_CP_REG, "Cm", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_CRm}, "a 4-bit opcode field named for historical reasons C0 - C15"}, {AARCH64_OPND_CLASS_IMMEDIATE, "IDX", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm4}, "an immediate as the index of the least significant byte"}, - {AARCH64_OPND_CLASS_IMMEDIATE, "IMM_VLSL", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a left shift amount for an AdvSIMD register"}, - {AARCH64_OPND_CLASS_IMMEDIATE, "IMM_VLSR", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a right shift amount for an AdvSIMD register"}, - {AARCH64_OPND_CLASS_IMMEDIATE, "SIMD_IMM", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an immediate"}, - {AARCH64_OPND_CLASS_IMMEDIATE, "SIMD_IMM_SFT", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an 8-bit unsigned immediate with optional shift"}, - {AARCH64_OPND_CLASS_IMMEDIATE, "SIMD_FPIMM", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an 8-bit floating-point constant"}, - {AARCH64_OPND_CLASS_IMMEDIATE, "SHLL_IMM", OPD_F_HAS_EXTRACTOR, {}, "an immediate shift amount of 8, 16 or 32"}, - {AARCH64_OPND_CLASS_IMMEDIATE, "IMM0", 0, {}, "0"}, - {AARCH64_OPND_CLASS_IMMEDIATE, "FPIMM0", 0, {}, "0.0"}, + {AARCH64_OPND_CLASS_IMMEDIATE, "IMM_VLSL", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a left shift amount for an AdvSIMD register"}, + {AARCH64_OPND_CLASS_IMMEDIATE, "IMM_VLSR", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a right shift amount for an AdvSIMD register"}, + {AARCH64_OPND_CLASS_IMMEDIATE, "SIMD_IMM", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an immediate"}, + {AARCH64_OPND_CLASS_IMMEDIATE, "SIMD_IMM_SFT", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an 8-bit unsigned immediate with optional shift"}, + {AARCH64_OPND_CLASS_IMMEDIATE, "SIMD_FPIMM", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an 8-bit floating-point constant"}, + {AARCH64_OPND_CLASS_IMMEDIATE, "SHLL_IMM", OPD_F_HAS_EXTRACTOR, {0}, "an immediate shift amount of 8, 16 or 32"}, + {AARCH64_OPND_CLASS_IMMEDIATE, "IMM0", 0, {0}, "0"}, + {AARCH64_OPND_CLASS_IMMEDIATE, "FPIMM0", 0, {0}, "0.0"}, {AARCH64_OPND_CLASS_IMMEDIATE, "FPIMM", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm8}, "an 8-bit floating-point constant"}, {AARCH64_OPND_CLASS_IMMEDIATE, "IMMR", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_immr}, "the right rotate amount"}, {AARCH64_OPND_CLASS_IMMEDIATE, "IMMS", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm6}, "the leftmost bit number to be moved from the source"}, @@ -86,30 +86,30 @@ const struct aarch64_operand aarch64_operands[] = {AARCH64_OPND_CLASS_IMMEDIATE, "AIMM", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_shift,FLD_imm12}, "a 12-bit unsigned immediate with optional left shift of 12 bits"}, {AARCH64_OPND_CLASS_IMMEDIATE, "HALF", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm16}, "a 16-bit immediate with optional left shift"}, {AARCH64_OPND_CLASS_IMMEDIATE, "FBITS", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_scale}, "the number of bits after the binary point in the fixed-point value"}, - {AARCH64_OPND_CLASS_IMMEDIATE, "IMM_MOV", 0, {}, "an immediate"}, - {AARCH64_OPND_CLASS_NIL, "COND", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a condition"}, + {AARCH64_OPND_CLASS_IMMEDIATE, "IMM_MOV", 0, {0}, "an immediate"}, + {AARCH64_OPND_CLASS_NIL, "COND", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a condition"}, {AARCH64_OPND_CLASS_ADDRESS, "ADDR_ADRP", OPD_F_SEXT | OPD_F_HAS_EXTRACTOR, {FLD_immhi, FLD_immlo}, "21-bit PC-relative address of a 4KB page"}, {AARCH64_OPND_CLASS_ADDRESS, "ADDR_PCREL14", OPD_F_SEXT | OPD_F_SHIFT_BY_2 | OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm14}, "14-bit PC-relative address"}, {AARCH64_OPND_CLASS_ADDRESS, "ADDR_PCREL19", OPD_F_SEXT | OPD_F_SHIFT_BY_2 | OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm19}, "19-bit PC-relative address"}, {AARCH64_OPND_CLASS_ADDRESS, "ADDR_PCREL21", OPD_F_SEXT | OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_immhi,FLD_immlo}, "21-bit PC-relative address"}, {AARCH64_OPND_CLASS_ADDRESS, "ADDR_PCREL26", OPD_F_SEXT | OPD_F_SHIFT_BY_2 | OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm26}, "26-bit PC-relative address"}, - {AARCH64_OPND_CLASS_ADDRESS, "ADDR_SIMPLE", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an address with base register (no offset)"}, - {AARCH64_OPND_CLASS_ADDRESS, "ADDR_REGOFF", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an address with register offset"}, + {AARCH64_OPND_CLASS_ADDRESS, "ADDR_SIMPLE", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an address with base register (no offset)"}, + {AARCH64_OPND_CLASS_ADDRESS, "ADDR_REGOFF", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an address with register offset"}, {AARCH64_OPND_CLASS_ADDRESS, "ADDR_SIMM7", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm7,FLD_index2}, "an address with 7-bit signed immediate offset"}, {AARCH64_OPND_CLASS_ADDRESS, "ADDR_SIMM9", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm9,FLD_index}, "an address with 9-bit signed immediate offset"}, {AARCH64_OPND_CLASS_ADDRESS, "ADDR_SIMM9_2", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_imm9,FLD_index}, "an address with 9-bit negative or unaligned immediate offset"}, {AARCH64_OPND_CLASS_ADDRESS, "ADDR_UIMM12", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {FLD_Rn,FLD_imm12}, "an address with scaled, unsigned immediate offset"}, - {AARCH64_OPND_CLASS_ADDRESS, "SIMD_ADDR_SIMPLE", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an address with base register (no offset)"}, - {AARCH64_OPND_CLASS_ADDRESS, "SIMD_ADDR_POST", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a post-indexed address with immediate or register increment"}, - {AARCH64_OPND_CLASS_SYSTEM, "SYSREG", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a system register"}, - {AARCH64_OPND_CLASS_SYSTEM, "PSTATEFIELD", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a PSTATE field name"}, - {AARCH64_OPND_CLASS_SYSTEM, "SYSREG_AT", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an address translation operation specifier"}, - {AARCH64_OPND_CLASS_SYSTEM, "SYSREG_DC", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a data cache maintenance operation specifier"}, - {AARCH64_OPND_CLASS_SYSTEM, "SYSREG_IC", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an instructin cache maintenance operation specifier"}, - {AARCH64_OPND_CLASS_SYSTEM, "SYSREG_TLBI", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a TBL invalidation operation specifier"}, - {AARCH64_OPND_CLASS_SYSTEM, "BARRIER", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "a barrier option name"}, - {AARCH64_OPND_CLASS_SYSTEM, "BARRIER_ISB", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "the ISB option name SY or an optional 4-bit unsigned immediate"}, - {AARCH64_OPND_CLASS_SYSTEM, "PRFOP", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {}, "an prefetch operation specifier"}, + {AARCH64_OPND_CLASS_ADDRESS, "SIMD_ADDR_SIMPLE", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an address with base register (no offset)"}, + {AARCH64_OPND_CLASS_ADDRESS, "SIMD_ADDR_POST", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a post-indexed address with immediate or register increment"}, + {AARCH64_OPND_CLASS_SYSTEM, "SYSREG", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a system register"}, + {AARCH64_OPND_CLASS_SYSTEM, "PSTATEFIELD", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a PSTATE field name"}, + {AARCH64_OPND_CLASS_SYSTEM, "SYSREG_AT", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an address translation operation specifier"}, + {AARCH64_OPND_CLASS_SYSTEM, "SYSREG_DC", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a data cache maintenance operation specifier"}, + {AARCH64_OPND_CLASS_SYSTEM, "SYSREG_IC", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an instructin cache maintenance operation specifier"}, + {AARCH64_OPND_CLASS_SYSTEM, "SYSREG_TLBI", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a TBL invalidation operation specifier"}, + {AARCH64_OPND_CLASS_SYSTEM, "BARRIER", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "a barrier option name"}, + {AARCH64_OPND_CLASS_SYSTEM, "BARRIER_ISB", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "the ISB option name SY or an optional 4-bit unsigned immediate"}, + {AARCH64_OPND_CLASS_SYSTEM, "PRFOP", OPD_F_HAS_INSERTER | OPD_F_HAS_EXTRACTOR, {0}, "an prefetch operation specifier"}, {AARCH64_OPND_CLASS_NIL, "", 0, {0}, "DUMMY"}, }; diff --git a/libr/asm/arch/arm/aarch64/aarch64-opc.c b/libr/asm/arch/arm/aarch64/aarch64-opc.c index 28eabbda9e..4610e14185 100644 --- a/libr/asm/arch/arm/aarch64/aarch64-opc.c +++ b/libr/asm/arch/arm/aarch64/aarch64-opc.c @@ -2223,7 +2223,7 @@ static void print_register_offset_address (char *buf, size_t size, const aarch64_opnd_info *opnd) { - const size_t tblen = 16; +#define tblen 16 char tb[tblen]; /* Temporary buffer. */ bfd_boolean lsl_p = FALSE; /* Is LSL shift operator? */ bfd_boolean wm_p = FALSE; /* Should Rm be Wm? */ @@ -2266,6 +2266,7 @@ print_register_offset_address (char *buf, size_t size, snprintf (buf, size, "[%s,%c%d%s]", get_64bit_int_reg_name (opnd->addr.base_regno, 1), wm_p ? 'w' : 'x', opnd->addr.offset.regno, tb); +#undef tblen } /* Generate the string representation of the operand OPNDS[IDX] for OPCODE diff --git a/libr/asm/arch/arm/aarch64/aarch64-tbl.h b/libr/asm/arch/arm/aarch64/aarch64-tbl.h index 7c77768329..b3854c307b 100644 --- a/libr/asm/arch/arm/aarch64/aarch64-tbl.h +++ b/libr/asm/arch/arm/aarch64/aarch64-tbl.h @@ -24,7 +24,7 @@ /* Operand type. */ #define OPND(x) AARCH64_OPND_##x -#define OP0() {} +#define OP0() { 0 } #define OP1(a) {OPND(a)} #define OP2(a,b) {OPND(a), OPND(b)} #define OP3(a,b,c) {OPND(a), OPND(b), OPND(c)} @@ -1766,8 +1766,8 @@ struct aarch64_opcode aarch64_opcode_table[] = {"br", 0xd61f0000, 0xfffffc1f, branch_reg, 0, CORE, OP1 (Rn), QL_I1X, 0}, {"blr", 0xd63f0000, 0xfffffc1f, branch_reg, 0, CORE, OP1 (Rn), QL_I1X, 0}, {"ret", 0xd65f0000, 0xfffffc1f, branch_reg, 0, CORE, OP1 (Rn), QL_I1X, F_OPD0_OPT | F_DEFAULT (30)}, - {"eret", 0xd69f03e0, 0xffffffff, branch_reg, 0, CORE, OP0 (), {}, 0}, - {"drps", 0xd6bf03e0, 0xffffffff, branch_reg, 0, CORE, OP0 (), {}, 0}, + {"eret", 0xd69f03e0, 0xffffffff, branch_reg, 0, CORE, OP0 (), { 0 }, 0}, + {"drps", 0xd6bf03e0, 0xffffffff, branch_reg, 0, CORE, OP0 (), { 0 }, 0}, /* Compare & branch (immediate). */ {"cbz", 0x34000000, 0x7f000000, compbranch, 0, CORE, OP2 (Rt, ADDR_PCREL19), QL_R_PCREL, F_SF}, {"cbnz", 0x35000000, 0x7f000000, compbranch, 0, CORE, OP2 (Rt, ADDR_PCREL19), QL_R_PCREL, F_SF}, @@ -1850,14 +1850,14 @@ struct aarch64_opcode aarch64_opcode_table[] = {"umnegl", 0x9ba0fc00, 0xffe0fc00, dp_3src, 0, CORE, OP3 (Rd, Rn, Rm), QL_I3SAMEL, F_ALIAS}, {"umulh", 0x9bc07c00, 0xffe08000, dp_3src, 0, CORE, OP3 (Rd, Rn, Rm), QL_I3SAMEX, 0}, /* Excep'n generation. */ - {"svc", 0xd4000001, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), {}, 0}, - {"hvc", 0xd4000002, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), {}, 0}, - {"smc", 0xd4000003, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), {}, 0}, - {"brk", 0xd4200000, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), {}, 0}, - {"hlt", 0xd4400000, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), {}, 0}, - {"dcps1", 0xd4a00001, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), {}, F_OPD0_OPT | F_DEFAULT (0)}, - {"dcps2", 0xd4a00002, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), {}, F_OPD0_OPT | F_DEFAULT (0)}, - {"dcps3", 0xd4a00003, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), {}, F_OPD0_OPT | F_DEFAULT (0)}, + {"svc", 0xd4000001, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), { 0 }, 0}, + {"hvc", 0xd4000002, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), { 0 }, 0}, + {"smc", 0xd4000003, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), { 0 }, 0}, + {"brk", 0xd4200000, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), { 0 }, 0}, + {"hlt", 0xd4400000, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), { 0 }, 0}, + {"dcps1", 0xd4a00001, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), { 0 }, F_OPD0_OPT | F_DEFAULT (0)}, + {"dcps2", 0xd4a00002, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), { 0 }, F_OPD0_OPT | F_DEFAULT (0)}, + {"dcps3", 0xd4a00003, 0xffe0001f, exception, 0, CORE, OP1 (EXCEPTION), { 0 }, F_OPD0_OPT | F_DEFAULT (0)}, /* Extract. */ {"extr", 0x13800000, 0x7fa00000, extract, 0, CORE, OP4 (Rd, Rn, Rm, IMMS), QL_EXTR, F_HAS_ALIAS | F_SF | F_N}, {"ror", 0x13800000, 0x7fa00000, extract, OP_ROR_IMM, CORE, OP3 (Rd, Rm, IMMS), QL_SHIFT, F_ALIAS | F_CONV}, @@ -2072,18 +2072,18 @@ struct aarch64_opcode aarch64_opcode_table[] = {"adr", 0x10000000, 0x9f000000, pcreladdr, 0, CORE, OP2 (Rd, ADDR_PCREL21), QL_ADRP, 0}, {"adrp", 0x90000000, 0x9f000000, pcreladdr, 0, CORE, OP2 (Rd, ADDR_ADRP), QL_ADRP, 0}, /* System. */ - {"msr", 0xd500401f, 0xfff8f01f, ic_system, 0, CORE, OP2 (PSTATEFIELD, UIMM4), {}, 0}, - {"hint", 0xd503201f, 0xfffff01f, ic_system, 0, CORE, OP1 (UIMM7), {}, F_HAS_ALIAS}, - {"nop", 0xd503201f, 0xffffffff, ic_system, 0, CORE, OP0 (), {}, F_ALIAS}, - {"yield", 0xd503203f, 0xffffffff, ic_system, 0, CORE, OP0 (), {}, F_ALIAS}, - {"wfe", 0xd503205f, 0xffffffff, ic_system, 0, CORE, OP0 (), {}, F_ALIAS}, - {"wfi", 0xd503207f, 0xffffffff, ic_system, 0, CORE, OP0 (), {}, F_ALIAS}, - {"sev", 0xd503209f, 0xffffffff, ic_system, 0, CORE, OP0 (), {}, F_ALIAS}, - {"sevl", 0xd50320bf, 0xffffffff, ic_system, 0, CORE, OP0 (), {}, F_ALIAS}, - {"clrex", 0xd503305f, 0xfffff0ff, ic_system, 0, CORE, OP1 (UIMM4), {}, F_OPD0_OPT | F_DEFAULT (0xF)}, - {"dsb", 0xd503309f, 0xfffff0ff, ic_system, 0, CORE, OP1 (BARRIER), {}, 0}, - {"dmb", 0xd50330bf, 0xfffff0ff, ic_system, 0, CORE, OP1 (BARRIER), {}, 0}, - {"isb", 0xd50330df, 0xfffff0ff, ic_system, 0, CORE, OP1 (BARRIER_ISB), {}, F_OPD0_OPT | F_DEFAULT (0xF)}, + {"msr", 0xd500401f, 0xfff8f01f, ic_system, 0, CORE, OP2 (PSTATEFIELD, UIMM4), { 0 }, 0}, + {"hint", 0xd503201f, 0xfffff01f, ic_system, 0, CORE, OP1 (UIMM7), { 0 }, F_HAS_ALIAS}, + {"nop", 0xd503201f, 0xffffffff, ic_system, 0, CORE, OP0 (), { 0 }, F_ALIAS}, + {"yield", 0xd503203f, 0xffffffff, ic_system, 0, CORE, OP0 (), { 0 }, F_ALIAS}, + {"wfe", 0xd503205f, 0xffffffff, ic_system, 0, CORE, OP0 (), { 0 }, F_ALIAS}, + {"wfi", 0xd503207f, 0xffffffff, ic_system, 0, CORE, OP0 (), { 0 }, F_ALIAS}, + {"sev", 0xd503209f, 0xffffffff, ic_system, 0, CORE, OP0 (), { 0 }, F_ALIAS}, + {"sevl", 0xd50320bf, 0xffffffff, ic_system, 0, CORE, OP0 (), { 0 }, F_ALIAS}, + {"clrex", 0xd503305f, 0xfffff0ff, ic_system, 0, CORE, OP1 (UIMM4), { 0 }, F_OPD0_OPT | F_DEFAULT (0xF)}, + {"dsb", 0xd503309f, 0xfffff0ff, ic_system, 0, CORE, OP1 (BARRIER), { 0 }, 0}, + {"dmb", 0xd50330bf, 0xfffff0ff, ic_system, 0, CORE, OP1 (BARRIER), { 0 }, 0}, + {"isb", 0xd50330df, 0xfffff0ff, ic_system, 0, CORE, OP1 (BARRIER_ISB), { 0 }, F_OPD0_OPT | F_DEFAULT (0xF)}, {"sys", 0xd5080000, 0xfff80000, ic_system, 0, CORE, OP5 (UIMM3_OP1, Cn, Cm, UIMM3_OP2, Rt), QL_SYS, F_HAS_ALIAS | F_OPD4_OPT | F_DEFAULT (0x1F)}, {"at", 0xd5080000, 0xfff80000, ic_system, 0, CORE, OP2 (SYSREG_AT, Rt), QL_SRC_X, F_ALIAS}, {"dc", 0xd5080000, 0xfff80000, ic_system, 0, CORE, OP2 (SYSREG_DC, Rt), QL_SRC_X, F_ALIAS}, @@ -2113,7 +2113,7 @@ struct aarch64_opcode aarch64_opcode_table[] = {"bgt", 0x5400000c, 0xff00001f, condbranch, 0, CORE, OP1 (ADDR_PCREL19), QL_PCREL_NIL, F_ALIAS | F_PSEUDO}, {"ble", 0x5400000d, 0xff00001f, condbranch, 0, CORE, OP1 (ADDR_PCREL19), QL_PCREL_NIL, F_ALIAS | F_PSEUDO}, - {0, 0, 0, 0, 0, 0, {}, {}, 0}, + {0, 0, 0, 0, 0, 0, { 0 }, { 0 }, 0}, }; #ifdef AARCH64_OPERANDS diff --git a/libr/asm/arch/include/dis-asm.h b/libr/asm/arch/include/dis-asm.h index 71363a992a..87cedda2b2 100644 --- a/libr/asm/arch/include/dis-asm.h +++ b/libr/asm/arch/include/dis-asm.h @@ -436,4 +436,8 @@ extern int print_insn_tricore (bfd_vma memaddr, struct disassemble_info *info); } #endif +#ifdef _MSC_VER +#undef xmalloc +#endif + #endif /* ! defined (DIS_ASM_H) */ diff --git a/libr/asm/arch/sparc/gnu/sparc-dis.c b/libr/asm/arch/sparc/gnu/sparc-dis.c index 1596eb1496..a91abd3532 100644 --- a/libr/asm/arch/sparc/gnu/sparc-dis.c +++ b/libr/asm/arch/sparc/gnu/sparc-dis.c @@ -1022,3 +1022,7 @@ print_insn_sparc (bfd_vma memaddr, disassemble_info *info) (*info->fprintf_func) (stream, _("unknown")); return sizeof (buffer); } + +#ifdef _MSC_VER +#undef xmalloc +#endif diff --git a/libr/asm/arch/tms320/tms320_dasm.h b/libr/asm/arch/tms320/tms320_dasm.h index 9b24a393f5..728daa830d 100644 --- a/libr/asm/arch/tms320/tms320_dasm.h +++ b/libr/asm/arch/tms320/tms320_dasm.h @@ -217,17 +217,25 @@ typedef struct { #define field_value(d, name) \ (d)->f.bf_##name##_value +#ifdef _MSC_VER +#define set_field_value(d, name, value) \ +{ \ + field_valid(d, name) = 1; \ + field_value(d, name) = value; \ +} +#else #define set_field_value(d, name, value) \ ({ \ field_valid(d, name) = 1; \ field_value(d, name) = value; \ }) +#endif #define LIST_END { 0 } #define INSN_MASK(af, an, av) { .f = af, .n = an, .v = av } #define INSN_FLAG(af, av) { .f = af, .v = TMS320_FLAG_##av } -#define INSN_SYNTAX(arg...) (char *)#arg +#define INSN_SYNTAX(...) (char *)#__VA_ARGS__ extern int tms320_dasm(tms320_dasm_t *, const ut8 *, int); diff --git a/libr/asm/arch/xap/dis.h b/libr/asm/arch/xap/dis.h index a5873105de..a3838d1ff8 100644 --- a/libr/asm/arch/xap/dis.h +++ b/libr/asm/arch/xap/dis.h @@ -10,8 +10,10 @@ struct instruction { in_reg:2, in_opcode:4, in_operand:8; -#if __sun +#if __sun || defined(_MSC_VER) +#ifndef _MSC_VER #warning XXX related to sunstudio :O +#endif }; #else } __packed; diff --git a/libr/asm/arch/xtensa/gnu/elf32-xtensa.c b/libr/asm/arch/xtensa/gnu/elf32-xtensa.c index 28bec33476..1b70c0e8c1 100644 --- a/libr/asm/arch/xtensa/gnu/elf32-xtensa.c +++ b/libr/asm/arch/xtensa/gnu/elf32-xtensa.c @@ -22,7 +22,6 @@ #include "dis-asm.h" #include #include -#include #include #include "bfdlink.h" diff --git a/libr/asm/arch/xtensa/gnu/xtensa-modules.c b/libr/asm/arch/xtensa/gnu/xtensa-modules.c index 66ede0f61a..d668f54df0 100644 --- a/libr/asm/arch/xtensa/gnu/xtensa-modules.c +++ b/libr/asm/arch/xtensa/gnu/xtensa-modules.c @@ -3824,7 +3824,7 @@ static xtensa_regfile_internal regfiles[] = { /* Interfaces. */ static xtensa_interface_internal interfaces[] = { - + { 0 } }; diff --git a/libr/asm/p/Makefile b/libr/asm/p/Makefile index 062a161548..4b7ca21064 100644 --- a/libr/asm/p/Makefile +++ b/libr/asm/p/Makefile @@ -4,7 +4,11 @@ include ../../../mk/platform.mk CFLAGS+=-I$(TOP)/shlr -I../../include -I../arch/ -I../arch/include CFLAGS+=-Wall -shared ${PIC_CFLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}.. LDFLAGS+=-L../../util -L../../lib -L../../flag +ifeq ($(CC),cccl) +LDFLAGS+=${LINK} -llibr_flag -llibr_util +else LDFLAGS+=${LINK} -lr_flag -lr_util +endif CURDIR= diff --git a/libr/asm/p/asm_m68k_cs.c b/libr/asm/p/asm_m68k_cs.c index 7ae53f4c7f..ebb158db44 100644 --- a/libr/asm/p/asm_m68k_cs.c +++ b/libr/asm/p/asm_m68k_cs.c @@ -8,8 +8,12 @@ #define CAPSTONE_HAS_M68K 1 #else #define CAPSTONE_HAS_M68K 0 +#ifdef _MSC_VER +#pragma message ("Cannot find capstone-m68k support") +#else #warning Cannot find capstone-m68k support #endif +#endif #if CAPSTONE_HAS_M68K diff --git a/libr/asm/p/asm_tms320.c b/libr/asm/p/asm_tms320.c index 42f5881d95..386dbda8b5 100644 --- a/libr/asm/p/asm_tms320.c +++ b/libr/asm/p/asm_tms320.c @@ -71,7 +71,7 @@ static int tms320c64x_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) #include "../arch/tms320/tms320_dasm.h" -static tms320_dasm_t engine = { }; +static tms320_dasm_t engine = { 0 }; static int tms320_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (a->cpu && strcasecmp (a->cpu, "c54x") == 0) { diff --git a/libr/bin/format/coff/coff_specs.h b/libr/bin/format/coff/coff_specs.h index 5a62f76330..93016bbce5 100644 --- a/libr/bin/format/coff/coff_specs.h +++ b/libr/bin/format/coff/coff_specs.h @@ -172,7 +172,6 @@ struct coff_symbol { ut8 n_numaux; /* Auxiliary Count */ } __attribute__((packed)); - struct coff_reloc { ut32 r_vaddr; /* Reference Address */ ut32 r_symndx; /* Symbol index */ diff --git a/libr/bin/format/elf/elf.c b/libr/bin/format/elf/elf.c index 83e3cf471e..6f47e29599 100644 --- a/libr/bin/format/elf/elf.c +++ b/libr/bin/format/elf/elf.c @@ -345,7 +345,7 @@ static int init_strtab(ELFOBJ *bin) { static int init_dynamic_section(struct Elf_(r_bin_elf_obj_t) *bin) { Elf_(Dyn) *dyn = NULL; - Elf_(Dyn) d = {}; + Elf_(Dyn) d = {0}; Elf_(Addr) strtabaddr = 0; ut64 offset = 0; char *strtab = NULL; @@ -731,7 +731,7 @@ static Sdb *store_versioninfo_gnu_verdef(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) char *vstart = ((char*)defs) + i; char key[32] = {0}; Elf_(Verdef) *verdef = (Elf_(Verdef)*)vstart; - Elf_(Verdaux) aux = {}; + Elf_(Verdaux) aux = {0}; int j = 0; int isum = 0; @@ -863,7 +863,7 @@ static Sdb *store_versioninfo_gnu_verneed(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) for (i = 0, cnt = 0; cnt < shdr->sh_info; ++cnt) { int j, isum; ut8 *vstart = need + i; - Elf_(Verneed) vvn = {}; + Elf_(Verneed) vvn = {0}; if (vstart + sizeof (Elf_(Verneed)) > end) { goto beach; } @@ -895,7 +895,7 @@ static Sdb *store_versioninfo_gnu_verneed(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) for (j = 0, isum = i + entry->vn_aux; j < entry->vn_cnt && vstart + sizeof (Elf_(Vernaux)) <= end; ++j) { int k; Elf_(Vernaux) * aux = NULL; - Elf_(Vernaux) vaux = {}; + Elf_(Vernaux) vaux = {0}; sdb_vernaux = sdb_new0 (); if (!sdb_vernaux) { goto beach; diff --git a/libr/bin/format/mach0/mach0.c b/libr/bin/format/mach0/mach0.c index 34c4ad5bb5..417c36d91a 100644 --- a/libr/bin/format/mach0/mach0.c +++ b/libr/bin/format/mach0/mach0.c @@ -541,10 +541,10 @@ static bool parse_signature(struct MACH0_(obj_t) *bin, ut64 off) { int i,len; ut32 data; bin->signature = NULL; - struct linkedit_data_command link = {}; + struct linkedit_data_command link = {0}; ut8 lit[sizeof (struct linkedit_data_command)] = {0}; - struct blob_index_t idx = {}; - struct super_blob_t super = {}; + struct blob_index_t idx = {0}; + struct super_blob_t super = {0}; if (off > bin->size || off + sizeof (struct linkedit_data_command) > bin->size) { return false; @@ -585,7 +585,7 @@ static bool parse_signature(struct MACH0_(obj_t) *bin, ut64 off) { bin->signature = (ut8 *)strdup ("Malformed entitlement"); break; } - struct blob_t entitlements = {}; + struct blob_t entitlements = {0}; entitlements.magic = r_read_ble32 (bin->b->buf + off, little_); entitlements.length = r_read_ble32 (bin->b->buf + off + 4, little_); len = entitlements.length - sizeof(struct blob_t); diff --git a/libr/bin/format/pe/pe.c b/libr/bin/format/pe/pe.c index 8c1d2acf29..af5e1a37f9 100644 --- a/libr/bin/format/pe/pe.c +++ b/libr/bin/format/pe/pe.c @@ -6,7 +6,6 @@ #include #include #include "pe.h" -#include #include #define PE_IMAGE_FILE_MACHINE_RPI2 452 diff --git a/libr/bin/mangling/cxx/libiberty.h b/libr/bin/mangling/cxx/libiberty.h index f54ca18caa..4f67c3f4b1 100644 --- a/libr/bin/mangling/cxx/libiberty.h +++ b/libr/bin/mangling/cxx/libiberty.h @@ -645,7 +645,9 @@ extern void setproctitle (const char *name, ...); USE_C_ALLOCA yourself. The canonical autoconf macro C_ALLOCA is also set/unset as it is often used to indicate whether code needs to call alloca(0). */ +#ifndef _MSC_VER extern void *C_alloca (size_t) ATTRIBUTE_MALLOC; +#endif #undef alloca #if GCC_VERSION >= 2000 && !defined USE_C_ALLOCA # define alloca(x) __builtin_alloca(x) @@ -656,7 +658,11 @@ extern void *C_alloca (size_t) ATTRIBUTE_MALLOC; char *const libiberty_nptr = (char *const) alloca (libiberty_len); \ (char *) memcpy (libiberty_nptr, libiberty_optr, libiberty_len); })) #else +#ifdef _MSC_VER +# define alloca(x) _alloca(x) +#else # define alloca(x) C_alloca(x) +#endif # undef USE_C_ALLOCA # define USE_C_ALLOCA 1 # undef C_ALLOCA diff --git a/libr/bin/p/Makefile b/libr/bin/p/Makefile index 79d0432695..dd992a93be 100644 --- a/libr/bin/p/Makefile +++ b/libr/bin/p/Makefile @@ -2,9 +2,15 @@ include ../../config.mk include ../../../mk/platform.mk CFLAGS+=-I$(LTOP)/include -I$(LTOP)/bin/format/ -Wall $(PIC_CFLAGS) +ifeq ($(CC),cccl) +LDFLAGS+=-L$(LTOP)/util -llibr_util +LDFLAGS+=-L$(LTOP)/bin -llibr_bin +LDFLAGS+=-L$(LTOP)/io -llibr_io +else LDFLAGS+=-L$(LTOP)/util -lr_util LDFLAGS+=-L$(LTOP)/bin -lr_bin LDFLAGS+=-L$(LTOP)/io -lr_io +endif SHLR=$(LTOP)/../shlr foo: all diff --git a/libr/bin/p/any.mk b/libr/bin/p/any.mk index 26067f6883..220e9aa7b9 100644 --- a/libr/bin/p/any.mk +++ b/libr/bin/p/any.mk @@ -8,6 +8,12 @@ ALL_TARGETS+=${TARGET_ANY} include $(SHLR)/zip/deps.mk ${TARGET_ANY}: ${OBJ_ANY} +ifeq ($(CC),cccl) + ${CC} $(call libname,bin_any) $(DL_LIBS) ${CFLAGS} $(OBJ_ANY) $(LINK) $(LDFLAGS) \ + -L../../magic -llibr_magic \ + -L../../util -llibr_util +else ${CC} $(call libname,bin_any) $(DL_LIBS) ${CFLAGS} $(OBJ_ANY) $(LINK) $(LDFLAGS) \ -L../../magic -lr_magic \ -L../../util -lr_util +endif diff --git a/libr/bin/p/bflt.mk b/libr/bin/p/bflt.mk index cef0fe5868..8067f8b36a 100644 --- a/libr/bin/p/bflt.mk +++ b/libr/bin/p/bflt.mk @@ -7,15 +7,15 @@ TARGET_BFLT=bin_bflt.${EXT_SO} ALL_TARGETS+=${TARGET_BFLT} ifeq ($(WITHNONPIC),1) -LINK+=../../io/libr_io.a -LINK+=../../util/libr_util.a -LINK+=../../magic/libr_magic.a -LINK+=../../socket/libr_socket.a -LINK+=../../../shlr/gdb/lib/libgdbr.a -LINK+=../../../shlr/wind/libr_wind.a -LINK+=../../../shlr/qnx/lib/libqnxr.a -LINK+=../../../shlr/bochs/lib/libbochs.a -LINK+=../../../shlr/java/libr_java.a +LINK+=../../io/libr_io.${EXT_AR} +LINK+=../../util/libr_util.${EXT_AR} +LINK+=../../magic/libr_magic.${EXT_AR} +LINK+=../../socket/libr_socket.${EXT_AR} +LINK+=../../../shlr/gdb/lib/libgdbr.${EXT_AR} +LINK+=../../../shlr/wind/libr_wind.${EXT_AR} +LINK+=../../../shlr/qnx/lib/libqnxr.${EXT_AR} +LINK+=../../../shlr/bochs/lib/libbochs.${EXT_AR} +LINK+=../../../shlr/java/libr_java.${EXT_AR} endif ${TARGET_BFLT}: ${OBJ_BFLT} diff --git a/libr/bin/p/bin_art.c b/libr/bin/p/bin_art.c index c3912893af..302ca2e78a 100644 --- a/libr/bin/p/bin_art.c +++ b/libr/bin/p/bin_art.c @@ -5,7 +5,11 @@ #include #include +#ifdef _MSC_VER +typedef struct art_header_t { +#else typedef struct __packed art_header_t { +#endif ut8 magic[4]; ut8 version[4]; ut32 image_base; diff --git a/libr/bin/p/bin_dex.c b/libr/bin/p/bin_dex.c index 1c91d42591..1ee654c518 100644 --- a/libr/bin/p/bin_dex.c +++ b/libr/bin/p/bin_dex.c @@ -428,6 +428,7 @@ static void dex_parse_debug_item(RBinFile *binfile, RBinDexObj *bin, if (register_num >= regsz) { r_list_free (debug_positions); free (params); + free (debug_locals); return; } // Emit what was previously there, if anything @@ -469,6 +470,7 @@ static void dex_parse_debug_item(RBinFile *binfile, RBinDexObj *bin, if (register_num >= regsz) { r_list_free (debug_positions); free (params); + free (debug_locals); return; } @@ -506,6 +508,7 @@ static void dex_parse_debug_item(RBinFile *binfile, RBinDexObj *bin, if (register_num >= regsz) { r_list_free (debug_positions); free (params); + free (debug_locals); return; } if (debug_locals[register_num].live) { @@ -534,6 +537,7 @@ static void dex_parse_debug_item(RBinFile *binfile, RBinDexObj *bin, if (register_num >= regsz) { r_list_free (debug_positions); free (params); + free (debug_locals); return; } if (!debug_locals[register_num].live) { @@ -593,6 +597,7 @@ static void dex_parse_debug_item(RBinFile *binfile, RBinDexObj *bin, if (!dexdump) { free (debug_positions); free (emitted_debug_locals); + free (debug_locals); free (params); return; } diff --git a/libr/bin/p/bin_ningb.c b/libr/bin/p/bin_ningb.c index 1273e85ed5..78c0f9ce23 100644 --- a/libr/bin/p/bin_ningb.c +++ b/libr/bin/p/bin_ningb.c @@ -86,10 +86,17 @@ static RList* sections(RBinFile *arch){ r_buf_read_at (arch->buf, 0x148, &bank, 1); bank = gb_get_rombanks(bank); +#ifdef _MSC_VER + RBinSection **rombank = (RBinSection**) malloc (sizeof (RBinSection*) * bank); +#else RBinSection *rombank[bank]; +#endif if (!arch->buf) { free (ret); +#ifdef _MSC_VER + free (rombank); +#endif return NULL; } @@ -116,6 +123,9 @@ static RList* sections(RBinFile *arch){ rombank[i]->add = true; r_list_append (ret,rombank[i]); } +#ifdef _MSC_VER + free (rombank); +#endif return ret; } diff --git a/libr/bin/p/bin_vsf.c b/libr/bin/p/bin_vsf.c index e58ed7eb33..8df144bf6c 100644 --- a/libr/bin/p/bin_vsf.c +++ b/libr/bin/p/bin_vsf.c @@ -127,6 +127,10 @@ static RList *mem(RBinFile *arch) { } static RList* sections(RBinFile* arch) { +#ifdef _MSC_VER +#pragma message ("Windows: WARNING: vsf_sections bypassed !") + return NULL; +#else struct r_bin_vsf_obj* vsf_obj = (struct r_bin_vsf_obj*) arch->o->bin_obj; if (!vsf_obj) { return NULL; @@ -292,6 +296,7 @@ static RList* sections(RBinFile* arch) { } return ret; +#endif } static RBinInfo* info(RBinFile *arch) { @@ -494,8 +499,12 @@ static RList* symbols(RBinFile *arch) { strncpy (ptr->name, _symbols[i].symbol_name, R_BIN_SIZEOF_STRINGS); ptr->vaddr = _symbols[i].address; ptr->size = 2; +#ifdef _MSC_VER +#pragma message("Windows: WARNING (TODO): vsf symbols bypassed") +#else ptr->paddr = (vsf_obj->mem + offset) - (void *)arch->buf->buf + _symbols[i].address; +#endif ptr->ordinal = i; r_list_append (ret, ptr); } @@ -523,7 +532,11 @@ static RList* entries(RBinFile *arch) { if (!(ptr = R_NEW0 (RBinAddr))) { return ret; } +#ifdef _MSC_VER +#pragma message("Windows: WARNING (TODO): vsf entries bypassed") +#else ptr->paddr = (vsf_obj->mem + offset) - (void*) arch->buf->buf; +#endif ptr->vaddr = vsf_obj->maincpu ? vsf_obj->maincpu->pc : 0; r_list_append (ret, ptr); diff --git a/libr/bin/p/dol.mk b/libr/bin/p/dol.mk index fe2316a468..07345bdebe 100644 --- a/libr/bin/p/dol.mk +++ b/libr/bin/p/dol.mk @@ -6,5 +6,10 @@ TARGET_DOLPHIN=bin_dol.${EXT_SO} ALL_TARGETS+=${TARGET_DOLPHIN} ${TARGET_DOLPHIN}: ${OBJ_DOLPHIN} +ifeq ($(CC),cccl) + ${CC} $(call libname,bin_dol) ${CFLAGS} $(OBJ_DOLPHIN) $(LINK) $(LDFLAGS) \ + -L../../magic -llibr_magic +else ${CC} $(call libname,bin_dol) ${CFLAGS} $(OBJ_DOLPHIN) $(LINK) $(LDFLAGS) \ -L../../magic -lr_magic +endif diff --git a/libr/bin/p/nin3ds.mk b/libr/bin/p/nin3ds.mk index 44acff83ed..c3a54a8829 100644 --- a/libr/bin/p/nin3ds.mk +++ b/libr/bin/p/nin3ds.mk @@ -6,5 +6,10 @@ TARGET_NIN3DS=bin_nin3ds.${EXT_SO} ALL_TARGETS+=${TARGET_NIN3DS} ${TARGET_NIN3DS}: ${OBJ_NIN3DS} +ifeq ($(CC),cccl) + ${CC} $(call libname,bin_nin3ds) ${CFLAGS} $(OBJ_NIN3DS) $(LINK) $(LDFLAGS) \ + -L../../magic -llibr_magic +else ${CC} $(call libname,bin_nin3ds) ${CFLAGS} $(OBJ_NIN3DS) $(LINK) $(LDFLAGS) \ -L../../magic -lr_magic +endif diff --git a/libr/bin/p/ninds.mk b/libr/bin/p/ninds.mk index 1c6b1c4227..72083ec798 100644 --- a/libr/bin/p/ninds.mk +++ b/libr/bin/p/ninds.mk @@ -6,5 +6,10 @@ TARGET_NINDS=bin_ninds.${EXT_SO} ALL_TARGETS+=${TARGET_NINDS} ${TARGET_NINDS}: ${OBJ_NINDS} +ifeq ($(CC),cccl) + ${CC} $(call libname,bin_ninds) ${CFLAGS} $(OBJ_NINDS) $(LINK) $(LDFLAGS) \ + -L../../magic -llibr_magic +else ${CC} $(call libname,bin_ninds) ${CFLAGS} $(OBJ_NINDS) $(LINK) $(LDFLAGS) \ -L../../magic -lr_magic +endif diff --git a/libr/bin/p/vsf.mk b/libr/bin/p/vsf.mk index aa8f643ac8..78c1fbc61b 100644 --- a/libr/bin/p/vsf.mk +++ b/libr/bin/p/vsf.mk @@ -6,5 +6,6 @@ TARGET_VSF=bin_vsf.${EXT_SO} ALL_TARGETS+=${TARGET_VSF} ${TARGET_VSF}: ${OBJ_VSF} + echo "FUCKOFF" ${CC} $(call libname,bin_vsf) -shared ${CFLAGS} \ -o ${TARGET_VSF} ${OBJ_VSF} $(LINK) $(LDFLAGS) diff --git a/libr/config.mk.tail b/libr/config.mk.tail index 0ddb2028d6..6802a74e95 100644 --- a/libr/config.mk.tail +++ b/libr/config.mk.tail @@ -6,6 +6,7 @@ ifeq ($(R2DIR),) $(error ERROR: Cannot find R2DIR. Please define this variable) else LIBR=$(R2DIR)/libr +MSVC=$(R2DIR)/msvc endif endif SHLR:=$(LIBR)/../shlr diff --git a/libr/cons/grep.c b/libr/cons/grep.c index 47be5123b7..698f198b70 100644 --- a/libr/cons/grep.c +++ b/libr/cons/grep.c @@ -275,7 +275,7 @@ static int cmp(const void *a, const void *b) { const char *ca = r_str_chop_ro (a); const char *cb = r_str_chop_ro (b); if (!a || !b) { - return (int) (size_t) (a - b); + return (int) (size_t) ((char*) a - (char*) b); } if (sorted_column > 0) { da = strdup (ca); diff --git a/libr/cons/hud.c b/libr/cons/hud.c index 23dd9ee14d..0e8ebb2ee4 100644 --- a/libr/cons/hud.c +++ b/libr/cons/hud.c @@ -98,7 +98,11 @@ static bool strmatch(char *entry, char *filter, char* mask, const int mask_size) R_API char *r_cons_hud(RList *list, const char *prompt) { const int buf_size = 128; int ch, nch, first_line, current_entry_n, j, i = 0; - char *p, *x, user_input[buf_size], mask[buf_size]; + char *p, *x; +#ifdef _MSC_VER +#define buf_size 128 +#endif + char user_input[buf_size], mask[buf_size]; int last_color_change, top_entry_n = 0; char *selected_entry = NULL; char tmp, last_mask = 0; diff --git a/libr/cons/rgb.c b/libr/cons/rgb.c index 424f766e46..e4df8bd694 100644 --- a/libr/cons/rgb.c +++ b/libr/cons/rgb.c @@ -172,7 +172,11 @@ R_API char *r_cons_rgb_str (char *outstr, ut8 r, ut8 g, ut8 b, int is_bg) { R_API void r_cons_rgb (ut8 r, ut8 g, ut8 b, int is_bg) { #if __WINDOWS__ && !__CYGWIN__ +#ifdef _MSC_VER +#pragma message "r_cons_rgb not yet supported on windows" +#else #warning r_cons_rgb not yet supported on windows +#endif #else char outstr[64]; r_cons_strcat (r_cons_rgb_str (outstr, r, g, b, is_bg)); diff --git a/libr/core/canal.c b/libr/core/canal.c index 3212f353e9..4e45f31b1d 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -850,7 +850,11 @@ R_API void r_core_anal_hint_print(RAnal* a, ut64 addr, int mode) { } R_API void r_core_anal_hint_list(RAnal *a, int mode) { +#ifdef _MSC_VER + HintListState hls = {0}; +#else HintListState hls = {}; +#endif hls.mode = mode; hls.count = 0; hls.a = a; diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 912c6c612b..65b744a4eb 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -637,12 +637,11 @@ static int cmd_interpret(void *data, const char *input) { r_core_cmd_help (core, help_msg); } break; -#if 1 - case '0'...'9': - eprintf ("|ERROR| No .[0..9] to avoid infinite loops\n"); - break; -#endif default: + if (*input >= 0 && *input <= 9) { + eprintf ("|ERROR| No .[0..9] to avoid infinite loops\n"); + break; + } inp = strdup (input); filter = strchr (inp, '~'); if (filter) { @@ -1255,7 +1254,11 @@ R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { } } #else +#ifdef _MSC_VER +#pragma message ("r_core_cmd_pipe UNIMPLEMENTED FOR THIS PLATFORM") +#else #warning r_core_cmd_pipe UNIMPLEMENTED FOR THIS PLATFORM +#endif eprintf ("r_core_cmd_pipe: unimplemented for this platform\n"); #endif if (pipecolor != -1) diff --git a/libr/core/cmd_debug.c b/libr/core/cmd_debug.c index d0ab7cd678..ada9ff21f4 100644 --- a/libr/core/cmd_debug.c +++ b/libr/core/cmd_debug.c @@ -3251,7 +3251,7 @@ beach: return 1; } -static char *get_corefile_name (const char *raw_name, pid_t pid) { +static char *get_corefile_name (const char *raw_name, int pid) { return (!*raw_name)? r_str_newf ("core.%u", pid) : r_str_chop (strdup (raw_name)); diff --git a/libr/core/core.c b/libr/core/core.c index 469e514bdb..2194f4f4dc 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -1829,8 +1829,7 @@ static void chop_prompt (const char *filename, char *tmp, size_t max_tmp_size) { } static void set_prompt (RCore *r) { - size_t max_tmp_size = 128; - char tmp[max_tmp_size]; + char tmp[128]; char *prompt = NULL; char *filename = strdup (""); const char *cmdprompt = r_config_get (r->config, "cmd.prompt"); @@ -1864,7 +1863,7 @@ static void set_prompt (RCore *r) { a = ((r->offset >> 16) << 12); b = (r->offset & 0xffff); - snprintf (tmp, max_tmp_size, "%04x:%04x", a, b); + snprintf (tmp, 128, "%04x:%04x", a, b); } else { char p[64], sec[32]; int promptset = false; @@ -1883,7 +1882,7 @@ static void set_prompt (RCore *r) { snprintf (tmp, sizeof (tmp), "%s%s", sec, p); } - chop_prompt (filename, tmp, max_tmp_size); + chop_prompt (filename, tmp, 128); prompt = r_str_newf ("%s%s[%s%s]>%s ", filename, BEGIN, remote, tmp, END); r_line_set_prompt (prompt ? prompt : ""); diff --git a/libr/core/visual.c b/libr/core/visual.c index 831f16bf09..4ec9f4ad95 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -927,7 +927,7 @@ R_API int r_core_visual_xrefs_X(RCore *core) { int skip = 0; int idx = 0; char cstr[32]; - const int maxcount = 9; +#define maxcount 9 ut64 references[maxcount]; ut64 addr = core->offset; if (core->print->cur_enabled) { @@ -1056,6 +1056,7 @@ repeat: eprintf ("TODO: sdbize xrefs here\n"); #endif return ret; +#undef maxcount } #if __WINDOWS__ && !__CYGWIN__ diff --git a/libr/crypto/p/crypto_aes_algo.c b/libr/crypto/p/crypto_aes_algo.c index fae5af4c5b..0225bb27fa 100644 --- a/libr/crypto/p/crypto_aes_algo.c +++ b/libr/crypto/p/crypto_aes_algo.c @@ -30,7 +30,11 @@ static const ut8 Rcon[30] = { void aes_expkey (const struct aes_state *st, ut32 expkey[2][st->rounds + 1][Nb]) #else // XXX this is wrong, but at least it compiles +#ifdef _MSC_VER +#pragma message ("AES broken for non-gcc compilers") +#else #warning AES broken for non-gcc compilers +#endif void aes_expkey (const struct aes_state *st, ut32 ***expkey) #endif { diff --git a/libr/crypto/p/crypto_rc6.c b/libr/crypto/p/crypto_rc6.c index 2f3cecbd79..c872069fa9 100644 --- a/libr/crypto/p/crypto_rc6.c +++ b/libr/crypto/p/crypto_rc6.c @@ -29,7 +29,7 @@ static bool rc6_init(struct rc6_state *const state, const ut8 *key, int keylen, int u = w / 8; int c = keylen / u; int t = 2 * r + 4; - ut32 L[c]; + ut32 *L = (ut32*) calloc (c, sizeof (ut32)); ut32 A = 0, B = 0, k = 0, j = 0; ut32 v = 3 * t; //originally v = 2 * ((c > t) ? c : t); @@ -55,13 +55,14 @@ static bool rc6_init(struct rc6_state *const state, const ut8 *key, int keylen, } state->key_size = keylen/8; + free (L); return true; } static void rc6_encrypt(struct rc6_state *const state, const ut8 *inbuf, ut8 *outbuf) { ut32 t, u; ut32 aux; - ut32 data[BLOCK_SIZE/4]; + ut32 data[BLOCK_SIZE / 4]; int i; int off = 0; for (i = 0; i < BLOCK_SIZE / 4; i++) { diff --git a/libr/debug/p/debug_native.c b/libr/debug/p/debug_native.c index 5d695e5784..bdccddab3b 100644 --- a/libr/debug/p/debug_native.c +++ b/libr/debug/p/debug_native.c @@ -8,7 +8,6 @@ #include #include #include -#include #if DEBUGGER @@ -1589,7 +1588,11 @@ RDebugPlugin r_debug_plugin_native = { .bits = 0, .arch = 0, .canstep = 0, +#ifdef _MSC_VER +#pragma message("Unsupported architecture") +#else #warning Unsupported architecture +#endif #endif .init = &r_debug_native_init, .step = &r_debug_native_step, diff --git a/libr/debug/p/native/w32.c b/libr/debug/p/native/w32.c index cf820b5d49..9f5b29f0b3 100644 --- a/libr/debug/p/native/w32.c +++ b/libr/debug/p/native/w32.c @@ -11,6 +11,11 @@ #ifndef WINAPI #define WINAPI #endif +#ifdef _MSC_VER +#pragma message("WARNING: WINAPI: Temporary hack for windows...") +#undef WINAPI +#define WINAPI +#endif // XXX remove #define WIN32_PI(x) x @@ -98,10 +103,12 @@ return (0); //BOOL WINAPI DebugActiveProcessStop(DWORD dwProcessId); +#ifndef _MSC_VER BOOL WINAPI DebugBreakProcess( HANDLE Process //_In_ HANDLE Process ); +#endif typedef struct _SYSTEM_HANDLE { ULONG ProcessId; @@ -483,11 +490,10 @@ static char *get_file_name_from_handle (HANDLE handle_file) { } /* Translate path with device name to drive letters. */ - int temp_size = 512; - TCHAR temp_buffer[temp_size]; + TCHAR temp_buffer[512]; temp_buffer[0] = '\0'; - if (!GetLogicalDriveStrings (temp_size-1, temp_buffer)) { + if (!GetLogicalDriveStrings (511, temp_buffer)) { free (filename); UnmapViewOfFile (map); CloseHandle (handle_file_map); @@ -586,7 +592,7 @@ typedef struct { LPVOID lpThreadLocalBase; LPVOID lpStartAddress; PVOID lpThreadEntryPoint; - DWORD dwExitCode + DWORD dwExitCode; } THREAD_ITEM, *PTHREAD_ITEM; LPVOID lstThread = 0; PTHREAD_ITEM lstThreadPtr = 0; @@ -1062,7 +1068,7 @@ static void printwincontext(HANDLE hThread, CONTEXT * ctx) { } } for (x = 0; x < 8; x++) { - xmm[x] = (ut128)*((ut128 *)&ctx->ExtendedRegisters[(10 + x) * 16]); + xmm[x] = *((ut128 *)&ctx->ExtendedRegisters[(10 + x) * 16]); } nxmm = 8; #endif diff --git a/libr/include/msvc/sys/time.h b/libr/include/msvc/sys/time.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libr/include/msvc/unistd.h b/libr/include/msvc/unistd.h new file mode 100644 index 0000000000..ba93293bac --- /dev/null +++ b/libr/include/msvc/unistd.h @@ -0,0 +1,2 @@ +/* This file is only included with mscv build */ +#include diff --git a/libr/include/r_cons.h b/libr/include/r_cons.h index ebe47fe640..33d04fc9d1 100644 --- a/libr/include/r_cons.h +++ b/libr/include/r_cons.h @@ -12,7 +12,6 @@ extern "C" { #include #include -#include #include #include #include @@ -26,6 +25,7 @@ extern "C" { #include #include #endif +#include /* constants */ #define CONS_MAX_USER 102400 diff --git a/libr/include/r_socket.h b/libr/include/r_socket.h index bdc6999ac2..de1164817c 100644 --- a/libr/include/r_socket.h +++ b/libr/include/r_socket.h @@ -1,6 +1,11 @@ #ifndef R2_SOCKET_H #define R2_SOCKET_H +/* Must be included before windows.h (r_types) */ +#if defined(__WINDOWS__) && !defined(__CYGWIN__) && !defined(MINGW32) && !defined(__MINGW64__) +#include +#endif + #include "r_types.h" #ifdef __cplusplus @@ -24,10 +29,6 @@ R_LIB_VERSION_HEADER(r_socket); #include #endif -#if defined(__WINDOWS__) && !defined(__CYGWIN__) && !defined(MINGW32) && !defined(__MINGW64__) -#include -#endif - #if __UNIX__ || defined(__CYGWIN__) #include #endif @@ -54,7 +55,11 @@ typedef struct { } R2Pipe; typedef struct r_socket_t { +#ifdef _MSC_VER + SOCKET fd; +#else int fd; +#endif int is_ssl; int local; // TODO: merge ssl with local -> flags/options int port; diff --git a/libr/include/r_types.h b/libr/include/r_types.h index 7401421177..84f788dead 100644 --- a/libr/include/r_types.h +++ b/libr/include/r_types.h @@ -81,6 +81,11 @@ #define MINGW32 1 #endif +#ifdef _MSC_VER + /* Useful for windows _CONTEXT structure declaration */ + #define _X86_ +#endif + #if defined(EMSCRIPTEN) || defined(__linux__) || defined(__APPLE__) || defined(__GNU__) || defined(__ANDROID__) || defined(__QNX__) || defined(__sun) #define __BSD__ 0 #define __UNIX__ 1 @@ -89,18 +94,25 @@ #define __BSD__ 1 #define __UNIX__ 1 #endif -#if __WINDOWS__ || _WIN32 || __CYGWIN__ || MINGW32 - #define __addr_t_defined - #include -#endif #if __WINDOWS__ || _WIN32 || MINGW32 && !(__MINGW64__ || __CYGWIN__) + #ifdef _MSC_VER + /* Must be included before windows.h */ + #include + #define WIN32_LEAN_AND_MEAN + #else + /* Deprecated */ #include + #endif typedef int socklen_t; #undef USE_SOCKETS #define __WINDOWS__ 1 #undef __UNIX__ #undef __BSD__ #endif +#if __WINDOWS__ || _WIN32 || __CYGWIN__ || MINGW32 + #define __addr_t_defined + #include +#endif #if defined(__APPLE__) && (__arm__ || __arm64__ || __aarch64__) #define TARGET_OS_IPHONE 1 @@ -148,7 +160,6 @@ #include #include #include -#include #include /* for O_RDONLY */ #include /* needs size_t */ @@ -288,11 +299,12 @@ static inline void *r_new_copy(int size, void *data) { #include #include #include -#endif #include +#include +#endif #ifndef HAVE_EPRINTF -#define eprintf(x,y...) fprintf(stderr,x,##y) +#define eprintf(...) fprintf(stderr,__VA_ARGS__) #define eprint(x) fprintf(stderr,"%s\n",x) #define HAVE_EPRINTF 1 #endif diff --git a/libr/include/r_types_base.h b/libr/include/r_types_base.h index 43de257295..5c17dccc56 100644 --- a/libr/include/r_types_base.h +++ b/libr/include/r_types_base.h @@ -14,6 +14,10 @@ #define st8 signed char #define boolt int +#ifdef _MSC_VER +#define __attribute__(x) +#endif + typedef struct _ut80 { ut64 Low; ut16 High; diff --git a/libr/include/sdb/sdb.h b/libr/include/sdb/sdb.h index 38cdae14a1..336e93b244 100644 --- a/libr/include/sdb/sdb.h +++ b/libr/include/sdb/sdb.h @@ -1,7 +1,7 @@ #ifndef SDB_H #define SDB_H -#ifndef O_BINARY +#if !defined(O_BINARY) && !defined(_MSC_VER) #define O_BINARY 0 #endif @@ -29,7 +29,7 @@ extern "C" { #define SZT_ADD_OVFCHK(x, y) ((SIZE_MAX - (x)) <= (y)) #endif -#if __SDB_WINDOWS__ && !__CYGWIN__ +#if __SDB_WINDOWS__ && !__CYGWIN__ && !_MSC_VER #include #include #include diff --git a/libr/include/sdb/types.h b/libr/include/sdb/types.h index de89d32c91..27ea489c53 100644 --- a/libr/include/sdb/types.h +++ b/libr/include/sdb/types.h @@ -6,9 +6,10 @@ #include #include #include +#include #undef eprintf -#define eprintf(x,y...) fprintf(stderr,x,##y) +#define eprintf(...) fprintf(stderr,__VA_ARGS__) #ifndef SDB_API #if defined(__GNUC__) && __GNUC__ >= 4 @@ -30,7 +31,7 @@ #define __MINGW__ 1 #endif -#if __WIN32__ || __MINGW__ || __WINDOWS__ +#if __WIN32__ || __MINGW__ || __WINDOWS__ || defined(_MSC_VER) #define __SDB_WINDOWS__ 1 #include #define DIRSEP '\\' @@ -40,8 +41,10 @@ #define DIRSEP '/' #endif +#include #include #define ULLFMT "ll" + #if __SDB_WINDOWS__ && !__CYGWIN__ #define HAVE_MMAN 0 #else @@ -52,7 +55,6 @@ #define USE_MMAN HAVE_MMAN #endif -#include #ifndef UNUSED # define UNUSED diff --git a/libr/io/Makefile b/libr/io/Makefile index 3a1d904931..c05054bdff 100644 --- a/libr/io/Makefile +++ b/libr/io/Makefile @@ -6,7 +6,6 @@ DEPS+=r_socket STATIC_OBJS=$(subst ..,p/..,$(subst io_,p/io_,$(STATIC_OBJ))) OBJS=${STATIC_OBJS} OBJS+=io.o plugin.o map.o section.o desc.o cache.o undo.o buffer.o - CFLAGS+=-Wall -DCORELIB include ../socket/deps.mk diff --git a/libr/io/io.c b/libr/io/io.c index 344dbb26e1..4ece811e5f 100644 --- a/libr/io/io.c +++ b/libr/io/io.c @@ -4,6 +4,10 @@ #include "r_util.h" #include +#ifdef _MSC_VER +#pragma comment(lib, "advapi32.lib") +#endif + R_LIB_VERSION (r_io); /* allocate 128 MB */ diff --git a/libr/io/p/bochs.mk b/libr/io/p/bochs.mk index 7508b9fefe..c7ec7f5080 100644 --- a/libr/io/p/bochs.mk +++ b/libr/io/p/bochs.mk @@ -6,7 +6,7 @@ ALL_TARGETS+=${TARGET_BOCHS} LIB_PATH=$(SHLR)/bochs/ CFLAGS+=-I$(SHLR)/bochs/include/ -LDFLAGS+=$(SHLR)/bochs/lib/libbochs.a +LDFLAGS+=$(SHLR)/bochs/lib/libbochs.$(EXT_AR) include $(LIBR)/socket/deps.mk diff --git a/libr/io/p/gdb.mk b/libr/io/p/gdb.mk index 8c060bf6a5..ba3e8ad902 100644 --- a/libr/io/p/gdb.mk +++ b/libr/io/p/gdb.mk @@ -6,7 +6,7 @@ ALL_TARGETS+=${TARGET_GDB} LIB_PATH=$(SHLR)/gdb/ CFLAGS+=-I$(SHLR)/gdb/include/ -LDFLAGS+=$(SHLR)/gdb/lib/libgdbr.a +LDFLAGS+=$(SHLR)/gdb/lib/libgdbr.$(EXT_AR) include $(LIBR)/socket/deps.mk diff --git a/libr/io/p/io_default.c b/libr/io/p/io_default.c index 9e7e2ba14c..a9b48f4c4b 100644 --- a/libr/io/p/io_default.c +++ b/libr/io/p/io_default.c @@ -3,6 +3,9 @@ #include #include #include +#ifdef _MSC_VER +typedef unsigned int ssize_t; +#endif typedef struct r_io_mmo_t { char * filename; diff --git a/libr/io/p/io_r2pipe.c b/libr/io/p/io_r2pipe.c index 0eb32f5f87..97386eae22 100644 --- a/libr/io/p/io_r2pipe.c +++ b/libr/io/p/io_r2pipe.c @@ -79,7 +79,20 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { arr += 2; for (num[0] = numi = bufi = 0; bufi < count && *arr; arr++) { switch (*arr) { +#ifdef _MSC_VER + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': +#else case '0'...'9': +#endif num[numi++] = *arr; num[numi] = 0; break; diff --git a/libr/io/p/io_self.c b/libr/io/p/io_self.c index fa1c56f685..ebf83524e2 100644 --- a/libr/io/p/io_self.c +++ b/libr/io/p/io_self.c @@ -110,8 +110,12 @@ static int update_self_regions(RIO *io, int pid) { fclose (fd); return true; +#else +#ifdef _MSC_VER +#pragma message ("Not yet implemented for this platform") #else #warning not yet implemented for this platform +#endif return false; #endif } @@ -291,8 +295,12 @@ static int __system(RIO *io, RIODesc *fd, const char *cmd) { signal (SIGALRM, got_alarm); // TODO: use setitimer alarm (atoi (cmd + 6)); +#else +#ifdef _MSC_VER +#pragma message ("self:// alarm is not implemented for this platform yet") #else #warning "self:// alarm is not implemented for this platform yet" +#endif #endif } else if (!strncmp (cmd, "dlsym ", 6)) { const char *symbol = cmd + 6; diff --git a/libr/io/p/qnx.mk b/libr/io/p/qnx.mk index fbc2542c50..ec4c4ac8cc 100644 --- a/libr/io/p/qnx.mk +++ b/libr/io/p/qnx.mk @@ -6,7 +6,7 @@ ALL_TARGETS+=${TARGET_QNX} LIB_PATH=$(SHLR)/qnx/ CFLAGS+=-I$(SHLR)/qnx/include/ -LDFLAGS+=$(SHLR)/qnx/lib/libqnxr.a +LDFLAGS+=$(SHLR)/qnx/lib/libqnxr.$(EXT_AR) include $(LIBR)/socket/deps.mk diff --git a/libr/io/p/windbg.mk b/libr/io/p/windbg.mk index 339f13c99f..96b8ef44fb 100644 --- a/libr/io/p/windbg.mk +++ b/libr/io/p/windbg.mk @@ -6,7 +6,7 @@ ALL_TARGETS+=${TARGET_WINDBG} LIB_PATH=$(SHLR)/wind CFLAGS+=-I$(SHLR)/wind -LDFLAGS+=$(SHLR)/wind/libr_wind.a +LDFLAGS+=$(SHLR)/wind/libr_wind.$(EXT_AR) ifeq (${WITHPIC},0) LINKFLAGS+=../../util/libr_util.a diff --git a/libr/magic/apprentice.c b/libr/magic/apprentice.c index b848a2cfa1..f1c0e93a39 100644 --- a/libr/magic/apprentice.c +++ b/libr/magic/apprentice.c @@ -34,7 +34,11 @@ #if !USE_LIB_MAGIC #include +#ifdef _MSC_VER +#define MAXPATHLEN 255 +#else #include +#endif #include #if __UNIX__ #define QUICK 1 @@ -501,6 +505,10 @@ static void load_1(RMagic *ms, int action, const char *file, int *errs, struct r * const char *fn: name of magic file or directory */ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, const char *fn, int action) { +#ifdef _MSC_VER +#pragma message ("WARNING: magic/apprentice.c:apprentice_load bypassed !") + return 0; +#else ut32 marraycount, i, mentrycount = 0, starttest; struct r_magic_entry *marray; struct stat st; @@ -654,6 +662,7 @@ out: } *nmagicp = mentrycount; return 0; +#endif } /* diff --git a/libr/magic/config.h b/libr/magic/config.h index 34323a6223..b0bdeb35f9 100644 --- a/libr/magic/config.h +++ b/libr/magic/config.h @@ -20,6 +20,10 @@ #define HAVE_UNISTD_H 1 #define HAVE_WCHAR_H 1 +#ifdef _MSC_VER +#undef HAVE_UNISTD_H +#endif + // TODO: add dependency for zlib? /* #define HAVE_ZLIB_H 1 DO NOT ENABLE YET -- chl */ /* #define HAVE_LIBZ 1 DO NOT ENABLE YET -- ian */ diff --git a/libr/magic/file.h b/libr/magic/file.h index 1f81a0a353..e75f7d2b4e 100644 --- a/libr/magic/file.h +++ b/libr/magic/file.h @@ -48,6 +48,9 @@ /* Do this here and now, because struct stat gets re-defined on solaris */ #include #include +#ifdef _MSC_VER +typedef unsigned int ssize_t; +#endif /* Type for Unicode characters */ typedef unsigned long unichar; diff --git a/libr/magic/magic.c b/libr/magic/magic.c index b8bb0c88e3..30f4ff125d 100644 --- a/libr/magic/magic.c +++ b/libr/magic/magic.c @@ -90,10 +90,11 @@ R_API int r_magic_errno(RMagic* m) { #include #include -#include #include #include +#ifndef _MSC_VER #include /* for MAXPATHLEN */ +#endif #include #include @@ -139,6 +140,10 @@ static void free_mlist(struct mlist *mlist) { free (ml); } +#ifdef _MSC_VER +static int info_from_stat(RMagic *ms, short int md) { +#pragma message("TODO Windows: info_from_stat not supported.") +#else static int info_from_stat(RMagic *ms, mode_t md) { /* We cannot open it, but we were able to stat it. */ if (md & 0222) @@ -152,6 +157,7 @@ static int info_from_stat(RMagic *ms, mode_t md) { return -1; if (file_printf (ms, "no read permission") == -1) return -1; +#endif return 0; } @@ -161,6 +167,10 @@ static void close_and_restore (const RMagic *ms, const char *name, int fd, const } static const char *file_or_fd(RMagic *ms, const char *inname, int fd) { +#ifdef _MSC_VER +#pragma message ("WARNING: magic/magic.c: file_or_fd bypassed !") + return 0; +#else int ispipe = 0, rv = -1; unsigned char *buf; struct stat sb; @@ -250,6 +260,7 @@ done: free (buf); close_and_restore (ms, inname, fd, &sb); return rv == 0 ? file_getbuffer(ms) : NULL; +#endif } /* API */ diff --git a/libr/parse/p/6502_pseudo.mk b/libr/parse/p/6502_pseudo.mk index 9bca6d6e5a..80ae0bec9c 100644 --- a/libr/parse/p/6502_pseudo.mk +++ b/libr/parse/p/6502_pseudo.mk @@ -2,8 +2,13 @@ OBJ_6502PSEUDO+=parse_6502_pseudo.o TARGET_6502PSEUDO=parse_6502_pseudo.${EXT_SO} STATIC_OBJ+=${OBJ_6502PSEUDO} +ifeq ($(CC),cccl) +LIBDEPS=-L../../util -llibr_util +LIBDEPS+=-L../../flag -llibr_flag +else LIBDEPS=-L../../util -lr_util LIBDEPS+=-L../../flag -lr_flag +endif ifeq ($(WITHPIC),1) ALL_TARGETS+=${TARGET_6502PSEUDO} diff --git a/libr/parse/p/arm_pseudo.mk b/libr/parse/p/arm_pseudo.mk index 0b094107f4..7624c9f6d2 100644 --- a/libr/parse/p/arm_pseudo.mk +++ b/libr/parse/p/arm_pseudo.mk @@ -2,8 +2,13 @@ OBJ_ARMPSEUDO+=parse_arm_pseudo.o TARGET_ARMPSEUDO=parse_arm_pseudo.${EXT_SO} STATIC_OBJ+=${OBJ_ARMPSEUDO} +ifeq ($(CC),cccl) +LIBDEPS=-L../../util -llibr_util +LIBDEPS+=-L../../flag -llibr_flag +else LIBDEPS=-L../../util -lr_util LIBDEPS+=-L../../flag -lr_flag +endif ifeq ($(WITHPIC),1) ALL_TARGETS+=${TARGET_ARMPSEUDO} diff --git a/libr/parse/p/m68k_pseudo.mk b/libr/parse/p/m68k_pseudo.mk index 641a3f722b..e59749ce7d 100644 --- a/libr/parse/p/m68k_pseudo.mk +++ b/libr/parse/p/m68k_pseudo.mk @@ -3,9 +3,15 @@ OBJ_M68KPSEUDO+=parse_m68k_pseudo.o TARGET_M68KPSEUDO=parse_m68k_pseudo.${EXT_SO} ALL_TARGETS+=${TARGET_M68KPSEUDO} STATIC_OBJ+=${OBJ_M68KPSEUDO} +ifeq ($(CC),cccl) +LIBDEPS=-L../../util -llibr_util +LIBDEPS+=-L../../flag -llibr_flag +LIBDEPS+=$(STOP)/zip/librz.lib +else LIBDEPS=-L../../util -lr_util LIBDEPS+=-L../../flag -lr_flag LIBDEPS+=$(STOP)/zip/librz.a +endif ${TARGET_M68KPSEUDO}: ${OBJ_M68KPSEUDO} ${CC} $(call libname,parse_m68k_pseudo) ${LIBDEPS} \ diff --git a/libr/parse/p/mips_pseudo.mk b/libr/parse/p/mips_pseudo.mk index cf12b8bfdc..d3b3ab37c5 100644 --- a/libr/parse/p/mips_pseudo.mk +++ b/libr/parse/p/mips_pseudo.mk @@ -5,5 +5,10 @@ ALL_TARGETS+=${TARGET_MIPSPSEUDO} STATIC_OBJ+=${OBJ_MIPSPSEUDO} ${TARGET_MIPSPSEUDO}: ${OBJ_MIPSPSEUDO} +ifeq ($(CC),cccl) + ${CC} $(call libname,parse_mips_pseudo) -L../../util -llibr_util \ + $(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_MIPSPSEUDO} ${OBJ_MIPSPSEUDO} +else ${CC} $(call libname,parse_mips_pseudo) -L../../util -lr_util \ $(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_MIPSPSEUDO} ${OBJ_MIPSPSEUDO} +endif diff --git a/libr/parse/p/mreplace.mk b/libr/parse/p/mreplace.mk index 97a7e3520d..34f00ad343 100644 --- a/libr/parse/p/mreplace.mk +++ b/libr/parse/p/mreplace.mk @@ -5,6 +5,12 @@ ALL_TARGETS+=${TARGET_MREPLACE} STATIC_OBJ+=${OBJ_MREPLACE} ${TARGET_MREPLACE}: ${OBJ_MREPLACE} +ifeq ($(CC),cccl) ${CC} $(call libname,parse_mreplace) ${CFLAGS} $(LDFLAGS) \ ${OBJ_MREPLACE} \ - -L ../util -L ../../util -lr_util + -L../util -L../../util -llibr_util +else + ${CC} $(call libname,parse_mreplace) ${CFLAGS} $(LDFLAGS) \ + ${OBJ_MREPLACE} \ + -L../util -L../../util -lr_util +endif diff --git a/libr/parse/p/parse_mreplace/mreplace.c b/libr/parse/p/parse_mreplace/mreplace.c index d591bfdf16..d1b29bc65f 100644 --- a/libr/parse/p/parse_mreplace/mreplace.c +++ b/libr/parse/p/parse_mreplace/mreplace.c @@ -61,7 +61,11 @@ void sreplace(char *s,char *orig,char *rep,char multi,long dsize){ } char *mreplace(char *string, char *se,char *rep) { +#ifdef _MSC_VER +#define nmatch 16 +#else const size_t nmatch = 16; +#endif memChunk *search,*temp,*found,*ffound; unsigned long offset = 0; RRegexMatch pm[nmatch]; @@ -145,6 +149,9 @@ char *mreplace(char *string, char *se,char *rep) { memFree (ffound); r_regex_free (re); return res; +#ifdef _MSC_VER +#undef nmatch +#endif } char *treplace(char *data,char *search,char *replace){ diff --git a/libr/parse/p/ppc_pseudo.mk b/libr/parse/p/ppc_pseudo.mk index ace8501c37..be077d684b 100644 --- a/libr/parse/p/ppc_pseudo.mk +++ b/libr/parse/p/ppc_pseudo.mk @@ -5,5 +5,10 @@ ALL_TARGETS+=${TARGET_PPCPSEUDO} STATIC_OBJ+=${OBJ_PPCPSEUDO} ${TARGET_PPCPSEUDO}: ${OBJ_PPCPSEUDO} +ifeq ($(CC),cccl) + ${CC} $(call libname,parse_ppc_pseudo) -L../../util -llibr_util \ + ${LDFLAGS_SHARED} ${CFLAGS} ${LDFLAGS} -o ${TARGET_PPCPSEUDO} ${OBJ_PPCPSEUDO} +else ${CC} $(call libname,parse_ppc_pseudo) -L../../util -lr_util \ ${LDFLAGS_SHARED} ${CFLAGS} ${LDFLAGS} -o ${TARGET_PPCPSEUDO} ${OBJ_PPCPSEUDO} +endif diff --git a/libr/parse/p/x86_pseudo.mk b/libr/parse/p/x86_pseudo.mk index 609ebcf3b5..16148e5797 100644 --- a/libr/parse/p/x86_pseudo.mk +++ b/libr/parse/p/x86_pseudo.mk @@ -2,11 +2,17 @@ OBJ_X86PSEUDO+=parse_x86_pseudo.o TARGET_X86PSEUDO=parse_x86_pseudo.${EXT_SO} STATIC_OBJ+=${OBJ_X86PSEUDO} +ifeq ($(CC),cccl) +LIBDEPS=-L../../util -llibr_util +LIBDEPS+=-L../../flag -llibr_flag +LDFLAGS+=-L../../reg -llibr_reg +LDFLAGS+=-L../../cons -llibr_cons +else LIBDEPS=-L../../util -lr_util LIBDEPS+=-L../../flag -lr_flag LDFLAGS+=-L../../reg -lr_reg LDFLAGS+=-L../../cons -lr_cons -LDFLAGS+=-L../../cons +endif ifeq ($(WITHPIC),1) ALL_TARGETS+=${TARGET_X86PSEUDO} diff --git a/libr/parse/p/z80_pseudo.mk b/libr/parse/p/z80_pseudo.mk index 6cc6efbbc2..bac15f7fce 100644 --- a/libr/parse/p/z80_pseudo.mk +++ b/libr/parse/p/z80_pseudo.mk @@ -3,8 +3,13 @@ OBJ_z80PSEUDO+=parse_z80_pseudo.o TARGET_z80PSEUDO=parse_z80_pseudo.${EXT_SO} ALL_TARGETS+=${TARGET_z80PSEUDO} STATIC_OBJ+=${OBJ_z80PSEUDO} +ifeq ($(CC),cccl) +LIBDEPS=-L../../util -llibr_util +LIBDEPS+=-L../../flag -llibr_flag +else LIBDEPS=-L../../util -lr_util LIBDEPS+=-L../../flag -lr_flag +endif ${TARGET_z80PSEUDO}: ${OBJ_z80PSEUDO} ${CC} $(call libname,parse_z80_pseudo) ${LIBDEPS} $(LDFLAGS_SHARED) \ diff --git a/libr/socket/run.c b/libr/socket/run.c index 60f806d049..9da51c1d7b 100644 --- a/libr/socket/run.c +++ b/libr/socket/run.c @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -295,7 +295,11 @@ static int handle_redirection_proc (const char *cmd, bool in, bool out, bool err close (saved_stdout); return 0; #else +#ifdef _MSC_VER +#pragma message ("TODO: handle_redirection_proc: Not implemented for this platform") +#else #warning handle_redirection_proc : unimplemented for this platform +#endif return -1; #endif } @@ -325,7 +329,11 @@ static int handle_redirection(const char *cmd, bool in, bool out, bool err) { } } #else +#ifdef _MSC_VER +#pragma message ("string redirection handle not yet done") +#else #warning quoted string redirection handle not yet done +#endif #endif return 0; } else if (cmd[0] == '!') { @@ -711,7 +719,11 @@ R_API int r_run_config_env(RRunProfile *p) { is_child = true; if (p->_dofork && !p->_dodebug) { +#ifdef _MSC_VER + int child_pid = r_sys_fork (); +#else pid_t child_pid = r_sys_fork (); +#endif if (child_pid == -1) { eprintf("rarun2: cannot fork\n"); r_socket_free (child); diff --git a/libr/socket/socket.c b/libr/socket/socket.c index ecfad34950..ed4f639906 100644 --- a/libr/socket/socket.c +++ b/libr/socket/socket.c @@ -1,9 +1,10 @@ /* radare - LGPL - Copyright 2006-2015 - pancake */ -#include +/* must be included first because of winsock2.h and windows.h */ +#include #include #include -#include +#include #include #include #include @@ -11,7 +12,9 @@ #include #include #include -#include +#ifdef _MSC_VER +#pragma comment(lib, "ws2_32.lib") +#endif #if EMSCRIPTEN #define NETWORK_DISABLED 1 @@ -107,7 +110,11 @@ R_API bool r_socket_is_connected (RSocket *s) { #if __WINDOWS__ && !defined(__CYGWIN__) //&& !defined(__MINGW64__) char buf[2]; r_socket_block_time (s, 0, 0); +#ifdef _MSC_VER + int ret = recv (s->fd, (char*)&buf, 1, MSG_PEEK); +#else ssize_t ret = recv (s->fd, (char*)&buf, 1, MSG_PEEK); +#endif r_socket_block_time (s, 1, 0); return ret? true: false; #else @@ -181,7 +188,11 @@ R_API RSocket *r_socket_new (int is_ssl) { signal (SIGPIPE, SIG_IGN); #endif s->local = 0; +#ifdef _MSC_VER + s->fd = INVALID_SOCKET; +#else s->fd = -1; +#endif #if HAVE_LIB_SSL if (is_ssl) { s->sfd = NULL; @@ -213,7 +224,11 @@ R_API bool r_socket_connect (RSocket *s, const char *host, const char *port, int return false; } s->fd = socket (AF_INET, SOCK_STREAM, 0); +#ifdef _MSC_VER + if (s->fd == INVALID_SOCKET) +#else if (s->fd == -1) +#endif return false; unsigned long iMode = 1; @@ -225,14 +240,22 @@ R_API bool r_socket_connect (RSocket *s, const char *host, const char *port, int sa.sin_family = AF_INET; he = (struct hostent *)gethostbyname (host); if (he == (struct hostent*)0) { +#ifdef _MSC_VER + closesocket (s->fd); +#else close (s->fd); +#endif return false; } sa.sin_addr = *((struct in_addr *)he->h_addr); s->port = r_socket_port_by_name (port); sa.sin_port = htons (s->port); if (!connect (s->fd, (const struct sockaddr*)&sa, sizeof (struct sockaddr))) { +#ifdef _MSC_VER + closesocket (s->fd); +#else close (s->fd); +#endif return false; } iMode = 0; @@ -351,7 +374,11 @@ R_API bool r_socket_connect (RSocket *s, const char *host, const char *port, int /* close the file descriptor associated with the RSocket s */ R_API int r_socket_close_fd (RSocket *s) { +#ifdef _MSC_VER + return s->fd != INVALID_SOCKET ? closesocket (s->fd) : false; +#else return s->fd != -1 ? close (s->fd) : false; +#endif } /* shutdown the socket and close the file descriptor */ @@ -450,14 +477,22 @@ R_API bool r_socket_listen (RSocket *s, const char *port, const char *certfile) s->sa.sin_port = htons (s->port); // TODO honor etc/services if (bind (s->fd, (struct sockaddr *)&s->sa, sizeof (s->sa)) < 0) { r_sys_perror ("bind"); +#ifdef _MSC_VER + closesocket (s->fd); +#else close (s->fd); +#endif return false; } #if __UNIX__ || defined(__CYGWIN__) signal (SIGPIPE, SIG_IGN); #endif if (listen (s->fd, 32) < 0) { +#ifdef _MSC_VER + closesocket (s->fd); +#else close (s->fd); +#endif return false; } #if HAVE_LIB_SSL @@ -636,7 +671,12 @@ R_API int r_socket_write(RSocket *s, void *buf, int len) { } else #endif { +#ifdef _MSC_VER + char* winbuf = (char*) buf + len; + ret = send (s->fd, winbuf, b, 0); +#else ret = send (s->fd, buf+delta, b, 0); +#endif } //if (ret == 0) return -1; if (ret<1) break; diff --git a/libr/util/base85.c b/libr/util/base85.c index b197716a9c..11342245b4 100644 --- a/libr/util/base85.c +++ b/libr/util/base85.c @@ -25,7 +25,9 @@ #include #include +#ifndef _MSC_VER #include +#endif #include #include #include diff --git a/libr/util/buf.c b/libr/util/buf.c index ed64b56e56..ee6e5ffd31 100644 --- a/libr/util/buf.c +++ b/libr/util/buf.c @@ -501,7 +501,11 @@ static int r_buf_fcpy_at (RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int for (i = len = 0; i < n; i++) for (j = 0; fmt[j]; j++) { switch (fmt[j]) { + #ifdef _MSC_VER + case'0':case'1':case'2':case'3':case'4':case'5':case'6':case'7':case'8':case'9': + #else case '0'...'9': + #endif if (m == 1) m = r_num_get (NULL, &fmt[j]); continue; @@ -652,7 +656,11 @@ R_API int r_buf_write_at(RBuffer *b, ut64 addr, const ut8 *buf, int len) { } if (newlen > b->length) { b->length = newlen; +#ifdef _MSC_VER + _chsize (b->fd, newlen); +#else ftruncate (b->fd, newlen); +#endif } return r_sandbox_write (b->fd, buf, len); } diff --git a/libr/util/file.c b/libr/util/file.c index e879774f87..28f2952c3c 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -3,11 +3,9 @@ #include "r_types.h" #include "r_util.h" #include -#include #include #include #include -#include #include #if __UNIX__ #include @@ -15,6 +13,8 @@ #if __APPLE__ #include #endif +#include +#include R_API bool r_file_truncate (const char *filename, ut64 newsize) { int fd; @@ -32,7 +32,11 @@ R_API bool r_file_truncate (const char *filename, ut64 newsize) { if (fd == -1) { return false; } +#ifdef _MSC_VER + _chsize (fd, newsize); +#else ftruncate (fd, newsize); +#endif close (fd); return true; } @@ -91,9 +95,11 @@ R_API bool r_file_is_directory(const char *str) { if (stat (str, &buf) == -1) { return false; } +#ifdef S_IFBLK if ((S_IFBLK & buf.st_mode) == S_IFBLK) { return false; } +#endif return (S_IFDIR == (S_IFDIR & buf.st_mode))? true: false; } @@ -113,10 +119,20 @@ R_API bool r_file_exists(const char *str) { if (!str || !*str) { return false; } +#ifdef _MSC_VER + WIN32_FIND_DATA FindFileData; + HANDLE handle = FindFirstFile (str, &FindFileData); + int found = handle != INVALID_HANDLE_VALUE; + if (found) { + FindClose (handle); + } + return found > 0; +#else if (stat (str, &buf) == -1) { return false; } return (S_ISREG (buf.st_mode))? true: false; +#endif } R_API long r_file_proc_size(FILE *fd) { @@ -250,7 +266,9 @@ R_API char *r_stdin_slurp (int *sz) { } return buf; #else +#ifndef _MSC_VER #warning TODO r_stdin_slurp +#endif return NULL; #endif } diff --git a/libr/util/p_date.c b/libr/util/p_date.c index 14d4fbcce1..c60ec93025 100644 --- a/libr/util/p_date.c +++ b/libr/util/p_date.c @@ -2,13 +2,6 @@ #include "r_print.h" #include "r_util.h" -#if 1 -#include -#include -#include -#include -#include -#endif R_API int r_print_date_dos(RPrint *p, ut8 *buf, int len) { ut8 _time[2] = { buf[0], buf[1] }; @@ -108,7 +101,11 @@ R_API int r_print_date_get_now(RPrint *p, char *str) { } #else *str = 0; +#ifdef _MSC_VER +#pragma message ("r_print_date_now NOT IMPLEMENTED FOR THIS PLATFORM") +#else #warning r_print_date_now NOT IMPLEMENTED FOR THIS PLATFORM +#endif #endif return ret; } diff --git a/libr/util/sandbox.c b/libr/util/sandbox.c index da68dd43c3..12f58ff4c2 100644 --- a/libr/util/sandbox.c +++ b/libr/util/sandbox.c @@ -306,7 +306,6 @@ R_API DIR* r_sandbox_opendir (const char *path) { return NULL; } } - return opendir (path); } #endif diff --git a/libr/util/str.c b/libr/util/str.c index 659fa7c975..28efd6eda3 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -7,6 +7,9 @@ #include #include #include +#ifdef _MSC_VER +#define strncasecmp _strnicmp +#endif /* stable code */ static const char *nullstr = ""; diff --git a/libr/util/sys.c b/libr/util/sys.c index f47553f1a4..78efb52e14 100644 --- a/libr/util/sys.c +++ b/libr/util/sys.c @@ -42,7 +42,7 @@ extern char **environ; # define Sleep sleep #endif #endif -#if __WINDOWS__ && !defined(__CYGWIN__) +#if __WINDOWS__ && (defined(_MSC_VER) || !defined(__CYGWIN__)) # include # include typedef BOOL WINAPI (*QueryFullProcessImageNameA_t) (HANDLE, DWORD, LPTSTR, PDWORD); @@ -202,8 +202,12 @@ R_API void r_sys_backtrace(void) { printf ("[%d] pc == %p fp == %p\n", depth++, saved_pc, saved_fp); } #else +#ifdef _MSC_VER +#pragma message ("TODO: r_sys_bt : unimplemented") +#else #warning TODO: r_sys_bt : unimplemented #endif +#endif } R_API int r_sys_sleep(int secs) { @@ -241,7 +245,11 @@ R_API int r_sys_clearenv(void) { #endif return 0; #else +#ifdef _MSC_VER +#pragma message ("r_sys_clearenv : unimplemented for this platform") +#else #warning r_sys_clearenv : unimplemented for this platform +#endif return 0; #endif } @@ -561,7 +569,11 @@ R_API int r_sys_cmdbg (const char *str) { exit (0); return -1; #else +#ifdef _MSC_VER +#pragma message ("r_sys_cmdbg is not implemented for this platform") +#else #warning r_sys_cmdbg is not implemented for this platform +#endif return -1; #endif } diff --git a/libr/util/unum.c b/libr/util/unum.c index 63da35ae7c..199a1ba599 100644 --- a/libr/util/unum.c +++ b/libr/util/unum.c @@ -280,9 +280,14 @@ R_API ut64 r_num_math(RNum *num, const char *str) { num->dbz = 0; } ret = r_num_calc (num, str, &err); - if (err) eprintf ("r_num_calc error: (%s) in (%s)\n", err, str); - else if (num) num->value = ret; - if (num) num->value = ret; + if (err) { + eprintf ("r_num_calc error: (%s) in (%s)\n", err, str); + } else if (num) { + num->value = ret; + } + if (num) { + num->value = ret; + } return ret; #else ut64 ret = 0LL; diff --git a/libr/util/zip.c b/libr/util/zip.c index 335873f38e..25e1ee11cf 100644 --- a/libr/util/zip.c +++ b/libr/util/zip.c @@ -42,6 +42,9 @@ R_API ut8 *r_inflate(const ut8 *src, int srcLen, int *srcConsumed, int *dstLen) stream.opaque = Z_NULL; // + 32 tells zlib not to care whether the stream is a zlib or gzip stream +#ifdef _MSC_VER +#pragma message ("TODO: Windows support here. Check dirent.h PR") +#else if (inflateInit2 (&stream, MAX_WBITS + 32) != Z_OK) { return NULL; } @@ -77,5 +80,6 @@ R_API ut8 *r_inflate(const ut8 *src, int srcLen, int *srcConsumed, int *dstLen) err_exit: inflateEnd (&stream); free (dst); +#endif return NULL; } diff --git a/mk/cccl.mk b/mk/cccl.mk new file mode 100644 index 0000000000..80b10e5598 --- /dev/null +++ b/mk/cccl.mk @@ -0,0 +1,25 @@ +ifeq (${_INCLUDE_MK_CCCL_},) +_INCLUDE_MK_CCCL_=1 +CC?=cccl +LINK= +RANLIB=echo no ranlib for +ONELIB=0 +CC_AR=arlib q ${LIBAR} +AR=arlib +EXT_AR=lib +CFLAGS+=-MD +CFLAGS_INCLUDE=-I +LDFLAGS_LINK=-l +LDFLAGS_LINKPATH=-L +CFLAGS_OPT0=-O0 +CFLAGS_OPT1=-O1 +CFLAGS_OPT2=-O2 +CFLAGS_OPT3=-O3 +CFLAGS_DEBUG=-g +PIC_CFLAGS= + +LDFLAGS_LIB=${LDFLAGS} -shared +LDFLAGS_SONAME=-Wl,-soname= + +CC_LIB=${CC} ${LDFLAGS_LIB} -o ${LIBSO} +endif diff --git a/mk/platform.mk b/mk/platform.mk index b7a5b997df..8d272566ce 100755 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -13,9 +13,12 @@ else ifneq (,$(findstring msys,${OSTYPE})) PIC_CFLAGS= else +ifeq ($(CC),cccl) +PIC_CFLAGS= +else PIC_CFLAGS=-fPIC endif endif endif endif - +endif diff --git a/shlr/Makefile b/shlr/Makefile index 4b6a9c64c4..2be66ec432 100644 --- a/shlr/Makefile +++ b/shlr/Makefile @@ -38,11 +38,12 @@ SHLR?=$(shell pwd) AR?=ar RANLIB?=ranlib MODS=sdb zip udis86 java tcc +MODS+=gdb qnx +ifneq ($(CC),cccl) ifeq (1,$(WITH_GPL)) MODS+=grub endif -MODS+=gdb -MODS+=qnx +endif SDB_URL=git://github.com/radare/sdb #SDB_URL=/Users/pancake/prg/sdb SPP_URL=git://github.com/radare/spp @@ -83,9 +84,14 @@ else SDB_TARGETS+=sdb/sdb endif +PIC= +ifneq ($(CC),cccl) +PIC=-fPIC ifeq ($(filter sdb/sdb${BUILD_EXT_EXE},$(SDB_TARGETS)),) SDB_TARGETS+=sdb/sdb${BUILD_EXT_EXE} endif +endif + targets: for TARGET in ${SDB_TARGETS} ; do ${MAKE} $$TARGET ; done @@ -107,7 +113,7 @@ ${SDB_TARGETS}: @echo $(MAKE) -C sdb clean $(MAKE) -C sdb src/sdb_version.h - $(MAKE) -C sdb/src CC=${HOST_CC} LDFLAGS='${HOST_LDFLAGS}' CPPFLAGS='' CFLAGS='${HOST_CFLAGS} -fPIC' bin + $(MAKE) -C sdb/src CC=${HOST_CC} LDFLAGS='${HOST_LDFLAGS}' CPPFLAGS='' CFLAGS='${HOST_CFLAGS} ${PIC}' bin cp -f sdb/src/sdb${BUILD_EXT_EXE} sdb/src/.sdb${BUILD_EXT_EXE} @echo @echo ">>>>>>>>>>>>>>>>" @@ -117,7 +123,7 @@ ${SDB_TARGETS}: $(MAKE) -C sdb clean cd sdb ; $(MAKE) src/sdb_version.h cd sdb/src ; $(MAKE) ARCH=xxx RANLIB="${RANLIB}" CFLAGS_SHARED="${CFLAGS_SHARED}" \ - CC="${CC}" AR="${AR}" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" libsdb.a + CC="${CC}" AR="${AR}" CFLAGS='${CFLAGS}' LDFLAGS='${LDFLAGS}' libsdb.a ${RANLIB} sdb/src/libsdb.a ifneq (${EXT_AR},a) -cp -f sdb/src/libsdb.a sdb/src/libsdb.${EXT_AR} @@ -142,7 +148,7 @@ bochs: sdb-clean clean-sdb: $(MAKE) -C sdb clean rm -f sdb/sdb.exe - rm -f sdb/src/libsdb.a + rm -f sdb/src/libsdb.${EXT_AR} sdb-sync sync-sdb: rm -rf sdb sdb.vc @@ -162,7 +168,7 @@ sdb-sync sync-sdb: git add $I/sdb* git add sdb -$(TCCLIB) libr_tcc/libr_tcc.a: +$(TCCLIB) libr_tcc/libr_tcc.${EXT_AR}: cd libr_tcc ; $(MAKE) udis-sync udis86-sync sync-udis sync-udis86: diff --git a/shlr/bochs/Makefile b/shlr/bochs/Makefile index e8e77575f8..f41c94f428 100644 --- a/shlr/bochs/Makefile +++ b/shlr/bochs/Makefile @@ -11,8 +11,13 @@ CFLAGS+=-Iinclude -I${LIBR}/include MAJOR=0 MINOR=1 LD=$(CC) +ifeq ($(LD),cccl) +LDFLAGS+=-L${LIBR}/socket -llibr_socket +LDFLAGS+=-L${LIBR}/util -llibr_util +else LDFLAGS+=-L${LIBR}/socket -lr_socket LDFLAGS+=-L${LIBR}/util -lr_util +endif ifeq ($(OSTYPE),darwin) LDFLAGS_SHARED=-dynamiclib else @@ -26,17 +31,17 @@ SRC_D=src SRC_C=$(wildcard $(SRC_D)/*.c) SRC_O=$(SRC_C:.c=.o) -all: lib/$(LIBNAME).a +all: lib/$(LIBNAME).$(EXT_AR) #$(LD) -shared -Wl,-soname,$(LIBNAME).so -o lib/$(LIBNAME).so $(SRC_O) lib: mkdir -p lib -lib/$(LIBNAME).a: lib $(SRC_O) +lib/$(LIBNAME).$(EXT_AR): lib $(SRC_O) mkdir -p lib $(LD) $(PIC_CFLAGS) $(LDFLAGS_SHARED) -o lib/$(LIBFILE) $(CFLAGS) $(SRC_O) $(LDFLAGS) $(LINK) - $(AR) rvs lib/$(LIBNAME).a $(SRC_O) - $(RANLIB) lib/$(LIBNAME).a + $(AR) rvs lib/$(LIBNAME).$(EXT_AR) $(SRC_O) + $(RANLIB) lib/$(LIBNAME).$(EXT_AR) clean: -rm -f $(SRC_O) diff --git a/shlr/bochs/include/libbochs.h b/shlr/bochs/include/libbochs.h index 93d2e031ba..83f6bfb09c 100644 --- a/shlr/bochs/include/libbochs.h +++ b/shlr/bochs/include/libbochs.h @@ -46,8 +46,12 @@ bool bochs_open(libbochs_t* b, const char *rutaBochs, const char *rutaConfig); #if ENABLE_DEBUG #define lprintf(x,y...) { FILE *fd;fd=fopen("bochs.io.log", "a"); if (fd) {fprintf(fd,x,##y);fflush(fd);fclose(fd); }} #else +#ifdef _MSC_VER +#define lprintf(x,...) {} +#else #define lprintf(x,y...) {} #endif +#endif /*! diff --git a/shlr/bochs/src/libbochs.c b/shlr/bochs/src/libbochs.c index b3ffacf1dc..c6cb3ab0c9 100644 --- a/shlr/bochs/src/libbochs.c +++ b/shlr/bochs/src/libbochs.c @@ -7,6 +7,9 @@ static char *lpTmpBuffer; //[0x2800u]; #define SIZE_BUF 0x5800 * 2 #if __WINDOWS__ +#ifdef _MSC_VER +#pragma comment(lib, "user32.lib") +#endif int RunRemoteThread_(libbochs_t* b, const ut8 *lpBuffer, ut32 dwSize, int a4, ut32 *lpExitCode) { LPVOID pProcessMemory; HANDLE hInjectThread; diff --git a/shlr/gdb/Makefile b/shlr/gdb/Makefile index b167651015..e9cf391dde 100644 --- a/shlr/gdb/Makefile +++ b/shlr/gdb/Makefile @@ -4,7 +4,8 @@ include ../../mk/$(COMPILER).mk include ../../shlr/zip/deps.mk EDITOR?=vim CC?=gcc -AR?=ar +CC_AR?=ar +AR?=$(CC_AR) RANLIB?=ranlib LIBNAME=libgdbr LIBFILE=$(LIBNAME).$(EXT_SO) @@ -13,8 +14,15 @@ CFLAGS+=-Iinclude -I${LIBR}/include MAJOR=0 MINOR=1 LD=$(CC) +ifeq ($(LD),cccl) +LDFLAGS+=-L${LIBR}/socket -llibr_socket +LDFLAGS+=-L${LIBR}/util -llibr_util +EXT_AR?=lib +else LDFLAGS+=-L${LIBR}/socket -lr_socket LDFLAGS+=-L${LIBR}/util -lr_util +EXT_AR?=a +endif ifeq (${OSTYPE},darwin) LDFLAGS_SHARED=-dynamiclib @@ -44,7 +52,7 @@ SRC_O=$(SRC_C:.c=.o) TEST_C=$(wildcard $(TEST_D)/*.c) TEST_O=$(TEST_C:.c=.o) -all: $(LIB)/$(LIBNAME).a +all: $(LIB)/$(LIBNAME).${EXT_AR} # make default: make @@ -55,11 +63,11 @@ prepare: $(LIB): mkdir -p $(LIB) -$(LIB)/$(LIBNAME).a: $(LIB) $(SRC_O) +$(LIB)/$(LIBNAME).${EXT_AR}: $(LIB) $(SRC_O) $(LD) $(PIC_CFLAGS) $(LDFLAGS_SHARED) -o $(LIB)/$(LIBFILE) $(CFLAGS) $(SRC_O) $(LDFLAGS) $(LINK) - $(AR) rvs $(LIB)/$(LIBNAME).a $(SRC_O) + $(AR) rvs $(LIB)/$(LIBNAME).${EXT_AR} $(SRC_O) # required for solaris and w32 - $(RANLIB) $(LIB)/$(LIBNAME).a + $(RANLIB) $(LIB)/$(LIBNAME).${EXT_AR} clean: -rm -f $(SRC_O) diff --git a/shlr/gdb/deps.mk b/shlr/gdb/deps.mk index cc21ca650f..865b0cc26d 100644 --- a/shlr/gdb/deps.mk +++ b/shlr/gdb/deps.mk @@ -1 +1 @@ -LINK+=../../shlr/gdb/lib/libgdbr.a +LINK+=../../shlr/gdb/lib/libgdbr.$(EXT_AR) diff --git a/shlr/gdb/include/libgdbr.h b/shlr/gdb/include/libgdbr.h index 7dd4f05507..a1e426f125 100644 --- a/shlr/gdb/include/libgdbr.h +++ b/shlr/gdb/include/libgdbr.h @@ -3,7 +3,11 @@ #define LIBGDBR_H #include +#ifdef _MSC_VER +typedef unsigned int ssize_t; +#else #include +#endif #include "arch.h" #include "r_types_base.h" diff --git a/shlr/gdb/include/packet.h b/shlr/gdb/include/packet.h index 1d38bbeb1a..494aa37c36 100644 --- a/shlr/gdb/include/packet.h +++ b/shlr/gdb/include/packet.h @@ -10,11 +10,10 @@ #include #if __WINDOWS__ #include -#if !__CYGWIN__ +#if !__CYGWIN__ && !defined(_MSC_VER) #include #endif #endif - /*! * \brief sends a packet sends a packet to the established connection * \param instance the "instance" of the current libgdbr session diff --git a/shlr/gdb/src/gdbclient/core.c b/shlr/gdb/src/gdbclient/core.c index f04c62f379..d548f13077 100644 --- a/shlr/gdb/src/gdbclient/core.c +++ b/shlr/gdb/src/gdbclient/core.c @@ -203,7 +203,7 @@ int gdbr_read_registers(libgdbr_t *g) { } int gdbr_read_memory(libgdbr_t *g, ut64 address, ut64 len) { - char command[255] = {}; + char command[255] = {0}; int ret; if (!g) { return -1; @@ -225,7 +225,7 @@ int gdbr_read_memory(libgdbr_t *g, ut64 address, ut64 len) { } int gdbr_write_memory(libgdbr_t *g, ut64 address, const uint8_t *data, ut64 len) { - char command[255] = {}; + char command[255] = {0}; int ret = 0; int command_len; char *tmp; @@ -442,7 +442,7 @@ int test_command(libgdbr_t *g, const char *command) { } int send_vcont(libgdbr_t *g, const char *command, int thread_id) { - char tmp[255] = {}; + char tmp[255] = {0}; int ret; if (!g) { return -1; @@ -466,7 +466,7 @@ int send_vcont(libgdbr_t *g, const char *command, int thread_id) { } int set_bp(libgdbr_t *g, ut64 address, const char *conditions, enum Breakpoint type) { - char tmp[255] = {}; + char tmp[255] = {0}; int ret = 0; if (!g) { return -1; @@ -520,7 +520,7 @@ int gdbr_remove_hwbp(libgdbr_t *g, ut64 address) { } int remove_bp(libgdbr_t *g, ut64 address, enum Breakpoint type) { - char tmp[255] = {}; + char tmp[255] = {0}; int ret = 0; if (!g) { return -1; diff --git a/shlr/grub/include/grub/misc.h b/shlr/grub/include/grub/misc.h index caead36f50..c1381e3cae 100644 --- a/shlr/grub/include/grub/misc.h +++ b/shlr/grub/include/grub/misc.h @@ -46,7 +46,7 @@ #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0])) #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } -#define grub_dprintf(condition, fmt, args...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, fmt, ## args) +#define grub_dprintf(condition, fmt, ...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, fmt, ## __VA_ARGS__) /* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */ #define grub_memcpy(d,s,n) grub_memmove ((d), (s), (n)) diff --git a/shlr/java/Makefile b/shlr/java/Makefile index 02afed6f3d..f13e45f0a2 100644 --- a/shlr/java/Makefile +++ b/shlr/java/Makefile @@ -1,5 +1,10 @@ NAME=r_java -LIBAR?=libr_java.a +ifeq ($(CC),cccl) +EXT_AR=lib +else +EXT_AR=a +endif +LIBAR?=libr_java.$(EXT_AR) include ../../config-user.mk include ../../global.mk @@ -26,19 +31,19 @@ CFLAGS+=-I../../libr/include LDFLAGS+=-L../../libr/util OBJS=code.o class.o ops.o dsojson.o -all: libr_java.a +all: libr_java.$(EXT_AR) RANLIB?=ranlib -libr_java.a: ${OBJS} - rm -f libr_java.a +libr_java.$(EXT_AR): ${OBJS} + rm -f libr_java.$(EXT_AR) ${CC_AR} ${OBJS} - ${RANLIB} libr_java.a + ${RANLIB} libr_java.$(EXT_AR) out: ${OBJS} main.o echo "COMPILER: ${COMPILER} ${CC}" ${CC} ${LDFLAGS} ${CFLAGS} -I. ${OBJS} main.o \ - -lr_util ../sdb/src/libsdb.a ${LINK} -o out + -lr_util ../sdb/src/libsdb.$(EXT_AR) ${LINK} -o out clean: - rm -f ${OBJS} main.o a.out libr_java.a out + rm -f ${OBJS} main.o a.out libr_java.$(EXT_AR) out diff --git a/shlr/qnx/Makefile b/shlr/qnx/Makefile index a48e61be7a..d5ea6161c3 100644 --- a/shlr/qnx/Makefile +++ b/shlr/qnx/Makefile @@ -12,8 +12,13 @@ CFLAGS+=-Iinclude -I${LIBR}/include MAJOR=0 MINOR=1 LD=$(CC) +ifeq ($(LD),cccl) +LDFLAGS+=-L${LIBR}/socket -llibr_socket +LDFLAGS+=-L${LIBR}/util -llibr_util +else LDFLAGS+=-L${LIBR}/socket -lr_socket LDFLAGS+=-L${LIBR}/util -lr_util +endif ifeq ($(OSTYPE),darwin) LDFLAGS_SHARED=-dynamiclib else @@ -41,7 +46,7 @@ SRC_O=$(SRC_C:.c=.o) TEST_C=$(wildcard $(TEST_D)/*.c) TEST_O=$(TEST_C:.c=.o) -all: $(LIB)/$(LIBNAME).a +all: $(LIB)/$(LIBNAME).$(EXT_AR) # make default: make @@ -53,11 +58,11 @@ prepare: $(LIB): mkdir -p $(LIB) -$(LIB)/$(LIBNAME).a: $(LIB) $(SRC_O) +$(LIB)/$(LIBNAME).$(EXT_AR): $(LIB) $(SRC_O) $(LD) $(PIC_CFLAGS) $(LDFLAGS_SHARED) -o $(LIB)/$(LIBFILE) $(CFLAGS) $(SRC_O) $(LDFLAGS) $(LINK) - $(AR) rvs $(LIB)/$(LIBNAME).a $(SRC_O) + $(AR) rvs $(LIB)/$(LIBNAME).$(EXT_AR) $(SRC_O) # required for solaris and w32 - $(RANLIB) $(LIB)/$(LIBNAME).a + $(RANLIB) $(LIB)/$(LIBNAME).$(EXT_AR) clean: -rm -f $(SRC_O) diff --git a/shlr/qnx/deps.mk b/shlr/qnx/deps.mk index dd253ae43c..d6f431400f 100644 --- a/shlr/qnx/deps.mk +++ b/shlr/qnx/deps.mk @@ -1 +1 @@ -LINK+=../../shlr/qnx/lib/libqnxr.a +LINK+=../../shlr/qnx/lib/libqnxr.$(EXT_AR) diff --git a/shlr/qnx/include/libqnxr.h b/shlr/qnx/include/libqnxr.h index 9f92b51bc1..312444d15f 100644 --- a/shlr/qnx/include/libqnxr.h +++ b/shlr/qnx/include/libqnxr.h @@ -3,7 +3,12 @@ #define LIBQNXR_H #include +#ifdef _MSC_VER +typedef unsigned int ssize_t; +typedef int pid_t; +#else #include +#endif #include "arch.h" #include "r_types_base.h" diff --git a/shlr/qnx/include/packet.h b/shlr/qnx/include/packet.h index 5adb165c1b..630a932a45 100644 --- a/shlr/qnx/include/packet.h +++ b/shlr/qnx/include/packet.h @@ -10,7 +10,7 @@ #include #if __WINDOWS__ #include -#if !__CYGWIN__ +#if !__CYGWIN__ && !defined(MSC_VER) #include #endif #endif diff --git a/shlr/qnx/src/utils.c b/shlr/qnx/src/utils.c index 2d4ea5ef70..ae6a84c332 100644 --- a/shlr/qnx/src/utils.c +++ b/shlr/qnx/src/utils.c @@ -113,6 +113,8 @@ int errnoconvert (int x) { {NTO_ELIBEXEC, ENOEXEC}, {NTO_EILSEQ, EILSEQ}, {NTO_ENOSYS, ENOSYS} +#else + {0} #endif }; int i; diff --git a/shlr/rar/cpu.c b/shlr/rar/cpu.c new file mode 100644 index 0000000000..c5a5f0ea37 --- /dev/null +++ b/shlr/rar/cpu.c @@ -0,0 +1,146 @@ +/* RAR-VM assembler/disassembler by pancake for radare with love */ +/* this implementation is licensed under LGPLv3 - 2012 */ + +#include +#include + +// XXX little endian only? + +/* helpers */ +#define eprintf(x,...) fprintf(stderr,x,##__VA_ARGS__) +#define SKIPSPACES(x) if (x) while (*x==' '||*x=='\t') x++ +static const char *skipspaces(const char *x) { SKIPSPACES(x); return x; } +//static const char *regs = "r0\x00r1\x00r2\x00r3\x00r4\x00r5\x00r6\x00r7"; +//static const char *getregi(int n) { return (n>=0&&n<=7)? regs+(3*n): "r?"; } +static int getreg(const char *s) { + if (s[0]=='r' && s[2]=='\0') { + int n = s[1]-'0'; + if (n<8) return n; + } + return -1; +} + +// ugly global vars +typedef struct { + int bits; + unsigned char *out; +} Bitbuf; + +//static void clrbit(Bitbuf *bb) { memset (bb->out, 0, 1+(bb->bits/8)); } + +static int bitget(Bitbuf *bb, int bit) { + if (bit>=bb->bits) return -1; + return (bb->out[bit/8] & (1<<((bit%8))))? 1: 0; +} + +static void bitadd(Bitbuf *bb, unsigned int v, int n) { + int i, b, bit; + for (i=0; ibits++) { + b = (bb->bits+i)/8; + bit = (bb->bits+i)%8; +//printf ("[%d].%d = %d\n", b, bit, v& (1<<(n-i-1))); + if (!bit) bb->out[b] = 0; +//printf ("BIT (%d)\n", n-i-1); + //if (v&(1<<(n-i-1))) bb->out[b] |= 1<out[b] |= 1<bits) + for (i=0; i0) + ret |= (1<bits) + for (i=0; i0) + ret |= (1<<(c-i-1)); + return ret; +} + +#endif +static inline const char *opcode_str (int n) { + if (n>=0 && n 0) { - ssize_t r = read (c->fd, buf, len); + ut32 r = read (c->fd, buf, len); if (r < 1 || (ut32) r != len) { return false; } diff --git a/shlr/sdb/src/journal.c b/shlr/sdb/src/journal.c index 04a0cb064b..1f9e1ce980 100644 --- a/shlr/sdb/src/journal.c +++ b/shlr/sdb/src/journal.c @@ -1,7 +1,11 @@ /* sdb - MIT - Copyright 2011-2016 - pancake */ #include "sdb.h" +#ifdef _MSC_VER +#include +#else #include +#endif #include static const char *sdb_journal_filename(Sdb *s) { @@ -96,7 +100,11 @@ SDB_API bool sdb_journal_log(Sdb *s, const char *key, const char *val) { SDB_API bool sdb_journal_clear(Sdb *s) { if (s->journal != -1) { +#ifdef _MSC_VER + return !_chsize (s->journal, 0); +#else return !ftruncate (s->journal, 0); +#endif } return false; } diff --git a/shlr/sdb/src/json/js0n.c b/shlr/sdb/src/json/js0n.c index eaff06a08c..b7af1ddf09 100644 --- a/shlr/sdb/src/json/js0n.c +++ b/shlr/sdb/src/json/js0n.c @@ -5,6 +5,12 @@ #include "rangstr.h" +#ifdef _MSC_VER +#pragma message ("TODO: json not implemented for this platform") +int js0n(const ut8 *js, RangstrType len, RangstrType *out) { + return 1; +} +#else #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) #pragma GCC diagnostic push #endif @@ -145,3 +151,4 @@ l_utf_continue: go = gostring; goto l_loop; } +#endif diff --git a/shlr/sdb/src/lock.c b/shlr/sdb/src/lock.c index 14ddb24c18..ac94bb7439 100644 --- a/shlr/sdb/src/lock.c +++ b/shlr/sdb/src/lock.c @@ -2,7 +2,11 @@ #include #include +#ifdef _MSC_VER +#include +#else #include +#endif #include #include "sdb.h" @@ -50,7 +54,7 @@ SDB_API int sdb_lock_wait(const char *s) { // wait forever here? while (!sdb_lock (s)) { // TODO: if waiting too much return 0 -#if __SDB_WINDOWS__ +#if __SDB_WINDOWS__ || _MSC_VER Sleep (500); // hack #else // TODO use lockf() here .. flock is not much useful (fd, LOCK_EX); diff --git a/shlr/sdb/src/sdb.h b/shlr/sdb/src/sdb.h index 38cdae14a1..336e93b244 100644 --- a/shlr/sdb/src/sdb.h +++ b/shlr/sdb/src/sdb.h @@ -1,7 +1,7 @@ #ifndef SDB_H #define SDB_H -#ifndef O_BINARY +#if !defined(O_BINARY) && !defined(_MSC_VER) #define O_BINARY 0 #endif @@ -29,7 +29,7 @@ extern "C" { #define SZT_ADD_OVFCHK(x, y) ((SIZE_MAX - (x)) <= (y)) #endif -#if __SDB_WINDOWS__ && !__CYGWIN__ +#if __SDB_WINDOWS__ && !__CYGWIN__ && !_MSC_VER #include #include #include diff --git a/shlr/sdb/src/types.h b/shlr/sdb/src/types.h index de89d32c91..555b2b805b 100644 --- a/shlr/sdb/src/types.h +++ b/shlr/sdb/src/types.h @@ -6,9 +6,10 @@ #include #include #include +#include #undef eprintf -#define eprintf(x,y...) fprintf(stderr,x,##y) +#define eprintf(...) fprintf(stderr,__VA_ARGS__) #ifndef SDB_API #if defined(__GNUC__) && __GNUC__ >= 4 @@ -40,9 +41,11 @@ #define DIRSEP '/' #endif +#include + #include #define ULLFMT "ll" -#if __SDB_WINDOWS__ && !__CYGWIN__ +#if defined(_MSC_VER) || (__SDB_WINDOWS__ && !__CYGWIN__) #define HAVE_MMAN 0 #else #define HAVE_MMAN 1 @@ -52,7 +55,6 @@ #define USE_MMAN HAVE_MMAN #endif -#include #ifndef UNUSED # define UNUSED @@ -97,7 +99,11 @@ #include "config.h" static inline int seek_set(int fd, off_t pos) { +#ifdef _MSC_VER + return ((fd == -1) || (_lseek (fd, pos, SEEK_SET) == -1))? 0:1; +#else return ((fd == -1) || (lseek (fd, (off_t) pos, SEEK_SET) == -1))? 0:1; +#endif } static inline void ut32_pack(char s[4], ut32 u) { diff --git a/shlr/sdb/src/util.c b/shlr/sdb/src/util.c index 39bf3f57b8..9d0e3140cb 100644 --- a/shlr/sdb/src/util.c +++ b/shlr/sdb/src/util.c @@ -6,9 +6,37 @@ #if USE_MONOTONIC_CLOCK #include +#else +#ifdef _MSC_VER +#pragma message ("TODO: Windows support is ugly here") +#include +int gettimeofday(struct timeval* p, void* tz) { + ULARGE_INTEGER ul; // As specified on MSDN. + FILETIME ft; + + // Returns a 64-bit value representing the number of + // 100-nanosecond intervals since January 1, 1601 (UTC). + GetSystemTimeAsFileTime(&ft); + + // Fill ULARGE_INTEGER low and high parts. + ul.LowPart = ft.dwLowDateTime; + ul.HighPart = ft.dwHighDateTime; + // Convert to microseconds. + ul.QuadPart /= 10ULL; + // Remove Windows to UNIX Epoch delta. + ul.QuadPart -= 11644473600000000ULL; + // Modulo to retrieve the microseconds. + p->tv_usec = (long) (ul.QuadPart % 1000000LL); + // Divide to retrieve the seconds. + p->tv_sec = (long) (ul.QuadPart / 1000000LL); + + return 0; +} + #else #include #endif +#endif SDB_API ut32 sdb_hash_len(const char *s, ut32 *len) { ut32 h = CDB_HASHSTART; @@ -214,7 +242,7 @@ SDB_API const char *sdb_const_anext(const char *str, const char **next) { } SDB_API ut64 sdb_now () { -#if USE_MONOTINIC_CLOCK +#if USE_MONOTONIC_CLOCK struct timespec ts; if (!clock_gettime (CLOCK_MONOTONIC, &ts)) { return ts.tv_sec; diff --git a/shlr/spp/r_api.h b/shlr/spp/r_api.h index 4414bfeadf..97b10ac702 100644 --- a/shlr/spp/r_api.h +++ b/shlr/spp/r_api.h @@ -22,7 +22,9 @@ #include #endif #if __WIN32__ || MINGW32 && !__CYGWIN__ + #ifndef _MSC_VER #include + #endif typedef int socklen_t; #undef USE_SOCKETS #define __WINDOWS__ 1 diff --git a/shlr/spp/spp.h b/shlr/spp/spp.h index 4b730034f5..5be628a2d1 100644 --- a/shlr/spp/spp.h +++ b/shlr/spp/spp.h @@ -14,6 +14,7 @@ int r_sys_setenv(const char *key, const char *value); #ifdef __WINDOWS__ #include +#include #define popen _popen #define pclose _pclose #define srandom srand diff --git a/shlr/tcc/Makefile b/shlr/tcc/Makefile index 443eacc42d..b9c2a94983 100644 --- a/shlr/tcc/Makefile +++ b/shlr/tcc/Makefile @@ -28,19 +28,25 @@ LDFLAGS+=-shared ifeq (${OSNAME},darwin) SOEXT?=dylib else +ifeq ($(CC),cccl) +EXT_AR=lib +SOEXT?=dll +else +EXT_AR=a SOEXT?=so endif +endif LIBNAME=libr_tcc.${SOEXT} -all: ${LIBNAME} libr_tcc.a +all: ${LIBNAME} libr_tcc.$(EXT_AR) ${LIBNAME}: ${OFILES} ${CC} -o ${LIBNAME} ${LDFLAGS} ${OFILES} -libr_tcc.a: ${OFILES} - rm -f libr_tcc.a - ${AR} q libr_tcc.a ${OFILES} - ${RANLIB} libr_tcc.a +libr_tcc.$(EXT_AR): ${OFILES} + rm -f libr_tcc.$(EXT_AR) + ${AR} q libr_tcc.$(EXT_AR) ${OFILES} + ${RANLIB} libr_tcc.$(EXT_AR) clean: - rm -f ${LIBNAME} *.o *.a + rm -f ${LIBNAME} *.o *.$(EXT_AR) diff --git a/shlr/tcc/tcc.h b/shlr/tcc/tcc.h index 32cde48810..68f279b433 100644 --- a/shlr/tcc/tcc.h +++ b/shlr/tcc/tcc.h @@ -37,7 +37,9 @@ #include #include #include +#ifndef _MSC_VER #include +#endif #include #include #include @@ -93,6 +95,10 @@ typedef unsigned char uint8_t; typedef unsigned short int uint16_t; typedef unsigned int uint32_t; typedef unsigned long long int uint64_t; +#ifdef _MSC_VER +typedef char int8_t; +typedef long long int int64_t; +#endif #endif #define LDOUBLE_SIZE 12 diff --git a/shlr/udis86/Makefile b/shlr/udis86/Makefile index 7c79f6aab7..80fe4765c3 100644 --- a/shlr/udis86/Makefile +++ b/shlr/udis86/Makefile @@ -9,7 +9,7 @@ CFLAGS+=-DHAVE_STRING_H=1 all: $(OUT) $(OUT): - $(CC) $(CFLAGS) $(LDFLAGS) -c `echo $@|sed -e 's,\.o,\.c,g'` + $(CC) $(CFLAGS) $(LDFLAGS) -c `echo $@|sed -e 's,\.o,\.c,g'` -o $@ sync: rm -rf tmp diff --git a/shlr/wind/Makefile b/shlr/wind/Makefile index 0919a0fc90..2f0e581c04 100644 --- a/shlr/wind/Makefile +++ b/shlr/wind/Makefile @@ -1,3 +1,4 @@ +include ../../libr/config.mk include ../../config-user.mk include ../../mk/platform.mk include ../../mk/${COMPILER}.mk @@ -26,21 +27,21 @@ endif endif CFLAGS+=-I../../libr/include -LIBAR=libr_wind.a +LIBAR=libr_wind.${EXT_AR} LDFLAGS+=-L../../libr/util LIBS=-lr_util OFILES=transport.o kd.o wind.o iob_pipe.o -all: libr_wind.a +all: ${LIBAR} %.o: %.c $(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@ -libr_wind.a: $(OFILES) - rm -f libr_wind.a - ${AR} q libr_wind.a ${OFILES} - ${RANLIB} libr_wind.a +${LIBAR}: $(OFILES) + rm -f ${LIBAR} + ${AR} q ${LIBAR} ${OFILES} + ${RANLIB} ${LIBAR} clean: - rm -f $(OBJS) libr_wind.a $(OFILES) + rm -f $(OBJS) ${LIBAR} $(OFILES) diff --git a/shlr/wind/iob_pipe.c b/shlr/wind/iob_pipe.c index 8de76f0720..1ef3c92093 100644 --- a/shlr/wind/iob_pipe.c +++ b/shlr/wind/iob_pipe.c @@ -2,7 +2,6 @@ #include #include -#include #if __WINDOWS__ || __CYGWIN__ || MINGW32 #include diff --git a/shlr/wind/kd.h b/shlr/wind/kd.h index b0e2388030..7e6108b420 100644 --- a/shlr/wind/kd.h +++ b/shlr/wind/kd.h @@ -17,6 +17,7 @@ #ifndef KD_H #define KD_H +#include enum { KD_E_OK = 0, diff --git a/shlr/wind/transport.h b/shlr/wind/transport.h index 0aafc09d64..317b01424b 100644 --- a/shlr/wind/transport.h +++ b/shlr/wind/transport.h @@ -5,7 +5,7 @@ #ifndef HAVE_EPRINTF #include -#define eprintf(x,y...) fprintf(stderr,x,##y) +#define eprintf(...) { fprintf(stderr,##__VA_ARGS__); } #define HAVE_EPRINTF 1 #endif diff --git a/shlr/wind/wind.c b/shlr/wind/wind.c index 71018dcb9a..2c2b5f3109 100644 --- a/shlr/wind/wind.c +++ b/shlr/wind/wind.c @@ -1012,7 +1012,7 @@ bool wind_break (WindCtx *ctx) { } int wind_break_read (WindCtx *ctx) { -#if __WINDOWS__ +#if __WINDOWS__ && !defined(_MSC_VER) static BOOL WINAPI (*w32_CancelIoEx)(HANDLE, LPOVERLAPPED) = NULL; if (!w32_CancelIoEx) { HANDLE lib; diff --git a/shlr/zip/Makefile b/shlr/zip/Makefile index a54c312a91..bd255cbf90 100644 --- a/shlr/zip/Makefile +++ b/shlr/zip/Makefile @@ -1,5 +1,5 @@ NAME=rz -LIBAR=librz.a +LIBAR=librz.$(EXT_AR) include ../../config-user.mk include ../../libr/config.mk @@ -8,27 +8,27 @@ include ../../mk/${COMPILER}.mk ifeq ($(USE_LIB_ZIP),1) all: - rm -f librz.a + rm -f librz.$(EXT_AR) else -LIBAR=librz.a +LIBAR=librz.$(EXT_AR) RANLIB?=ranlib all: $(LIBAR) -$(LIBAR): zip/libr_zip.a +$(LIBAR): zip/libr_zip.$(EXT_AR) ${CC_AR} zlib/*.o zip/*.o - $(RANLIB) librz.a + $(RANLIB) librz.$(EXT_AR) -zip/libr_zip.a: zlib/libr_z.a +zip/libr_zip.$(EXT_AR): zlib/libr_z.$(EXT_AR) $(MAKE) -C zip -zlib/libr_z.a: +zlib/libr_z.$(EXT_AR): $(MAKE) -C zlib clean: $(MAKE) -C zlib clean $(MAKE) -C zip clean - rm -f *.a *.${EXT_SO} zlib/*.a zip/*.a + rm -f *.$(EXT_AR) *.${EXT_SO} zlib/*.$(EXT_AR) zip/*.$(EXT_AR) endif diff --git a/shlr/zip/deps.mk b/shlr/zip/deps.mk index e0e513e625..4091278e90 100644 --- a/shlr/zip/deps.mk +++ b/shlr/zip/deps.mk @@ -5,6 +5,6 @@ ifeq ($(USE_LIB_ZIP),1) LINK+=$(LIBZIP) else -LINK+=$(SHLR)/zip/librz.a +LINK+=$(SHLR)/zip/librz.$(EXT_AR) CFLAGS+=-I$(SHLR)/zip/include endif diff --git a/shlr/zip/zip/Makefile b/shlr/zip/zip/Makefile index 14720429c4..432e9989f7 100644 --- a/shlr/zip/zip/Makefile +++ b/shlr/zip/zip/Makefile @@ -76,18 +76,18 @@ OBJS= zip_add.o zip_add_dir.o zip_add_entry.o \ zip_string.o zip_unchange.o zip_unchange_all.o \ zip_unchange_archive.o zip_unchange_data.o zip_utf-8.o -#OFILES=libr_zip.a $(OBJS) +#OFILES=libr_zip.$(EXT_AR) $(OBJS) OFILES=$(OBJS) #CFLAGS+=-g -fPIC CFLAGS+=-I../../../libr/include -I../include/ LDFLAGS+=-L../../../libr/util -LINKFLAGS=../zlib/libr_z.a +LINKFLAGS=../zlib/libr_z.$(EXT_AR) #LDFLAGS=-shared EXT_SO?=dylib LIBNAME=libr_zip.${SOVER} -LIBAR=libr_zip.a +LIBAR=libr_zip.$(EXT_AR) all: ${LIBNAME} ${LIBAR} @@ -102,4 +102,4 @@ ${LIBAR}: ${OFILES} ${RANLIB} ${LIBAR} clean: - rm -f ${LIBNAME} *.o *.a *.d *.${EXT_SO} + rm -f ${LIBNAME} *.o *.$(EXT_AR) *.d *.${EXT_SO} diff --git a/shlr/zip/zip/config.h b/shlr/zip/zip/config.h index 0e57bb0def..0beb7dcc89 100644 --- a/shlr/zip/zip/config.h +++ b/shlr/zip/zip/config.h @@ -58,7 +58,9 @@ #define HAVE_SNPRINTF 1 /* Define to 1 if the system has the type `ssize_t'. */ +#ifndef _MSC_VER #define HAVE_SSIZE_T 1 +#endif /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 @@ -73,7 +75,9 @@ #define HAVE_STRDUP 1 /* Define to 1 if you have the header file. */ +#ifndef _MSC_VER #define HAVE_STRINGS_H 1 +#endif /* Define to 1 if you have the header file. */ #define HAVE_STRING_H 1 @@ -110,7 +114,11 @@ #define HAVE_UINT8_T 1 /* Define to 1 if you have the header file. */ +#ifdef _MSC_VER +#define HAVE_UNISTD_H 0 +#else #define HAVE_UNISTD_H 1 +#endif /* Define to 1 if you have the `_close' function. */ /* #undef HAVE__CLOSE */ diff --git a/shlr/zip/zip/zipint.h b/shlr/zip/zip/zipint.h index a50fea255f..bed84d6e76 100644 --- a/shlr/zip/zip/zipint.h +++ b/shlr/zip/zip/zipint.h @@ -141,7 +141,7 @@ #define ZIP_EF_ZIP64 0x0001 #define ZIP_EF_IS_INTERNAL(id) ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_ZIP64) - + /* This section contains API that won't materialize like this. It's placed in the internal section, pending cleanup. */ @@ -201,7 +201,7 @@ struct zip_source *zip_source_window(struct zip *, struct zip_source *, struct zip_source *zip_source_pop(struct zip_source *); - + /* error source for layered sources */ @@ -330,7 +330,7 @@ struct zip_extra_field { zip_uint8_t *data; }; - + struct zip_source { struct zip_source *src; @@ -352,7 +352,7 @@ struct zip_entry { int deleted; }; - + /* file or archive comment, or filename */ @@ -364,7 +364,7 @@ struct zip_string { zip_uint32_t converted_length; /* length of converted */ }; - + /* which files to write, and in which order (name is for torrentzip sorting) */ @@ -373,13 +373,13 @@ struct zip_filelist { const char *name; }; - + extern const char * const _zip_err_str[]; extern const int _zip_nerr_str; extern const int _zip_err_type[]; - + #define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f))) @@ -387,7 +387,7 @@ extern const int _zip_err_type[]; #define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY) - + zip_int64_t _zip_add_entry(struct zip *); diff --git a/shlr/zip/zlib/Makefile b/shlr/zip/zlib/Makefile index 7c13eb3cff..a18916a351 100644 --- a/shlr/zip/zlib/Makefile +++ b/shlr/zip/zlib/Makefile @@ -52,14 +52,14 @@ OBJS = adler32.o crc32.o deflate.o infback.o \ zutil.o compress.o uncompr.o gzclose.o \ gzlib.o gzread.o gzwrite.o -#OFILES= libr_z.a $(OBJS) +#OFILES= libr_z.$(EXT_AR) $(OBJS) OFILES= $(OBJS) CFLAGS+=-Wall CFLAGS+=-I../../libr/include -I../include/ #LDFLAGS+=-L../../../libr/util LIBNAME=libr_z.${SOVER} -LIBAR=libr_z.a +LIBAR=libr_z.$(EXT_AR) all: ${LIBNAME} ${LIBAR} @@ -69,9 +69,9 @@ ifneq ($(SILENT),) endif ${CC} ${CFLAGS} ${LDFLAGS} $(LDFLAGS_SHARED) -o $@ ${OBJS} -libr_z.a: ${OFILES} +libr_z.$(EXT_AR): ${OFILES} ${CC_AR} ${OFILES} - ${RANLIB} libr_z.a + ${RANLIB} libr_z.$(EXT_AR) clean: - rm -f ${LIBNAME} *.o *.a *.d *.dylib *.so + rm -f ${LIBNAME} *.o *.$(EXT_AR) *.d *.dylib *.so diff --git a/shlr/zip/zlib/gzguts.h b/shlr/zip/zlib/gzguts.h index 189e8f8900..8643c0252c 100644 --- a/shlr/zip/zlib/gzguts.h +++ b/shlr/zip/zlib/gzguts.h @@ -21,7 +21,6 @@ #include #include "zlib.h" #include -#include #include #include #include diff --git a/sys/arlib b/sys/arlib new file mode 100755 index 0000000000..8fe997cc12 --- /dev/null +++ b/sys/arlib @@ -0,0 +1,59 @@ +#!/bin/sh + +# Wrapper around MS's lib.exe to make it act more like Unix ar + +case $MACHTYPE in + *-msys) + slash="-" + ;; + *) + slash="/" + ;; +esac + +# prog specifies the program that should be run cl.exe +prog=lib +# opts specifies the command line to pass to the MSVC program +libopt="${slash}nologo" +verbose=1 + +processargs() +{ + # Ignore first argument (q, rfs...) + shift + # Add out library + libopt="${libopt},${slash}out:${1}" + shift + # Modify path for files + for arg in $@; do + path=$(cygpath -w "${arg}") + libopt="${libopt},${path}" + done + +} + +IFS="" +processargs $@ + +# Default LIB environment variable is overwritten by some makefiles ... +# So we just add it with LIBPATH (LIB is backed up in VC_LIB) +IFS=";" +for p in ${VC_LIB}; do + libopt="${libopt},${slash}LIBPATH:${p}" +done + +if test "x$V" = "x1" ; then + verbose=1 +fi + +IFS="," +if test -n "$verbose" ; then + printf "%s" "$prog" + for opt in ${libopt} ; do + printf "%s" " \"$opt\"" + done + echo "" +fi + +exec ${prog} ${libopt} + diff --git a/sys/cccl b/sys/cccl new file mode 100755 index 0000000000..516f4fbe96 --- /dev/null +++ b/sys/cccl @@ -0,0 +1,316 @@ +#!/bin/sh + +# cccl +# Wrapper around MS's cl.exe to make it act more like Unix cc +# +# Copyright (C) 2000-2015 by contributors listed in the AUTHORS file. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# Modified for radare2 purposes + + +usage() +{ + cat <nul') do ( + set VC_DIR=%%C +) +if ["%VC_DIR%"] == [""] goto :FindFail + +:VcVarsDefaults +echo Found VC_DIR location: %VC_DIR% +if exist "%VC_DIR%VC\Auxiliary\Build\vcvarsall.bat" ( + set vcvarsall="%VC_DIR%VC\Auxiliary\Build\vcvarsall.bat" +) +if exist "%VC_DIR%VC\vcvarsall.bat" ( + set vcvarsall="%VC_DIR%VC\vcvarsall.bat" +) +if [%vcvarsall%] == [] ( + goto :FindFail +) +echo Found %vcvarsall% +goto :SetVars + +:VcSearch +echo Could not find vcvarsall.bat, making a deeper search... +for /r "%VC_DIR%" %%a in (*) do if "%%~nxa"=="vcvarsall.bat" set vcvarsall=%%~dpnxa +if defined vcvarsall ( + echo Found %vcvarsall% ! +) else ( + goto :FindFail +) + +:SetVars +echo Setting vars... +call %vcvarsall% x64 +set VC_LIB=%LIB% + +:Bash +echo Calling script... +PATH=%cd%\sys;C:\cygwin64\bin;%PATH% +bash sys\msvc.sh +goto :End + +:FindFail +echo Could not find the vcvarsall.bat location. +echo Maybe are you missing Visual Studio compiler ? +echo Try setting it manually at the beginning of this file. + +:End diff --git a/sys/msvc.sh b/sys/msvc.sh new file mode 100755 index 0000000000..be7ffe2884 --- /dev/null +++ b/sys/msvc.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +#make clean +CC=cccl + +# Configure +#COMPILER=${CC} USERCC=${CC} CC=${CC} LD=${CC} ./configure --with-ostype=windows --with-nonpic --without-pic +if [ ! -e "libr/config.mk" ]; then + COMPILER=${CC} USERCC=${CC} CC=${CC} LD=${CC} ./configure --with-ostype=windows + if [ $? -ne 0 ]; then + echo "Configure failed. Exiting" + exit 1 + fi + rm test.exe test.obj +fi + +# TODO I cannot say why cl.exe does not use the environment variables when ran from make +# so I give it to cl.exe with -LIBPATH (translated from -L by cccl) +_IFS=${IFS} +IFS=\; +for path in ${LIBPATH}${LIB}; do + LDFLAGS="${LDFLAGS} -L\"${path}\"" +done +IFS=${_IFS} + +# Use /FS to allow cl.exe to write to the same .pdb file +CFLAGS="/FS" +# Include msvc directory to provide unistd.h and sys/time.h +INC_DIR=$(cygpath -aw $(pwd)/libr/include/msvc) +CFLAGS="${CFLAGS} /I\"${INC_DIR}\"" + +export CCCL_OPTIONS="--cccl-verbose" +export CFLAGS="${CFLAGS}" +export LDFLAGS="${LDFLAGS}" +export HOST_CFLAGS="${CFLAGS}" +export HOST_LDFLAGS="${LDFLAGS}" +export R2DIR="${R2DIR}" + +# Set capstone to release +sed -i s/CS_RELEASE=0/CS_RELEASE=1/ shlr/Makefile +# Disable some plugins +sed -i "s,p/tricore.mk ,," libr/config.mk +sed -i "s,p/z80.mk ,," libr/config.mk + +# Now we can make +make CC=${CC} USERCC=${CC} HOST_CC=${CC} USE_CAPSTONE=1 + +#make w64dist + +# Reset capstone Makefile (git) +sed -i s/CS_RELEASE=1/CS_RELEASE=0/ shlr/Makefile