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