⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sitable.c

📁 MiniWinOuterSM MiniWinOuterSM
💻 C
📖 第 1 页 / 共 3 页
字号:
//////////////////////////////////////////////////////////////////////////
// DII Functions
int GetModuleInfo(UCHAR*section,int index,ModuleInfo*mi)
{
	int i;
	UCHAR*p=section+8+GetMsgHeaderLength(section)+20;
	for(i=0;i<index;i++)
		p+=8+p[7];
	mi->moduleId=(p[0]<<8)|p[1];
	
	mi->moduleSize=p[2]<<24;
	mi->moduleSize|=p[3]<<16;
	mi->moduleSize|=p[4]<<8;
	mi->moduleSize|=p[5];
	
	mi->moduleVersion=p[6];
	mi->moduleInfoLength=p[7];
	mi->moduleInfoBytes=(p+8);
	return 0;
}
int GetDownloadInfoIndicate(UCHAR*section,DOWNLOADINFOINDICATE*dii)
{
	UCHAR*p=section+8+GetMsgHeaderLength(section);
	dii->downloadId=p[0]<<24;
	dii->downloadId|=p[1]<<16;
	dii->downloadId|=p[2]<<8;
	dii->downloadId|=p[3];
	p+=4;

	dii->blockSize=(p[0]<<8)|p[1];
	dii->windowSize=p[2];
	dii->ackperiod=p[3];
	dii->tCDownloadWindow=p[4]<<24;
	dii->tCDownloadWindow|=p[5]<<16;
	dii->tCDownloadWindow|=p[6]<<8;
	dii->tCDownloadWindow|=p[7];
	dii->tCDownloadScenario=p[8]<<24;
	dii->tCDownloadScenario|=p[9]<<16;
	dii->tCDownloadScenario|=p[10]<<8;
	dii->tCDownloadScenario|=p[11];
	p+=12;
	dii->compatibilityDescriptor=p;
	p+=2;
	dii->numberOfModules=(p[0]<<8)|p[1];
	p+=2;
	return 0;
}
char*GetModuleName(ModuleInfo*mi,char*name,int maxnamelen)
{
	UCHAR*des=FindDescriptor(mi->moduleInfoBytes,mi->moduleInfoLength,DSMCC_NAME_DESCRIPTOR_TAG);
	if(des!=NULL){
		int nlen;
		if(maxnamelen>0)
			nlen=(maxnamelen>des[1])?des[1]:maxnamelen;
		memcpy(name,des+2,nlen);
		name[nlen]='\0';
		return name;
	}
	return NULL;
}
//////////////////////////////////////////////////////////////////////////
//for DDB
int GetDSMCCDownloadData(UCHAR *section,DSMCCDownloadData *dsmcDownData)
{
	UCHAR *p;
	UCHAR *pHead;
	pHead=p=section+8;
	dsmcDownData->protocolDiscriminator=p[0];
	p++;
	dsmcDownData->dsmccType=p[0];
	p++;
	dsmcDownData->messageId=(p[0]<<8)|p[1];
	p += 2;
	dsmcDownData->downloadId=(p[0])<<24|(p[1])<<16|(p[2])<<8|p[3];
	p+=4;
	dsmcDownData->reserved=p[0];
	p++;
	dsmcDownData->adaptationLength=p[0];
	p++;
	dsmcDownData->messsageLength=(p[0]<<8)|p[1];
	p += 2;
	return p-pHead;
}
int GetDDBData(UCHAR *section,UCHAR *buf)
{
	UCHAR *p;
	DSMCCDownloadData dsmcDownData;
	int blockSize=0;
	p = section+8+GetMsgHeaderLength(section);
	GetDSMCCDownloadData(section,&dsmcDownData);
	blockSize = dsmcDownData.messsageLength-6-GetMsgHeaderAdapLength(section);
	
	memcpy(buf,p+6,blockSize);
	return blockSize;
}
/////////////////////////////////////////////////////////////////////////
//for BIOPMessage IOP::IOR..

int GetIOPIOR(UCHAR*p,IOPIOR*ior)
{
	UCHAR *op=p;
	int i;
	ior->typeId_length=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
	p+=4;

	ior->typeId=p;	
	p+=ior->typeId_length;
	if(ior->typeId_length%4)
		p+=(4-ior->typeId_length%4);// skip 4 bytes alignment 
	if(ior->typeId_length>32){
		//TRACE("IOP::IOR typeId_length error\n");
		return ERR_IOR_TYPEIDLEN;
	}
	ior->taggedProfileCount=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
	p+=4;

	ior->profileBytes=p;
	for(i=0;i<(int)ior->taggedProfileCount;i++){
		UINT profilelen;
		p+=4;//skip profileId_tag;
		profilelen=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
		p+=4+profilelen;
	}
	return p-op;
}
int GetProfile(IOPIOR*ior,int index,BIOPProfile*profile)
{
	UCHAR*p;
	int i;
	p=ior->profileBytes;
	for(i=0;(i<index)&&(i<(int)ior->taggedProfileCount);i++){
		UINT profile_data_length;
		p+=4;//skip profileId_tag;
		profile_data_length=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
		p+=4+profile_data_length;
	}
	profile->profileId_tag=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];		p+=4;
	profile->profile_data_length=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
	profile->profile_data_byte_order=*p++;
	profile->ComponentCount=*p++;
	profile->ComponentBytes=p;
	return profile->profile_data_length+8;
}
int FindProfile(IOPIOR*ior,BIOPProfile*profile,UINT profileId_tag)
{
	int i;
	for(i=0;i<(int)ior->taggedProfileCount;i++){
		GetProfile(ior,i,profile);
		if(profile->profileId_tag==profileId_tag)
			return 1;
	}
	return 0;
}
static int GetObjLocation(UCHAR*p,BIOPObjectLocation*location)
{
	UINT componentId_tag=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
	if(componentId_tag==TAG_ObjectLocation){
		location->componentId_tag=componentId_tag;
		location->component_data_length=*p++;
		location->carouselId=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
		location->moduleId=(p[0]<<8)|p[1];	p+=2;
		location->version=(p[0]<<8)|p[1];	p+=2;
		location->objectKeyLength=*p++;
		location->objectKey=p;
		p+=location->objectKeyLength;
		return location->component_data_length+5;
	}
	return 0;
}
int GetObjectLocation(BIOPProfile*profile,BIOPObjectLocation*location)
{
	UCHAR*p;
	int i;
	//ASSERT(profile->profileId_tag==TAG_BIOP);
	p=profile->ComponentBytes;
	for(i=0;i<profile->ComponentCount;i++){
		int clen=GetObjLocation(p,location);
		if(clen)
			return clen;
		else
			p+=p[4]+5;
	}
	return 0;
}
static int _GetConnBinder(UCHAR*p,DSMConnBinder*binder)
{
	UINT componentId_tag=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
	if(componentId_tag==TAG_ConnBinder){
		binder->componentId_tag=componentId_tag;
		binder->component_data_length=*p++;
		binder->tapCount=*p++;
		binder->tapBytes=p;
		return binder->component_data_length+5;
	}
	return 0;
}
int GetConnBinder(BIOPProfile*profile,DSMConnBinder*binder)
{
	UCHAR*p;
	int i;
	ASSERT(profile->profileId_tag==TAG_BIOP);
	p=profile->ComponentBytes;
	for(i=0;i<profile->ComponentCount;i++){
		int clen=_GetConnBinder(p,binder);
		if(clen)
			return clen;
		else
			p+=p[4]+5;
	}
	return 0;
}
int GetDSMTap(UCHAR*p,DSMTap*tap)
{
	tap->Id =(p[0]<<8)|p[1];	p+=2;
	tap->Use=(p[0]<<8)|p[1];	p+=2;
	tap->associationTag=(p[0]<<8)|p[1];	p+=2;
	tap->selectorLength=*p++;
	tap->selectorBytes=p;
	if(tap->selectorLength>0){
		tap->msgSelector.selectorType=(p[0]<<8)|p[1];	p+=2;
		tap->msgSelector.transactionId=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
		tap->msgSelector.timeOut=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
	}
	return 7+tap->selectorLength;
}
static int Get_Object(UCHAR*pobj,Object*obj);

int GetConnBinderTap(DSMConnBinder*binder,int index,DSMTap*tap)
{
	int i;
	UCHAR*p=binder->tapBytes;
	for(i=0;i<index;i++){
		p+=7+p[6];
	}
	return GetDSMTap(p,tap);
}
int GetObjectByName(BIOPMessage*msg,const char*name,Object*obj)
{
	UCHAR*p=msg->messageBody;
	int i,bindCount=(p[0]<<8)|p[1];
	p+=2;
	for( i=0;i<bindCount;i++){
		p+=Get_Object(p,obj);
		if(strncmp((char*)obj->Name,name,obj->nameLength)==0)
			return 1;
	}
	return 0;
}

int GetBIOPMessage(UCHAR*p,BIOPMessage*msg)
{
	UCHAR*pstart=p;
	msg->magic=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
	if(msg->magic!=0x42494F50)
		return -1;
	msg->version=(p[0]<<8)|p[1];	p+=2;
	p+=2;	//skip byte_order and message_type;
	msg->messageSize=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
	msg->objectKeyLength=*p++;
	msg->objectKey=p;	p+=msg->objectKeyLength;
	msg->objectKindLength=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
	msg->objectKind=p;	p+=msg->objectKindLength;
	msg->objectInfoLength=(p[0]<<8)|p[1];	p+=2;
	msg->objectInfo=p;	p+=msg->objectInfoLength;
	msg->serviceContextCount=*p++;
	msg->serviceContextBytes=p;	p+=msg->serviceContextCount;
	if(p-pstart+4>msg->messageSize+12){
		//ASSERT(FALSE);
		return -1;
	}
	msg->messageBodyLengh=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
	msg->messageBody=p;
	return msg->messageSize+12;
}
int FindMessage(UCHAR*moduleBytes,UINT moduleSize,BIOPMessage*msg,UCHAR*key)
{
	UCHAR*p=moduleBytes;
	UINT pos;
	for(pos=0;pos<moduleSize;){
		int msgSize=GetBIOPMessage(p,msg);
		if(msgSize==-1)return 0;
		p+=msgSize;
		pos+=msgSize;
		if(memcmp(msg->objectKey,key,msg->objectKeyLength)==0)
			return msgSize;
	}
	return 0;
}
//存在于ior中,包含locationComponent和binderComponent等多个子结构
int GetProfileBody(IOPIOR*ior, int index, BIOPProfile *profile)
{
	UCHAR*p;
	int i;
	p=ior->profileBytes;
	for(i=0;(i<index)&&(i<ior->taggedProfileCount);i++){
		UINT profile_data_length;
		p+=4;//skip profileId_tag;
		profile_data_length=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
		p+=4+profile_data_length;
	}
	profile->profileId_tag=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];		p+=4;
	profile->profile_data_length=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
	profile->profile_data_byte_order=*p++;
	profile->ComponentCount=*p++;
	profile->ComponentBytes=p;
	return profile->profile_data_length+8;
}
int FindProfileBody(IOPIOR*ior,BIOPProfile *profile,UINT tag)
{
	int i;
	for(i=0;i<ior->taggedProfileCount;i++){
		GetProfileBody(ior,i,profile);
		if(profile->profileId_tag==tag)
			return 1;
	}
	return 0;
}
//pobj为object在BIOP::DirectoryMessage中的第一个字节
//函数返回object信息的长度
static int Get_Object(UCHAR*pobj,Object*obj)
{
	UCHAR*p=pobj;
	int nameCount=*p++;
	int iorlen,j;
	IOPIOR ior;
	for(j=0;j<nameCount;j++){
		obj->nameLength=*p++;
		obj->Name=p;
		p+=obj->nameLength;
		obj->kindLength=*p++;
		obj->kind=p;
		p+=obj->kindLength;
	}
	obj->bindType=*p++;//bindingType;
	obj->ior=p;
	iorlen=GetIOPIOR(p,&ior);	p+=iorlen;
	obj->objectInfoLength=(p[0]<<8)|p[1];
	obj->objectInfo=p+2;
	p+=obj->objectInfoLength+2;//
	if(iorlen<0)
		return iorlen;
	return p-pobj;
}
int GetOCObject(BIOPMessage*msg,int index,Object*obj)
{
	int i;
	UCHAR*p=msg->messageBody;
	int bindCount=(p[0]<<8)|p[1];
	p+=2;
	for(i=0;i<index;i++){
		p+=Get_Object(p,obj);
	}
	return Get_Object(p,obj);
}
UCHAR*FindObjectByName(BIOPMessage*msg,const char*fname)
{
	int i,bindCount;
	UCHAR*p=msg->messageBody;
	bindCount=(p[0]<<8)|p[1];
	for(i=0;i<bindCount;i++){
		Object obj;
		int len=strlen(fname);
		GetOCObject(msg,i,&obj);
		if(len<obj.nameLength)
			len=obj.nameLength;
		if(strncmp(fname,(const char*)obj.Name,len)==0)
			return obj.ior;
	}
	return NULL;
}
int OCMSGAdd(OCMSG*parentMsg,OCMSG*msg)
{
	msg->next=parentMsg->next;
	msg->prev=parentMsg;
	if(msg->next)msg->next->prev=msg;
	parentMsg->next=msg;
	return 0;
}

OCMSG*FindOCMSGByKey(OCMSG*root,UCHAR*key)
{
	BIOPMessage msg;
	OCMSG*dir=root;
	while(dir){
		GetBIOPMessage(dir->msgData,&msg);
		if(memcmp(msg.objectKey,key,msg.objectKeyLength)==0)	
			return dir;
		dir=dir->next;
	}
	return NULL;
}
char*GetHexStr(UCHAR*str,int len)
{
	int i;
	static char hex[256];
	char*p=hex;
	for(i=0;(i<len)&&(i<256);i++,p+=2)
		sprintf(p,"%02X",*str++);
	*p++=0;
	return hex;
}
UCHAR*OCGetFileMessage(OCMSG*root,const char*fname)
{//param dir must be BIOP::DirectoryMessage
	char name[128];
	char*p=(char*)fname;
	char*pname=name;
	UCHAR*iorBytes=NULL;
	OCMSG*dir=root;
	while(*p)
	{
		BIOPMessage msg;
		BIOPObjectLocation loc;
		BIOPProfile profile;
		IOPIOR ior;
		p++;
		pname=name;
		while((*p!='/')&&(*p!=0))
			*pname++=*p++;
		*pname++='\0';
		GetBIOPMessage(dir->msgData,&msg);
		iorBytes=FindObjectByName(&msg,name);
		if(iorBytes==NULL)
			return NULL;
		GetIOPIOR(iorBytes,&ior);
		GetProfileBody(&ior,0,&profile);
		GetObjectLocation(&profile,&loc);
		printf("Find '%s'\n",GetHexStr(loc.objectKey,loc.objectKeyLength));
		dir=FindOCMSGByKey(root,loc.objectKey);
	}while((*p)&&dir);
	return iorBytes;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -