Skip to content

Instantly share code, notes, and snippets.

@cessationoftime
Created November 21, 2012 02:24
Show Gist options
  • Save cessationoftime/4122669 to your computer and use it in GitHub Desktop.
Save cessationoftime/4122669 to your computer and use it in GitHub Desktop.
Attempt to use Bridj to retrieve information about the firewall
package firewall
import org.bridj.Pointer
import org.bridj.BridJ
import org.bridj.Pointer
import org.bridj.cpp.com.COMRuntime
object FirewallMain extends App {
val x: INetFwMgr = COMRuntime.newInstance(classOf[INetFwMgr]);
val point = Pointer.allocatePointer(classOf[INetFwPolicy]);
val hresult = x.get_LocalPolicy(point);
}
package firewall;
import org.bridj.BridJ;
import org.bridj.IntValuedEnum;
import org.bridj.Pointer;
import org.bridj.ann.Convention;
import org.bridj.ann.Convention.Style;
import org.bridj.ann.Field;
import org.bridj.ann.Library;
import org.bridj.ann.Ptr;
import org.bridj.ann.Virtual;
import org.bridj.cpp.com.CLSID;
import org.bridj.cpp.com.COMRuntime;
import org.bridj.cpp.com.IDispatch;
import org.bridj.cpp.com.IID;
import firewall.FirewallAPILibrary.NET_FW_IP_PROTOCOL;
import firewall.FirewallAPILibrary.NET_FW_IP_VERSION;
import firewall.FirewallAPILibrary.NET_FW_PROFILE_TYPE;
/**
* <i>native declaration : fire_netfw.h:29611</i><br>
* This file was autogenerated by <a href="http://jnaerator.googlecode.com/">JNAerator</a>,<br>
* a tool written by <a href="http://ochafik.com/">Olivier Chafik</a> that <a href="http://code.google.com/p/jnaerator/wiki/CreditsAndLicense">uses a few opensource projects.</a>.<br>
* For help, please visit <a href="http://nativelibs4java.googlecode.com/">NativeLibs4Java</a> or <a href="http://bridj.googlecode.com/">BridJ</a> .
*/
@IID("F7898AF5-CAC4-4632-A2EC-DA06E5111AF2")
@CLSID("304CE942-6E39-40D8-943A-B913C40C9CD4")
@Library("FirewallAPI")
public class INetFwMgr extends IDispatch {
static {
BridJ.register();
}
public INetFwMgr() {
super();
}
/**
* [propget][id]<br>
* Original signature : <code>HRESULT get_LocalPolicy(INetFwPolicy**)</code><br>
* <i>native declaration : fire_netfw.h:29590</i>
*/
@Ptr
//@Virtual(0)
@Field(7)
public native long get_LocalPolicy(Pointer<Pointer<INetFwPolicy > > localPolicy);
/**
* [propget][id]<br>
* Original signature : <code>HRESULT get_CurrentProfileType(NET_FW_PROFILE_TYPE*)</code><br>
* <i>native declaration : fire_netfw.h:29595</i>
*/
@Ptr
//@Virtual(1)
@Field(8)
public native long get_CurrentProfileType(Pointer<IntValuedEnum<NET_FW_PROFILE_TYPE > > profileType);
/**
* [id]<br>
* Original signature : <code>HRESULT RestoreDefaults()</code><br>
* <i>native declaration : fire_netfw.h:29600</i>
*/
@Ptr
//@Virtual(2)
@Field(9)
public native long RestoreDefaults();
/**
* [id]<br>
* Original signature : <code>HRESULT IsPortAllowed(BSTR, NET_FW_IP_VERSION, long, BSTR, NET_FW_IP_PROTOCOL, VARIANT*, VARIANT*)</code><br>
* <i>native declaration : fire_netfw.h:29605</i>
*/
@Ptr
//@Virtual(3)
@Field(10)
public native long IsPortAllowed(Pointer<Short > imageFileName, IntValuedEnum<NET_FW_IP_VERSION > ipVersion, @Ptr long portNumber, Pointer<Short > localAddress, IntValuedEnum<NET_FW_IP_PROTOCOL > ipProtocol, Pointer<? > allowed, Pointer<? > restricted);
//public native long IsPortAllowed(Pointer<Short > imageFileName, IntValuedEnum<NET_FW_IP_VERSION > ipVersion, @Ptr long portNumber, Pointer<Short > localAddress, IntValuedEnum<NET_FW_IP_PROTOCOL > ipProtocol, Pointer<tagVARIANT > allowed, Pointer<tagVARIANT > restricted);
/**
* [id]<br>
* Original signature : <code>HRESULT IsIcmpTypeAllowed(NET_FW_IP_VERSION, BSTR, BYTE, VARIANT*, VARIANT*)</code><br>
* <i>native declaration : fire_netfw.h:29610</i>
*/
@Ptr
//@Virtual(4)
@Field(11)
public native long IsIcmpTypeAllowed(IntValuedEnum<NET_FW_IP_VERSION > ipVersion, Pointer<Short > localAddress, byte type, Pointer<? > allowed, Pointer<? > restricted);
//public native long IsIcmpTypeAllowed(IntValuedEnum<NET_FW_IP_VERSION > ipVersion, Pointer<Short > localAddress, byte type, Pointer<tagVARIANT > allowed, Pointer<tagVARIANT > restricted);
// public INetFwMgr(Pointer pointer) {
// super(pointer);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment