Hey Guys, i've been working on a .dll injector/loader and i added the inject code and i keep getting this error..
Code:
Error 1 'IsNot' requires operands that have reference types, but this operand has the value type 'System.IntPtr'. C:\Users\SimplyUnknown\documents\visual studio 2010\Projects\HC Loader\HC Loader\Class1.vb 64 16 HC Loader
here is the original code >
Code:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Threading
Namespace Injector
Public Class Inject
<DllImport("kernel32")> _
Public Shared Function CreateRemoteThread(hProcess As IntPtr, lpThreadAttributes As IntPtr, dwStackSize As UInteger, lpStartAddress As UIntPtr, lpParameter As IntPtr, dwCreationFlags As UInteger, _
lpThreadId As IntPtr) As IntPtr
End Function
<DllImport("kernel32.dll")> _
Public Shared Function OpenProcess(dwDesiredAccess As UInt32, bInheritHandle As Int32, dwProcessId As Int32) As IntPtr
End Function
<DllImport("kernel32.dll")> _
Public Shared Function CloseHandle(hObject As IntPtr) As Int32
End Function
Private Declare Auto Function VirtualFreeEx Lib "kernel32.dll" (hProcess As IntPtr, lpAddress As IntPtr, dwSize As UIntPtr, dwFreeType As UInteger) As Boolean
<DllImport("kernel32.dll", CharSet := CharSet.Ansi, ExactSpelling := True)> _
Public Shared Function GetProcAddress(hModule As IntPtr, procName As String) As UIntPtr
End Function
Private Declare Auto Function VirtualAllocEx Lib "kernel32.dll" (hProcess As IntPtr, lpAddress As IntPtr, dwSize As UInteger, flAllocationType As UInteger, flProtect As UInteger) As IntPtr
<DllImport("kernel32.dll")> _
Private Shared Function WriteProcessMemory(hProcess As IntPtr, lpBaseAddress As IntPtr, lpBuffer As String, nSize As UIntPtr, lpNumberOfBytesWritten As IntPtr) As Boolean
End Function
<DllImport("kernel32.dll", CharSet := CharSet.Auto)> _
Public Shared Function GetModuleHandle(lpModuleName As String) As IntPtr
End Function
Friend Declare Auto Function WaitForSingleObject Lib "kernel32" (handle As IntPtr, milliseconds As Int32) As Int32
Public Shared Function GetProcessId(proc As [String]) As Int32
Dim ProcList As Process()
ProcList = Process.GetProcessesByName(proc)
Return ProcList(0).Id
End Function
Private Shared Function CalcBytes(sToConvert As String) As Byte()
Dim bRet As Byte() = System.Text.Encoding.ASCII.GetBytes(sToConvert)
Return bRet
End Function
Public Shared Sub InjectDLL(hProcess As IntPtr, strDLLName As [String])
Dim bytesout As IntPtr
Dim LenWrite As Int32 = strDLLName.Length + 1
Dim AllocMem As IntPtr = CType(VirtualAllocEx(hProcess, CType(Nothing, IntPtr), CUInt(LenWrite), &H1000, &H40), IntPtr)
WriteProcessMemory(hProcess, AllocMem, strDLLName, CType(LenWrite, UIntPtr), bytesout)
Dim Injector As UIntPtr = CType(GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA"), UIntPtr)
Dim hThread As IntPtr = CType(CreateRemoteThread(hProcess, CType(Nothing, IntPtr), 0, Injector, AllocMem, 0, _
bytesout), IntPtr)
Dim Result As Integer = WaitForSingleObject(hThread, 1000)
Thread.Sleep(1000)
VirtualFreeEx(hProcess, AllocMem, CType(0, UIntPtr), &H8000)
If hThread IsNot Nothing Then
CloseHandle(hThread)
End If
Return
End Sub
End Class
End Namespace
The whole code has been converted from C# to vb.net via an online tool.. and i get that error, if someone can kindly help me that would be great!!