-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
72 lines (58 loc) · 1.93 KB
/
Copy pathMakefile
File metadata and controls
72 lines (58 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#
# Makefile for building the Windows x64 C++ Shellcode Template on Linux
# Requires: x86_64-w64-mingw32 toolchain and nasm
#
# --- Tools ---
CXX := x86_64-w64-mingw32-g++
ASM := nasm
LD := x86_64-w64-mingw32-ld
OBJCOPY := x86_64-w64-mingw32-objcopy
# --- Flags ---
CFLAGS := -c -Os -nostdlib -fno-asynchronous-unwind-tables -std=c++20
CFLAGS += -fno-ident -fpack-struct=8 -falign-functions=1 -s -w -mno-sse
CFLAGS += -ffunction-sections -falign-jumps=1 -falign-labels=1
CFLAGS += -Wl,-s,--no-seh,--enable-stdcall-fixup -masm=intel -fno-exceptions
CFLAGS += -fms-extensions -fPIC -Iinclude -fno-builtin -Wall -Wextra
ASMFLAGS := -f win64
LDFLAGS := -T linker/linker.ld
# --- Directories ---
SRC_DIR_CPP := src
SRC_DIR_ASM := src/asm
OBJ_DIR := obj
BIN_DIR := bin
# --- Sources and Outputs ---
CPP_SRCS := $(wildcard $(SRC_DIR_CPP)/*.cpp)
ASM_SRCS := $(wildcard $(SRC_DIR_ASM)/*.asm)
CPP_OBJS := $(patsubst $(SRC_DIR_CPP)/%.cpp, $(OBJ_DIR)/%.o, $(CPP_SRCS))
ASM_OBJS := $(patsubst $(SRC_DIR_ASM)/%.asm, $(OBJ_DIR)/%.o, $(ASM_SRCS))
OBJS := $(CPP_OBJS) $(ASM_OBJS)
TARGET_EXE := $(BIN_DIR)/shellcode.exe
TARGET_BIN := $(BIN_DIR)/shellcode.bin
# --- Rules ---
all: $(TARGET_BIN)
# Build binary shellcode from exe
$(TARGET_BIN): $(TARGET_EXE)
@mkdir -p $(BIN_DIR)
@echo "[+] Extracting raw shellcode -> $@"
@$(OBJCOPY) $< --dump-section .text=$@
@echo "[*] Success! Final shellcode is in $@"
# Link executable
$(TARGET_EXE): $(OBJS)
@mkdir -p $(BIN_DIR)
@echo "[+] Linking object files -> $@"
@$(LD) $(LDFLAGS) -o $@ $^
# Compile C++ source files
$(OBJ_DIR)/%.o: $(SRC_DIR_CPP)/%.cpp
@mkdir -p $(OBJ_DIR)
@echo "[+] Compiling C++ -> $@"
@$(CXX) $(CFLAGS) -o $@ $<
# Assemble ASM source files
$(OBJ_DIR)/%.o: $(SRC_DIR_ASM)/%.asm
@mkdir -p $(OBJ_DIR)
@echo "[+] Assembling ASM -> $@"
@$(ASM) $(ASMFLAGS) $< -o $@
# Clean
clean:
@echo "[+] Cleaning up build files"
@rm -rf $(OBJ_DIR) $(BIN_DIR)
.PHONY: all clean