1、准备源码包
直接去github下载zip包或者直接克隆一下。
git clone https://github.com/upx/upx.git
cd upx
rmdir lzma-sdk
git clone https://github.com/upx/upx-lzma-sdk.git lzma-sdk
Copy
lzma库无需编译。
然后去下载UCL库。
UCL是完全使用ANSI C编写的NRV(Not Really Vanished)算法的一个开源实现。 具体的介绍请查阅http://www.oberhumer.com/opensource/ucl/
wget http://www.oberhumer.com/opensource/ucl/download/ucl-1.03.tar.gz
Copy
国外的网站下载比较慢,可以直接点击此处下载我已经下好的。
2、编译
UCL编译
先生成Makefile文件
tar -xzvf ucl-1.03.tar.gz
cd ucl-1.03
./configure --prefix=/home/o/ucl CC=clang
Copy
注意上面,指定了C编译器为clang。这里是因为gcc的一个bug,导致 ACC一致性测试失败 ,所以使用clang。
gcc出现的错误情况在这里FTBFS with GCC 6: compiler failed the ACC conformance test有详细描述。
如果没有安装clang,安装
sudo apt install clang
编译UPX
使用下面命令编译upx
make all UPX_UCLDIR=/home/o/upx/ucl/ucl-1.03 UPX_LZMADIR=./src/lzma-sdk
Copy
注意,这里的UPX_UCLDIR变量的值必须是绝对路径。
编译出的结果是upx.out程序,在src目录下。
报错1:
relocation R_X86_64_32S against `.text' can not be used when making a PIE object; recompile with -fPIC:链接时 加上 -no-pie,修改makefile
vim src/Makefile
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
ifeq ($(BUILD_TYPE_DEBUG),1)
CXXFLAGS_OPTIMIZE ?= -no-pie -O0 -g
else
CXXFLAGS_OPTIMIZE ?= -no-pie -O2
endif
报错2:
home/ubuntu/upx/process/upx-3.94/src/stub/scripts/check_whitespace.sh,将下面的语句全部注释掉
#print("$ARGV\n");
if (m,[\x00\x01\x02\xfe\xff],) { print "ERROR: binary file detected $ARGV: $_"; exit(1); }
if (m,[\r\x1a],) { print "ERROR: DOS EOL detected $ARGV: $_"; exit(1); }
if (m,([ \t]+)$,) {
# allow exactly two trailing spaces for GitHub flavoured Markdown in .md files
if ($1 ne " " || $ARGV !~ m,\.md$,) {
print "ERROR: trailing whitespace detected $ARGV: $_"; exit(1);
}
}
if (m,\t,) {
if ($ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
elsif ($ARGV =~ m,/tmp/.*\.(disasm|dump)$,) { }
elsif ($ARGV =~ m,/src/stub/src/arch/.*/lzma\w+\.S$,) { }
else { print "ERROR: hard TAB detected $ARGV: $_"; exit(1); }
}