-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: anindya_sen <[email protected]>
- Loading branch information
1 parent
5974451
commit 03709ab
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Build zip as static PIE | ||
|
||
Build the [zip](https://infozip.sourceforge.net/Zip.html) application as a static PIE ELF running on Linux. | ||
|
||
## Requirements | ||
|
||
Make sure the following packages are installed: | ||
|
||
* GCC | ||
* GNU Make | ||
|
||
## Build | ||
|
||
The `zip` static PIE ELF file is located in the current directory. | ||
In order to rebuild it you have to run the `build.sh` bash script. | ||
The `build.sh` script will download the `zip` source code, extract it, patch it with the patches present in the `patch/` directory then build the code to generate the static PIE zip binary. | ||
|
||
## Running | ||
|
||
```bash | ||
./zip 1.zip rootfs/testfile1 rootfs/testfile2 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
APP=zip | ||
DIR=${APP}30 | ||
ARCHIVE=${DIR}.tar.gz | ||
URL=http://downloads.sourceforge.net/infozip/${ARCHIVE} | ||
|
||
# Clean up | ||
rm -rf ${ARCHIVE} | ||
rm -rf ${DIR} | ||
|
||
echo -n "Downloading ${APP} sources ... " | ||
wget -q ${URL} | ||
if test $? -ne 0; then | ||
echo "" | ||
echo "Unable to download ${APP} from ${URL}" | ||
exit 1 | ||
fi | ||
echo "DONE" | ||
|
||
echo "" | ||
echo -n "Unpacking ${APP} ... " | ||
tar -zxvf ${ARCHIVE} | ||
if test $? -ne 0; then | ||
echo "" | ||
echo "Unable to extract ${APP}" | ||
exit 1 | ||
fi | ||
echo "DONE" | ||
|
||
echo "" | ||
echo -n "Building ${APP} ... " | ||
echo "" | ||
pushd ${DIR} > /dev/null 2>&1 || exit 1 | ||
|
||
patch -p1 < ../patches/add-static-pie-flag.patch | ||
make -f unix/Makefile generic | ||
|
||
popd > /dev/null 2>&1 || exit 1 | ||
|
||
cp ${DIR}/${APP} . | ||
|
||
rm -rf ${DIR} | ||
rm -rf ${ARCHIVE} | ||
|
||
echo -n "Build complete!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
diff --git a/unix/Makefile b/unix/Makefile | ||
index abd0c44..d3fe778 100644 | ||
--- a/unix/Makefile | ||
+++ b/unix/Makefile | ||
@@ -61,6 +61,7 @@ CFLAGS_NOOPT = -I. -DUNIX $(LOCAL_ZIP) | ||
CFLAGS = -O2 $(CFLAGS_NOOPT) | ||
LFLAGS1 = | ||
LFLAGS2 = -s | ||
+LDFLAGS = -static-pie -static-libgcc | ||
|
||
# object file lists | ||
OBJZ = zip.o zipfile.o zipup.o fileio.o util.o globals.o crypt.o ttyio.o \ | ||
@@ -125,13 +126,13 @@ zips: $(ZIPS) | ||
zipsman: $(ZIPS) $(ZIPMANUALs) | ||
|
||
zip$E: $(OBJZ) $(OBJI) $(OBJA) $(LIB_BZ) | ||
- $(BIND) -o zip$E $(LFLAGS1) $(OBJZ) $(OBJI) $(OBJA) $(LFLAGS2) | ||
+ $(BIND) -o zip$E $(LFLAGS1) $(OBJZ) $(OBJI) $(OBJA) $(LFLAGS2) $(LDFLAGS) | ||
zipnote$E: $(OBJN) | ||
- $(BIND) -o zipnote$E $(LFLAGS1) $(OBJN) $(LFLAGS2) | ||
+ $(BIND) -o zipnote$E $(LFLAGS1) $(OBJN) $(LFLAGS2) $(LDFLAGS) | ||
zipcloak$E: $(OBJC) $(OCRCTB) | ||
- $(BIND) -o zipcloak$E $(LFLAGS1) $(OBJC) $(LFLAGS2) | ||
+ $(BIND) -o zipcloak$E $(LFLAGS1) $(OBJC) $(LFLAGS2) $(LDFLAGS) | ||
zipsplit$E: $(OBJS) | ||
- $(BIND) -o zipsplit$E $(LFLAGS1) $(OBJS) $(LFLAGS2) | ||
+ $(BIND) -o zipsplit$E $(LFLAGS1) $(OBJS) $(LFLAGS2) $(LDFLAGS) | ||
|
||
$(ZIPMANUAL): man/zip.1 | ||
nroff -man man/zip.1 | col -bx | uniq > $(ZIPMANUAL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a testfile1 for testing zip application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a testfile2 for testing zip application |