• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2021 Google Inc.
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
18MAVEN_ARGS="-DskipTests -Djavac.src.version=15 -Djavac.target.version=15"
19$MVN package org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade $MAVEN_ARGS
20CURRENT_VERSION=$($MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \
21 -Dexpression=project.version -q -DforceStdout)
22cp "core/target/core-$CURRENT_VERSION.jar" $OUT/zxing.jar
23
24mkdir -p $OUT/com/google/zxing
25cp core/target/test-classes/com/google/zxing/BufferedImageLuminanceSource.class $OUT/com/google/zxing
26
27ALL_JARS="zxing.jar"
28
29# The classpath at build-time includes the project jars in $OUT as well as the
30# Jazzer API. Additionally, include $OUT itself to pick up
31# BufferedImageLuminanceSource.
32BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH:$OUT
33
34# All .jar and .class files lie in the same directory as the fuzzer at runtime.
35RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir
36
37for fuzzer in $(find $SRC -name '*Fuzzer.java'); do
38  fuzzer_basename=$(basename -s .java $fuzzer)
39  javac -cp $BUILD_CLASSPATH $fuzzer
40  cp $SRC/$fuzzer_basename*.class $OUT/
41
42  # Create an execution wrapper that executes Jazzer with the correct arguments.
43  echo "#!/bin/sh
44# LLVMFuzzerTestOneInput for fuzzer detection.
45this_dir=\$(dirname \"\$0\")
46LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \
47\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \
48--cp=$RUNTIME_CLASSPATH \
49--target_class=$fuzzer_basename \
50--jvm_args=\"-Xmx2048m;-Djava.awt.headless=true\" \
51\$@" > $OUT/$fuzzer_basename
52  chmod u+x $OUT/$fuzzer_basename
53done
54