about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2024-11-05 12:21:36 +0900
committerNguyễn Gia Phong <cnx@loang.net>2024-11-05 12:22:03 +0900
commit3aa0dbdc85f9a4cadac0152ed1bfb4cad7c3174b (patch)
tree922d54580ff125666e30c7a6c3bb381c8a94e930
parentedde9d3d6010ee8e58bf593ebe94e1a187321958 (diff)
downloadafl-dyninst-3aa0dbdc85f9a4cadac0152ed1bfb4cad7c3174b.tar.gz
Use C++ preprocessor in build recipe
Also add uninstall target
-rw-r--r--CHANGES5
-rw-r--r--Makefile23
-rw-r--r--afl-dyninst.cc16
3 files changed, 25 insertions, 19 deletions
diff --git a/CHANGES b/CHANGES
index b588b5c..57f4bf2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,10 +4,11 @@ Tag: 1.0.0
 
 	Additions:
 	- Compliance with REUSE 3.0 has been added
+	- Make target uninstall
 
 	Removals:
-	- Support for Dyninst < 10 has been dropped
-	- Command-line options -dfl have been removed
+	- Support for Dyninst < 10
+	- Command-line options -dfl
 
 
 Remote: https://github.com/vanhauser-thc/afl-dyninst
diff --git a/Makefile b/Makefile
index d6a0829..df078b0 100644
--- a/Makefile
+++ b/Makefile
@@ -8,12 +8,9 @@
 # SPDX-License-Identifier: AGPL-3.0-or-later
 
 .POSIX:
-.PHONY: all clean install
-
-CXXFLAGS += -std=c++11 -Wextra -Werror
-LDFLAGS ?= -fPIC
-LDLIBS += -ldyninstAPI
+.PHONY: all clean install uninstall
 
+VERSION ::= 1.0.0
 PREFIX ?= /usr/local
 BINDIR ::= $(DESTDIR)$(PREFIX)/bin
 LIBDIR ::= $(DESTDIR)$(PREFIX)/lib
@@ -23,19 +20,26 @@ DYNINST_LIB ?= $(LIBDIR)
 # Override to . for local development
 AFL_DYNINST_LIB ?= $(LIBDIR)
 
+CPPFLAGS = -DPROG=\"afl-dyninst\" -DVERSION=\"$(VERSION)\"\
+	-DAFL_DYNINST_LIB=\"$(AFL_DYNINST_LIB)/libafldyninst.so\"\
+	-DDYNINSTAPI_RT_LIB=\"$(DYNINST_LIB)/libdyninstAPI_RT.so\"
+CXXFLAGS += -std=c++11 -Wextra -Werror
+LDFLAGS ?= -fPIC
+LDLIBS += -ldyninstAPI
+
 BIN ::= afl-dyninst afl-dyninst-env
 LIB ::= libafldyninst.so
 
 all: $(BIN) $(LIB)
 
-afl-dyninst: afl-dyninst.cc afl-dyninst.h
+afl-dyninst: afl-dyninst.cc
 
-afl-dyninst%: afl-dyninst%.m4
+afl-dyninst-env: afl-dyninst-env.m4
 	m4 -D AFL_DYNINST_LIB=$(AFL_DYNINST_LIB)\
 		-D DYNINST_LIB=$(DYNINST_LIB) $< > $@
 
 %.so: %.cc
-	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -shared $< -o $@
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $< -o $@
 
 clean:
 	rm -f $(BIN) $(LIB)
@@ -47,3 +51,6 @@ $(BINDIR)/%: %
 
 $(LIBDIR)/%: %
 	install -Dm 644 $< $@
+
+uninstall:
+	rm -f $(BIN:%=$(BINDIR)/%) $(LIB:%=$(LIBDIR)/%)
diff --git a/afl-dyninst.cc b/afl-dyninst.cc
index 8e3389d..5fb3d38 100644
--- a/afl-dyninst.cc
+++ b/afl-dyninst.cc
@@ -7,8 +7,6 @@
 // SPDX-FileCopyrightText: 2024 Nguyễn Gia Phong <cnx@loang.net>
 // SPDX-License-Identifier: AGPL-3.0-or-later
 
-#include "afl-dyninst.h"
-
 // DyninstAPI includes
 #include "BPatch.h"
 #include "BPatch_flowGraph.h"
@@ -336,16 +334,16 @@ int main(int argc, char **argv) {
     bpatch.setTrampRecursive(true);
   }
 
-  const char *dyninstapi_rt_lib_old = getenv("DYNINSTAPI_RT_LIB");
-  if (setenv("DYNINSTAPI_RT_LIB", dyninstapi_rt_lib, true) != 0) {
+  const char *dyninstapi_rt_lib = getenv("DYNINSTAPI_RT_LIB");
+  if (setenv("DYNINSTAPI_RT_LIB", DYNINSTAPI_RT_LIB, true) != 0) {
     cerr << "Failed to set DYNINSTAPI_RT_LIB\n"; // TODO: explain
     return EXIT_FAILURE;
   }
-  BPatch_addressSpace *appBin = bpatch.openBinary(originalBinary, instrumentLibraries.size() != 1);
-  if (dyninstapi_rt_lib_old == NULL)
+  BPatch_addressSpace *appBin = bpatch.openBinary(originalBinary, false);
+  if (dyninstapi_rt_lib == NULL)
     unsetenv("DYNINSTAPI_RT_LIB");
   else
-    setenv("DYNINSTAPI_RT_LIB", dyninstapi_rt_lib_old, true);
+    setenv("DYNINSTAPI_RT_LIB", dyninstapi_rt_lib, true);
   if (appBin == NULL) {
     cerr << "Failed to open binary" << endl;
     return EXIT_FAILURE;
@@ -402,8 +400,8 @@ int main(int argc, char **argv) {
   if (defaultModule == NULL)
     defaultModule = firstModule;
 
-  if (!appBin->loadLibrary(afl_dyninst_lib)) {
-    cerr << "Failed to open instrumentation library " << afl_dyninst_lib << endl;
+  if (!appBin->loadLibrary(AFL_DYNINST_LIB)) {
+    cerr << "Failed to open instrumentation library " << AFL_DYNINST_LIB << endl;
     cerr << "It needs to be located in the current working directory." << endl;
     return EXIT_FAILURE;
   }