Ghidra Decompiler Analysis Engine
stringmanage.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 
19 #ifndef __STRING_MANAGE__
20 #define __STRING_MANAGE__
21 
22 #include "type.hh"
23 
24 class Architecture;
25 
32 protected:
34  class StringData {
35  public:
36  bool isTruncated;
37  vector<uint1> byteData;
38  };
39  map<Address,StringData> stringMap;
40  int4 maximumChars;
41 public:
42  StringManager(int4 max);
43  virtual ~StringManager(void);
44 
45  void clear(void) { stringMap.clear(); }
46 
47  bool isString(const Address &addr,Datatype *charType); // Determine if data at the given address is a string
48 
57  virtual const vector<uint1> &getStringData(const Address &addr,Datatype *charType,bool &isTrunc)=0;
58 
59  void saveXml(ostream &s) const;
60  void restoreXml(const Element *el,const AddrSpaceManager *m);
61 
62  static bool hasCharTerminator(const uint1 *buffer,int4 size,int4 charsize);
63  static int4 readUtf16(const uint1 *buf,bool bigend);
64  static void writeUtf8(ostream &s,int4 codepoint);
65  static int4 getCodepoint(const uint1 *buf,int4 charsize,bool bigend,int4 &skip);
66 };
67 
73  Architecture *glb;
74  uint1 *testBuffer;
75  int4 checkCharacters(const uint1 *buf,int4 size,int4 charsize) const;
76 public:
77  StringManagerUnicode(Architecture *g,int4 max);
78  virtual ~StringManagerUnicode(void);
79 
80  virtual const vector<uint1> &getStringData(const Address &addr,Datatype *charType,bool &isTrunc);
81  bool writeUnicode(ostream &s,uint1 *buffer,int4 size,int4 charsize);
82 };
83 
84 #endif
StringManagerUnicode::writeUnicode
bool writeUnicode(ostream &s, uint1 *buffer, int4 size, int4 charsize)
Translate/copy unicode to UTF8.
Definition: stringmanage.cc:374
StringManager::isString
bool isString(const Address &addr, Datatype *charType)
Definition: stringmanage.cc:78
StringManager::StringManager
StringManager(int4 max)
Constructor.
Definition: stringmanage.cc:20
StringManager::saveXml
void saveXml(ostream &s) const
Save cached strings to a stream as XML.
Definition: stringmanage.cc:88
StringManager::StringData::isTruncated
bool isTruncated
true if the the string is truncated
Definition: stringmanage.hh:36
StringManagerUnicode::StringManagerUnicode
StringManagerUnicode(Architecture *g, int4 max)
Constructor.
Definition: stringmanage.cc:263
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
StringManager::getCodepoint
static int4 getCodepoint(const uint1 *buf, int4 charsize, bool bigend, int4 &skip)
Extract next unicode codepoint.
Definition: stringmanage.cc:200
StringManagerUnicode
An implementation of StringManager that understands terminated unicode strings.
Definition: stringmanage.hh:72
Architecture
Manager for all the major decompiler subsystems.
Definition: architecture.hh:119
StringManager::StringData
String data (a sequence of bytes) stored by StringManager.
Definition: stringmanage.hh:34
StringManager::StringData::byteData
vector< uint1 > byteData
UTF8 encoded string data.
Definition: stringmanage.hh:37
StringManager::readUtf16
static int4 readUtf16(const uint1 *buf, bool bigend)
Read a UTF16 code point from a byte array.
Definition: stringmanage.cc:177
StringManagerUnicode::getStringData
virtual const vector< uint1 > & getStringData(const Address &addr, Datatype *charType, bool &isTrunc)
Retrieve string data at the given address as a UTF8 byte array.
Definition: stringmanage.cc:276
StringManager::getStringData
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.
StringManager::restoreXml
void restoreXml(const Element *el, const AddrSpaceManager *m)
Restore string cache from XML.
Definition: stringmanage.cc:114
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
Datatype
The base datatype class for the decompiler.
Definition: type.hh:62
type.hh
Classes for describing and printing data-types.
StringManager::hasCharTerminator
static bool hasCharTerminator(const uint1 *buffer, int4 size, int4 charsize)
Check for a unicode string terminator.
Definition: stringmanage.cc:157
AddrSpaceManager
A manager for different address spaces.
Definition: translate.hh:218
StringManager::maximumChars
int4 maximumChars
Maximum characters in a string before truncating.
Definition: stringmanage.hh:40
StringManager::~StringManager
virtual ~StringManager(void)
Destructor.
Definition: stringmanage.cc:26
StringManager::stringMap
map< Address, StringData > stringMap
Map from address to string data.
Definition: stringmanage.hh:39
StringManager::writeUtf8
static void writeUtf8(ostream &s, int4 codepoint)
Write unicode character to stream in UTF8 encoding.
Definition: stringmanage.cc:36
StringManager
Storage for decoding and storing strings associated with an address.
Definition: stringmanage.hh:31