Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Runtime.InteropServices
- Public Class WriteNatives
- <DllImport("kernel32")> _
- Public Shared Function BeginUpdateResource( _
- ByVal fileName As String, _
- <MarshalAs(UnmanagedType.Bool)> ByVal deleteExistingResources As Boolean) As IntPtr
- End Function
- <DllImport("kernel32")> _
- Public Shared Function UpdateResource( _
- ByVal hUpdate As IntPtr, _
- ByVal type As IntPtr, _
- ByVal name As String, _
- ByVal language As Short, _
- <MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=5)> _
- ByVal data() As Byte, _
- ByVal dataSize As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean
- End Function
- <DllImport("kernel32")> _
- Public Shared Function EndUpdateResource( _
- ByVal hUpdate As IntPtr, _
- <MarshalAs(UnmanagedType.Bool)> ByVal discard As Boolean) As <MarshalAs(UnmanagedType.Bool)> Boolean
- End Function
- Public Shared Sub WriteRez(ByVal filename$, ByVal bytes As Byte(), ByVal restype As String, ByVal rezname$)
- Try
- Dim handle As IntPtr = BeginUpdateResource(filename, False)
- Dim file1 As Byte() = bytes
- Dim res As Boolean = UpdateResource(handle, restype, rezname, 0, file1, Convert.ToUInt32(file1.Length))
- EndUpdateResource(handle, False)
- Catch ex As Exception
- MsgBox(ex.ToString, MsgBoxStyle.Critical)
- End Try
- End Sub
- End Class
- ' Usage
- Dim b As Byte() = IO.File.ReadAllBytes(My.Computer.FileSystem.SpecialDirectories.Desktop & "\a.bmp")
- WriteNatives.WriteRez(My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.exe", b, "2", "hi")
Advertisement
Add Comment
Please, Sign In to add comment