sh脚本转可执行文件、加密
# 安装使用
GitHub官网: https://github.com/neurobin/shc (opens new window)
从release页面下载最新版,或者比较新的版本, 然后解压安装
./configure
make
sudo make install
1
2
3
2
3
创建测试脚本 tests.sh
#!/bin/sh
echo "test1 test\n"
1
2
2
转换为可执行文件:
shc -f test.sh
1
会生成test.sh.x
,可以直接执行
注意测试,并不一定能执行成功
# 老版本安装和可能存在的问题
下面的方式安装有可能是老版本
# ubuntu
sudo apt-get install shc
# centos
yum install shc
1
2
3
4
5
2
3
4
5
# 使用
创建test1.sh, 注意第一行必须指明解释器
实测解释器如果是#!/bin/bash
可能会有问题, 最好设置为#!/bin/sh
#!/bin/sh
echo "test1 test\n"
1
2
2
将脚本编译成可执行文件
shc -v -r -T -f test1.sh
# 加上过期时间
shc -v -r -T -e 30/12/2022 -f test1.sh
1
2
3
4
2
3
4
奇怪的坑: 不加-T可能会提示权限不足, 不加-e可能会提示脚本过期,-e加了时间也可能会提示过期 不加-v可能会乱码 帮助命令
$ shc -help
shc Version 3.8.6, Generic Script Compiler
shc Copyright (c) 1994-2006 Francisco Rosales <frosal@fi.upm.es>
shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script
-e %s Expiration date in dd/mm/yyyy format [none]
-m %s Message to display upon expiration ["Please contact your provider"]
-f %s File name of the script to compile
-i %s Inline option for the shell interpreter i.e: -e
-x %s eXec command, as a printf format i.e: exec('%s',@ARGV);
-l %s Last shell option i.e: --
-r Relax security. Make a redistributable binary
-v Verbose compilation
-D Switch ON debug exec calls [OFF]
-T Allow binary to be traceable [no]
-C Display license and exit
-A Display abstract and exit
-h Display help and exit
Environment variables used:
Name Default Usage
CC cc C compiler command
CFLAGS <none> C compiler flags
Please consult the shc(1) man page.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
编辑 (opens new window)
上次更新: 2023/05/07, 17:27:54