Zydis  v2.0.2
String.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 
3  Zyan Disassembler Library (Zydis)
4 
5  Original Author : Florian Bernd, Joel Hoener
6 
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24 
25 ***************************************************************************************************/
26 
27 #ifndef ZYDIS_STRING_H
28 #define ZYDIS_STRING_H
29 
30 #include <Zydis/CommonTypes.h>
31 #include <Zydis/Status.h>
32 #include <Zydis/Internal/LibC.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* ============================================================================================== */
39 /* Enums and types */
40 /* ============================================================================================== */
41 
42 /* ---------------------------------------------------------------------------------------------- */
43 /* String */
44 /* ---------------------------------------------------------------------------------------------- */
45 
49 typedef struct ZydisString_
50 {
54  char* buffer;
64 
65 /* ---------------------------------------------------------------------------------------------- */
66 /* Static string */
67 /* ---------------------------------------------------------------------------------------------- */
68 
69 #pragma pack(push, 1)
70 
76 typedef struct ZydisStaticString_
77 {
81  const char* buffer;
87 
88 #pragma pack(pop)
89 
90 /* ---------------------------------------------------------------------------------------------- */
91 /* Letter Case */
92 /* ---------------------------------------------------------------------------------------------- */
93 
98 
103 {
116 
121 };
122 
123 /* ---------------------------------------------------------------------------------------------- */
124 
125 /* ============================================================================================== */
126 /* Macros */
127 /* ============================================================================================== */
128 
129 /* ---------------------------------------------------------------------------------------------- */
130 /* Helper Macros */
131 /* ---------------------------------------------------------------------------------------------- */
132 
138 #define ZYDIS_MAKE_STRING(string) \
139  { (char*)string, sizeof(string) - 1, sizeof(string) - 1 }
140 
146 #define ZYDIS_MAKE_STATIC_STRING(string) \
147  { string, sizeof(string) - 1 }
148 
149 /* ---------------------------------------------------------------------------------------------- */
150 
151 /* ============================================================================================== */
152 /* Functions */
153 /* ============================================================================================== */
154 
155 /* ---------------------------------------------------------------------------------------------- */
156 /* Basic Operations */
157 /* ---------------------------------------------------------------------------------------------- */
158 
167 ZYDIS_EXPORT ZydisStatus ZydisStringInit(ZydisString* string, char* text);
168 
177 
178 /* ---------------------------------------------------------------------------------------------- */
179 
190 ZYDIS_EXPORT ZydisStatus ZydisStringAppend(ZydisString* string, const ZydisString* text);
191 
204 ZYDIS_EXPORT ZydisStatus ZydisStringAppendEx(ZydisString* string, const ZydisString* text,
205  ZydisLetterCase letterCase);
206 
217 ZYDIS_EXPORT ZydisStatus ZydisStringAppendC(ZydisString* string, const char* text);
218 
231 ZYDIS_EXPORT ZydisStatus ZydisStringAppendExC(ZydisString* string, const char* text,
232  ZydisLetterCase letterCase);
233 
245  const ZydisStaticString* text, ZydisLetterCase letterCase);
246 
260  const ZydisStaticString* text, ZydisLetterCase letterCase);
261 
262 /* ---------------------------------------------------------------------------------------------- */
263 /* Formatting */
264 /* ---------------------------------------------------------------------------------------------- */
265 
283  ZydisU8 paddingLength);
284 
302  ZydisU8 paddingLength);
303 
325  ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString* prefix,
326  const ZydisString* suffix);
327 
349  ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString* prefix,
350  const ZydisString* suffix);
351 
352 /* ---------------------------------------------------------------------------------------------- */
353 
354 /* ============================================================================================== */
355 
356 #ifdef __cplusplus
357 }
358 #endif
359 
360 #endif // ZYDIS_STRING_H
Includes and defines some default datatypes.
uint64_t ZydisU64
Definition: CommonTypes.h:48
uint8_t ZydisU8
Definition: CommonTypes.h:45
int64_t ZydisI64
Definition: CommonTypes.h:52
ZydisU8 ZydisBool
@briefs Defines the ZydisBool datatype.
Definition: CommonTypes.h:133
size_t ZydisUSize
Definition: CommonTypes.h:53
Status code definitions and check macros.
ZydisU32 ZydisStatus
Defines the ZydisStatus datatype.
Definition: Status.h:48
ZYDIS_EXPORT ZydisStatus ZydisStringAppendDecS(ZydisString *string, ZydisI64 value, ZydisU8 paddingLength)
Formats the given signed ordinal value to its decimal text-representation and appends it to the strin...
ZYDIS_EXPORT ZydisStatus ZydisStringAppendStatic(ZydisString *string, const ZydisStaticString *text, ZydisLetterCase letterCase)
Appends the given 'ZydisStaticString' to a ZydisString.
ZYDIS_EXPORT ZydisStatus ZydisStringAppendHexU(ZydisString *string, ZydisU64 value, ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString *prefix, const ZydisString *suffix)
Formats the given unsigned ordinal value to its hexadecimal text-representation and appends it to the...
ZYDIS_EXPORT ZydisStatus ZydisStringAppend(ZydisString *string, const ZydisString *text)
Appends a ZydisString to another ZydisString.
ZYDIS_EXPORT ZydisStatus ZydisStringFinalize(ZydisString *string)
Finalizes a ZydisString struct by adding a terminating zero byte.
ZYDIS_EXPORT ZydisStatus ZydisStringAppendDecU(ZydisString *string, ZydisU64 value, ZydisU8 paddingLength)
Formats the given unsigned ordinal value to its decimal text-representation and appends it to the str...
ZydisU8 ZydisLetterCase
Defines the ZydisLetterCase datatype.
Definition: String.h:97
ZYDIS_EXPORT ZydisStatus ZydisStringInit(ZydisString *string, char *text)
Initializes a ZydisString struct with a C-string.
struct ZydisStaticString_ ZydisStaticString
Defines the ZydisStaticString struct.
ZYDIS_EXPORT ZydisStatus ZydisStringAppendExC(ZydisString *string, const char *text, ZydisLetterCase letterCase)
Appends the given C-string to a ZydisString, converting it to the specified letter-case.
ZydisLetterCases
Values that represent letter cases.
Definition: String.h:103
@ ZYDIS_LETTER_CASE_UPPER
Converts the given text to uppercase letters.
Definition: String.h:115
@ ZYDIS_LETTER_CASE_MAX_VALUE
Maximum value of this enum.
Definition: String.h:120
@ ZYDIS_LETTER_CASE_DEFAULT
Uses the given text "as is".
Definition: String.h:107
@ ZYDIS_LETTER_CASE_LOWER
Converts the given text to lowercase letters.
Definition: String.h:111
ZYDIS_EXPORT ZydisStatus ZydisStringAppendEx(ZydisString *string, const ZydisString *text, ZydisLetterCase letterCase)
Appends a ZydisString to another ZydisString, converting it to the specified letter-case.
ZYDIS_EXPORT ZydisStatus ZydisStringAppendHexS(ZydisString *string, ZydisI64 value, ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString *prefix, const ZydisString *suffix)
Formats the given signed ordinal value to its hexadecimal text-representation and appends it to the s...
struct ZydisString_ ZydisString
Defines the ZydisString struct.
ZYDIS_EXPORT ZydisStatus ZydisStringAppendExStatic(ZydisString *string, const ZydisStaticString *text, ZydisLetterCase letterCase)
Appends the given 'ZydisStaticString' to a ZydisString, converting it to the specified letter-case.
ZYDIS_EXPORT ZydisStatus ZydisStringAppendC(ZydisString *string, const char *text)
Appends the given C-string to a ZydisString.
Defines the ZydisStaticString struct.
Definition: String.h:77
ZydisU8 length
The length of the string (without 0-termination).
Definition: String.h:85
const char * buffer
The buffer that contains the actual string (0-termination is optional!).
Definition: String.h:81
Defines the ZydisString struct.
Definition: String.h:50
ZydisUSize length
The length of the string (without 0-termination).
Definition: String.h:58
ZydisUSize capacity
The total buffer capacity.
Definition: String.h:62
char * buffer
The buffer that contains the actual string (0-termination is optional!).
Definition: String.h:54