[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

ascode 的一些资料汇编

本帖最后由 CrLf 于 2012-12-23 16:01 编辑

此汇编非彼汇编,它是特殊汇编的资料汇编...唔,越讲越乱
-----------------------------------------------------------------------------------------------------------------
ascode是什么(引用自批处理与其他语言混合编程2):
这类汇编程序的特殊性在于,所有的代码全部分布于ASCII码表的可显示字符范围中,当然这样的程序不是碰巧得到的,而是人为的构造出来的,其中需要用到许多技巧。比如最常见的中断调用代码int 21(CD 21),因为不在ASCII可显示字符范围内,所以用到许多压栈、出栈、增减代码来构造,所以它的代码段是动态变化的。这样的代码被叫做 ASCODE,这样的技术被称作 ASCII Assemble,一门即将消失的技术,可想而知,这样的代码构造起来是困难的,在网上流传的ASCODE只有很少量的是人为构造的,因为已经有成熟的技术可以将任何二进制文件转变为ASCODE,这样的过程叫encode。而ASCODE执行的过程需要decode,合称codec,codec 的算法已知的超过4种,比较有名的应该是Herbert Kleebauer的算法,不过它要求原程序必须有org 170H的类似标记,因为前面的文件头被用来存放decode代码。

后文链接的帖子中如果提到 cn-dos,请自行将链接中的 www.cn-dos.net 替换为备份站点地址 cndos.fam.cx(站点由 qzwqzw 提供)
-----------------------------------------------------------------------------------------------------------------
据说几种编码名称:
uuencoded
base64
binhex
XXencoded
yencoded
能搜就自己搜下吧,反正我是没谷歌到...

-----------------------------------------------------------------------------------------------------------------
cn-dos 全文搜索 ascode 的一些链接(来自 Batcher):
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode
http://cndos.fam.cx/forum/viewth ... mp;highlight=ascode

-----------------------------------------------------------------------------------------------------------------
cn-dos 的搜索结果里整理出的内容:

双句柄同步输出:
  1. echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>tee.com
  2. echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>tee.com
  3. echo @VyI?@xAp~sA`LZNxOq@Kt@FB?sUs`LbLB?tgj`{gjB~0x>>tee.com
  4. tee.com >a.txt 2>b.txt
复制代码
根据输入创建bat:
  1. @echo off
  2. echo BATCH_INPUT___hgQX-PPP_XPPP E#HH0E50EG0Ef0Ehs>myinput.com
  3. echo myinput.bat hoAX5@@PZYh@xX5@D3!r/P[WX,b,-PZh>>myinput.com
  4. echo X3!X2ErP,{,{PYX4=0ErWX,j,-PZh@@X3!=set input>>myinput.com
  5. echo Enter your name:
  6. myinput.com
  7. call myinput.bat
  8. echo Hello %input%
复制代码
将输入的内容输出:
  1. echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5x>in.com
  2. set /p passwd=enter your QQ password:<nul
  3. for /f "tokens=*" %%i in ('in.com') do set passwd=%%i
  4. del /f in.com >nul 2>nul
复制代码
字节长度计算:
  1. :0hmrX-D@-r0P[h$pX-p#P]3/1/horX-D@-r0P[h?EX-r#P]3/1/h#rX-cA-@0P[1/3/UXtoum
复制代码
-----------------------------------------------------------------------------------------------------------------
bathome 全文搜索 ascode 找到的一些帖子,只贴链接代码就不发了。粗筛了一下有所创新的,如有遗漏请跟帖补充:
小型二进制文件ASCII编码器
【挑战】批处理如何创建仅含一个nul字符的文件
[挑战]如何不换行输出以等号或引号开头的行?
屏蔽命令行密码(见附)

附:《屏蔽命令行密码》一贴中 techon 提供的资料:
你可以从下面的连接看到Herbert Kleebauer所参与的3000多个帖子,里面有大量的批处理技术讨论和代码,看来他主要活跃于google group。
http://groups.google.com/groups/ ... xUGDBtnv2zlXxVZTWPs
1

评分人数

    • 老刘1号: 很强大!可惜64位不支持技术 + 1

TOP

回复 2# Demon


    thanks,回头研究下。
    小规模的工程还是可以目测手算的,很累但是很好玩,代码也比较短。稍大的工程恐怕没这个精力,应该用解码段+文本数据段来实现了,有构思,不过貌似早就有了,只是作为一只半英盲实在是谷歌不到

TOP

回复  Demon


    thanks,回头研究下。
    小规模的工程还是可以目测手算的,很累但是很好玩,代码 ...
CrLf 发表于 2012-12-24 00:21


关键在于这种技术的英文名称是什么,ascode或者ascii assemble是否只是以讹传讹的称呼,Google这两个关键词什么都找不到。

TOP

回复 4# Demon


    汗,这个倒是挺蛋疼的,可惜资料少,也许 qzw 会知道吧~

TOP

ASCII Assemble和ASCODE只是圈内人的叫法
并没有得到大范围的公认
该技术的源起于HK和Laura等几位大能的互动
主要活跃时期大概是2000年前后的五六年
相关技术、代码、大能主要散见在Usenet下面几个讨论组中
alt.msdos
alt.msdos.batch
alt.msdos.batch.nt
如果还能访问到Google Group对Usenet的镜像的话
应该还能查到那些讨论的邮件帖子
之前曾经收集过一些代码和技术讨论
不过还是回家找一找再看吧
天的白色影子

TOP

回复 1# CrLf

uuencoded
base64
binhex
XXencoded
yencoded

这些编码大多都不应该算作ASCII Assemble
ASCII Assemble的明确定义我没有找到
但是它有一些显而易见区别与其它技术的特征
最主要的就是ASCODE可以直接保存为.com文件在OS中运行
这与某些二进制转ASCII文本的技术相区别
     
另外为了批处理编写以及网络交流的方便
ASCODE代码中尽量避免利用特殊含义的字符做code
TAB 空格 回车 换行 < > | ‘ ”

另外根据就是早期的文本编辑习惯
批处理代码一般是以80为每行的右边界
所以ASCODE代码一般每行控制在60个字符左右
也因此代码中的回车换行空格等符号也应该可以被“忽略”
天的白色影子

TOP

回复 7# qzwqzw


    为了压缩代码,有三个特殊字符实在避不开,不过好在不多,对于行长度的控制倒是实现了,断行的位置刚好在正中间~不过更新算法貌似多次运行会出错,不知道是什么鬼原因,真的是鬼原因,完全没法调试,认栽了,Fuck...实在解决不了的话,只好把上次的算法改改来用了,那样的话没法压缩长度,恐怕又要到 60h

TOP

Herbert Kleebauer 的 ASCII 汇编教程

How to include binaries into batch files?
========================================

(source code in source.zip)

To include com programs into batch files you have to
write programs which only uses opcodes in the range
0x20 to 0x7e (without  < > | % ^ & " !). Small programs
can be directly coded using the processor opcode table.
Two examples are ech and myinput:

ech.com is similar to the echo command. It writes the
command line after the first " till the penultimate
character to stdout (without an trailing CRLF)

myinput.com assigns a keyboard input to batch variable
  1. @echo off
  2. echo XP,;P_,EP0Ex0Ez0Em3Em-ZBP(Eiu![j@_YQ2M@53#@CI~.8'uxCISZ[SC5.bM!C>ech.com
  3. ech.com "line with <>|^&%">tmp.txt
  4. ech.com "but no CRLF">>tmp.txt
  5. del ech.com
复制代码
  1. @echo off
  2. echo BATCH_INPUT___hgQX-PPP_XPPP E#HH0E50EG0Ef0Ehs>myinput.com
  3. echo myinput.bat hoAX5@@PZYh@xX5@D3!r/P[WX,b,-PZh>>myinput.com
  4. echo X3!X2ErP,{,{PYX4=0ErWX,j,-PZh@@X3!=set input>>myinput.com
  5. echo Enter name:
  6. myinput.com
  7. call myinput.bat
  8. del myinput.com
  9. del myinput.bat
  10. echo You entered %input%
复制代码
For larger programs (more than a few bytes) it is simpler to use
a program to convert a normal com program to an ascii-only program.
The batch below does this job. NOTE: you must assemble your com
program with ORG=0x178 because the first 120 bytes are needed for
the decoding routine which is inserted by the convert program.
Six bits of the original com program are coded in one ascii-byte,
so your program must not exceed 47 kbyte. The decoding routine of
the convert program is (just as MYINPUT and ECH) directly written with
ascii-only opcodes, the rest of the program is a normal com program,
converted by itself to ascii only bytes.
  1. rem - save the lines below as CONVERT.BAT
  2. rem - write a COM program and assemble it with ORG=0x178 (PROG.COM)
  3. rem   (you must not use the standard ORG=0x100 for this com programs!!!!)
  4. rem - enter: CONVERT PROG.COM PROG.BAT
  5. rem - the BATCH file PROG.BAT contains an encoded form of PROG.COM
  6. @echo off
  7. echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>bat.com
  8. echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>bat.com
  9. echo ??wQ@tyM?WxI?@zA=`Lbw?y_y~?_xA[bz?B_L??oAN`_H?e?as?Fx?pkz?>>bat.com
  10. echo B_}A[aIA]b@MCs?A_rVAgr?\gBGpangV_~r?TO?wGJLy?hKxAG@z?G`L?K>>bat.com
  11. echo K?wQO`LRaRPdwA_by??cxA_bL?@O=Et`x?y_z?P_L?@oXZ`SdBW\ngbTiA>>bat.com
  12. echo _Syi?To_gD_lWPOOnSOOOTg`ODgDCDgLCDgNCDg**grKDgtKDgWKDYdKT>>bat.com
  13. echo \QQTDDDTQXTTCqWP}=w@s`aTnbmSILl@gbdTo_n@EwCTokO@mwWDOosPW=>>bat.com
  14. echo kOrFsTnsAP~c?@xHOTV_TPoWvDTvFTV_XPnzuPWAuTuFqSwDoStHFTusgD>>bat.com
  15. echo a}}Oms`DlnbTdILOngbT}o_?`a}SbmsPLlnD??I??~?OBA@TEDCTHGFTKJ>>bat.com
  16. echo ITNMLTQPOTTSRTWVUTZYXTp\[D`_1TcbaTfedTihgTlkjTonmTrqpTutsT>>bat.com
  17. echo xwvT=zyD?}=D????}}??s`aTnbmSILl@gbdTg_nP0>>bat.com
  18. bat.com <%1 >%2
  19. del bat.com
复制代码
An example for a program generated with CONVERT is echoo. echoo
is similar to  echo, but you can also include binary characters
by specifying the hex code:
  1. @echo off
  2. echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>echoo.com
  3. echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>echoo.com
  4. echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg>>echoo.com
  5. echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0>>echoo.com
  6. echoo This line contains $3c $3e $7c $25 and $24  $0d$0a
  7. echoo           All leading spaces are removed
  8. echoo (to get identical results in DOS/Win9x/NT/2000)$0d$0a
  9. echoo $20       insert a explitcit space ($2420) if you want leading spaces.
  10. del echoo.com
复制代码
As an other example you can use this method to generate a hex-to-binary
converter with ascii-only opcodes. This allows you to include any binary
file into a batch file. h2b.com has a string as a parameter. Any line
in stdin, starting with this string, is converted from hex to binary and
written to stdout.
  1. @echo off
  2. if exist %0.bat %0.bat
  3. echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>h2b.com
  4. echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>h2b.com
  5. echo ?@}I{uNWEF~NFAa_Lj@KLtH]~CEvEFIKbAa_wN@SuNS`{ECCttasae~BHM>>h2b.com
  6. echo AcjFnvnHAwrvx[}gIKDw??Frt\gqj~{?s?csIsqo{O_KtBve{Sx{nB{Eu@>>h2b.com
  7. echo fq`tkfk?e@oKCA_?_E@?WxAs?agBwRjnLK?s@w`G`LKLAcyA?@xAsZpk`L>>h2b.com
  8. echo ~KxlqLct@vAc_A_yBJ@xAGZp?o?sBXq`LR@xUrFQt=A_E?B?~rB?~r0>>h2b.com
  9. h2b "::f1" <%0 >bild1.gif
  10. h2b "::f2" <%0 >bild2.gif
  11. h2b "::f3" <%0 >demo.com
  12. del h2b.com
  13. :: hex dump of bild1.gif
  14. ::f1 4749463839614b001100a20000140b00fffbf7ff6600fffcfa0000000000
  15. ::f1 000000000000002c000000004b0011000003a228badcfe30ca0901bd386b
  16. ::f1 66b7ff5f078e64242a419aa2eabaa84cebb2731d2cc39357f1cd0ab306ec
  17. ::f1 e503fa5cc8e26cc06c30778d53f0e758d988c6c715f7643ca10ae9902abc
  18. ::f1 6db35372faebed86cb4399d23c6f917b32079bdb7c576169687354816702
  19. ::f1 7b0a887e5a747f79593f8583897d7c0f6258695b9b479d58893a26704976
  20. ::f1 909041a493a61e2725ae25adafb2acb3b52100b8b9babbbcbdbebfc0c1bf
  21. ::f1 09003b
  22. :: hex dump of bild2.gif
  23. ::f2 47494638396121001000b30000fffdfbff6702ffc39aff9e5effdfcaffef
  24. ::f2 e5fff8f4ffffffc0c0c00000000000000000000000000000000000000000
  25. ::f2 0021f90401000008002c0000000021001000000463f0c849abbd385f3384
  26. ::f2 fe9911041e2811432a1499300e00388c743010d83ce26deddf16110d78d1
  27. ::f2 f96a1dd6c485e4518ed0a1406044962451a80aa5751eaadd0a73a8a48c8f
  28. ::f2 83f2a480548bd1ee892e0d2a4c05841886793581847d7e1f007882862611
  29. ::f2 003b
  30. :: hex dump of an executable
  31. ::f3 fcbe3301bf4301b95000b020f3aa89fab91000f3a4bbffffb93c00b409cd
  32. ::f3 21b40bcd2108c0750801dae2f0f7dbebe9b44ccd21707265737320616e79
  33. ::f3 206b65790d0a24
复制代码
A further method is, to make a dual executable file. Such a file
is a valid batch program and a valid com program. You can generate
such files with the following batch:
  1. rem - save the lines below as CONVERT.BAT
  2. rem - write a COM program and assemble it with ORG=0x200 (PROG.COM)
  3. rem   (you must not use the standard ORG=0x100 for this com programs!!!!)
  4. rem - enter: CONVERT PROG.COM PROG.BAT
  5. rem - the BATCH file PROG.BAT contains an encoded form of PROG.COM
  6. @echo off
  7. echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>ube.com
  8. echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>ube.com
  9. echo ??wQ@tyM@CxA?@zA=`Lbw??`y~?_xB{_z?B_L??oAN`_H?e?as?Fx?pkz?>>ube.com
  10. echo B_}A{bIB}_@MCs?A_rVAgr?\gBGpangV_~r?TO?wGJxy?xBxAG@z?G`L?K>>ube.com
  11. echo K?wQO`LRaRPdwB?`y??cxB?`L?@O=Et`x??`z?F_L?@oXZ`S?BW\gBDTN_>>ube.com
  12. echo NPLEEDyyI?M_mOhqNT_brD___?gS_S_rhD_rhDa_`P`mhT_xqDlnbTdg_S>>ube.com
  13. echo dc`T_mq@mnCTLsfCyyI?M_mOteNT__m@___?cd_S_shDdgsThe_SsrqTrp>>ube.com
  14. echo _?hk_SrdmTmh_Sgs_S_rhDkheTLmd@yyI?M_mODcNP?iWTtyiD?`oOOgsO>>ube.com
  15. echo OOOT`OOT`CgChCgCjCgCGCgSRKgSTKgSwKgCnK**KgSQQYTDD\TXTDTqW>>ube.com
  16. echo QDOWCTyIL?_my?oWMDEWCTokO@gwWDOssPW=kOrJsTysE@sSsDc?TDHO~S>>ube.com
  17. echo `JxDWUVTVFoS_XTDzUVDAUnTFqWPDoUPHFWTsgtTILk?myy?Lo_??~IOBA>>ube.com
  18. echo @TEDCTHGFTKJITNMLTQPOTTSRTWVUTZYXTp\[D`_1TcbaTfedTihgTlkjT>>ube.com
  19. echo onmTrqpTutsTxwvT=zyD?}=D????IL??myy?my_?0>>ube.com
  20. ube.com <%1 >%2
  21. del ube.com
复制代码
As an example, here is a binary executable batch header
(source code: echadd.mac) which supports 2 functions:

e (echo)  and  + (increment)


The increment function increments a decimal number by 1.

example: ube.com +123

will write 124 to stdout (note: no space allowed after +
and after the number)



The echo function is similar to the standard echo command.
The text after the echo command is written to stdout. No
<CR> <LF> is appended. You can output any byte by writing
the hex value ($3c for < or $0d for <CR> ...). $t writes
the current date in the form yymmdd to stdout. After
writing the command line text, echo reads from stdin and
writes to stdout until a <CR> or <EOF> is read. This byte
transfer from stdin to stdout can be modified by subcommands:

l converts all characters to lower case
u converts all characters to upper case
_ converts all spaces to _
. will copy until the first .  (.. until the second . and so on)
: will copy after the first .  (:: after the second . and so on)

The @ must be the first character in the batch file and there must
be no trailing spaces in the first 13 lines.
  1. @EChO OFF
  2. ::. NOrisc     This is a binary com header. Don't
  3. ::. NOfun      edit the first 13 lines in this file.
  4. ::. NO$EXj@jz50!@4(PPPPPPa(D!(D)(D+(DH(LS(LU(L8(L/(LEZRR]EEEUYRX2DXP
  5. ::. NX0DXFP,0Xx(t4P,=XtKsF4:tT4U@$?PIyK!WVX0GWUY WV;oVBX2GV0EXGIuht,
  6. ::. ?A}I{uNWNN}VINw`{ECCus_ssd{Sj{_?B@spNxH]HTw`}@qr?C}bux{OCEFKNMoS
  7. ::. gqx=B@GoBYyE?@xAuwNTECIQtk{SE}CK{B_?CttD_M}B1{BO}CtpB`E?tm{OE}CK
  8. ::. {Ba?CtyCaM}B_{B?NMt\ICwd{ECCwtcCs{?QNltPisEHH`LbuuGN@BpozGgbgBYp
  9. ::. G?PaKgonOG?w?FgJBYyE?ExA?WgJ?@xAgCj~g?Wqg?Tqj?Fqzgx]dq?Ss?H[Y_`X
  10. ::. I{B?{osLRsLS_EuBs~B[IxUCq`{Sy{OOjKvp@{GO{Eq@AvYDu_soB`E?Es~Ft_{O
  11. ::. 1oAWaEuBs~B[Ix\Ctm{OE}tMjBaom{nA}LtpBaM?EFtpBaE?]j?m?_gBgXjzB?So
  12. ::. ????quuBoDB?FHoGpBBDcB?1~sIGLZp{aB`ksBY`@z?H`L?KINBf?Ecc?_KbxVkV
  13. ::. C?Bw_?f{_?Co_?Br0
  14. REM ***************** WIN98 batch***************************
  15. REM This batch file will read a word from keyboard,  convert
  16. REM all filenames with this extention to upper case, replace
  17. REM spaces in the filename by _ and insert the current  date
  18. REM in font of the new filename
  19. if [%1]==[] goto main
  20. _ <nul e $t%1|_ >>__.bat eu_ $0d$0aren %1
  21. goto ende
  22. :main
  23. if exist %0 copy %0 _.com
  24. if exist %0.bat copy %0.bat _.com
  25. _ <nul e enter file extention:
  26. _ >__.bat e set ext=
  27. call __.bat
  28. del  __.bat
  29. LFNFOR on
  30. for %%i in (*.%ext%) do call %0 "%%i"
  31. LFNFOR off
  32. del _.com
  33. echo check __.bat and execute it
  34. REM call __
  35. :ende
复制代码
To assemble the source code files, download
ftp://137.193.64.130/pub/assembler/ass486.zip

[email]hk@unibwm.de[/email]

相关附件下载链接: https://pan.baidu.com/s/12FKVNV2spI4UET1MkICjGg?pwd=vi4g
天的白色影子

TOP

Encoding Binary Data into Batch Code

I wrote this up at the beginning of 2002 but did not post it for a few reasons.. the main reason being the BASM dos compiler was replaced with a Windows-based version. Tokiwa disappeared as well, or at least was hiding the last time I looked. ASIC is still around in archives and the Moonrock page works, at least there are a couple tiny-com compilers the modern simple problem-solver can use. Recently I've noticed a renewed interest in how ascii assembler works, and even if my application of it is a bit extreme this document provides a decent overview and links to tools. One usually does not write ascii-assembler by hand if it can possibly be helped, rather encoding/decoding techniques are used to translate existing machine code into batch-legal code. NT-like OS's redefine what is legal, be very careful using some of the raw translaters since they output code NT/XP/etc will not interpret correctly, when machine code is involved the results can be unpredictable, why I adopted a more complicated but compatible approach. If I was smart enough to write a compatible one-step encoder I would but I'm mostly batch and high-level, machine code isn't my thing unless it's for a PIC.

Standard disclaimers, not responsible if you fry your computer using these techniques and programs. Machine code can do just about anything, including horribly crash the computer the errant code is running on. Who knows my code might have a bug, all I can say is it works on my Windows 95 machine, and the output runs under XP. The batch code will likely need adapting to your environment if used, especially CONV2BAT since it is so compiler-specific. If you need to do stuff like this you probably have other specific needs, consider crafting your own solution that best suits your needs, taking code here and elsewhere as examples.

Contents:

Binary to Batch Encoding Techniques
Binary Batch Echo Rules
A Universal Batch-Compatible Encoder and Decoder
Com-file Compilers and Conv2Bat.bat
Conv2Bat.bat file
DecBin assembly source
EncBin assembly source
Using Conv2Bat and Reusing Binary Batch Code
Links to binary batch code and compiler resources
Many times when programming in batch it is necessary to use binary data of one kind or another, be it a helper utility or simply a file without a return at the end. For the purpose of this article, binary means a sequence of bytes where the bytes can take on any value without restriction and can represent a machine code program, a gif file or any other arbitrary file. The important thing is the sequence has to remain exact, there can be no system-created changes or malfunction will likely occur. MsDos Batch is an ascii-based language which can only write files that end in CrLf (Ascii 13, 10), and cannot directly write certain characters that mean other things to the system unless specific steps are taken to ensure syntactic legality. Most of the time batch files are written to use already-existing binary files, however there are times when a single file solution would be better, particularly when distributing a solution for others to use but also to avoid accumulating extra files for trivial purposes.

Just like any programming tool there are advantages and drawbacks. Advantages: Binary-to-batch (Bin-batch) encoding techniques enable batch programmers to recreate any small file as needed. Bin-batch tools let the batch programmer write complex functions in a true HLL (high-level language) then convert it to batch code, rather than relying on unreliable version-specific batch hacks (if the function is even expressible in batch). Carefully constructed bin-batch code can run on all known dos platforms from the earliest MsDos with echo and redirection to Windows XP so long as the underlying app is compatible. Bin-batch text cannot be modified by com-infecting viruses and is safer to redistribute than raw com files, provided of course the files are clean to begin with. Any change is visible and changes the way the encoded ascii "reads" (phrases that randomly appear in a particular routine's encoded text).

Disadvantages: Encoding obscures the original content, and people are fearful of code that cannot be discerned. Depending on the context, bin-batch is no more and arguably less dangerous than simply distributing the binaries with the batch, however in an area where binaries generally are not allowed such as a discussion newsgroup. Posting bin-batch code can get you majorly flamed, in alt.msdos.batch only very small binaries written by known authors are tolerated. Bin-batch code is always a bit slower than merely accessing already-existing binaries, and it adds another layer of possible incompatibility. Creating executable binaries on-the-fly might be against company policy or require specific approval. Some lockdown-style anti-virus (AV) programs prevent the creation of executable code altogether when enabled, other AV programs slow down bin-batches because they have to scan each line of the binary file as it is written to disk. Using a separate decoder greatly reduces scanning overhead by creating the binary in one scanned step (only the decoder has to be scanned line-by-line), or write the com to a file with a non-executable extension then rename before running.

Binary to Batch Encoding Techniques

The old MsDos debug command is probably the most common method of encoding binary data for batch, the command is available on most systems but it is possible the user removed or renamed it, and if booting from floppy you'll have to make sure the debug command is available by putting it on the disk. Debug more than triples the unencoded file size so is best used for very small routines. Numerous debug-encoding utilities are available.

It is possible to write small machine code programs that consist entirely of batch-legal characters and echo it directly to a com file for execution, this method is handy for echoing characters without a CrLf, inputting data and other simple functions that otherwise cannot easily be done in batch. Writing such "ascii assembler" code though is a tedious affair even when one is familiar with assembly, often the results contain more code for patching incompatible bytes than for the task itself but still the utilities rarely exceed a few lines of ascii. Herbert Kleebauer and Laura Fairhead are established experts in this area and have published many useful ascii machine code batch routines on the alt.msdos.batch newsgroup over the years.

Among the most interesting of bin-batch utilities are com-file encoders. After being echoed to disk the com file consists of a decoder consisting entirely of batch-echoable ascii characters followed by an ascii-encoded representation of the original machine code program. When the com runs, the decoder decodes the original code and executes it, if all goes well the original code is not aware of the process. Herbert Kleebauer's Convert.bat program requires that the machine code be assembled at an offset to make room for the decoder. Laura Fairhead's Cm3.com program goes a step further and appends a copy routine, permitting it to encode standard com files.

The method I settled on uses a CM3-encoded decoder that decodes data from one redirected file to another, allowing any small file to be encoded and recreated exactly regardless of its contents. There is more overhead running machine code programs this way but the same decoder can be used multiple times, and the decoding process doesn't produce as much AV scanner activity since only the decoder itself is written line-by-line to a com file. A major reason for going with a separate decoder was to be able to control the encoding process myself, CM3 sometimes produced NT-incompatible output on the 2nd line.

Binary Batch Echo Rules

The code should consist of characters entirely between ascii 32 and 127, if not then nul, eof, bs, tab, cr, lf and probably other characters must be avoided. Must survive editing.
Avoid lines that begin with on[space] or off[space].
Must avoid redirection characters (|<>) unless surrounded by quotes.
Percent characters (%) must be doubled (%%) to result in a single percent in the file.
NT - the characters & and ^ must be avoided.
NT - Avoid [delim][digit] at the end of a line. [delim] is space, semicolon or parenthesis, [digit] is 0-9.
Tricky stuff! Cross-compatibility information can be hard to come by so there may be errors or omissions in the above. Best to keep the encoding method simple as possible to avoid errors with some platforms.

A Universal Batch-Compatible Encoder and Decoder

For my encoding scheme I chose to reduce the range of characters from 256 to 64 starting at ascii 48 ("0") to pack 1.5 bytes per pair of encoded characters. To assure batch compatibility ascii 58 thru 64 (":" to "@") and ascii 94 thru 96 ("^" to "`") are skipped. This encoding scheme doesn't reach the problem ascii 124 pipe character. To create my solution I started with another binary-ascii encoder/decoder pair named zencode/zdecode by Tenie Remmel and replaced the 13-bit (91 position) binary fetch code with by own 12-bit code, along with changes to offset and skip as needed. I further modified the decoder so that it outputs a single RET instruction should the decoded size not match the size recorded at the beginning of the encoded data. Not as good as a checksum but at least provides some protection. The decoder is encoded using CM3, for batch use and distribution the encoder can be encoded by itself. Note that my encoder converts to raw ascii, echo redirection to a file must be added to include within a batch.

Here is a batch containing the decoder which I call "DecBin" and used to decode the encoder I call "EncBin"...
  1. @echo off
  2. set dec=decbin.com
  3. set enc=encbin.com
  4. set tf=encbin.tmp
  5. ::---------------------
  6. :: CM3-encoded DecBin decoder...
  7. ECHO:`h}aXP5y`P]4nP_XW(F4(F6(F=(FF)FH(FL(Fe(FR0FTs*}`A?+,>%dec%
  8. ECHO:fkOU):G*@Crv,*t$HU[rlf~#IubfRfXf(V#fj}fX4{PY$@fPfZsZ$:NvN$>>%dec%
  9. ECHO:9AyroNB-)dOKwK0rRkfTbi)ws_~[[q9wE'sqlu1sY*Bsfe=@ziNS1a)88e>>%dec%
  10. ECHO:f9RTL)9Z{3INBD?o6@MDLO{Zz4Q23E-'09NX9@Vz(42A7c8zMS:u$w6k5Q>>%dec%
  11. ECHO:N,h:le)~gF?tutTyxoe5UiIdtn';0rJ1q:{7;lAl']y:yTjZBbOo?QRIdN>>%dec%
  12. ECHO:$Bp@P/nAp_r0*4f'XcF4q3o?$_t5lx$Q-OxSfUNQ__Gd~$Q-Oxgkx=LGHU>>%dec%
  13. ECHO:S)$C6P8#>>%dec%
  14. ::---------------------
  15. :: the EncBin encoder, encodes stdin to stdout, encoded by itself...
  16. ECHO:AALIxnCmeRf0\Uf0pWjXYBlxr0MyG02u022nc1Z5Z0r4G2ldMAj[8F34dd>%tf%
  17. ECHO:Z1Z0r4G2ld6Aj[8F34Ed3EmbG02lJpNl0jjjCt9v0407ZvjtS3I0j7rvLv>>%tf%
  18. ECHO:G203l0wUDv20F42eD3ZujTS6fmprbD2e4uwp39gwYdfDfAdng0f1f0ZF2t>>%tf%
  19. ECHO:04bemDCXj0C0LHtA2701ZsG0SFdfW]6630Jf36S6W1f0rJ2fMfQYW1YAoO>>%tf%
  20. ECHO:EAt0y[36S6W1[8LRi3}>>%tf%
  21. ::---------------------
  22. :: decode encoder...
  23. %dec% < %tf% > %enc%
  24. if errorlevel 1 echo error decoding binary
  25. if not errorlevel 1 echo Created encoder in %enc%
  26. echo Created decoder in %dec%
  27. del %tf%
复制代码
To encode a binary manually using encbin.com run: encbin < binary > file then edit file and add "echo " or "echo:" at the beginning and redirection to the desired file at the end of each line. To do this automatically as part of a binary-to-batch batch presents a bit of difficulty, either the symmetry and simplicity of the encoder/decoder pair has to be broken by including echo and file redirection in the encoder output, or the problem can be simply solved using encoded HLL.

Com-file Compilers and Conv2Bat.bat

Several BASIC-like compilers produce com files small enough to encode for batch usage, just about all of them can be found on the Basm page (see links). Each of these has its own particular syntax which has to be memorized, at least where in the doc file the info can be found. For the most part it's like regular basic but expressions must be highly simplified and some of the commands have slightly different syntax. Basm works the best for me but each have strengths and weaknesses... Basm and Moonrock produce assembly source which can be used for hand-tweeking the compiler output. Basm provides easy access to stdin and stdout and produces simple, stable code that should run on any platform that supports dos (I have no info about NT/2000/XP compatibility, I'd guess probably ok). Moonrock worked with everything I wrote with it but the bounce.moo demo crashes and takes down Windows on my machine. Asic is the most complete but the com file often is inflated in size and must be compressed using PkLite or equivalent. Tokiwa does floating point math but I don't know much about it.

The compiler binaries and batch files need to be in path directories so they can be operated by issuing simple dos commands in the directory the source is in. Usually linking batches (@c:\path\prog.exe %1 %2 etc) in a path dir are ok for compilers but some command line parms cannot be passed (specifically asm's ";" no-prompt option) and anything that uses redirection to specify input or output must be available in binary form. On my system I have link batches for asicc.exe, mrc.exe and tbc.com, with basm.exe, asm.exe, freelink.exe and moonrock's mrlink.com in a path directory. In its default configuration Moonrock uses A86 to assemble the output, to use asm unzip mrcasm.cfg from config.zip and rename to mrc.cfg, and make sure everything listed is on the path. Of course it's not necessary to install and learn all of these, to use Basm all you need is Basm, Asm and Freelink.

Conv2bat.bat combines compiling and converting to batch into one step usable from Windows' right-click menu system. Asicc is called to compile asi files, basm/asm/freelink for bas files, Moonrock's mrc for moo files and Tokiwa's tbc for tok files. Notepad or any other text editor can be used to create the source, keep shortcuts to the docs handy. After compiling the source, Conv2bat encodes it into batch form, leaving a .com file and a .bat file with the same base name as the original source file. A batch-commented version of the original source is included in the output batch to help remember what the binary does. If the specified file's extension isn't a supported source file then Conv2Bat encodes it directly to batch, edit the output batch code as needed to use the binary.

All that sounds easy enough... for a real language! Problems... If batch is used as a drag and drop target the current directory is not set to where the file is, rather it must be determined from the passed filename. Essentially the extension must be separated from the rest of the filename but doing anything besides adding strings together is outside the scope of batch. After encoding with EncBin, "ECHO:" and ">>file" (one > on the first line, file is variable) needs to be added to each line to create runnable batch code. To include source code, "::" needs to be inserted before each line. A batch that does all that using only standard commands (if you count debug) is possible, a QBasic script would work, but the former would take quite a bit of hack-style programming, and QBasic isn't installed on every system (and flashes). Binary batch blocks written in Basm easily solved all these problems.

NT compatibility should be reasonably good but NT's find command doesn't return an errorlevel, the part that documents whether or not the com file was compressed with PkLite won't work properly but code output is not affected. Getting away from incompatibilities like this is a major reason for using binary batch (I just hope it doesn't create new incompatibilities), but since this one is minor so I don't think I'll fix unless I get an NT-like system. There may be other incompatibilities I don't know about, all I have is 95 and the Win95Cmd Cmd emulator to test with.

Here is Conv2Bat... (skip to source or more docs)
  1. :: CONV2BAT.BAT - this batch converts HLL source or an
  2. :: existing file (<40K) into equivalent batch code.
  3. :: Required components... (assumed to be on the path)
  4. ::  for ASIC (asi): ASICC
  5. ::  for BASM (bas): BASM ASM FREELINK
  6. ::  for Moonrock (moo): MRC (plus asm/link in mrc.cfg)
  7. ::  for Tokiwa (tok): TBC
  8. :: Compresses com with PKLITE, uses Dos6+ FC and FIND to
  9. :: determine if compressed for comments. Disable below.
  10. :: The temp variable must point to a writable directory.
  11. :: This batch is designed to operate by drag-drop, from
  12. :: Windows' right-click menus, or from a dos prompt.
  13. :: Usage: CONV2BAT [path\]filename.ext
  14. :: If extension is asi bas moo or tok then produces
  15. :: filename.bat containing batch-encoded binary with
  16. :: attached source, in addition to compiler output.
  17. :: If ext not supported then encodes binary to batch.
  18. :: Tested in Win95, should be dos and NT-tolerent except
  19. :: for compression test (see comments) but maybe more.
  20. :: This is free software and comes with no guarantee,
  21. :: test thoroughly before distributing the output code.
  22. :: Last major mod 12/08/01, last mod 1/03/02
  23. :: (C) Copyright 2002 Terry Newton
  24. :: EncBin encoder, DecBin decoder and Basm helpers
  25. :: are public domain, use as you wish.
  26. @echo off
  27. if .%1==.Shell goto %1
  28. if not .%1==. if exist %1 goto fileexists
  29. echo  Compiles HLL source and converts to batch
  30. echo  Usage: CONV2BAT [path\]filename.ext
  31. echo  Compiles .asi .bas .moo and .tok files
  32. echo  encodes other types directly to batch
  33. goto end
  34. :fileexists
  35. :: shell with lots of environment space
  36. %comspec% /e:30000 /c %0 Shell %1
  37. goto end
  38. :Shell
  39. ::**** options, edit as needed...
  40. :: usepklite=yes to compress with pklite
  41. set usepklite=yes
  42. :: usetempdir=yes to use temp dir in output code
  43. set usetempdir=no
  44. :: decname=filename used for decoder
  45. set decname=_d.com
  46. :: tempname=filename used for temp file
  47. set tempname=_t.tmp
  48. :: extension to output batch code to
  49. set outputext=bat
  50. :: callconv2cfg=yes to put variables in conv2cfg.bat
  51. set callconv2cfg=no
  52. :: temp filenames...
  53. set dec=%temp%.\_decbin.com
  54. set enc=%temp%.\_encbin.com
  55. set file2bat=%temp%.\_2bat.com
  56. set cmntsrc=%temp%.\_cmntsrc.com
  57. set sepname=%temp%.\_sepname.com
  58. set replace=%temp%.\_replace.com
  59. set tf=%temp%.\_tf.tmp
  60. set tf1=%temp%.\_tf1.tmp
  61. set tf2=%temp%.\_tf2.tmp
  62. :: override variables if configured...
  63. if .%callconv2cfg%==.yes call conv2cfg.bat
  64. :: double check...
  65. set xyz=0123456789012345678901234567890123456789
  66. if not .%xyz%==.0123456789012345678901234567890123456789 goto end
  67. set xyz=
  68. echo.
  69. echo  **** CONV2BAT **** 12/8/01 WTN
  70. echo  Checking file support...
  71. ::-----------------------
  72. :: CM3-encoded DecBin decoder...
  73. ECHO:`h}aXP5y`P]4nP_XW(F4(F6(F=(FF)FH(FL(Fe(FR0FTs*}`A?+,>%dec%
  74. ECHO:fkOU):G*@Crv,*t$HU[rlf~#IubfRfXf(V#fj}fX4{PY$@fPfZsZ$:NvN$>>%dec%
  75. ECHO:9AyroNB-)dOKwK0rRkfTbi)ws_~[[q9wE'sqlu1sY*Bsfe=@ziNS1a)88e>>%dec%
  76. ECHO:f9RTL)9Z{3INBD?o6@MDLO{Zz4Q23E-'09NX9@Vz(42A7c8zMS:u$w6k5Q>>%dec%
  77. ECHO:N,h:le)~gF?tutTyxoe5UiIdtn';0rJ1q:{7;lAl']y:yTjZBbOo?QRIdN>>%dec%
  78. ECHO:$Bp@P/nAp_r0*4f'XcF4q3o?$_t5lx$Q-OxSfUNQ__Gd~$Q-Oxgkx=LGHU>>%dec%
  79. ECHO:S)$C6P8#>>%dec%
  80. ::---- EncBin-encoded binary ----
  81. :: sepname.com made with BASM ASM FREELINK
  82. ECHO:AEPPr64U2y00tD61O0AAj7CDXn28A5S5D7JeRkl5Ll00xG47uvgmv5gl[5>%tf%
  83. ECHO:gGC0v]U[2uY7213301EBu1Je13dnJDrX5OIZO5QZO5ibr1Vbj3AxS5Ayv6>>%tf%
  84. ECHO:Zb02ibf3Axv6Rbf2RbC2Ayv6Jbf3abb3Axv62yK6ebr12rK6ZbC2ib42Ay>>%tf%
  85. ECHO:v6ab[3Axv6Eyj5Rb42Dn3e0J]xN53b8l3b6l3bB\2jG0gC7DB7n6j50037>>%tf%
  86. ECHO:v6j5000mF0cdr5ilW6tfC106Ld2ZNH37C6n5003yC6n5EXn5Ou3Hr5S3Fe>>%tf%
  87. ECHO:IGebC3Axv6EXn56u00qbC3ybb1EyG7qb83ExG7Myn5ebb1Dn3e07]XNJ2Z>>%tf%
  88. ECHO:ND2xT32yNN3b6M1nf3r76GeJC5eFf5thpXj5Ou3Fv5S3Ve2GR73F0500Rb>>%tf%
  89. ECHO:r2]xn5Iy[7Vb81ebn2Axv6Myr7ib41ubj2hxn5QyC8yb01t3FF451yf3s6>>%tf%
  90. ECHO:EGF0O33FK53yFyeTW5tfv2vpNT1bRl3b933b4Z2yV\3bAX0mF006NH0ev6>>%tf%
  91. ECHO:j5pZn5abW2RyFTW5RlW6rrW2r0v1fpW8sxC2WxND01Dy3e1I]XND2ZNT3b>>%tf%
  92. ECHO:9Z3ynpn59bv6ebv1ebn0Iy[7ZbK20mlZLd2xV\3b2N03b6O5pZn50mj3n6>>%tf%
  93. ECHO:n5Oe3DC5eTW5rhv2vpNT1bV\3b7T3b2\2yV\3b8Z1bNV3b8s1bUK3b8m1b>>%tf%
  94. ECHO:LR3b8g1bNd3b8a1bV\3b8X1bLR3b8R1bNo3b8L1bWp3b8F1bLR3b892n9C>>%tf%
  95. ECHO:F07DAn83Fy3D4me0Z23xlZLI2Au6y0IZK5i3WMLI3x7AcKb5Zjuxlnn2jG>>%tf%
  96. ECHO:m3xfdd30coy3PHLNtBvla0iymyylUhyHg9Z1sVLP73LNPMLNXUuXiyZOXU>>%tf%
  97. ECHO:uRiyZ8s1LVf3yvRmA[DPlxPG2yNy3byRy3TGLMmvdhHo0AN0VrwULOi3Zr>>%tf%
  98. ECHO:6sK0ivZqlfD1Pl0vwQS20ftdBYy3ebaygGZ8]3v0gxEBOUK5IXK5tBDIr5>>%tf%
  99. ECHO:46w8I33y1yC2Fy2tK0Bqr37rqa2r2j2ElnnFjGSv1nW5f0trZ0Jvb]p857>>%tf%
  100. ECHO:ZYv7WVK186K5y3hXW6s3uyhXW6ryr0gGv6hXW6rnuyhXW6r1C0lyQX3bva>>%tf%
  101. ECHO:xxQX2yPG3bvUxxPG3bvWxyPG2BF83rpA603u9yCBF0M819DFZsn0Vhy3hX>>%tf%
  102. ECHO:W6uruxhXC6F9l0CWTo16D1ZsLHVn6sK02yK6Fvv]E[m786K5013yG6K5t3>>%tf%
  103. ECHO:DKb55ov4vELK2tLO2nn9jXtB5Ib5ZJexlBGUK5EAyxFEFRAn3DCGkLlBtB>>%tf%
  104. ECHO:Hp2yPG2BPE3vRmA[0ml8n5N2041LlBt3Bf0ma0X6ixXpW4t8ix9606I9s6>>%tf%
  105. ECHO:vw001wW6f1[0X6yxgGO6j5f0Xpv4gGC61puxIs1H0esEyvRmA[0ml8f5Z\>>%tf%
  106. ECHO:9Tj4v0iyC5F0M933xxv5mbFxF3LGmbuyyvgGW6K3ujHPRmA[N600N3MBif>>%tf%
  107. ECHO:XpW4r\ixZ86u00QBK42nJDnXN202014000070DGA8D0A07000000000000>>%tf%
  108. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  109. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  110. ECHO:00000000whOW5jPl1g0000000000j0K00h000000001mH\SW1]TXXnOwC0>>%tf%
  111. ECHO:T\1n9]5YPmo\C0LmPnOWP\HrSwn0}>>%tf%
  112. :: BASM source...
  113. :: rem separate specified name into fpath,fbase,fext
  114. :: rem outputs sets to stdout
  115. :: $com
  116. :: a$=command$:a$=trim$(a$):a$=lcase$(a$)
  117. :: if a$="" then
  118. ::  print "no parm":end
  119. :: endif
  120. :: rem loop through string, mark last \ and .
  121. :: slash=0:dot=0:ilen=len(a$)
  122. :: for i=1 to ilen
  123. ::  c$=mid$(a$,i,1):if c$="\" then slash=i
  124. ::  if c$="." then dot=i
  125. :: next i
  126. :: rem not an extension if \ after .
  127. :: if slash>dot then dot=0
  128. :: fpath$="":fbase$=a$:fext$=""
  129. :: if dot>1 then
  130. ::  d=dot-1:fbase$=left$(a$,d)
  131. ::  d=ilen-dot:fext$=right$(a$,d)
  132. :: endif
  133. :: if slash>1 then
  134. ::  rem includes trailing \
  135. ::  d=slash:fpath$=left$(a$,d)
  136. ::  d=len(fbase$):d=d-slash
  137. ::  fbase$=right$(fbase$,d)
  138. :: endif
  139. :: output "set fpath=";fpath$
  140. :: output "set fbase=";fbase$
  141. :: output "set fext=";fext$
  142. ::-------------------------------
  143. :: decode and use _sepname.com to parse input (in %2)
  144. %dec% < %tf% > %sepname%
  145. if errorlevel 1 goto binerror
  146. %sepname% %2 > %temp%.\_sep_tmp.bat
  147. call %temp%.\_sep_tmp.bat
  148. del %temp%.\_sep_tmp.bat
  149. if .%fpath%==. goto incurrent
  150. :: change to source directory
  151. %fpath%
  152. cd %fpath%
  153. :incurrent
  154. if exist %fbase%.%fext% goto curdirok
  155. echo  Could not change to directory
  156. goto cleanup
  157. :curdirok
  158. :: *******
  159. :: ******* compiler support, edit as needed
  160. :: *******
  161. if .%fext%==.asi goto asifile
  162. if .%fext%==.bas goto basfile
  163. if .%fext%==.moo goto moofile
  164. if .%fext%==.tok goto tokfile
  165. echo  Unknown filetype, encoding as-is
  166. set compname=
  167. set madewith=????
  168. set binfile=%fbase%.%fext%
  169. goto conv2batch
  170. :asifile
  171. set compname=ASIC
  172. set madewith=ASICC
  173. if exist %fbase%.com del %fbase%.com
  174. call asicc %fbase%.asi C
  175. goto checkcom
  176. :basfile
  177. set compname=BASM
  178. set madewith=BASM ASM FREELINK
  179. if exist %fbase%.com del %fbase%.com
  180. call basm %fbase%.bas
  181. if exist %fbase%.asm call asm %fbase%.asm ;
  182. if exist %fbase%.obj call freelink /c %fbase%.obj
  183. goto checkcom
  184. :moofile
  185. set compname=Moonrock
  186. set madewith=MRC ASM MRLINK
  187. if exist %fbase%.com del %fbase%.com
  188. call mrc %fbase%.moo
  189. goto checkcom
  190. :tokfile
  191. set compname=Tokiwa
  192. set madewith=TBC
  193. if exist %fbase%.com del %fbase%.com
  194. call tbc /c %fbase%.tok
  195. goto checkcom
  196. :: ******* end compiler commands
  197. :checkcom
  198. set binfile=%fbase%.com
  199. if exist %binfile% goto comexists
  200. echo.
  201. echo  =======================================
  202. echo    Compile failed, debug and try again
  203. echo  =======================================
  204. echo.
  205. goto cleanup
  206. :comexists
  207. if exist %fbase%.obj del %fbase%.obj
  208. :: try to pklite it (if option enabled)
  209. if not .%usepklite%==.yes goto conv2batch
  210. copy %binfile% %tf1% >nul
  211. call pklite %binfile%
  212. fc /b %binfile% %tf1% > %tf2%
  213. find "00" < %tf2% > nul
  214. ::reset var for docs if not changed by pklite...
  215. ::note--not NT compatible here, PkLite status won't
  216. ::be properly indicated in the output batch comments
  217. if errorlevel 1 set usepklite=no
  218. del %tf1%
  219. del %tf2%
  220. :conv2batch
  221. echo.
  222. echo  Converting to batch code...
  223. ::---------------------
  224. :: the EncBin encoder, encodes stdin to stdout, encoded by itself...
  225. ECHO:AALIxnCmeRf0\Uf0pWjXYBlxr0MyG02u022nc1Z5Z0r4G2ldMAj[8F34dd>%tf%
  226. ECHO:Z1Z0r4G2ld6Aj[8F34Ed3EmbG02lJpNl0jjjCt9v0407ZvjtS3I0j7rvLv>>%tf%
  227. ECHO:G203l0wUDv20F42eD3ZujTS6fmprbD2e4uwp39gwYdfDfAdng0f1f0ZF2t>>%tf%
  228. ECHO:04bemDCXj0C0LHtA2701ZsG0SFdfW]6630Jf36S6W1f0rJ2fMfQYW1YAoO>>%tf%
  229. ECHO:EAt0y[36S6W1[8LRi3}>>%tf%
  230. ::---------------------
  231. :: decode encoder...
  232. %dec% < %tf% > %enc%
  233. if errorlevel 1 goto binerror
  234. ::---- EncBin-encoded binary ----
  235. :: 2bat.com made with BASM ASM FREELINK
  236. ECHO:AFDJr64U2y00tD61O0AAj7CDXn28p5j5D7JeRkl5ND00xG47uviEv5iD[5>%tf%
  237. ECHO:gGC0v]U[2ues213301EBu1Je13dnJDrX5OhZf5pZf5JbC2qb04pxj56yb8>>%tf%
  238. ECHO:ybC27b046xb8ubv2qbO26yb8ebv3ybr36xb8qbf2ibK26yb8Zbr36xb8ty>>%tf%
  239. ECHO:46RbK2Do3c7j0mF0e5v5hXr8fYW6sQC206N52ZO[23Gx86v0S37cn13bf3>>%tf%
  240. ECHO:RyC[W6QXW8s7W3rOv2fPW9t\W3tQr3fPW9sbW2r6v2fPW9tJC3F0MZj56x>>%tf%
  241. ECHO:b8Fbj1O335C5b]C6F0O30]f686O[2ZO]3bDc3yOp865bb8Zb437bn16y[9>>%tf%
  242. ECHO:ubK30mlZN52y]H2xOY3b7U03K6j5IZ86t3C[061y[3sLW1rnv3vpO[1b]H>>%tf%
  243. ECHO:3bBB3b6S2yb93bCc3bCU2xb93b7f3b6A2yb93bCN0mF0e5r5hHW9s7C106>>%tf%
  244. ECHO:N52ZO]0mF006O]0eG686QZ86qbr2RyC]W6QHW9tSW2sLv1hHW9uYb2fPf9>>%tf%
  245. ECHO:fbW6ubC2WxMs00Dn3c3\2tb92rOd3bB]23[xf5G0S3Bcn0R70f0600ibb2>>%tf%
  246. ECHO:tx866yWAqbn0t3Cf061n[3tYO0j6YX006GbbW6tkr1fsv6hXW8tx40e3C5>>%tf%
  247. ECHO:bfC6WxOf00Dn3e1u]xOj3b2j2B78bdf6ZO2tC62nJDWXuer0hXW8tPf0Z8>>%tf%
  248. ECHO:dX86YBptYX2no0jXJbn06xWABbW0YBlXOd2BeOh1GAg07DBb2w2x]H3b1e>>%tf%
  249. ECHO:2B78bdf6ZO6t[92nJDWXt]40bdf6ZOAs00xtb52nJDWXtKW0r2r2fpv6h1>>%tf%
  250. ECHO:WArnf0r4hGr4]GsEiyWUOd3b7r2BWU867bv1lnGlq0jXEn0lqyjG0mlAu2>>%tf%
  251. ECHO:y0]Zb5QAmxF0deC5mvdfbAN0Vt73LMgNZx0llsyyyvuleqaHIBy1LUDPkH>>%tf%
  252. ECHO:PNLMsNNbyXxBuONbyRxB78HUDV3uFvv]][N36xf7]yC7ibqy33LNkMxfMh>>%tf%
  253. ECHO:S40AkourLVDOkmC3dsW5y3XLtciyZOgMZq7bey2BoUtBsBVvMBmodBBAxh>>%tf%
  254. ECHO:ko6BiHZBRmcnCB3sfevuVJVaee2GfexBi7Keq3N30mkRDTlyWc3bwXxxWc>>%tf%
  255. ECHO:2yUk3bwOxxUk3bwQxyUk2BF83rpA603u9yCBF0M819DFZsn0Vhy3fcW8rl>>%tf%
  256. ECHO:uyfcC8F9l0CWTo16D1ZsLrVnYsS06yf7Fvv]E[kWYBps3y2tOs2nnyjXol>>%tf%
  257. ECHO:KBJ0TPDGLI8ULV2BpxMi2u022BihJvMBxfdBmlMhSQ6BpBFBx]gn03isBu>>%tf%
  258. ECHO:Cuoqiar8hGBuXFye02asxBq6070VgQLOXl63B70eVtKeV7yOhPZ867pr81>>%tf%
  259. ECHO:JDWXNe0Fabuuy7C6j5012BRQj740R3gLZfQBS46yf7tBG6Fvv]E[F0M81T>>%tf%
  260. ECHO:J200gLZfl3r20ml9s6xBHp3bssveP610Q9Jx0w00Pw2r0129s6xyUk3605>>%tf%
  261. ECHO:2BHp2yUk03spwEYsS0reJxFvv]E[F0M82Bq\N2042ySs0ma0W5u3fsW7rg>>%tf%
  262. ECHO:FxlnnxjXabVxF3KmF0e3G5fw7DBbsewRU9331IKma9WEN32nnvjXZbNx\R>>%tf%
  263. ECHO:W7YBpnnxjXmbJx1Qf1pnFDWXs2Fxj14000070DGA8D0A07000000000000>>%tf%
  264. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  265. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  266. ECHO:00000000000000000W000000000000000x15X3HF0t0x0x0g}>>%tf%
  267. :: BASM source...
  268. :: '2bat infile outfile tmpfile
  269. :: 'reads infile, surrounds each line with
  270. :: '"ECHO:" and ">>tmpfile" (one > 1st line)
  271. :: 'and outputs results to outfile
  272. :: $com
  273. :: $string 120
  274. :: a$=command$:a$=ltrim$(a$):a$=rtrim$(a$)
  275. :: if a$<>"" then
  276. ::  b=instr(a$," ")
  277. ::  if b>0 then
  278. ::   infile$=left$(a$,b)
  279. ::   infile$=rtrim$(infile$)
  280. ::   c=len(a$):c=c-b
  281. ::   tmpfile$=right$(a$,c)
  282. ::   b=instr(tmpfile$," ")
  283. ::   if b>0 then
  284. ::    outfile$=left$(tmpfile$,b)
  285. ::    outfile$=rtrim$(outfile$)
  286. ::    c=len(tmpfile$):c=c-b
  287. ::    tmpfile$=right$(tmpfile$,c)
  288. ::    open infile$ for input as 1
  289. ::    if err=0 then
  290. ::     open outfile$ for output as 2
  291. ::     if err=0 then
  292. ::      done=0:b$=">"
  293. ::      while done=0
  294. ::       line input #1,a$:done=eof
  295. ::       if done=0 then
  296. ::        print #2,"ECHO:",a$,b$,tmpfile$
  297. ::        b$=">>"
  298. ::       end if
  299. ::      wend
  300. ::      close 2
  301. ::      close 1
  302. ::     end if
  303. ::    end if
  304. ::   end if
  305. ::  end if
  306. :: end if
  307. ::-------------------------------
  308. :: decode 2bat utility...
  309. %dec% < %tf% > %file2bat%
  310. if errorlevel 1 goto binerror
  311. ::---- EncBin-encoded binary ----
  312. :: cmntsrc.com made with BASM ASM FREELINK
  313. ECHO:ADLNr64U2y00tD61O0AAj7CDXn28h5G4D7JeRkl5HB00xG47uvgCv4gB[4>%tf%
  314. ECHO:gGC0v]U[2uS1213301EBu1Je13dnJDrX5O]ZC4hZC4ybb0Zb[2hxG42yf6>>%tf%
  315. ECHO:mbj0mbW22xf6ebO1ebv02yf6NbW22xf6ly[4Nbv0Dn3e0J]xIU3b413b2H>>%tf%
  316. ECHO:3b8j2jG0gC7DAtQj2uI]3b9e2XGq2ZIb23Wxb4v0S3Fe6Gdxb4Rbn0RbO0>>%tf%
  317. ECHO:Nb022j2noCjXR62j062GQXb4VbS1pxf42yf6ebK06XG4YZb4t3Eb041nf3>>%tf%
  318. ECHO:rLYGQsW4riW2QjW6rcW2OjW4rZf2u7tB6]W4r1G2gC0lmDGXf3vlyDCGF0>>%tf%
  319. ECHO:AAmxF0bab4Z63xlZGc33QB4ar4yA]X842AyxJEf23D73mvdd0AkoFtkHTM>>%tf%
  320. ECHO:MBBxF0xsyyBvxh7qo96BkV\UN3THLMTMLU7buyYBoUibqyYBk1wUK3muym>>%tf%
  321. ECHO:G]cPu3fEv6hwW5uRFykGPNNvtfcob430XowUXVN3Dm2ZGq3rZ3td3yMBF8>>%tf%
  322. ECHO:Zsr0SutB4e44bcf4WxGa0UW6HFx3v09y0meygGS0yYW3yHZaf0tjZ0xn3D>>%tf%
  323. ECHO:jGC7Ln2rW0hEm0x[W]WT97urv75OO10aC4lyPV3bwJxxPV3b0y2xOE2yPV>>%tf%
  324. ECHO:3bw4xxPV3b0133xyK6VbFyxxK6ty06ubBytx063bFyty06YBj3erWTh0vW>>%tf%
  325. ECHO:gy0mZ0W5w9I33s1wFhlyPV3bv8xxPV0m39WvKWS756I37sLoangHv0fEj6>>%tf%
  326. ECHO:ymG]e3gWZOxsv0ptf4xnFD8XTT0Bkn1PLJsI5IgVZGpx84Au00tBsBivZo>>%tf%
  327. ECHO:hfZAulcofQZHhBmmI]SB[3veiuFJTque08[eyuJrBe2GisZVV600bVLR9O>>%tf%
  328. ECHO:SOU3j2bewNSemqaO]BV8ZH6r127D9Oye2G7bqxR7114400dBq6071XV3j6>>%tf%
  329. ECHO:Ga01v0v6Gc23[x84KQS4uy0cb4fgG4f97DABSU84EAqxiAWUGc2AumyEfm>>%tf%
  330. ECHO:pnn2jGy3hwC5F0M933pxf5ybBxJ3fx7DBbsuy3DJF06ZG4pnFDWXsgixM9>>%tf%
  331. ECHO:C7kLlBtBHp3brKxBi8f1f0XMG4g07D9TB2000101S000bD0[bD00070000>>%tf%
  332. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  333. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  334. ECHO:000000000000000000001h1i9j9XTg0000001]kcP\rWPi1n9]LiTh1[0t>>%tf%
  335. ECHO:0t80jt}>>%tf%
  336. :: BASM source...
  337. :: rem open file specified on command line and write
  338. :: rem to stdout with ":: " prefixed to each line
  339. :: $com
  340. :: a$=command$:a$=trim$(a$)
  341. :: if a$="" then
  342. ::  print "no parm":end
  343. :: endif
  344. :: open a$ for input as 1:e=err
  345. :: if e>0 then
  346. ::  print "file not found":end
  347. :: endif
  348. :: fileloop:
  349. :: line input #1,a$:e=eof
  350. :: if e=0 then
  351. ::  output ":: ";a$:goto fileloop:
  352. :: endif
  353. :: close 1
  354. ::-------------------------------
  355. :: decode cmntsrc utility...
  356. %dec% < %tf% > %cmntsrc%
  357. if errorlevel 1 goto binerror
  358. ::---- EncBin-encoded binary ----
  359. :: replace.com made with BASM ASM FREELINK
  360. ECHO:AGINr64U2y00tD61O0AAj7CDXn28Q587D7JeRkl5S]00xG47uvfav7f][7>%tf%
  361. ECHO:gGC0v]U[2uMDA13301EBu1Je13dnJDrX5OYZ47dZ47Fbv2ibO5pyW9dr00>>%tf%
  362. ECHO:M90maRXTW1s3v3hDWJs[W5sIv5hDW9fD[0W5fmp95T3bCd2yMD7bLB3bKs>>%tf%
  363. ECHO:2y]D2r0Y29C5FRp9K17b43pyWNBbC53b85Qx87pyWPNbj2Jb45pxWPabK4>>%tf%
  364. ECHO:Fbv2pyWPJb45Bb05pxWPZb447br2pyWPBb053bv45d1b]D7bI93bBD2yhD>>%tf%
  365. ECHO:7bJh2xhD6yUD7bB81of3r4]Gr7C2F0tZ47pxWPabS2O30UC7cqv7vETq3b>>%tf%
  366. ECHO:Io3ySpS7obWPJbO43b[2pyWP7bf40mlZSU2y]D6xUD7bC]03r647]ZS7t3>>%tf%
  367. ECHO:Ds871vf3r1xGvETs3bHv3y[pS7obWPFb44VbK2pyWTZbS4Q31s870mF0bU>>%tf%
  368. ECHO:r7hDWPrFC206SU2ZTq0mF006Tq0e[6S7hZS7BbG4RyDuW7QDWPukW3rTv2>>%tf%
  369. ECHO:hDWVrxW4rfr4hDWVskW3rBv2hDWVrfW4rQb4O1obWVFbf3Vbv1pyWRZb44>>%tf%
  370. ECHO:pxWRpyWNBbv1Do3e04ac4k3bFo1dW1QDWVt]W3uIv1hDWRumr3hDvRhDWN>>%tf%
  371. ECHO:uDK1S3Je2Gmc010mlZSU2xxD7b5x03r647UZS7t3Dq871vf3r4]GugC0Wx>>%tf%
  372. ECHO:Tq02Dy3e0raySES7Fbb3RyDqW7QDWVsIW3sxv1hDWVtVv3vETq3bE93ySp>>%tf%
  373. ECHO:S7obWV3b83JbO1pyWVNbW3qe2G3bS3pxS7pyWVNb41JbO3xxS7pyWXab01>>%tf%
  374. ECHO:R7210700BbK3ubS3JbC1pyWZNbK3pxWZEyW7yb81Dn3e04ae1S]xEDAyMD>>%tf%
  375. ECHO:7b4U1nf3r3hGuGpxWZpyWJub01Dn3e0Oab1V3bCH2xU52y6DBb2p3746W7>>%tf%
  376. ECHO:003e6eWxU100j2S3ee6GBbv2pxWXJbv2pxWZubr2pyWXybr2Ry21f7t5t3>>%tf%
  377. ECHO:E1071yf3r4YGrO00f0lnJDrXh7W7tHW1sQW0rc02f0lnJDrXhDvThDWBsQ>>%tf%
  378. ECHO:r0hDvVhDWDsHr0hDvXhDWFs8W0tPr0hDv7hDWXrvW0QDWXtUW2OFW7tOC2>>%tf%
  379. ECHO:ln9CF07DAn83Fy3D4me0Z23xlZS62Au6y0YZ07i3WMS63x7Ab8b7Zjuxln>>%tf%
  380. ECHO:n2jGm3xfdd30coy3PHLNtBvla0iymyylUhyHg9Z1sVLP73LNPMLNXUuXiy>>%tf%
  381. ECHO:ZOXUuRiyZ8s1LVf3yvRmA[DPlx]D2yUD3byRy3TGLMmvdhHo0AN0VrwULO>>%tf%
  382. ECHO:N3MBFfZfv6hDOHj5v0hDO7j5r0hDWFtSayX6uxhDWBtJayX6FvF0Q9JtRy>>%tf%
  383. ECHO:JtQBJtOuJxXyMxxD2y]D03cpwEtBJvFvv]E[F0M82x]D2y6D7bwQxx6D6y>>%tf%
  384. ECHO:hD3bxLworLhDvDhDW7s[iyX67v16ytwEitrPtGhDvFhDC91putIs013vRm>>%tf%
  385. ECHO:A[0ml8W5sSiytTMBsTN3NbvWxBROMBZqrOiyZGgUZhkBwNMBxfdBmlMhSS>>%tf%
  386. ECHO:6BpBFBx]gn03isBuCuoqiarAhGBuUBkRCekTF3F0oRN3FbuxgGZ8]3v0gx>>%tf%
  387. ECHO:EBbU07YX07tBC6r746w8I33y1yC2Fy2tK0Bqr37rqa2r2j2ElnnFjGSv1n>>%tf%
  388. ECHO:W5f0trZ0Jvb]p857ZYv7WVK1O607y3hDWBtCuxhDvBhDW9t3uxhDW9t5yx>>%tf%
  389. ECHO:hDf9Z8W3xA0TZuvWSB0ml8[5HF]3v0swu3pyWBqbNxpxWB[ml00v9oO8H1>>%tf%
  390. ECHO:]1v0K2Vm2s02pyW9Fvv]E[m7O607013yW607t3C8b75ov4vES82tSC2nn9>>%tf%
  391. ECHO:jXtB46b7ZJexlBWU07EAyxFEFRAn3DCGkLlBtBHp2y]D2BPE3vRmA[0ml8>>%tf%
  392. ECHO:n5N2041LlBt3Bf0ma0X6ixXpW4ufiw9606I9s6vw001wW6f1[0X6yxhDO9>>%tf%
  393. ECHO:j5f0Xpv4hDC91puxIs800esEyvRmA[0ml8f5Z\9Tj4v0hDC7F0M933pyW7>>%tf%
  394. ECHO:ubiwu3hDW7tPFwkLlBtBHp3bpNxBi8f1f0XMG4g07D9TB200gLZfR62D09>>%tf%
  395. ECHO:2GQn2lqyjX\n2Y]D36r6W900]Bq\N30101S000bD0[bD00070000000000>>%tf%
  396. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  397. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  398. ECHO:00000000000000000000000000009\Tl9iS08j}>>%tf%
  399. :: BASM source...
  400. :: 'typical usage: type file | _replace "abc" "def" > newfile
  401. :: 'replace all occurences of string "abc" with string "def"
  402. :: 'read from standard input, write to standard output
  403. :: $com
  404. :: $string 512 'max line len
  405. :: chr10$=chr$(10)
  406. :: chr13$=chr$(13)
  407. :: quote$=chr$(34)
  408. :: 'parse command line...
  409. :: c$=command$
  410. :: c$=ltrim$(c$)      'get rid of surrounding spaces
  411. :: c$=rtrim$(c$)
  412. :: d$=left$(c$,1)
  413. :: if d$<>quote$ then goto clerror
  414. :: clen=len(c$)
  415. :: clen=clen-1
  416. :: c$=right$(c$,clen) 'remove 1st quote
  417. :: qpos=instr(c$,quote$)  'get position of 2nd quote
  418. :: if qpos<2 goto clerror 'must be at least 1 char
  419. :: qpos=qpos-1
  420. :: str1$=left$(c$,qpos) 'slice off match string
  421. :: qpos=qpos+2
  422. :: clen=len(c$)
  423. :: rlen=clen-qpos
  424. :: str2$=right$(c$,rlen) 'raw second half
  425. :: str2$=ltrim$(str2$)  'no extra spaces
  426. :: d$=left$(str2$,1)      'check for quotes
  427. :: if d$<>quote$ then goto clerror
  428. :: d$=right$(str2$,1)
  429. :: if d$<>quote$ then goto clerror
  430. :: clen=len(str2$)      'make sure valid string
  431. :: if clen<2 then goto clerror 'too short
  432. :: if clen>2 then            'at least 1 char
  433. ::  clen=clen-1
  434. ::  str2$=right$(str2$,clen)  'remove quotes
  435. ::  clen=clen-1
  436. ::  str2$=left$(str2$,clen)
  437. :: else
  438. ::  str2$=""          'otherwise empty replace
  439. :: end if
  440. :: oneline$=""  'initialise main processing loop
  441. :: linelen=0    'count chars to avoid overrun
  442. :: mainloop:          'loop until no more...
  443. :: a$=stdin$                   'get one character
  444. :: if a$="" then goto nomore   'done with input
  445. :: if a$=chr13$ then goto mainloop 'skip cr
  446. :: if a$=chr10$ then           'if lf process line
  447. ::  gosub process               'replace and output
  448. ::  oneline$=""                 'reset string
  449. ::  linelen=0
  450. ::  goto mainloop               'and loop for more
  451. :: end if                  'if not lf
  452. :: if linelen<512 then      'if not overflow
  453. ::  oneline$=oneline$+a$     'add to line
  454. ::  linelen=linelen+1        'bump length count
  455. :: end if
  456. :: goto mainloop
  457. :: nomore:
  458. :: if linelen>0 then       'if extra chars w/ no crlf
  459. ::  gosub process           'process as one line
  460. :: endif
  461. :: end               'exit to dos
  462. :: clerror:              'command line error
  463. :: print "error"
  464. :: end
  465. :: process:                     'subroutine...
  466. :: replace str1$ with str2$ in oneline$  'nice
  467. :: output oneline$              'write to stdout+crlf
  468. :: return
  469. ::-------------------------------
  470. :: decode replace helper...
  471. %dec% < %tf% > %replace%
  472. if errorlevel 1 goto binerror
  473. :: everything is in place to convert com into batch code...
  474. ::  %dec% - the decoder program
  475. ::  %enc% - encodes binary to text, stdin to stdout
  476. ::  %file2bat% infile outfile tmpfile - turns into echo code
  477. ::  %cmntsrc% file - outputs stdout with commented file
  478. ::  %replace% "search" "replace" - stdin to stdout
  479. ::  %compname% = the compiler name
  480. ::  %madewith% = utilities used to compile
  481. ::  %usetempdir% = yes if tempdir to be used
  482. ::  %decname% = decoder filename to use
  483. ::  %tempname% = temp filename to use
  484. ::  %fbase%.%outputext% = output filename
  485. :: determine temp names...
  486. set t=
  487. if .%usetempdir%==.yes set t=%%temp%%.\
  488. :: create output file...
  489. set outfile=%fbase%.%outputext%
  490. echo @echo off>%outfile%
  491. echo>>%outfile% ::---- Generated by CONV2BAT ----
  492. :: attach decoder...
  493. echo>>%outfile% :: CM3-encoded DecBin decoder...
  494. %file2bat% %dec% %tf1% %t%%decname%
  495. type>>%outfile% %tf1%
  496. :: attach encoded com file...
  497. echo>>%outfile% ::---- EncBin-encoded binary ----
  498. echo>>%outfile% :: %binfile% made with %madewith%
  499. %enc% < %binfile% > %tf%
  500. %file2bat% %tf% %tf1% %t%%tempname%
  501. type>>%outfile% %tf1%
  502. :: attach source code...
  503. if not .%compname%==. echo>>%outfile% :: %compname% source...
  504. if not .%compname%==. %cmntsrc% %fbase%.%fext% >>%outfile%
  505. echo>>%outfile% ::-------------------------------
  506. :: attach decode/run/delete lines...
  507. echo>>%outfile% :: decode/run/delete, modify as needed...
  508. echo>%tf1% %t%%decname% {{.lt{{ %t%%tempname% }}.gt}} %t%%binfile%
  509. %replace% "{{.lt{{" "<" < %tf1% > %tf2%
  510. %replace% "}}.gt}}" ">" < %tf2% >>%outfile%
  511. if not .%compname%==. echo>>%outfile% %t%%binfile% %%1 %%2 %%3
  512. if not .%compname%==. echo>>%outfile% del %t%%binfile%
  513. if .%compname%==. echo>>%outfile% :: use %t%%binfile% as needed
  514. echo>>%outfile% del %t%%tempname%
  515. echo>>%outfile% del %t%%decname%
  516. echo.
  517. echo  ===========================================================
  518. echo    Done! %binfile% is the raw binary
  519. if exist %fbase%.asm echo    intermediate assembly is in %fbase%.asm
  520. echo    %outfile% batch code recreates %binfile% when run
  521. echo  ===========================================================
  522. echo.
  523. goto cleanup
  524. :binerror
  525. echo  Error in encoded binary
  526. :cleanup
  527. if exist %tf% del %tf%
  528. if exist %tf1% del %tf1%
  529. if exist %tf2% del %tf2%
  530. if exist %enc% del %enc%
  531. if exist %dec% del %dec%
  532. if exist %replace% del %replace%
  533. if exist %sepname% del %sepname%
  534. if exist %cmntsrc% del %cmntsrc%
  535. if exist %file2bat% del %file2bat%
  536. :end
复制代码
Tasm assembly source for the DecBin decoder... (before CM3 encoding)
  1. ;decbin.asm
  2. ;original code by Tenie Remmel - zdecode.asm from ASnip
  3. ;modified by Terry Newton to use 12 bit/64 char encoding
  4. ;verifies length, if not correct outputs ret and sets el=1
  5. Ideal
  6. Model Tiny
  7. P186
  8. CodeSeg
  9. Org 100h
  10. Proc        Program
  11.             mov ah,3Fh         ;Read file/device
  12.             xor bx,bx          ;handle for STDIN
  13.             mov dx,1024        ;Start at DS:1K
  14.             mov cx,63488       ;62K bytes (max)
  15.             int 21h            ;DOS services
  16.             mov si,1024        ;SI, DI = 1K
  17.             mov di,si
  18.             mov ah,'A'         ;AH = 'A'
  19.             call GetDigit      ;First digit
  20.             shl al,4           ;Shift over
  21.             mov ch,al          ;Put in CH
  22.             call GetDigit      ;Second digit
  23.             or ch,al           ;OR into CH
  24.             call GetDigit      ;Third digit
  25.             shl al,4           ;Shift over
  26.             mov cl,al          ;Put in CL
  27.             call GetDigit      ;Last digit
  28.             or cl,al           ;OR into CL
  29.             push cx            ;Save numbytes
  30. InpLoop:    lodsb              ;Load byte
  31.             cmp al,21h         ;< 21h?
  32.             jb InpLoop         ;Get new byte
  33.             cmp al,'}'         ;Check for right bracket
  34.             je Done            ;It's a right bracket, done
  35.             ja InpLoop         ;Get new byte
  36.             dec si             ;Re-load that byte
  37.             lodsw              ;Load word
  38.                 ;first char in al, 2nd in ah
  39.             xor dh,dh          ;Clear DH
  40.             cmp al,5Eh         ;restore skip ^_` (mod...)
  41.             jl AL_ok0
  42.             sub al,3
  43. AL_ok0:     cmp ah,5Eh
  44.             jl AH_ok0
  45.             sub ah,3
  46. AH_ok0:     cmp al,3Ah         ;restore skip :;<=>?@ (mod...)
  47.             jl AL_ok
  48.             sub al,7
  49. AL_ok:      cmp ah,3Ah
  50.             jl AH_ok
  51.             sub ah,7
  52. AH_ok:
  53.             sub ax,3030h       ;Adjust to binary (mod)
  54.             mov dl,ah          ;Save remainder
  55.             mov ah,64          ;Multiply by 64 (mod)
  56.             mul ah
  57.             add ax,dx          ;Add in remainder
  58.             call Out12         ;Output 12 bits (mod)
  59.             jmp InpLoop
  60. Done:
  61.             pop cx             ;Number of bytes (moved)
  62. ;verify size... (mod)
  63.             mov ax,di          ;get output pointer
  64.             sub ax,1024        ;subtract starting offset
  65.             cmp ax,cx          ;compare actual vs recorded bytes
  66.             je VerOK           ;if equal then cool
  67.             dec ax
  68.             cmp ax,cx          ;if actual is 1 more then cool
  69.             jne VerNotOK       ;otherwise verify fails
  70.             xor ax,ax          ;zero ax
  71.             push ax            ;save for return value
  72. VerOK: ;(stock minus pop plus label)
  73.             mov ah,40h         ;Write file/device
  74.             mov bx,1           ;handle for STDOUT
  75.             mov dx,1024        ;Start at DS:1K
  76.             int 21h            ;DOS services
  77.        ;return errorlevel 0 or 1 depending on verify status
  78.             pop ax             ;get saved errorlevel
  79.             mov ah, 4Ch        ;exit function
  80.             int 21h            ;do it
  81. VerNotOK: ;here if size doesn't match (mod)
  82.             mov cx,1           ;just one byte
  83.             mov [byte ds:1024],0C3h ;make it a return
  84.             push cx            ;save for return value
  85.             jmp VerOK          ;write it
  86. EndP        Program
  87. Proc        GetDigit
  88. DLoop:      lodsb
  89.             cmp al,'A'
  90.             jb DLoop
  91.             cmp al,'P'
  92.             ja DLoop
  93.             sub al,'A'
  94.             ret
  95. EndP        GetDigit
  96. ;my code follows...
  97. Split**    db 0     ;if not 0 then split byte
  98. SplitByt    db 0     ;buffer
  99. Proc        Out12    ;output 12 bits (to out buffer)
  100. ;on calling al/ah=Byte1/Byte2low, Byte3/Byte2high, Byte4/Byte5low
  101. ;                 Byte6/Byte5high, Byte7/Byte8low, etc (starting at 1)
  102.             push bx cx
  103.             mov bl,[Split**]  ;get even/split flag
  104.             cmp bl,0
  105.             je OutEven         ;if 0 then goto OutEven
  106.             mov bl,[SplitByt]  ;get last split byte
  107.             and bl,0Fh         ;low nibble
  108.             shl ah,4           ;ah=high nibble
  109.             or ah,bl           ;ah=reconstructed byte
  110.             xchg ah,al         ;swap bytes
  111.             stosb              ;store split byte
  112.             mov al,ah          ;put split byte in al
  113.             stosb              ;followed by whole byte
  114.             mov [Split**],0   ;clear flag
  115.             jmp Out12x         ;exit
  116. OutEven:    mov [SplitByt],ah  ;save split byte low nibble
  117.             stosb              ;store even byte
  118.             mov [Split**],1   ;set split flag
  119. Out12x:     pop cx bx
  120.             ret
  121. EndP        Out12
  122. End Program
复制代码
Tasm source for the EncBin encoder...
  1. ;encbin.asm
  2. ;original code by Tenie Remmel - zencode.asm from ASnip
  3. ;modified by Terry Newton for 12 bits per character pair
  4. ;batch-compatible encoding (64 possible values)
  5. Ideal
  6. Model Tiny
  7. P186
  8. CodeSeg
  9. Org 100h
  10. Proc        Program
  11.             mov ah,3Fh         ;Read file/device
  12.             xor bx,bx          ;handle for STDIN
  13.             mov dx,24064       ;Start at DS:23.5K (mod)
  14.             mov cx,40960       ;40K bytes (max) (mod)
  15.             int 21h            ;DOS services
  16.             mov cx,ax          ;Number of bytes in CX
  17.             mov si,24064       ;SI = 23.5K (mod)
  18.             mov di,1024        ;DI = 1K
  19.             mov bx,2           ;BX = 2 (words)
  20.             mov ah,'A'         ;AH = 'A'
  21.             mov al,ch          ;First digit
  22.             shr al,4           ;Shift over
  23.             add al,ah          ;Adjust to text
  24.             stosb              ;Store byte
  25.             mov al,ch          ;Second digit
  26.             and al,0Fh         ;AND mask
  27.             add al,ah          ;Adjust to text
  28.             stosb              ;Store byte
  29.             mov al,cl          ;Third digit
  30.             shr al,4           ;Shift over
  31.             add al,ah          ;Adjust to text
  32.             stosb              ;Store byte
  33.             mov al,cl          ;Last digit
  34.             and al,0Fh         ;AND mask
  35.             add al,ah          ;Adjust to text
  36.             stosb              ;Store byte
  37.             add cx,si          ;CX = limit for SI
  38. InpLoop:    call In12          ;Input 12 bits     (mod)
  39.             mov dl,64          ;Divide AX by 64   (mod)
  40.             div dl             ;now AL, AH <= 63
  41.             add ax,3030h       ;Adjust to text 1st char="0" (mod)
  42.             cmp al,3Ah         ;skip :;<=>?@ (mod...)
  43.             jl AL_ok
  44.             add al,7
  45. AL_ok:      cmp ah,3Ah
  46.             jl AH_ok
  47.             add ah,7
  48. AH_ok:      cmp al,5Eh         ;skip ^_` (mod...)
  49.             jl AL_ok0
  50.             add al,3
  51. AL_ok0:     cmp ah,5Eh
  52.             jl AH_ok0
  53.             add ah,3
  54. AH_ok0:
  55.             stosw              ;Store word
  56.             inc bx             ;Inc line counter
  57.             cmp bx,29          ;58 chars on this line? (mod)
  58.             jl Next            ;Jump if not
  59.             xor bx,bx          ;Clear line counter
  60.             mov ax,0A0Dh       ;Put a CRLF in AX
  61.             stosw              ;Store it
  62. Next:       cmp si,cx          ;SI > CX?
  63.             jbe InpLoop        ;Jump if not
  64.             mov al,'}'         ;Store bracket (ending char)
  65.             stosb
  66.             mov ax,0A0Dh       ;Put a CRLF in AX (added)
  67.             stosw              ;Store it (added)
  68.             mov ah,40h         ;Write file/device
  69.             mov bx,1           ;handle for STDOUT
  70.             mov cx,di          ;Number of bytes
  71.             mov dx,1024        ;Start at DS:1K
  72.             sub cx,dx          ;Adjust CX
  73.             int 21h            ;DOS services
  74.             ret                ;Exit
  75. EndP        Program
  76. ;the following is my code...
  77. SplitByt    db 0               ;buffer byte
  78. Split**    db 0               ;even/split flag
  79. Proc        In12
  80.    ;return next 12 bits in ax, al=whole ah=fractions
  81.    ;al/ah.. Byte1/Byte2low, Byte3/Byte2high, Byte4/Byte5low etc
  82.             push bx cx        ;save regs
  83.             mov cl,[Split**] ;get flag
  84.             cmp cl,0
  85.             je get2           ;if 0 then goto get2
  86.             lodsb             ;get one more byte in al
  87.             mov ah,[SplitByt] ;ah=left over bits from 2nd byte
  88.             shr ah,4          ;top nibble
  89.             mov [Split**],0  ;clear even/split flag
  90.             jmp exin12        ;exit
  91. get2:       lodsb             ;load byte into al
  92.             push ax           ;save it
  93.             lodsb             ;get next byte
  94.             mov [SplitByt],al ;into buffer
  95.             mov bl,al         ;save it
  96.             pop ax            ;al=1st byte
  97.             mov ah,bl         ;ah=2nd byte
  98.             and ah,0Fh        ;ah=bottom nibble of 2nd byte
  99.             mov [Split**],8  ;anything but 0
  100. exin12:     pop cx bx         ;restore regs
  101.             ret               ;back to caller
  102. EndP        In12
  103. End Program
复制代码
Using Conv2Bat and Reusing Binary Batch Code

Download and install the compilers you wish to use, copy binaries that don't access libraries (such as basm, asm and the linkers) to a path directory, create linking batch files in a path directory for the larger compilers (asicc, mrc, tbc). For Windows, make shortcuts to the doc files of the compilers you're using or make printed copies, you'll need to refer to them often as you write code. If you want to be able to right-click and select "Convert to Batch" (or however named) use Windows' View|Options File Types dialog and add entries for asi, bas, moo and tok files as needed. You can also drag and drop the source file on top of the Conv2Bat.bat file or a shortcut to it. Conv2Bat should work fine in Dos 6, it contains no Windows-specific code but does need the Dos 6 or later FIND command to properly document whether or not PkLite was used. Under NT the comments in the output batch will likely be incorrect but the code output should be the same (if there are no other incompatibilities, have only tested with Win95Cmd).

Conv2Bat outputs batch code that writes the decoder to "_d.com", the temp file to "_t.tmp" and the actual decoded program to its original filename. Edit the output code as needed for your requirements. I often change the file targets to variables (like >>%tf%) to allow writing to the temp directory without requiring a long filename on each line. Once useful utilities have been created you can copy/paste them as needed into your batch files.

I just installed a new compact html browser called "Off By One" and wanted to be able to drag an html file onto the icon to load, but the browser wants to see a file:///c:/whatever type url for local files. Basically I needed a batch that converts a quoted long filename into a url that the browser can load. First I need to convert the long name into a short name (really to get rid of the quotes but doesn't hurt to be short so a simple for loop will do), prepend "file:///" to the quoteless name, and change "\" to "/". Here's what I come up in very little time using code copied from Conv2Bat...
  1. :: OffByOne doesn't understand disk filenames like "c:\web\file.htm"
  2. :: Convert parm to "file:///" + name without quotes and change \ to /
  3. @echo off
  4. set url=
  5. if .%1==. goto noparm
  6. if not exist %1 goto noparm
  7. set dec=%temp%.\_dec.com
  8. set tf=%temp%.\_tmp.tmp
  9. set replace=%temp%.\_rep.com
  10. ::-----------------------
  11. :: CM3-encoded DecBin decoder...
  12. ECHO:`h}aXP5y`P]4nP_XW(F4(F6(F=(FF)FH(FL(Fe(FR0FTs*}`A?+,>%dec%
  13. ECHO:fkOU):G*@Crv,*t$HU[rlf~#IubfRfXf(V#fj}fX4{PY$@fPfZsZ$:NvN$>>%dec%
  14. ECHO:9AyroNB-)dOKwK0rRkfTbi)ws_~[[q9wE'sqlu1sY*Bsfe=@ziNS1a)88e>>%dec%
  15. ECHO:f9RTL)9Z{3INBD?o6@MDLO{Zz4Q23E-'09NX9@Vz(42A7c8zMS:u$w6k5Q>>%dec%
  16. ECHO:N,h:le)~gF?tutTyxoe5UiIdtn';0rJ1q:{7;lAl']y:yTjZBbOo?QRIdN>>%dec%
  17. ECHO:$Bp@P/nAp_r0*4f'XcF4q3o?$_t5lx$Q-OxSfUNQ__Gd~$Q-Oxgkx=LGHU>>%dec%
  18. ECHO:S)$C6P8#>>%dec%
  19. ::---- EncBin-encoded binary ----
  20. :: replace.com made with BASM ASM FREELINK
  21. ECHO:AGINr64U2y00tD61O0AAj7CDXn28Q587D7JeRkl5S]00xG47uvfav7f][7>%tf%
  22. ECHO:gGC0v]U[2uMDA13301EBu1Je13dnJDrX5OYZ47dZ47Fbv2ibO5pyW9dr00>>%tf%
  23. ECHO:M90maRXTW1s3v3hDWJs[W5sIv5hDW9fD[0W5fmp95T3bCd2yMD7bLB3bKs>>%tf%
  24. ECHO:2y]D2r0Y29C5FRp9K17b43pyWNBbC53b85Qx87pyWPNbj2Jb45pxWPabK4>>%tf%
  25. ECHO:Fbv2pyWPJb45Bb05pxWPZb447br2pyWPBb053bv45d1b]D7bI93bBD2yhD>>%tf%
  26. ECHO:7bJh2xhD6yUD7bB81of3r4]Gr7C2F0tZ47pxWPabS2O30UC7cqv7vETq3b>>%tf%
  27. ECHO:Io3ySpS7obWPJbO43b[2pyWP7bf40mlZSU2y]D6xUD7bC]03r647]ZS7t3>>%tf%
  28. ECHO:Ds871vf3r1xGvETs3bHv3y[pS7obWPFb44VbK2pyWTZbS4Q31s870mF0bU>>%tf%
  29. ECHO:r7hDWPrFC206SU2ZTq0mF006Tq0e[6S7hZS7BbG4RyDuW7QDWPukW3rTv2>>%tf%
  30. ECHO:hDWVrxW4rfr4hDWVskW3rBv2hDWVrfW4rQb4O1obWVFbf3Vbv1pyWRZb44>>%tf%
  31. ECHO:pxWRpyWNBbv1Do3e04ac4k3bFo1dW1QDWVt]W3uIv1hDWRumr3hDvRhDWN>>%tf%
  32. ECHO:uDK1S3Je2Gmc010mlZSU2xxD7b5x03r647UZS7t3Dq871vf3r4]GugC0Wx>>%tf%
  33. ECHO:Tq02Dy3e0raySES7Fbb3RyDqW7QDWVsIW3sxv1hDWVtVv3vETq3bE93ySp>>%tf%
  34. ECHO:S7obWV3b83JbO1pyWVNbW3qe2G3bS3pxS7pyWVNb41JbO3xxS7pyWXab01>>%tf%
  35. ECHO:R7210700BbK3ubS3JbC1pyWZNbK3pxWZEyW7yb81Dn3e04ae1S]xEDAyMD>>%tf%
  36. ECHO:7b4U1nf3r3hGuGpxWZpyWJub01Dn3e0Oab1V3bCH2xU52y6DBb2p3746W7>>%tf%
  37. ECHO:003e6eWxU100j2S3ee6GBbv2pxWXJbv2pxWZubr2pyWXybr2Ry21f7t5t3>>%tf%
  38. ECHO:E1071yf3r4YGrO00f0lnJDrXh7W7tHW1sQW0rc02f0lnJDrXhDvThDWBsQ>>%tf%
  39. ECHO:r0hDvVhDWDsHr0hDvXhDWFs8W0tPr0hDv7hDWXrvW0QDWXtUW2OFW7tOC2>>%tf%
  40. ECHO:ln9CF07DAn83Fy3D4me0Z23xlZS62Au6y0YZ07i3WMS63x7Ab8b7Zjuxln>>%tf%
  41. ECHO:n2jGm3xfdd30coy3PHLNtBvla0iymyylUhyHg9Z1sVLP73LNPMLNXUuXiy>>%tf%
  42. ECHO:ZOXUuRiyZ8s1LVf3yvRmA[DPlx]D2yUD3byRy3TGLMmvdhHo0AN0VrwULO>>%tf%
  43. ECHO:N3MBFfZfv6hDOHj5v0hDO7j5r0hDWFtSayX6uxhDWBtJayX6FvF0Q9JtRy>>%tf%
  44. ECHO:JtQBJtOuJxXyMxxD2y]D03cpwEtBJvFvv]E[F0M82x]D2y6D7bwQxx6D6y>>%tf%
  45. ECHO:hD3bxLworLhDvDhDW7s[iyX67v16ytwEitrPtGhDvFhDC91putIs013vRm>>%tf%
  46. ECHO:A[0ml8W5sSiytTMBsTN3NbvWxBROMBZqrOiyZGgUZhkBwNMBxfdBmlMhSS>>%tf%
  47. ECHO:6BpBFBx]gn03isBuCuoqiarAhGBuUBkRCekTF3F0oRN3FbuxgGZ8]3v0gx>>%tf%
  48. ECHO:EBbU07YX07tBC6r746w8I33y1yC2Fy2tK0Bqr37rqa2r2j2ElnnFjGSv1n>>%tf%
  49. ECHO:W5f0trZ0Jvb]p857ZYv7WVK1O607y3hDWBtCuxhDvBhDW9t3uxhDW9t5yx>>%tf%
  50. ECHO:hDf9Z8W3xA0TZuvWSB0ml8[5HF]3v0swu3pyWBqbNxpxWB[ml00v9oO8H1>>%tf%
  51. ECHO:]1v0K2Vm2s02pyW9Fvv]E[m7O607013yW607t3C8b75ov4vES82tSC2nn9>>%tf%
  52. ECHO:jXtB46b7ZJexlBWU07EAyxFEFRAn3DCGkLlBtBHp2y]D2BPE3vRmA[0ml8>>%tf%
  53. ECHO:n5N2041LlBt3Bf0ma0X6ixXpW4ufiw9606I9s6vw001wW6f1[0X6yxhDO9>>%tf%
  54. ECHO:j5f0Xpv4hDC91puxIs800esEyvRmA[0ml8f5Z\9Tj4v0hDC7F0M933pyW7>>%tf%
  55. ECHO:ubiwu3hDW7tPFwkLlBtBHp3bpNxBi8f1f0XMG4g07D9TB200gLZfR62D09>>%tf%
  56. ECHO:2GQn2lqyjX\n2Y]D36r6W900]Bq\N30101S000bD0[bD00070000000000>>%tf%
  57. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  58. ECHO:0000000000000000000000000000000000000000000000000000000000>>%tf%
  59. ECHO:00000000000000000000000000009\Tl9iS08j}>>%tf%
  60. :: BASM source...
  61. :: 'typical usage: type file | _replace "abc" "def" > newfile
  62. :: 'replace all occurences of string "abc" with string "def"
  63. :: 'read from standard input, write to standard output
  64. :: $com
  65. :: $string 512 'max line len
  66. :: chr10$=chr$(10)
  67. :: chr13$=chr$(13)
  68. :: quote$=chr$(34)
  69. :: 'parse command line...
  70. :: c$=command$
  71. :: c$=ltrim$(c$)      'get rid of surrounding spaces
  72. :: c$=rtrim$(c$)
  73. :: d$=left$(c$,1)
  74. :: if d$<>quote$ then goto clerror
  75. :: clen=len(c$)
  76. :: clen=clen-1
  77. :: c$=right$(c$,clen) 'remove 1st quote
  78. :: qpos=instr(c$,quote$)  'get position of 2nd quote
  79. :: if qpos<2 goto clerror 'must be at least 1 char
  80. :: qpos=qpos-1
  81. :: str1$=left$(c$,qpos) 'slice off match string
  82. :: qpos=qpos+2
  83. :: clen=len(c$)
  84. :: rlen=clen-qpos
  85. :: str2$=right$(c$,rlen) 'raw second half
  86. :: str2$=ltrim$(str2$)  'no extra spaces
  87. :: d$=left$(str2$,1)      'check for quotes
  88. :: if d$<>quote$ then goto clerror
  89. :: d$=right$(str2$,1)
  90. :: if d$<>quote$ then goto clerror
  91. :: clen=len(str2$)      'make sure valid string
  92. :: if clen<2 then goto clerror 'too short
  93. :: if clen>2 then            'at least 1 char
  94. ::  clen=clen-1
  95. ::  str2$=right$(str2$,clen)  'remove quotes
  96. ::  clen=clen-1
  97. ::  str2$=left$(str2$,clen)
  98. :: else
  99. ::  str2$=""          'otherwise empty replace
  100. :: end if
  101. :: oneline$=""  'initialise main processing loop
  102. :: linelen=0    'count chars to avoid overrun
  103. :: mainloop:          'loop until no more...
  104. :: a$=stdin$                   'get one character
  105. :: if a$="" then goto nomore   'done with input
  106. :: if a$=chr13$ then goto mainloop 'skip cr
  107. :: if a$=chr10$ then           'if lf process line
  108. ::  gosub process               'replace and output
  109. ::  oneline$=""                 'reset string
  110. ::  linelen=0
  111. ::  goto mainloop               'and loop for more
  112. :: end if                  'if not lf
  113. :: if linelen<512 then      'if not overflow
  114. ::  oneline$=oneline$+a$     'add to line
  115. ::  linelen=linelen+1        'bump length count
  116. :: end if
  117. :: goto mainloop
  118. :: nomore:
  119. :: if linelen>0 then       'if extra chars w/ no crlf
  120. ::  gosub process           'process as one line
  121. :: endif
  122. :: end               'exit to dos
  123. :: clerror:              'command line error
  124. :: print "error"
  125. :: end
  126. :: process:                     'subroutine...
  127. :: replace str1$ with str2$ in oneline$  'nice
  128. :: output oneline$              'write to stdout+crlf
  129. :: return
  130. ::-------------------------------
  131. :: decode replace helper...
  132. %dec% < %tf% > %replace%
  133. del %dec%
  134. del %tf%
  135. :: convert parameter into url...
  136. :: first get rid of quotes...
  137. for %%a in (%1) do set file=%%a
  138. :: create set for new url...
  139. echo set url=file:///%file% > %temp%.\tf1.tmp
  140. :: use helper utility to change \ to /
  141. %replace% "\" "/" < %temp%.\tf1.tmp > %temp%.\tf2.bat
  142. :: run results to set url var...
  143. call %temp%.\tf2.bat
  144. :: clean up...
  145. del %temp%.\tf2.bat
  146. del %temp%.\tf1.tmp
  147. del %replace%
  148. :: run browser...
  149. :noparm
  150. "c:\Program Files\hpsw\OffByOne\ob1.exe" %url%
复制代码
Batch file size is increased, perhaps too much for some tastes, but I don't think that's a huge disadvantage. It does require about 3 seconds to launch rather than 1 second just running the program but a single batch line starting the browser takes almost as long (bin-batch adds only a fraction of a second) and it doesn't matter anyway considering 3 seconds is about 4 times faster than opening Netscape or IE. It doesn't bother me that two com files are created and deleted in my temp directory, it looks scary and takes more bytes, I'm happy I can drag a file to OffByOne and it only took a few minutes to accomplish using a search and replace helper ripped as-is from another bin-batch. I could make it smaller by writing custom code that directly changes "\" to "/" but that would have take longer.. it's faster to copy/paste existing code than write new code if the existing code does the job, the number of lines doesn't figure unless so large it impedes things in other ways.. like when notepad will no longer load the batch. In today's world of multi-megabyte programs a bloated batch is insignificant. I could save space and make the replace utility a persistent file and not encode at all, but then I'd have another utility on my path to keep up with, not worth saving a few kilobytes. Echoed QBasic scripts can do just about anything bin-batch can do, but there's a screen flash, QBasic.exe must be available, and not being able to use "<" or ">" in the code complicates comparisons. Whatever works.

Links to binary batch code and compiler resources

Herbert Kleebauer's Convert.bat (Google)
UBE.zip contains Convert.bat, source and other "ascii assembler" routines
Ass486.zip contains Herbert Kleebauer's 68K-like assember
Laura Fairhead's CM3 utility · alternate page
Disassembly of CM3 by Herbert Kleebauer (Google)
Disassembly of CM3's decoder by Laura Fairhead (Google)
The Moonrock Compiler Page


--------------------------------------------------------------------------------


(C) Copyright 2003 by Terry Newton
http://www.infionline.net/~wtnewton
1

评分人数

    • CrLf: 好资料!技术 + 1
天的白色影子

TOP

@echo off
if exist %0.bat %0.bat
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>h2b.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>h2b.com
echo ?@}I{uNWEF~NFAa_Lj@KLtH]~CEvEFIKbAa_wN@SuNS`{ECCttasae~BHM>>h2b.com
echo AcjFnvnHAwrvx[}gIKDw??Frt\gqj~{?s?csIsqo{O_KtBve{Sx{nB{Eu@>>h2b.com
echo fq`tkfk?e@oKCA_?_E@?WxAs?agBwRjnLK?s@w`G`LKLAcyA?@xAsZpk`L>>h2b.com
echo ~KxlqLct@vAc_A_yBJ@xAGZp?o?sBXq`LR@xUrFQt=A_E?B?~rB?~r0>>h2b.com

h2b "::f1" <%0 >bild1.gif
h2b "::f2" <%0 >bild2.gif
h2b "::f3" <%0 >demo.com
del h2b.com

:: hex dump of bild1.gif
::f1 4749463839614b001100a20000140b00fffbf7ff6600fffcfa0000000000
::f1 000000000000002c000000004b0011000003a228badcfe30ca0901bd386b
::f1 66b7ff5f078e64242a419aa2eabaa84cebb2731d2cc39357f1cd0ab306ec
::f1 e503fa5cc8e26cc06c30778d53f0e758d988c6c715f7643ca10ae9902abc
::f1 6db35372faebed86cb4399d23c6f917b32079bdb7c576169687354816702
::f1 7b0a887e5a747f79593f8583897d7c0f6258695b9b479d58893a26704976
::f1 909041a493a61e2725ae25adafb2acb3b52100b8b9babbbcbdbebfc0c1bf
::f1 09003b

:: hex dump of bild2.gif
::f2 47494638396121001000b30000fffdfbff6702ffc39aff9e5effdfcaffef
::f2 e5fff8f4ffffffc0c0c00000000000000000000000000000000000000000
::f2 0021f90401000008002c0000000021001000000463f0c849abbd385f3384
::f2 fe9911041e2811432a1499300e00388c743010d83ce26deddf16110d78d1
::f2 f96a1dd6c485e4518ed0a1406044962451a80aa5751eaadd0a73a8a48c8f
::f2 83f2a480548bd1ee892e0d2a4c05841886793581847d7e1f007882862611
::f2 003b

:: hex dump of an executable
::f3 fcbe3301bf4301b95000b020f3aa89fab91000f3a4bbffffb93c00b409cd
::f3 21b40bcd2108c0750801dae2f0f7dbebe9b44ccd21707265737320616e79
::f3 206b65790d0a24

;我想知道SERCH.GIF的二进制码,人类是如何凭空想出来,写出来的,bird.gif又是如何来的,唱歌说,用HEX工具编辑GIF文件复制出来,那是没有任何意义的,那样使用这种BAT纯纯的自我欺骗

TOP

回复 11# bluenightsky


    h2b 这个名字已经说明了一切,真就是 Bin To Hex 再 Hex To Bin 的把戏

TOP

  1. @echo off
  2. chcp 437 >nul
  3. echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>echoo.com
  4. echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU!WvX0GwUY Wv;ovBX2Gv0ExGIuht6>>echoo.com
  5. echo ?@xAyJHmH@=a?}VjuN?_LEkS?`w`s_{OCIvJDGEHtc{OCIKGMgELCI?GGg>>echoo.com
  6. echo EL?s?WL`LRBcx=k_K?AxVD?fCo?Cd?BLDs0>>echoo.com
  7. echoo $31$30$30$25$20$b4$bf$cf$e3$d3$cd$0d$0a>~tmp.txt
  8. chcp 936 >nul
  9. type ~tmp.txt
  10. pause
复制代码

TOP

返回列表