string_common.hHeader
Implementation details for encoding and decoding strings in the antispy SDK library. More...
Detailed Description
The string_common.h
file provides the underlying implementation for securely encoding and decoding strings, both at compile time and runtime, within the antispy SDK
library. This file is a critical part of the library's functionality, ensuring that sensitive string data is protected through encryption and is not easily exposed in memory or binaries.
Key Features:
Compile-Time String Encoding and Decoding :
- The file includes template functions for encoding and decoding strings at compile time. These operations are crucial for obfuscating sensitive string literals in the binary, protecting them from static analysis.
Runtime String Encoding and Decoding :
- The file also provides runtime functions for encoding and decoding strings. These are useful for scenarios where strings are dynamically created or modified during program execution and need to be encrypted on-the-fly.
Support for Multiple String Types :
- The encoding and decoding functions support different string types, including
char32_t
, which is used for handling Unicode strings. This makes the library versatile and capable of securely managing a wide range of string data.
- The encoding and decoding functions support different string types, including
Detailed Description:
Namespaces:
- libantispy::detail::string :
- This namespace contains all the functions related to string encoding and decoding. These functions are part of the
antispy SDK
library's internal implementation and are not intended for direct use by end-users. They provide the core logic for securely handling string data within the library.
- This namespace contains all the functions related to string encoding and decoding. These functions are part of the
Functions:
encode (Compile-Time) :
This template function encodes a string at compile time by encrypting each character using a provided key and index. The encoded string is returned as a
const_array
.Template Parameters :
T
: The type of the string (e.g.,char32_t
).Key
: The encryption key used to encode the string.N
: The indices of the characters in the string, provided as a parameter pack.
Parameters :
c
: A pointer to the string to be encoded.std::index_sequence<N...>
: A compile-time sequence representing the indices of the string's characters.
Returns : A
const_array<T, sizeof...(N)>
containing the encoded string.
encode (Runtime) :
This function encodes a string at runtime by encrypting each character using a provided key and index. The encoded string is returned as a vector of
char32_t
.Parameters :
c
: A pointer to the string to be encoded.Key
: The encryption key used to encode the string.N
: The length of the string.
Returns : A
std::vector<char32_t>
containing the encoded string.
encode (Runtime, Fixed Size) :
This template function encodes a fixed-size string at runtime by encrypting each character using a provided key and index. The encoded string is returned as a vector of
char32_t
.Template Parameters :
N
: The length of the string.
Parameters :
str
: A reference to the fixed-size string to be encoded.Key
: The encryption key used to encode the string.
Returns : A
std::vector<char32_t>
containing the encoded string.
decode (Compile-Time) :
This template function decodes a string at compile time by decrypting each character using a provided key and index. The decoded string is returned as a
const_array
.Template Parameters :
T
: The type of the string (e.g.,char32_t
).Key
: The encryption key used to decode the string.N
: The indices of the characters in the string, provided as a parameter pack.
Parameters :
c
: A pointer to the encoded string.std::index_sequence<N...>
: A compile-time sequence representing the indices of the string's characters.
Returns : A
const_array<T, sizeof...(N)>
containing the decoded string.
decode (Runtime) :
This function decodes a string at runtime by decrypting each character using a provided key and index. The decoded string is returned as a vector of
char32_t
.Parameters :
c
: A pointer to the encoded string.Key
: The encryption key used to decode the string.N
: The length of the string.
Returns : A
std::vector<char32_t>
containing the decoded string.
Static Members:
wchar_converter :
- A static member using
std::wstring_convert
to convert between UTF-8 and wide character strings (wchar_t
). This converter is marked withWIN_SUPRESS_4996
to suppress deprecation warnings.
- A static member using
char32_converter :
- A static member using
std::wstring_convert
to convert between UTF-8 andchar32_t
strings. This converter is also marked withWIN_SUPRESS_4996
to suppress deprecation warnings.
- A static member using
Security Considerations:
The encoding and decoding functions provided in this file are designed to securely handle string data, whether it is hardcoded or generated at runtime. By applying encryption to each character in the string, the file ensures that sensitive string data is protected from unauthorized access.
Compile-time encoding obfuscates string literals in the binary, making it difficult for attackers to extract sensitive data through static analysis.
Runtime encoding provides flexibility in handling dynamic string data, ensuring that it remains secure throughout its lifecycle.
Usage:
- These functions are part of the
antispy SDK
library's internal implementation and are typically invoked by higher-level components within the library. They are not intended for direct use by end-users.
Dependencies:
const_array :
- The file relies on the
const_array
class to store the encoded and decoded strings, ensuring that the data remains immutable and secure.
- The file relies on the
encryptor :
- The
encryptor
class template is used within the encode and decode functions to perform the actual encryption and decryption operations.
- The
wstring_convert :
- The file uses
std::wstring_convert
to handle conversions between different string encodings, such as UTF-8 and wide character strings (wchar_t
,char32_t
).
- The file uses
Conclusion:
The string_common.h string_common.h file is an essential component of the antispy SDK
library, providing the necessary tools for securely encoding and decoding string data. Its compile-time and runtime functions ensure that sensitive information embedded in strings is protected from unauthorized access and reverse engineering, making it a vital part of the library's security infrastructure.