forked from geohot/eda-2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChangelistFactory.cc
58 lines (53 loc) · 2.06 KB
/
ChangelistFactory.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ChangelistFactory.cc -- May 10, 2009
// by geohot
// part of "The Embedded Disassembler"
// released under GPLv3, see http://gplv3.fsf.org/
//
// I make Changelists
#include "logic.h"
#include "util.h"
using namespace eda;
ChangelistFactory::ChangelistFactory() {
//Changelists start at 1 since every Address contains [0] = 0
current_changelist_number_ = 1;
}
Changelist* ChangelistFactory::CreateFromInput(Address* owner, const string& data, Address* start) {
Changelist* out = new Changelist(current_changelist_number_++, owner);
int i;
for (i = 0; i < data.size() && start!=0; i++) {
//cout << start << endl;
out->add_change(start, data[i]);
start = start->get_next();
}
if (i != data.size()) {
LOG(INFO) << "only added " << i << " changes" << endl;
}
return out;
}
Changelist* ChangelistFactory::CreateFromStatelessChangelist(Address* owner, StatelessChangelist& in, Memory* state) {
StatelessChangelistIterator it;
if (!in.get_first_change(&it)) return NULL;
Changelist* out = new Changelist(current_changelist_number_, owner);
LOG(DEBUG) << "changelist is number " << current_changelist_number_;
do {
if (state->ResolveToNumber(current_changelist_number_, it->first.second) != 0) { // Check the condition
Address *target = state->ResolveToAddress(current_changelist_number_, it->first.first);
uint32_t value = state->ResolveToNumber(current_changelist_number_, it->second.second);
if (target != NULL) {
/*LOG(INFO) << "setting address " << target->get_location() << " to data of size " << it->second.first;
target->set_size(it->second.first);
target->type_ = "data";*/
for (int bc = 0; bc < it->second.first; bc++) {
//LOG(DEBUG) << "adding change " << target << " = " << (value&0xFF);
out->add_change(target, value & 0xFF);
target = target->get_next();
value >>= 8;
}
} else {
LOG(INFO) << "Address not found " << it->first.first;
}
}
} while (in.get_next_change(&it));
current_changelist_number_++;
return out;
}