Skip to content

Instantly share code, notes, and snippets.

@gvanem
Last active May 26, 2018 02:57
Show Gist options
  • Save gvanem/1fda55314efed464e4d004cab05e4dff to your computer and use it in GitHub Desktop.
Save gvanem/1fda55314efed464e4d004cab05e4dff to your computer and use it in GitHub Desktop.
A makefile for Ettercap supporting MSVC, clang-cl and MinGW (the latter is little tested). Ref: https://github.com/Ettercap/ettercap
#
# Ettercap NG Makefile for MinGW / cl / clang-cl.
# by G. Vanem <[email protected]> 2011 - 2018.
#
THIS_FILE = Makefile.Windows
#
# Comment this away to NOT rebuild too many things when $(THIS_FILE) changes.
#
MDEPEND = $(THIS_FILE)
#
# Python is required in '%.i: %.c' rule below.
#
PYTHON ?= python
lparam := (
comma := ,
VERSION := $(shell grep 'set$(lparam)VERSION ' CMakeLists.txt | cut -d'"' -f2)
DATE := $(shell date +%d-%B-%Y)
define USAGE
Usage: make -f $(THIS_FILE) CC=[gcc | cl | clang-cl] [depend | all | clean | vclean]
endef
#
# Choose your weapons:
# Note: do a 'make clean' after changing any of these settings.
#
USE_NCURSES = 0
USE_TD_CURSES = 1
USE_DEBUG = 1
USE_DETAILED_DEBUG = 1
USE_GTK = 1
USE_GTK3 = 0
USE_GTK2_HEXCHAT = 0
USE_GEOIP = 1
USE_IPV6 = 1
USE_LUAJIT = 1
USE_PCAP2 = 0
USE_PCAP_DLL = 0
USE_GNU_INDENT = 0
USE_CLANG_FORMAT = 1
#
# Options for MSVC/clang-cl only:
#
# USE_CRT_DEBUG = 1: Build in debug-mode (uses MSVCR*D.DLL or VCRUNTIME140D.DLL)
# USE_CRT_DEBUG = 0: Build in release-mode (uses MSVCR*.DLL or VCRUNTIME140.DLL)
# USE_WSOCK_TRACE = 1: Use the Wsock-trace library from:
# https://github.com/gvanem/wsock-trace
#
# Notes:
# *) Mixing release and debug libs may bite hard. To be perfect, all
# external libs (EC_LIBS) should match the value of $(USE_CRT_DEBUG).
#
# *) wsock_trace.lib must be on %LIB-path.
#
# *) '_MSC_VER <= 1800' is no longer supported.
#
USE_CRT_DEBUG = 0
USE_WSOCK_TRACE = 1
#
# Root directories. Change to suite!
#
# These are required:
# PCAP_ROOT, WINPCAP_ROOT, LIBNET_ROOT, PTHREADS_ROOT, ICONV_ROOT,
# PCRE_ROOT, REGEX_ROOT and ZLIB_ROOT.
#
# These are required for Gtk3:
# GTK_ROOT. All the dependants of Gtk should be under this messy tree.
#
# 'lua*.lib' under '$(LUAJIT_ROOT)/src' are required if 'USE_LUAJIT=1'.
# (the normal LUA 5.x cannot be used).
#
# If USE_NCURSES=1, the only Ncurses/Win32 port that seems to work is
# Eli Zaretskii's port from:
# http://sourceforge.net/projects/ezwinports/files/
#
# Ref. $(NCURSES_ROOT) below.
#
# The rest are optional depending on what 'USE_x' you've set above.
# Missing packages should not make a difference unless 'USE_x' requires them.
#
# Note: to avoid too many DLLs and increase the speed of pthread, we build
# ettercap with the static version of pthreads. You may need to dive
# into $(PTHREADS_ROOT) and do a "make -f GNUmakefile GC-static".
# This should produce $(PTHREADS_ROOT)/libpthreadGC2.a.
#
MINGW_ROOT = $(realpath $(MINGW32))
PCAP_ROOT = $(MINGW_ROOT)/src/inet/libpcap
WINPCAP_ROOT = $(MINGW_ROOT)/src/inet/libpcap/WinPcap
LIBNET_ROOT = $(MINGW_ROOT)/src/inet/libnet/libnet
LIBCURL_ROOT = $(MINGW_ROOT)/src/inet/curl
GEOIP_ROOT = $(MINGW_ROOT)/src/inet/GeoIP-API-C/libGeoIP
OPENSSL_ROOT = $(MINGW_ROOT)/src/inet/Crypto/OpenSSL
PTHREADS_ROOT = $(MINGW_ROOT)/src/pthreads-w32-2-9-1-release/pthreads.2
REGEX_ROOT = $(MINGW_ROOT)/src/RegExp/regex-0.12
PCRE_ROOT = $(MINGW_ROOT)/src/RegExp/libpcre
ICONV_ROOT = $(MINGW_ROOT)/src/libiconv-1.9.1
LUAJIT_ROOT = $(MINGW_ROOT)/src/Parsers/LuaJIT
NCURSES_ROOT = $(MINGW_ROOT)/src/TUI/ncurses-5.4
ZLIB_ROOT = $(MINGW_ROOT)/src/Compression/zlib-1.2.8
#
# The following codes used in macro 'colour_msg' assumes you have
# MSys/Cygwin's echo with colour support.
#
LIGHT_RED = \e[1;31m
LIGHT_GREEN = \e[1;32m
LIGHT_YELLOW = \e[1;33m
colour_msg = @echo -e "$(1)\e[0m"
message_green = $(call colour_msg,$(LIGHT_GREEN)$(1))
#
# $(PF) -> %ProgramFiles%
# Since in a 32-bit gnumake, Windows seems to want to return the value
# of %ProgramFiles(x86)%.
#
ifeq ($(USE_GTK2_HEXCHAT),1)
#
# An unofficial Gtk2 from HexChat:
# https://github.com/hexchat/gtk-win32
#
GTK_ROOT ?= $(MINGW_ROOT)/src/GUI/WinGTK-HexChat
USE_GTK := 1
USE_GTK3 := 0
else ifeq ($(USE_GTK),1)
#
# The official Gtk3 3.x.
#
GTK_ROOT ?= $(realpath $(PF))/Gtk-Plus/Gtk3-3.6.4
GTK_ROOT := $(realpath $(PF))/Gtk3
endif
#
# Base for generated man-pages
#
MAN_BASE = $(MINGW_ROOT)/share/man
#
# Import-libraries used by '$(call build_plugin)' which we do not need.
#
TMP_FOO_LIB_gcc = $(realpath $(TEMP))/libfoo.dll.a
TMP_FOO_LIB_cl = $(realpath $(TEMP))/foo_imp.lib
TMP_FOO_LIB_clang-cl = $(TMP_FOO_LIB_cl)
#
# Now test for compilers:
#
ifeq ($(CC),gcc)
OBJ_DIR = MinGW_obj
else ifeq ($(CC),cl)
OBJ_DIR = MSVC_obj
else ifeq ($(CC),clang-cl)
#
# clang-cl doesn't like stuff in %CL%.
#
export CL=
OBJ_DIR = Clang_obj
else
$(error $(USAGE))
endif
ifeq ($(CC),gcc)
O = o
lib_name = $(strip $(1))
CFLAGS = -m32 -Wall -O2 -fno-strength-reduce -g # -gdwarf-2 -fdwarf2-cfi-asm
else
O = obj
lib_name = $(strip $(2))
ifeq ($(USE_NCURSES),1)
$(warning "Ncurses is very flaky for MSVC/clang-cl.")
endif
ifeq ($(USE_CRT_DEBUG),1)
CFLAGS = -MDd
else
CFLAGS = -MD
endif
CFLAGS += -nologo -W3 -O2 -Zi -DWIN32 -DYY_NO_UNISTD_H
endif
ifeq ($(USE_PCAP_DLL),1)
CFLAGS += -DPCAP_DLL
endif
#
# Use static-libs wherever we can to avoid a potential DLL hell.
#
# The libs for Glib and GTK.
#
GLIB_LIBS = $(call lib_name, $(addprefix $(GTK_ROOT)/lib/, \
libglib-2.0.dll.a \
libgmodule-2.0.dll.a \
libgobject-2.0.dll.a \
libgthread-2.0.dll.a) , \
$(addprefix $(GTK_ROOT)/lib/, \
glib-2.0.lib \
gobject-2.0.lib \
gthread-2.0.lib) )
ifeq ($(USE_GTK3),1)
GTK_LIBS = $(call lib_name, $(GTK_ROOT)/lib/libgdk-3.dll.a \
$(GTK_ROOT)/lib/libgdk_pixbuf-2.0.dll.a \
$(GTK_ROOT)/lib/libgtk-3.dll.a \
$(GTK_ROOT)/lib/libgio-2.0.dll.a, \
$(GTK_ROOT)/lib/gtk-win32-3.0.lib \
$(GTK_ROOT)/lib/gdk_pixbuf-2.0.lib \
$(GTK_ROOT)/lib/gio-2.0.lib)
else
GTK_LIBS = $(call lib_name, $(GTK_ROOT)/lib/libgdk-win32-2.0.dll.a \
$(GTK_ROOT)/lib/libgdk_pixbuf-2.0.dll.a \
$(GTK_ROOT)/lib/libgtk-win32-2.0.dll.a, \
$(GTK_ROOT)/lib/gtk-win32-2.0.lib \
$(GTK_ROOT)/lib/gdk_pixbuf-2.0.lib)
endif
GEOIP_LIB = $(call lib_name, $(GEOIP_ROOT)/libGeoIP.a, \
$(GEOIP_ROOT)/GeoIP.lib)
ICONV_LIB = $(call lib_name, $(ICONV_ROOT)/lib/libiconv.dll.a, \
$(ICONV_ROOT)/lib/iconv.lib)
LIBCURL_LIB = $(call lib_name, $(LIBCURL_ROOT)/lib/libcurl.dll.a, \
$(LIBCURL_ROOT)/lib/libcurl_imp.lib)
ifeq ($(USE_PCAP2),1)
TWO = 2
else
TWO =
endif
ifeq ($(USE_PCAP_DLL),1)
LIBPCAP_LIBS = $(call lib_name, $(PCAP_ROOT)/libwpcap$(TWO).a, \
$(PCAP_ROOT)/wpcap$(TWO).lib)
else
LIBPCAP_LIBS = $(call lib_name, $(PCAP_ROOT)/libwpcap$(TWO)_static.a, \
$(PCAP_ROOT)/wpcap$(TWO)_static.lib)
endif
LIBNET_LIBS = $(call lib_name, $(LIBNET_ROOT)/src/libnet.a \
$(WINPCAP_ROOT)/lib/libpacket.a, \
$(LIBNET_ROOT)/src/libnet.lib \
$(WINPCAP_ROOT)/lib/Packet.lib)
LIBNET_LIBS += $(call lib_name, -lversion -ladvapi32 -liphlpapi, \
version.lib advapi32.lib iphlpapi.lib)
OPENSSL_LIBS = $(call lib_name, $(OPENSSL_ROOT)/lib32/libssl.a \
$(OPENSSL_ROOT)/lib32/libcrypto.a, \
$(OPENSSL_ROOT)/lib32/libssl.lib \
$(OPENSSL_ROOT)/lib32/libcrypto.lib)
OPENSSL_LIBS += $(call lib_name, -ladvapi32 -lgdi32, \
advapi32.lib gdi32.lib user32.lib)
PCRE_LIB = $(call lib_name, $(PCRE_ROOT)/libpcre.a, \
$(PCRE_ROOT)/pcre.lib)
PTHREADS_LIB = $(call lib_name, $(PTHREADS_ROOT)/libpthreadGC2.a, \
$(PTHREADS_ROOT)/pthreadVC2.lib)
REGEX_LIB = $(call lib_name, $(REGEX_ROOT)/libregex.a, \
$(REGEX_ROOT)/regex.lib)
ZLIB_LIB = $(call lib_name, $(ZLIB_ROOT)/lib/x86/libz.a, \
$(ZLIB_ROOT)/lib/x86/zlib.lib)
#
# Since OpenSSL may have been configured with 'enable-zlib'.
#
OPENSSL_LIBS += $(ZLIB_LIB)
VPATH = ../utils/etterfilter \
../utils/etterlog \
dissectors \
protocols \
lua \
missing \
mitm \
os \
$(addprefix interfaces/, \
curses \
curses/widgets \
text)
PROGRAMS = ../ettercap.exe ../etterfilter.exe ../etterlog.exe
#
# What should be generated before 'make all' or 'make depend' is done.
#
GENERATED = config.h \
el_windows.c \
ef_windows.c \
lua/ec_lua_config.h \
$(addprefix ../utils/etterfilter/, \
ef_syntax.c \
ef_grammar.c \
ef_grammar.h)
#
# Generate these fake .h-files for MSVC/clang-cl:
#
ifneq ($(CC),gcc)
GENERATED += $(addprefix ../include/missing/msvc/, \
strings.h \
unistd.h \
sys/param.h \
sys/time.h) \
msvc-init.c
endif
#
# Use Ncurses with Tomas Dickey's TD_lib
#
ifeq ($(USE_NCURSES),1)
ifeq ($(USE_TD_CURSES),1)
GENERATED += $(OBJ_DIR)/ncurses.h
CFLAGS += -I$(OBJ_DIR) \
-I$(NCURSES_ROOT)/td_lib/include \
-I$(NCURSES_ROOT)/menu \
-I$(NCURSES_ROOT)/form \
-I$(NCURSES_ROOT)/panel
endif
endif
GENERATED += extra-exports.def
MAN_PAGES = $(addprefix ../man/, \
etter.conf.5 \
ettercap.8 \
ettercap_curses.8 \
ettercap_plugins.8 \
etterfilter.8 \
etterlog.8)
PDF_FILES = $(addsuffix .pdf, $(basename $(MAN_PAGES)))
#
# Do some checks first.
#
path_find = $(wildcard $(addsuffix /$(1),$(subst ;, ,$(subst \,/,$(PATH)))))
file_find = $(wildcard $(1))
.PHONY: check_stuff
default: all
check_stuff:
ifeq ($(CC),gcc)
ifneq ($(shell gcc -dumpmachine), mingw32)
ifneq ($(shell gcc -dumpmachine), x86_64-w64-mingw32)
$(error "gcc seems not to be MinGW compiled. Maybe your $$PATH is wrong?")
endif
endif
endif
ifeq ($(call file_find,../INSTALL),)
$(error "../INSTALL not found. Run 'make -f $(THIS_FILE)' in the Ettercap src-dir only.")
endif
ifeq ($(call file_find,$(OBJ_DIR)/.),)
-@mkdir -p $(OBJ_DIR)
endif
$(call message_green,"$@" okay)
###############################################################################################
#
# Shit-for-brains <libnet.h> tests on '#ifdef __WIN32__' in a public header!
# Avoid reading it's incompatible "stdint.h" too.
#
CFLAGS += -D__WIN32__ -D_MSC_STDINT_H_
ifneq ($(CC),gcc)
CFLAGS += -DTYPES_DEFINED
endif
CFLAGS += -DHAVE_CONFIG_H \
-DHAVE_PCRE \
-DPCRE_STATIC \
-DPTW32_STATIC_LIB \
-D_WIN32_WINNT=0x0501 \
-DHAVE_OPENSSL
#
# We need all these internal include dirs. A bit of a mess :-(
#
CFLAGS += -I. \
-I../include \
-I../include/missing \
-I./interfaces/text \
-I./interfaces/curses \
-I./interfaces/curses/widgets \
-I./interfaces/daemon \
-I../utils/etterfilter \
-I../utils/etterlog
ifeq ($(USE_IPV6),1)
CFLAGS += -DWITH_IPV6
endif
ifeq ($(USE_GEOIP),1)
CFLAGS += -DWITH_GEOIP -DHAVE_GEOIP -DGEOIP_STATIC -I$(GEOIP_ROOT)
endif
#
# And these external include dirs.
#
CFLAGS += -I$(ZLIB_ROOT) \
-I$(ICONV_ROOT)/include \
-I$(LIBNET_ROOT)/include \
-I$(REGEX_ROOT) \
-I$(PTHREADS_ROOT) \
-I$(PCAP_ROOT) \
-I$(WINPCAP_ROOT)/Include \
-I$(LIBCURL_ROOT)/include \
-I$(OPENSSL_ROOT)/include \
-I$(PCRE_ROOT)
ifeq ($(CC),gcc)
CFLAGS += -Wno-strict-aliasing \
-Wno-unused-function \
-Wno-unused-variable \
-Wno-return-type \
-Wno-parentheses \
-Wno-pointer-sign \
-Wno-pointer-to-int-cast \
-Wno-unused-but-set-variable \
-Wno-maybe-uninitialized \
-Wno-deprecated-declarations \
-Wno-discarded-qualifiers \
-Wno-incompatible-pointer-types
LDFLAGS += -m32 -Wl,--print-map,--sort-common,--cref
WSOCK_LIB = -lws2_32
else
ifeq ($(USE_WSOCK_TRACE),1)
WSOCK_LIB = wsock_trace.lib
else
WSOCK_LIB = ws2_32.lib
endif
CFLAGS += -I../include/missing/msvc
#
# Always generate .pdb and .map-files. Some external libraries may
# reference 'libcmt.lib'. But we DO NOT want it (we use 'ucrt.lib' + 'vcruntime.lib').
#
LDFLAGS += -debug -verbose -incremental:no -map -nodefaultlib:libcmt.lib
ifeq ($(CC),clang-cl)
CFLAGS += -Wall \
-Wno-pedantic \
-Wno-pointer-sign \
-Wno-conversion \
-Wno-sign-conversion \
-Wno-deprecated-declarations \
-Wno-compare-distinct-pointer-types \
-Wno-incompatible-pointer-types \
-Wno-incompatible-pointer-types-discards-qualifiers \
-Wno-unused-function \
-Wno-unused-variable \
-Wno-unused-parameter \
# -Wno-unknown-pragmas
#
# I've not added '-Wno-shadow' as that warning is pretty important.
# And there are lots of these warnings when using clang-cl v6.
#
# These were added in clang ver 6 (I think).
#
CFLAGS += -Wno-reserved-id-macro \
-Wno-documentation \
-Wno-documentation-unknown-command \
-Wno-strict-prototypes \
-Wno-undef \
-Wno-gnu-zero-variadic-macro-arguments \
-Wno-language-extension-token \
-Wno-nonportable-system-include-path \
-Wno-missing-variable-declarations \
-Wno-missing-prototypes \
-Wno-unused-macros \
-Wno-cast-align \
-Wno-cast-qual \
-Wno-redundant-parens \
-Wno-unreachable-code-break \
-Wno-format-nonliteral \
-Wno-missing-noreturn \
-Wno-comma \
-Wno-assign-enum \
-Wno-double-promotion \
-Wno-unreachable-code
endif
endif
#
# EC_LIBS = External libraries for ettercap_c.dll:
#
# These are the external libraries we always need.
#
EC_LIBS = $(PCRE_LIB) $(PTHREADS_LIB) $(OPENSSL_LIBS) $(LIBPCAP_LIBS) $(LIBNET_LIBS)
ifeq ($(CC),gcc)
RCFLAGS = -O COFF --target=pe-i386 -D__MINGW32__
else
RCFLAGS = -nologo
ifeq ($(CC),clang-cl)
RCFLAGS += -D__clang__
else
RCFLAGS += -D_MSC_VER
endif
endif
RCFLAGS += -I. -I..
ifeq ($(USE_DEBUG),1)
CFLAGS += -DDEBUG
RCFLAGS += -DDEBUG
ifeq ($(USE_DETAILED_DEBUG),1)
CFLAGS += -DDETAILED_DEBUG
endif
endif
ifeq ($(USE_NCURSES),1)
CFLAGS += -DHAVE_NCURSES -I$(NCURSES_ROOT)/include
EC_LIBS += $(NCURSES_ROOT)/libncurses.a
endif
#
# And the unbelievable messy GTK layout.
#
ifeq ($(USE_GTK),1)
EC_LIBS += $(GLIB_LIBS) $(GTK_LIBS)
CFLAGS += # -DIM_A_GUI_APP
CFLAGS += -I$(GTK_ROOT)/lib/glib-2.0/include \
-I$(GTK_ROOT)/include \
-I$(GTK_ROOT)/include/glib-2.0 \
-I$(GTK_ROOT)/include/gdk-pixbuf-2.0 \
-I$(GTK_ROOT)/include/cairo \
-I$(GTK_ROOT)/include/pango-1.0 \
-I$(GTK_ROOT)/include/atk-1.0
ifeq ($(USE_GTK3),1)
CFLAGS += -I$(GTK_ROOT)/include/gtk-3.0 \
-I./interfaces/gtk3 \
-DHAVE_GTK3
else
CFLAGS += -I$(GTK_ROOT)/lib/gtk-2.0/include \
-I$(GTK_ROOT)/include/gtk-2.0 \
-I./interfaces/gtk \
-DHAVE_GTK
endif
#
# If 'USE_DEBUG=1', we need a console to print to.
#
# ifeq ($(USE_DEBUG),0)
# ifeq ($(CC),gcc)
# EC_LDFLAGS = -Wl,--subsystem,windows
# else
# EC_LDFLAGS = -subsystem:windows
# endif
# endif
endif
ifeq ($(USE_GEOIP),1)
EC_LIBS += $(GEOIP_LIB)
endif
ifeq ($(USE_LUAJIT),1)
CFLAGS += -DHAVE_EC_LUA -DUSE_LUAJIT \
-I./lua -I$(LUAJIT_ROOT)/src
EC_LIBS += $(call lib_name, $(LUAJIT_ROOT)/src/libluajit.a, \
$(LUAJIT_ROOT)/src/lua51_static.lib)
endif
EC_LIBS += $(ICONV_LIB) $(ZLIB_LIB) $(WSOCK_LIB)
#
# Sources for ettercap_c.dll
#
EC_LIB_SRC = ec_capture.c ec_checksum.c ec_conf.c ec_connbuf.c \
ec_conntrack.c ec_debug.c ec_decode.c ec_dispatcher.c \
ec_dissect.c ec_error.c ec_file.c ec_filter.c \
ec_fingerprint.c ec_format.c ec_globals.c ec_hash.c \
ec_hook.c ec_inet.c ec_inject.c ec_interfaces.c \
ec_log.c ec_manuf.c ec_mitm.c ec_encryption_ccmp.c \
ec_packet.c ec_passive.c ec_plugins.c ec_geoip.c \
ec_poll.c ec_profiles.c ec_resolv.c ec_scan.c \
ec_send.c ec_services.c ec_session.c ec_signals.c \
ec_sniff.c ec_sniff_bridge.c ec_sniff_unified.c ec_socket.c \
ec_stats.c ec_streambuf.c ec_strings.c ec_threads.c \
ec_ui.c ec_network.c ec_sslwrap.c ec_sleep.c \
ec_encryption.c ec_set.c ec_encryption_tkip.c ec_exit.c \
ec_utils.c ec_mem.c ec_asn1.c
EC_LIB_SRC += $(addprefix dissectors/, \
ec_bgp.c ec_cvs.c ec_dhcp.c ec_dns.c ec_ftp.c ec_gg.c \
ec_http.c ec_icq.c ec_imap.c ec_irc.c ec_iscsi.c ec_ldap.c \
ec_mdns.c ec_mongodb.c ec_mountd.c ec_msn.c ec_mysql.c \
ec_nbns.c ec_nntp.c ec_o5logon.c ec_ospf.c ec_pop.c ec_portmap.c \
ec_postgresql.c ec_radius.c ec_rcon.c ec_rip.c ec_rlogin.c ec_smb.c \
ec_smtp.c ec_snmp.c ec_socks.c ec_telnet.c ec_TN3270.c \
ec_vnc.c ec_vrrp.c ec_x11.c ec_ymsg.c ec_kerberos.c) \
\
# dissectors/ec_ssh.c
ifeq ($(USE_LUAJIT),1)
EC_LIB_SRC += lua/ec_lua.c
endif
EC_LIB_SRC += $(addprefix protocols/, \
ec_arp.c \
ec_cooked.c \
ec_erf.c \
ec_eth.c \
ec_fddi.c \
ec_gre.c \
ec_esp.c \
ec_icmp.c \
ec_icmp6.c \
ec_ip.c \
ec_ip6.c \
ec_mpls.c \
ec_null.c \
ec_ppi.c \
ec_ppp.c \
ec_pppoe.c \
ec_rawip.c \
ec_tcp.c \
ec_tr.c \
ec_udp.c \
ec_vlan.c \
ec_wifi.c \
ec_wifi_eapol.c \
ec_wifi_prism.c \
ec_wifi_radiotap.c)
ifeq ($(USE_NCURSES),1)
EC_LIB_SRC += $(addprefix interfaces/curses/, \
ec_curses.c \
ec_curses_help.c \
ec_curses_filters.c \
ec_curses_hosts.c \
ec_curses_live.c \
ec_curses_logging.c \
ec_curses_mitm.c \
ec_curses_offline.c \
ec_curses_plugins.c \
ec_curses_start.c \
ec_curses_targets.c \
ec_curses_view.c \
ec_curses_view_connections.c \
ec_curses_view_profiles.c)
EC_LIB_SRC += $(addprefix interfaces/curses/widgets/, \
wdg.c \
wdg_compound.c \
wdg_debug.c \
wdg_dialog.c \
wdg_dynlist.c \
wdg_error.c \
wdg_file.c \
wdg_input.c \
wdg_list.c \
wdg_menu.c \
wdg_panel.c \
wdg_percentage.c \
wdg_scroll.c \
wdg_window.c)
endif
ifeq ($(USE_GTK3),1)
#
# Gtk3 only code
#
VPATH += interfaces/gtk3
EC_LIB_SRC += $(addprefix interfaces/gtk3/, \
ec_gtk3.c \
ec_gtk3_conf.c \
ec_gtk3_filters.c \
ec_gtk3_help.c \
ec_gtk3_hosts.c \
ec_gtk3_live.c \
ec_gtk3_logging.c \
ec_gtk3_menus.c \
ec_gtk3_mitm.c \
ec_gtk3_offline.c \
ec_gtk3_plugins.c \
ec_gtk3_shortcuts.c \
ec_gtk3_start.c \
ec_gtk3_targets.c \
ec_gtk3_view.c \
ec_gtk3_view_connections.c \
ec_gtk3_view_profiles.c)
else ifeq ($(USE_GTK),1)
#
# Gtk2/3 interface
#
VPATH += interfaces/gtk
EC_LIB_SRC += $(addprefix interfaces/gtk/, \
ec_gtk.c \
ec_gtk_filters.c \
ec_gtk_hosts.c \
ec_gtk_live.c \
ec_gtk_logging.c \
ec_gtk_menus.c \
ec_gtk_mitm.c \
ec_gtk_offline.c \
ec_gtk_plugins.c \
ec_gtk_start.c \
ec_gtk_targets.c \
ec_gtk_view.c \
ec_gtk_view_connections.c \
ec_gtk_view_profiles.c \
ec_gtk_conf.c \
ec_gtk_help.c)
endif
EC_LIB_SRC += $(addprefix interfaces/text/, \
ec_text.c \
ec_text_conn.c \
ec_text_display.c \
ec_text_plugin.c \
ec_text_profile.c)
EC_LIB_SRC += $(addprefix mitm/, \
ec_arp_poisoning.c \
ec_dhcp_spoofing.c \
ec_icmp_redirect.c \
ec_port_stealing.c)
ifeq ($(USE_IPV6),1)
EC_LIB_SRC += mitm/ec_ip6nd_poison.c
endif
EC_LIB_SRC += $(addprefix missing/, \
basename.c \
inet_pton.c \
memmem.c \
memrchr.c \
scandir.c \
strcasestr.c \
strlcat.c \
strlcpy.c \
strndup.c \
strsep.c) \
os/ec_mingw.c
#
# Not longer a need for 'inet_aton()'.
#
# EC_LIB_SRC += missing/inet_aton.c
#
EC_LIB_SRC := $(sort $(strip $(EC_LIB_SRC)))
EC_LIB_OBJ = $(addprefix $(OBJ_DIR)/, $(notdir $(EC_LIB_SRC:.c=.$(O))))
#
# Sources for ettercap.exe
#
MAIN_SRC = ec_main.c \
ec_parser.c \
missing/getopt.c
MAIN_OBJ = $(addprefix $(OBJ_DIR)/, \
$(notdir $(MAIN_SRC:.c=.$(O))))
#
# Adding a '-DBUILDING_PLUGIN' is not only for plugin sources.
# It just forces the correct 'dllimport' on functions and variables needed
# in these sources too.
#
$(OBJ_DIR)/ec_main.$(O) ec_main.i: EXTRA_CFLAGS = -DBUILDING_PLUGIN
$(OBJ_DIR)/ec_parser.$(O) ec_parser.i: EXTRA_CFLAGS = -DBUILDING_PLUGIN
#
# Sources for etterfilter.exe:
#
EF_SOURCES = $(addprefix ../utils/etterfilter/, \
ef_compiler.c \
ef_ec_compat.c \
ef_encode.c \
ef_grammar.c \
ef_main.c \
ef_output.c \
ef_parser.c \
ef_tables.c \
ef_test.c \
ef_syntax.c) \
missing/getopt.c \
ef_windows.c
#
# Sources for etterlist.exe:
#
EL_SOURCES = $(addprefix ../utils/etterlog/, \
el_analyze.c \
el_conn.c \
el_decode.c \
el_decode_http.c \
el_display.c \
el_log.c \
el_main.c \
el_parser.c \
el_profiles.c \
el_stream.c \
el_target.c \
el_ec_compat.c) \
\
ec_manuf.c \
ec_services.c \
missing/getopt.c \
missing/strlcat.c \
el_windows.c
EF_OBJECTS = $(addprefix $(OBJ_DIR)/, $(notdir $(EF_SOURCES:.c=.$(O))))
EL_OBJECTS = $(addprefix $(OBJ_DIR)/, $(notdir $(EL_SOURCES:.c=.$(O))))
#
# All these files must be copied to ../share/lua before
# ettercap can use them.
#
LUA_SOURCES = $(addprefix lua/share/, \
init.lua \
\
$(addprefix core/, \
base64.lua \
dumper.lua \
eclib.lua \
ec_string.lua \
ettercap.lua \
ettercap_ffi.lua \
ettercap_reg.lua \
hook_points.lua \
http.lua \
packet.lua \
packet_meta.lua \
shortpacket.lua \
shortsession.lua) \
\
$(addprefix scripts/, \
geoip_demo.lua \
get_imap_demo.lua \
http_creds.lua \
http_inject2_demo.lua \
http_requests.lua \
inject_http.lua \
inject_http_demo.lua \
smtp_redir.lua \
tcp_session_demo.lua) \
\
$(addprefix third-party/stdlib/, \
mkrockspecs.lua \
rockspecs.lua \
template.lua \
src/base.lua \
src/bin.lua \
src/debug_ext.lua \
src/debug_init.lua \
src/fstable.lua \
src/getopt.lua \
src/io_ext.lua \
src/lcs.lua \
src/list.lua \
src/math_ext.lua \
src/mbox.lua \
src/modules.lua \
src/object.lua \
src/package_ext.lua \
src/parser.lua \
src/set.lua \
src/strbuf.lua \
src/strict.lua \
src/string_ext.lua \
src/table_ext.lua \
src/tree.lua \
src/xml.lua))
#
# The import library used by ettercap.exe, the plugin DLLs, .lua-files and
# the utils-programs etterfilter.exe and etterlog.exe.
#
ifeq ($(CC),gcc)
EC_IMPORT = ../ettercap_c.dll.a
EXPORTS_DEF_ARG = extra-exports.def
else
EC_IMPORT = ../ettercap_c_imp.lib
EXPORTS_DEF_ARG = -def:extra-exports.def
NO_OLDNAMES_LIB = -nodefaultlib:oldnames.lib
endif
VPATH += $(addprefix ../plug-ins/, \
arp_cop \
autoadd \
chk_poison \
dns_spoof \
dos_attack \
dummy \
find_conn \
find_ettercap \
find_ip \
finger \
finger_submit \
fraggle_attack \
gre_relay \
gw_discover \
isolate \
krb5_downgrade \
link_type \
mdns_spoof \
nbns_spoof \
pptp_chapms1 \
pptp_clear \
pptp_pap \
pptp_reneg \
rand_flood \
remote_browser \
reply_arp \
repoison_arp \
scan_poisoner \
search_promisc \
smb_clear \
smb_down \
smurf_attack \
sslstrip \
stp_mangler)
PLUGIN_SRC = $(addprefix ../plug-ins/, \
arp_cop/arp_cop.c \
autoadd/autoadd.c \
chk_poison/chk_poison.c \
dns_spoof/dns_spoof.c \
dos_attack/dos_attack.c \
dummy/dummy.c \
find_conn/find_conn.c \
find_ettercap/find_ettercap.c \
find_ip/find_ip.c \
finger/finger.c \
finger_submit/finger_submit.c \
fraggle_attack/fraggle_attack.c \
gre_relay/gre_relay.c \
gw_discover/gw_discover.c \
isolate/isolate.c \
link_type/link_type.c \
krb5_downgrade/krb5_downgrade.c \
mdns_spoof/mdns_spoof.c \
nbns_spoof/nbns_spoof.c \
pptp_chapms1/pptp_chapms1.c \
pptp_clear/pptp_clear.c \
pptp_pap/pptp_pap.c \
pptp_reneg/pptp_reneg.c \
rand_flood/rand_flood.c \
remote_browser/remote_browser.c \
reply_arp/reply_arp.c \
repoison_arp/repoison_arp.c \
scan_poisoner/scan_poisoner.c \
search_promisc/search_promisc.c \
smb_clear/smb_clear.c \
smb_down/smb_down.c \
smurf_attack/smurf_attack.c \
sslstrip/sslstrip.c \
stp_mangler/stp_mangler.c)
PLUGIN_DLLs = $(addprefix ../lib/ec_, \
$(notdir $(PLUGIN_SRC:.c=.dll)) )
PLUGIN_OBJs = $(addprefix $(OBJ_DIR)/, \
$(notdir $(PLUGIN_DLLs:.dll=.$(O))) )
$(PLUGIN_DLLs): $(EC_IMPORT)
$(addprefix $(OBJ_DIR)/ec_, dns.$(O) inject.$(O) sslwrap.$(O) gre.$(O) ip.$(O) ip6.$(O) tcp.$(O)): \
EXTRA_CFLAGS = -Dint16=int16_t -Dint32=int32_t
all: check_stuff $(OBJ_DIR) $(GENERATED) $(PROGRAMS) plugins copy_lua_files_$(USE_LUAJIT) man_pages
@echo "Welcome to EtterCap $(VERSION)"
test:
@echo "Building EtterCap $(VERSION)."
$(EC_IMPORT): ../ettercap_c.dll
../ettercap_c.dll: $(EC_LIB_OBJ) extra-exports.def $(OBJ_DIR)/ettercap_c.res
$(call link_DLL, $@, $(EC_LDFLAGS) $(EC_LIB_OBJ) $(OBJ_DIR)/ettercap_c.res $(EXPORTS_DEF_ARG) $(EC_LIBS), $(EC_IMPORT))
../ettercap.exe: $(MAIN_OBJ) $(OBJ_DIR)/ettercap.res $(EC_IMPORT)
$(call link_EXE, $@, $^ $(NO_OLDNAMES_LIB) $(WSOCK_LIB))
../etterfilter.exe: $(EF_OBJECTS) $(EC_IMPORT)
$(call link_EXE, $@, $^ $(NO_OLDNAMES_LIB) $(PCRE_LIB) $(WSOCK_LIB))
../etterlog.exe: $(EL_OBJECTS) $(EC_IMPORT)
$(call link_EXE, $@, $^ $(ZLIB_LIB) $(REGEX_LIB) $(WSOCK_LIB))
#
# Rules for compiling and linking plugins into ../lib.
#
../lib/ec_dummy.dll: ../plug-ins/dummy/dummy.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_arp_cop.dll: ../plug-ins/arp_cop/arp_cop.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_autoadd.dll: ../plug-ins/autoadd/autoadd.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_chk_poison.dll: ../plug-ins/chk_poison/chk_poison.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB))
../lib/ec_dns_spoof.dll: ../plug-ins/dns_spoof/dns_spoof.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_dos_attack.dll: ../plug-ins/dos_attack/dos_attack.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB) $(WSOCK_LIB))
../lib/ec_find_conn.dll: ../plug-ins/find_conn/find_conn.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_find_ettercap.dll: ../plug-ins/find_ettercap/find_ettercap.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_find_ip.dll: ../plug-ins/find_ip/find_ip.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_finger.dll: ../plug-ins/finger/finger.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_finger_submit.dll: ../plug-ins/finger_submit/finger_submit.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_fraggle_attack.dll: ../plug-ins/fraggle_attack/fraggle_attack.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB) $(WSOCK_LIB))
../lib/ec_gre_relay.dll: ../plug-ins/gre_relay/gre_relay.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_gw_discover.dll: ../plug-ins/gw_discover/gw_discover.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_isolate.dll: ../plug-ins/isolate/isolate.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB))
../lib/ec_link_type.dll: ../plug-ins/link_type/link_type.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB))
../lib/ec_krb5_downgrade.dll: ../plug-ins/krb5_downgrade/krb5_downgrade.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_mdns_spoof.dll: ../plug-ins/mdns_spoof/mdns_spoof.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_nbns_spoof.dll: ../plug-ins/nbns_spoof/nbns_spoof.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_pptp_chapms1.dll: ../plug-ins/pptp_chapms1/pptp_chapms1.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_pptp_clear.dll: ../plug-ins/pptp_clear/pptp_clear.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_pptp_pap.dll: ../plug-ins/pptp_pap/pptp_pap.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_pptp_reneg.dll: ../plug-ins/pptp_reneg/pptp_reneg.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_rand_flood.dll: ../plug-ins/rand_flood/rand_flood.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB) $(WSOCK_LIB))
../lib/ec_reply_arp.dll: ../plug-ins/reply_arp/reply_arp.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_repoison_arp.dll: ../plug-ins/repoison_arp/repoison_arp.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_scan_poisoner.dll: ../plug-ins/scan_poisoner/scan_poisoner.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB))
../lib/ec_search_promisc.dll: ../plug-ins/search_promisc/search_promisc.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB))
../lib/ec_smb_clear.dll: ../plug-ins/smb_clear/smb_clear.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
../lib/ec_smb_down.dll: ../plug-ins/smb_down/smb_down.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(WSOCK_LIB))
../lib/ec_smurf_attack.dll: ../plug-ins/smurf_attack/smurf_attack.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB) $(WSOCK_LIB))
../lib/ec_sslstrip.dll: ../plug-ins/sslstrip/sslstrip.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PCRE_LIB) $(LIBCURL_LIB) $(PTHREADS_LIB) $(WSOCK_LIB))
../lib/ec_stp_mangler.dll: ../plug-ins/stp_mangler/stp_mangler.c $(EC_IMPORT)
$(call build_plugin, $@, $<, $(PTHREADS_LIB) $(WSOCK_LIB))
../lib/ec_remote_browser.dll: ../plug-ins/remote_browser/remote_browser.c $(EC_IMPORT)
$(call build_plugin, $@, $<)
#
# The ./share/lua structure is completely flat!
#
copy_lua_files_1: $(LUA_SOURCES)
$(call message_green,Creating dirs for Lua.)
-@mkdir --parents ../share/lua
cp --update $^ ../share/lua
copy_lua_files_0:
$(call message_green,Nothing to do for Lua.)
plugins: $(PLUGIN_DLLs)
$(call message_green,$(words $(PLUGIN_DLLs)) plugins created.)
rm -f $(TMP_FOO_LIB_$(CC))
man_pages: $(MAN_PAGES)
pdf_files: $(PDF_FILES)
$(OBJ_DIR):
-@mkdir $(OBJ_DIR)
#
# Compile-rule for '../plugins/*/%.c' files:
#
# $(PLUGIN_OBJs): EXTRA_CFLAGS = -DBUILDING_PLUGIN -DPLUGIN_FILE=\"$(strip $(word 1,$<))\" -Dint16=int16_t -Dint32=int32_t
#
# $(OBJ_DIR)/ec_%.$(O): %.c | $(CC).args
# $(call Compile, $<, $@)
$(OBJ_DIR)/%.$(O): %.c | $(CC).args
$(call Compile, $<, $@)
../man/%.5: ../man/%.5.in
sed -e 's/@VERSION/$(VERSION)/' < $< > $@
cp -u $@ $(MAN_BASE)/man5
../man/%.8: ../man/%.8.in
sed -e 's/@VERSION/$(VERSION)/' < $< > $@
cp -u $@ $(MAN_BASE)/man8
../man/%.pdf: ../man/%.5
groff -Tdvi -mandoc $^ > tmp.dvi
dvipdfm -o $@ tmp.dvi
rm -f tmp.dvi
../man/%.pdf: ../man/%.8
groff -Tdvi -mandoc $^ > tmp.dvi
dvipdfm -o $@ tmp.dvi
rm -f tmp.dvi
../utils/etterfilter/ef_grammar.c ../utils/etterfilter/ef_grammar.h: ../utils/etterfilter/ef_grammar.y
bison --yacc --defines $^
mv -f y.tab.c ../utils/etterfilter/ef_grammar.c
mv -f y.tab.h ../utils/etterfilter/ef_grammar.h
../utils/etterfilter/ef_syntax.c: ../utils/etterfilter/ef_syntax.l
flex -t $^ > $@
$(OBJ_DIR)/ettercap.res: $(OBJ_DIR)/_ettercap.rc ../contrib/nsis/eNG.ico
$(call make_res, $<, $@)
$(OBJ_DIR)/ettercap_c.res: $(OBJ_DIR)/_ettercap_c.rc ../contrib/nsis/eNG.ico
$(call make_res, $<, $@)
$(OBJ_DIR)/_ettercap.rc: $(MDEPEND)
$(call Generate, $@, //)
$(file >> $@, #define RC_FILETYPE VFT_APP)
$(file >> $@, #define RC_FILENAME "ettercap.exe")
$(file >> $@, #include "ettercap.rc")
$(OBJ_DIR)/_ettercap_c.rc: $(MDEPEND)
$(call Generate, $@, //)
$(file >> $@, #define RC_FILETYPE VFT_DLL)
$(file >> $@, #define RC_FILENAME "ettercap_c.dll")
$(file >> $@, #include "ettercap.rc")
#
# Command to generate a nicer C preprocessed output
# with the help of 'cpp_filter.py' and optionally 'GNU indent' or 'clang-format'.
#
ifeq ($(USE_GNU_INDENT),1)
C_FORMATER = | indent -st
else ifeq ($(USE_CLANG_FORMAT),1)
C_FORMATER = | clang-format -style=Mozilla -assume-filename=c
else
C_FORMATER =
endif
C_preprocess = $(CC) -E @$(CC).args $(1) | $(PYTHON) cpp_filter.py $(C_FORMATER) > $(2)
%.i: %.c FORCE cpp_filter.py config.h $(CC).args
$(call C_preprocess, $< $(EXTRA_CFLAGS), $@)
@echo
FORCE:
clean:
rm -f $(GENERATED) msvc-init.c $(CC).args gcc_dep.args
rm -f $(OBJ_DIR)/*
realclean vclean: clean
rm -f $(PROGRAMS) $(PROGRAMS:.exe=.map) $(PLUGIN_DLLs) $(PLUGIN_DLLs:.dll=.map)
rm -f $(EC_IMPORT) ../ettercap_c.dll ../ettercap_c.map .depend.Windows
rm -f $(MAN_PAGES) $(PDF_FILES) cpp_filter.py
- rmdir $(OBJ_DIR)
ifneq ($(CC),gcc)
rm -f $(PROGRAMS:.exe=.pdb) $(PLUGIN_DLLs:.dll=.pdb) vc1*.pdb ../ettercap_c.pdb
endif
#
# Return a list with all '-Dxx' first.
#
sorted_CFLAGS = $(filter -D%, $(1)) \
$(filter-out -D%, $(1))
$(CC).args: $(THIS_FILE)
$(call message_green,Generating $@...)
$(call make_resp_file, $@, $(call sorted_CFLAGS, $(CFLAGS)))
#
# GNU Make macro for compiling a .c-file:
# $(1): The .c-file and extra CFLAGS.
# $(2): The .$(O)-file.
#
Compile = $(call Compile_$(CC), $(1) $(EXTRA_CFLAGS), $(2))
Compile_gcc = gcc -c @gcc.args $(1) -o $(2)
Compile_cl = cl -c @cl.args $(1) -Fo./$(strip $(2))
Compile_clang-cl = clang-cl -c @clang-cl.args $(1) -Fo./$(strip $(2))
#
# Macro for building a .EXE from .$(O)-file(s):
# arg1, $(1): The name of the produced EXE.
# arg2, $(2): The .$(O) file(s), libraries and $(EXTRA_LDFLAGS).
#
define link_EXE
$(call message_green,Linking $(strip $(1)))
$(call link_EXE_$(CC), $(1), $(2) $(EXTRA_LDFLAGS))
@echo
endef
define link_EXE_cl
link -out:$(strip $(1)) $(LDFLAGS) $(2) > link.tmp
@cat link.tmp >> $(1:.exe=.map)
@rm -f link.tmp $(1:.exe=.exp) $(1:.exe=.lib)
endef
link_EXE_clang-cl = $(call link_EXE_cl, $(1), $(2))
link_EXE_gcc = gcc -o $(1) $(LDFLAGS) $(2) > $(1:.exe=.map)
#
# Macro for building a .DLL with an import-library from .$(O)-file(s):
# arg1, $(1): The name of the produced DLL.
# arg2, $(2): The .$(O) file(s), libraries and $(EXTRA_LDFLAGS).
# arg3, $(3): The import library.
#
define link_DLL
$(call message_green,Linking $(strip $(1)))
$(call link_DLL_$(CC), $(1), $(2) $(EXTRA_LDFLAGS), $(3))
@echo
endef
link_DLL_gcc = gcc -shared -o $(1) -Wl$(comma)--out-implib$(comma)$(strip $(3)) \
$(LDFLAGS) $(2) > $(1:.dll=.map)
define link_DLL_cl
link -dll -out:$(strip $(1)) -implib:$(strip $(3)) $(LDFLAGS) $(2) > link.tmp
@cat link.tmp >> $(1:.dll=.map)
@rm -f link.tmp $(3:.lib=.exp)
endef
link_DLL_clang-cl = $(call link_DLL_cl, $(1), $(2), $(3))
#
# Macro for building a plugin DLL from .c-file(s):
# arg1, $(1): The name of the produced DLL.
# arg2, $(2): The source file(s).
# arg3, $(3): Extra libs.
#
define build_plugin
$(call colour_msg,Compiling and linking$(LIGHT_YELLOW)$(1))
$(call make_resp_file, $(CC).args, $(CFLAGS) -Dint16=int16_t -Dint32=int32_t \
-DBUILDING_PLUGIN -DPLUGIN_FILE=\"$(strip $(word 1,$(2)))\")
$(call Compile_$(CC), $(2), $(OBJ_DIR)/$(notdir $(2:.c=.$(O))))
$(call link_plugin_$(CC), $(1), $(2), $(3))
@echo
endef
PLUGIN_LDFLAGS_gcc = -Wl$(comma)--exclude-all-symbols -Wl$(comma)--warn-duplicate-exports -export:plugin_load
#
# We need to export only 'plugin_load', but how to do that with 'ld'?
#
PLUGIN_LDFLAGS_gcc = -Wl$(comma)--export-all-symbols
link_plugin_gcc = $(call link_DLL_gcc, $(1), $(PLUGIN_LDFLAGS_gcc) \
$(OBJ_DIR)/$(notdir $(2:.c=.$(O))) \
$(EC_IMPORT) $(3), $(TMP_FOO_LIB_$(CC)))
#
# No MSVC/clang-cl plugin.DLL should need these libraries:
#
PLUGIN_LDFLAGS_cl = -nodefaultlib:oldnames.lib -nodefaultlib:uuid.lib \
-export:plugin_load
link_plugin_cl = $(call link_DLL_cl, $(1), $(PLUGIN_LDFLAGS_cl) \
$(OBJ_DIR)/$(notdir $(2:.c=.$(O))) \
$(EC_IMPORT) $(3), $(TMP_FOO_LIB_$(CC)))
link_plugin_clang-cl = $(call link_plugin_cl, $(1), $(2), $(3))
#
# Macro for creating a resource-file:
# arg1, $(1): The name of the .rc file.
# arg2, $(2): The name of the .res file.
#
define make_res
$(call make_res_$(CC), $(1), $(2))
@echo
endef
make_res_cl = rc $(RCFLAGS) -fo $(2) $(1)
make_res_clang-cl = rc $(RCFLAGS) -fo $(2) $(1)
make_res_gcc = windres $(RCFLAGS) -o $(2) $(1)
#
# Macro for creating a response-file:
# arg1, $(1): The name of the response file.
# arg2, $(2): The content for the response file.
#
# Note: Each word in $(2) is written to file $(1) on a
# separate line.
#
define make_resp_file
$(file > $(1))
$(foreach f, $(2), $(file >>$(1),$(strip $(f))) )
endef
define EC_CONFIG_H
#ifndef EC_CONFIG_H
#define EC_CONFIG_H
#define OS_WINDOWS
#define OS_SIZEOF_P 4
//#define GTK_DISABLE_DEPRECATED 1 /* Maybe not? */
#if defined(__MINGW32__)
#define OS_MINGW
#define CC_VERSION "MinGW"
#elif defined(__clang__)
#define OS_MSVC
#define CC_VERSION "clang-cl"
#elif defined(_MSC_VER)
#define OS_MSVC
#define CC_VERSION "MSVC"
#endif
#if !defined(RC_INVOKED) /* Rest of file */
#define WIN32_LEAN_AND_MEAN
#define HAVE_STRSIGNAL 1
#define HAVE_CTYPE_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_STRING_H 1
#define HAVE_STRUCT_TIMEVAL 1
#define HAVE_POLL 1 /* A fake one in os/ec_mingw.c */
#define HAVE_UTF8 1
#define HAVE_PLUGINS 1
#if (_WIN32_WINNT >= 0x600)
#define HAVE_STRUCT_POLLFD 1
#endif
/* Yacc / Flex stuff.
*/
#define YYMALLOC malloc
#define YYFREE free
#if defined(__MINGW32__)
#define HAVE_STRUCT_TIMEZONE 1
#define HAVE_STRUCT_TIMESPEC 1 /* MinGW 3.21 and later */
#elif defined(_MSC_VER)
/*
* Shut up about old stuff:
*/
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#undef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#undef _CRT_SECURE_NO_WARNINGS_GLOBALS
#define _CRT_SECURE_NO_WARNINGS_GLOBALS
#undef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#undef _CRT_NONSTDC_NO_WARNINGS
#define _CRT_NONSTDC_NO_WARNINGS
#undef _CRT_OBSOLETE_NO_WARNINGS
#define _CRT_OBSOLETE_NO_WARNINGS
#if defined(__clang__)
/*
* Use '-Wno-xx' in 'clang-cl.args' for better control of warnings.
*/
#else
/*
* Disable some extra warnings:
*/
#pragma warning (disable:4101 4244 4267)
#endif
#include <time.h>
/* Detect if 'Windows Kit + VCRuntime' is used.
*/
#if defined(_CRT_BEGIN_C_HEADER)
#define HAVE_STRUCT_TIMESPEC 1
#endif
#if defined(NTDDI_VERSION ) && (NTDDI_VERSION >= NTDDI_VISTA)
/*
* Already prototyped in <ws2tcpip.h>. But do they work on Win-XP?
*/
#define HAVE_INET_NTOP 1
#define HAVE_INET_PTON 1
#endif
/*
* Include this here before <bittypes.h> in WinPcap could mess things up.
*/
#include <inttypes.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <process.h>
#include <dirent.h> /* For MSVC/clang-cl this is in ../include/missing/msvc/ */
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
#ifndef S_IWUSR
#define S_IWUSR _S_IWRITE
#endif
#ifndef S_IRUSR
#define S_IRUSR _S_IREAD
#endif
#ifndef S_IRGRP
#define S_IRGRP 0
#endif
#ifndef S_IWGRP
#define S_IWGRP 0
#endif
#ifndef S_IROTH
#define S_IROTH 0
#endif
#ifndef S_IWOTH
#define S_IWOTH 0
#endif
#ifndef uid_t
#define uid_t int
#endif
#ifndef gid_t
#define gid_t int
#endif
#if defined(_MSC_VER) && defined(TYPES_DEFINED)
#define u_int8 uint8_t
#define u_int16 uint16_t
#define u_int32 uint32_t
#define u_int64 uint64_t
#define u_int8_t uint8_t
#define u_int16_t uint16_t
#define u_int32_t uint32_t
#define u_int64_t uint64_t
#endif
#if defined(__MINGW32__) // && defined(TYPES_DEFINED)
#include <stdint.h>
#include <inttypes.h>
#define u_int8 uint8_t
#define u_int16 uint16_t
#define u_int32 uint32_t
#define u_int64 uint64_t
#define u_int8_t uint8_t
#define u_int16_t uint16_t
#define u_int32_t uint32_t
#define u_int64_t uint64_t
#endif
#if defined(_MSC_VER) /* This means to 'clang-cl' too */
#define popen(_cmd, _mode) _popen (_cmd, _mode)
#define pclose(_file) _pclose (_file)
#define strcasecmp(_s1, _s2) _stricmp (_s1, _s2)
#define strncasecmp(_s1, _s2, _n) _strnicmp (_s1, _s2, _n)
/*
* Try to avoid linking with 'oldnames.lib' in the plugins, etterlog.exe and etterfilter.exe.
*/
#define strdup(s) _strdup (s) /* ec_dns_spoof.dll etc. */
#define execvp(file, argv) _execvp (file, argv) /* ec_remote_browser.dll */
#define close(fd) _close (fd) /* ec_sslstrip.dll */
#define read(fd, buf, len) _read (fd, buf, len) /* ec_sslstrip.dll */
#define write(fd, buf, len) _write (fd, buf, len) /* ec_sslstrip.dll */
#if defined(BUILDING_UTILS)
#define open(file, mode, perm) _open (file, mode, perm)
#define fileno(stream) _fileno (stream)
#define isatty(fd) _isatty (fd)
#define itoa(num, buf, radix) _itoa (num, buf, radix)
#endif
#if !defined(__clang__)
#define __func__ __FUNCTION__
#endif
#endif
#if defined(BUILDING_UTILS)
#define EC_API_EXTERN
#elif defined(BUILDING_PLUGIN)
#define EC_API_EXTERN extern __declspec(dllimport)
#else
#define EC_API_EXTERN extern __declspec(dllexport)
#endif
#if !defined(BUILDING_UTILS)
#if defined(LUA_BUILD_AS_DLL) && !defined(BUILDING_PLUGIN)
/*
* When using LUA.DLL (not using Lua statically), this will
* mark 'luaopen_ettercap_c()' etc. as '__declspec(dllexport)'.
* This is needed for the .lua-scripts to access our functions.
*/
#define LUA_LIB
#endif
/*
* Put this here for missing/getopt.c. Also in ec_os_mingw.h.
*/
EC_API_EXTERN char *ec_getenv_expand (const char *variable);
#define getenv(env) ec_getenv_expand (env)
#undef EC_API_EXTERN /* Gets defined to the same in <ec.h> */
#endif /* !BUILDING_UTILS */
/*
* Since Windows cannot have hardcoded paths (like Unix have), the
* 'ec_win_get_ec_dir()' (in os/ec_mingw.c) must return the full path
* of the running program (using GetModuleFileName()) at run-time.
* Thus:
*/
#define INSTALL_PREFIX ec_win_get_ec_dir()
#define INSTALL_EXECPREFIX ec_win_get_ec_dir()
#define INSTALL_SYSCONFDIR ec_win_get_ec_dir()
#define INSTALL_BINDIR ec_win_get_ec_dir()
#define INSTALL_LIBDIR "/lib"
/* The 'INSTALL_LIBDIR' and 'INSTALL_DATADIR' are used relative to
* ret-val of 'ec_win_get_ec_dir()'.
*/
/* Include this here to pull in all the 'u_intX_t' types.
*/
#define uint unsigned int
#include <pcap.h>
#if defined(__GNUC__)
#undef __argc /* In MinGW's stdlib.h */
#undef __argv
#include_next <getopt.h>
#else
/*
* A section for non-gcc builds.
*/
#if !defined(__clang__)
#define __attribute__(x)
#endif
#define __restrict
#endif
#if defined(BUILDING_PLUGIN) /* Do not add a 'DllMain()' in '$(OBJ_DIR)/ec_main.$(O)' */ && \
defined(PLUGIN_FILE)
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
{
/*
* It is nice to have some debug in plugins too.
*/
#if defined(DETAILED_DEBUG)
if (dwReason == DLL_PROCESS_ATTACH)
printf ("DEBUG: %s: DLL_PROCESS_ATTACH.\n", PLUGIN_FILE);
else if (dwReason == DLL_PROCESS_DETACH)
printf ("DEBUG: %s: DLL_PROCESS_DETACH.\n", PLUGIN_FILE);
#endif
(void) hinstDLL;
(void) lpvReserved;
return (TRUE);
}
#endif /* BUILDING_PLUGIN && PLUGIN_FILE */
#endif /* RC_INVOKED */
#endif /* EC_CONFIG_H */
endef
define EC_LUA_CONFIG_H
#ifndef EC_LUA_CONFIG_H
#define EC_LUA_CONFIG_H
#include <ec_file.h>
/* 'get_local_path()' return the <root>path + "/share/" + it's arg.
*/
#define INSTALL_LUA_ROOT get_local_path ("lua/")
#define INSTALL_LUA_INIT get_local_path ("lua/init.lua")
#define INSTALL_LUA_CORE get_local_path ("lua/")
#define INSTALL_LUA_SCRIPTS get_local_path ("lua/")
#endif /* EC_LUA_CONFIG_H */
endef
$(OBJ_DIR)/el_windows.$(O) \
$(OBJ_DIR)/ef_windows.$(O): os/ec_mingw.c
$(EL_OBJECTS) $(EF_OBJECTS): \
EXTRA_CFLAGS = -DBUILDING_UTILS
ifneq ($(CC),gcc)
msvc-init.c: os/ec_mingw.c
endif
#
# Generate a file with a '$(2) Warning header'.
# arg1, $(1): The name of the file.
# arg2, $(2): The comment start
#
define Generate
$(call message_green,Generating $(strip $(1))...)
$(file > $(1), $(2) This file been generated by $(realpath $(THIS_FILE)))
$(file >> $(1), $(2) at $(DATE).)
$(file >> $(1), $(2) DO NOT EDIT. YOUR CHANGES WILL BE LOST.)
$(file >> $(1), $(2))
endef
#
# The Windows code from "os/ec_mingw.c" needed by
# etterfilter.exe and etterlog.exe
#
define eX_windows_c
#include <ec.h>
#undef BUILDING_PLUGIN
#define BUILDING_PLUGIN
#undef EC_API_EXTERN
#define EC_API_EXTERN
#include "os/ec_mingw.c"
endef
ef_windows.c: $(MDEPEND)
$(call Generate, $@, //)
$(file >> $@, $(eX_windows_c))
el_windows.c: $(MDEPEND)
$(call Generate, $@, //)
$(file >> $@, $(eX_windows_c))
config.h: $(MDEPEND)
$(call Generate, $@, //)
$(file >> $@, $(EC_CONFIG_H))
touch -t 200001010101 $@
lua/ec_lua_config.h: $(MDEPEND)
$(call Generate, $@, //)
$(file >> $@, $(EC_LUA_CONFIG_H))
lua/share/init.lua: lua/share/init.lua.in $(MDEPEND)
$(call Generate, $@, --)
sed < $< -e 's|@INSTALL_LUA_CORE@|./share/lua|g' \
-e 's|@INSTALL_LUA_LIBS@|./share/lua|g' \
-e 's|@INSTALL_LUA_SCRIPTS@|./share/lua|g' \
-e 's|@INSTALL_LUA_THIRD_PARTY@|./share/lua|g' >> $@
cpp_filter.py: $(THIS_FILE)
$(call Generate, $@, #)
$(file >> $@,from __future__ import print_function)
$(file >> $@,if 1:)
$(file >> $@,$(CPP_FILTER_PY))
define CPP_FILTER_PY
import sys, os
try:
import ntpath
except ImportError as e:
print ("Failed to import ntpath: %s" % e)
sys.exit(1)
def _win32_abspath (path):
path = ntpath.abspath (path)
return path.replace ('\\', '/')
def skip_cwd (s1, s2):
''' Skip the leading part that is in common with s1 and s2
'''
i = 0
while i < len(s1) and s1[i] == s2[i]:
i += 1
return s2[i:]
cwd = _win32_abspath (os.getcwd()) + '/'
last_line = '??'
last_fname = '??'
empty_lines = 0
while True:
line = sys.stdin.readline()
if not line:
break
if line.startswith('\n') or line.startswith('\r'):
empty_lines += 1
continue
# print ("orig: \"%s\"" % line)
line = line.replace ("\\\\", "/")
fname = None
quote = line.find ('\"')
if line.startswith("#line ") and quote > 0:
fname = _win32_abspath (line[quote:])
last_fname = fname
if line.strip() != '' and last_line != '':
if fname is None or fname != last_fname:
print (line, end="")
if line.strip() == '}': # Print a newline after a function
print ("")
last_line = line
if empty_lines > 0:
sys.stderr.write ("Removed %d empty lines." % empty_lines)
endef
$(OBJ_DIR)/ncurses.h: $(THIS_FILE)
$(call Generate, $@, //)
$(file >> $@,$(EC_NCURSES_H))
define EC_NCURSES_H
#undef HAVE_CONFIG_H
#define HAVE_TYPE_CHTYPE 1
#define HAVE_BEEP 1
#define HAVE_ERASECHAR 1
#define HAVE_KILLCHAR 1
#define HAVE_ADDCHNSTR 1
#define HAVE_STRERROR 1
#include "$(NCURSES_ROOT)/td_lib/include/td_curse.h"
#define HAVE_CONFIG_H
#ifndef KEY_RESIZE
#define KEY_RESIZE -100
#endif
#ifndef KEY_MAX
#define KEY_MAX 16
#endif
#ifndef KEY_EXIT
#define KEY_EXIT 0551
#endif
#ifndef KEY_BACKSPACE
#define KEY_BACKSPACE 0407
#endif
#ifndef KEY_DC
#define KEY_DC 0512
#endif
#ifndef BUTTON1_DOUBLE_CLICKED
#define BUTTON1_DOUBLE_CLICKED 000000000010L
#endif
bool wenclose (const WINDOW *win, int y, int x);
endef
#
# MSVC/clang-cl only section.
# 'touch' these files so that make doesn't get overworked.
#
$(addprefix ../include/missing/msvc/, strings.h unistd.h sys/param.h sys/time.h): dirs
$(call Generate, $@, //)
@echo '/* Dummy header for MSVC/clang-cl */' >> $@
touch -t 200001010101 $@
dirs:
- mkdir --parents ../include/missing/msvc/sys
#
# Since MSVC has no support for '__attribute__((constructor))', we must
# generate a list of functions to be called from 'ec_msvc_init()'.
#
# Todo? Use this hack:
#
# /* http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc
# */
# #if defined(__GNUC__)
# #define INITIALIZER(f) \
# static void f (void) __attribute__((constructor)); \
# static void f (void)
#
# #else
# #pragma section (".CRT$$XCU", read)
# #define INITIALIZER(f) \
# static void __cdecl f (void); \
# __declspec (allocate(".CRT$$XCU")) void (*f ##_) (void) = f; \
# __pragma (comment(linker,"/include: _" #f "_")) \
# static void f (void)
# #endif
#
# INITIALIZER (do_library_init)
# {
# ...
# }
#
MSVC_CTORS = $(shell grep --no-filename 'void __init .*(void)$$' $(EC_LIB_SRC) | \
sed -e's/void __init //' -e's/(void)//' )
msvc-init.c: $(MDEPEND)
$(call Generate, $@, //)
$(file >> $@, #ifndef ETTERCAP_OS_MINGW_H)
$(file >> $@, #error Include and compile this inside os/ec_mingw.c only.)
$(file >> $@, #endif)
$(file >> $@,)
@$(foreach ctor, $(MSVC_CTORS), \
$(file >> $@, INIT_DECODER ($(ctor)); ))
test_ctor:
$(call colour_msg,$(LIGHT_RED)MSVC_CTORS:)
@$(foreach ctor, $(MSVC_CTORS), \
echo -e " $(LIGHT_GREEN)$(ctor)()\e[0m" ; )
#
# These export are needed in some of the .lua scripts via the FFI interface.
# Ref: lua/share/core/ettercap_ffi.lua
#
# But it would be tricky to trampoline over to the ws2_32.dll functions.
# Therefore just export them as aliases for 'swap16()' and 'swap32()' defined
# in 'ec_mingw.c'.
#
extra-exports.def: $(THIS_FILE)
$(call Generate, $@, ;)
$(file >> $@, EXPORTS)
$(file >> $@, ntohs = swap16)
$(file >> $@, ntohl = swap32)
$(file >> $@, htohs = swap16)
$(file >> $@, htonl = swap32)
#
# Create dependencies
#
DEP_REPLACE = sed -e 's|\(.*\)\.o: |\n$$(OBJ_DIR)\/\1.$$(O): |' \
-e 's|$(LIBCURL_ROOT)|$$(LIBCURL_ROOT)|g' \
-e 's|$(GEOIP_ROOT)|$$(GEOIP_ROOT)|g' \
-e 's|$(GTK_ROOT)|$$(GTK_ROOT)|g' \
-e 's|$(ICONV_ROOT)|$$(ICONV_ROOT)|g' \
-e 's|$(LIBNET_ROOT)|$$(LIBNET_ROOT)|g' \
-e 's|$(LUAJIT_ROOT)|$$(LUAJIT_ROOT)|g' \
-e 's|$(OPENSSL_ROOT)|$$(OPENSSL_ROOT)|g' \
-e 's|$(PCAP_ROOT)|$$(PCAP_ROOT)|g' \
-e 's|$(PCRE_ROOT)|$$(PCRE_ROOT)|g' \
-e 's|$(PTHREADS_ROOT)|$$(PTHREADS_ROOT)|g' \
-e 's|$(NCURSES_ROOT)|$$(NCURSES_ROOT)|g' \
-e 's|$(REGEX_ROOT)|$$(REGEX_ROOT)|g' \
-e 's|$(ZLIB_ROOT)|$$(ZLIB_ROOT)|g'
depend: check_stuff $(GENERATED)
$(call Generate, .depend.Windows, #)
$(call make_resp_file, gcc_dep.args, $(filter -D% -I%, $(CFLAGS)))
gcc -MM @gcc_dep.args $(MAIN_SRC) $(EC_LIB_SRC) $(EF_SOURCES) $(EL_SOURCES) | $(DEP_REPLACE) >> .depend.Windows
gcc -MM @gcc_dep.args -DBUILDING_PLUGIN $(PLUGIN_SRC) | $(DEP_REPLACE) >> .depend.Windows
ifeq ($(MAKECMDGOALS),depend)
$(info Ignoring .depend.Windows now)
else
-include .depend.Windows
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment