Thursday, September 16, 2010

Converting Bash script to Binary code

Bash Shell basically comprises of commands written in C language. Hence we basically need a Compiler that can convert the C code into executable Binary file.  I guess there are many C compilers available;  the one which I use is SHC (SHell script Compiler).  When we compile using this tool, it creates an execute file with .x extension, which is basically a executable version of your Bash script which can’t be readable or modifiable.


Extract the shc tar file.
Go into the shc-3.8.7 folder
Install the package by executing 'make'. It will create the 'shc' executable.

Create a sample bash script "".

[root@host01 opt]$ cat

echo "Hello how r u"
[root@host01 opt]$
[root@host01 opt]# ./                              #  Take a note on output
Hello how r u

[root@host01 opt]#
[root@host01 shc-3.8.7]$ ./shc -f /opt/
[root@host01 opt]# ls -l*
-rwxr-xr-x 1 root root    39 Sep 13 12:11
-rwx--x--x 1 root root 11720 Sep 13 12:12     #  .x file created
-rw-r--r-- 1 root root  9406 Sep 13 12:12
[root@host01 opt]#
[root@host01 opt]# ./                                #  Same result as before
Hello how r u

[root@host01 opt]# tail                            #  File is in Binary format
        @OÞ}¬÷ú=hòL³})âïM 3ði¹_=ÄÊÚî¦kpsJ=¸­¡`h]L1ôÌ7©+Éj3


  1. Wonderful !! thanks a lot !!!!

  2. That's What I Want

  3. Is the reverse possible .coverting binary to readable script ?

  4. why can't i export the script to a remote host and run it on the remote host? i get the following error:
    $ ./
    ./ error while loading shared libraries: requires glibc 2.5 or later dynamic linker