Skip to content

Commit 1124ffc

Browse files
committed
sse and some namespace changes
1 parent 17f8604 commit 1124ffc

File tree

11 files changed

+5499
-207
lines changed

11 files changed

+5499
-207
lines changed

lifter/GEPTracker.cpp

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ Value* lifterClass::retrieveCombinedValue(uint64_t startAddress,
135135
uint8_t bytesize = v.end - v.start;
136136

137137
APInt mem_value(1, 0);
138+
printvalue2(v.isRef);
139+
auto read_mem =
140+
BinaryOperations::readMemory(v.memoryAddress, bytesize, mem_value);
141+
printvalue2(read_mem);
142+
printvalue2(mem_value);
138143
if (v.isRef) {
139144
byteValue = extractBytes(v.ref.value, v.ref.byteOffset,
140145
v.ref.byteOffset + bytesize);
@@ -143,6 +148,10 @@ Value* lifterClass::retrieveCombinedValue(uint64_t startAddress,
143148
byteValue = builder.getIntN(bytesize * 8, mem_value.getZExtValue());
144149
} else if (!v.isRef) {
145150
// llvm_unreachable_internal("uh...");
151+
/*
152+
byteValue = ConstantInt::get(Type::getIntNTy(context, (bytesize) * 8), 0);
153+
*/
154+
// TODO :
146155
byteValue = extractBytes(orgLoad, m, m + bytesize);
147156
}
148157
if (byteValue) {
@@ -270,9 +279,19 @@ void lifterClass::pagedCheck(Value* address, Instruction* ctxI) {
270279
raw_fd_ostream OS(Filename, EC);
271280
builder.GetInsertBlock()->getParent()->getParent()->print(OS, nullptr);
272281
});
282+
/*
273283
UNREACHABLE("\nmemory is not paged, so we(more likely) or the program "
274284
"probably do some incorrect stuff "
275285
"we abort to avoid incorrect output\n");
286+
*/
287+
288+
Function* externFunc = cast<Function>(
289+
fnc->getParent()
290+
->getOrInsertFunction("exception", fnc->getReturnType())
291+
.getCallee());
292+
builder.CreateRet(builder.CreateCall(externFunc));
293+
run = 0;
294+
finished = 1;
276295
break;
277296
}
278297
case MEMORY_MIGHT_BE_PAGED: {
@@ -336,8 +355,8 @@ bool overlaps(uint64_t addr1, uint64_t size1, uint64_t addr2, uint64_t size2) {
336355

337356
uint64_t createmask(uint64_t a1, uint64_t a2, uint64_t b1, uint64_t b2) {
338357

339-
auto start_overlap = max(a1, b1);
340-
auto end_overlap = min(a2, b2);
358+
auto start_overlap = std::max(a1, b1);
359+
auto end_overlap = std::min(a2, b2);
341360
int64_t diffStart = a1 - b1;
342361

343362
printvalue2(start_overlap) printvalue2(end_overlap);
@@ -367,16 +386,18 @@ uint64_t createmask(uint64_t a1, uint64_t a2, uint64_t b1, uint64_t b2) {
367386
struct PairHash {
368387
std::size_t operator()(const std::pair<llvm::Value*, int>& pair) const {
369388
// Combine the hashes of the two elements
370-
return hash<llvm::Value*>{}(pair.first) ^ hash<int>{}(pair.second);
389+
return std::hash<llvm::Value*>{}(pair.first) ^
390+
std::hash<int>{}(pair.second);
371391
}
372392
};
373393

374-
void removeDuplicateOffsets(vector<Instruction*>& vec) {
394+
void removeDuplicateOffsets(std::vector<Instruction*>& vec) {
375395
if (vec.empty())
376396
return;
377397

378-
unordered_map<pair<Value*, int>, Instruction*, PairHash> latestOffsets;
379-
vector<Instruction*> uniqueInstructions;
398+
std::unordered_map<std::pair<Value*, int>, Instruction*, PairHash>
399+
latestOffsets;
400+
std::vector<Instruction*> uniqueInstructions;
380401
uniqueInstructions.reserve(
381402
vec.size()); // reserve space assuming all could be unique
382403
latestOffsets.reserve(
@@ -389,7 +410,7 @@ void removeDuplicateOffsets(vector<Instruction*>& vec) {
389410
int size = valOp->getType()->getIntegerBitWidth();
390411
auto GEPInst = cast<GetElementPtrInst>(GEPval);
391412
auto offset = GEPInst->getOperand(1);
392-
auto pair = make_pair(offset, size);
413+
auto pair = std::make_pair(offset, size);
393414

394415
if (latestOffsets.emplace(pair, *it).second) {
395416
uniqueInstructions.push_back(*it);
@@ -399,7 +420,7 @@ void removeDuplicateOffsets(vector<Instruction*>& vec) {
399420
vec.assign(uniqueInstructions.rbegin(), uniqueInstructions.rend());
400421
}
401422

402-
set<APInt, APIntComparator>
423+
std::set<APInt, APIntComparator>
403424
lifterClass::getPossibleValues(const llvm::KnownBits& known,
404425
unsigned max_unknown) {
405426

@@ -411,15 +432,13 @@ lifterClass::getPossibleValues(const llvm::KnownBits& known,
411432
builder.GetInsertBlock()->getParent()->getParent()->print(OS, nullptr);
412433
});
413434
printvalueforce2(max_unknown);
414-
UNREACHABLE(
415-
"We cant solve the address because too many potential values! "
416-
"This shouldn't happen, maybe calculate some kind of a range ?");
435+
UNREACHABLE("There is a very huge chance that this shouldnt happen");
417436
}
418437
llvm::APInt base = known.One;
419438
llvm::APInt unknowns = ~(known.Zero | known.One);
420439
unsigned numBits = known.getBitWidth();
421440

422-
set<APInt, APIntComparator> values;
441+
std::set<APInt, APIntComparator> values;
423442

424443
llvm::APInt combo(unknowns.getBitWidth(), 0);
425444
for (uint64_t i = 0; i < (1ULL << max_unknown); ++i) {
@@ -566,8 +585,8 @@ calculatePossibleValues(std::set<APInt, APIntComparator> v1,
566585
return res;
567586
}
568587

569-
set<APInt, APIntComparator> lifterClass::computePossibleValues(Value* V,
570-
uint8_t Depth) {
588+
std::set<APInt, APIntComparator>
589+
lifterClass::computePossibleValues(Value* V, uint8_t Depth) {
571590
printvalue2(Depth);
572591
if (Depth > 16) {
573592
debugging::doIfDebug([&]() {
@@ -578,7 +597,7 @@ set<APInt, APIntComparator> lifterClass::computePossibleValues(Value* V,
578597
});
579598
UNREACHABLE("Depth exceeded");
580599
}
581-
set<APInt, APIntComparator> res;
600+
std::set<APInt, APIntComparator> res;
582601
printvalue(V);
583602
if (auto v_ci = dyn_cast<ConstantInt>(V)) {
584603
res.insert(v_ci->getValue());
@@ -750,7 +769,7 @@ Value* lifterClass::solveLoad(LoadInst* load) {
750769
}
751770

752771
// create a new vector with only leave what we care about
753-
vector<Instruction*> clearedMemInfos;
772+
std::vector<Instruction*> clearedMemInfos;
754773

755774
clearedMemInfos = memInfos;
756775
removeDuplicateOffsets(clearedMemInfos);
@@ -869,7 +888,7 @@ Value* lifterClass::solveLoad(LoadInst* load) {
869888
auto retvalload = retval;
870889
printvalue(cleared_retval);
871890
printvalue(retvalload);
872-
debugging::doIfDebug([&]() { cout << "-------------------\n"; });
891+
debugging::doIfDebug([&]() { std::cout << "-------------------\n"; });
873892
}
874893
}
875894
return retval;

0 commit comments

Comments
 (0)