2016-08-24 06:49:14 +00:00
|
|
|
CC ?= gcc
|
|
|
|
|
2016-11-26 09:20:33 +00:00
|
|
|
CFLAGS := $(shell pkg-config --cflags python-2.7) -I../lzma -fPIC $(CFLAGS_EXTRA)
|
2016-10-22 20:02:14 +00:00
|
|
|
LDFLAGS := -lpthread -ldl -fPIC $(LDFLAGS_EXTRA) -Wl,-Bstatic -lz -Wl,-Bdynamic
|
2016-10-20 20:16:53 +00:00
|
|
|
PFLAGS := -O
|
2016-08-23 16:48:10 +00:00
|
|
|
PIE ?= -pie
|
2016-08-22 22:53:26 +00:00
|
|
|
|
2016-08-24 06:49:14 +00:00
|
|
|
LIBPYTHON ?= $(shell ldconfig -p | awk '/libpython2.7.so/{print $$4}' | head -n 1)
|
|
|
|
|
|
|
|
ARCH ?= $(shell file $(LIBPYTHON) | grep 32-bit >/dev/null && echo 32 || echo 64)
|
|
|
|
ifeq ($(ARCH),64)
|
|
|
|
NAME := 64
|
2016-08-22 22:53:26 +00:00
|
|
|
else
|
2016-08-24 06:49:14 +00:00
|
|
|
NAME := 86
|
2016-08-22 22:53:26 +00:00
|
|
|
endif
|
|
|
|
|
2016-08-24 06:49:14 +00:00
|
|
|
LINUX_INJECT_CFLAGS := -include debug.h -include fixes.h -Dmain=linux_inject_main
|
2016-08-23 16:48:10 +00:00
|
|
|
|
2016-08-22 22:53:26 +00:00
|
|
|
ifneq ($(DEBUG),)
|
2016-10-22 15:40:11 +00:00
|
|
|
DEBUG_ADD := -debug
|
2016-08-22 22:53:26 +00:00
|
|
|
CFLAGS += -DDEBUG -O0 -g
|
2016-08-28 11:29:02 +00:00
|
|
|
NAME := "$(NAME)d"
|
2016-08-22 22:53:26 +00:00
|
|
|
else
|
2016-10-22 20:02:14 +00:00
|
|
|
CFLAGS += -Os
|
2016-08-23 16:48:10 +00:00
|
|
|
LINUX_INJECT_CFLAGS += -Dprintf=dprint -Dfprintf=dfprint
|
2016-10-22 20:02:14 +00:00
|
|
|
LDFLAGS += -O1 -Wl,-s -Wl,-x -Wl,--gc-sections -Wl,--no-undefined
|
|
|
|
LDFLAGS += -Wl,-z,now -Wl,-z,combreloc -Wl,--enable-new-dtags
|
2016-08-23 16:48:10 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
PYTHON ?= python
|
|
|
|
TEMPLATE_OUTPUT_PATH ?= ../../pupy/payload_templates/
|
|
|
|
|
|
|
|
PYOBJS := _memimporter.o Python-dynload.o pupy_load.o pupy.o
|
2016-11-29 16:53:39 +00:00
|
|
|
COMMON_OBJS := list.o tmplibrary.o daemonize.o decompress.o LzmaDec.o
|
2016-08-23 16:48:10 +00:00
|
|
|
|
|
|
|
ifeq ($(ARCH),64)
|
|
|
|
COMMON_OBJS += linux-inject/inject-x86_64.o
|
|
|
|
else
|
|
|
|
COMMON_OBJS += linux-inject/inject-x86.o
|
2016-08-22 22:53:26 +00:00
|
|
|
endif
|
|
|
|
|
2016-08-23 16:48:10 +00:00
|
|
|
COMMON_OBJS += linux-inject/ptrace.o
|
|
|
|
COMMON_OBJS += linux-inject/utils.o
|
|
|
|
|
2016-08-24 06:49:14 +00:00
|
|
|
all: $(TEMPLATE_OUTPUT_PATH)/pupyx$(NAME).lin $(TEMPLATE_OUTPUT_PATH)/pupyx$(NAME).so
|
|
|
|
|
2016-11-29 16:53:39 +00:00
|
|
|
pupy.c: resources_library_compressed_string_txt.c
|
|
|
|
pupy_load.c: resources_bootloader_pyc.c resources_python27_so.c
|
|
|
|
|
2016-08-23 16:48:10 +00:00
|
|
|
import-tab.c import-tab.h: mktab.py
|
2016-10-20 20:16:53 +00:00
|
|
|
$(PYTHON) $(PFLAGS) $<
|
2016-08-23 16:48:10 +00:00
|
|
|
|
|
|
|
Python-dynload.o: Python-dynload.c import-tab.c import-tab.h
|
|
|
|
$(CC) -c -o $@ $< $(CFLAGS)
|
|
|
|
|
2016-11-26 09:20:33 +00:00
|
|
|
LzmaDec.o: ../lzma/LzmaDec.c
|
|
|
|
$(CC) -O3 -c -o $@ $<
|
|
|
|
|
2016-10-22 15:40:11 +00:00
|
|
|
resources/library_compressed_string.txt: ../gen_library_compressed_string.py resources/library.zip
|
|
|
|
$(PYTHON) $(PFLAGS) ../gen_library_compressed_string.py
|
2016-08-22 22:53:26 +00:00
|
|
|
|
2016-10-22 15:40:11 +00:00
|
|
|
resources_library_compressed_string_txt.c: ../gen_resource_header.py resources/library_compressed_string.txt resources/library.zip
|
|
|
|
$(PYTHON) $(PFLAGS) ../gen_resource_header.py resources/library_compressed_string.txt
|
2016-08-22 22:53:26 +00:00
|
|
|
|
2016-10-22 15:40:11 +00:00
|
|
|
resources/bootloader.pyc: ../gen_python_bootloader.py ../../pupy/packages/all/pupyimporter.py ../../pupy/pp.py
|
|
|
|
$(PYTHON) $(PFLAGS) ../gen_python_bootloader.py $(DEBUG_ADD)
|
2016-08-22 22:53:26 +00:00
|
|
|
|
2016-10-22 15:40:11 +00:00
|
|
|
resources_bootloader_pyc.c: ../gen_resource_header.py resources/bootloader.pyc
|
2016-10-20 20:16:53 +00:00
|
|
|
$(PYTHON) $(PFLAGS) $+
|
2016-08-22 22:53:26 +00:00
|
|
|
|
2016-08-23 16:48:10 +00:00
|
|
|
linux-inject/%.o: linux-inject/%.c
|
|
|
|
$(CC) -c $(LINUX_INJECT_CFLAGS) $(CFLAGS) -o $@ $<
|
|
|
|
|
2016-08-22 22:53:26 +00:00
|
|
|
resources/python27.so: $(LIBPYTHON)
|
2016-08-24 06:49:14 +00:00
|
|
|
cp -vf $< $@.tmp
|
2016-11-26 09:20:33 +00:00
|
|
|
-chmod 600 $@.tmp
|
2016-08-24 06:49:14 +00:00
|
|
|
-strip $@.tmp
|
2016-11-29 16:53:39 +00:00
|
|
|
mv $@.tmp $@
|
2016-08-24 06:49:14 +00:00
|
|
|
rm -f $@.tmp
|
2016-08-22 22:53:26 +00:00
|
|
|
|
2016-10-22 15:40:11 +00:00
|
|
|
resources/library.zip: ../build_library_zip.py ../additional_imports.py
|
2016-10-20 20:16:53 +00:00
|
|
|
$(PYTHON) $(PFLAGS) $<
|
2016-08-22 22:53:26 +00:00
|
|
|
|
2016-10-22 15:40:11 +00:00
|
|
|
resources_python27_so.c: ../gen_resource_header.py resources/python27.so
|
2016-10-20 20:16:53 +00:00
|
|
|
$(PYTHON) $(PFLAGS) $+
|
2016-08-22 22:53:26 +00:00
|
|
|
|
2016-08-24 06:49:14 +00:00
|
|
|
$(TEMPLATE_OUTPUT_PATH)/pupyx$(NAME).lin: main_exe.o $(PYOBJS) $(COMMON_OBJS)
|
2016-08-23 16:48:10 +00:00
|
|
|
$(CC) $(PIE) $+ -o $@ $(LDFLAGS)
|
2016-08-22 22:53:26 +00:00
|
|
|
|
2016-08-24 06:49:14 +00:00
|
|
|
$(TEMPLATE_OUTPUT_PATH)/pupyx$(NAME).so: main_so.o $(PYOBJS) $(COMMON_OBJS)
|
2016-08-22 22:53:26 +00:00
|
|
|
$(CC) -shared $+ -o $@ $(LDFLAGS)
|
|
|
|
|
2016-08-24 06:49:14 +00:00
|
|
|
.PHONY: clean all
|
2016-08-22 22:53:26 +00:00
|
|
|
|
|
|
|
clean:
|
2016-10-20 20:16:53 +00:00
|
|
|
find -name "*.pyc" | xargs rm -f
|
|
|
|
find -name "*.pyo" | xargs rm -f
|
|
|
|
find -name "*.o" | xargs rm -f
|
2016-11-26 09:20:33 +00:00
|
|
|
rm -f $(COMMON_OBJS)
|
2016-08-22 22:53:26 +00:00
|
|
|
rm -f pupy pupy.so
|
|
|
|
rm -f resources/library.zip
|
|
|
|
rm -f resources/*.so
|
|
|
|
rm -f resources/*.txt
|
2016-08-24 06:49:14 +00:00
|
|
|
rm -f resources_*.c
|
|
|
|
rm -f import-tab.c
|
|
|
|
rm -f import-tab.h
|
|
|
|
|
|
|
|
$(COMMON_OBJS) $(PYOBJS): import-tab.h
|
|
|
|
|