/************************************************************************
 *
 * L i s t M o d u l e s
 *
 * Lists all the modules in the database, along with their slots and tokens.
 */
Error
ListModules()
{
    SECMODListLock *lock;
    SECMODModuleList *list;
    SECMODModuleList *deadlist;
    SECMODModuleList *mlp;
    Error ret=UNSPECIFIED_ERR;
    int count = 0;

    lock = SECMOD_GetDefaultModuleListLock();
    if(!lock) {
	PR_fprintf(PR_STDERR, errStrings[NO_LIST_LOCK_ERR]);
	return NO_LIST_LOCK_ERR;
    }

    SECMOD_GetReadLock(lock);

    list = SECMOD_GetDefaultModuleList();
    deadlist = SECMOD_GetDeadModuleList();
    if (!list && !deadlist) {
	PR_fprintf(PR_STDERR, errStrings[NO_MODULE_LIST_ERR]);
	ret = NO_MODULE_LIST_ERR;
	goto loser;
    }

    PR_fprintf(PR_STDOUT,
	"\nListing of PKCS #11 Modules\n"
	"-----------------------------------------------------------\n");
    
    for(mlp=list; mlp != NULL; mlp = mlp->next) {
	printModule(mlp->module, &count);
    }
    for (mlp=deadlist; mlp != NULL; mlp = mlp->next) {
	printModule(mlp->module, &count);
    }


    PR_fprintf(PR_STDOUT,
	"-----------------------------------------------------------\n");

    ret = SUCCESS;

loser:
    SECMOD_ReleaseReadLock(lock);
    return ret;
}
void thModuleEnumerator::ReceivePid( DWORD dwPid )
{
	HANDLE hSnapshot = CreateToolhelp32Snapshot(
		TH32CS_SNAPMODULE,
		dwPid);

	if (INVALID_HANDLE_VALUE == hSnapshot)
	{
		//m_bWork = FALSE;
		return;
	}

	MODULEENTRY32 entry;
	memset(&entry, 0, sizeof(entry));
	entry.dwSize = sizeof(entry);

	TiXmlElement* node = new TiXmlElement("process");
	node->SetAttribute("PID", dwPid);

	BOOL bRet = Module32First(
		hSnapshot,
		&entry);

	while (bRet)
	{
		printModule(&entry, node);

		memset(&entry, 0, sizeof(entry));
		entry.dwSize = sizeof(entry);
		bRet = Module32Next(
			hSnapshot,
			&entry);		
	}

	m_root->LinkEndChild(node);

	CloseHandle(hSnapshot);
}
Ejemplo n.º 3
0
int
main(int argc, char **argv)
{
    CONDITION				cond;								/* Return value from DUL and ACR routines */
    DCM_OBJECT				* object;							/* Handle to the information object */
    DCM_ELEMENT				element;							/* Handle to the DCM_ELEMENT */
    IE_OBJECT				* ieObject;							/* Handle to the IE_OBJECT object */
    IE_INFORMATIONENTITY	* ieIE, *ie_node;					/* Handle to IE_INFORMATIONENTITY */
    LST_HEAD				* ie_head, *mod_head, *attr_head;	/* Handle to the LST_HEAD */
    IE_MODULE				* ieModule, *mod_node;				/* Handle to IE_MODULE */
    IE_ATTRIBUTE			* attr_node;						/* Handle to IE_ATTRIBUTE */
    CTNBOOLEAN				verbose = FALSE;					/* For debugging purpose */
    CTNBOOLEAN				flag;								/* Return value from findElement routine */
    unsigned long			options = DCM_ORDERLITTLEENDIAN;	/* Byte order in data streams */
    char					*file;								/* The image file name */
    char					UID[90];							/* The SOP Class UID of the image file */
    U32						length;								/* Length of the data field of DCM_ELEMENT */
    int						ie_loop, mod_loop, attr_loop, j, k, i;/* Iteration variables */


    while (--argc > 0 && (*++argv)[0] == '-') {
    	switch (*(argv[0] + 1)) {
			case 'v':
						verbose = TRUE;
						break;
			case 'b':
						options &= ~DCM_ORDERMASK;
						options |= DCM_ORDERBIGENDIAN;
						break;
			case 't':
						options &= ~DCM_FILEFORMATMASK;
						options |= DCM_PART10FILE;
						break;
			default:
						break;
    	}
    }

    if (argc < 1) usageerror();

    file = *argv;
    THR_Init();
    DCM_Debug(verbose);

    /* Open a DICOM object file and put the contents into the memory represented by the information object. */
    cond = DCM_OpenFile(file, options, &object);


    if (cond != DCM_NORMAL && ((options & DCM_PART10FILE) == 0)) {
    	COND_DumpConditions();
    	(void) DCM_CloseObject(&object);
    	(void) COND_PopCondition(TRUE);
    	fprintf(stderr, "Could not open %s as expected.  Trying Part 10 format.\n", file);
    	cond = DCM_OpenFile(file, options | DCM_PART10FILE, &object);
    }

    if (cond != DCM_NORMAL) {
     	COND_DumpConditions();
     	THR_Shutdown();
     	return 1;
    }else{
    	printf("file is successfully opened!\n");
    	/* Call IE_ExamineObject to examine this DCM object. */
    	cond = IE_ExamineObject(&object, &ieObject);
    	if (cond == IE_ILLEGALDCMOBJECT || cond == IE_LISTFAILURE || cond == IE_MALLOCFAILURE){
    		COND_DumpConditions();
    	}else{
    		/* Print the IE_OBJECT object.  */
    		strcpy(UID, ieObject->classUID);
    		printObject(ieObject);

    		/* Examine each IE on the list.  */
    		ie_head = ieObject->ieList;
    		ie_loop = LST_Count(&ie_head);

    		for (i = 0; i < ie_loop; i++) {
    			ie_node = LST_Pop(&ie_head);
    			cond = IE_ExamineInformationEntity(&object, ie_node->ieType, &ieIE);

    			/* Print each IE_IE. */
    			printIE(ieIE);

    			/* Examine each module on the list. */
    			mod_head = ieIE->moduleList;
    			mod_loop = LST_Count(&mod_head);

    			for (k = 0; k < mod_loop; k++) {
    				mod_node = LST_Pop(&mod_head);
    				cond = IE_ExamineModule(&object, ieIE->ieType, mod_node->moduleType, &ieModule);
    				printModule(ieModule);

    				/* Print each IE_ATTRIBUTE.  */
    				attr_head = ieModule->attributeList;
    				attr_loop = LST_Count(&attr_head);

    				for (j = 0; j < attr_loop; j++) {
    					attr_node = LST_Pop(&attr_head);
    					printIEAttribute(attr_node);
    					free(attr_node);
    				}
    				free(mod_node);

    				cond = IE_Free((void **) &ieModule);
    			}
    			free(ie_node);

    			cond = IE_Free((void **) &ieIE);
    		}
    		cond = IE_Free((void **) &ieObject);

	    /* Check to see the status of the Information Entities. */
	    cond = IE_ExamineObject(&object, &ieObject);
	    printf("\n%s requirements:\n", ieObject->objectDescription);
	    ie_head = ieObject->ieList;
	    ie_loop = LST_Count(&ie_head);

	    for (i = 0; i < ie_loop; i++) {
	    	ie_node = LST_Pop(&ie_head);
	    	if (ie_node->requirement == IE_K_REQUIRED) printIE(ie_node);
	    	free(ie_node);
	    }

	    cond = IE_Free((void **) &ieObject);

	    /* Check to see the status of the Information Entity and status of the Modules within them. */
	    cond = IE_ExamineObject(&object, &ieObject);
	    printf("\n%s requirements:\n", ieObject->objectDescription);
	    ie_head = ieObject->ieList;
	    ie_loop = LST_Count(&ie_head);

	    for (i = 0; i < ie_loop; i++) {
	    	ie_node = LST_Pop(&ie_head);
	    	cond = IE_ExamineInformationEntity(&object, ie_node->ieType, &ieIE);
	    	if (ie_node->requirement == IE_K_REQUIRED) {
	    		printf("\n");
	    		printIE(ieIE);
	    		mod_head = ieIE->moduleList;
	    		mod_loop = LST_Count(&mod_head);

	    		for (k = 0; k < mod_loop; k++) {
	    			mod_node = LST_Pop(&mod_head);
	    			if (mod_node->requirement == IE_K_REQUIRED) printModule(mod_node);
	    			free(mod_node);
	    		}
	    	}
	    	free(ie_node);
	    	cond = IE_Free((void **) &ieIE);
	    }
	    cond = IE_Free((void **) &ieObject);

	    /* Check to see the missing attributes if there is any. */
	    cond = IE_ObjectRequirements(UID, &ieObject);
	    printf("\n  Missing required(type1 and type2) attributes: \n");
	    ie_head = ieObject->ieList;
	    ie_loop = LST_Count(&ie_head);

	    for (i = 0; i < ie_loop; i++) {
	    	ie_node = LST_Pop(&ie_head);
	    	cond = IE_IERequirements(UID, ie_node->ieType, &ieIE);
	    	mod_head = ieIE->moduleList;
	    	mod_loop = LST_Count(&mod_head);

	    	for (k = 0; k < mod_loop; k++) {
	    		mod_node = LST_Pop(&mod_head);
	    		cond = IE_ModuleRequirements(UID, ie_node->ieType, mod_node->moduleType, &ieModule);
	    		printf("  %s\n", ieModule->moduleDescription);
	    		attr_head = ieModule->attributeList;
	    		attr_loop = LST_Count(&attr_head);

	    		for (j = 0; j < attr_loop; j++) {
	    			attr_node = LST_Pop(&attr_head);
	    			flag = findElement(object, attr_node->element.tag, &element);
	    			cond = DCM_LookupElement(&element);
	    			if (cond != DCM_NORMAL) cond = COND_PopCondition(FALSE);

	    			if (!flag) {
	    				if (attr_node->requirement == IE_K_TYPE1){
	    					printf("    %08x, %s\n", element.tag, element.description);
	    				}else if (attr_node->requirement == IE_K_TYPE2){
	    					cond = DCM_GetElementSize(&object, attr_node->element.tag, &length);
	    					if (cond != DCM_NORMAL){
	    						cond = COND_PopCondition(FALSE);
	    						printf("    %08x, %s\n", element.tag, element.description);
	    					}
	    				}
	    			}
	    		}		/* finish one module */
	    		free(mod_node);
	    		cond = IE_Free((void **) &ieModule);
	    	}
	    	free(ie_node);
	    	cond = IE_Free((void **) &ieIE);
	    }
	    cond = IE_Free((void **) &ieObject);
    	}
    }

    /* Free the memory and remove the object handle. */
    cond = DCM_CloseObject(&object);
    if (cond != DCM_NORMAL){
    	COND_DumpConditions();
    }else{
    	printf("The object  is closed successfully.\n");
    }
    THR_Shutdown();
    return 0;
}