1 // Copyright 2021 Code Intelligence GmbH 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package com.code_intelligence.jazzer.android; 16 17 import com.code_intelligence.jazzer.utils.Log; 18 import com.github.fmeum.rules_jni.RulesJni; 19 20 /** 21 * Loads Android tooling library and registers native functions. 22 */ 23 public class AndroidRuntime { 24 private static final String DO_NOT_INITIALIZE = "use_none"; 25 private static final String FUZZ_DIR = "/data/fuzz/"; 26 private static final String PLATFORM_LIB_DIRS = ":/system/lib64/:/apex/com.android.i18n@1/lib64/"; 27 initialize(String runtimeLibs)28 public static void initialize(String runtimeLibs) { 29 if (runtimeLibs == null) { 30 return; 31 } 32 33 RulesJni.loadLibrary("jazzer_android_tooling", "/com/code_intelligence/jazzer/driver"); 34 if (runtimeLibs.equals(DO_NOT_INITIALIZE)) { 35 Log.warn("Android Runtime (ART) is not being initialized for this fuzzer."); 36 } else { 37 registerNatives(); 38 } 39 }; 40 41 /** 42 * Returns a command to set the classpath for fuzzing. 43 * 44 * @return The classpath command. 45 */ getClassPathsCommand()46 public static String getClassPathsCommand() { 47 return "export CLASSPATH=" + System.getProperty("java.class.path"); 48 } 49 50 /** 51 * Builds and returns the value to set for LD_LIBRARY_PATH. 52 * This value is consumed when launching jazzer on the device 53 * and specifies which directories to search for dependencies. 54 * 55 * @return The string for LD_LIBRARY_PATH. 56 */ getLdLibraryPath()57 public static String getLdLibraryPath() { 58 String initOptString = System.getProperty("jazzer.android_init_options"); 59 if (initOptString.equals(DO_NOT_INITIALIZE) || initOptString.equals("")) { 60 return FUZZ_DIR; 61 } 62 63 return FUZZ_DIR + PLATFORM_LIB_DIRS; 64 } 65 registerNatives()66 private static native int registerNatives(); 67 } 68