How to compile a linux shell script to be a standa

2019-01-08 06:56发布

I'm looking for a free open source tool-set that will compile various "classic" scripting languages, e.g. Korn Shell, ksh, csh, bash etc. as an executable -- and if the script calls other programs or executables, for them to be included in the single executable.

Reasons:

  1. To obfuscate the code for delivery to a customer so as not to reveal our Intellectual Property - for delivery onto a customer's own machine/systems for which I have no control over what permissions I can set regarding access, so the program file has to be binary whereby the workings cannot be easily seen by viewing in a text editor or hexdump viewer.

  2. To make a single, simply deployed program for the customer without/or a minimal amount of any external dependencies.

I would prefer something simple without the need for package manager since:

  1. I can't rely on the customer's knowledge to carry out (un) packaging instructions and

  2. I can't rely on the policies governing their machines regarding installing packages (and indeed from third parties).

The simplest preferred approach is to be able to compile to proper machine code a single executable that will run out of the box without any dependencies.

7条回答
贼婆χ
2楼-- · 2019-01-08 07:08

The solution that fully meets my needs would be SHC - a free tool, or CCsh a commercial tool. Both compile shell scripts to C, which then can be compiled using a C compiler.

Links about SHC:

Links about CCsh:

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-08 07:12

You can obfuscate shell scripts with something like ofbsh. You won't easily bundle other programs into a single executable for unix, though. Normally the approach for installation would be to buld a package for your platform's package manager (e.g. rpm, deb, pkg) or to provide a tarball to unravel in the appropriate directory.

If you need an executable file that unpacks the contents you might be able to use a shell archive. Take a look at the docs for shar(1) and see if that will get what you want

If you really need a scripting capability to glue multiple C programs together, take a look at the Tcl language. It has an API that is designed to trivially wrap C programs that expect to see argv[] style parameters. You can even embed the chunks of C code into a custom Tcl interpreter and glue it together with various Tcl scripts.

If you really need to make it opaque, you could encrypt the tcl scripts and wrap the whole thing in something that unencrypts the tcl scripts to a buffer and then runs the Tcl interpreter on them. Tcl can accept scripts from a file or a char* buffer, so the unencrypted scripts never have to hit the file system.

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-08 07:17

You can also use the free online version of CCsh to compile a shell script into a binary: http://www.comeaucomputing.com/tryccsh/

查看更多
何必那么认真
5楼-- · 2019-01-08 07:20

You could use this: http://megastep.org/makeself/

This generates a shell script that auto-extracts a bundled tar.gz archive into the temporary directory, and then can run an arbitrary command upon extraction.

Using this tool, you can provide only one shell script to the client.

This script will then extract your ofbsh obfuscated scripts and binaries into /tmp, and run them transparently.

查看更多
放荡不羁爱自由
6楼-- · 2019-01-08 07:30

arx is a great bundler, and you may be able to integrate a obfuscator in its workflow.

查看更多
贼婆χ
7楼-- · 2019-01-08 07:31

shc

I have modified the original source and upgraded to a new version with some feature addition and bug fixes. It's here.

Example Usage:

shc -f script.sh -o binary_name

script.sh will be compiled to a binary named binary_name

Note that, you still need the required shell to be installed in your system to run this executable.

查看更多
登录 后发表回答