说明
今天扒拉ys168网盘的时候,发现了曾经研究的一个批处理。他的作用就是通过批处理的debug命令,将内置的十六进制转换为文件。
但由于debug的命令只会存在于32位的系统上,但32位系统现在已经退出舞台了,所以这种方式基本已经被淘汰了。
正好今天通过AI又重新研究了这一块的功能。
截图

演示

成品下载
源码
Imports System.IO
Imports System.Text
Imports System.IO.Compression
Public Class Form1
<System.Reflection.Obfuscation(Feature:="virtualization", Exclude:=False)>
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "极速文件释放器 By:Lxjc.Com"
Me.Size = New Size(450, 350)
Me.StartPosition = FormStartPosition.CenterScreen
Me.AllowDrop = True
Dim lbl As New Label With {
.Text = "【使用说明】" & vbCrLf & vbCrLf &
"1. 将需要封装的文件(EXE、图片等)拖入此窗口" & vbCrLf &
"2. 程序将自动在同目录下生成一个 [原文件名_释放器.bat]" & vbCrLf &
"3. 运行该批处理即可实现静默释放、解密并自动打开" & vbCrLf & vbCrLf &
"请拖入文件开始转换...",
.Dock = DockStyle.Fill,
.TextAlign = ContentAlignment.MiddleCenter,
.Font = New Font("微软雅黑", 10)
}
Me.Controls.Add(lbl)
End Sub
Private Sub Form1_DragEnter(sender As Object, e As DragEventArgs) Handles Me.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then e.Effect = DragDropEffects.Copy
End Sub
Private Sub Form1_DragDrop(sender As Object, e As DragEventArgs) Handles Me.DragDrop
Dim files As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
If files.Length > 0 Then GenerateBatchFile(files(0))
End Sub
<System.Reflection.Obfuscation(Feature:="virtualization", Exclude:=False)>
Private Sub GenerateBatchFile(filePath As String)
Try
Dim rawBytes As Byte() = File.ReadAllBytes(filePath)
Dim fileName As String = Path.GetFileName(filePath)
Dim directory As String = Path.GetDirectoryName(filePath)
Dim batchFileName As String = Path.Combine(directory, Path.GetFileNameWithoutExtension(filePath) & "_释放器.bat")
Dim compressedBytes As Byte()
Using ms As New MemoryStream()
Using gs As New GZipStream(ms, CompressionLevel.Optimal, True)
gs.Write(rawBytes, 0, rawBytes.Length)
End Using
compressedBytes = ms.ToArray()
End Using
For i As Integer = 0 To compressedBytes.Length - 1
compressedBytes(i) = compressedBytes(i) Xor &H88
Next
Dim hex As New StringBuilder(compressedBytes.Length * 2)
For Each b In compressedBytes : hex.Append(b.ToString("X2")) : Next
Dim rawCsharp As String = "using System;using System.IO;using System.IO.Compression;using System.Text;using System.Diagnostics;public class FastEngine{public static void Release(string m,byte k,string b64Name){string p=Environment.GetEnvironmentVariable(""SELF"");string dir=Path.GetDirectoryName(p);string t=Path.Combine(dir,Encoding.UTF8.GetString(Convert.FromBase64String(b64Name)));string s=File.ReadAllText(p,Encoding.UTF8);int i=s.LastIndexOf(m)+m.Length;string h=s.Substring(i).Trim();byte[] b=new byte[h.Length/2];for(int x=0;x<b.Length;x++){b[x]=(byte)((Gv(h[x*2])<<4)|Gv(h[x*2+1]));b[x]^=k;}using(MemoryStream mi=new MemoryStream(b))using(GZipStream g=new GZipStream(mi,CompressionMode.Decompress))using(FileStream fs=new FileStream(t,FileMode.Create)){g.CopyTo(fs);}Process.Start(new ProcessStartInfo(t){UseShellExecute=true});}private static int Gv(char c){return c<='9'?c-'0':c<='F'?c-'A'+10:c-'a'+10;}}"
Dim base64Csharp As String = Convert.ToBase64String(Encoding.UTF8.GetBytes(rawCsharp))
Dim base64FileName As String = Convert.ToBase64String(Encoding.UTF8.GetBytes(fileName))
Dim sb As New StringBuilder()
sb.AppendLine("@echo off")
sb.AppendLine("if ""%1"" == ""h"" goto :run")
sb.AppendLine("mshta vbscript:createobject(""wscript.shell"").run(""""""%~f0"""" h"",0)(window.close)&&exit")
sb.AppendLine(":run")
sb.AppendLine("setlocal")
sb.AppendLine("set ""SELF=%~f0""")
Dim psCommand As String = String.Format(
"$c=[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('{0}')); " &
"Add-Type -TypeDefinition $c; " &
"[FastEngine]::Release(':::DATA:::', 0x88, '{1}');",
base64Csharp, base64FileName)
sb.Append("powershell -NoProfile -ExecutionPolicy Bypass -Command """).Append(psCommand).AppendLine(""" >nul 2>&1")
sb.AppendLine("endlocal")
sb.AppendLine("exit /b")
sb.AppendLine()
sb.AppendLine(":::DATA:::")
sb.Append(hex.ToString())
File.WriteAllText(batchFileName, sb.ToString(), New UTF8Encoding(False))
MessageBox.Show("转换完成!", "成功")
Catch ex As Exception
MessageBox.Show("错误: " & ex.Message)
End Try
End Sub
End Class