Skip to content

Commit

Permalink
Add UnZip static PIE build
Browse files Browse the repository at this point in the history
Co-authored-by: Jumarea Stefan <[email protected]>

Signed-off-by: anindya_sen <[email protected]>
  • Loading branch information
anindyasen committed Oct 21, 2022
1 parent 5974451 commit 5f8c941
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
22 changes: 22 additions & 0 deletions unzip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build unzip as static PIE

Build the [unzip](https://infozip.sourceforge.net/UnZip.html) application as static PIE ELF running on Linux.

## Requirements

Make sure the following packages are installed:

* GCC
* GNU Make

## Build

The `unzip` 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, extract, patch and build the code to generate the static PIE unzip binary.

## Running

```bash
./unzip extract.zip
```
46 changes: 46 additions & 0 deletions unzip/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

APP=unzip
DIR=${APP}60
ARCHIVE=${DIR}.tar.gz
URL=https://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!"
29 changes: 29 additions & 0 deletions unzip/patches/add-static-pie-flag.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/unix/Makefile b/unix/Makefile
index ab32270..e00aa7b 100644
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -53,6 +53,7 @@ CF = $(CFLAGS) $(CF_NOOPT)
LFLAGS1 =
LF = -o unzip$E $(LFLAGS1)
LF2 = -s
+LDFLAGS = -static-pie -static-libgcc

# UnZipSFX flags
SL = -o unzipsfx$E $(LFLAGS1)
@@ -280,13 +281,13 @@ unzipsdocs: unzips docs
# make utilities if default: change "unzip$E:" to "unzip$E:&"

unzip$E: $(OBJS) $(LIBBZ2) # add `&' for parallel makes
- $(LD) $(LF) -L$(IZ_BZIP2) $(LOBJS) $(L_BZ2) $(LF2)
+ $(LD) $(LF) -L$(IZ_BZIP2) $(LOBJS) $(L_BZ2) $(LF2) $(LDFLAGS)

unzipsfx$E: $(OBJX) # add `&' for parallel makes
- $(LD) $(SL) $(LOBJX) $(SL2)
+ $(LD) $(SL) $(LOBJX) $(SL2) $(LDFLAGS)

funzip$E: $(OBJF) # add `&' for parallel makes
- $(LD) $(FL) $(OBJF) $(FL2)
+ $(LD) $(FL) $(OBJF) $(FL2) $(LDFLAGS)

zipinfo$E: unzip$E # `&' is pointless here...
@echo\
Binary file added unzip/rootfs/extract.zip
Binary file not shown.
1 change: 1 addition & 0 deletions unzip/rootfs/tesfile1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a testfile used for compression using zip.
Binary file added unzip/unzip
Binary file not shown.

0 comments on commit 5f8c941

Please sign in to comment.