1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package dexfuzz.listeners; 18 19 import dexfuzz.ExecutionResult; 20 import dexfuzz.executors.Executor; 21 import dexfuzz.program.Mutation; 22 23 import java.util.List; 24 import java.util.Map; 25 26 /** 27 * Logs output to the console, when not using --repeat. 28 */ 29 public class ConsoleLoggerListener extends BaseListener { 30 @Override setup()31 public void setup() { 32 33 } 34 35 @Override shutdown()36 public void shutdown() { 37 38 } 39 logToConsole(String msg)40 private void logToConsole(String msg) { 41 System.out.println("CONSOLE: " + msg); 42 } 43 44 @Override handleSuccessfulHostVerification()45 public void handleSuccessfulHostVerification() { 46 logToConsole("Successful host verification"); 47 } 48 49 @Override handleFailedHostVerification(ExecutionResult verificationResult)50 public void handleFailedHostVerification(ExecutionResult verificationResult) { 51 logToConsole("Failed host verification"); 52 } 53 54 @Override handleMutations(List<Mutation> mutations)55 public void handleMutations(List<Mutation> mutations) { 56 for (Mutation mutation : mutations) { 57 logToConsole("Applied mutation: " + mutation.toString()); 58 } 59 } 60 61 @Override handleArchitectureSplit()62 public void handleArchitectureSplit() { 63 logToConsole("Detected architectural split."); 64 } 65 66 @Override handleFailedTargetVerification()67 public void handleFailedTargetVerification() { 68 logToConsole("Failed target verification"); 69 } 70 71 @Override handleIterationStarted(int iteration)72 public void handleIterationStarted(int iteration) { 73 logToConsole("Starting iteration " + iteration); 74 } 75 76 @Override handleIterationFinished(int iteration)77 public void handleIterationFinished(int iteration) { 78 logToConsole("Finished iteration " + iteration); 79 } 80 81 @Override handleTimeouts(List<Executor> timedOut, List<Executor> didNotTimeOut)82 public void handleTimeouts(List<Executor> timedOut, List<Executor> didNotTimeOut) { 83 logToConsole("Timed out: " + timedOut.size() + " Did not time out: " + didNotTimeOut.size()); 84 } 85 86 @Override handleDivergences(Map<String, List<Executor>> outputMap)87 public void handleDivergences(Map<String, List<Executor>> outputMap) { 88 logToConsole("Got divergences!"); 89 int outputCount = 1; 90 for (List<Executor> executors : outputMap.values()) { 91 logToConsole("Output " + outputCount + ":"); 92 for (Executor executor : executors) { 93 logToConsole(" " + executor.getName()); 94 } 95 outputCount++; 96 } 97 } 98 99 @Override handleFuzzingFile(String inputFile)100 public void handleFuzzingFile(String inputFile) { 101 logToConsole("Fuzzing: " + inputFile); 102 } 103 104 @Override handleSeed(long seed)105 public void handleSeed(long seed) { 106 logToConsole("Seed: " + seed); 107 } 108 109 @Override handleHostVerificationSigabort(ExecutionResult verificationResult)110 public void handleHostVerificationSigabort(ExecutionResult verificationResult) { 111 logToConsole("Sigaborted host verification"); 112 } 113 114 @Override handleSuccessfullyFuzzedFile(String programName)115 public void handleSuccessfullyFuzzedFile(String programName) { 116 logToConsole("Program " + programName + " successfully fuzzed."); 117 } 118 119 @Override handleSuccess(Map<String, List<Executor>> outputMap)120 public void handleSuccess(Map<String, List<Executor>> outputMap) { 121 logToConsole("Execution was successful"); 122 } 123 124 @Override handleDumpOutput(String outputLine, Executor executor)125 public void handleDumpOutput(String outputLine, Executor executor) { 126 logToConsole(executor.getName() + " OUTPUT: " + outputLine); 127 } 128 129 @Override handleDumpVerify(String verifyLine)130 public void handleDumpVerify(String verifyLine) { 131 logToConsole("VERIFY: " + verifyLine); 132 } 133 134 @Override handleMutationFail()135 public void handleMutationFail() { 136 logToConsole("DEX file was not mutated"); 137 } 138 139 @Override handleMutationStats(String statsString)140 public void handleMutationStats(String statsString) { 141 logToConsole("Mutations performed: " + statsString); 142 } 143 144 @Override handleTiming(String name, float elapsedTime)145 public void handleTiming(String name, float elapsedTime) { 146 logToConsole(String.format("'%s': %.3fs", name, elapsedTime)); 147 } 148 149 @Override handleSummary()150 public void handleSummary() { 151 logToConsole("--- SUMMARY ---"); 152 } 153 154 @Override handleSelfDivergence()155 public void handleSelfDivergence() { 156 logToConsole("Seen self divergence"); 157 } 158 159 @Override handleMessage(String msg)160 public void handleMessage(String msg) { 161 logToConsole(msg); 162 } 163 } 164