查找字符串中第一个字符的偏移量并使用此方法:
Private Sub Patch(ByVal TargetFile As String, ByVal FileOffset As Long, ByVal NewValue() As Byte)
Try
Dim br As BinaryReader = New BinaryReader(File.Open(TargetFile, FileMode.Open))
br.BaseStream.Position = FileOffset
Dim byteB As Byte
For Each byteB In NewValue
If (byteB.ToString <> String.Empty) Then
br.BaseStream.WriteByte(byteB)
Else
Exit For
End If
Next byteB
br.Close()
Catch
End Try
End Sub
像这样:
Patch("C:\localhost.exe", Val("OFFSET OF FIRST CHARACTER IN STRING"), New Byte() {&H31, &H32, &H37, &H2e, &H30, &H2e, &H30, &H2e, &H38})
或者代替你的字节数组,使用这个:
System.Text.Encoding.ASCII.GetBytes("127.0.0.8") 'It'll change 127.0.0.1 to 127.0.0.8
只需确保字符串的第一个字符具有正确的偏移量