Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

unix and linux commands - unix shell scripting

convert shell script into a binary executable

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-09-2010   -   Original Discussion by venu
venu's Unix or Linux Image
venu venu is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 5 June 2013, 11:08 AM EDT
Posts: 38
Thanks: 24
Thanked 0 Times in 0 Posts
convert shell script into a binary executable

Hello every one, i want to convert my shell script into a binary executable a .exe file , is it possible to do that if so are there any tools . Would the script take off when the arguments are parsed.

Thanks
Venu
Sponsored Links
    #2  
Old Unix and Linux 12-09-2010   -   Original Discussion by venu
jim mcnamara's Unix or Linux Image
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 11 January 2018, 11:47 PM EST
Location: NM
Posts: 11,280
Thanks: 581
Thanked 1,125 Times in 1,036 Posts
There is a shell compiler maintained and available here:

Francisco Rosales, home page
Sponsored Links
    #3  
Old Unix and Linux 12-10-2010   -   Original Discussion by venu
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 11 January 2018, 12:00 PM EST
Location: Lancashire, UK
Posts: 3,435
Thanks: 1,491
Thanked 671 Times in 604 Posts
Am I being thick?

Well, this is something I have often pondered. A way to write code that is far more difficult to decipher - unless you have the source.

We have a number of intelligent users (if that's not an oxymoron) who like to read scripts and work out what they do and how. Of course, there are various sensitive things that we want to keep secret from them, yet give them the scripted ability to do. Nothing too complex, but it often involves privileged access to a database, for which we store the passwords in a file. Of course, if you can read the script, you know where to find the file! Linux

I grabbed at this link delighted that someone could solve all my woes, but I fail to get it to build. I have a few versions of AIX and two HPUX servers. From the README, it seems to suggest I just run a make, but that fails and I don't know even what it is trying to do. I've pretty much written everything as SQL or KSH (unless you count REXX on VM), so I've no experience in this. I did gcc compile the shc.c and get an executeable which I could then use to process test.ksh to create test.ksh.x, but this wouldn't run. Just the message "Killed" came back.

Am I being a complete fool? Linux

Any pointers?

"Hat's Off" to Jim for finding this if it works. Linux
    #4  
Old Unix and Linux 12-10-2010   -   Original Discussion by venu
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 11 January 2018, 6:12 PM EST
Location: Amsterdam
Posts: 11,695
Thanks: 529
Thanked 3,396 Times in 2,992 Posts
ksh93 comes with a compiler called shcomp


Code:
$ cat test
#!/bin/ksh
for (( i=1; i<=5; i++)); do
  echo Hello World
done
$ ( echo '#!/bin/ksh' ; shcomp test ) > test.bin && chmod +x test.bin
$ ./test.bin
Hello World
Hello World
Hello World
Hello World
Hello World

Which will not make it totally unreadable, but to a certain extent.


Code:
$ od -c < test.bin
0000000   #   !   /   b   i   n   /   k   s   h  \n  \v 023  \b  \0 003
0000020  \0 003  \f 002 005       i   =   1 001  \0 005  \f 002 004   i
0000040   +   + 001  \0  \f 002 006       i   <   =   5 001  \0 203  \0
0000060   @  \0 003 005   e   c   h   o 006   H   e   l   l   o 006   W
0000100   o   r   l   d  \0 003
0000106

Sponsored Links
    #5  
Old Unix and Linux 12-10-2010   -   Original Discussion by venu
pludi's Unix or Linux Image
pludi pludi is offline Forum Advisor  
Cat herder
 
Join Date: Dec 2008
Last Activity: 28 March 2014, 8:35 AM EDT
Location: Vienna, Austria, Earth
Posts: 5,521
Thanks: 38
Thanked 335 Times in 308 Posts
shcomp doesn't really compile the script, but saves the parser tree that's generated internally. The script itself is still traceable using -x as if it were plain text.

shc, as suggested, will encrypt the script using RC4, but you'll lose the cross-platform advantage. Also, somehow it seems to dislike newer versions of Linux, or at least VirtualBox, as the compiled scripts always died.
The Following User Says Thank You to pludi For This Useful Post:
Scrutinizer (12-10-2010)
Sponsored Links
    #6  
Old Unix and Linux 12-21-2010   -   Original Discussion by venu
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 11 January 2018, 12:00 PM EST
Location: Lancashire, UK
Posts: 3,435
Thanks: 1,491
Thanked 671 Times in 604 Posts
So, are there any suggestion how to get shc running? As a non-C person, I don't understand the compile process to get the tool installed, so I don't know what I'm looking for to fix it. Linux



Robin
Liverpool/Blackburn
UK

Last edited by rbatte1; 12-21-2010 at 08:23 AM.. Reason: Grammer
Sponsored Links
    #7  
Old Unix and Linux 12-21-2010   -   Original Discussion by venu
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 10 January 2018, 8:37 PM EST
Posts: 3,429
Thanks: 147
Thanked 1,215 Times in 1,114 Posts
Are you on AIX 64 bit, as it looks like someone had a similar problem here and found a fix.

You could also try the -T option to shc, this also got it working of AIX 5.3 64bit for me, also fixed `PTRACE_ATTACH' undeclared error when generating on cygwin:



Code:
$ ./shc -T -f test.ksh
 
$ ./test.ksh.x test params 1 2 3
+ alias whence=type -a
+ alias ll=ls -l
+ alias la=ls -A
+ alias l=ls -CF
+ echo $@ is test params 1 2 3
$@ is test params 1 2 3
+ echo command line: ./test.ksh.x test params 1 2 3
command line: ./test.ksh.x test params 1 2 3
+ echo hello world
hello world
+ echo [581760] PAUSED... Hit return!
[581760] PAUSED... Hit return!
+ read DUMMY
done
+ exit 0

'
BTW I think you probably need to set CC=gcc before trying the make (If not I might be able to help if you supply the error make is giving):



Code:
$ CC=gcc ; export CC
$ make

Sponsored Links
Closed


Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Is there any script which convert binary file to CSV format ahmad.diab Shell Programming and Scripting 14 11-09-2009 07:56 AM
can UNIX scripting be converted into binary(executable) umarbangash Shell Programming and Scripting 5 08-21-2009 10:29 AM
running command prompt executable file in shell script atl@mav UNIX for Dummies Questions & Answers 5 04-14-2009 12:14 PM
Linking Libaries to binary executable bhavana UNIX and Linux Applications 0 07-27-2008 02:38 PM



All times are GMT -4. The time now is 03:16 AM.