Exemple #1
0
 public static void VirtualFreeEx(Handle processHandle, Address targetAddress, int size, APIProxy.FreeType freeType)
 {
     if (WINAPI.VirtualFreeEx(processHandle.GetHandleAsPointer(), targetAddress.GetAsPointer(), size, freeType) == false)
     {
         throw new VirtualFreeException("Freeing  Bytes at " + targetAddress + " failed with errorcode " + Marshal.GetLastWin32Error());
     }
 }
Exemple #2
0
 public static void CloseHandle(Handle handle)
 {
     if (WINAPI.CloseHandle(handle.GetHandleAsPointer()) == false)
     {
         throw new CloseHandleException("Closing the handle " + handle + " has failed with errorcode+" + Marshal.GetLastWin32Error());
     }
 }
Exemple #3
0
        public static void WriteProcessMemory(Handle processHandle, Address targetAddress, byte[] input)
        {
            long bytesWritten = 0;

            if (WINAPI.WriteProcessMemory(processHandle.GetHandleAsPointer(), targetAddress.GetAsPointer(), input, input.Length, ref bytesWritten) == false)
            {
                throw new WriteProcessMemoryException("Writing " + input.Length + " Bytes to " + targetAddress + " has failed with errorcode " + Marshal.GetLastWin32Error());
            }
        }
Exemple #4
0
        public static Handle OpenProcess(ProcessAccessFlags accessFlags, int processId)
        {
            IntPtr res = WINAPI.OpenProcess(accessFlags, false, processId);

            if (res == null)
            {
                throw new OpenProcessException("Getting a handle with " + accessFlags + " access to the process with the id " + processId + " has failed with errorcode " + Marshal.GetLastWin32Error());
            }
            return(new Handle(res));
        }
Exemple #5
0
        public static Address GetProcedureAddress(Handle moduleHandle, string procedureName)
        {
            IntPtr res = WINAPI.GetProcAddress(moduleHandle.GetHandleAsPointer(), procedureName);

            if (res == null)
            {
                throw new GetProcedureAddressException("Getting the procedure address for the procedure named " + procedureName + " in the module with the handle " + moduleHandle + " has failed with errorcode " + Marshal.GetLastWin32Error());
            }
            return(new Address(res));
        }
Exemple #6
0
        public static Handle CreateRemoteThread(Handle processHandle, Address threadAttributesPointer, uint stackSize, Address startAddress, Address parameterPointer, uint creationFlags, int threadId)
        {
            IntPtr res = WINAPI.CreateRemoteThread(processHandle.GetHandleAsPointer(), threadAttributesPointer.GetAsPointer(), stackSize, startAddress.GetAsPointer(), parameterPointer.GetAsPointer(), creationFlags, (IntPtr)threadId);

            if (res == null)
            {
                throw new CreateRemoteThreadException("Creating a remote thread in the process " + processHandle + " with the threadattributePointer " + threadAttributesPointer + " stacksize " + stackSize + " startaddress " + startAddress + " parameterPointer " + parameterPointer + " creationFlags " + creationFlags + " and threadId " + threadId + " has failed with errorcode " + Marshal.GetLastWin32Error());
            }
            return(new Handle(res));
        }
Exemple #7
0
        public static Handle GetModuleHandle(string moduleName)
        {
            IntPtr res = WINAPI.GetModuleHandle(moduleName);

            if (res == null)
            {
                throw new GetModuleHandleException("Obtaining a handle for the module " + moduleName + " has failed with errorcode" + Marshal.GetLastWin32Error());
            }
            return(new Handle(res));
        }
Exemple #8
0
        public static Handle OpenThread(ThreadAccessFlags desiredAccess, uint threadID)
        {
            IntPtr res = WINAPI.OpenThread(desiredAccess, false, threadID);

            if (res == null)
            {
                throw new OpenThreadException("Getting a handle with " + desiredAccess + " access for the thread with the id " + threadID + " has failed with errorcode" + Marshal.GetLastWin32Error());
            }
            return(new Handle(res));
        }
Exemple #9
0
        public static uint VirtualProtectEx(Handle processHandle, Address regionStart, int regionSize, uint newProtection)
        {
            uint oldProtection = 0;

            if (WINAPI.VirtualProtectEx(processHandle.GetHandleAsPointer(), regionStart.GetAsPointer(), regionSize, newProtection, out oldProtection) == false)
            {
                throw new VirtualProtectionException("Protecting " + regionStart + " to " + regionStart + " + " + regionSize + " with the protection " + newProtection + " has failed with errorcode" + Marshal.GetLastWin32Error());
            }
            return(oldProtection);
        }
Exemple #10
0
        public static byte[] ReadProcessMemory(Handle processHandle, Address targetAddress, int outputSize)
        {
            byte[] buffer    = new byte[outputSize];
            long   bytesRead = 0;

            if (WINAPI.ReadProcessMemory(processHandle.GetHandleAsPointer(), targetAddress.GetAsPointer(), buffer, outputSize, ref bytesRead) == false)
            {
                throw new ReadProcessMemoryException("Reading " + outputSize + " Bytes from " + targetAddress + " has failed with errorcode " + Marshal.GetLastWin32Error());
            }
            return(buffer);
        }
Exemple #11
0
        public static MemoryRegion VirtualAllocEx(Handle processHandle, Address startAddress, int size, AllocationType allocationType, MemoryProtection protection)
        {
            IntPtr res = WINAPI.VirtualAllocEx(processHandle.GetHandleAsPointer(), startAddress.GetAsPointer(), (IntPtr)size, allocationType, protection);

            if (res == null)
            {
                throw new VirtualAllocationException("Allocating " + size + " Bytes at " + startAddress + " with the allocationType " + allocationType + " and the protection " + protection + " has failed with errorcode " + Marshal.GetLastWin32Error());
            }
            MemoryRegion region = new MemoryRegion();

            region.start  = new Address(res);
            region.lenght = (int)size;
            return(region);
        }
Exemple #12
0
 public static void ResumeThread(Handle threadHandle)
 {
     WINAPI.ResumeThread(threadHandle.GetHandleAsPointer());
 }
Exemple #13
0
 public static void SuspendThread(Handle threadHandle)
 {
     WINAPI.SuspendThread(threadHandle.GetHandleAsPointer());
 }