Skip to content

Commit ee9eb3e

Browse files
authored
Revert "Update cmplog-routines-pass.cc (#1589)" (#1591)
This reverts commit d2ff88f.
1 parent 60b3408 commit ee9eb3e

File tree

1 file changed

+6
-198
lines changed

1 file changed

+6
-198
lines changed

libafl_cc/src/cmplog-routines-pass.cc

Lines changed: 6 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,12 @@ char CmpLogRoutines::ID = 0;
172172
#endif
173173

174174
bool CmpLogRoutines::hookRtns(Module &M) {
175-
std::vector<CallInst *> calls, llvmStdStd, llvmStdC, gccStdStd, gccStdC,
176-
Memcmp, Strcmp, Strncmp;
177-
LLVMContext &C = M.getContext();
175+
std::vector<CallInst *> calls, llvmStdStd, llvmStdC, gccStdStd, gccStdC;
176+
LLVMContext &C = M.getContext();
178177

179178
Type *VoidTy = Type::getVoidTy(C);
180179
// PointerType *VoidPtrTy = PointerType::get(VoidTy, 0);
181180
IntegerType *Int8Ty = IntegerType::getInt8Ty(C);
182-
IntegerType *Int64Ty = IntegerType::getInt64Ty(C);
183181
PointerType *i8PtrTy = PointerType::get(Int8Ty, 0);
184182

185183
#if LLVM_VERSION_MAJOR < 9
@@ -271,60 +269,6 @@ bool CmpLogRoutines::hookRtns(Module &M) {
271269
FunctionCallee cmplogGccStdC = c4;
272270
#endif
273271

274-
#if LLVM_VERSION_MAJOR >= 9
275-
FunctionCallee
276-
#else
277-
Constant *
278-
#endif
279-
c5 = M.getOrInsertFunction("__cmplog_rtn_hook_n", VoidTy, i8PtrTy,
280-
i8PtrTy, Int64Ty
281-
#if LLVM_VERSION_MAJOR < 5
282-
,
283-
NULL
284-
#endif
285-
);
286-
#if LLVM_VERSION_MAJOR >= 9
287-
FunctionCallee cmplogHookFnN = c5;
288-
#else
289-
Function *cmplogHookFnN = cast<Function>(c5);
290-
#endif
291-
292-
#if LLVM_VERSION_MAJOR >= 9
293-
FunctionCallee
294-
#else
295-
Constant *
296-
#endif
297-
c6 = M.getOrInsertFunction("__cmplog_rtn_hook_strn", VoidTy, i8PtrTy,
298-
i8PtrTy, Int64Ty
299-
#if LLVM_VERSION_MAJOR < 5
300-
,
301-
NULL
302-
#endif
303-
);
304-
#if LLVM_VERSION_MAJOR >= 9
305-
FunctionCallee cmplogHookFnStrN = c6;
306-
#else
307-
Function *cmplogHookFnStrN = cast<Function>(c6);
308-
#endif
309-
310-
#if LLVM_VERSION_MAJOR >= 9
311-
FunctionCallee
312-
#else
313-
Constant *
314-
#endif
315-
c7 = M.getOrInsertFunction("__cmplog_rtn_hook_str", VoidTy, i8PtrTy,
316-
i8PtrTy
317-
#if LLVM_VERSION_MAJOR < 5
318-
,
319-
NULL
320-
#endif
321-
);
322-
#if LLVM_VERSION_MAJOR >= 9
323-
FunctionCallee cmplogHookFnStr = c7;
324-
#else
325-
Function *cmplogHookFnStr = cast<Function>(c7);
326-
#endif
327-
328272
/* iterate over all functions, bbs and instruction and add suitable calls */
329273
for (auto &F : M) {
330274
if (isIgnoreFunction(&F)) { continue; }
@@ -339,87 +283,12 @@ bool CmpLogRoutines::hookRtns(Module &M) {
339283
if (callInst->getCallingConv() != llvm::CallingConv::C) { continue; }
340284

341285
FunctionType *FT = Callee->getFunctionType();
342-
std::string FuncName = Callee->getName().str();
343286

344287
bool isPtrRtn = FT->getNumParams() >= 2 &&
345288
!FT->getReturnType()->isVoidTy() &&
346289
FT->getParamType(0) == FT->getParamType(1) &&
347290
FT->getParamType(0)->isPointerTy();
348291

349-
bool isPtrRtnN = FT->getNumParams() >= 3 &&
350-
!FT->getReturnType()->isVoidTy() &&
351-
FT->getParamType(0) == FT->getParamType(1) &&
352-
FT->getParamType(0)->isPointerTy() &&
353-
FT->getParamType(2)->isIntegerTy();
354-
if (isPtrRtnN) {
355-
auto intTyOp =
356-
dyn_cast<IntegerType>(callInst->getArgOperand(2)->getType());
357-
if (intTyOp) {
358-
if (intTyOp->getBitWidth() != 32 &&
359-
intTyOp->getBitWidth() != 64) {
360-
isPtrRtnN = false;
361-
}
362-
}
363-
}
364-
365-
bool isMemcmp =
366-
(!FuncName.compare("memcmp") || !FuncName.compare("bcmp") ||
367-
!FuncName.compare("CRYPTO_memcmp") ||
368-
!FuncName.compare("OPENSSL_memcmp") ||
369-
!FuncName.compare("memcmp_const_time") ||
370-
!FuncName.compare("memcmpct"));
371-
isMemcmp &= FT->getNumParams() == 3 &&
372-
FT->getReturnType()->isIntegerTy(32) &&
373-
FT->getParamType(0)->isPointerTy() &&
374-
FT->getParamType(1)->isPointerTy() &&
375-
FT->getParamType(2)->isIntegerTy();
376-
377-
bool isStrcmp =
378-
(!FuncName.compare("strcmp") || !FuncName.compare("xmlStrcmp") ||
379-
!FuncName.compare("xmlStrEqual") ||
380-
!FuncName.compare("g_strcmp0") ||
381-
!FuncName.compare("curl_strequal") ||
382-
!FuncName.compare("strcsequal") ||
383-
!FuncName.compare("strcasecmp") ||
384-
!FuncName.compare("stricmp") ||
385-
!FuncName.compare("ap_cstr_casecmp") ||
386-
!FuncName.compare("OPENSSL_strcasecmp") ||
387-
!FuncName.compare("xmlStrcasecmp") ||
388-
!FuncName.compare("g_strcasecmp") ||
389-
!FuncName.compare("g_ascii_strcasecmp") ||
390-
!FuncName.compare("Curl_strcasecompare") ||
391-
!FuncName.compare("Curl_safe_strcasecompare") ||
392-
!FuncName.compare("cmsstrcasecmp") ||
393-
!FuncName.compare("strstr") ||
394-
!FuncName.compare("g_strstr_len") ||
395-
!FuncName.compare("ap_strcasestr") ||
396-
!FuncName.compare("xmlStrstr") ||
397-
!FuncName.compare("xmlStrcasestr") ||
398-
!FuncName.compare("g_str_has_prefix") ||
399-
!FuncName.compare("g_str_has_suffix"));
400-
isStrcmp &=
401-
FT->getNumParams() == 2 && FT->getReturnType()->isIntegerTy(32) &&
402-
FT->getParamType(0) == FT->getParamType(1) &&
403-
FT->getParamType(0) == IntegerType::getInt8PtrTy(M.getContext());
404-
405-
bool isStrncmp = (!FuncName.compare("strncmp") ||
406-
!FuncName.compare("xmlStrncmp") ||
407-
!FuncName.compare("curl_strnequal") ||
408-
!FuncName.compare("strncasecmp") ||
409-
!FuncName.compare("strnicmp") ||
410-
!FuncName.compare("ap_cstr_casecmpn") ||
411-
!FuncName.compare("OPENSSL_strncasecmp") ||
412-
!FuncName.compare("xmlStrncasecmp") ||
413-
!FuncName.compare("g_ascii_strncasecmp") ||
414-
!FuncName.compare("Curl_strncasecompare") ||
415-
!FuncName.compare("g_strncasecmp"));
416-
isStrncmp &= FT->getNumParams() == 3 &&
417-
FT->getReturnType()->isIntegerTy(32) &&
418-
FT->getParamType(0) == FT->getParamType(1) &&
419-
FT->getParamType(0) ==
420-
IntegerType::getInt8PtrTy(M.getContext()) &&
421-
FT->getParamType(2)->isIntegerTy();
422-
423292
bool isGccStdStringStdString =
424293
Callee->getName().find("__is_charIT_EE7__value") !=
425294
std::string::npos &&
@@ -467,13 +336,10 @@ bool CmpLogRoutines::hookRtns(Module &M) {
467336
*/
468337

469338
if (isGccStdStringCString || isGccStdStringStdString ||
470-
isLlvmStdStringStdString || isLlvmStdStringCString || isMemcmp ||
471-
isStrcmp || isStrncmp) {
472-
isPtrRtnN = isPtrRtn = false;
339+
isLlvmStdStringStdString || isLlvmStdStringCString) {
340+
isPtrRtn = false;
473341
}
474342

475-
if (isPtrRtnN) { isPtrRtn = false; }
476-
477343
if (isPtrRtn) { calls.push_back(callInst); }
478344
if (isGccStdStringStdString) { gccStdStd.push_back(callInst); }
479345
if (isGccStdStringCString) { gccStdC.push_back(callInst); }
@@ -485,9 +351,9 @@ bool CmpLogRoutines::hookRtns(Module &M) {
485351
}
486352

487353
if (!calls.size() && !gccStdStd.size() && !gccStdC.size() &&
488-
!llvmStdStd.size() && !llvmStdC.size() && !Memcmp.size() &&
489-
Strcmp.size() && Strncmp.size())
354+
!llvmStdStd.size() && !llvmStdC.size()) {
490355
return false;
356+
}
491357

492358
for (auto &callInst : calls) {
493359
Value *v1P = callInst->getArgOperand(0), *v2P = callInst->getArgOperand(1);
@@ -506,64 +372,6 @@ bool CmpLogRoutines::hookRtns(Module &M) {
506372
// errs() << callInst->getCalledFunction()->getName() << "\n";
507373
}
508374

509-
for (auto &callInst : Memcmp) {
510-
Value *v1P = callInst->getArgOperand(0), *v2P = callInst->getArgOperand(1),
511-
*v3P = callInst->getArgOperand(2);
512-
513-
IRBuilder<> IRB(callInst->getParent());
514-
515-
std::vector<Value *> args;
516-
Value *v1Pcasted = IRB.CreatePointerCast(v1P, i8PtrTy);
517-
Value *v2Pcasted = IRB.CreatePointerCast(v2P, i8PtrTy);
518-
Value *v3Pbitcast = IRB.CreateBitCast(
519-
v3P, IntegerType::get(C, v3P->getType()->getPrimitiveSizeInBits()));
520-
Value *v3Pcasted =
521-
IRB.CreateIntCast(v3Pbitcast, IntegerType::get(C, 64), false);
522-
args.push_back(v1Pcasted);
523-
args.push_back(v2Pcasted);
524-
args.push_back(v3Pcasted);
525-
526-
IRB.CreateCall(cmplogHookFnN, args);
527-
528-
// errs() << callInst->getCalledFunction()->getName() << "\n";
529-
}
530-
531-
for (auto &callInst : Strcmp) {
532-
Value *v1P = callInst->getArgOperand(0), *v2P = callInst->getArgOperand(1);
533-
534-
IRBuilder<> IRB(callInst->getParent());
535-
std::vector<Value *> args;
536-
Value *v1Pcasted = IRB.CreatePointerCast(v1P, i8PtrTy);
537-
Value *v2Pcasted = IRB.CreatePointerCast(v2P, i8PtrTy);
538-
args.push_back(v1Pcasted);
539-
args.push_back(v2Pcasted);
540-
541-
IRB.CreateCall(cmplogHookFnStr, args);
542-
543-
// errs() << callInst->getCalledFunction()->getName() << "\n";
544-
}
545-
546-
for (auto &callInst : Strncmp) {
547-
Value *v1P = callInst->getArgOperand(0), *v2P = callInst->getArgOperand(1),
548-
*v3P = callInst->getArgOperand(2);
549-
550-
IRBuilder<> IRB(callInst->getParent());
551-
std::vector<Value *> args;
552-
Value *v1Pcasted = IRB.CreatePointerCast(v1P, i8PtrTy);
553-
Value *v2Pcasted = IRB.CreatePointerCast(v2P, i8PtrTy);
554-
Value *v3Pbitcast = IRB.CreateBitCast(
555-
v3P, IntegerType::get(C, v3P->getType()->getPrimitiveSizeInBits()));
556-
Value *v3Pcasted =
557-
IRB.CreateIntCast(v3Pbitcast, IntegerType::get(C, 64), false);
558-
args.push_back(v1Pcasted);
559-
args.push_back(v2Pcasted);
560-
args.push_back(v3Pcasted);
561-
562-
IRB.CreateCall(cmplogHookFnStrN, args);
563-
564-
// errs() << callInst->getCalledFunction()->getName() << "\n";
565-
}
566-
567375
for (auto &callInst : gccStdStd) {
568376
Value *v1P = callInst->getArgOperand(0), *v2P = callInst->getArgOperand(1);
569377

0 commit comments

Comments
 (0)