这是一次失败的任务,即使再来一次,依然会失败,因为无法验证,真够shit的,扣了我10$的手续费。
记录一下,以儆效尤。
任务如下:
1Job would be to compile an ipk file of SHC that would work with LEDE OS (openwrt) and the processor used in our system - will provide details
2
3SHC can be downloaded here: http://www.datsi.fi.upm.es/~frosal/
4
5I think you must have a 64 bit system to use the SDK to compile the file
翻译一下:在OpenWRT平台下编译一个SHC,并且能工作。
完全步骤如下:
1How to compile SHC on LEDE:
2
3Tested build environment:
4
5OS: Ubuntu 14.04.5 LTS
6CPU: ARMv7 Processor rev 5 (v7l)
7
8
9Before you begin, check your system is updated, i.e.
10
11sudo apt-get update
12sudo apt-get upgrade
13sudo apt-get autoremove
14
15
16Step-by-step manual:
17Note: perform all steps as regular (non-root) user. User must be in sudo group.
18
191. Update your sources
20
21sudo apt-get update
22
232. Install nesessary packages:
24
25sudo apt-get install g++ libncurses5-dev zlib1g-dev bison flex unzip autoconf gawk make gettext gcc binutils patch bzip2 libz-dev asciidoc subversion sphinxsearch libtool sphinx-common libssl-dev libssl0.9.8
26
273. Get latest LEDE source from git repository
28 We know our CPU is armv7, it belongs to arm64, so go to http://downloads.lede-project.org/releases , just download sdk.
29
30wget http://downloads.lede-project.org/releases/17.01.4/targets/arm64/generic/lede-sdk-17.01.4-arm64_gcc-5.4.0_musl-1.1.16.Linux-x86_64.tar.xz
31
32
334. No Need to Update and install all LEDE packages
34 We just want to compile shc, not other packages , so don't update.
35
36
375. Run 'make menuconfig' (Just Save and Exit)
38
39
406. Get SHC sources to LEDE package tree
41 (we are and shc-3.8.9b.tgz is in source directory)
42
43wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz
44mkdir -p package/shc/src
45tar xvf shc-3.8.9b.tgz -C package/shc/src --strip-components 1
46
477. Make ipk Makefile
48
49vi package/shc/Makefile
50##############################################
51# OpenWrt Makefile for shc program
52#
53#
54# Most of the variables used here are defined in
55# the include directives below. We just need to
56# specify a basic description of the package,
57# where to build our program, where to find
58# the source files, and where to install the
59# compiled program on the router.
60#
61# Be very careful of spacing in this file.
62# Indents should be tabs, not spaces, and
63# there should be no trailing whitespace in
64# lines that are not commented.
65#
66##############################################
67
68include $(TOPDIR)/rules.mk
69
70# Name and release number of this package
71
72PKG_NAME:=shc
73PKG_VERSION:=3.8.9b
74PKG_MAINTAINER:=Francisco, Rosales, <frosal@fi.upm.es>
75
76
77# This specifies the directory where we're going to build the program.
78# The root build directory, $(BUILD_DIR), is by default the build_mipsel
79# directory in your OpenWrt SDK directory
80PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
81
82
83include $(INCLUDE_DIR)/package.mk
84
85
86
87# Specify package information for this program.
88# The variables defined here should be self explanatory.
89# If you are running Kamikaze, delete the DESCRIPTION
90# variable below and uncomment the Kamikaze define
91# directive for the description below
92define Package/$(PKG_NAME)
93 SECTION:=utils
94 CATEGORY:=Utilities
95 TITLE:= shc ---- This tool generates a stripped binary executable version of the script specified at command line.
96 URL:=http://www.datsi.fi.upm.es/~frosal
97endef
98
99
100# Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
101define Package/$(PKG_NAME)/description
102 shc ---- This tool generates a stripped binary executable version
103 of the script specified at command line."
104endef
105
106# Specify what needs to be done to prepare for building the package.
107# In our case, we need to copy the source files to the build directory.
108# This is NOT the default. The default uses the PKG_SOURCE_URL and the
109# PKG_SOURCE which is not defined here to download the source from the web.
110# In order to just build a simple program that we have just written, it is
111# much easier to do it this way.
112define Build/Prepare
113 mkdir -p $(PKG_BUILD_DIR)
114 $(CP) ./src/* $(PKG_BUILD_DIR)/
115endef
116
117
118# We do not need to define Build/Configure or Build/Compile directives
119# The defaults are appropriate for compiling a simple program such as this one
120
121# Specify where and how to install the program. Since we only have one file,
122# the helloworld executable, install it by copying it to the /bin directory on
123# the router. The $(1) variable represents the root directory on the router running
124# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
125# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
126# command to copy the binary file from its current location (in our case the build
127# directory) to the install directory.
128define Package/$(PKG_NAME)/install
129 $(INSTALL_DIR) $(1)/bin
130 $(INSTALL_BIN) $(PKG_BUILD_DIR)/shc $(1)/bin/
131endef
132
133
134# This line executes the necessary commands to compile our program.
135# The above define directives specify all the information needed, but this
136# line calls BuildPackage which in turn actually uses this information to
137# build a package.
138$(eval $(call BuildPackage,$(PKG_NAME)))
139
140
1418. Compile shc ipk without errors.
142
143make package/shc/compile V=99
144
1459. Building process complete witout errors.
146Now we have :
147binary packages directory: source/bin/packages/aarch64_armv8-a/
148[SHC_BIN] = ./bin/packages/aarch64_armv8-a/base/shc_3.8.9b_aarch64_armv8-a.ipk
149
15010. Copy and install SHC .ipk to LEDE device.
151
152scp shc_3.8.9b_aarch64_armv8-a.ipk root@<LEDE device IP address or name>:/tmp/
153ssh root@<LEDE device IP address or name> #IP usually 192.168.1.1
154opkg install shc_3.8.9b_aarch64_armv8-a.ipk
155
15611. Create test script and compile it to execute. (in LEDE shell)
157ssh root@<LEDE device IP address or name> #IP usually 192.168.1.1
158
159vi /tmp/1.sh
160#!/bin/sh
161echo "hahahaha"
162
163shc -v -f /tmp/1.sh
164/tmp/1.sh.x
这里面有几个注意点,一个是网上有很多教程,上去就是
1./scripts/feeds update -a
2./scripts/feeds install -a
这个千万不要,这两条命令是把所有的库和软件都给下载下来的,如果再编译,基本半天过去了,浪费时间生命。我们的目标只是要编译个shc,其他都不管。
第二点就是那个Makefile,其实编译shc就一句话,但是我们要放到LEDE里就必须有这个Makefile.
这样就顺利编译出来个shc3.8.9baarch64_armv8-a.ipk,但是雇主反映拷上去不能用,我去!
这才又仔细研究shc,这个软件其实是个混淆的软件,把shell脚本变成*.c,然后再用gcc编译成2进制文件。
但是依OpenWRT的性格,一般根本装不下gcc的,所以必须外挂U盘装GCC上去,装法如下:
http://www.th7.cn/Program/cp/201708/1224085.shtml
验证方法也比较古怪,首先写好shell,然后跑到openwrt上用shc进行混淆,然后把混淆过的.c文件拷出来,再用gcc编译成bin,然后再拷回openwrt运行验证。
再附上单独用gcc编译的方法:
1export STAGING_DIR=~/LEDE-IPQ40XX$/staging_dir
2cd ~/LEDE-IPQ40XX$
3./staging_dir/toolchain-arm_cortex-a7+neon-vfpv4_gcc-7.3.0_musl_eabi/bin/arm-openwrt-linux-muslgnueabi-gcc script.sh.x.c -o script.sh.x
shit啊,其实我编译出来的shc已经是可以运行并混淆出*.c的,但是不知道为什么arm-gcc编译出的bin文件在openwrt上无法运行,更悲剧的是我没有他那个平台,无法自己装个gcc看看到底是怎么回事
悲惨世界啊,被扣了10$手续费。
最后问了雇主,他又找了一个家伙解决了问题,给出的方法如下:
19. Compile shell script
2
3${HOME}/shc.sh -r ${HOME}/openwrt-sdk -n hello-world -s ${HOME}/hello-world.sh.x.c;
4ls -lh ${HOME}/openwrt-sdk/bin/packages/arm_cortex-a7_neon-vfpv4/base/script_*;
5ls -lh ${HOME}/openwrt-sdk/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/hello-world-0.0.1/hello-world;
6
710. Install the script package on OpenWrt.
8
9scp ${HOME}/openwrt/bin/packages/arm_cortex-a7_neon-vfpv4/base/script_* root@192.168.1.1:/tmp/;
10ssh root@192.168.1.1;
11opkg install /tmp/script_*;
12exit;
看明白了吧,我也无法验证,靠有心人去试试了。记录一下。