Пример #1
0
bool USBDevice::Load(const CString &nDeviceDir, const vector<CString> &interfaces)
{
	m_sDeviceDir = nDeviceDir;
	m_sInterfaceDeviceDirs = interfaces;
	CString buf;

	if (GetDeviceProperty("idVendor", buf))
		sscanf(buf, "%x", &m_iIdVendor);
	else
		m_iIdVendor = -1;

	if (GetDeviceProperty("idProduct", buf))
		sscanf(buf, "%x", &m_iIdProduct);
	else
		m_iIdProduct = -1;

	if (GetDeviceProperty("bMaxPower", buf))
		sscanf(buf, "%imA", &m_iMaxPower);
	else
		m_iMaxPower = -1;

	if (m_iIdVendor == -1 || m_iIdProduct == -1 || m_iMaxPower == -1)
	{
		LOG->Warn( "Could not load USBDevice %s", nDeviceDir.c_str() );
		return false;
	}

	for (unsigned i = 0; i < m_sInterfaceDeviceDirs.size(); i++)
	{
		int iClass;
		if ( GetInterfaceProperty( "bInterfaceClass", i, buf ) )
		{
			sscanf( buf, "%x", &iClass );
		}
		else
		{
			//LOG->Warn("Could not read interface %i for %s:%s", i, m_sDeviceDir.c_str(), m_sInterfaceDeviceDirs[i].c_str() );
			iClass = -1;
		}
		m_iInterfaceClasses.push_back(iClass);
	}
	return true;
}
Пример #2
0
void ProcessMe(HDATA Data, const char* pcName)
{
    PluginMetadata aPragueMetadata;
	int i;
	char szName[MAX_PATH];
    
	RegisterExportFunctions(Data, 0, 0, &aPragueMetadata.theExportsCount);
	
	if ( aPragueMetadata.theExportsCount )
	{
		if ( !aPragueMetadata.allocateExports () )
		  return;
		RegisterExportFunctions(Data, aPragueMetadata.theExports, sizeof(tDWORD) * aPragueMetadata.theExportsCount, 0);
	}

	enum_interfaces(Data, 0, &aPragueMetadata.theInterfacesCount);
	if ( aPragueMetadata.theInterfacesCount )
	{
		if ( !aPragueMetadata.allocateInterfaces () )
          return;
		enum_interfaces(Data, aPragueMetadata.theInterfaces, 0);
	}

	aPragueMetadata.theAutoStart = GetBoolPropVal(Data,0,VE_PID_PL_AUTOSTART);
    GetDwordPropVal(Data,0,VE_PID_PL_CODEPAGEID, &aPragueMetadata.theCodePage );
    GetInterfaceProperty(Data, 0,0,pgPLUGIN_ID,&aPragueMetadata.thePluginID,sizeof(aPragueMetadata.thePluginID));

	strcpy(szName, pcName);
	for (i = strlen(pcName); (i > 0) && (szName[i] != '\\') && (szName[i] != '/'); i--)
	{
		if (szName[i] == '.')
		{
			szName[i] = '\x00';
			break;
		}
	}

	strcat(szName, ".meta");

	save ( aPragueMetadata, szName );
}
Пример #3
0
void enum_interfaces( HDATA Data, InterfaceMetadata *pOut, tDWORD* p_iface_count ) 
{

	tDWORD size;
	tDWORD icount;
	tDWORD i;
	tERROR error;
    tCODEPAGE plugin_codepage;

    if ( p_iface_count )
		*p_iface_count = 0;

	prop_iface_count( Data, &size, (tCHAR*)&icount, sizeof(tDWORD) );

    if (p_iface_count != 0)
	  *p_iface_count = icount;

	if (pOut == 0)
		return;

    error = GetDwordPropVal(Data,0,VE_PID_PL_CODEPAGEID, &plugin_codepage );

    if ( PR_FAIL ( error ) ) {
      PR_TRACE(( this, prtNOTIFY, "(%terr): cannot get iface CODEPAGE id from metadata (plugin = \"%s\"(\"%s\"), iface number = %u, %tiid, %tpid", error, m_name, comment, i-1, iid, pid ) );
      plugin_codepage = cCP_ANSI;
    }

	for( i=0; i<icount; i++ ) 
	{
				
		tIID iid;
		
        error = GetInterfaceProperty(Data, 0, i, pgINTERFACE_ID, &iid, sizeof(iid) ); // index zero is for the plugin properties
		if ( PR_FAIL(error) ) 
		{ 
			PR_TRACE(( this, prtERROR, "Error reading iface description (plugin = \"%s\", iface item number - %u, %terr)", m_name, i-1, error ));
		}
		else if ( (iid == IID_ANY) || (iid == IID_NONE) ) 
		{
			continue;
		}
		else 
		{
			tPID     pid;
			tDWORD   sub;
			tVERSION ver;
			tVID     vid;
			tDWORD   flags;
			tIID     compat;
            tCODEPAGE codepage;

			if ( PR_SUCC(error=GetInterfaceProperty(Data, 0,i, pgPLUGIN_ID,&pid,sizeof(pid))) ) // plugin ID
			{

				if ( PR_FAIL(error=GetInterfaceProperty(Data, 0,i,pgINTERFACE_SUBTYPE,&sub,sizeof(sub))) ) {// subtype of interface in plugin
					sub = 0;
					PR_TRACE(( this, prtERROR, "(%terr): error in metadata: cannot get subtype (plugin = \"%s\"(\"%s\"), iface number = %u, %tiid, %tpid", error, m_name, comment, i-1, iid, pid ) );
				}

				if ( PR_FAIL(error=GetInterfaceProperty(Data, 0,i,pgINTERFACE_VERSION,&ver,sizeof(ver))) ) { // version
					ver = 1;
					PR_TRACE(( this, prtIMPORTANT, "(%terr): error in metadata: cannot get iface VERSION from metadata (plugin = \"%s\"(\"%s\"), iface number = %u, %tiid, %tpid", error, m_name, comment, i-1, iid, pid ) );
				}

				if ( PR_FAIL(error=GetInterfaceProperty(Data, 0,i,pgVENDOR_ID,&vid,sizeof(vid))) ) { // vendor id
					vid = VID_KASPERSKY_LAB;
					PR_TRACE(( this, prtNOTIFY, "(%terr): error in metadata: cannot get VENDOR ID from metadata (plugin = \"%s\"(\"%s\"), iface number = %u, %tiid, %tpid", error, m_name, comment, i-1, iid, pid ) );
				}

				if ( PR_FAIL(error=GetInterfaceProperty(Data, 0,i,pgINTERFACE_FLAGS,&flags,sizeof(flags))) ) { // interface flags
					flags = 0;
					PR_TRACE(( this, prtNOTIFY, "(%terr): error in metadata: cannot get iface FLAGS from metadata (plugin = \"%s\"(\"%s\"), iface number = %u, %tiid, %tpid", error, m_name, comment, i-1, iid, pid ) );
				}
				
				if ( PR_FAIL(error=GetInterfaceProperty(Data, 0,i,pgINTERFACE_COMPATIBILITY,&compat,sizeof(compat))) ) { // interface compatibility
					compat = PID_ANY;
					PR_TRACE(( this, prtNOTIFY, "(%terr): cannot get iface COMPATIBILITY id from metadata (plugin = \"%s\"(\"%s\"), iface number = %u, %tiid, %tpid", error, m_name, comment, i-1, iid, pid ) );
				}
                
                if ( PR_FAIL(error=GetInterfaceProperty(Data, 0,i,pgINTERFACE_CODEPAGE,&codepage,sizeof(codepage))) ) { // interface code page
					codepage = plugin_codepage;
					PR_TRACE(( this, prtNOTIFY, "(%terr): cannot get iface CODEPAGE id from metadata (plugin = \"%s\"(\"%s\"), iface number = %u, %tiid, %tpid", error, m_name, comment, i-1, iid, pid ) );
				}

                HDATA iface = GetIface ( Data, i );  
               	enum_static_properties(iface, 0, & pOut [i].theStaticPropertiesCount );
	            if ( pOut[i].theStaticPropertiesCount )
	            {
		          if ( !pOut[i].allocateStaticProperties () )
                    return;
		          enum_static_properties(iface, pOut[i].theStaticProperties, 0);
	            }
		        pOut[i].thePID = pid;
		        pOut[i].theSub = sub;
		        pOut[i].theVersion = ver;
		        pOut[i].theVID = vid;
		        pOut[i].theIID = iid;
		        pOut[i].theFlags = flags;
		        pOut[i].theCompat = compat;
                pOut[i].theCodePage = codepage;
      }
    }
  } 
  
  return;
}