Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change Bat code to pure PowerShell code? #8

Open
Davider-code opened this issue Nov 14, 2021 · 2 comments
Open

How to change Bat code to pure PowerShell code? #8

Davider-code opened this issue Nov 14, 2021 · 2 comments

Comments

@Davider-code
Copy link

Thank you very much for the hard work of the developers of this project

I want to change the bat code into PowerShell code

My programming level is not good. I tried several times without success, so I want to ask the developer for help. Thank you in advance

In addition, I want to know how to customize the output path, for example: $path ='c:\ABC '

code1---bat

@echo off & color 07 & chcp 65001 >nul
set "0=%~f0" & powershell -nop -c $f=[IO.File]::ReadAllText($env:0)-split':bat2file\:.*';iex($f[1]); X 1
@pause & exit/b

:bat2file: Compressed2TXT v6.1
$k='$&Y5OqzhK#sx]F+~,);@m3CaWT0_/Hb(2ekj8N-pr^6ltQ{VndBGJ|SMEo[cvA?9yZ=f!}.i4XwgRDPuUI1L7'; Add-Type -Ty @'
using System.IO; public class BAT85 {public static void Dec (ref string[] f, int x, string fo, string key) { unchecked {
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++;
int[] p85={52200625,614125,7225,85,1}; using (FileStream o=new FileStream(fo,FileMode.Create)) { for (int i=0;i != z;i++) {
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));}
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));} } } }}}
'@; cd -lit (Split-Path $env:0); function X([int]$x=1) {[BAT85]::Dec([ref]$f,$x+1,$x,$k); expand -R $x -F:* .; del $x -force}

:bat2file:[ test_txt
::W4Nj6$$$$$(+uW]$$$$$+]YEt$$$$$$1q8q$__#&Tz,rIC~$0}$__;T$II_5$$$$$$$5DaP6yG&Nk}Qa+uKH[$5iJ-$Yxja$$&vx$$#z&$$#z&$$#z&$q3mZ$$
:bat2file:]

code2---powershell--no't succeed

$_b = @'
::W4Nj6$$$$$(+uW]$$$$$+]YEt$$$$$$1q8q$__#&Tz,rIC~$0}$__;T$II_5$$$$$$$5DaP6yG&Nk}Qa+uKH[$5iJ-$Yxja$$&vx$$#z&$$#z&$$#z&$q3mZ$$
'@

$k='$&Y5OqzhK#sx]F+~,);@m3CaWT0_/Hb(2ekj8N-pr^6ltQ{VndBGJ|SMEo[cvA?9yZ=f!}.i4XwgRDPuUI1L7'; Add-Type -Ty @'
using System.IO; public class BAT85 {public static void Dec (ref string[] f, int x, string fo, string key) { unchecked {
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++;
int[] p85={52200625,614125,7225,85,1}; using (FileStream o=new FileStream(fo,FileMode.Create)) { for (int i=0;i != z;i++) {
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));}
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));} } } }}}
'@

function X([int]$x = 1) { [BAT85]::Dec([ref]$_b, $x + 1, $x, $k); expand -R $x -F:* .; del $x -force }

X 1
@AveYo
Copy link
Owner

AveYo commented Nov 14, 2021

You can pushd / set-location to the directory you want before running it, and it will unpack there

As for using it purely via powershell, it needs more adjustments since it's made to support multiple file attachments.
I plan to restructure the output to make that easier.

But if you can't wait, here's your example with BAT85 and randomized password:

# first, mimic $f as it is in the batch file output - the first attachment would be $f[2] 
$f = @(0,0)
$f+= @'
::!e^f7}}}}}zpN]c}}}}}-{0Xr}}}}}}=9K9}OOh0V8SfqpTx3.}||hw}66|U}}}}}}}UECg^Oq/^JPQCbZiR,^l8a4^C,JJ}}}_U}}}}}fnUWb2!oz~^_Sa-$mr67-~db4
::}0+l;WG=TE}}VZu}}|hU}}_@V}}_@V}9o.GWj5Q
'@

# second, add the decode part
$b='Microsoft.VisualBasic';Add-Type -As $b;$k=iex "[$b.Interaction]::InputBox('Key',85)";if($k.Length-ne85){exit};Add-Type -Ty @'
using System.IO; public class BAT85 {public static void Dec (ref string[] f, int x, string fo, string key) { unchecked {
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++;
int[] p85={52200625,614125,7225,85,1}; using (FileStream o=new FileStream(fo,FileMode.Create)) { for (int i=0;i != z;i++) {
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));}
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)));} } } }}}
'@; cd -Lit($env:__CD__); function X([int]$x=1){[BAT85]::Dec([ref]$f,$x+1,$x,$k); expand -R $x -F:* .; del $x -force}

# third, call decode function - with arg = 1 because it's the 1st attachment
X(1)

use this randomized key when asked:
}V0UN9@Sd_23{A-WBqh(.oHC!w]|lb)D$pJfK^/n+x7zrQR&1?cmvIOMXa4uZL#TiGkFjPy;esYt[Eg~86=5,

@Davider-code
Copy link
Author

You can pushd / set-location to the directory you want before running it, and it will unpack there

As for using it purely via powershell, it needs more adjustments since it's made to support multiple file attachments. I plan to restructure the output to make that easier.

But if you can't wait, here's your example with BAT85 and randomized password:

# first, mimic $f as it is in the batch file output - the first attachment would be $f[2] 
$f = @(0,0)
$f+= @'
::!e^f7}}}}}zpN]c}}}}}-{0Xr}}}}}}=9K9}OOh0V8SfqpTx3.}||hw}66|U}}}}}}}UECg^Oq/^JPQCbZiR,^l8a4^C,JJ}}}_U}}}}}fnUWb2!oz~^_Sa-$mr67-~db4
::}0+l;WG=TE}}VZu}}|hU}}_@V}}_@V}9o.GWj5Q
'@

# second, add the decode part
$b='Microsoft.VisualBasic';Add-Type -As $b;$k=iex "[$b.Interaction]::InputBox('Key',85)";if($k.Length-ne85){exit};Add-Type -Ty @'
using System.IO; public class BAT85 {public static void Dec (ref string[] f, int x, string fo, string key) { unchecked {
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++;
int[] p85={52200625,614125,7225,85,1}; using (FileStream o=new FileStream(fo,FileMode.Create)) { for (int i=0;i != z;i++) {
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));}
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)));} } } }}}
'@; cd -Lit($env:__CD__); function X([int]$x=1){[BAT85]::Dec([ref]$f,$x+1,$x,$k); expand -R $x -F:* .; del $x -force}

# third, call decode function - with arg = 1 because it's the 1st attachment
X(1)

use this randomized key when asked: }V0UN9@Sd_23{A-WBqh(.oHC!w]|lb)D$pJfK^/n+x7zrQR&1?cmvIOMXa4uZL#TiGkFjPy;esYt[Eg~86=5,

Thank you very much for your reply
I'm looking forward to code enhancement. Pure PowerShell code can support custom expand paths,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants