Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Runtime.InteropServices
- Public Class Win32RW
- <DllImport("kernel32", CharSet:=CharSet.Unicode)> _
- Public Shared Function BeginUpdateResource( _
- ByVal fileName As String, _
- <MarshalAs(UnmanagedType.Bool)> ByVal deleteExistingResources As Boolean) As IntPtr
- End Function
- <DllImport("kernel32", CharSet:=CharSet.Unicode)> _
- Public Shared Function UpdateResource( _
- ByVal hUpdate As IntPtr, _
- ByVal type As IntPtr, _
- ByVal name As IntPtr, _
- 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", CharSet:=CharSet.Unicode)> _
- Public Shared Function EndUpdateResource( _
- ByVal hUpdate As IntPtr, _
- <MarshalAs(UnmanagedType.Bool)> ByVal discard As Boolean) As <MarshalAs(UnmanagedType.Bool)> Boolean
- End Function
- <DllImport("kernel32.dll", CharSet:=CharSet.Unicode)> _
- Private Shared Function FindResource(hModule As IntPtr, lpName As IntPtr, lpType As IntPtr) As IntPtr
- End Function
- <DllImport("kernel32.dll")> _
- Private Shared Function LoadLibraryEx(lpFileName As String, hReservedNull As IntPtr, dwFlags As LoadLibraryFlags) As IntPtr
- End Function
- <System.Flags()>
- Enum LoadLibraryFlags As UInteger
- DONT_RESOLVE_DLL_REFERENCES = &H1
- LOAD_IGNORE_CODE_AUTHZ_LEVEL = &H10
- LOAD_LIBRARY_AS_DATAFILE = &H2
- LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = &H40
- LOAD_LIBRARY_AS_IMAGE_RESOURCE = &H20
- LOAD_WITH_ALTERED_SEARCH_PATH = &H8
- End Enum
- <DllImport("kernel32", CharSet:=CharSet.Unicode)> _
- Private Shared Function SizeofResource(ByVal hModule As IntPtr, ByVal hResInfo As IntPtr) As Integer
- End Function
- <DllImport("kernel32", CharSet:=CharSet.Unicode)> _
- Private Shared Function LoadResource(ByVal hModule As IntPtr, ByVal hResInfo As IntPtr) As IntPtr
- End Function
- Sub read()
- Dim hModule As IntPtr = LoadLibraryEx(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Junk.exe", IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)
- Dim loc As IntPtr = FindResource(hModule, New IntPtr(1), New IntPtr(10))
- Dim x As IntPtr = LoadResource(hModule, loc)
- Dim size As Integer = SizeofResource(hModule, loc)
- Dim bPtr As Byte() = New Byte(size - 1) {}
- Marshal.Copy(x, bPtr, 0, CInt(size))
- MsgBox(System.Text.Encoding.UTF8.GetString(bPtr))
- End Sub
- Sub write()
- Dim bytes() As Byte = System.Text.Encoding.UTF8.GetBytes("#yolo")
- Dim handle As IntPtr = BeginUpdateResource(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Junk.exe", False)
- UpdateResource(handle, New IntPtr(10), New IntPtr(1), 0, bytes, bytes.Length)
- EndUpdateResource(handle, False)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment