Snippets
Created by
Алексей Корепанов
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace sbrte_run_test
{
class Hook : IDisposable
{
[DllImport("ole32.dll")]
static extern int CoRegisterChannelHook([MarshalAs(UnmanagedType.LPStruct)] Guid ExtensionUuid, IChannelHook ChannelHook);
static private Guid ChannelExtention = new Guid("{CDB80353-F3B3-4767-AA96-D9AC6211B782}");
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("1008C4A0-7613-11CF-9AF1-0020AF6E72F4")]
[ComImport]
interface IChannelHook
{
[MethodImpl(MethodImplOptions.PreserveSig)]
void ClientGetSize([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, out int DataSize);
[MethodImpl(MethodImplOptions.PreserveSig)]
void ClientFillBuffer([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, ref int DataSize, IntPtr DataBuffer);
[MethodImpl(MethodImplOptions.PreserveSig)]
void ClientNotify([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, int DataSize, IntPtr DataBuffer, int lDataRep, int hrFault);
[MethodImpl(MethodImplOptions.PreserveSig)]
void ServerNotify([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, int DataSize, IntPtr DataBuffer, int lDataRep);
[MethodImpl(MethodImplOptions.PreserveSig)]
void ServerGetSize([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, int hrFault, out int DataSize);
[MethodImpl(MethodImplOptions.PreserveSig)]
void ServerFillBuffer([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, ref int DataSize, IntPtr DataBuffer, int hrFault);
}
class ChannelHook : IChannelHook
{
private readonly Stack<string> stack = new Stack<string>();
public void ClientFillBuffer([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, ref int DataSize, IntPtr DataBuffer)
{
lock (stack)
{
var test = stack.Pop();
var buffer = Encoding.UTF8.GetBytes(test);
DataSize = test.Length;
Marshal.Copy(buffer, 0, DataBuffer, DataSize);
}
}
public void ClientGetSize([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, out int DataSize)
{
var test = Environment.StackTrace;
DataSize = test.Length;
lock (stack)
{
stack.Push(test);
}
}
public void ClientNotify([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, int DataSize, IntPtr DataBuffer, int lDataRep, int hrFault)
{
}
public void ServerFillBuffer([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, ref int DataSize, IntPtr DataBuffer, int hrFault)
{
}
public void ServerGetSize([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, int hrFault, out int DataSize)
{
DataSize = 0;
}
public void ServerNotify([MarshalAs(UnmanagedType.LPStruct)] Guid uExtent, [MarshalAs(UnmanagedType.LPStruct)] Guid iid, int DataSize, IntPtr DataBuffer, int lDataRep)
{
}
}
#region IDisposable Support
private bool disposedValue = false;
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
}
CoRegisterChannelHook(ChannelExtention, null);
disposedValue = true;
}
}
public Hook()
{
CoRegisterChannelHook(ChannelExtention, new ChannelHook());
}
~Hook()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.