Chinaunix首页 | 论坛 | 博客
  • 博客访问: 805741
  • 博文数量: 94
  • 博客积分: 1767
  • 博客等级: 上尉
  • 技术积分: 1168
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-13 23:16
个人简介

ha

文章分类

全部博文(94)

文章存档

2014年(2)

2013年(17)

2012年(6)

2011年(15)

2010年(23)

2009年(23)

2008年(8)

我的朋友

分类: LINUX

2013-10-29 13:04:48

转载自:http://learningloong.blog.163.com/blog/static/16230812420127453937376/
有些地方可能与新版的shc不匹配,适当修改了一下

shell脚本有时候需要保存密码,比如登陆ftp脚本。

有时候又需要是可执行文件的格式,比如在windows下的gvim中是无法直接调用shell脚本的,这就可以通过编译成可执行文件来调用。
shc(下载地址:)是一个脚本编译工具,使用RC4加密算法,可以将shell脚本编译成动态链接或者静态链接的可执行文件。

Win32:
Cygwin环境下需要下载源代码并且用Cygwin自身的编译方式,编译成当前平台可以执行的格式,即需调用cygwin1.dll.

Ubuntu12.04.2 bit64:(这个是我的实际操作环境)
安装包:shc-3.8.9.tgz
解压后进入目录:ln -s shc-3.8.9.c shc.c
编译后即可使用:make


使用方式:
1.动态链接:
shc -v -r -T -f shellname.sh
shc会将脚本翻译成c语言的代码,,然后编译成可执行文件。
成功后可以看到生成了动态链接可执行二进制文件shellname.sh.x和C源文件shellname.sh.x.c

2.静态链接:
export CFLAGS=-static
./shc -r -f shellname.sh
生成的文件自动取名为shellname.sh.x

另外, sch还可以设置脚本的运行期限和自定义返回信息:
shc -e 04/31/2010 -m “the script is now out of date.” -f shellname.sh
-e表示脚本将在2010年4月31日前失效, 并根据-m定义的信息返回给用户.

选项:
     The command line options are:

     -e date
          Expiration date in dd/mm/yyyy format [none]

     -m message
          message to display  upon  expiration  ["Please  contact
          your provider"]

     -f script_name
          File name of the script to compile

     -i inline_option
          Inline option for the shell interpreter i.e: -e

     -x comand
          eXec    command,    as    a    printf    format    i.e:
          exec(//'%s//',@ARGV);

     -l last_option
          Last shell option i.e: --

     -r   Relax security. Make  a  redistributable  binary  which
          executes  on different systems running the same operat-
          ing system.

     -v   Verbose compilation

     -D   Switch on debug exec calls

     -T   Allow binary to be  traceable  (using  strace,  ptrace,
          truss, etc.)

     -C   Display license and exit

     -A   Display abstract and exit

     -h   Display help and exit
阅读(4226) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~