mirror of
https://github.com/capstone-engine/capstone.git
synced 2024-11-26 23:10:32 +00:00
104f693c11
* Add auto-sync updater. * Update Capstone core with auto-sync changes. * Update ARM via auto-sync. * Make changes to arch modules which are introduced by auto-sync. * Update tests for ARM. * Fix build warnings for make * Remove meson.build * Print shift amount in decimal * Patch non LLVM register alias. * Change type of immediate operand to unsiged (due to: #771) * Replace all occurances of a register with its alias. * Fix printing of signed imms * Print rotate amount in decimal * CHange imm type to int64_t to match LLVM imm type. * Fix search for register names, by completing string first. * Print ModImm operands always in decimal * Use number format of previous capstone version. * Correct implicit writes and update_flags according to SBit. * Add missing test for RegImmShift * Reverse incorrect comparision. * Set shift information for move instructions. * Set mem access for all memory operands * Set subtracted flag if offset is negative. * Add flag for post-index memory operands. * Add detail op for BX_RET and MOVPCLR * Use instruction post_index operand. * Add VPOP and VPUSH as unique CS IDs. * Add shifting info for MOVsr. * Add TODOs. * Add in LLVM hardcoded operands to detail. * Move detail editing from InstPrinter to Mapping * Formatting * Add removed check. * Add writeback register and constraints to RFEI instructions. * Translate shift immediate * Print negative immediates * Remove duplicate invalid entry * Add CS groups to instructions * Fix write attriutes of stores. * Add missing names of added instructions * Fix LLVM bug * Add more post_index flags * http -> https * Make generated functions static * Remove tab prefix for alias instructions. * Set ValidateMCOperand to NULL. * Fix AddrMode3Operand operands * Allow getting system and banked register name via API * Add writeback to STC/LDC instructions. * Fix (hopefully) last case where disp is negative and subtracted = true * Remove accidentially introduced regressions
205 lines
4.0 KiB
C
205 lines
4.0 KiB
C
/* Capstone Disassembly Engine */
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */
|
|
|
|
#include <stdarg.h>
|
|
#if defined(CAPSTONE_HAS_OSXKERNEL)
|
|
#include <Availability.h>
|
|
#include <libkern/libkern.h>
|
|
#include <i386/limits.h>
|
|
#else
|
|
#include <stdio.h>
|
|
#include <limits.h>
|
|
#endif
|
|
#include <string.h>
|
|
|
|
#include <capstone/platform.h>
|
|
|
|
#include "SStream.h"
|
|
#include "cs_priv.h"
|
|
#include "utils.h"
|
|
|
|
#ifdef _MSC_VER
|
|
#pragma warning(disable: 4996) // disable MSVC's warning on strcpy()
|
|
#endif
|
|
|
|
void SStream_Init(SStream *ss)
|
|
{
|
|
ss->index = 0;
|
|
ss->buffer[0] = '\0';
|
|
}
|
|
|
|
/**
|
|
* Copy the string \p s to the buffer of \p ss and terminate it with a '\\0' byte.
|
|
*/
|
|
void SStream_concat0(SStream *ss, const char *s)
|
|
{
|
|
#ifndef CAPSTONE_DIET
|
|
if (s[0] == '\0')
|
|
return;
|
|
unsigned int len = (unsigned int) strlen(s);
|
|
|
|
memcpy(ss->buffer + ss->index, s, len);
|
|
ss->index += len;
|
|
ss->buffer[ss->index] = '\0';
|
|
#endif
|
|
}
|
|
|
|
/**
|
|
* Copy the single char \p c to the buffer of \p ss.
|
|
*/
|
|
void SStream_concat1(SStream *ss, const char c)
|
|
{
|
|
#ifndef CAPSTONE_DIET
|
|
if (c == '\0')
|
|
return;
|
|
ss->buffer[ss->index] = c;
|
|
ss->index++;
|
|
ss->buffer[ss->index] = '\0';
|
|
#endif
|
|
}
|
|
|
|
/**
|
|
* Copy all strings given to the buffer of \p ss according to formatting \p fmt.
|
|
*/
|
|
void SStream_concat(SStream *ss, const char *fmt, ...)
|
|
{
|
|
#ifndef CAPSTONE_DIET
|
|
va_list ap;
|
|
int ret;
|
|
|
|
va_start(ap, fmt);
|
|
ret = cs_vsnprintf(ss->buffer + ss->index, sizeof(ss->buffer) - (ss->index + 1), fmt, ap);
|
|
va_end(ap);
|
|
ss->index += ret;
|
|
#endif
|
|
}
|
|
|
|
// print number with prefix #
|
|
void printInt64Bang(SStream *O, int64_t val)
|
|
{
|
|
if (val >= 0) {
|
|
if (val > HEX_THRESHOLD)
|
|
SStream_concat(O, "#0x%"PRIx64, val);
|
|
else
|
|
SStream_concat(O, "#%"PRIu64, val);
|
|
} else {
|
|
if (val <- HEX_THRESHOLD) {
|
|
if (val == LONG_MIN)
|
|
SStream_concat(O, "#-0x%"PRIx64, (uint64_t)val);
|
|
else
|
|
SStream_concat(O, "#-0x%"PRIx64, (uint64_t)-val);
|
|
} else
|
|
SStream_concat(O, "#-%"PRIu64, -val);
|
|
}
|
|
}
|
|
|
|
void printUInt64Bang(SStream *O, uint64_t val)
|
|
{
|
|
if (val > HEX_THRESHOLD)
|
|
SStream_concat(O, "#0x%"PRIx64, val);
|
|
else
|
|
SStream_concat(O, "#%"PRIu64, val);
|
|
}
|
|
|
|
// print number
|
|
void printInt64(SStream *O, int64_t val)
|
|
{
|
|
if (val >= 0) {
|
|
if (val > HEX_THRESHOLD)
|
|
SStream_concat(O, "0x%"PRIx64, val);
|
|
else
|
|
SStream_concat(O, "%"PRIu64, val);
|
|
} else {
|
|
if (val <- HEX_THRESHOLD) {
|
|
if (val == LONG_MIN)
|
|
SStream_concat(O, "-0x%"PRIx64, (uint64_t)val);
|
|
else
|
|
SStream_concat(O, "-0x%"PRIx64, (uint64_t)-val);
|
|
} else
|
|
SStream_concat(O, "-%"PRIu64, -val);
|
|
}
|
|
}
|
|
|
|
void printUInt64(SStream *O, uint64_t val)
|
|
{
|
|
if (val > HEX_THRESHOLD)
|
|
SStream_concat(O, "0x%"PRIx64, val);
|
|
else
|
|
SStream_concat(O, "%"PRIu64, val);
|
|
}
|
|
|
|
// print number in decimal mode
|
|
void printInt32BangDec(SStream *O, int32_t val)
|
|
{
|
|
if (val >= 0)
|
|
SStream_concat(O, "#%u", val);
|
|
else {
|
|
if (val == INT_MIN)
|
|
SStream_concat(O, "#-%u", val);
|
|
else
|
|
SStream_concat(O, "#-%u", (uint32_t)-val);
|
|
}
|
|
}
|
|
|
|
void printInt32Bang(SStream *O, int32_t val)
|
|
{
|
|
if (val >= 0) {
|
|
if (val > HEX_THRESHOLD)
|
|
SStream_concat(O, "#0x%x", val);
|
|
else
|
|
SStream_concat(O, "#%u", val);
|
|
} else {
|
|
if (val <- HEX_THRESHOLD) {
|
|
if (val == INT_MIN)
|
|
SStream_concat(O, "#-0x%x", (uint32_t)val);
|
|
else
|
|
SStream_concat(O, "#-0x%x", (uint32_t)-val);
|
|
} else
|
|
SStream_concat(O, "#-%u", -val);
|
|
}
|
|
}
|
|
|
|
void printInt32(SStream *O, int32_t val)
|
|
{
|
|
if (val >= 0) {
|
|
if (val > HEX_THRESHOLD)
|
|
SStream_concat(O, "0x%x", val);
|
|
else
|
|
SStream_concat(O, "%u", val);
|
|
} else {
|
|
if (val <- HEX_THRESHOLD) {
|
|
if (val == INT_MIN)
|
|
SStream_concat(O, "-0x%x", (uint32_t)val);
|
|
else
|
|
SStream_concat(O, "-0x%x", (uint32_t)-val);
|
|
} else
|
|
SStream_concat(O, "-%u", -val);
|
|
}
|
|
}
|
|
|
|
void printUInt32Bang(SStream *O, uint32_t val)
|
|
{
|
|
if (val > HEX_THRESHOLD)
|
|
SStream_concat(O, "#0x%x", val);
|
|
else
|
|
SStream_concat(O, "#%u", val);
|
|
}
|
|
|
|
void printUInt32(SStream *O, uint32_t val)
|
|
{
|
|
if (val > HEX_THRESHOLD)
|
|
SStream_concat(O, "0x%x", val);
|
|
else
|
|
SStream_concat(O, "%u", val);
|
|
}
|
|
|
|
void printFloat(SStream *O, float val)
|
|
{
|
|
SStream_concat(O, "%e", val);
|
|
}
|
|
|
|
void printFloatBang(SStream *O, float val)
|
|
{
|
|
SStream_concat(O, "#%e", val);
|
|
}
|