private String checkForEnvVar(Map<String, String> envVars, String key) { if (!envVars.containsKey(key)) {
Log.errorAndQuit("Cannot run a fuzzed program if $" + key + " is not set!");
} return envVars.get(key);
}
private String getHostCoreImagePathWithArch() { // TODO: Using host currently implies x86 (see Options.java), change this when generalized. assert(Options.useArchX86); return androidHostOut + "/framework/x86/core.art";
}
if (Options.executeOnHost) {
File coreImage = new File(getHostCoreImagePathWithArch()); if (!coreImage.exists()) {
Log.errorAndQuit("Host core image not found at " + coreImage.getPath()
+ ". Did you forget to build it?");
}
} if (!isHost) { // Create temporary consumers for the initial test.
StreamConsumer outputConsumer = new StreamConsumer();
outputConsumer.start();
StreamConsumer errorConsumer = new StreamConsumer();
errorConsumer.start();
// Check for ADB. try {
ProcessBuilder pb = new ProcessBuilder();
pb.command("adb", "devices");
Process process = pb.start(); int exitValue = process.waitFor(); if (exitValue != 0) {
Log.errorAndQuit("Problem executing ADB - is it in your $PATH?");
}
} catch (IOException e) {
Log.errorAndQuit("IOException when executing ADB, is it working?");
} catch (InterruptedException e) {
Log.errorAndQuit("InterruptedException when executing ADB, is it working?");
}
// Check we can run something on ADB.
ExecutionResult result = executeCommand("true", true, outputConsumer, errorConsumer); if (result.getFlattenedAll().contains("device not found")) {
Log.errorAndQuit("Couldn't connect to specified ADB device: " + deviceName);
}
try {
ProcessBuilder processBuilder = new ProcessBuilder(splitCommand(command));
processBuilder.environment().put("ANDROID_ROOT", androidHostOut); if (Options.executeOnHost) {
processBuilder.environment().put("ANDROID_DATA", androidData);
}
Process process = processBuilder.start();
if (captureOutput) { // Give the streams to the StreamConsumers.
outputConsumer.giveStreamAndStartConsuming(process.getInputStream());
errorConsumer.giveStreamAndStartConsuming(process.getErrorStream());
}
// Wait until the process is done - the StreamConsumers will keep the // buffers drained, so this shouldn't block indefinitely. // Get the return value as well.
result.returnValue = process.waitFor();
Log.info("Return value: " + result.returnValue);
if (captureOutput) { // Tell the StreamConsumers to stop consuming, and wait for them to finish // so we know we have all of the output.
outputConsumer.processFinished();
errorConsumer.processFinished();
result.output = outputConsumer.getOutput();
result.error = errorConsumer.getOutput();
// Always explicitly indicate the return code in the text output now. // NB: adb shell doesn't actually return exit codes currently, but this will // be useful if/when it does.
result.output.add("RETURN CODE: " + result.returnValue);
}
} catch (IOException e) {
Log.errorAndQuit("ExecutionResult.execute() caught an IOException");
} catch (InterruptedException e) {
Log.errorAndQuit("ExecutionResult.execute() caught an InterruptedException");
}
return result;
}
/** *Splitscommandrespectingsinglequotes.
*/ private List<String> splitCommand(String command) {
List<String> ret = new ArrayList<String>();
Matcher m = Pattern.compile("(\'[^\']+\'| *[^ ]+ *)").matcher(command); while (m.find())
ret.add(m.group(1).trim().replace("\'", "")); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.