欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

使用VBS修改二进制文件HEX数据

程序员文章站 2022-07-06 12:57:36
可用之处还是有的,如:隐藏快捷方式中目标文件位置;破解xp中tcp/ip连接数限制;去掉rar右键解压菜单等等。 复制代码 代码如下:public binarydata...
可用之处还是有的,如:隐藏快捷方式中目标文件位置;破解xp中tcp/ip连接数限制;去掉rar右键解压菜单等等。

使用VBS修改二进制文件HEX数据

复制代码 代码如下:

public binarydata

if (lcase(right(wscript.fullname,11))="wscript.exe") then
 wscript.quit(0)
end if

if wscript.arguments.count<4 then
 wscript.echo "change file hex. by: lxzzr  lxzzr@21cn.com"
 wscript.echo ""
 wscript.echo "usage: cscript.exe " & wscript.scriptname & " filepath savepath shex dhex"
 wscript.echo "     : cscript.exe chex.vbs "".\test.exe"" "".\new.exe"" ""80 7a 01 61"" ""80 7a 01 61"""
 wscript.quit(0)
end if

shex = replace(lcase(wscript.arguments(2)), " ", "")
dhex = replace(lcase(wscript.arguments(3)), " ", "")

wscript.echo "file: " & wscript.arguments(0)
wscript.echo "shex: " & wscript.arguments(2)
wscript.echo "dhex: " & wscript.arguments(3)

readbinary(wscript.arguments(0))

mydata = replace(binarydata, shex, dhex)

writebinary wscript.arguments(1), mydata

wscript.echo "all done."
wscript.quit(0)

 


function readbinary(filename)
 dim stream, objxml, mynode

 set objxml = createobject("microsoft.xmldom")
 set mynode = objxml.createelement("binary")
 set stream = createobject("adodb.stream")

 mynode.datatype = "bin.hex"

 stream.type = 1
 stream.open
 stream.loadfromfile filename

 mynode.nodetypedvalue = stream.read

 stream.close

 binarydata = mynode.text

 set mynode = nothing
 set stream = nothing
 set objxml = nothing
end function


function writebinary(filename, bufferdata)
 dim stream, objxml, mynode

 set objxml = createobject("microsoft.xmldom")
 set mynode = objxml.createelement("binary")
 set stream = createobject("adodb.stream")

 mynode.datatype = "bin.hex"
 mynode.text = bufferdata

 stream.type = 1
 stream.open
 stream.write mynode.nodetypedvalue
 stream.savetofile filename, 2
 stream.close

 set stream = nothing
 set mynode = nothing
 set objxml = nothing
end function