-1

I searched a lot but did not got the clear answer the one I'm looking for.

I want to edit the hex of the file and insert bytes in a .dll file

For example

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    ("C:\test.dll")

End Sub

so that when I click button1 it searches hex like 12 23 34 45 56 67 78 and modify it to 00 00 00 00 00 00 00/

Next, I want to insert without overwriting like 12 23 34 45 56, and I can insert 12 23 00 00 34 45 56.

Can anybody can help with these two points?

Thanks.

user353gre3
  • 2,747
  • 4
  • 24
  • 27
Js78955
  • 21
  • 5

1 Answers1

0

If the file is not too large, the simplest approach would be to

  1. load the file into a byte array (File.ReadAllBytes),
  2. find and replace the parts you want to replace,
  3. save the file back (File.WriteAllBytes).

For inserting, converting the byte array into a List(Of Byte), inserting the bytes and converting it back to an array is probably the easiest solution. (Again, if the file is not too large and the operation is not performance-critical.)

The implementation is left as an exercise.

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • As noted above, you cannot insert instructions or data into a DLL, as it would offset every relative branch and jumps that follow. You can however patch it, as long as the resulting machine code is still valid. – Drunken Code Monkey Dec 08 '14 at 20:20
  • @Heinzi Could You Please Write Whole Code Like Dim a as string like this taking example as file is in C:\Test.dll ? – Js78955 Dec 09 '14 at 23:54
  • @Drunken Code Monkey how about Adding in .exe ,will it break ? – Js78955 Dec 09 '14 at 23:56
  • 1
    @Js78955: Sorry, StackOverflow, is not a "we write your code for you" service. You are a software developer, are you not? Read the documentation, learn the language, try to write the code yourself, and if you have a *specific* question during development, return here and ask a (new) question. :-) – Heinzi Dec 10 '14 at 07:58
  • @Heinzi Im beginner i just started learning vb.net 5-7 days ago where ever i find vb tutorial i check it cus i want to learn vb.net i got interested in it so this basic commands should be known so that if you write it i will implement different way and find new way :) – Js78955 Dec 10 '14 at 13:32
  • i tried im not getting what the link all is in C# and im in vb.net help be bro, i need push to start now im left with nowwhere :( i want to edit the pattern and they totally over my head im not pro im just starter going over my head – Js78955 Dec 10 '14 at 14:35