-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
143 lines (136 loc) · 3.77 KB
/
build.sh
File metadata and controls
143 lines (136 loc) · 3.77 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
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
#!/usr/bin/env sh
main() {
CC32="i686-w64-mingw32-gcc"
CC64="x86_64-w64-mingw32-gcc"
CC32="$CC32 -msse2"
CC64="$CC64 -mcmodel=small"
WARNING_FLAGS="-Wall -Wextra -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-unused-function -Wno-unused-value -Wno-unused-variable -Wno-array-bounds"
CC_FLAGS="-Os -fomit-frame-pointer -fno-ident -nostdlib -ffunction-sections -fdata-sections -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables $WARNING_FLAGS -D _UNICODE -D UNICODE -D __USE_MINGW_ANSI_STDIO=0"
LIB_FLAGS="-lkernel32 -luser32 -ladvapi32" # Add your libraries here
LINK_FLAGS="$LIB_FLAGS -Ltools/link -lgcc -Wl,--gc-sections,--section-alignment,16,--file-alignment,16,--image-base,0,-T,linker.ld"
LINK_FLAGS32="-l:msvcrt.x86.lib $LINK_FLAGS,-e,_Entry"
LINK_FLAGS64="-l:msvcrt.x64.lib $LINK_FLAGS,-e,Entry"
mkdir -p bin
$CC32 src/startup.c src/main.c $CC_FLAGS -o bin/myshellcode.x86.exe $LINK_FLAGS32 &
$CC64 src/startup.c src/main.c $CC_FLAGS -o bin/myshellcode.x64.exe $LINK_FLAGS64 &
wait
gcc tools/c2sc.c -otools/c2sc
./tools/c2sc bh bin/myshellcode.x86.exe bin/myshellcode.x64.exe
mv myshellcode_*.bin myshellcode_*.h bin
rm tools/c2sc bin/myshellcode.*.exe
}
create_linker_ld() {
cat << 'EOF' > linker.ld
SECTIONS
{
/* Make the virtual address and file offset synced if the alignment is
lower than the target page size. */
. = SIZEOF_HEADERS;
. = ALIGN(__section_alignment__);
.text __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :
{
/* .text */
*(.text.entry)
*(.text)
*(SORT(.text$*))
*(.text.*)
*(.gnu.linkonce.t.*)
/* IAT */
__IAT_start__ = .;
KEEP (SORT(*)(.idata$5))
__IAT_end__ = .;
/* .rdata */
*(.rdata)
*(SORT(.rdata$*))
/* .data */
__data_start__ = . ;
*(.data)
*(.data2)
*(SORT(.data$*))
__data_end__ = . ;
}
.idata BLOCK(__section_alignment__) :
{
/* This cannot currently be handled with grouped sections.
See pe.em:sort_sections. */
KEEP (SORT(*)(.idata$2))
KEEP (SORT(*)(.idata$3))
/* These zeroes mark the end of the import list. */
LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
KEEP (SORT(*)(.idata$4))
KEEP (SORT(*)(.idata$6))
KEEP (SORT(*)(.idata$7))
}
.eh_frame BLOCK(__section_alignment__) :
{
KEEP (*(.eh_frame*))
}
.pdata BLOCK(__section_alignment__) :
{
KEEP(*(.pdata*))
}
.xdata BLOCK(__section_alignment__) :
{
KEEP(*(.xdata*))
}
.bss BLOCK(__section_alignment__) :
{
__bss_start__ = . ;
*(.bss)
*(COMMON)
__bss_end__ = . ;
}
.edata BLOCK(__section_alignment__) :
{
*(.edata)
}
/DISCARD/ :
{
*(.debug$S)
*(.debug$T)
*(.debug$F)
*(.drectve)
*(.note.GNU-stack)
*(.gnu.lto_*)
}
.CRT BLOCK(__section_alignment__) :
{
___crt_xc_start__ = . ;
KEEP (*(SORT(.CRT$XC*))) /* C initialization */
___crt_xc_end__ = . ;
___crt_xi_start__ = . ;
KEEP (*(SORT(.CRT$XI*))) /* C++ initialization */
___crt_xi_end__ = . ;
___crt_xl_start__ = . ;
KEEP (*(SORT(.CRT$XL*))) /* TLS callbacks */
/* ___crt_xl_end__ is defined in the TLS Directory support code */
___crt_xp_start__ = . ;
KEEP (*(SORT(.CRT$XP*))) /* Pre-termination */
___crt_xp_end__ = . ;
___crt_xt_start__ = . ;
KEEP (*(SORT(.CRT$XT*))) /* Termination */
___crt_xt_end__ = . ;
KEEP (*(SORT_NONE(.init)))
KEEP (*(.ctors));
KEEP (*(.ctor));
KEEP (*(SORT_BY_NAME(.ctors.*)));
KEEP (*(.dtors));
KEEP (*(.dtor));
KEEP (*(SORT_BY_NAME(.dtors.*)));
KEEP (*(SORT_NONE(.fini)))
}
.rsrc BLOCK(__section_alignment__) : SUBALIGN(4)
{
KEEP (*(.rsrc))
KEEP (*(.rsrc$*))
}
.reloc BLOCK(__section_alignment__) :
{
*(.reloc)
}
}
EOF
}
create_linker_ld
main
rm linker.ld