Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UnZip static PIE build #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
anindyasen marked this conversation as resolved.
Show resolved Hide resolved

# 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.