import transform fix into autodict, code-format

This commit is contained in:
van Hauser
2020-05-07 08:08:20 +02:00
parent 01b5aa123d
commit 140053502b
4 changed files with 58 additions and 36 deletions

View File

@ -279,12 +279,13 @@ library_list_t *find_library(char *name) {
/* for having an easy breakpoint after load the shared library */ /* for having an easy breakpoint after load the shared library */
// this seems to work for clang too. nice :) requires gcc 4.4+ // this seems to work for clang too. nice :) requires gcc 4.4+
#pragma GCC push_options #pragma GCC push_options
#pragma GCC optimize ("O0") #pragma GCC optimize("O0")
void breakpoint() { void breakpoint() {
if (debug) fprintf(stderr, "Breakpoint function \"breakpoint\" reached.\n"); if (debug) fprintf(stderr, "Breakpoint function \"breakpoint\" reached.\n");
} }
#pragma GCC pop_options #pragma GCC pop_options
/* Error reporting to forkserver controller */ /* Error reporting to forkserver controller */
@ -470,7 +471,7 @@ void setup_trap_instrumentation() {
FILE *patches = fopen(filename, "r"); FILE *patches = fopen(filename, "r");
if (!patches) FATAL("Couldn't open AFL_UNTRACER_FILE file %s", filename); if (!patches) FATAL("Couldn't open AFL_UNTRACER_FILE file %s", filename);
// Index into the coverage bitmap for the current trap instruction. // Index into the coverage bitmap for the current trap instruction.
#ifdef __aarch64__ #ifdef __aarch64__
uint64_t bitmap_index = 0; uint64_t bitmap_index = 0;
#else #else
@ -507,11 +508,13 @@ void setup_trap_instrumentation() {
PROT_READ | PROT_WRITE | PROT_EXEC) != 0) PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
FATAL("Failed to mprotect library %s writable", line); FATAL("Failed to mprotect library %s writable", line);
// Create shadow memory. // Create shadow memory.
#ifdef __aarch64__ #ifdef __aarch64__
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
#else #else
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
#endif #endif
void *shadow_addr = SHADOW(lib_addr + i); void *shadow_addr = SHADOW(lib_addr + i);
@ -540,16 +543,17 @@ void setup_trap_instrumentation() {
FATAL("Too many basic blocks to instrument"); FATAL("Too many basic blocks to instrument");
#ifdef __arch64__ #ifdef __arch64__
uint64_t uint64_t
#else #else
uint32_t uint32_t
#endif #endif
*shadow = SHADOW(lib_addr + offset); *shadow = SHADOW(lib_addr + offset);
if (*shadow != 0) continue; // skip duplicates if (*shadow != 0) continue; // skip duplicates
// Make lookup entry in shadow memory. // Make lookup entry in shadow memory.
#if ((defined(__APPLE__) && defined(__LP64__)) || defined(__x86_64__) || defined(__i386__)) #if ((defined(__APPLE__) && defined(__LP64__)) || defined(__x86_64__) || \
defined(__i386__))
// this is for Intel x64 // this is for Intel x64
@ -566,10 +570,10 @@ void setup_trap_instrumentation() {
// this is for aarch64 // this is for aarch64
uint32_t *patch_bytes = (uint32_t*)(lib_addr + offset); uint32_t *patch_bytes = (uint32_t *)(lib_addr + offset);
uint32_t orig_bytes = *patch_bytes; uint32_t orig_bytes = *patch_bytes;
*shadow = (bitmap_index << 32) | orig_bytes; *shadow = (bitmap_index << 32) | orig_bytes;
*patch_bytes = 0xd4200000; // replace instruction with debug trap *patch_bytes = 0xd4200000; // replace instruction with debug trap
if (debug) if (debug)
fprintf(stderr, fprintf(stderr,
"Patch entry: %p[%x] = %p = %02x -> SHADOW(%p) #%d -> %016x\n", "Patch entry: %p[%x] = %p = %02x -> SHADOW(%p) #%d -> %016x\n",
@ -577,14 +581,14 @@ void setup_trap_instrumentation() {
bitmap_index, *shadow); bitmap_index, *shadow);
#else #else
// this will be ARM and AARCH64 // this will be ARM and AARCH64
// for ARM we will need to identify if the code is in thumb or ARM // for ARM we will need to identify if the code is in thumb or ARM
#error "non x86_64/aarch64 not supported yet" #error "non x86_64/aarch64 not supported yet"
//__arm__: //__arm__:
// linux thumb: 0xde01 // linux thumb: 0xde01
// linux arm: 0xe7f001f0 // linux arm: 0xe7f001f0
//__aarch64__: //__aarch64__:
// linux aarch64: 0xd4200000 // linux aarch64: 0xd4200000
#endif #endif
bitmap_index++; bitmap_index++;

View File

@ -716,9 +716,11 @@ int main(int argc, char **argv, char **envp) {
} }
} }
if (instrument_opt_mode && lto_mode) if (instrument_opt_mode && lto_mode)
FATAL("CTX and NGRAM can not be used in LTO mode (and would make LTO useless)"); FATAL(
"CTX and NGRAM can not be used in LTO mode (and would make LTO "
"useless)");
if (!instrument_opt_mode) { if (!instrument_opt_mode) {

View File

@ -346,11 +346,15 @@ struct InsTrimLTO : public ModulePass {
if (auto *Var = if (auto *Var =
dyn_cast<GlobalVariable>(Ptr->getOperand(0))) { dyn_cast<GlobalVariable>(Ptr->getOperand(0))) {
if (auto *Array = dyn_cast<ConstantDataArray>( if (Var->hasInitializer()) {
Var->getInitializer())) {
HasStr2 = true; if (auto *Array = dyn_cast<ConstantDataArray>(
Str2 = Array->getAsString().str(); Var->getInitializer())) {
HasStr2 = true;
Str2 = Array->getAsString().str();
}
} }
@ -419,11 +423,15 @@ struct InsTrimLTO : public ModulePass {
if (auto *Var = if (auto *Var =
dyn_cast<GlobalVariable>(Ptr->getOperand(0))) { dyn_cast<GlobalVariable>(Ptr->getOperand(0))) {
if (auto *Array = dyn_cast<ConstantDataArray>( if (Var->hasInitializer()) {
Var->getInitializer())) {
HasStr1 = true; if (auto *Array = dyn_cast<ConstantDataArray>(
Str1 = Array->getAsString().str(); Var->getInitializer())) {
HasStr1 = true;
Str1 = Array->getAsString().str();
}
} }

View File

@ -326,11 +326,15 @@ bool AFLLTOPass::runOnModule(Module &M) {
if (auto *Var = dyn_cast<GlobalVariable>(Ptr->getOperand(0))) { if (auto *Var = dyn_cast<GlobalVariable>(Ptr->getOperand(0))) {
if (auto *Array = if (Var->hasInitializer()) {
dyn_cast<ConstantDataArray>(Var->getInitializer())) {
HasStr2 = true; if (auto *Array = dyn_cast<ConstantDataArray>(
Str2 = Array->getAsString().str(); Var->getInitializer())) {
HasStr2 = true;
Str2 = Array->getAsString().str();
}
} }
@ -398,11 +402,15 @@ bool AFLLTOPass::runOnModule(Module &M) {
if (auto *Var = dyn_cast<GlobalVariable>(Ptr->getOperand(0))) { if (auto *Var = dyn_cast<GlobalVariable>(Ptr->getOperand(0))) {
if (auto *Array = if (Var->hasInitializer()) {
dyn_cast<ConstantDataArray>(Var->getInitializer())) {
HasStr1 = true; if (auto *Array = dyn_cast<ConstantDataArray>(
Str1 = Array->getAsString().str(); Var->getInitializer())) {
HasStr1 = true;
Str1 = Array->getAsString().str();
}
} }