Zydis  v2.0.0
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 /* ============================================================================================== */
35 /* Enums and types */
36 /* ============================================================================================== */
37 
38 /* ---------------------------------------------------------------------------------------------- */
39 /* String */
40 /* ---------------------------------------------------------------------------------------------- */
41 
45 typedef struct ZydisString_
46 {
50  char* buffer;
60 
61 /* ---------------------------------------------------------------------------------------------- */
62 /* Static string */
63 /* ---------------------------------------------------------------------------------------------- */
64 
65 #pragma pack(push, 1)
66 
72 typedef struct ZydisStaticString_
73 {
77  const char* buffer;
83 
84 #pragma pack(pop)
85 
86 /* ---------------------------------------------------------------------------------------------- */
87 /* Letter Case */
88 /* ---------------------------------------------------------------------------------------------- */
89 
94 
99 {
112 
117 };
118 
119 /* ---------------------------------------------------------------------------------------------- */
120 
121 /* ============================================================================================== */
122 /* Macros */
123 /* ============================================================================================== */
124 
125 /* ---------------------------------------------------------------------------------------------- */
126 /* Helper Macros */
127 /* ---------------------------------------------------------------------------------------------- */
128 
134 #define ZYDIS_MAKE_STRING(string) \
135  { (char*)string, sizeof(string) - 1, sizeof(string) - 1 }
136 
142 #define ZYDIS_MAKE_STATIC_STRING(string) \
143  { string, sizeof(string) - 1 }
144 
145 /* ---------------------------------------------------------------------------------------------- */
146 
147 /* ============================================================================================== */
148 /* Functions */
149 /* ============================================================================================== */
150 
151 /* ---------------------------------------------------------------------------------------------- */
152 /* Basic Operations */
153 /* ---------------------------------------------------------------------------------------------- */
154 
163 ZYDIS_EXPORT ZydisStatus ZydisStringInit(ZydisString* string, char* text);
164 
173 
174 /* ---------------------------------------------------------------------------------------------- */
175 
186 ZYDIS_EXPORT ZydisStatus ZydisStringAppend(ZydisString* string, const ZydisString* text);
187 
200 ZYDIS_EXPORT ZydisStatus ZydisStringAppendEx(ZydisString* string, const ZydisString* text,
201  ZydisLetterCase letterCase);
202 
213 ZYDIS_EXPORT ZydisStatus ZydisStringAppendC(ZydisString* string, const char* text);
214 
227 ZYDIS_EXPORT ZydisStatus ZydisStringAppendExC(ZydisString* string, const char* text,
228  ZydisLetterCase letterCase);
229 
241  const ZydisStaticString* text, ZydisLetterCase letterCase);
242 
256  const ZydisStaticString* text, ZydisLetterCase letterCase);
257 
258 /* ---------------------------------------------------------------------------------------------- */
259 /* Formatting */
260 /* ---------------------------------------------------------------------------------------------- */
261 
279  ZydisU8 paddingLength);
280 
298  ZydisU8 paddingLength);
299 
321  ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString* prefix,
322  const ZydisString* suffix);
323 
345  ZydisU8 paddingLength, ZydisBool uppercase, const ZydisString* prefix,
346  const ZydisString* suffix);
347 
348 /* ---------------------------------------------------------------------------------------------- */
349 
350 /* ============================================================================================== */
351 
352 #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:93
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:99
@ ZYDIS_LETTER_CASE_UPPER
Converts the given text to uppercase letters.
Definition: String.h:111
@ ZYDIS_LETTER_CASE_MAX_VALUE
Maximum value of this enum.
Definition: String.h:116
@ ZYDIS_LETTER_CASE_DEFAULT
Uses the given text "as is".
Definition: String.h:103
@ ZYDIS_LETTER_CASE_LOWER
Converts the given text to lowercase letters.
Definition: String.h:107
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:73
ZydisU8 length
The length of the string (without 0-termination).
Definition: String.h:81
const char * buffer
The buffer that contains the actual string (0-termination is optional!).
Definition: String.h:77
Defines the ZydisString struct.
Definition: String.h:46
ZydisUSize length
The length of the string (without 0-termination).
Definition: String.h:54
ZydisUSize capacity
The total buffer capacity.
Definition: String.h:58
char * buffer
The buffer that contains the actual string (0-termination is optional!).
Definition: String.h:50