]> git.siccegge.de Git - frida/frida.git/blob - src/core/Comment.cxx
e864ef673cb71abc182a0b51cbc1d2aa8528a667
[frida/frida.git] / src / core / Comment.cxx
1 #include "Comment.hxx"
2 #include "Function.hxx"
3 #include "InformationManager.hxx"
4 #include "events/ChangeCommentEvent.hxx"
5
6 Comment::Comment(uint64_t address, InformationManager* manager)
7 : address(address)
8 , location(NULL)
9 , manager(manager) {}
10
11 Comment::Comment(uint64_t address, Function* location, InformationManager* manager)
12 : address(address)
13 , location(location)
14 , manager(manager) {}
15
16 void Comment::setText(const std::string& text) {
17 ChangeCommentEvent event(address, location, this);
18 this->text = text;
19 manager->dispatch(&event);
20 }
21
22 uint64_t Comment::getAddress() {
23 return address;
24 }
25
26 Function* Comment::getLocation() {
27 return location;
28 }
29
30 void Comment::serialize(QXmlStreamWriter& stream) {
31 stream.writeStartElement("comment");
32
33 stream.writeTextElement("address", QString::number(address, 16));
34 stream.writeTextElement("text", text.c_str());
35
36 stream.writeEndElement(); // "comment"
37 }
38
39 Comment* Comment::deserialize(QXmlStreamReader& stream, InformationManager* manager, Function* function) {
40 Q_ASSERT(stream.name() == "comment");
41
42 QString text;
43 uint64_t address = 0;
44 Comment* comment;
45
46 while (QXmlStreamReader::NoToken != stream.readNext()) {
47 while (QXmlStreamReader::Characters == stream.tokenType() &&
48 stream.isWhitespace())
49 stream.readNext();
50 if (QXmlStreamReader::EndElement == stream.tokenType())
51 break;
52
53 if(QXmlStreamReader::StartElement != stream.tokenType())
54 return NULL;
55
56 if (stream.name() == "text") {
57 stream.readNext();
58 if (QXmlStreamReader::Characters != stream.tokenType())
59 return NULL;
60
61 text = stream.text().toString();
62 stream.readNext();
63
64 if(QXmlStreamReader::EndElement != stream.tokenType())
65 return NULL;
66 }
67 if (stream.name() == "address") {
68 stream.readNext();
69 if (QXmlStreamReader::Characters != stream.tokenType())
70 return NULL;
71
72 address = stream.text().toULongLong(NULL, 16);
73 stream.readNext();
74
75 if(QXmlStreamReader::EndElement != stream.tokenType())
76 return NULL;
77 }
78 }
79
80 if (address == 0 or text == "")
81 return NULL;
82
83 if (function)
84 comment = manager->newLocalComment(address, function);
85 else
86 comment = manager->newGlobalComment(address);
87
88 comment->text = text.toStdString();
89
90 assert(stream.name() == "comment");
91
92 manager->finishComment(comment);
93 return comment;
94 }
95