本帖最后由 CrLf 于 2013-7-16 20:46 编辑
一个方案是 ascode,比 debug 通用些:- @echo off
- if "%1"=="" goto gethex
- if %1%2%3%4==52617221 echo 可能是 RAR 格式
- if %1%2%3==FFD8FF echo 可能是 JPG 格式文本
- if %1%2%3%4%5==4749463839 echo 可能是 GIF 格式文本
- if %1%2==FFFE echo 可能是 Unicode 格式文本
-
- :gethex
- (for /f "delims=" %%a in ('findstr /ib "::gethex" "%~0"') do echo %%~na)>gethex.com
- (gethex.com; &echo;)<222.txt | cmd /vc "set /p str=&%0 !str!"
- ::gethex\RQPUWP]UZV_BBBB5``PY(E1(E5)E7)E<(E@)EI-
- ::gethex\SX3CP< ~v<P}k%ooQRY2AY0@ uP0EPGEB?_]XYZ
- ::gethex\020680008KN8740LKN82004M4MJL3L3K7402454N
- ::gethex\K40KLM213L007432K408LM213L0J74063L0M7402
- ::gethex\NK078JM0N82O00NKN38JM052K104M2NJN815005J
- ::gethex\N8110050K440KK01008KLM8KM6LM2158NKL6LM20
- ::gethex\80N20O80L23080OJ3J7L0380L207K402LM21L3
复制代码 另一个方案是 ado,用 "cscript /nologo gethex.vbs 要取得的文件 要取得的字节数" 可以取得头部几个字节的 hex,至于比较关键词什么的,就和上面的 bat 大同小异了,gethex.vbs 内容如下:- Const length = 16 '输出时每段的字节数
- delim = vbCrLf '连接连接每段的字符串
-
- Dim var()
- ReDim var(0)
- id = 0
-
- With CreateObject("ADODB.Stream")
- .Type = 1
- .Open
- .LoadFromFile WScript.Arguments(0)
-
- For i = 1 To WScript.Arguments(1)
- h = Hex(AscB(.Read(1)))
- If Len(h) = 1 Then h = 0 & h
- var(id) = var(id) & h & " "
-
- If (i Mod length) = 0 Then
- var(id) = var(id)
- id = id+1
- ReDim Preserve var(id)
- End If
- Next
- End With
-
- WScript.Echo Join(var,delim)
复制代码
|