Commit d887af54 authored by Alex Yustasov's avatar Alex Yustasov Committed by Automatic Converter

3.7-alt1

- initial release
parents
copy: *.patch
tar.gz: shc suffix=.tgz
--- Makefile.old 2005-01-27 00:16:40 +0200
+++ Makefile 2005-01-27 00:16:58 +0200
@@ -1,29 +1,29 @@
# Makefile
#
-INSTALL_PATH = /usr/local
+INSTALL_PATH =$(RPM_BUILD_ROOT)/usr
# For SCO
-CFLAGS = -b elf -O -D_SVID
+#CFLAGS = -b elf -O -D_SVID
# For IRIX
-CFLAGS = -xansi -fullwarn -O3 -g0
+#CFLAGS = -xansi -fullwarn -O3 -g0
# For Solaris
-CFLAGS = -fast -xO4 -s -v -Xa
+#CFLAGS = -fast -xO4 -s -v -Xa
# For HPUX
-CFLAGS = -Wall -O -Ae
+#CFLAGS = -Wall -O -Ae
# For OSF1
-CFLAGS = -w -verbose -fast -std1 -g0
+#CFLAGS = -w -verbose -fast -std1 -g0
# For GNU C compiler
CFLAGS = -Wall -O6 -pedantic
-SHELL = /bin/sh
+SHELL = /bin/bash
-all: shc ask_for_test
+all: shc
shc: shc.c
$(CC) $(CFLAGS) $< -o $@
@@ -63,9 +63,8 @@
install: shc
@echo '*** Installing shc and shc.1 on '$(INSTALL_PATH)
- @echo -n '*** Do you want to continue? '; read ANS; case "$$ANS" in y|Y|yes|Yes|YES) ;; *) exit 1;; esac;
install -c -s shc $(INSTALL_PATH)/bin/
- install -c -m 644 shc.1 $(INSTALL_PATH)/man/man1/
+ install -c -m 644 shc.1 $(INSTALL_PATH)/share/man/man1/
clean:
rm -f *.o *~ *.x.c
Name: shc
Version: 3.7
Release: alt1
Summary: Generic shell script compiler
License: GPL
Group: Development/Other
URL: http://www.datsi.fi.upm.es/~frosal/
Packager: Alex Yustasov <yust@altlinux.ru>
Source0: %name-%version.tgz
Patch0: %name-3.7-makefile.patch
%description
A generic shell script compiler. shc takes a script, which is
specified on the command line and produces C source code. The
generated source code is then compiled and linked to produce a
stripped binary executable. Use with care.
%prep
%setup -q -n %name-%version
%patch0
%build
%make
%install
%__mkdir_p $RPM_BUILD_ROOT{%_bindir,%_man1dir}
%makeinstall
%files
%_bindir/*
%doc CHANGES Copying shc.README shc.html
%_mandir/man?/*
%changelog
* Wed Jan 26 2005 Alex Yustasov <yust@altlinux.ru> 3.7-alt1
- initial release
CHANGES
3.7 Wed Jun 18 16:32:26 CEST 2003
Thanks to Philipp Koller <philipp@open.ch> for:
- Removed all strings in the compiled script.
- Improved program output and error messages.
- The -m option allows to define the *complete* expiration message.
- Updated manpage shc.1.
Thanks to Bryan <bryan.hogan@dstintl.com> for:
- Fix wrong $0 on ksh.
3.6 Fri Feb 21 09:40:32 CET 2003
Two new options:
-D switch on Debug exec calls.
-T switch off unTraceable.
Bash does not need -- after -c.
3.5 Mon Jan 20 19:08:43 CET 2003
Rewrite of large strings to silence the ISO C89 compiler
warnings about strings larger than 509 characters.
3.4 Tue Apr 16 17:43:12 CEST 2002
Remove "bad alignment" problem on AIX and other systems.
Where exists, use /proc/<pid>/as in untraceable.
3.3 Thu Jan 24 21:27:07 CET 2002
Prevent to ptrace the process.
3.2 Tue Mar 9 19:03:54 CET 1999
Find ancient pclose that must be fclose.
3.1 Tue Feb 16 21:36:59 CET 1999
Fixed a misbehavior on scripts with a in-frist-line option
equal to "end of options" (i.e. #!/bin/sh -- )
(Thanks to Bernard Blundell <blundell@lts.sel.alcatel.de>)
Stupid GCC "warning: return type of `main' is not `int'" removed.
3.0 Tue Oct 14 14:20:52 MET DST 1997
Added a new option "-r" to force a relaxed security and
so make a redistributable binary.
Modified expiration day format. Now is dd/mm/yyyy.
3.0b3 Fri Jun 6 22:09:05 WET DST 1997
Yet other few bugs fixed.
Output format simplified.
-pedantic compilation.
3.0b2 Tue Jun 3 17:51:51 GMT 1997
Some explicit type conversions removed.
Fixed the bug "END_OF_FILE" when compiling the generated code.
A flush is needed before a pclose.
st_blksize and st_blocks struct stat fields does not exist on
SCO, both not used now.
3.0b1 Wed Feb 26 14:27:22 WET 1997
The main difference with 2.4 is that in it the script was
compressed an then shuffle around, now int 3.0 the script is encripted
with an inline code, so not needend any external comand to work, and been
faster at startup. Other related adventage is that the only information
not encripted in .x.c is an stamp, expiration date and provider email
address.
Something equivalent to cheksums have been used to enforced at
execution that the executing shell has not been modified from the time
the script was compiled. If anybody tries to change the excuting shell,
.x will refuse to execute.
The generated .x.c source code is now readable.
This diff is collapsed. Click to expand it.
# Makefile
#
INSTALL_PATH = /usr/local
# For SCO
CFLAGS = -b elf -O -D_SVID
# For IRIX
CFLAGS = -xansi -fullwarn -O3 -g0
# For Solaris
CFLAGS = -fast -xO4 -s -v -Xa
# For HPUX
CFLAGS = -Wall -O -Ae
# For OSF1
CFLAGS = -w -verbose -fast -std1 -g0
# For GNU C compiler
CFLAGS = -Wall -O6 -pedantic
SHELL = /bin/sh
all: shc ask_for_test
shc: shc.c
$(CC) $(CFLAGS) $< -o $@
ask_for_test:
@echo '*** Do you want to probe shc with a test script?'
@echo '*** Please try... make test'
test: make_the_test ask_for_strings
make_the_test: match.x
@echo '*** Running a compiled test script!'
@echo '*** It must show files with substring "sh" in your PATH...'
./match.x sh
match.x: match.x.c
$(CC) $(CFLAGS) $< -o $@
match.x.c: shc match
@echo '*** Compiling script "match"'
CFLAGS="$(CFLAGS)" ./shc -v -r -f match
ask_for_strings:
@echo '*** Do you want to see strings in the generated binary?'
@echo '*** Please try... make strings'
strings: make_the_strings ask_for_install
make_the_strings: match.x
@echo '*** Running: "strings -n 5 '$<'"'
@echo '*** It must show no sensible information...'
strings -n 5 $<
ask_for_install:
@echo '*** Do you want to install shc?'
@echo '*** Please try... make install'
install: shc
@echo '*** Installing shc and shc.1 on '$(INSTALL_PATH)
@echo -n '*** Do you want to continue? '; read ANS; case "$$ANS" in y|Y|yes|Yes|YES) ;; *) exit 1;; esac;
install -c -s shc $(INSTALL_PATH)/bin/
install -c -m 644 shc.1 $(INSTALL_PATH)/man/man1/
clean:
rm -f *.o *~ *.x.c
cleanall: clean
rm -f shc *.x
#
# sed script to wrapp C code as a C string.
#
# Duplicate unquoted %
s/[^\\]%/&%/g
#
# Unquote quoted %
s/\\%/%/g
#
# Duplicate \
s/\\/\\\\/g
#
# Quote "
s/"/\\"/g
#
# End each line with new-line
s/^.*$/&\\n/
#
# Enclose each line within "
s/^.*$/"&"/
#
#!/bin/sh
#
# File search script by <workexp@csc.liv.ac.uk>
# Usage: match [Filename]
#
IFS=":$IFS"
for substring in $@
do
for path in $PATH
do
for command in $path/*$substring*
do
if [ -f $command ]
then
echo $command
fi
done
done
done
# Added
echo "[$$] PAUSED... Hit return!"
read DUMMY
#! /bin/sh -x
echo "$0" "$@"
ps $$
ps wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww $$
cat /proc/$$/cmdline
touch $0.kk
read ENTER
#
# sed script to extract C code wrapped as a C string.
#
# Remove "s enclossing each line
s/^"\(.*\)"$/\1/
#
# Remove trailing new-line
s/^\(.*\)\\n$/\1/
#
# Unquote "
s/\\"/"/g
#
# Unduplicate \
s/\\\\/\\/g
#
# Quote unquoted and unduplicated %
s/\([^\\%]\)%\([^%]\)/\1\\%\2/g
#
# Unduplicate unquoted %
s/\([^\\]%\)%/\1/g
.TH shc 1 "Jun 18, 2003" "shc Version 3.7"
.UC 4
.SH "NAME"
shc - Generic shell script compiler
.SH "SYNOPSIS"
.B shc
[ \-\fBe\fP date ]
[ \-\fBm\fP addr ]
[ \-\fBi\fP iopt ]
[ \-\fBx\fP cmnd ]
.br
[ \-\fBl\fP lopt ]
[ \-\fBACDhTv\fP ]
\-\fBf\fP script
.SH "DESCRIPTION"
.B shc
creates a stripped binary executable version of the script
specified with \fI\-f\fP on the command line.
The binary version will get a \fI.x\fP extension appended
and will usually be a bit larger in size than the original ascii code.
Generated C source code is saved in a file with the extension \fI.x.c\fP
If you supply an expiration date with the \fI\-e\fP option the
compiled binary will refuse to run after the date specified.
The message \fB"Please contact your provider"\fP will be displayed instead.
This message can be changed with the \fI\-m\fP option.
You can compile any kind of shell script, but you need to supply valid
\fI\-i\fP, \fI\-x\fP and \fI\-l\fP options.
The compiled binary will still be dependent on the shell specified
in the first line of the shell code (i.e. #!/bin/sh), thus \fBshc\fP does not create
completely independent binaries.
\fBshc\fP itself is not a compiler such as cc, it rather encodes and
encrypts a shell script and generates C source code with the added expiration
capability. It then uses the system compiler to compile a stripped binary
which behaves exactly like the original script. Upon execution, the compiled binary
will decrypt and execute the code with the shell \fI-c\fP option.
Unfortunatelly, it will not give you any speed improvement as a real C program would.
\fBshc\fP's main purpose is to protect your shell scripts from modification or
inspection. You can use it if you wish to distribute your scripts but don't
want them to be easily readable by other people.
.SH "OPTIONS"
The command line options are:
.TP
.B -e date
Expiration date in dd/mm/yyyy format [none]
.TP
.B -m message
message to display upon expiration ["Please contact your provider"]
.TP
.B -f script_name
File name of the script to compile
.TP
.B -i inline_option
Inline option for the shell interpreter i.e: -e
.TP
.B -x comand
eXec command, as a printf format i.e: exec(\\\\'%s\\\\',@ARGV);
.TP
.B -l last_option
Last shell option i.e: --
.TP
.B -r
Relax security. Make a redistributable binary which executes on
different systems running the same operating system.
.TP
.B -v
Verbose compilation
.TP
.B -D
Switch on debug exec calls
.TP
.B -T
Allow binary to be traceable (using strace, ptrace, truss, etc.)
.TP
.B -C
Display license and exit
.TP
.B -A
Display abstract and exit
.TP
.B -h
Display help and exit
.SH "ENVIRONMENT VARIABLES"
.TP
.B CC
C compiler command [cc]
.TP
.B CFLAGS
C compiler flags [none]
.SH "EXAMPLES"
.SM
Compile a script which can be run on other systems with the trace
option enabled:
example% \fBshc\fP -v -r -T -f myscript
.SH "BUGS"
The maximum size of the script that could be executed once compiled is limited
by the operating system configuration parameter
.B _SC_ARG_MAX
(see
.BR sysconf ( 2 )\c
)
.SH "AUTHOR"
Francisco Rosales
<frosal@fi.upm.es>
.SH "REPORT BUGS TO"
the author.
Purpose:
A generic shell script compiler. Shc takes a script, which is
specified on the command line and produces C source code. The
generated source code is then compiled and linked to produce a
stripped binary executable. Use with care.
Building:
Just do a "make"
Testing:
Try: "make test"
or: "shc -v -f match" then "match.x sh"
Caveat emptor: see Copyright
The results look fine to me, but I havn't used this in anger, but
the author has used shc for his work widely over SunOS, Solaris and
Linux, and done some testing on Irix and HPUX.
We tested it on a few SMALL ksh scripts - big tasks should probably
be written in C in the first place (see _SC_ARG_MAX below)!
Bugs:
The one (and I hope the only) limitation using shc is the
_SC_ARG_MAX system configuration parameter.
It limits the maximum length of the arguments to the exec function,
limiting the maximum length of the runnable script of shc.
!! - CHECK YOUR RESULTS CAREFULLY BEFORE USING - !!
Archived at: ftp://hpux.csc.liv.ac.uk/hpux/Languages/shc-2.4a
Archived by: steff@csc.liv.ac.uk
Author: Francisco Rosales Garcia
--------------------------------------------------------------------
Francisco Rosales García <frosal@fi.upm.es> TEL: +341 336 73 80
http://www.datsi.fi.upm.es/~frosal FAX: +34 1 336 73 73
Departamento de Arquitectura y Tecnología de Sistemas Informáticos
Facultad de Informática. Universidad Politécnica de Madrid. España
--------------------------------------------------------------------
This diff is collapsed. Click to expand it.
<HTML>
<HEAD>
<TITLE>shc(1)</TITLE>
<link rel=stylesheet type="text/css" href="/css/osix.css">
</HEAD>
<BODY>
<H1>Manpage for shc(1)</H1>
<PRE>
<!-- Manpage converted by man2html 3.0.1 -->
</PRE>
<H2>NAME</H2><PRE>
shc - Generic shell script compiler
</PRE>
<H2>SYNOPSIS</H2><PRE>
shc [ -e date ] [ -m addr ] [ -i iopt ] [ -x cmnd ]
[ -l lopt ] [ -ACDhTv ] -f script
</PRE>
<H2>DESCRIPTION</H2><PRE>
shc creates a stripped binary executable version of the
script specified with -<I>f</I> on the command line.
The binary version will get a .<I>x</I> extension appended and will
usually be a bit larger in size than the original ascii
code. Generated C source code is saved in a file with the
extension .<I>x</I>.<I>c</I>
If you supply an expiration date with the -<I>e</I> option the com-
piled binary will refuse to run after the date specified.
The message "Please contact your provider" will be displayed
instead. This message can be changed with the -<I>m</I> option.
You can compile any kind of shell script, but you need to
supply valid -<I>i</I>, -<I>x</I> and -<I>l</I> options.
The compiled binary will still be dependent on the shell
specified in the first line of the shell code (i.e.
#!/bin/sh), thus shc does not create completely independent
binaries.
shc itself is not a compiler such as cc, it rather encodes
and encrypts a shell script and generates C source code with
the added expiration capability. It then uses the system
compiler to compile a stripped binary which behaves exactly
like the original script. Upon execution, the compiled
binary will decrypt and execute the code with the shell -<I>c</I>
option. Unfortunatelly, it will not give you any speed
improvement as a real C program would.
shc's main purpose is to protect your shell scripts from
modification or inspection. You can use it if you wish to
distribute your scripts but don't want them to be easily
readable by other people.
</PRE>
<H2>OPTIONS</H2><PRE>
The command line options are:
-e date
Expiration date in dd/mm/yyyy format [none]
-m message
message to display upon expiration ["Please contact
your provider"]
-f script_name
File name of the script to compile
-i inline_option
Inline option for the shell interpreter i.e: -e
-x comand
eXec command, as a printf format i.e:
exec(\\'%s\\',@ARGV);
-l last_option
Last shell option i.e: --
-r Relax security. Make a redistributable binary which
executes on different systems running the same operat-
ing system.
-v Verbose compilation
-D Switch on debug exec calls
-T Allow binary to be traceable (using strace, ptrace,
truss, etc.)
-C Display license and exit
-A Display abstract and exit
-h Display help and exit
</PRE>
<H2>ENVIRONMENT VARIABLES</H2><PRE>
CC C compiler command [cc]
CFLAGS
C compiler flags [none]
</PRE>
<H2>EXAMPLES</H2><PRE>
Compile a script which can be run on other systems with the
trace option enabled:
example% shc -v -r -T -f myscript
</PRE>
<H2>BUGS</H2><PRE>
The maximum size of the script that could be executed once com­
piled is limited by the operating system configuration parameter
_SC_ARG_MAX (see <B>sysconf(2)</B>)
</PRE>
<H2>AUTHOR</H2><PRE>
Francisco Rosales &lt;frosal@fi.upm.es&gt;
</PRE>
<H2>REPORT BUGS TO</H2><PRE>
the author.
</PRE>
<P>
</BODY>
</HTML>
#!/bin/bash -x
echo "\$@ is $@"
echo "command line: $0 $*"
echo "hello world"
# Added
echo "[$$] PAUSED... Hit return!"
read DUMMY
exit 0
#!/bin/csh -x
echo Hello world
# A comment
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment