Today we will create binary file before compiling it into an RPM package. I had wrote a find script which is basically doing the same thing as find command in addition, you can give to the script exact date, hour, second to search. Imagine that you have 3.000 files in a directory, you are asked to delete files between 20/02/2016 at 08:00:00 and 05/08/2017 till 16:25:00. To do that you have to create reference files with touch –t command. Otherwise, -mmin or –mtime may miss some files or delete important files which is not welcomed in real work environment. My script can list files, delete, compress, create a tar ball and move it to desired location, change or delete extensions. These operations can be done by searching files with name or given time interval.
SHC is a tool that we are looking for. First, let’s download and install it:
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@pvmove ~]# cd /tmp [root@pvmove tmp]# wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.7.tgz --2018-08-25 17:08:45-- http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.7.tgz Resolving www.datsi.fi.upm.es... 138.100.9.22 Connecting to www.datsi.fi.upm.es|138.100.9.22|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 20498 (20K) [application/x-gzip] Saving to: “shc-3.8.7.tgz” 100%[======================================>] 20,498 92.3K/s in 0.2s 2018-08-25 17:08:46 (92.3 KB/s) - “shc-3.8.7.tgz” saved [20498/20498] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@pvmove tmp]# tar xvfz shc-3.8.7.tgz shc-3.8.7/CHANGES shc-3.8.7/Copying shc-3.8.7/Makefile shc-3.8.7/match shc-3.8.7/pru.sh shc-3.8.7/shc-3.8.7.c shc-3.8.7/shc.1 shc-3.8.7/shc.README shc-3.8.7/shc.c shc-3.8.7/shc.html shc-3.8.7/test.bash shc-3.8.7/test.csh shc-3.8.7/test.ksh |
Go inside SHC directory and type make, after that you will be able to execute the script by ./shc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@pvmove tmp]# cd shc-3.8.7 [root@pvmove shc-3.8.7]# [root@pvmove shc-3.8.7]# ls CHANGES Makefile pru.sh shc-3.8.7.c shc.html test.bash test.ksh Copying match shc.1 shc.c shc.README test.csh [root@pvmove shc-3.8.7]# make cc -Wall -O6 shc.c -o shc *** ▒Do you want to probe shc with a test script? *** Please try... make test [root@pvmove shc-3.8.7]# ./shc -v shc parse(-f): No source file specified shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script [root@pvmove shc-3.8.7]# ./shc -f /root/Downloads/find_script.sh |
Where –f is your script as a file
Then under your script’s directory which is f /root/Downloads you will see newly create .sh.x and .sh.x.c files.
1 2 3 4 5 |
[root@pvmove shc-3.8.7]# ll /root/Downloads/ total 148 -rwxr-xr-x. 1 root root 16568 Aug 25 16:53 find_script.sh -rwx--x--x. 1 root root 32056 Aug 25 17:15 find_script.sh.x -rw-r--r--. 1 root root 96527 Aug 25 17:15 find_script.sh.x.c |
.sh.x is the encrypted shell script in binary format
.sh.x.c is the C source code of the random.sh file. The logic behind it is shc converts shell script to a C program find_script.sh.x.c has been generated. Then C file is compiled, find_script.sh.x executable is created.
As you see, find_script.sh.x is henceforth a 64 bit executable.
1 2 3 4 5 6 |
[root@pvmove shc-3.8.7]# file /root/Downloads/find_script.sh.x /root/Downloads/find_script.sh.x: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped [root@pvmove shc-3.8.7]# [root@pvmove shc-3.8.7]# file /root/Downloads/find_script.sh /root/Downloads/find_script.sh: Bourne-Again shell script text executable [root@pvmove shc-3.8.7]# |
Shc options:
-e : specify expiration date. If used, a message will be printed while executing the script.
./script.sh.x: has expired!
Please contact your provider
-m option is for message. While printing a warning message you can print whatever you want.
-T option will allow the created binary files to be traceable using programs like strace, ltrace, etc.
-v is for verbose.
Now, let’s run our program.
Script is in French language with multiple options I just wanted to show menus and how it looks the binary file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@pvmove shc-3.8.7]# ./find_script.sh.x Essayer avec ./find_script.sh.x -h pour voir les options disponibles [root@pvmove shc-3.8.7]# ./find_script.sh.x -h Essayer avec ./find_script.sh.x -h pour voir les options disponibles ****** -l: Pour lister les fichiers dans l'intervalle donnee. ****** -c: Compresser les fichiers trouves, les fichiers sont verifiables via ./ find_script.sh.x -l commande. ****** -t: Creer un archive tar.gz a partir des fichiers trouves. ****** -d: Supprimer les fichiers trouves. ****** -e: Manipuler l'extension. ****** -o: Traitement par nom. [root@pvmove shc-3.8.7]# less find_script.sh.x "find_script.sh.x" may be a binary file. See it anyway? [root@pvmove shc-3.8.7]# |
You can download the script from here, if you want to check.
Leave A Comment