Skip to content

Commit e121a12

Browse files
authored
v6.5
fixed bug with BAT85 decoding, got broken in some previous update and I did not spot it since I mostly use BAT91 thanks to kyjdp for reporting it
1 parent a9f6ae9 commit e121a12

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

Compressed 2 TXT.bat

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@(echo off% <#%) &color 07 &title Compressed2TXT v6.4 - Files/Folders SendTo menu ascii encoder and makecab by AveYo
1+
@(echo off% <#%) &color 07 &title Compressed2TXT v6.5 - Files/Folders SendTo menu ascii encoder and makecab by AveYo
22
chcp 850 >nul &set "0=%~f0" &set 1=%*& powershell -nop -c iex ([io.file]::ReadAllText($env:0)); &exit/b ||#>)[1]; $PS={
33

44
## Now defaults to BAT91 and short lines
@@ -8,7 +8,7 @@ $env:1; if (!$env:1) {write-host "`n No input files or folders to encode! use 'S
88
$SendTo = [Environment]::GetFolderPath('ApplicationData') + '\Microsoft\Windows\SendTo'
99
## Save to SendTo menu when run from another location as well as when copy-pasted directly into powershell console
1010
if (!$env:1 -and $env:0 -notlike '*\SendTo\Compressed 2 TXT*') {
11-
$BAT='@(echo off% <#%) &color 07 &title Compressed2TXT v6.4 - Files/Folders SendTo menu ascii encoder and makecab by AveYo'+"`n"
11+
$BAT='@(echo off% <#%) &color 07 &title Compressed2TXT v6.5 - Files/Folders SendTo menu ascii encoder and makecab by AveYo'+"`n"
1212
$BAT+='chcp 850 >nul &set "0=%~f0" &set 1=%*& powershell -nop -c iex ([io.file]::ReadAllText($env:0)); &exit/b ||#>)[1]'
1313
$BAT+='; $PS={' + $PS + '}; .$PS; .$Main' + "`n#-.-# hybrid script, can be pasted directly into powershell console"
1414
[IO.File]::WriteAllLines($SendTo + '\Compressed 2 TXT.bat', $BAT -split "`r`n" -split "`n", [Text.Encoding]::ASCII)
@@ -106,9 +106,9 @@ if (!$env:1) { timeout -1; return }
106106
## Generate text decoding header - compact self-expanding batch file for bundled ascii encoded cab archive of target files
107107
$HEADER = "@echo off &chcp 850 >nul &pushd `"%~dp0`"`r`n"
108108
$HEADER += '@set "0=%~f0" &powershell -nop -c $f=[IO.File]::ReadAllText($env:0)-split'':bat2file\:.*'';iex($f[1]); X(1) '
109-
$HEADER += "&timeout /t 6 &exit/b`r`n`r`n:bat2file: Compressed2TXT v6.4`r`n"
109+
$HEADER += "&timeout /t 6 &exit/b`r`n`r`n:bat2file: Compressed2TXT v6.5`r`n"
110110
## Choice 4: Long lines (less overhead) - each line has 4 extra chars (cr lf ::) and short lines are ~8 times as many
111-
if ($choices -eq 'longlines') {$line = 1014} else {$line = 126}
111+
if ($choices -eq 'longlines') {$line = 1016} else {$line = 128}
112112
## Choice 1: Input decoding key as password - or bundle it with the file for automatic extraction
113113
if ($choices -eq 'password') {
114114
$HEADER += '$b=''Microsoft.VisualBasic'';Add-Type -As $b;$k=iex "[$b.Interaction]::InputBox(''Key'','+$chars+')";'
@@ -123,19 +123,18 @@ using System.IO; public class BAT85 {public static void Dec (ref string[] f, int
123123
byte[] b85=new byte[256];long n=0;int p=0,q=0,c=255,z=f[x].Length; while (c>0) b85[c--]=85; while (c<85) b85[key[c]]=(byte)c++;
124124
int[] p85={52200625,614125,7225,85,1}; using (FileStream o=new FileStream(fo,FileMode.Create)) { for (int i=0;i != z;i++) {
125125
c=b85[f[x][i]]; if (c==85) continue; n += c * p85[p++]; if (p==5) {p=0; q=4; while (q > 0) {q--; o.WriteByte((byte)(n>>8*q));}
126-
n=0;}} if (p>0) {for (int i=0;i<5-p;i++) {n += 84 * p85[p+i];} q=4; while (q > p-1) {q--;o.WriteByte((byte)(n>>8*q));} } } }}}
127-
'@ + "`r`n'@; "
126+
n=0;}} if (p>0) {for (int i=0;i<5-p;i++) {n += 84 * p85[p+i];} q=4; while (q>(5-p)) {o.WriteByte((byte)(n>>8*(--q)));} } } }}}
127+
'@ + "`r`n'@; " + 'cd -Lit($env:__CD__); function X([int]$x=1){[BAT85]::Dec([ref]$f,$x+1,$x,$k); '
128128
} else {
129129
$HEADER += @'
130130
using System.IO;public class BAT91{public static void Dec(ref string[] f,int x,string fo,string key){unchecked{int n=0,c=255,q=0
131131
,v=91,z=f[x].Length; byte[]b91=new byte[256]; while(c>0) b91[c--]=91; while(c<91) b91[key[c]]=(byte)c++; using (FileStream o=new
132132
FileStream(fo,FileMode.Create)){for(int i=0;i!=z;i++){c=b91[f[x][i]]; if(c==91)continue; if(v==91){v=c;}else{v+=c*91;q|=v<<n;if(
133133
(v&8191)>88){n+=13;}else{n+=14;}v=91;do{o.WriteByte((byte)q);q>>=8;n-=8;}while(n>7);}}if(v!=91)o.WriteByte((byte)(q|v<<n));} }}}
134-
'@ + "`r`n'@; "
134+
'@ + "`r`n'@; " + 'cd -Lit($env:__CD__); function X([int]$x=1){[BAT91]::Dec([ref]$f,$x+1,$x,$k); '
135135
}
136136
## Generate expand function
137-
$HEADER += 'cd -Lit($env:__CD__); function X([int]$x=1){[BAT91]::Dec([ref]$f,$x+1,$x,$k); expand -R $x -F:* .; del $x -force}'
138-
$HEADER += "`r`n`r`n:bat2file:[ $fn1`r`n"
137+
$HEADER += "expand -R `$x -F:* .; del `$x -force}`r`n`r`n:bat2file:[ $fn1`r`n"
139138
## BAT91 or BAT85 ascii encoding the cab archive of target files
140139
$output = $dir + "\$fn1~.bat"; $outputkey = $dir + "\$fn1~.ini"
141140
[IO.File]::WriteAllText($output, $HEADER)

0 commit comments

Comments
 (0)