[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 将CMD和PS混合的代码改为纯PS代码

本帖最后由 5i365 于 2021-11-14 09:17 编辑

代码1是CMD和PS混合的代码,
将其另存为 a.bat 执行后,可以在当前目录下生成一个 test.txt 的文件

现在我想将这个代码改为纯Powershell代码, 改了很多次, 不能执行成功, 求助精通CMD和PS的高手, 指点一下, 非常感谢
代码2是我自己改的纯PS代码, 不能执行成功, 供参考

代码1---CMD代码
  1. @echo off & color 07 & chcp 65001 >nul
  2. set "0=%~f0" & powershell -nop -c $f=[IO.File]::ReadAllText($env:0)-split':bat2file\:.*';iex($f[1]); X 1
  3. @pause & exit/b
  4. :bat2file: Compressed2TXT v6.1
  5. $k='$&Y5OqzhK#sx]F+~,);@m3CaWT0_/Hb(2ekj8N-pr^6ltQ{VndBGJ|SMEo[cvA?9yZ=f!}.i4XwgRDPuUI1L7'; Add-Type -Ty @'
  6. using System.IO; public class BAT85 {public static void Dec (ref string[] f, int x, string fo, string key) { unchecked {
  7. 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++;
  8. int[] p85={52200625,614125,7225,85,1}; using (FileStream o=new FileStream(fo,FileMode.Create)) { for (int i=0;i != z;i++) {
  9. 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));}
  10. 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));} } } }}}
  11. '@; 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}
  12. :bat2file:[ test_txt
  13. ::W4Nj6$$$$$(+uW]$$$$$+]YEt$$$$$$1q8q$__#&Tz,rIC~$0}$__;T$II_5$$$$$$$5DaP6yG&Nk}Qa+uKH[$5iJ-$Yxja$$&vx$$#z&$$#z&$$#z&$q3mZ$$
  14. :bat2file:]
复制代码
代码2---PS代码
  1. $_b = @'
  2. ::W4Nj6$$$$$(+uW]$$$$$+]YEt$$$$$$1q8q$__#&Tz,rIC~$0}$__;T$II_5$$$$$$$5DaP6yG&Nk}Qa+uKH[$5iJ-$Yxja$$&vx$$#z&$$#z&$$#z&$q3mZ$$
  3. '@
  4. $k='$&Y5OqzhK#sx]F+~,);@m3CaWT0_/Hb(2ekj8N-pr^6ltQ{VndBGJ|SMEo[cvA?9yZ=f!}.i4XwgRDPuUI1L7'; Add-Type -Ty @'
  5. using System.IO; public class BAT85 {public static void Dec (ref string[] f, int x, string fo, string key) { unchecked {
  6. 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++;
  7. int[] p85={52200625,614125,7225,85,1}; using (FileStream o=new FileStream(fo,FileMode.Create)) { for (int i=0;i != z;i++) {
  8. 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));}
  9. 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));} } } }}}
  10. '@
  11. function X([int]$x = 1) { [BAT85]::Dec([ref]$_b, $x + 1, $x, $k); expand -R $x -F:* .; del $x -force }
  12. X 1
复制代码

返回列表