@@ -135,6 +135,11 @@ Value* lifterClass::retrieveCombinedValue(uint64_t startAddress,
135
135
uint8_t bytesize = v.end - v.start ;
136
136
137
137
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);
138
143
if (v.isRef ) {
139
144
byteValue = extractBytes (v.ref .value , v.ref .byteOffset ,
140
145
v.ref .byteOffset + bytesize);
@@ -143,6 +148,10 @@ Value* lifterClass::retrieveCombinedValue(uint64_t startAddress,
143
148
byteValue = builder.getIntN (bytesize * 8 , mem_value.getZExtValue ());
144
149
} else if (!v.isRef ) {
145
150
// llvm_unreachable_internal("uh...");
151
+ /*
152
+ byteValue = ConstantInt::get(Type::getIntNTy(context, (bytesize) * 8), 0);
153
+ */
154
+ // TODO :
146
155
byteValue = extractBytes (orgLoad, m, m + bytesize);
147
156
}
148
157
if (byteValue) {
@@ -270,9 +279,19 @@ void lifterClass::pagedCheck(Value* address, Instruction* ctxI) {
270
279
raw_fd_ostream OS (Filename, EC);
271
280
builder.GetInsertBlock ()->getParent ()->getParent ()->print (OS, nullptr );
272
281
});
282
+ /*
273
283
UNREACHABLE("\nmemory is not paged, so we(more likely) or the program "
274
284
"probably do some incorrect stuff "
275
285
"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 ;
276
295
break ;
277
296
}
278
297
case MEMORY_MIGHT_BE_PAGED: {
@@ -336,8 +355,8 @@ bool overlaps(uint64_t addr1, uint64_t size1, uint64_t addr2, uint64_t size2) {
336
355
337
356
uint64_t createmask (uint64_t a1, uint64_t a2, uint64_t b1, uint64_t b2) {
338
357
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);
341
360
int64_t diffStart = a1 - b1;
342
361
343
362
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) {
367
386
struct PairHash {
368
387
std::size_t operator ()(const std::pair<llvm::Value*, int >& pair) const {
369
388
// 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 );
371
391
}
372
392
};
373
393
374
- void removeDuplicateOffsets (vector<Instruction*>& vec) {
394
+ void removeDuplicateOffsets (std:: vector<Instruction*>& vec) {
375
395
if (vec.empty ())
376
396
return ;
377
397
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;
380
401
uniqueInstructions.reserve (
381
402
vec.size ()); // reserve space assuming all could be unique
382
403
latestOffsets.reserve (
@@ -389,7 +410,7 @@ void removeDuplicateOffsets(vector<Instruction*>& vec) {
389
410
int size = valOp->getType ()->getIntegerBitWidth ();
390
411
auto GEPInst = cast<GetElementPtrInst>(GEPval);
391
412
auto offset = GEPInst->getOperand (1 );
392
- auto pair = make_pair (offset, size);
413
+ auto pair = std:: make_pair (offset, size);
393
414
394
415
if (latestOffsets.emplace (pair, *it).second ) {
395
416
uniqueInstructions.push_back (*it);
@@ -399,7 +420,7 @@ void removeDuplicateOffsets(vector<Instruction*>& vec) {
399
420
vec.assign (uniqueInstructions.rbegin (), uniqueInstructions.rend ());
400
421
}
401
422
402
- set<APInt, APIntComparator>
423
+ std:: set<APInt, APIntComparator>
403
424
lifterClass::getPossibleValues (const llvm::KnownBits& known,
404
425
unsigned max_unknown) {
405
426
@@ -411,15 +432,13 @@ lifterClass::getPossibleValues(const llvm::KnownBits& known,
411
432
builder.GetInsertBlock ()->getParent ()->getParent ()->print (OS, nullptr );
412
433
});
413
434
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" );
417
436
}
418
437
llvm::APInt base = known.One ;
419
438
llvm::APInt unknowns = ~(known.Zero | known.One );
420
439
unsigned numBits = known.getBitWidth ();
421
440
422
- set<APInt, APIntComparator> values;
441
+ std:: set<APInt, APIntComparator> values;
423
442
424
443
llvm::APInt combo (unknowns.getBitWidth (), 0 );
425
444
for (uint64_t i = 0 ; i < (1ULL << max_unknown); ++i) {
@@ -566,8 +585,8 @@ calculatePossibleValues(std::set<APInt, APIntComparator> v1,
566
585
return res;
567
586
}
568
587
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) {
571
590
printvalue2 (Depth);
572
591
if (Depth > 16 ) {
573
592
debugging::doIfDebug ([&]() {
@@ -578,7 +597,7 @@ set<APInt, APIntComparator> lifterClass::computePossibleValues(Value* V,
578
597
});
579
598
UNREACHABLE (" Depth exceeded" );
580
599
}
581
- set<APInt, APIntComparator> res;
600
+ std:: set<APInt, APIntComparator> res;
582
601
printvalue (V);
583
602
if (auto v_ci = dyn_cast<ConstantInt>(V)) {
584
603
res.insert (v_ci->getValue ());
@@ -750,7 +769,7 @@ Value* lifterClass::solveLoad(LoadInst* load) {
750
769
}
751
770
752
771
// create a new vector with only leave what we care about
753
- vector<Instruction*> clearedMemInfos;
772
+ std:: vector<Instruction*> clearedMemInfos;
754
773
755
774
clearedMemInfos = memInfos;
756
775
removeDuplicateOffsets (clearedMemInfos);
@@ -869,7 +888,7 @@ Value* lifterClass::solveLoad(LoadInst* load) {
869
888
auto retvalload = retval;
870
889
printvalue (cleared_retval);
871
890
printvalue (retvalload);
872
- debugging::doIfDebug ([&]() { cout << " -------------------\n " ; });
891
+ debugging::doIfDebug ([&]() { std:: cout << " -------------------\n " ; });
873
892
}
874
893
}
875
894
return retval;
0 commit comments