Exemplo n.º 1
0
static int
parse_entry(struct mod_metadata *md, const char *cval,
    struct elf_file *ef, const char *kldname)
{
	struct mod_depend mdp;
	struct mod_version mdv;
	Elf_Off data = (Elf_Off)md->md_data;
	int error = 0;

	record_start();
	switch (md->md_type) {
	case MDT_DEPEND:
		if (!dflag)
			break;
		check(EF_SEG_READ(ef, data, sizeof(mdp), &mdp));
		printf("  depends on %s.%d (%d,%d)\n", cval,
		    mdp.md_ver_preferred, mdp.md_ver_minimum, mdp.md_ver_maximum);
		break;
	case MDT_VERSION:
		check(EF_SEG_READ(ef, data, sizeof(mdv), &mdv));
		if (dflag) {
			printf("  interface %s.%d\n", cval, mdv.mv_version);
		} else {
			record_int(MDT_VERSION);
			record_string(cval);
			record_int(mdv.mv_version);
			record_string(kldname);
		}
		break;
	case MDT_MODULE:
		if (dflag) {
			printf("  module %s\n", cval);
		} else {
			record_int(MDT_MODULE);
			record_string(cval);
			record_string(kldname);
		}
		break;
	default:
		warnx("unknown metadata record %d in file %s", md->md_type, kldname);
	}
	if (!error)
		record_end();
	return error;
}
Exemplo n.º 2
0
void disconnect_abrupt(struct bufferevent* bev, hoststate_t* state) {
	log_trace(
						"disconnect-abrupt",
						"%s : Disconnecting (abrupt)",
						state->ip_address_str
	);
	record_string(state, RECKEY_DISCONNECT_RESULT, "ABRUPT");
	if (state->lastState == S_UNSET_STATE) {
		state->lastState = state->state;
	}
	end_channel_now(bev, state);
}
Exemplo n.º 3
0
void disconnect_rude(struct bufferevent* bev, void* args) {
	hoststate_t* state = (hoststate_t*) args;
	log_trace(
						"disconnect-rude",
						"%s : Disconnecting (rude)",
						state->ip_address_str
	);
	record_string(state, RECKEY_DISCONNECT_RESULT, "RUDE");
	if (state->lastState == S_UNSET_STATE) {
		state->lastState = state->state;
	}
	end_channel_now(bev, state);
}
Exemplo n.º 4
0
void store_filesystem_type(hoststate_t* state) {
	switch (state->destType) {
	case (VXWORKS) :
			record_string(state, RECKEY_FS_TYPE, "VxWorks");
			break;

	case (WINDOWS) :
			record_string(state, RECKEY_FS_TYPE, "Windows");
			break;

	case (UNIX) :
			record_string(state, RECKEY_FS_TYPE, "Unix");
			break;

	case (UNK) :
			record_string(state, RECKEY_FS_TYPE, "Unk");
			break;

	default :
			record_string(state, RECKEY_FS_TYPE, "BAD");
			break;
	}
}
Exemplo n.º 5
0
/* 对各种类型的文件buffer抽取出来的中文字符串进行集中处理 */
int
string_process(char* pBuffer, int nStrLen, int bError){
	int 		nStrType, nRet, nRet2;
	char		szTranslate[MAX_TRANS_LEN];
	char		cOld1, cOld2, *pChineseStr, *pTemp;
	int         	nHaveChinese = 0;
	int		nStrLen2;

	if ( pBuffer == NULL || *pBuffer == '\0' )
		return 1;

	memset(szTranslate, 0, MAX_TRANS_LEN);
	cOld1 = pBuffer[nStrLen];
	cOld2 = '\0';
 	pBuffer[nStrLen] = '\0';
	nRet = nStrLen+1;

	pChineseStr = pBuffer;
	nStrLen2 = nStrLen;
	if ( bError == 1 ){
		/* if this string is a error string, judge
		   there is chinese string it, if have then
		   write record to file or not;
		*/
		nStrType = STR_ERROR;
		pTemp = pBuffer;
		while ( *(pTemp+1) != '\0' ){
			if ( is_gbk_chinese(*pTemp, *(pTemp+1)) ){
				nHaveChinese = 1;
				break;
			}
			pTemp++;
		}
		if ( nHaveChinese == 0 )
			goto exit;
	}
	else{
		nStrType = get_string_type(pBuffer, nStrLen);
	}		

	if ( nStrType != STR_NORMAL ) {
		/*在抽取字符串时,非需要翻译的字符串直接记录在对应的文件里即可 */
		if ( g_nTranslate == 0 )
			record_string(nStrType, pChineseStr, nStrLen2);
		goto exit;
	}

	/* 对于需要翻译的中文字符串,先去除前后的非关键字符 */
	pChineseStr = strip_ignore_sign(pBuffer, &nStrLen2);
	cOld2= pChineseStr[nStrLen2];
	pChineseStr[nStrLen2] = '\0';

	if (pChineseStr[0] == '\0')
		goto exit;

	if ( g_nTranslate == 0 ){
		/* 如果不需要翻译,那么将这个字符串插入到字典数据库中 */
		nRet2 = insert_notrans_to_db(pChineseStr);
		if ( nRet2 == 1 ){
			/* 返回值为1,则这个字符串字典中尚不存在需要翻译,那么记录下来 */
			record_string(nStrType, pChineseStr, nStrLen2);
			g_nRightCount ++;
		}
		else if ( nRet2 == 0 ) /* 查找字典时出错 */
			g_nWrongCount ++;
		else if ( nRet2 == 2) /* 字典中已存在 */
			g_nRepeatCount ++;
	}
	else{
		nRet2 = get_trans_from_db(pChineseStr,
					  szTranslate, MAX_TRANS_LEN);
		if ( nRet2 == 0 ){
			g_nWrongCount ++;
			record_string(nStrType, pChineseStr, nStrLen2);
			goto exit;
		}
		else if ( nRet2 == 1 )
			g_nRightCount ++;

		nRet = (int)strlen(szTranslate) + 1;
		if ( (nStrLen != nStrLen2) && (cOld2 != '\0') ){
			szTranslate[nRet-1] = cOld2;
			if ( *(pChineseStr+nStrLen2+1) != '\0' )
				memcpy(szTranslate + nRet, pChineseStr + nStrLen2 + 1,
				       (int)strlen(pChineseStr + nStrLen2 + 1));
			nRet = (int)strlen(szTranslate) + 1;
		}
			
		szTranslate[nRet - 1] = cOld1;
		if ( cOld1 != '\0' )
			memcpy(szTranslate + nRet, pBuffer + nStrLen + 1,
			       (int)strlen(pBuffer + nStrLen + 1));

		strcpy(pChineseStr, szTranslate);
		nRet += (int)(pChineseStr-pBuffer);	
		goto exit2;
	}
exit:	
	pBuffer[nRet-1] = cOld1;
	if ( cOld2 != '\0' )
		pChineseStr[nStrLen2] = cOld2;
 exit2:	
	return nRet;
}