1# Copyright 2017 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/buildflag_header.gni") 6import("//chrome/process_version_rc_template.gni") 7import("//testing/test.gni") 8 9buildflag_header("buildflags") { 10 header = "buildflags.h" 11 12 # Disable DEX on Windows Official Builds. 13 _enable_dex = !(is_win && is_official_build) 14 _enable_elf = true 15 _enable_win = true 16 17 # Disable ZTF (Zucchini Text Format) on official builds it is for testing only. 18 _enable_ztf = !is_official_build 19 flags = [ 20 "ENABLE_DEX=$_enable_dex", 21 "ENABLE_ELF=$_enable_elf", 22 "ENABLE_WIN=$_enable_win", 23 "ENABLE_ZTF=$_enable_ztf", 24 ] 25} 26 27static_library("zucchini_lib") { 28 sources = [ 29 "abs32_utils.cc", 30 "abs32_utils.h", 31 "address_translator.cc", 32 "address_translator.h", 33 "algorithm.h", 34 "arm_utils.cc", 35 "arm_utils.h", 36 "binary_data_histogram.cc", 37 "binary_data_histogram.h", 38 "buffer_sink.cc", 39 "buffer_sink.h", 40 "buffer_source.cc", 41 "buffer_source.h", 42 "buffer_view.h", 43 "crc32.cc", 44 "crc32.h", 45 "disassembler.cc", 46 "disassembler.h", 47 "disassembler_dex.cc", 48 "disassembler_dex.h", 49 "disassembler_elf.cc", 50 "disassembler_elf.h", 51 "disassembler_no_op.cc", 52 "disassembler_no_op.h", 53 "disassembler_win32.cc", 54 "disassembler_win32.h", 55 "disassembler_ztf.cc", 56 "disassembler_ztf.h", 57 "element_detection.cc", 58 "element_detection.h", 59 "encoded_view.cc", 60 "encoded_view.h", 61 "ensemble_matcher.cc", 62 "ensemble_matcher.h", 63 "equivalence_map.cc", 64 "equivalence_map.h", 65 "heuristic_ensemble_matcher.cc", 66 "heuristic_ensemble_matcher.h", 67 "image_index.cc", 68 "image_index.h", 69 "image_utils.h", 70 "imposed_ensemble_matcher.cc", 71 "imposed_ensemble_matcher.h", 72 "io_utils.cc", 73 "io_utils.h", 74 "patch_reader.cc", 75 "patch_reader.h", 76 "patch_utils.h", 77 "patch_writer.cc", 78 "patch_writer.h", 79 "reference_bytes_mixer.cc", 80 "reference_bytes_mixer.h", 81 "reference_set.cc", 82 "reference_set.h", 83 "rel32_finder.cc", 84 "rel32_finder.h", 85 "rel32_utils.cc", 86 "rel32_utils.h", 87 "reloc_elf.cc", 88 "reloc_elf.h", 89 "reloc_win32.cc", 90 "reloc_win32.h", 91 "suffix_array.h", 92 "target_pool.cc", 93 "target_pool.h", 94 "targets_affinity.cc", 95 "targets_affinity.h", 96 "type_dex.h", 97 "type_elf.h", 98 "type_win_pe.h", 99 "typed_value.h", 100 "zucchini.h", 101 "zucchini_apply.cc", 102 "zucchini_apply.h", 103 "zucchini_gen.cc", 104 "zucchini_gen.h", 105 "zucchini_tools.cc", 106 "zucchini_tools.h", 107 ] 108 109 deps = [ 110 ":buildflags", 111 "//base", 112 ] 113} 114 115static_library("zucchini_io") { 116 sources = [ 117 "mapped_file.cc", 118 "mapped_file.h", 119 "zucchini_integration.cc", 120 "zucchini_integration.h", 121 ] 122 123 deps = [ 124 ":zucchini_lib", 125 "//base", 126 ] 127} 128 129executable("zucchini") { 130 sources = [ 131 "main_utils.cc", 132 "main_utils.h", 133 "zucchini_commands.cc", 134 "zucchini_commands.h", 135 "zucchini_main.cc", 136 ] 137 138 deps = [ 139 ":zucchini_io", 140 ":zucchini_lib", 141 "//base", 142 ] 143 144 if (is_win) { 145 deps += [ ":zucchini_exe_version" ] 146 } 147} 148 149if (is_win) { 150 process_version_rc_template("zucchini_exe_version") { 151 template_file = "zucchini_exe_version.rc.version" 152 output = "$target_gen_dir/zucchini_exe_version.rc" 153 } 154} 155 156test("zucchini_unittests") { 157 sources = [ 158 "abs32_utils_unittest.cc", 159 "address_translator_unittest.cc", 160 "algorithm_unittest.cc", 161 "arm_utils_unittest.cc", 162 "binary_data_histogram_unittest.cc", 163 "buffer_sink_unittest.cc", 164 "buffer_source_unittest.cc", 165 "buffer_view_unittest.cc", 166 "crc32_unittest.cc", 167 "disassembler_dex_unittest.cc", 168 "disassembler_elf_unittest.cc", 169 "disassembler_ztf_unittest.cc", 170 "element_detection_unittest.cc", 171 "encoded_view_unittest.cc", 172 "equivalence_map_unittest.cc", 173 "image_index_unittest.cc", 174 "image_utils_unittest.cc", 175 "imposed_ensemble_matcher_unittest.cc", 176 "io_utils_unittest.cc", 177 "mapped_file_unittest.cc", 178 "patch_read_write_unittest.cc", 179 "patch_utils_unittest.cc", 180 "reference_set_unittest.cc", 181 "rel32_finder_unittest.cc", 182 "rel32_utils_unittest.cc", 183 "reloc_elf_unittest.cc", 184 "reloc_win32_unittest.cc", 185 "suffix_array_unittest.cc", 186 "target_pool_unittest.cc", 187 "targets_affinity_unittest.cc", 188 "test_disassembler.cc", 189 "test_disassembler.h", 190 "test_reference_reader.cc", 191 "test_reference_reader.h", 192 "test_utils.cc", 193 "test_utils.h", 194 "typed_value_unittest.cc", 195 "zucchini_apply_unittest.cc", 196 "zucchini_gen_unittest.cc", 197 ] 198 199 deps = [ 200 ":zucchini_io", 201 ":zucchini_lib", 202 "//base", 203 "//base/test:run_all_unittests", 204 "//base/test:test_support", 205 "//testing/gtest", 206 ] 207} 208 209test("zucchini_integration_test") { 210 sources = [ "integration_test.cc" ] 211 212 deps = [ 213 ":zucchini_lib", 214 "//base", 215 "//base/test:run_all_unittests", 216 "//base/test:test_support", 217 "//testing/gtest", 218 ] 219 220 data = [ "testdata" ] 221} 222 223# Group to build and depend on all the Zucchini related fuzzers. 224group("zucchini_fuzzers") { 225 testonly = true 226 deps = [ 227 "//components/zucchini/fuzzers:zucchini_disassembler_dex_fuzzer", 228 "//components/zucchini/fuzzers:zucchini_disassembler_win32_fuzzer", 229 "//components/zucchini/fuzzers:zucchini_patch_fuzzer", 230 ] 231 232 # Ensure protoc is available. 233 # Disabled on Windows due to crbug/844826. 234 if (current_toolchain == host_toolchain && !is_win) { 235 deps += [ 236 "//components/zucchini/fuzzers:zucchini_apply_fuzzer", 237 "//components/zucchini/fuzzers:zucchini_imposed_ensemble_matcher_fuzzer", 238 "//components/zucchini/fuzzers:zucchini_raw_gen_fuzzer", 239 "//components/zucchini/fuzzers:zucchini_ztf_gen_fuzzer", 240 ] 241 } 242} 243