亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 6589 | 回復: 13
打印 上一主題 下一主題

shell腳本中如何嵌入二進制數(shù)據(jù) [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2008-08-06 10:09 |只看該作者 |倒序瀏覽
5可用積分
有誰知道shell腳本中如何嵌入二進制數(shù)據(jù)?以前有人在論壇里問過,但沒有人給出確切的答案,在網(wǎng)上搜索也沒有結果,有沒有高人指點迷津?

下面的腳本已經(jīng)去掉了后面緊跟著的二進制數(shù)據(jù)。

#! /bin/sh
skip=222
# This script was generated using Makeself 1.5.5
CRCsum=3603969685
MD5=00000000000000000000000000000000
label="CrossOver Linux Professional"
script=./setup.sh
targetdir=cxoffice
scriptargs=""
keep=n
TMPROOT=${TMPDIR:=/tmp}
finish=true
xterm_loop=""
# Shells really don't like CR/LFs. So use some CR/LF-resistant
# code to perform a quick sanity check.
crlf_sentry=
if [ -n "$crlf_sentry" ]; then #
  echo "Line ends have been converted to CR/LF." #
  echo  #
  echo "You need to download the installer again, as this one" #
  echo "has been corrupted." #
  echo  #
  echo "If your download appeared to be successful, try a different" #
  echo "browser. Some browsers, such as Netscape, are known to corrupt" #
  echo "some types of binary files by trying treating them as text." #
  echo  #
  exit 2 #
fi #
LOKISCRIPTPATH=`which $0 2>/dev/null`
if [ ! -f "$LOKISCRIPTPATH" ]; then
  LOKISCRIPTPATH=$0
fi
echo $LOKISCRIPTPATH | egrep "^/" >/dev/null
rc=$?
if [ $rc -ne 0 -a -f "$LOKISCRIPTPATH" -a -f "`pwd`/$LOKISCRIPTPATH" ]; then
  LOKISCRIPTPATH="`pwd`/$LOKISCRIPTPATH"
fi
export LOKISCRIPTPATH
if tail -n 1 /dev/null >/dev/null 2>&1
then
  TAIL_CMD="tail -n"
else
  TAIL_CMD="tail"
fi
[ x"$1" = x-xwin ] && {
finish="echo Press Return to close this window...; read junk"; xterm_loop=1; shift 1;
}
if [ x"$1" = "x-help" -o x"$1" = "x--help" ]; then
  cat << tac
1) Getting help or info about $0 :
  $0 --help   Print this message
  $0 --info   Print embedded info : title, default target directory, embedded script ...
  $0 --lsm    Print embedded lsm entry (or no LSM)
  $0 --list   Print the list of files in the archive
  $0 --check  Checks integrity of the archive

2) Running $0 :
  $0 [options] [additional arguments to embedded script]
  with following options (in that order)
  --confirm             Ask before running embedded script
  --keep                Do not erase target directory after running embedded script
  --target NewDirectory Extract in NewDirectory
tac
  exit 0;
fi
if [ x"$1" = "x-lsm" -o x"$1" = "x--lsm" ]; then
  cat << EOF_LSM
no LSM
EOF_LSM
  exit 0;
fi
if [ "$1" = "--info" ]; then
        echo Identification: $label
        echo Target directory: $targetdir
        echo Uncompressed size: 63244 KB
        echo Compression: gzip
        echo Date of packaging: Fri Jan  5 12:24:05 CST 2007
        echo script run after extraction: $script $scriptargs
        [ x"$keep" = xy ] && echo "directory $targetdir is permanent" || echo "$targetdir will be removed after extraction"
        exit 0;
fi
if [ "$1" = "--list" ]; then
        echo Target directory: $targetdir
        $TAIL_CMD +$skip "$0" | gzip -cd | tar tvf -
        exit 0;
fi
if [ "$1" = "--check" ]; then
sum1=`$TAIL_CMD +6 "$0" | cksum | sed -e 's/ /Z/' -e 's/        /Z/' | cut -dZ -f1`
[ "$sum1" != "$CRCsum" ] && {
  echo "Error in checksums $sum1 != $CRCsum"
  exit 2;
}
if [ $MD5 != "00000000000000000000000000000000" ]; then
# space separated list of directories
  [ x"$GUESS_MD5_PATH" = "x" ] && GUESS_MD5_PATH="/usr/local/ssl/bin"
  MD5_PATH=""
  for a in $GUESS_MD5_PATH; do
    if which $a/md5 >/dev/null 2>&1 ; then
       MD5_PATH=$a;
    fi
  done
  if [ -x $MD5_PATH/md5 ]; then
    md5sum=`$TAIL_CMD +6 "$0" | $MD5_PATH/md5`;
    [ $md5sum != $MD5 ] && {
      echo Error in md5 sums $md5sum $MD5
      exit 2
    } || { echo check sums and md5 sums are ok; exit 0; }
  fi
  if [ ! -x $MD5_PATH/md5 ]; then
      echo an embedded md5 sum of the archive exists but no md5 program was found in $GUESS_MD5_PATH
      echo if you have md5 on your system, you should try :
      echo env GUESS_MD5_PATH=\"FirstDirectory SecondDirectory ...\" $0 -check
  fi
else
  echo check sums are OK ; echo $0 does not contain embedded md5 sum ;
fi
        exit 0;
fi
[ x"$finish" = x ] && finish=true
parsing=yes
x11=y
while [ x"$parsing" != x ]; do
    case "$1" in
      -confirm|--confirm) verbose=y; shift;;
      -keep|--keep) keep=y; shift;;
      -nox11|--nox11) x11=n; shift;;
      -target|--target) if [ x"$2" != x ]; then targetdir="$2"; keep=y; shift 2; fi;;
      *) parsing="";;
    esac
done
mask=`umask`
umask 077
if [ x"$keep" = xy ]; then echo "Creating directory $targetdir"; tmpdir=$targetdir;
else tmpdir="$TMPROOT/selfgz$$"; fi
mkdir $tmpdir || {
        echo 'Cannot create target directory' $tmpdir >&2
        echo 'you should perhaps try option -target OtherDirectory' >&2
        eval $finish; exit 1;
}

# Create a wrapper script which can be exec'd so we don't lock the CD
wrapperbase=`basename "$LOKISCRIPTPATH"`-wrapper
wrapperpath="$tmpdir/$wrapperbase"
echo '#!/bin/sh' >"$wrapperpath"
[ x"$keep" = xy ] || echo "trap 'echo Signal caught, cleaning up > /dev/tty; cd \"$TMPROOT\"; /bin/rm -rf \"$tmpdir\"; exit 15' 1 2 15" >>"$wrapperpath"
echo "$script $scriptargs $*" >>"$wrapperpath"
echo "cd $TMPROOT" >>"$wrapperpath"
if [ x"$keep" = xy ] ; then
    echo "exec rm -f \"$wrapperpath\"" >>"$wrapperpath"
else
    echo "exec rm -rf \"$tmpdir\"" >>"$wrapperpath"
fi
chmod +rx "$wrapperpath"
umask $mask
location="`pwd`"
if [ -x /usr/bin/printf ]
then
  echo_n=/usr/bin/printf
elif [ -x /usr/ucb/echo ]
then
  echo_n="/usr/ucb/echo -n"
else
  echo_n="echo -n"
fi
if [ x$SETUP_NOCHECK != x1 ]; then
    $echo_n "Verifying archive integrity..."
    sum1=`$TAIL_CMD +6 "$0" | cksum | sed -e 's/ /Z/' -e 's/        /Z/' | cut -dZ -f1`
    [ "$sum1" != "$CRCsum" ] && {
        echo "Error in check sums $sum1 != $CRCsum"
        echo
        echo "You need to download the installer again, as it is corrupt."
        echo
        echo "If your download appeared to be successful, try a different"
        echo "browser. Some browsers, such as Netscape, are known to corrupt"
        echo "some types of binary files by trying treating them as text."
        echo
        eval $finish; exit 2;
    }
    echo OK
fi
if [ $MD5 != "00000000000000000000000000000000" ]; then
# space separated list of directories
  [ x$GUESS_MD5_PATH = x ] && GUESS_MD5_PATH="/usr/local/ssl/bin"
  MD5_PATH=""
  for a in $GUESS_MD5_PATH; do
    if which $a/md5 >/dev/null 2>&1 ; then
       MD5_PATH=$a;
    fi
  done
  if [ -x $MD5_PATH/md5 ]; then
    md5sum=`$TAIL_CMD +6 "$0" | $MD5_PATH/md5`;
    [ $md5sum != $MD5 ] && {
      echo "Error in md5 sums $md5sum $MD5"
      eval $finish; exit 2;
    }
  fi
fi
UnTAR() { tar xvf - || { echo Extraction failed. > /dev/tty; kill -15 $$; } ; }
echo "Uncompressing $label"
cd $tmpdir ; res=3
[ "$keep" = y ] || trap 'echo Signal caught, cleaning up > /dev/tty; cd $TMPROOT; /bin/rm -rf $tmpdir; eval $finish; exit 15' 1 2 15
if (cd "$location"; $TAIL_CMD +$skip "$0"; ) | gzip -cd | UnTAR |  (while read a; do $echo_n .; done; echo; ); then
        uid=`id | sed -e 's/^uid=\([0-9]*\)(.*/\1/'`
        gid=`id | sed -e 's/^.* gid=\([0-9]*\)(.*/\1/'`
        chown -Rf $uidgid .
    res=0; if [ x"$script" != x ]; then
                if [ x"$verbose" = xy ]; then
                        echo "OK to execute: $script $scriptargs $* ? [Y/n] "
                        read yn
                        [ x"$yn" = x -o x"$yn" = xy -o x"$yn" = xY ] && { exec "./$wrapperbase"; res=$?; }
                else
                        exec "./$wrapperbase" ; res=$?
                fi
                #[ $res != 0 ] && echo "The program returned an error code ($res)"
        fi
    [ "$keep" = y ] || { cd $TMPROOT; /bin/rm -rf $tmpdir; }
else
  echo "Cannot decompress $0"; eval $finish; exit 1
fi
eval $finish; exit $res
END_OF_STUB

最佳答案

查看完整內(nèi)容

分割線是就是準備讓你分割數(shù)據(jù)時用的,如果你不用這條線怎么分割?

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設計版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
2 [報告]
發(fā)表于 2008-08-06 10:09 |只看該作者
原帖由 hinux 于 2008-8-6 15:29 發(fā)表
sed '1,/^__ARCHIVE_FOLLOWS__/d' $0 >$$.tar.gz
在這條語句里也用到了__ARCHIVE_FOLLOWS__,是不是也起到變量的作用?

分割線是就是準備讓你分割數(shù)據(jù)時用的,如果你不用這條線怎么分割?

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設計版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
3 [報告]
發(fā)表于 2008-08-06 10:24 |只看該作者

論壇徽章:
0
4 [報告]
發(fā)表于 2008-08-06 14:46 |只看該作者
看不大懂簡單模擬:
cat >test.sh <<\EOF
#! /bin/bash
sed '1,/^__ARCHIVE_FOLLOWS__/d' $0 >$$.tar.gz
tar tzvf $$.tar.gz
rm -f $$.tar.gz
exit
__ARCHIVE_FOLLOWS__
EOF
chmod +x test.sh
echo this is a test >test
tar -czf - test >>test.sh
./test.sh


有沒有關于這方面的更詳細的說明?

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設計版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
5 [報告]
發(fā)表于 2008-08-06 15:09 |只看該作者

回復 #3 hinux 的帖子

只要第一行的 #!寫好
后面幾進制都無所謂,這個不需要更詳細說明吧?

論壇徽章:
0
6 [報告]
發(fā)表于 2008-08-06 15:16 |只看該作者
-_"
#!是shell腳本稱為“幻行”的開頭我當知道啦,我想知道的是怎么把包或二進制的可執(zhí)行文件植入shell腳本中,然后是怎樣執(zhí)行的。

論壇徽章:
0
7 [報告]
發(fā)表于 2008-08-06 15:18 |只看該作者
./test.sh
+ sed '1,/^__ARCHIVE_FOLLOWS__/d' ./test.sh
+ tar tzvf 31780.tar.gz
-rwx--x--x root/root        15 2008-08-06 14:40:33 test
+ rm -f 31780.tar.gz
+ exit

還是沒看出__ARCHIVE_FOLLOWS__的作用來。

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設計版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
8 [報告]
發(fā)表于 2008-08-06 15:26 |只看該作者
原帖由 hinux 于 2008-8-6 15:18 發(fā)表
./test.sh
+ sed '1,/^__ARCHIVE_FOLLOWS__/d' ./test.sh
+ tar tzvf 31780.tar.gz
-rwx--x--x root/root        15 2008-08-06 14:40:33 test
+ rm -f 31780.tar.gz
+ exit

還是沒看出__ARCHIVE_FOLL ...



那只是分割“包或二進制的可執(zhí)行文件”與腳本的線,隨便你寫成什么都行啊

論壇徽章:
0
9 [報告]
發(fā)表于 2008-08-06 15:29 |只看該作者
sed '1,/^__ARCHIVE_FOLLOWS__/d' $0 >$$.tar.gz
在這條語句里也用到了__ARCHIVE_FOLLOWS__,是不是也起到變量的作用?

論壇徽章:
0
10 [報告]
發(fā)表于 2008-08-06 16:56 |只看該作者
waker忽略了一點,sed會自動給數(shù)據(jù)最后加上\n,這樣數(shù)據(jù)就有問題了,用tail沒有問題。
錯了,是我用vi編輯的時候添加的。
還是注釋一下吧:
walkerxk@www:~/test$ cat a.sh
#!/bin/bash
tail -n +3 $0 > hash;exit         #把從第三行開始的數(shù)據(jù)保存到hash文件,并且退出。這里要求文件前面的腳本是2行,如果行數(shù)不對,自己改-n后面的+3
walkerxk@www:~/test$ cat a.sh bash >b.sh     #合并腳本和二進制文件
walkerxk@www:~/test$ bash b.sh                 #運行腳本
walkerxk@www:~/test$ md5sum *ash           #校驗文件,發(fā)現(xiàn)文件一樣
807b337f4c3804cf9a196359dcc61e2b  bash
807b337f4c3804cf9a196359dcc61e2b  hash
walkerxk@www:~/test$
當然,那行腳本你可以寫很多東西,比如:
tail -n +3 $0 > a.tar.gz;tar -zxf a.tar.gz -C /tmp/a/;cd /tmp/a/;bash install.sh;exit
或者拆成多行的話是這樣:
tail -n +7 $0 > a.tar.gz
tar -zxf a.tar.gz -C /tmp/a/
cd /tmp/a/
bash install.sh
exit

[ 本帖最后由 walkerxk 于 2008-8-6 17:39 編輯 ]
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP