[已解决]查找与替换的小程序,生成的大小与原文件不同![4楼正解!]
本帖最后由 chishingchan 于 2012-12-17 19:41 编辑$FN = ("File.dll")
$FS = "740717"
$RS = "909090"
$SR = StringReplace(StringToBinary(FileRead($FN)),$FS,$RS)
FileMove($FN,$FN&".BAK")
$KO = BinaryToString($SR)
FileWrite($FN,$KO)
如题,请问如何修正这个错误?谢谢! FileOpen("文件名", 16) 回复 2# afan
改成 FileOpen("文件名",16) 也不行,比原文件小的更厉害! 回复 3# chishingchan
谁知道你怎么写的…Local $FN = 'File.dll'
Local $FO = FileOpen($FN, 16)
Local $sBin = FileRead($FO)
FileClose($FO)
Local $sFS = '740717', $sRS = '909090'
Local $sSR = StringReplace($sBin, $sFS, $sRS)
If @extended = 0 Then Exit 1
FileMove($FN, $FN & '.BAK')
$FO = FileOpen($FN, 2 + 16)
FileWrite($FO, $sSR)
FileClose($FO) $FN = ("PPP.dll");541152 字节
$FS = "741F8BF1"
$RS = "90908BF1"
$FR = FileRead($FN)
$SB = StringToBinary($FR)
$SR = StringReplace($SB,$FS,$RS)
FileMove($FN,$FN&".BAK")
$KO = BinaryToString($SR)
MsgBox(0,"长度","$FR=" & StringLen($FR) & @CRLF& "$SR=" & StringLen($SR) & @CRLF & "$KO=" & StringLen($KO))
FileWrite($FN,$KO)
回复 5# chishingchan
我是这样写的。 回复 4# afan
谢谢!你的代码可以了。 总结一下:如有错误请指正,谢谢!Func SRB($FileName,$SearchBin,$ReplaceBin)
$FR = FileRead(FileOpen($FileName))
$STB = StringToBinary($FR)
FileClose($FileName)
$SR = StringReplace($STB,$SearchBin,$ReplaceBin)
$BTS = BinaryToString($SR)
;FileMove($FileName,$FileName&".BAK")
FileOpen($FileName,2+16)
FileWrite($FileName,$BTS)
FileClose($FileName)
EndFunc
页:
[1]