Advanced hooking
Have you ever needed a simple way to control an application without having to resort to DLL injection? I decided to release a class library for .NET applications that allows you to easily manipulate a remote process by using debugging techniques.
All you have to do is add it as a reference to your project, and you're ready to use it. You can see the sample I provided if you're unsure of how it works (can easily be translated to C#, which someone already did (thanks))
The Debuggee class
Functions
AttachDebugger() - Tries to attach the debugger to the target process. Returns true if the function succeeds - returns false otherwise
DetachDebugger() - Tries to detach the debugger from the target process and remove all breakpoints. Returns true if the function succeeds - returns false otherwise
SetHardwareBreakpoint(Address) - Tries to set a hardware breakpoint at the specified address. Returns true if the function succeeds - returns false otherwise
RemoveHardwareBreakpoint(Address) - Tries to remove a hardware breakpoint at the specified address. Returns true if the function succeeds - returns false otherwise
SetMemoryBreakpoint(Address) - Tries to set a memory breakpoint at the specified address. Returns true if the function succeeds - returns false otherwise
RemoveMemoryBreakpoint(Address) - Tries to remove a memory breakpoint at the specified address. Returns true if the function succeeds - returns false otherwise
RemoveAllBreakpoints() - Tries to remove all memory and hardware breakpoints. Returns true if the function succeeds - returns false otherwise
GetModuleFunctionAddress(ModuleName, FunctionName) - Tries to retrieve the address of a function inside a module (DLL) in the target process. If the function succeeds, the return value is the address of the module/DLL function
AllocateMemory(Size) - Tries to allocate memory in the target process. The Size parameter is the amount of bytes to allocate. If the function succeeds, the return value is the address of the allocated memory
FreeMemory(Address) - Tries to free memory at the specified address. The address has to be an address provided by the AllocateMemory function, otherwise the function will fail. Returns true if the function succeeds - returns false otherwise
ReadByte/Int16/Int32/Int64(Address) - Reads from the target process' memory and returns that value
ReadString(Address, Length) - Reads a null-terminated text string from the target process' memory and returns that string
ReadByteArray(Address, Length) - Reads an array of bytes from the target process' memory and returns that array
WriteByte/Int16/Int32/Int64/String/ByteArray(Value, Address) - Writes the value to the target process' memory. Returns true if the function succeeds - returns false otherwise
Methods
RemoveDebugFlag() - Removes the debug flag from the PEB (prevents IsDebuggerPresent function from detecting the debugger)
ExecuteCode(ByteCode) - Executes the "assembly" code specified by the ByteCode parameter
Properties
hProcess - Contains a handle to the targeted process (Initialized on debugger attach)
CurrentHardwareBreakpoint - Contains the current hardware breakpoint (for use with the OnHardwareBreakpoint event)
CurrentMemoryBreakpoint - Contains the current hardware breakpoint (for use with the OnMemoryBreakpoint event)
Events
OnAttach(ref Debuggee, ref ctx) - Raised upon successful debugger attach (EXCEPTION_BREAKPOINT)
OnProcessExit(ref Debuggee, ref ctx) - Raised when the target process exits
OnAccessViolation(ref Debuggee, ref ctx) - Raised upon access violation inside the target process
OnHardwareBreakpoint(ref Deuggee, ref ctx) - Raised when a hardware breakpoint is hit inside the target process
OnMemoryBreakpoint(ref Deuggee, ref ctx) - Raised when a memory breakpoint is hit inside the target process
Have you ever needed a simple way to control an application without having to resort to DLL injection? I decided to release a class library for .NET applications that allows you to easily manipulate a remote process by using debugging techniques.
All you have to do is add it as a reference to your project, and you're ready to use it. You can see the sample I provided if you're unsure of how it works (can easily be translated to C#, which someone already did (thanks))
The Debuggee class
Functions
AttachDebugger() - Tries to attach the debugger to the target process. Returns true if the function succeeds - returns false otherwise
DetachDebugger() - Tries to detach the debugger from the target process and remove all breakpoints. Returns true if the function succeeds - returns false otherwise
SetHardwareBreakpoint(Address) - Tries to set a hardware breakpoint at the specified address. Returns true if the function succeeds - returns false otherwise
RemoveHardwareBreakpoint(Address) - Tries to remove a hardware breakpoint at the specified address. Returns true if the function succeeds - returns false otherwise
SetMemoryBreakpoint(Address) - Tries to set a memory breakpoint at the specified address. Returns true if the function succeeds - returns false otherwise
RemoveMemoryBreakpoint(Address) - Tries to remove a memory breakpoint at the specified address. Returns true if the function succeeds - returns false otherwise
RemoveAllBreakpoints() - Tries to remove all memory and hardware breakpoints. Returns true if the function succeeds - returns false otherwise
GetModuleFunctionAddress(ModuleName, FunctionName) - Tries to retrieve the address of a function inside a module (DLL) in the target process. If the function succeeds, the return value is the address of the module/DLL function
AllocateMemory(Size) - Tries to allocate memory in the target process. The Size parameter is the amount of bytes to allocate. If the function succeeds, the return value is the address of the allocated memory
FreeMemory(Address) - Tries to free memory at the specified address. The address has to be an address provided by the AllocateMemory function, otherwise the function will fail. Returns true if the function succeeds - returns false otherwise
ReadByte/Int16/Int32/Int64(Address) - Reads from the target process' memory and returns that value
ReadString(Address, Length) - Reads a null-terminated text string from the target process' memory and returns that string
ReadByteArray(Address, Length) - Reads an array of bytes from the target process' memory and returns that array
WriteByte/Int16/Int32/Int64/String/ByteArray(Value, Address) - Writes the value to the target process' memory. Returns true if the function succeeds - returns false otherwise
Methods
RemoveDebugFlag() - Removes the debug flag from the PEB (prevents IsDebuggerPresent function from detecting the debugger)
ExecuteCode(ByteCode) - Executes the "assembly" code specified by the ByteCode parameter
Properties
hProcess - Contains a handle to the targeted process (Initialized on debugger attach)
CurrentHardwareBreakpoint - Contains the current hardware breakpoint (for use with the OnHardwareBreakpoint event)
CurrentMemoryBreakpoint - Contains the current hardware breakpoint (for use with the OnMemoryBreakpoint event)
Events
OnAttach(ref Debuggee, ref ctx) - Raised upon successful debugger attach (EXCEPTION_BREAKPOINT)
OnProcessExit(ref Debuggee, ref ctx) - Raised when the target process exits
OnAccessViolation(ref Debuggee, ref ctx) - Raised upon access violation inside the target process
OnHardwareBreakpoint(ref Deuggee, ref ctx) - Raised when a hardware breakpoint is hit inside the target process
OnMemoryBreakpoint(ref Deuggee, ref ctx) - Raised when a memory breakpoint is hit inside the target process