Rizin
unix-like reverse engineering framework and cli tools
SStream.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <capstone/platform.h>
#include "SStream.h"
#include "cs_priv.h"
#include "utils.h"

Go to the source code of this file.

Functions

void SStream_Init (SStream *ss)
 
void SStream_concat0 (SStream *ss, const char *s)
 
void SStream_concat (SStream *ss, const char *fmt,...)
 
void printInt64Bang (SStream *O, int64_t val)
 
void printUInt64Bang (SStream *O, uint64_t val)
 
void printInt64 (SStream *O, int64_t val)
 
void printInt32BangDec (SStream *O, int32_t val)
 
void printInt32Bang (SStream *O, int32_t val)
 
void printInt32 (SStream *O, int32_t val)
 
void printUInt32Bang (SStream *O, uint32_t val)
 
void printUInt32 (SStream *O, uint32_t val)
 

Function Documentation

◆ printInt32()

void printInt32 ( SStream O,
int32_t  val 
)

Definition at line 137 of file SStream.c.

138 {
139  if (val >= 0) {
140  if (val > HEX_THRESHOLD)
141  SStream_concat(O, "0x%x", val);
142  else
143  SStream_concat(O, "%u", val);
144  } else {
145  if (val <- HEX_THRESHOLD) {
146  if (val == INT_MIN)
147  SStream_concat(O, "-0x%x", (uint32_t)val);
148  else
149  SStream_concat(O, "-0x%x", (uint32_t)-val);
150  }
151  else
152  SStream_concat(O, "-%u", -val);
153  }
154 }
void SStream_concat(SStream *ss, const char *fmt,...)
Definition: SStream.c:45
ut16 val
Definition: armass64_const.h:6
#define O
Definition: rcond.c:14
unsigned int uint32_t
Definition: sftypes.h:29
#define HEX_THRESHOLD
Definition: utils.h:16

References HEX_THRESHOLD, O, SStream_concat(), and val.

◆ printInt32Bang()

void printInt32Bang ( SStream O,
int32_t  val 
)

Definition at line 118 of file SStream.c.

119 {
120  if (val >= 0) {
121  if (val > HEX_THRESHOLD)
122  SStream_concat(O, "#0x%x", val);
123  else
124  SStream_concat(O, "#%u", val);
125  } else {
126  if (val <- HEX_THRESHOLD) {
127  if (val == INT_MIN)
128  SStream_concat(O, "#-0x%x", (uint32_t)val);
129  else
130  SStream_concat(O, "#-0x%x", (uint32_t)-val);
131  }
132  else
133  SStream_concat(O, "#-%u", -val);
134  }
135 }

References HEX_THRESHOLD, O, SStream_concat(), and val.

◆ printInt32BangDec()

void printInt32BangDec ( SStream O,
int32_t  val 
)

Definition at line 107 of file SStream.c.

108 {
109  if (val >= 0)
110  SStream_concat(O, "#%u", val);
111  else
112  if (val == INT_MIN)
113  SStream_concat(O, "#-%u", val);
114  else
115  SStream_concat(O, "#-%u", (uint32_t)-val);
116 }

References O, SStream_concat(), and val.

◆ printInt64()

void printInt64 ( SStream O,
int64_t  val 
)

Definition at line 87 of file SStream.c.

88 {
89  if (val >= 0) {
90  if (val > HEX_THRESHOLD)
91  SStream_concat(O, "0x%"PRIx64, val);
92  else
93  SStream_concat(O, "%"PRIu64, val);
94  } else {
95  if (val <- HEX_THRESHOLD) {
96  if (val == LONG_MIN)
98  else
99  SStream_concat(O, "-0x%"PRIx64, (uint64_t)-val);
100  }
101  else
102  SStream_concat(O, "-%"PRIu64, -val);
103  }
104 }
#define PRIu64
Definition: macros.h:18
unsigned long uint64_t
Definition: sftypes.h:28
#define PRIx64
Definition: sysdefs.h:94

References HEX_THRESHOLD, O, PRIu64, PRIx64, SStream_concat(), and val.

◆ printInt64Bang()

void printInt64Bang ( SStream O,
int64_t  val 
)

Definition at line 59 of file SStream.c.

60 {
61  if (val >= 0) {
62  if (val > HEX_THRESHOLD)
63  SStream_concat(O, "#0x%"PRIx64, val);
64  else
65  SStream_concat(O, "#%"PRIu64, val);
66  } else {
67  if (val <- HEX_THRESHOLD) {
68  if (val == LONG_MIN)
69  SStream_concat(O, "#-0x%"PRIx64, (uint64_t)val);
70  else
71  SStream_concat(O, "#-0x%"PRIx64, (uint64_t)-val);
72  }
73  else
74  SStream_concat(O, "#-%"PRIu64, -val);
75  }
76 }

References HEX_THRESHOLD, O, PRIu64, PRIx64, SStream_concat(), and val.

◆ printUInt32()

void printUInt32 ( SStream O,
uint32_t  val 
)

Definition at line 164 of file SStream.c.

165 {
166  if (val > HEX_THRESHOLD)
167  SStream_concat(O, "0x%x", val);
168  else
169  SStream_concat(O, "%u", val);
170 }

References HEX_THRESHOLD, O, SStream_concat(), and val.

◆ printUInt32Bang()

void printUInt32Bang ( SStream O,
uint32_t  val 
)

Definition at line 156 of file SStream.c.

157 {
158  if (val > HEX_THRESHOLD)
159  SStream_concat(O, "#0x%x", val);
160  else
161  SStream_concat(O, "#%u", val);
162 }

References HEX_THRESHOLD, O, SStream_concat(), and val.

◆ printUInt64Bang()

void printUInt64Bang ( SStream O,
uint64_t  val 
)

Definition at line 78 of file SStream.c.

79 {
80  if (val > HEX_THRESHOLD)
81  SStream_concat(O, "#0x%"PRIx64, val);
82  else
83  SStream_concat(O, "#%"PRIu64, val);
84 }

References HEX_THRESHOLD, O, PRIu64, PRIx64, SStream_concat(), and val.

◆ SStream_concat()

void SStream_concat ( SStream ss,
const char *  fmt,
  ... 
)

Definition at line 45 of file SStream.c.

46 {
47 #ifndef CAPSTONE_DIET
48  va_list ap;
49  int ret;
50 
51  va_start(ap, fmt);
52  ret = cs_vsnprintf(ss->buffer + ss->index, sizeof(ss->buffer) - (ss->index + 1), fmt, ap);
53  va_end(ap);
54  ss->index += ret;
55 #endif
56 }
cs_vsnprintf_t cs_vsnprintf
Definition: cs.c:352
int index
Definition: SStream.h:11
char buffer[512]
Definition: SStream.h:10

References SStream::buffer, cs_vsnprintf, and SStream::index.

Referenced by EVM_printInst(), M68K_printInst(), printAddressingMode(), printInt32(), printInt32Bang(), printInt32BangDec(), printInt64(), printInt64Bang(), printUInt32(), printUInt32Bang(), printUInt64Bang(), registerBits(), and registerPair().

◆ SStream_concat0()

void SStream_concat0 ( SStream ss,
const char *  s 
)

Definition at line 31 of file SStream.c.

32 {
33 #ifndef CAPSTONE_DIET
34  if (!ss || !s) {
35  return;
36  }
37  unsigned int len = (unsigned int) strlen(s);
38 
39  memcpy(ss->buffer + ss->index, s, len);
40  ss->index += len;
41  ss->buffer[ss->index] = '\0';
42 #endif
43 }
size_t len
Definition: 6502dis.c:15
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static RzSocket * s
Definition: rtr.c:28
static int
Definition: sfsocketcall.h:114

References SStream::buffer, SStream::index, int, len, memcpy(), and s.

Referenced by EVM_printInst(), and M68K_printInst().

◆ SStream_Init()

void SStream_Init ( SStream ss)

Definition at line 25 of file SStream.c.

26 {
27  ss->index = 0;
28  ss->buffer[0] = '\0';
29 }

References SStream::buffer, and SStream::index.

Referenced by cs_disasm(), cs_disasm_iter(), and M68K_getInstruction().