WinRAR 安裝後會在檔案總管右鍵選單加入解壓縮相關項目。若不想透過安裝程式設定關閉,可直接修改 WinRAR.exe 二進制資源,將特徵位元組修改以停用選單項目。本文提供 VBScript 實作,利用 ADODB.Stream 讀寫二進制檔案,配合 Microsoft.XMLDOM 進行十六進制編碼轉換。
Public ReadBinary
' 讀取原檔案並修改特徵碼
ReadBinaryDat(".1.exe")
BinaryDat = Replace(Replace(ReadBinary, "526172211a07", "522172211a07"), "807a0161", "807a0121")
WriteBinaryDat "new.exe", BinaryDat
' 讀取二進制檔案並轉為 Hex 字串
Function ReadBinaryDat(FileName)
Const adTypeBinary = 1
Dim stream, xmldom, node
Set xmldom = CreateObject("Microsoft.XMLDOM")
Set node = xmldom.CreateElement("binary")
node.DataType = "bin.hex"
Set stream = CreateObject("ADODB.Stream")
stream.Type = adTypeBinary
stream.Open
stream.LoadFromFile FileName
node.NodeTypedValue = stream.Read
stream.Close
Set stream = Nothing
ReadBinary = node.Text
Set node = Nothing
Set xmldom = Nothing
End Function
' 將 Hex 字串寫入二進制檔案
Sub WriteBinaryDat(FileName, Buf)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Dim stream, xmldom, node
Set xmldom = CreateObject("Microsoft.XMLDOM")
Set node = xmldom.CreateElement("binary")
node.DataType = "bin.hex"
node.Text = Buf
Set stream = CreateObject("ADODB.Stream")
stream.Type = adTypeBinary
stream.Open
stream.Write node.NodeTypedValue
stream.SaveToFile FileName, adSaveCreateOverWrite
stream.Close
Set stream = Nothing
Set node = Nothing
Set xmldom = Nothing
End Sub
ADODB.Stream:支援二進制讀寫,Type=1 表示二進制模式。Microsoft.XMLDOM + bin.hex 資料類型:將二進位資料 ↔ 十六進制字串互轉,方便用 Replace 做位元組級搜尋取代。526172211a07 (Rar!..) 與 807a0161 為 WinRAR 特定版本的資源標記,修改後使其不被識別為有效選單項目。WinRAR.exe。cscript.exe 或 wscript.exe)。同樣技術可用於:隱藏捷徑目標路徑、破解 TCP/IP 連線數限制、修補其他二進制資源等。核心模式:讀檔 → Hex 化 → 字串取代 → 寫檔。