def filter_binary_path(binary_path): """Filters binary path to provide a local copy.""" platform = environment.platform() if platform == 'ANDROID': # Skip symbolization when running it on bad entries like [stack:XYZ]. if not binary_path.startswith('/') or '(deleted)' in binary_path: return '' # Initialize some helper variables. binary_filename = os.path.basename(binary_path) build_directory = environment.get_value('BUILD_DIR') symbols_directory = environment.get_value('SYMBOLS_DIR') # Try to find the library in the build directory first. local_binary_path = utils.find_binary_path(build_directory, binary_path) if local_binary_path: return local_binary_path # We didn't find the library locally in the build directory. # Try finding the library in the local system library cache. download_system_symbols_if_needed(symbols_directory) local_binary_path = utils.find_binary_path(symbols_directory, binary_path) if local_binary_path: return local_binary_path # Try pulling in the binary directly from the device into the # system library cache directory. local_binary_path = os.path.join(symbols_directory, binary_filename) adb.run_command('pull %s %s' % (binary_path, local_binary_path)) if os.path.exists(local_binary_path): return local_binary_path # Unable to find library. logs.log_error('Unable to find library %s for symbolization.' % binary_path) return '' if platform == 'CHROMEOS': # FIXME: Add code to pull binaries from ChromeOS device. return binary_path if environment.is_chromeos_system_job(): # This conditional is True for ChromeOS system fuzzers that are running on # Linux. Ensure that the binary is always looked for in the chroot and not # in system directories. build_dir = environment.get_value('BUILD_DIR') if not binary_path.startswith(build_dir): # Fixup path so |binary_path| points to a binary in the chroot (probably # a system library). return os.path.join(build_dir, binary_path[1:]) # For Linux and Mac, the binary exists locally. No work to do, # just return the same binary path. return binary_path
def get_kernel_prefix_and_full_hash(): """Download repo.prop and return the full hash and prefix.""" symbols_directory = os.path.join( environment.get_value('SYMBOLS_DIR'), 'kernel') kernel_partial_hash, build_id = get_kernel_hash_and_build_id() target = get_kernel_name() if not build_id or not target: logs.log_error('Could not get kernel parameters, exiting.') return None repro_filename = symbols_downloader.get_symbols_archive_filename( build_id, target) # Grab repo.prop, it is not on the device nor in the build_dir. symbols_downloader.download_system_symbols_if_needed( symbols_directory, is_kernel=True) local_repo_path = utils.find_binary_path(symbols_directory, repro_filename) if local_repo_path and os.path.exists(local_repo_path): android_kernel_repo_data = utils.read_data_from_file( local_repo_path, eval_data=False).decode() return _get_prefix_and_full_hash(android_kernel_repo_data, kernel_partial_hash) return None, None
def filter_binary_path(binary_path): """Filter binary path to provide local copy.""" # LKL fuzzer name is not full path. if environment.is_android(): # Skip symbolization when running it on bad entries like [stack:XYZ]. if not binary_path.startswith('/') or '(deleted)' in binary_path: return '' # Initialize some helper variables. build_directory = environment.get_value('BUILD_DIR') # Try to find the library in the build directory first. local_binary_path = utils.find_binary_path(build_directory, binary_path) if local_binary_path: return local_binary_path # We should only download from the build server if we are Android. if environment.is_android(): local_binary_path = _get_binary_from_build_or_device(binary_path) if local_binary_path: return local_binary_path # Unable to find library. logs.log_error('Unable to find library %s for symbolization.' % binary_path) return ''
def _get_repo_prop_data(build_id, fuzz_target): """Downloads repo.prop and returuns the data based on build_id and target.""" symbols_directory = os.path.join( environment.get_value('SYMBOLS_DIR'), fuzz_target) repro_filename = symbols_downloader.get_repo_prop_archive_filename( build_id, fuzz_target) # Grab repo.prop, it is not on the device nor in the build_dir. _download_kernel_repo_prop_if_needed(symbols_directory, build_id, fuzz_target) local_repo_path = utils.find_binary_path(symbols_directory, repro_filename) if local_repo_path and os.path.exists(local_repo_path): return utils.read_data_from_file(local_repo_path, eval_data=False).decode() return None
def get_repo_prop_path(): """Download repo.prop and return path of it on local machine.""" symbols_directory = os.path.join( environment.get_value('SYMBOLS_DIR'), 'kernel') build_id = get_kernel_build_id() target = get_kernel_name() if not build_id or not target: logs.log_error('Could not get kernel parameters, exiting.') return None repro_filename = symbols_downloader.get_symbols_archive_filename( build_id, target) # Grab repo.prop, it is not on the device nor in the build_dir. symbols_downloader.download_system_symbols_if_needed( symbols_directory, is_kernel=True) local_binary_path = utils.find_binary_path(symbols_directory, repro_filename) return local_binary_path
def _get_binary_from_build_or_device(binary_path): """Look for binary on build server or on device.""" # Initialize some helper variables. symbols_directory = environment.get_value('SYMBOLS_DIR') binary_filename = os.path.basename(binary_path) # We didn't find the library locally in the build directory. # Try finding the library in the local system library cache. download_system_symbols_if_needed(symbols_directory) local_binary_path = utils.find_binary_path(symbols_directory, binary_path) if local_binary_path: return local_binary_path # Try pulling in the binary directly from the device into the # system library cache directory. local_binary_path = os.path.join(symbols_directory, binary_filename) adb.run_command('pull %s %s' % (binary_path, local_binary_path)) if os.path.exists(local_binary_path): return local_binary_path return None
def _setup_application_path(self, build_dir=None, app_path='APP_PATH', build_update=False): """Sets up APP_PATH environment variables for revision build.""" logs.log('Setup application path.') if not build_dir: build_dir = self.build_dir # Make sure to initialize so that we don't carry stale values # in case of errors. app_path can be APP_PATH or APP_PATH_DEBUG. environment.set_value(app_path, '') environment.set_value('APP_DIR', '') environment.set_value('BUILD_DIR', build_dir) environment.set_value('GN_ARGS_PATH', '') environment.set_value('LLVM_SYMBOLIZER_PATH', environment.get_default_tool_path('llvm-symbolizer')) # Initialize variables. fuzzer_directory = environment.get_value('FUZZER_DIR') search_directories = [build_dir] if fuzzer_directory: search_directories.append(fuzzer_directory) set_environment_vars(search_directories, app_path=app_path) absolute_file_path = environment.get_value(app_path) app_directory = environment.get_value('APP_DIR') if not absolute_file_path: return # Set the symlink if needed. symbolic_link_target = environment.get_value('SYMBOLIC_LINK') if symbolic_link_target: os.system('mkdir --parents %s' % os.path.dirname(symbolic_link_target)) os.system('rm %s' % symbolic_link_target) os.system('ln -s %s %s' % (app_directory, symbolic_link_target)) # Android specific initialization. if environment.platform() == 'ANDROID': # Prepare device for app install. android.device.initialize_device() # On Android, we may need to write a command line file. We do this in # advance so that we do not have to write this to the device multiple # times. # TODO(mbarbella): Build code should not depend on fuzzing. from fuzzing import tests tests.get_command_line_for_application(write_command_line_file=True) # Install the app if it does not exist. android.device.install_application_if_needed(absolute_file_path, build_update) return if not build_update: return # The following hacks are only applicable in Chromium. if utils.is_chromium(): return # Chromium specific workaround for missing ICU data file in root directory. # Copy it from relative folders. See crbug.com/741603. root_icu_data_file_path = os.path.join(app_directory, ICU_DATA_FILENAME) find_icu_data_file_path = utils.find_binary_path(app_directory, ICU_DATA_FILENAME) if find_icu_data_file_path and not os.path.exists(root_icu_data_file_path): shell.copy_file(find_icu_data_file_path, root_icu_data_file_path)