shownb / shownb.github.com

shownb.github.io
shownb.github.io
5 stars 1 forks source link

交叉编译+静态编译 #40

Open shownb opened 5 years ago

shownb commented 5 years ago

armv7的交叉编译

apt-get update apt-get install gcc-arm-linux-gnueabihf apt-get install g++-arm-linux-gnueabihf 这个不装的后遗症是出现configure: error: C compiler cannot create executables

目标 tcpdump的静态编译 git clone https://github.com/the-tcpdump-group/libpcap git clone git://bpf.tcpdump.org/tcpdump

编译libpcap

./configure --prefix=/root/libpcap --host=arm-linux CC=arm-linux-gnueabihf-gcc
make
make install

编译tcpdump 下面三个export不做的话,会在编译完成之后在目标机器运行的时 出现如下错误: not found. 这真不是开玩笑,出现这个问题是,是因为,你不静态编译的话,他还会调用一些so库。 arm-linux-gnueabihf-readelf -e tcpdump 可以知道是不是会调用其他库。我在没有export之前,会出现[Requesting program interpreter: /lib/ld-linux-armhf.so.3]

export CFLAGS=-static
export CPPFLAGS=-static
export LDFLAGS=-static
./configure --prefix=/root/tcpdump --disable-ipv6  CC=arm-linux-gnueabihf-gcc --host=arm-linux CFLAGS='-I/root/libpcap/include' LDFLAGS='-L/root/libpcap/lib/libpcap.a'
或
./configure --prefix=/root/tcpdump CC=arm-linux-gnueabihf-gcc --host=arm-linux CFLAGS='-I/root/libpcap/include -static' CPPFLAGS='-static' LDFLAGS='-L/root/libpcap/lib/libpcap.a -static'
make

如果出现某些错误,还需要改一下configure 把那些对版本的注视掉.

./configure --prefix=/root/tcpdump CC=arm-linux-gnueabi-gcc --host=arm-linux CFLAGS='-I/root/libpcap/include -static' CPPFLAGS='-static' LDFLAGS='-L/root/libpcap/lib/libpcap.a -static' ac_cv_linux_vers=2 --with-crypto=no

再减减肥,完美了。 arm-linux-gnueabihf-strip tcpdump

静态编译lua

http://www.neptune8.com/post/lua交叉编译/

CROSS=arm-linux-gnueabihf- CC=$(CROSS)gcc LIBS= -lm $(SYSLIBS) -static AR=$(CROSS)ar rcu RANLIB=$(CROSS)ranlib $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline" 去掉最后的-lreadline

luaconf.h修改 需要把 #define LUA_USE_READLINE 注释掉

mips的交叉编译

apt-get install gcc-mips-linux-gnu
apt-get install g++-mips-linux-gnu

更多的交叉编译器 curl https://codescape.mips.com/components/toolchain/2017.10-08/Codescape.GNU.Tools.Package.2017.10-08.for.MIPS.MTI.Linux.CentOS-5.x86_64.tar.gz -O

一般编辑 nano /etc/bash.bashrc 添加编译器的路径 export PATH=/yourpatch/rsdk-1.5.10-5281-EB-2.6.30-0.9.30-m32ub-130429/bin:$PATH

source /etc/bash.bashrc

问题:

  1. 出现"kernel too old”"的原因是不同版本的glibc库文件要依赖于不同版本的linux内核版本,并且编译器会限定运行该可执行文件所需的最低的内核版本。在编译时使用的编译器的版本比较高,它所指定的最低linux内核版本要高于m5声明的内核版本。 编译出来之后看看适用版本 file tcpdump tcpdump: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=7820526da766673fe27af2231cd7f89b4cd2a440, stripped

目标机器内核是:Linux 2.6.34.10

  1. rtk的破假mips

安装指定版本的软件 apt-get install openssh-client=1:6.6p1-2ubuntu1

shownb commented 5 years ago

mips-mti-linux-gnu ./configure --prefix=/root/libpcap --host=mips-linux CC=mips-linux-gcc ./configure --prefix=/root/tcpdump CC=mips-linux-gcc --host=mips-linux CFLAGS='-I/root/libpcap/include' LDFLAGS='-L/root/libpcap/lib/libpcap.a'

https://github.com/sawrose/DSL2750U_U1_GPL_IN_1.08_IN

shownb commented 5 years ago

dropbear的编译 zlib prefix=/home/noname/zlib_install CC=arm-linux-gnueabihf-gcc CFLAGS="-static -fPIC" ./configure

dropbear ./configure --prefix=/home/noname/dropbear_install --with-zlib=/home/noname/zlib_install CC=arm-linux-gnueabihf-gcc --host=arm --enable-static 不带--enable-static 会带有/lib/ld-uClibc.so.0

./configure --disable-zlib --disable-largefile --disable-loginfunc --disable-shadow --disable-utmp --disable-utmpx --disable-wtmp --disable-wtmpx --disable-pututline --disable-pututxline --disable-lastlog CC=arm-none-linux-gnueabi-gcc LDFLAGS=-static --host=arm-linux

shownb commented 5 years ago

mips-linux-gcc -o test test.c --static -lutil

shownb commented 5 years ago

busybox的编译 遇到什么错误,就需要在make menuconfig里面删除。例如

libbb/lib.a(copy_file.o): In function `copy_file':
copy_file.c:(.text.copy_file+0x81c): warning: the use of LEGACY `utimes' is discouraged, use `utime'
coreutils/lib.a(sync.o): In function `sync_main':
sync.c:(.text.sync_main+0xd4): undefined reference to `syncfs'

就需要在core utils不编译这个组件就可以了。

shownb commented 5 years ago

fucking openssl

./Configure gcc -static -no-shared --prefix=/http/ettercap --cross-compile-prefix=arm-linux-gnueabi-

x86 下的一个问题

./config -fPIC no-shared --prefix=/http/ettercap

其中,-fPIC:指示生成位置无关的代码,这个选项是在把openssl生成的静态库链接到动态库的时候提示错误添加的;no-shared:指示生成静态库。

最终在当前目录下会编译出libssl.a和libcrypto.a两个库文件,在开发的时候只需要包含头件并链接这两个库就可以了。

export OPENSSL_LIBRARIES=/openssl/lib export OPENSSL_ROOT_DIR=/openssl 关于cmake 为了将程序更智能一点,我们可以使用CMAKE_INCLUDE_PATH来进行,使用bash的方法如下: export CMAKE_INCLUDE_PATH=/http/ettercap/include export CMAKE_LIBRARY_PATH=/http/ettercap/lib

export CC=arm-linux-gnueabi-gcc
export CXX=arm-linux-gnueabi-g++
cmake ../
make

declare -x CC="arm-linux-gnueabi-gcc" declare -x CMAKE_INCLUDE_PATH="/http/ettercap/include" declare -x CMAKE_LIBRARY_PATH="/http/ettercap/lib" declare -x CXX="arm-linux-gnueabi-g++" declare -x OPENSSL_INCLUDE_DIR="openssl" declare -x OPENSSL_LIBRARIES=""

x86

cmake -DOPENSSL_ROOT_DIR=/openssl -DOPENSSL_LIBRARIES=/openssl/lib ../

shownb commented 5 years ago

libpcap

./configure --prefix=/ettercap
make
make install
rm /ettercap/lib/libpcap.so

zlib

./configure --prefix=/ettercap --static

openssl

./Configure gcc -static -no-shared --prefix=/ettercap
make

ettercap

export CMAKE_INCLUDE_PATH=/ettercap/include
export CMAKE_LIBRARY_PATH=/ettercap/lib

ettercap目录的CMakeLists.txt添加set(CMAKE_EXE_LINKER_FLAGS "-static -pthread -lrt -ldl") src/interfaces/CMakeLists.txt 处的SHARED改为STATIC src/CMakeLists.txt 的也是一样。

交叉编译时候 ettercap/bundled_deps/libnet# cat libnet_configure_wrapper.sh.in ./configure --host=arm-linux --disable-shared --disable-samples --enable-static --prefix="@LIBNET_PREFIX@" --includedir="@LIBNET_INCLUDE_DIR@" --libdir="@LIBNET_LIB_DIR@"

shownb commented 5 years ago

ettercap.patch patch -p1 < ../ettercap.patch

diff -ruNa ettercap/bundled_deps/libnet/libnet_configure_wrapper.sh.in ettercap_new/bundled_deps/libnet/libnet_configure_wrapper.sh.in
--- ettercap/bundled_deps/libnet/libnet_configure_wrapper.sh.in 2019-04-20 08:28:41.098954880 +0000
+++ ettercap_new/bundled_deps/libnet/libnet_configure_wrapper.sh.in 2019-04-20 08:36:56.604593184 +0000
@@ -1,3 +1,3 @@
 #!/bin/sh
-./configure --disable-shared --disable-samples --enable-static --prefix="@LIBNET_PREFIX@" --includedir="@LIBNET_INCLUDE_DIR@" --libdir="@LIBNET_LIB_DIR@"
+./configure --host=arm-linux --disable-shared --disable-samples --enable-static --prefix="@LIBNET_PREFIX@" --includedir="@LIBNET_INCLUDE_DIR@" --libdir="@LIBNET_LIB_DIR@"

diff -ruNa ettercap/CMakeLists.txt ettercap_new/CMakeLists.txt
--- ettercap/CMakeLists.txt 2019-04-20 08:28:41.062953992 +0000
+++ ettercap_new/CMakeLists.txt 2019-04-20 08:35:42.411400212 +0000
@@ -2,7 +2,7 @@
 project(ettercap C)

 set(VERSION "0.8.2")
-
+set(CMAKE_EXE_LINKER_FLAGS "-static -pthread -lrt -ldl")
 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
 set(CMAKE_SCRIPT_PATH "${CMAKE_SOURCE_DIR}/cmake/Scripts")

@@ -10,16 +10,16 @@
 macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build.
 Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there.")

-option(ENABLE_CURSES "Enable curses interface" ON)
-option(ENABLE_GTK "Enable GTK interface" ON)
-option(ENABLE_PLUGINS "Enable plugins support" ON)
+option(ENABLE_CURSES "Enable curses interface" OFF)
+option(ENABLE_GTK "Enable GTK interface" OFF)
+option(ENABLE_PLUGINS "Enable plugins support" OFF)
 option(ENABLE_IPV6 "Enable IPv6 support" OFF)
 option(ENABLE_LUA "Enable LUA support (EXPERIMENTAL)" OFF)
 option(ENABLE_PDF_DOCS "Enable PDF document generation" OFF)
 option(ENABLE_TESTS "Enable Unit Tests" OFF)
-option(ENABLE_GEOIP "Build with GeoIP support" ON)
+option(ENABLE_GEOIP "Build with GeoIP support" OFF)
 option(LIBRARY_BUILD "Build for libettercap only" OFF)
-option(INSTALL_DESKTOP "Install ettercap desktop files" ON)
+option(INSTALL_DESKTOP "Install ettercap desktop files" OFF)

 set(VALID_BUILD_TYPES Debug Release RelWithDebInfo)
@@ -41,7 +41,7 @@
 # set to off.
 option(SYSTEM_LIBS "Search for system-provided libraries.
 This is only used for libraries that we happen to also bundle.
-Disabling this implies that we would only use bundled libraries." ON)
+Disabling this implies that we would only use bundled libraries." OFF)

 # If BUNDLED_LIBS is set to off, then all BUNDLED_* options will be
 # set to off.
diff -ruNa ettercap/src/CMakeLists.txt ettercap_new/src/CMakeLists.txt
--- ettercap/src/CMakeLists.txt 2019-04-20 08:28:41.134955768 +0000
+++ ettercap_new/src/CMakeLists.txt 2019-04-20 08:37:58.133537039 +0000
@@ -187,7 +187,7 @@
   set(EC_SRC ${EC_SRC} missing/getopt.c)
 endif()

-add_library(lib_ettercap SHARED ${EC_SRC})
+add_library(lib_ettercap STATIC ${EC_SRC})
 add_dependencies(lib_ettercap libnet)
 target_link_libraries(lib_ettercap ec_interfaces ${EC_LIBS})

diff -ruNa ettercap/src/interfaces/CMakeLists.txt ettercap_new/src/interfaces/CMakeLists.txt
--- ettercap/src/interfaces/CMakeLists.txt  2019-04-20 08:28:41.146956064 +0000
+++ ettercap_new/src/interfaces/CMakeLists.txt  2019-04-20 08:38:42.354192757 +0000
@@ -96,7 +96,7 @@
 endif()

-add_library(ec_interfaces SHARED ../ec_interfaces.c
+add_library(ec_interfaces STATIC ../ec_interfaces.c
 ${EC_TEXT_SRC} ${EC_DAEMON_SRC} ${EC_WDG_SRC} ${EC_CURSES_SRC} ${EC_GTK_SRC})
 set_target_properties(ec_interfaces PROPERTIES
   ENABLE_EXPORTS On
shownb commented 5 years ago

ettercap -i ppp0 -T -p -m ok.log -D 需要把share/etter.conf的utf8_encoding = "ISO-8859-1"注释