I have built the "NDIS 6.0 Filter Driver" WinDDK sample (ndislwf.sys), and built the BindView sample to install "NDIS 6.0 Filter Driver".
It installs OK, but it always bound to all Network Interfaces by default.
Is it possible to install NDIS Filter Driver and have it unbound from all Network Interfaces so then I could bind it only to certain interfaces ?
The code from BindView uses SetupCopyOEMInfW to copy the driver to the OemInfs :
if ( !SetupCopyOEMInfW(lpszInfFullPath,
DirWithDrive, // Other files are in the
// same dir. as primary INF
SPOST_PATH, // First param is path to INF
0, // Default copy style
NULL, // Name of the INF after
// it's copied to %windir%\inf
0, // Max buf. size for the above
NULL, // Required size if non-null
NULL) ) { // Optionally get the filename
// part of Inf name after it is copied.
dwError = GetLastError();
And then, uses INetCfgClassSetup::Install():
INetCfgClassSetup *pncClassSetup = NULL;
INetCfgComponent *pncc = NULL;
OBO_TOKEN OboToken;
HRESULT hr = S_OK;
//
// OBO_TOKEN specifies on whose behalf this
// component is being installed.
// Set it to OBO_USER so that szComponentId will be installed
// on behalf of the user.
//
ZeroMemory( &OboToken,
sizeof(OboToken) );
OboToken.Type = OBO_USER;
//
// Get component's setup class reference.
//
hr = pnc->QueryNetCfgClass ( pguidClass,
IID_INetCfgClassSetup,
(void**)&pncClassSetup );
if ( hr == S_OK ) {
hr = pncClassSetup->Install( szComponentId,
&OboToken,
0,
0, // Upgrade from build number.
NULL, // Answerfile name
NULL, // Answerfile section name
&pncc ); // Reference after the component
if ( S_OK == hr ) { // is installed.
//
// we don't need to use pncc (INetCfgComponent), release it
//
ReleaseRef( pncc );
}
ReleaseRef( pncClassSetup );
}
Recent versions of Windows 10 have a feature for this. Put this line into your INF:
HKR, Ndi\Interfaces, DisableDefaultBindings, 0x00010001, 1
Add that line in the same section that has the FilterMediaTypes directive.
That directive will create all new bindings to your filter in the disabled state. You can manually re-enable them in the same ways as before:
from the command-line (Set-NetAdapterBinding);
the GUI (run ncpa.cpl, open the adapter properties, check the box next to the filter driver); or
from INetCfg code (INetCfgBindingPath::Enable).
Related
I am implementing a sniffer with the help of winpcap. Now I am getting packets and updating UI with background worker. Now I am trying to apply a filter on the packets, so I decided to use pcap_compile() and pcap_setfilter() API's . But pcap_Compile() needs a netmask so I was using the following code
for(pIf=pIfList,i=0; i<num-1; pIf=pIf->next,i++);
// Open the device.
if((pPcap= pcap_open(
pIf->name, // name of the device
65536, // portion of the packet to capture
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
1000, // read timeout
NULL, // authentication on the remote machine
err // error buffer
)) == NULL)
{
printf("\nUnable to open the adapter. %s is not supported by WinPcap\n",pIf->name);
//goto Exit; //one function is nedded*/
}
gPcap = pPcap;
if (pIf->addresses != NULL)
/* Retrieve the mask of the first address of the interface */
net=((struct sockaddr_in *)(pIf->addresses->netmask))->sin_addr.S_un.S_addr;
else
/* If the interface is without an address we suppose to be in a C class network */
net=0xffffffff;
//compile the filter
if (pcap_compile(gPcap, &fcode, "type ctl subtype rts", 0, net) < 0)
{
fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
/* Free the device list */
pcap_freealldevs(alldevs);
return -1;
}
//set the filter
if (pcap_setfilter(gPcap, &fcode) < 0)
{
fprintf(stderr,"\nError setting the filter.\n");
/* Free the device list */
pcap_freealldevs(alldevs);
return -1;
}
I am getting netmask value as zero. and I used different filter expressions like "type mgt", "type ctl",type data", " ip" etc.. but the filter action is not working, it is giving all the packets. I am not understanding why the filter is not working. could you suggest me?
I am using a following API to get the packets:
restart:
status = pcap_next_ex( pPcap, &header, &pkt_data);
{
if(status == 0)// Timeout elapsed
goto restart;
}
The above code I am running in a infinite loop.
could you suggest me why my filter is not working?
Thanks,
sathish
For some reason I seem to be unable to initialize my RenderTargetView (it stays NULL) which causes an access violation.
Here is the line that should initialize the RenderTargetView:
hr = g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_pRenderTargetView);
pBackBuffer is the Back buffer and it gets a value, it isn't NULL. However, the rendertagetview stays NULL throughout the process. Any idea why?
In order to trace the DirectX11 errors, you'd better to create the D3D11 device with the debug layer, it will print the error message to output window in Visual Studio when you launch your app.
// Create device and swap chain
HRESULT hr;
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined( DEBUG ) || defined( _DEBUG )
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// Create device and swap chain
D3D_FEATURE_LEVEL FeatureLevelsRequested = D3D_FEATURE_LEVEL_11_0; // Use d3d11
UINT numLevelsRequested = 1; // Number of levels
D3D_FEATURE_LEVEL FeatureLevelsSupported;
if (FAILED (hr = D3D11CreateDeviceAndSwapChain( NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
0,
&FeatureLevelsRequested,
numLevelsRequested,
D3D11_SDK_VERSION,
&sd_,
&swap_chain_,
&d3ddevice_,
&FeatureLevelsSupported,
&immediate_context_)))
{
MessageBox(hWnd, L"Create device and swap chain failed!", L"Error", 0);
}
I think you are failing to create the render target view because the second parameter is NULL:
HRESULT CreateRenderTargetView
(
[in] ID3D11Resource *pResource,
[in] const D3D11_RENDER_TARGET_VIEW_DESC *pDesc, <== You need to pass in a valid description
[out] ID3D11RenderTargetView **ppRTView
);
You can initialize it to something like this:
D3D11_RENDER_TARGET_VIEW_DESC desc = {0};
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
am trying to create a link in windows 7 that has an icon. I am using the JNA library for this. I am having trouble with the call to CoCreateInstance. It returns error. First I am not sure if the GUID for IShellLink is the correct ( I am not a windows programer). Below is my code so far. Once I get the pointer to an IShellLink I would need to fill the paramaters for the link (target,icon, description, etc). I am modeling this call from the C code below found at this link (http://www.codeproject.com/Articles/11467/How-to-create-short-cuts-link-files). I know I could use mklink command for this but it does have an option to add an icon and description.
private void createLink(){
Pointer reserved = null; //Must be null
int dwCoInit = 0;
HRESULT oleInitResult = Ole32.INSTANCE.CoInitializeEx(reserved,dwCoInit);
if(oleInitResult.equals(W32Errors.S_OK)){
GUID rclsid = Ole32Util.getGUIDFromString("{e82a2d71-5b2f-43a0-97b8-81be15854de8}"); //Shell object
GUID riid = Ole32Util.getGUIDFromString("{000214EE-0000-0000-C000-000000000046}"); //CLSID of the IShellLink object
PointerByReference ppv = new PointerByReference();
HRESULT oleCreateResult = Ole32.INSTANCE.CoCreateInstance(rclsid,null,ObjBase.CLSCTX_INPROC,riid,ppv);
if(oleCreateResult.equals(W32Errors.S_OK)){
}else{
System.out.println("Failed to create link error "+oleCreateResult.intValue());
}
}
Ole32.INSTANCE.CoUninitialize();
}
###################### C++ Sample code
/*
--------------------------------------------------------------------------------
Description: Creates the actual 'lnk' file (assumes COM has been initialized).
Parameters: pszTargetfile - File name of the link's target, must be a non-empty string.
pszTargetargs - Command line arguments passed to link's target, may be an empty string.
pszLinkfile - File name of the actual link file, must be a non-empty string.
pszDescription - Description of the linked item. If this is an empty string the description is not set.
iShowmode - ShowWindow() constant for the link's target. Use one of:
1 (SW_SHOWNORMAL) = Normal window.
3 (SW_SHOWMAXIMIZED) = Maximized.
7 (SW_SHOWMINNOACTIVE) = Minimized.
If this is zero the showmode is not set.
pszCurdir - Working directory of the active link. If this is an empty string the directory is not set.
pszIconfile - File name of the icon file used for the link. If this is an empty string the icon is not set.
iIconindex - Index of the icon in the icon file. If this is < 0 the icon is not set.
Returns: HRESULT value >= 0 for success, < 0 for failure.
--------------------------------------------------------------------------------
*/
static HRESULT CreateShortCut(LPSTR pszTargetfile, LPSTR pszTargetargs, LPSTR pszLinkfile, LPSTR pszDescription,
int iShowmode, LPSTR pszCurdir, LPSTR pszIconfile, int iIconindex) {
HRESULT hRes; /* Returned COM result code */
IShellLink* pShellLink; /* IShellLink object pointer */
IPersistFile* pPersistFile; /* IPersistFile object pointer */
WORD wszLinkfile[MAX_PATH]; /* pszLinkfile as Unicode string */
int iWideCharsWritten; /* Number of wide characters written */
hRes = E_INVALIDARG;
if (
(pszTargetfile != NULL) && (strlen(pszTargetfile) > 0) &&
(pszTargetargs != NULL) &&
(pszLinkfile != NULL) && (strlen(pszLinkfile) > 0) &&
(pszDescription != NULL) &&
(iShowmode >= 0) &&
(pszCurdir != NULL) &&
(pszIconfile != NULL) &&
(iIconindex >= 0)
) {
hRes = CoCreateInstance(&CLSID_ShellLink, /* pre-defined CLSID of the IShellLink object */
NULL, /* pointer to parent interface if part of aggregate */
CLSCTX_INPROC_SERVER, /* caller and called code are in same process */
&IID_IShellLink, /* pre-defined interface of the IShellLink object */
&pShellLink); /* Returns a pointer to the IShellLink object */
if (SUCCEEDED(hRes))
{
/* Set the fields in the IShellLink object */
hRes = pShellLink->lpVtbl->SetPath(pShellLink, pszTargetfile);
hRes = pShellLink->lpVtbl->SetArguments(pShellLink, pszTargetargs);
if (strlen(pszDescription) > 0)
{
hRes = pShellLink->lpVtbl->SetDescription(pShellLink, pszDescription);
}
if (iShowmode > 0)
{
hRes = pShellLink->lpVtbl->SetShowCmd(pShellLink, iShowmode);
}
if (strlen(pszCurdir) > 0)
{
hRes = pShellLink->lpVtbl->SetWorkingDirectory(pShellLink, pszCurdir);
}
if (strlen(pszIconfile) > 0 && iIconindex >= 0)
{
hRes = pShellLink->lpVtbl->SetIconLocation(pShellLink, pszIconfile, iIconindex);
}
/* Use the IPersistFile object to save the shell link */
hRes = pShellLink->lpVtbl->QueryInterface(pShellLink, /* existing IShellLink object */
&IID_IPersistFile, /* pre-defined interface of the IPersistFile object */
&pPersistFile); /* returns a pointer to the IPersistFile object */
if (SUCCEEDED(hRes))
{
iWideCharsWritten = MultiByteToWideChar(CP_ACP, 0, pszLinkfile, -1, wszLinkfile, MAX_PATH);
hRes = pPersistFile->lpVtbl->Save(pPersistFile, wszLinkfile, TRUE);
pPersistFile->lpVtbl->Release(pPersistFile);
}
pShellLink->lpVtbl->Release(pShellLink);
}
}
return (hRes);
}
It turn out to be very simple. So If you hit this page you probably will save couple days by following this instructions:
Generate the mappings for the shell32.dll per instructions in the com4j site:
http://com4j.java.net/tutorial.html
Then just call the following to create the icons. It is very simple once you know.
IWshShell3 shellLink = ClassFactory.createWshShell();
Com4jObject obj = shellLink.createShortcut(linkPath.getAbsolutePath());
IWshShortcut link = obj.queryInterface(IWshShortcut.class);
link.workingDirectory(desktopPath.getAbsolutePath());
link.description("My Link");
link.arguments(" Hello ");
link.iconLocation(iconPath.getAbsolutePath());
link.targetPath(javawsPath.getAbsolutePath());
link.setName("Test Link");
link.save();
I have fixed the called to CoCreateInstance by changing the GUID. Below is the code and it returns OK. But now that I got the pointer I am not sure how to set the parameters I need (link name, target name, desc, icon). Anybody has any suggestions?
GUID rclsid = Ole32Util.getGUIDFromString("{00021401-0000-0000-C000-000000000046}"); //CLSID_ShellLink
if (W32Errors.FAILED(hr.intValue())) {
Ole32.INSTANCE.CoUninitialize();
throw new Exception("Shell Object GUID failed.");
}
GUID riid = Ole32Util.getGUIDFromString("{000214EE-0000-0000-C000-000000000046}"); //CLSID of the IShellLink object
PointerByReference ppv = new PointerByReference();
hr = Ole32.INSTANCE.CoCreateInstance(rclsid,null,WTypes.CLSCTX_LOCAL_SERVER,riid,ppv);
if(hr.equals(W32Errors.S_OK)){
Pointer type = ppv.getValue();
}else{
System.out.println("Failed to create link error "+hr.intValue());
}
Need to show browser through my application.
My application should go in background and browser should come in foreground.
int moduleHandle =
CodeModuleManager.getModuleHandle("net_rim_bb_browser_daemon");
if (moduleHandle > 0)
{
// Use the default browser application descriptor as the
// model descriptor.
ApplicationDescriptor[] browserDescriptors =
CodeModuleManager.getApplicationDescriptors(moduleHandle);
// Create the new application descriptor.
String[] args = {"url", url, null};
// Turn off auto restart (the original descriptor has it
// turned on) so we don't end up in a never ending loop of
// restarting the browser.
int flags = browserDescriptors[0].getFlags() ^
ApplicationDescriptor.FLAG_AUTO_RESTART;
ApplicationDescriptor newDescriptor =
new ApplicationDescriptor
(
browserDescriptors[0],
"BrowserPS",
args,
null,
-1,
null,
-1,
flags
);
// Run the application.
try
{
ApplicationManager.getApplicationManager().
runApplication(newDescriptor);
}
catch (ApplicationManagerException ame)
{
System.err.println(ame.toString());
}
}
This is my code it's working fine in simulator, but not on actual device.
any help.
Try like
BrowserSession browserSession = Browser.getDefaultSession();
browserSession.displayPage(URL);
Microsoft DxDiag can detect whether a system has "Direct3D Acceleration".
If the system has not the capability, DxDiag will write "Direct3D Acceleration not available" and will write in the console "Direct3D functionality not available. You should verify that the driver is a final version from the hardware manufacturer."
I would like the same with a C++ function.
I made some tests and the following function seems to do the job.
Any other better idea?
Thank you.
Alessandro
#include <ddraw.h>
#include <atlbase.h>
bool has3D()
{
CComPtr< IDirectDraw > dd;
HRESULT hr = ::DirectDrawCreate( 0, &dd, 0 );
if ( hr != DD_OK ) return false;
DDCAPS hel_caps, hw_caps;
::ZeroMemory( &hel_caps, sizeof( DDCAPS ) );
::ZeroMemory( &hw_caps, sizeof( DDCAPS ) );
hw_caps.dwSize = sizeof( DDCAPS );
hel_caps.dwSize = sizeof( DDCAPS );
hr = dd->GetCaps( &hw_caps, &hel_caps );
if ( hr != DD_OK ) return false;
return (hw_caps.dwCaps & DDCAPS_3D) && (hel_caps.dwCaps & DDCAPS_3D);
}
As DirectDraw is now deprecated, it's maybe preferable to use the Direct3D functions.
If the purpose is to detect if 3D acceleration is available for an application, I would initialize Direct3D and then check if the HAL Device Type is available.
LPDIRECT3D9 d3d = Direct3DCreate9( D3D_SDK_VERSION );
D3DCAPS9 caps;
if ( FAILED(d3d->GetDeviceCaps(D3DADAPTER_DEFAULT , D3DDEVTYPE_HAL, &caps)) )
{
return false;
}
You can check the validity of this code by forcing the software rendering in the DirectX Control Panel by checking the "Software only" checkbox in the Direct3D tab.
Test the code with and without the checkbox checked and see if it suits your needs.
You can access DX Diag via IDXDiagContainer and IDXDiagProvider