forked from Samsung/ADBI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
206 lines (151 loc) · 5.75 KB
/
Makefile
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
########################################################################################################################
#
# This is the main Makefile for adbiserver. See docs/BUILDING for a building instructions.
#
########################################################################################################################
ARCH ?= arm64
# Set compiler path
SELF_DIR := $(PWD)
# Multiple toolchains
TOOLCHAINDIRv7 ?= $(SELF_DIR)/toolchain/
PREFIXv7 ?= $(patsubst $(TOOLCHAINDIRv7)/bin/%gcc,%, $(wildcard $(TOOLCHAINDIRv7)/bin/*-gcc))
CCv7 := $(TOOLCHAINDIRv7)/bin/$(PREFIXv7)gcc
TOOLCHAINDIRv8 ?= $(SELF_DIR)/toolchain64/
PREFIXv8 ?= $(patsubst $(TOOLCHAINDIRv8)/bin/%gcc,%, $(wildcard $(TOOLCHAINDIRv8)/bin/*-gcc))
CCv8 := $(TOOLCHAINDIRv8)/bin/$(PREFIXv8)gcc
ifeq ($(ARCH),arm64)
TOOLCHAINDIR := $(TOOLCHAINDIRv8)
PREFIX := $(PREFIXv8)
CC := $(CCv8)
else
TOOLCHAINDIR := $(TOOLCHAINDIRv7)
PREFIX := $(PREFIXv7)
CC := $(CCv7)
endif
# export CCs for sub-make
export CC
export CCv7
export CCv8
########################################################################################################################
ifeq ($(ARCH),arm64)
LIBS = lib/asdd/libasdd64.a lib/capstone/libcapstone.a
INCDIRS = lib/asdd/include lib/capstone/include
CFLAGS += -Wno-missing-braces
CPPFLAGS += -DEXEC_RESTOP
# Unbelieveble things are happen on Galaxy S6 without -fomit-frame-pointer
# or with -O3 while tracing multiple processes
CFLAGS += -fomit-frame-pointer
CFLAGS += -mfix-cortex-a53-843419 -mfix-cortex-a53-835769
# Uncomment to use x16 register in bl instruction trampoline.
# Use of x16 register will save one jump (return jump), it may
# be important if relative jump is not siutable. But it increses
# trampoline size by 12 bytes and may cause problems if x16 is in
# use between bl innstructions (forbidden by AAPCS).
#CPPFLAGS += -DUSE_X16_IN_BL_TRAMPOLINE
else
# Disable executable stack warnings (however, it seems that the linker ignores this anyway...)
LDFLAGS += -Wl,--no-warn-execstack
CPPFLAGS += -DEXEC_RESTOP
LIBS = lib/asdd/libasdd.a
INCDIRS = lib/asdd/include
endif
# Include dirs
CPPFLAGS += $(foreach dir,$(INCDIRS),-I$(dir))
# Warnings
CFLAGS += -Wall -Wextra
# Use the gnu99 C dialect
CFLAGS += --std=gnu99
CFLAGS += -fPIE
LDFLAGS += -pie
# Remove unused symbols
CFLAGS += -fdata-sections -ffunction-sections
#LDFLAGS += --gc-sections
CPPFLAGS += -iquote$(PWD)
# Generate debug symbols
#CFLAGS += -O0 -ggdb3
# Automatically generate dependency files
CPPFLAGS += -MD
# Preinclude common.h header
CPPFLAGS += -include util/common.h
CPPFLAGS += -DBIONIC_VSNPRINTF_WORKAROUND
# Link statically with libraries. This is not necessary, but useful for easier debugging.
static: LDFLAGS += -static
# Force executable stack (adbiserver needs this for nested functions).
LDFLAGS += -Wl,-z,execstack
########################################################################################################################
ARCHDIR := arch/$(ARCH)
#ifneq (,$(filter $(ARCH),arm arm64))
# ARCHCDIR := arch/arm_common
#endif
INCDIRS += $(ARCHDIR)/include
SRCDIRS += communication \
configuration \
injectable \
injection \
process \
procutil \
tracepoint \
util \
$(ARCHDIR) \
.
SUBMAKE := ./inj/adbi_mmap \
./inj/adbi \
./inj/adbi_munmap \
./arch/$(ARCH)/templates \
./adbilog
INJECTABLES := inj/adbi/adbi.inj.c inj/adbi_mmap/adbi_mmap.inj.c inj/adbi_munmap/adbi_munmap.inj.c
HANDLERSRC := $(ARCHDIR)/templates/templates.c
HANDLERHEAD := $(ARCHDIR)/templates/templates.h
SUPSRC := $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c))
GENSRC := $(INJECTABLES) $(HANDLERSRC)
GENHEAD := $(HANDLERHEAD)
OUT := adbiserver
all: $(OUT)
########################################################################################################################
SRC := $(SUPSRC) $(GENSRC)
GEN := $(GENSRC) $(GENHEAD)
OBJ := $(SRC:.c=.o)
DEP := $(SRC:.c=.d)
########################################################################################################################
profile: CPPFLAGS += -DADBI_PROFILING
profile: CFLAGS += -pg
profile: PROFOBJ := profiler.o
profile: all
########################################################################################################################
$(SUBMAKE):
$(MAKE) -C $@
SUBMAKE_CLEAN := $(addsuffix /clean, $(SUBMAKE))
$(SUBMAKE_CLEAN):
@echo " Clean up $(dir $@)..."
$(MAKE) -C $(dir $@) clean
########################################################################################################################
$(SUPSRC) : $(SUBMAKE)
$(OUT): $(OBJ) $(PROFOBJ) $(LIBS)
@echo " [LD] $@"
$(CC) $(LDFLAGS) -o $@ $^ $(PROFOBJ)
find-unused: $(OBJ)
./unused-syms $(OBJ)
$(OBJ): %.o : %.c
@echo " [CC] $@"
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(HANDLERHEAD): $(HANDLERSRC)
$(SUPSRC): $(HANDLERHEAD)
$(HANDLERSRC) $(INJECTABLES): $(SUBMAKE)
clean: $(SUBMAKE_CLEAN)
@echo " Clean up main directory..."
$(RM) $(OBJ) $(DEP) $(OUT)
########################################################################################################################
push: $(OUT)
adb push $(OUT) /data
run: push
adb shell /data/$(OUT)
debug: push
adb shell gdbserver tcp:7777 /data/$(OUT)
########################################################################################################################
toolchain: toolchain.7z
7z x -bd toolchain.7z
########################################################################################################################
.PHONY : all clean $(SUBMAKE) $(SUBMAKE_CLEAN) push run debug toolchain
.SILENT :
########################################################################################################################
-include $(DEP)