『第
19 楼』:
关于任意文件debug转十六进制码、加解密
任意文件转十六进制码与解密程序如下:
(为了初学者共同学习,便于理解思路和原理,代码没有进行优化。用sed是为了解决效率,程序中有+255是为了清除e00-e99的无关代码,长度计算的代码表达更为清晰理解。)
@echo off
:3nm
endlocal EnableDelayedExpansion
cls
title 任意文件转十六进制码、解密、 编辑:WangWei QQ251485609
@echo.
@echo 1 用debug将任何小于65280字节的文件均可转换成cmd文件(十六进制编码)。
@echo.
@echo 2 可以转换成十六进制编码的加密txt文件(无地址码、无长度码。不易破解)。
@echo.
@echo 3 解密任意十六进制编码的文件。
@echo.
@echo 注:用fc虽然可以转换成十六进制编码,但处理图片文件会出错掉码。
@echo.
@echo 作者:Wangwei QQ:251485609 2009.12.21
@echo.
@echo.
set/p file= 请输入要处理的文件:
for %%i in (%file%) do (
set "jkz=%%~ni"
set "jz=%%~nxi"
set /a "size=%%~zi"
)
cd/d "%~dp0">nul
cls
@echo.
@echo 生成cmd文件或十六进制--输入任意码
@echo.
@echo 解密十六进制(需要sed.exe配合) 请输入 j
@echo.
set/p jcwj= 请选择输入:
if %jcwj%==j goto jai
if 65280 LSS %size% echo.该文件%size% ,大于65280字节,超出处理范围&pause>nul &goto zj
setlocal EnableDelayedExpansion
copy/b %file% $$$>nul
set/a qwe=%size%+255
call :duon %qwe%>nul
echo @echo off>"%jz%.cmd"
echo more +5 "%%~0"^|debug^&graftabl 936^>nul>>"%jz%.cmd"
echo copy/b/y $tmp$ "new%jz%"^>nul>>"%jz%.cmd"
echo del/a/f/q $tmp$>>"%jz%.cmd"
echo del %%0>>"%jz%.cmd"
(echo d100,%cdm%^&echo q)|debug $$$>ymdb.txt
for /f "eol=- skip=1 tokens=*" %%i in (ymdb.txt) do (
set bj=%%i
set bj=!bj:-= !
echo e !bj:~5,53!>>"%jz%.cmd")
del $$$
set /a qwe=%size%
call :duon %qwe% >nul
echo rcx>>"%jz%.cmd"
echo %cdm%>>"%jz%.cmd"
echo n$tmp$>>"%jz%.cmd"
echo w>>"%jz%.cmd"
echo q>>"%jz%.cmd"
graftabl 936 >nul
cls
@echo.
@echo 十六进制 bat 文件已经生成。
@echo.
set/p jxcl= 要生成十六进制码txt文本(无地址码、长度码)请输入1 (退出 任意码):
if %jxcl%==1 goto wb
goto :zj
:wb
findstr /v "Invalid" ymdb.txt>hwb.txt
cd.>a.txt
for /f "eol=- skip=1 tokens=*" %%i in (hwb.txt) do (
set bj=%%i
set bj=!bj:-= !
echo e !bj:~5,53!>>a.txt)
cd.>ah.txt
for /f "tokens=*" %%j in (a.txt) do (
set dd=%%j
echo !dd:~8,47!>>ah.txt)
set "r=1200"
(for /f "usebackq delims=" %%i in (ah.txt) do (
set "s=!s1!%%i "
set /a "m=8180,x=0,k=0"
for /l %%a in (1,1,14) do (
set /a "k=(m+x)/2"
for %%i in (!k!) do if "!s:~%%i!" equ "" (set /a m=k) else set /a x=k
)
for /l %%a in (0,%r%,!k!) do (
if !k! geq !r! echo !s:~%%a,%r%!
set/a "k-=r"&set "s1=!s:~%%a!"
)
)
if "!s1!" neq "" echo !s1!
)>"%jz%.txt"
del ah.txt
del hwb.txt
del a.txt
goto zj
:jai
::用 sed 第三方工具去除行尾空格
sed "s/ *$//" %file%>out.txt
findstr /v "Invalid" out.txt>awb.txt
::用 sed 第三方工具,快速将横列变纵列(方便计算原始文件字节)。
sed "s/ /\n/g" awb.txt>wab.txt
findstr /v "Invalid" wab.txt>wb.txt
del out.txt
del wab.txt
::检测行数并产生同等字节文件(这里行数就是原始文件字节)
set line=0
for /f "delims=" %%i in (wb.txt) do set /a line+=1
fsutil file createnew $$$ %line% >nul
setlocal EnableDelayedExpansion
::用debug(用纯批处理较慢)快速产生标准地址码
set/a qwe=%line%+255
call :duon %qwe%
(echo d100,%cdm%^&echo q)|debug $$$>ymdb.txt
cls
graftabl 936>nul
cd.>db.txt
for /f "eol=- skip=1 tokens=*" %%i in (ymdb.txt) do (
set bj=%%i
echo e !bj:~5,5!>>db.txt)
del $$$
del ymdb.txt
@echo 正在按48字节分割文件
set "r=48"
(for /f "usebackq delims=" %%i in (awb.txt) do (
set "s=!s1!%%i "
set /a "m=%size%+%r%,x=0,k=0"
for /l %%a in (1,1,14) do (
set /a "k=(m+x)/2"
for %%i in (!k!) do if "!s:~%%i!" equ "" (set /a m=k) else set /a x=k
)
for /l %%a in (0,%r%,!k!) do (
if !k! geq !r! echo !s:~%%a,%r%!
set/a "k-=r"&set "s1=!s:~%%a!"
)
)
if "!s1!" neq "" echo !s1!
)>m.txt
del wb.txt
@echo 标准地址码与编码正在合并
cd.>a.txt
set n=-1
for /f "delims=" %%a in (db.txt) do (
set/a n+=1
call :mp1 "%%a" )
del db.txt
del awb.txt
goto :ef
:mp1
if !n! equ 0 for /f "delims=" %%i in (m.txt) do echo %%a%%i>>a.txt&goto:eof
if not !n! equ 0 for /f "skip=%n% delims=" %%i in (m.txt) do echo %%a%%i>>a.txt&goto:eof
:duon
set /a y= qwe%%16
set /a ya=qwe/16%%16
set /a yb=qwe/256%%16
set /a yc=qwe/4069%%16
set m=0123456789ABCDEF
set cdm=!m:~%yc%,1!!m:~%yb%,1!!m:~%ya%,1!!m:~%y%,1!
goto:eof
:ef
echo @echo off>m.txt
echo more +5 "%%~0"^|debug^&graftabl 936^>nul>>m.txt
echo copy/b/y $tmp$ new-"%jkz%"^>nul>>m.txt
echo del/a/f/q $tmp$>>m.txt
echo del %%0>>m.txt
more a.txt>>m.txt
del a.txt
set/a qwe=%line%
call :duon %qwe%
echo rcx>>m.txt
echo %cdm%>>m.txt
echo n$tmp$>>m.txt
echo w>>m.txt
echo q>>m.txt
copy /b m.txt new-"%jz%".cmd
del m.txt
call new-%jz%.cmd
:zj
del ymdb.txt
goto 3nm [ Last edited by ZJHJ on 2010-3-3 at 09:50 ]
|