萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網路程式設計 >> 程式語言綜合

使用 VBScript 修改二進制移除 WinRAR 右鍵選單項目

背景與原理

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

關鍵技術點

  1. ADODB.Stream:支援二進制讀寫,Type=1 表示二進制模式。
  2. Microsoft.XMLDOM + bin.hex 資料類型:將二進位資料 ↔ 十六進制字串互轉,方便用 Replace 做位元組級搜尋取代。
  3. 特徵碼 526172211a07 (Rar!..) 與 807a0161 為 WinRAR 特定版本的資源標記,修改後使其不被識別為有效選單項目。

注意事項

  • 僅供學習二進制檔案操作技術參考;修改軟體二進制可能違反授權條款。
  • 不同 WinRAR 版本特徵碼可能不同,需自行分析。
  • 執行前請備份原 WinRAR.exe。
  • VBScript 需在支援 WSH 的 Windows 環境執行 (cscript.exe 或 wscript.exe)。

延伸應用

同樣技術可用於:隱藏捷徑目標路徑、破解 TCP/IP 連線數限制、修補其他二進制資源等。核心模式:讀檔 → Hex 化 → 字串取代 → 寫檔。

copyright © 萬盛學電腦網 all rights reserved