Skip to content

Commit

Permalink
Add Zip static PIE build
Browse files Browse the repository at this point in the history
Signed-off-by: anindya_sen <[email protected]>
  • Loading branch information
anindyasen committed Oct 21, 2022
1 parent 5974451 commit 03709ab
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
22 changes: 22 additions & 0 deletions zip/README.md
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
```
46 changes: 46 additions & 0 deletions zip/build.sh
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!"
30 changes: 30 additions & 0 deletions zip/patches/add-static-pie-flag.patch
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)
1 change: 1 addition & 0 deletions zip/rootfs/testfile1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a testfile1 for testing zip application
1 change: 1 addition & 0 deletions zip/rootfs/testfile2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a testfile2 for testing zip application
Binary file added zip/zip
Binary file not shown.

0 comments on commit 03709ab

Please sign in to comment.