Skip to content

Commit

Permalink
Merge d07affd into 5e232ec
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr authored Jun 19, 2020
2 parents 5e232ec + d07affd commit f24e01d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "zstd"]
path = zstd
url = https://github.com/facebook/zstd
[submodule "minlzma"]
path = minlzma
url = https://github.com/dimkr/minlzma
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ papaw consists of a small executable (~15-40K) containing a decompressor. It ext

The payload executable is extracted to a temporary file. When running as root, this is done by mounting a tmpfs file system and lazily unmounting it before the extraction.

## Supported Compression Algorithms
## Supported Compression Algorithms and Implementations

* LZMA2, using [XZ Embedded](https://tukaani.org/xz/embedded.html) (the default)
* LZMA1, using the [LZMA SDK](https://www.7-zip.org/sdk.html) decompressor
* LZMA2, using [Minimal LZMA](https://github.com/ionescu007/minlzma)
* Zstandard, using the [zstd](https://github.com/facebook/zstd) decompressor
* Deflate, using [miniz](https://github.com/richgel999/miniz)

Expand Down
4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ steps:
displayName: 'LAMA1 Test'
- script: docker run --privileged -w /root/papaw -v `pwd`:/root/papaw $(imageName) ./ci/build.sh lzma
displayName: 'LAMA1 Build'
- script: docker run --privileged -w /root/papaw -v `pwd`:/root/papaw $(imageName) ./ci/test.sh minlzma
displayName: 'Minimal LAMA Test'
- script: docker run --privileged -w /root/papaw -v `pwd`:/root/papaw $(imageName) ./ci/build.sh minlzma
displayName: 'Minimal LAMA Build'
- script: docker run --privileged -w /root/papaw -v `pwd`:/root/papaw $(imageName) ./ci/test.sh zstd
displayName: 'Zstandard Test'
- script: docker run --privileged -w /root/papaw -v `pwd`:/root/papaw $(imageName) ./ci/build.sh zstd
Expand Down
6 changes: 5 additions & 1 deletion ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ test x`./build-$1/test_crasher` = x
test -z "`ls /tmp/core* 2>/dev/null`"

# make sure there are no compression-related strings
test -z "`strings -a ./build-$1/test_putser | grep -i -e $1 -e miniz -e zlib -e zstandard -e zstd -e huff -e rle -e copy -e license -e papaw`"
DESTDIR=out ninja -C build-$1 install
for i in ./build-$1/out/usr/local/bin/papaw ./build-$1/test_putser
do
test -z "`strings -a $i | grep -i -e $1 -e miniz -e zlib -e zstandard -e zstd -e huff -e rle -e copy -e license -e papaw`"
done

# the payload should be extracted to dir_prefix
here=`pwd`
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ if compression == 'lzma'
cfg.set('COMPRESSION_CMD', '"xz", "-c", "--format=lzma", "--lzma1=preset=9e,dict=512KiB"')
cfg.set('OBFUSCATION', 'compressed[:5] + b"\\x08" + compressed[5:]')
cfg.set('DEOBFUSCATION', 'deobfuscated = obfuscated[:5] + obfuscated[6:]')
elif compression == 'minlzma'
compression_cflags = ['-DPAPAW_MINLZMA']
elif compression == 'zstd'
compression_cflags = ['-DPAPAW_ZSTD']
compression_includes = []
Expand Down
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ option('dir_prefix', type: 'string', value: '/tmp')
option('allow_coredumps', type: 'boolean')
option('allow_ptrace', type: 'boolean')
option('ci', type: 'boolean', value: false)
option('compression', type: 'combo', choices: ['xz', 'lzma', 'zstd', 'deflate'])
option('compression', type: 'combo', choices: ['xz', 'lzma', 'minlzma', 'zstd', 'deflate'])
1 change: 1 addition & 0 deletions minlzma
Submodule minlzma added at 3081dc
26 changes: 25 additions & 1 deletion papaw.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ static void xfree(void *);
# define LZMA_PROPS_SIZE 6
# include "lzma/C/LzmaDec.c"
# define LZMA_HEADER_SIZE LZMA_PROPS_SIZE + 8
#elif defined(PAPAW_MINLZMA)
# include "minlzma/minlzlib/dictbuf.c"
# include "minlzma/minlzlib/inputbuf.c"
# include "minlzma/minlzlib/lzma2dec.c"
# include "minlzma/minlzlib/xzstream.c"
# include "minlzma/minlzlib/lzmadec.c"
# include "minlzma/minlzlib/rangedec.c"
#elif defined(PAPAW_ZSTD)
# define DYNAMIC_BMI2 0
# define ZSTD_NO_INLINE
Expand Down Expand Up @@ -152,6 +159,9 @@ static bool extract(const int out,
unsigned char *p;
ELzmaStatus status;
const ISzAlloc alloc = {xalloc, xfree};
#elif defined(PAPAW_MINLZMA)
unsigned char *p;
uint32_t dlen;
#elif defined(PAPAW_ZSTD)
unsigned char *p;
#elif defined(PAPAW_DEFLATE)
Expand All @@ -163,7 +173,7 @@ static bool extract(const int out,
if (ftruncate(out, (off_t)olen) < 0)
return false;

#if defined(PAPAW_XZ) || defined(PAPAW_LZMA) || defined(PAPAW_ZSTD) || defined(PAPAW_DEFLATE)
#if defined(PAPAW_XZ) || defined(PAPAW_LZMA) || defined(PAPAW_MINLZMA) || defined(PAPAW_ZSTD) || defined(PAPAW_DEFLATE)
if (clen != olen)
goto decompress;
#endif
Expand Down Expand Up @@ -228,6 +238,20 @@ static bool extract(const int out,
return false;
}

munmap(p, (size_t)olen);
return true;
#elif defined(PAPAW_MINLZMA)
decompress:
p = mmap(NULL, (size_t)olen, PROT_WRITE, MAP_SHARED, out, 0);
if (p == MAP_FAILED)
return false;

dlen = olen;
if (!XzDecode((uint8_t *)data, clen, p, &dlen) || (dlen != olen)) {
munmap(p, (size_t)olen);
return false;
}

munmap(p, (size_t)olen);
return true;
#elif defined(PAPAW_ZSTD)
Expand Down

0 comments on commit f24e01d

Please sign in to comment.