


I never dreamed there would be such an elegant hack that would work even on native XP. Lots of clever techniques all packed into one solution.
Dave Benham
Moderator: DosItHelp
Code: Select all
findstr /v $ "%~f0" >outputFile
dbenham wrote:no one figured out a universal way to generate <tab> with batch.
Code: Select all
@echo off
set "t=~.bat"
type nul>"%temp%\%t%"
set "space= "
ver | find /i "XP" >nul && set "space="
forfiles -m%space%"%t%" -p%space%"%temp%" -c%space%"cmd /c set /p =set tab=0x09<nul">"%temp%\%t%"
call "%temp%\%t%"
del "%temp%\%t%"
echo "%tab%"
pause
Code: Select all
@Echo Off
Set "foo=%Temp%\foo.foo"
Call :0
Call :8
Call :10
Call :13
Call :26
Call :27
Goto :Eof
:0
::This routine create the file 0.chr that only have the nul character
::Tested on windows 8, winxp 32 home, win xp 32 prof, windows 7 32bit
::Authors: carlos, aGerman, penpen
Cmd /U /C Set /P "=a" <Nul > 0.chr
Copy /Y 0.chr+Nul 0.chr >Nul
Type 0.chr |(Pause>Nul &Findstr "^") > "%foo%"
Copy /Y "%foo%" /A 0.chr /B >Nul
Goto :Eof
:8
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do Set /P "=%%#" <Nul >8.chr
Goto :Eof
:10
Echo(|(Pause >Nul &Findstr "^" >10.chr)
Goto :Eof
:13
Call :26
For /F %%# In (26.chr) Do Set "sub=%%#"
Echo(>"%foo%"
For /F %%# In ('Copy /Z "%foo%" Nul') Do Echo(%%#%sub%>"%foo%"
Copy /Y "%foo%" /A 13.chr /B >Nul
Goto :Eof
:26
Copy /Y Nul+Nul /A 26.chr /A >Nul
Goto :Eof
:27
For /F %%# In (
'"Prompt $E &For %%_ In (_) Do Rem"') Do Set /P "=%%#" <Nul >27.chr
Goto :Eof
Code: Select all
@echo off
set "t=~.bat"
type nul>"%temp%\%t%"
set "space= "
ver | find /i "XP" >nul && set "space="
forfiles -m%space%"%t%" -p%space%"%temp%" -c%space%"cmd /c set /p =set FF=0xff<nul">"%temp%\%t%"
call "%temp%\%t%"
del "%temp%\%t%"
echo "%FF%"
pause
penpen wrote:I think i remember it contains its own filesize somewhere in the header (in little endian).
Code: Select all
@echo off &setlocal
>"t.tmp" type nul
for /l %%i in (1 1 169) do >>t.tmp <nul set /p "=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
>nul makecab /d compress=off "t.tmp" "t.chr"
type "t.chr" | >"t.tmp" (pause>nul&pause>nul&pause>nul&pause>nul&pause>nul&pause>nul&pause>nul&pause>nul&findstr "^")
>nul copy /y "t.tmp" /a "t.chr" /b
del "t.tmp"
foxidrive wrote:The forfiles that I downloaded in XP days doesn't have the same syntax as Vista and later version so I added a kludge for XP.
penpen wrote:Actually i'm posting by my mobile phone so i can't test it, but couldn't we use the makecab.exe:
I think i remember it contains its own filesize somewhere in the header (in little endian).
So creating a non compressed cab with the right filesize (and name) should serve us the needed hex codes.
A filesize of 0x1AFF should serve us a header entry of "FF1A" so we could do the same trick as above to extract this hex FFchar.
So we need to create cab filesizes of 0x1A01 to 0x1AFF.
penpen
Edit: If i'm wrong with the cab filesize, then the filesize of the (un)compressed must be present somewhere in the cab, same trick, but not as near to the start of the file.
Code: Select all
Makecab /D Compress=OFF file.dat file.cab
Code: Select all
Makecab /D Compress=OFF a file.cab
Code: Select all
@Echo Off
REM This will create a file with the size of 6665 bytes.
>a.a (echo AAA)
for /L %%f in (1,1,2220) do >>a.a (echo A)
Set "p=Pause>Nul"
Set "q=%p%&%p%&%p%&%p%&%p%&%p%&%p%&%p%&%p%&%p%&%p%"
Set "s=%q%%q%%q%%q%&%p%&%p%&%p%"
Makecab /D Compress=OFF a.a a.cab >Nul
Type a.cab |(%s%&Findstr "^") >wnul.tmp
Copy /Y wnul.tmp /A tab.chr /B >Nul
Del a.cab a.a wnul.tmp
Rem tab.chr has the TAB character
miskox wrote:- aGerman's solution to get TAB does not work for me (XP PRO)
miskox wrote:- here is my code (modified original Carlo's work):
carlos wrote:then if we create a cabinet of file with 6656 bytes with a length filename of 1, the cabinet size would be 6718 bytes, in Little endian 3E 1A
and we have this 1A in offset 9 stopping our work.
Also, cutoff the cabinet in the 1A is needed for avoid a findstr error message "too large line".
Code: Select all
@echo off &setlocal EnableDelayedExpansion
md "characters"
pushd "characters"
>"t.tmp" <nul set /p "=a"
for /l %%i in (1 1 140) do >>t.tmp <nul set /p "=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
set "strMap=0123456789ABCDEF"
for /l %%i in (0 1 255) do (
set "byte=%%i" &set "strHex="
for /l %%j in (1 1 2) do (
set /a "x = byte & 15, byte >>= 4"
for %%k in (!x!) do set "strHex=!strMap:~%%k,1!!strHex!"
)
>>t.tmp <nul set /p "=a"
>nul makecab /d compress=off "t.tmp" "!strHex!.chr"
type "!strHex!.chr" | >"temp.tmp" (pause>nul&pause>nul&pause>nul&pause>nul&pause>nul&pause>nul&pause>nul&pause>nul&findstr "^")
>nul copy /y "temp.tmp" /a "!strHex!.chr" /b
)
REM carlos' bug fix for the SUB character
Copy /Y Nul+Nul /A 1A.chr /A >Nul
del "t.tmp" "temp.tmp"
popd
pause
Code: Select all
Rem Fix for 26.chr
Copy /Y Nul+Nul /A 026.chr /A >Nul
aGerman, please you can create the character on hexadecimal notation with a width of 2, example: 0F.chr