Find and replace in binary
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts
Page 1 of 1
I have the code to read binary etc.
I want to find a replace a text string in a binary, any code?
I want to find a replace a text string in a binary, any code?
What sort of string? This should work for ASCII. Also assuming your input is a byte array.
Code: Select all
Dim input As Byte() = Encoding.ASCII.GetBytes("00FindThis12")
Dim lookFor As Byte() = Encoding.ASCII.GetBytes("FindThis")
Dim temp(lookFor.Length - 1) As Byte
For i As Integer = 0 To input.Length - lookFor.Length
System.Buffer.BlockCopy(input, i, temp, 0, lookFor.Length)
'MsgBox(Encoding.ASCII.GetString(temp))'show progress
If temp.SequenceEqual(lookFor) Then
MsgBox("Found lookfor at offset " & i & " of input.")
input(i) = Asc("2"c) ' replace 'F' with '2'
MsgBox(Encoding.ASCII.GetString(input))'output for visible purpose only. do not use this string for your data
Exit For
End If
Next
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023