|
decompiler 1.0.0
|
Storage for decoding and storing strings associated with an address. More...
#include <stringmanage.hh>
Classes | |
| class | StringData |
| String data (a sequence of bytes) stored by StringManager. More... | |
Public Member Functions | |
| StringManager (int4 max) | |
| Constructor. More... | |
| virtual | ~StringManager (void) |
| Destructor. | |
| void | clear (void) |
| Clear out any cached strings. | |
| bool | isString (const Address &addr, Datatype *charType) |
| virtual const vector< uint1 > & | getStringData (const Address &addr, Datatype *charType, bool &isTrunc)=0 |
| Retrieve string data at the given address as a UTF8 byte array. More... | |
| void | encode (Encoder &encoder) const |
| Encode cached strings to a stream. More... | |
| void | decode (Decoder &decoder) |
| Restore string cache from a stream. More... | |
Static Public Member Functions | |
| static bool | hasCharTerminator (const uint1 *buffer, int4 size, int4 charsize) |
| Check for a unicode string terminator. More... | |
| static int4 | readUtf16 (const uint1 *buf, bool bigend) |
| Read a UTF16 code point from a byte array. More... | |
| static void | writeUtf8 (ostream &s, int4 codepoint) |
| Write unicode character to stream in UTF8 encoding. More... | |
| static int4 | getCodepoint (const uint1 *buf, int4 charsize, bool bigend, int4 &skip) |
| Extract next unicode codepoint. More... | |
Protected Attributes | |
| map< Address, StringData > | stringMap |
| Map from address to string data. | |
| int4 | maximumChars |
| Maximum characters in a string before truncating. | |
Storage for decoding and storing strings associated with an address.
Looks at data in the loadimage to determine if it represents a "string". Decodes the string for presentation in the output. Stores the decoded string until its needed for presentation.
| StringManager::StringManager | ( | int4 | max | ) |
Constructor.
| max | is the maximum number of characters to allow before truncating string |
References maximumChars.
| void StringManager::decode | ( | Decoder & | decoder | ) |
Restore string cache from a stream.
Parse a <stringmanage> element, with <string> children.
| decoder | is the stream decoder |
References ATTRIB_TRUNC, StringManager::StringData::byteData, Decoder::closeElement(), Address::decode(), ELEM_BYTES, ELEM_STRING, ELEM_STRINGMANAGE, StringManager::StringData::isTruncated, Decoder::openElement(), Decoder::readBool(), Decoder::readString(), and stringMap.
Referenced by Architecture::restoreXml().
| void StringManager::encode | ( | Encoder & | encoder | ) | const |
Encode cached strings to a stream.
Encode <stringmanage> element, with <string> children.
| encoder | is the stream encoder |
References ATTRIB_TRUNC, StringManager::StringData::byteData, Encoder::closeElement(), ELEM_BYTES, ELEM_STRING, ELEM_STRINGMANAGE, StringManager::StringData::isTruncated, Encoder::openElement(), stringMap, Encoder::writeBool(), and Encoder::writeString().
Referenced by Architecture::encode().
|
static |
Extract next unicode codepoint.
One or more bytes is consumed from the array, and the number of bytes used is passed back.
| buf | is a pointer to the bytes in the character array |
| charsize | is 1 for UTF8, 2 for UTF16, or 4 for UTF32 |
| bigend | is true for big endian encoding of the UTF element |
| skip | is a reference for passing back the number of bytes consumed |
References readUtf16().
Referenced by StringManagerUnicode::checkCharacters(), PrintLanguage::escapeCharacterData(), and StringManagerUnicode::writeUnicode().
|
pure virtual |
Retrieve string data at the given address as a UTF8 byte array.
If the address does not represent string data, a zero length vector is returned. Otherwise, the string data is fetched, converted to a UTF8 encoding, cached and returned.
| addr | is the given address |
| charType | is a character data-type indicating the encoding |
| isTrunc | passes back whether the string is truncated |
Implemented in GhidraStringManager, and StringManagerUnicode.
Referenced by isString(), and PrintC::printCharacterConstant().
|
static |
Check for a unicode string terminator.
| buffer | is the byte buffer |
| size | is the number of bytes in the buffer |
| charsize | is the presumed size (in bytes) of character elements |
Referenced by StringManagerUnicode::getStringData().
Returns true if the data is some kind of complete string. A given character data-type can be used as a hint for the encoding. The string decoding can be cached internally.
| addr | is the given address |
| charType | is the given character data-type |
References getStringData().
Referenced by RulePtrsubCharConstant::applyOp().
|
inlinestatic |
Read a UTF16 code point from a byte array.
Pull the first two bytes from the byte array and combine them in the indicated endian order
| buf | is the byte array |
| bigend | is true to request big endian encoding |
Referenced by getCodepoint().
|
static |
Write unicode character to stream in UTF8 encoding.
Encode the given unicode codepoint as UTF8 (1, 2, 3, or 4 bytes) and write the bytes to the stream.
| s | is the output stream |
| codepoint | is the unicode codepoint |
References mostsigbit_set().
Referenced by PrintC::printUnicode(), PrintJava::printUnicode(), and StringManagerUnicode::writeUnicode().