Originally posted by VectraMan
View Post


typedef enum FWP_DIRECTION_ {
FWP_DIRECTION_OUTBOUND,
FWP_DIRECTION_INBOUND,
FWP_DIRECTION_MAX
} FWP_DIRECTION;
LIST_ENTRY listEntry;
int srcport;
int destport;
char sourceIp[16];
char destIp[16];
int protocol;
long packetRef;
FWP_DIRECTION direction; //FWP_DIRECTION Defined in Inspect.h
int type;
UINT64 processId;
int allow;
} FIREWALL_MESSAGE;
extern "C" _declspec(dllexport) void Cpkdll::listenForALEConnections(void (_stdcall *func)(int destPort, int srcPort))
{
m_bListenForALEConnections=true;
FIREWALL_MESSAGE fwm;
while (m_bListenForALEConnections==true)
{
strcpy(fwm.destIp,"212.58.254.251");
fwm.destport = 80;
strcpy(fwm.sourceIp,"192.168.1.5");
fwm.packetRef = 111;
fwm.processId = 0;
fwm.protocol = 53;
fwm.srcport = 2453;
fwm.type = 1;
func(fwm.destport,fwm.srcport);
Sleep(2000);
}
return;
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct LIST_ENTRY
{
/// _LIST_ENTRY*
public System.IntPtr Flink;
/// _LIST_ENTRY*
public System.IntPtr Blink;
}
public struct FIREWALL_MESSAGE
{
public LIST_ENTRY listEntry;
public Int32 srcport;
public Int32 destport;
public char[] sourceIp;
public char[] destIp;
public Int32 protocol;
public Int32 packetRef;
public EFWPDIRECTION direction; //FWP_DIRECTION Defined in Inspect.h
public Int32 type;
}
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void CallBackMethodDelegate(int destPort, int srcPort);
[DllImport("C:\\Projects\\portknox\\User Mode Dll\\pk.dll\\Debug\\pk.dll.dll", EntryPoint = "?listenForALEConnections@Cpkdll@@QAEXP6GXHH@Z@Z", CallingConvention = CallingConvention.StdCall)]
public static extern void listenForALEConnections(CallBackMethodDelegate del);
static void aleCallBack(int destPort, int srcPort)
{
Console.WriteLine(destPort.ToString() + "," + srcPort.ToString());
return;
}
static void Main(string[] args)
{
CallBackMethodDelegate del = new CallBackMethodDelegate(aleCallBack);
listenForALEConnections(del);
Console.WriteLine("Listening for ALE Connections");
}

Leave a comment: