Skip to content

Commit

Permalink
fix error path of AFLplusplus, fix #71, fix #72
Browse files Browse the repository at this point in the history
  • Loading branch information
thientc committed May 11, 2023
1 parent 20eebbb commit 710168d
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 32 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ FUTAG использует, в качестве внешнего интерф
Вы можете попробовать собрать Futag с готовыми [Докер-файлами](https://github.com/ispras/Futag/tree/main/product-tests/build-test) для ОС Ubuntu.

## 2.2. Использование предварительно упакованного пакета
- Загрузите последнюю версию [futag-llvm.2.0.3.tar.xz](https://github.com/ispras/Futag/releases/tag/2.0.3) и разархивируйте.
- Загрузите последнюю версию [futag-llvm.2.0.3.tar.xz](https://github.com/ispras/Futag/releases/tag/2.0.3) и разархивируйте. В результате инструмент будет установлен в директорию futag-llvm.
- Для сборки AFLplusplus запустите скрипт buildAFLplusplus.sh в futag-llvm

```bash
~/futag-llvm$ ./buildAFLplusplus.sh
```

## 2.3. Сборка и установка из исходного кода

Expand Down Expand Up @@ -78,6 +83,12 @@ FUTAG использует, в качестве внешнего интерф

- В результате инструмент будет установлен в директорию Futag/futag-llvm

- Для сборки AFLplusplus запустите скрипт buildAFLplusplus.sh в Futag/futag-llvm

```bash
~/Futag/futag-llvm$ ./buildAFLplusplus.sh
```

## 3. Примеры использования
- Предварительно должен быть установлен пакет futag-<версия>.tar.gz по пути futag-llvm/python-package/:
```bash
Expand Down
20 changes: 7 additions & 13 deletions custom-llvm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cp $futag_src/Checkers/lib/*.cpp $custom_llvm/clang/lib/StaticAnalyzer/Checkers/
cp -r $futag_src/Checkers/lib/$CheckerCMakeLists $custom_llvm/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

if [ $llvmVersion == "LLVM=14.0.6" ]; then
cmake -G "Unix Makefiles" -DLLVM_BUILD_TESTS=OFF -DLLVM_ENABLE_ZLIB=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_BINUTILS_INCDIR=/usr/include/ -DCMAKE_INSTALL_PREFIX=$futag_install_folder -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCLANG_INCLUDE_DOCS="OFF" -DLLVM_BUILD_LLVM_DYLIB="ON" -DLLVM_ENABLE_BINDINGS="OFF" -DLLVM_ENABLE_PROJECTS='clang;' -DLLVM_ENABLE_WARNINGS="OFF" -DLLVM_INCLUDE_BENCHMARKS="OFF" -DLLVM_INCLUDE_DOCS="OFF" -DLLVM_INCLUDE_EXAMPLES="OFF" -DLLVM_INCLUDE_TESTS="OFF" -DLLVM_LINK_LLVM_DYLIB="ON" -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_ENABLE_RUNTIMES="compiler-rt;lld" $custom_llvm/llvm
cmake -G "Unix Makefiles" -DLLVM_BUILD_TESTS=OFF -DLLVM_ENABLE_ZLIB=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_BINUTILS_INCDIR=/usr/include/ -DCMAKE_INSTALL_PREFIX=$futag_install_folder -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCLANG_INCLUDE_DOCS="OFF" -DLLVM_BUILD_LLVM_DYLIB="ON" -DLLVM_ENABLE_BINDINGS="OFF" -DLLVM_ENABLE_PROJECTS='clang;lld' -DLLVM_ENABLE_WARNINGS="OFF" -DLLVM_INCLUDE_BENCHMARKS="OFF" -DLLVM_INCLUDE_DOCS="OFF" -DLLVM_INCLUDE_EXAMPLES="OFF" -DLLVM_INCLUDE_TESTS="OFF" -DLLVM_LINK_LLVM_DYLIB="ON" -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_ENABLE_RUNTIMES="compiler-rt" $custom_llvm/llvm

fi
if [ $llvmVersion == "LLVM=13.0.1" ]; then
Expand All @@ -64,16 +64,6 @@ if [ $llvmVersion == "LLVM=13.0.1" ]; then
fi
make -j$(($(nproc)/2)) && make -j$(($(nproc)/2)) install

export PATH="$futag_install_folder/bin:$PATH"
export LLVM_CONFIG="$futag_install_folder/bin/llvm-config"
export LD_LIBRARY_PATH="$(llvm-config --libdir)${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

#build AFLplusplus
cd AFLplusplus-4.02c
make -j$(($(nproc)/2)) distrib
make -j$(($(nproc)/2)) DESTDIR=$futag_install_folder/AFLplusplus install
cd ..

if [ -d $futag_install_folder/python-package ]
then
rm -rf $futag_install_folder/python-package
Expand All @@ -85,9 +75,13 @@ cp -r $futag_src/python/*.py $futag_install_folder/python-package
cp -r $futag_src/svres-tmpl $futag_install_folder/
cp -r ../*.md $futag_install_folder/
cp -r ../LICENSE $futag_install_folder/
cp $custom_prepare/export.sh $futag_install_folder/

cp $custom_prepare/buildAFLplusplus.sh $futag_install_folder/
if [ ! -f 4.02c.tar.gz ]; then
wget https://github.com/AFLplusplus/AFLplusplus/archive/refs/tags/4.02c.tar.gz
fi
mv 4.02c.tar.gz $futag_install_folder/
cd ../product-tests

XZ_OPT='-T'$(($(nproc)/2))' -9' tar cJf futag-llvm$version.latest.tar.xz ../futag-llvm

echo ""
Expand Down
37 changes: 37 additions & 0 deletions custom-llvm/buildAFLplusplus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

#===-- build.sh -------*- bash script -*-===//
#
# This file is distributed under the GPL v3 license (https://www.gnu.org/licenses/gpl-3.0.en.html).
#
# This script helps to build llvm with clang and compiler-rt

echo "************************************************"
echo "* ______ __ __ ______ ___ ______ *"
echo "* / ____/ / / / / /_ __/ / | / ____/ *"
echo "* / /_ / / / / / / / /| | / / __ *"
echo "* / __/ / /_/ / / / / ___ | / /_/ / *"
echo "* /_/ \____/ /_/ /_/ |_| \____/ *"
echo "* *"
echo "* Fuzzing target Automated Generator *"
echo "* a tool of ISP RAS *"
echo "************************************************"
echo ""


SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
echo "Exporting Futag path for AFLplusplus: "$SCRIPTPATH
echo ""
set -x
export PATH="$SCRIPTPATH/bin:$PATH"
export LLVM_CONFIG="$SCRIPTPATH/bin/llvm-config"
export LD_LIBRARY_PATH="$(llvm-config --libdir)${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

futag_install_folder="$SCRIPTPATH"

cd $SCRIPTPATH
tar xf 4.02c.tar.gz
# mv AFLplusplus-4.02c $build_folder/
cd AFLplusplus-4.02c
make -j$(($(nproc)/2)) distrib
make -j$(($(nproc)/2)) DESTDIR=$futag_install_folder/AFLplusplus install
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ WORKDIR /home/futag/Futag/custom-llvm
RUN ./prepare.sh 1
WORKDIR /home/futag/Futag/build
RUN ./build.sh
WORKDIR /home/futag/Futag/futag-llvm
RUN ./buildAFLplusplus.sh

USER root
WORKDIR /home/futag/Futag/
RUN pip install futag-llvm/python-package/futag-2.0.1.tar.gz
RUN pip install -r futag-llvm/python-package/requirements.txt

USER futag
WORKDIR /home/futag/Futag/
RUN pip install futag-llvm/python-package/futag-2.0.3.tar.gz
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ WORKDIR /home/futag/Futag/custom-llvm
RUN ./prepare.sh 1
WORKDIR /home/futag/Futag/build
RUN ./build.sh
WORKDIR /home/futag/Futag/futag-llvm
RUN ./buildAFLplusplus.sh

USER root
WORKDIR /home/futag/Futag/
RUN pip install futag-llvm/python-package/futag-2.0.1.tar.gz
RUN pip install futag-llvm/python-package/futag-2.0.3.tar.gz
8 changes: 4 additions & 4 deletions src/Checkers/lib/FutagAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,25 +735,25 @@ void ento::registerFutagAnalyzer(CheckerManager &Mgr) {
Chk->context_report_path = "";
sys::path::append(
Chk->context_report_path, Chk->report_dir,
"context-" + Chk->rand.GenerateRandomString(consts::cAlphabet, 16) +
".context-" + Chk->rand.GenerateRandomString(consts::cAlphabet, 16) +
".futag-analyzer.json");

Chk->func_decl_report_path = "";
sys::path::append(
Chk->func_decl_report_path, Chk->report_dir,
"declaration-" + Chk->rand.GenerateRandomString(consts::cAlphabet, 16) +
".declaration-" + Chk->rand.GenerateRandomString(consts::cAlphabet, 16) +
".futag-analyzer.json");

Chk->types_info_report_path = "";
sys::path::append(
Chk->types_info_report_path, Chk->report_dir,
"types-info-" + Chk->rand.GenerateRandomString(consts::cAlphabet, 16) +
".types-info-" + Chk->rand.GenerateRandomString(consts::cAlphabet, 16) +
".futag-analyzer.json");

Chk->includesInfoReportPath = "";
sys::path::append(
Chk->includesInfoReportPath, Chk->report_dir,
"file-info-" + Chk->rand.GenerateRandomString(consts::cAlphabet, 16) +
".file-info-" + Chk->rand.GenerateRandomString(consts::cAlphabet, 16) +
".futag-analyzer.json");
}

Expand Down
Binary file modified src/python/futag-package/dist/futag-2.0.3-py3-none-any.whl
Binary file not shown.
Binary file modified src/python/futag-package/dist/futag-2.0.3.tar.gz
Binary file not shown.
8 changes: 8 additions & 0 deletions src/python/futag-package/src/futag/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,21 @@ def __init__(self, futag_llvm_package: str, library_root: str, target_type: int
sys.exit(INVALID_TARGET_TYPE)

self.target_type = target_type


if pathlib.Path(self.futag_llvm_package).exists():
self.futag_llvm_package = pathlib.Path(
self.futag_llvm_package).absolute()
else:
sys.exit(INVALID_FUTAG_PATH)

if self.target_type == LIBFUZZER:
if not pathlib.Path(self.futag_llvm_package/ "bin/clang").exists():
sys.exit(INVALID_FUTAG_PATH)
else:
if not pathlib.Path(self.futag_llvm_package/ "AFLplusplus/usr/local/bin/afl-clang-fast").exists():
sys.exit(INVALID_FUTAG_PATH)

if pathlib.Path(self.library_root).exists():
self.library_root = pathlib.Path(self.library_root).absolute()
else:
Expand Down
16 changes: 8 additions & 8 deletions src/python/futag-package/src/futag/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ def build_configure(self) -> bool:
make_command = make_command + [
f"CC={(self.futag_llvm_package / 'bin/clang').as_posix()}",
f"CXX={(self.futag_llvm_package / 'bin/clang++').as_posix()}",
f"CFLAGS={self.flags}",
f"CPPFLAGS={self.flags}",
f"CXXFLAGS={self.flags}",
f"LDFLAGS={self.flags}",
f"CFLAGS='{self.flags}'",
f"CPPFLAGS='{self.flags}'",
f"CXXFLAGS='{self.flags}'",
f"LDFLAGS='{self.flags}'",
]
p = Popen(make_command, stdout=PIPE,
stderr=PIPE, universal_newlines=True, env=my_env)
Expand Down Expand Up @@ -589,26 +589,26 @@ def analyze(self):
# Find all declaration files in given location
decl_files = [
x
for x in self.analysis_path.glob("**/declaration-*.futag-analyzer.json")
for x in self.analysis_path.glob("**/.declaration-*.futag-analyzer.json")
if x.is_file()
]

# Find all context files in given location
context_files = [
x for x in self.analysis_path.glob("**/context-*.futag-analyzer.json") if x.is_file()
x for x in self.analysis_path.glob("**/.context-*.futag-analyzer.json") if x.is_file()
]

# Find all type_info files in given location
typeinfo_files = [
x
for x in self.analysis_path.glob("**/types-info-*.futag-analyzer.json")
for x in self.analysis_path.glob("**/.types-info-*.futag-analyzer.json")
if x.is_file()
]

# Find all includes info files in given location
info_files = [
x
for x in self.analysis_path.glob("**/file-info-*.futag-analyzer.json")
for x in self.analysis_path.glob("**/.file-info-*.futag-analyzer.json")
if x.is_file()
]

Expand Down

0 comments on commit 710168d

Please sign in to comment.