shell加密,java&shell互相調用

(一)shell腳本啓動java程序

linux下通過.sh文件啓動java程序的步驟:

1、在linux系統上安裝JDK,並配置環境變量。可以參考:http://blog.csdn.net/u013713294/article/details/52514608

2)把java程序打成jar包。可以參考:http://jingyan.baidu.com/article/219f4bf7d0ef87de442d3820.html

3)指定好主類入口並添加java項目依賴的jar

①指定主類入口

java應用項目打包成一個jar,必須指定一個擁有main函數的main class作爲你這個jar包的程序入口,具體的方法是修改jar包內目錄META-INF下的MANIFEST.MF文件。

MANIFEST.MF裏面添加如下一句話:Main-Class:firstpack.HelloWorld,如下圖:


註釋:

 1Main-Class格式:Main-Class+空格+包名+包含主函數的類名


②添加依賴的jar

AppClassloader來加載第三方依賴的jar。例如:在MANIFEST.MF中添加如下代碼:Class-Path:lib/some.jar,如果有多個jar包需要引用的情況:Class-Path:lib/some.jar lib/some2.jarjar之間用空格隔開。

4)編寫sh腳本文件,執行即可。

   此處用shell腳本調用HelloWorld程序,演示:

①腳本:

#!/bin/bash

java-jar RunJava.jar

----------------------------------------------------------------------------------------------------------------------

②linux裏運行截圖:


(二)java程序調用shell腳本

1、linux下截圖


2、執行結果:



(三) 對shell腳本加密

1、用gzexe命令加密:


 

2、用shc加密

 

[[email protected]]# ls

CHANGES  l.sh     match    match.x.c  shc   shc-3.8.7.c  shc.html    test.bash test.ksh

  pying Makefile  match.x  pru.sh    shc.1  shc.c        shc.README  test.csh

[[email protected]]# ./l.sh

-bash:./l.sh: Permission denied

 

#加密

[[email protected]]# ./shc -v -r -T -f l.sh         

shcshll=bash

shc[-i]=-c

shc[-x]=exec '%s' "$@"

shc[-l]=

shcopts=

shc:cc  l.sh.x.c -o l.sh.x

shc:strip l.sh.x

shc:chmod go-r l.sh.x

[[email protected]]# ls

CHANGES  l.sh.x   match      pru.sh  shc-3.8.7.c shc.README  test.ksh

Copying  l.sh.x.c match.x    shc     shc.c        test.bash

l.sh     Makefile match.x.c  shc.1   shc.html    test.csh

 

#執行加密生成的二進制文件

[[email protected]]#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^@¹^@^@^@^@^@^@^@^

@^@^@^@^R^@^@^@z^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@Þ^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@^A^@^@^@^@^@^@^@^@^

@^@^@^@^@^@1^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@<96>^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@T^@^@^@^@^@^@^@^@^@

^@^@^R^@^@^@b^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@Â^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@³^@^@^@^@^@^@^@^@^@^@^

@^R^@^@^@<88>^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@¤^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@[^@^@^@^@^@^@^@^@^@^@^

@^R^@^@^@<81>^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@«^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@A^@^@^@^@^@^@^@^@^@^@^

@^R^@^@^@<8f>^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@M^@^@^@^@^@^@^@^@^@^@^@^R^@^@^@Ö^@^@^@<80>¦^D^H^D^@^@

^@!^@^Y^@Õ^@^@^@<80>¦^D^H^D^@^@^@!^@^Y^@^Z^@^@^@<9c><91>^D^H^D^@^@^@^Q^@^O^@<9d>^@^@^@`¦^D^H^D^@

^@^@^Q^@^Y^@Ô^@^@^@<80>¦^D^H^D^@^@^@^Q^@^Y^@^@__gmon_start__^@libc.so.6^@_IO_stdin_used^@sprintf

^@__isoc99_sscanf^@time^@getpid^@strdup^@calloc^@strlen^@memset^@__errno_location^@memcmp^@puten

v^@memcpy^@malloc^@getenv^@stderr^@execvp^@fprintf^@atoll^@strerror^@__libc_start_main^@__enviro

[[email protected]]# file l.sh.x

l.sh.x:ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked(uses shared libs), for GNU/Linux 2.6.18, stripped

[[email protected]]# ./l.sh.x  

helloworld

[[email protected]]# ls

CHANGES  l.sh.x   match      pru.sh  shc-3.8.7.c shc.README  test.ksh

Copying  l.sh.x.c match.x    shc     shc.c        test.bash

l.sh     Makefile match.x.c  shc.1   shc.html    test.csh

[[email protected]]# rm -rf l.sh.x*

[[email protected]]# ls

CHANGES  l.sh     match    match.x.c  shc   shc-3.8.7.c  shc.html    test.bash test.ksh

Copying  Makefile match.x  pru.sh     shc.1 shc.c        shc.README  test.csh

 

#重新加密,併爲生成的二進制文件添加有效日期18/10/2006

[[email protected]]# ./shc -e 18/10/2006 -m " It’s too late to run this script" -r -v -T -f l.sh

shcshll=bash

shc[-i]=-c

shc[-x]=exec '%s' "$@"

shc[-l]=

shcopts=

shc:cc  l.sh.x.c -o l.sh.x

shc:strip l.sh.x

shc:chmod go-r l.sh.x

[[email protected]]# ls

CHANGES  l.sh.x   match      pru.sh  shc-3.8.7.c shc.README  test.ksh

Copying  l.sh.x.c match.x    shc     shc.c        test.bash

l.sh     Makefile match.x.c  shc.1   shc.html    test.csh

 

#執行二進制文件顯示過期

[[email protected]]# ./l.sh.x

./l.sh.x:has expired!

 It’s too late to run this script

 

#執行l.sh腳本,正確執行,不受過期時間影響

[[email protected]]# ./l.sh

-bash:./l.sh: Permission denied

[[email protected]]# chmod 755 l.sh

[[email protected]]# ./l.sh       

helloworld


發佈了11 篇原創文章 · 獲贊 28 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章