首页
社区
课程
招聘
未解决 [求助]C语言实现ce搜索功能的两道题
发表于: 2020-1-21 12:26 3791

未解决 [求助]C语言实现ce搜索功能的两道题

2020-1-21 12:26
3791
有两道道题,想请各问大神解答一下
题目是                                               
(1)模拟实现CE的数据搜索功能:                                                                                       
        这一堆数据中存储了角色的血值信息,假设血值的类型为int类型,值为100(10进制)                       
       请列出所有可能的值以及该值对应的地址       
        0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,                                       
        0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00,                                       
        0x00,0x33,0x00,0x47,0x0C,0x0E,0x00,0x0D,0x00,0x11,                                       
        0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00,                                       
        0x00,0x00,0x64,0x10,0x00,0x00,0x00,0x00,0x00,0x00,                                       
        0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00,                                       
        0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00,                                       
        0x00,0x02,0x74,0x0F,0x41,0x00,0x06,0x08,0x00,0x00,                                       
        0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00,                                       
        0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00       
(2)如果这一堆数据中存储了角色的名字信息(WOW),请列出角色名的内存地址.                                       
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,
 0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00, 
 0x00,0x33,0x00,0x47,0x0C,0x0E,0x00,0x0D,0x00,0x11,
 0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00, 
 0x00,0x00,0x64,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00, 
 0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00, 
 0x00,0x02,0x57,0x4F,0x57,0x00,0x06,0x08,0x00,0x00, 
 0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00, 
 0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00 
编写函数,返回角色名字信息的地址,如果没有返回0                                                                               
 char* FindRoleNameAddr(char* pData,char* pRoleName)  
并且编写函数,遍历上面数据中所有角色名字.                                          
两道题的搜索的要求是:将这堆数据定义一个数组,搜索从第一个0x00开始然后四个字节(0x00,0x01,0x02,0x03)与int型的100进行比较,然后下一个从0x01开始再是四个字节(0x01,0x02,0x03,0x04)与int型的100进行比较,依次进行搜索查找,直到数组查找完成,同样对于字符串“WOW”的查找也是一样,索从第一个0x00开始然后四个字节与字符串“WOW”进行比较,然后下一个从0x01开始再是四个字节(0x01,0x02,0x03,0x04)与与字符串“WOW”进行比较
因为实在不会,代码写半天也是错误,只能求助了,在此麻烦大家了

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 0
支持
分享
最新回复 (8)
雪    币: 6669
活跃值: (4516)
能力值: ( LV10,RANK:163 )
在线值:
发帖
回帖
粉丝
2
这也太简单了吧.....
上传的附件:
2020-1-21 14:39
0
雪    币: 1156
活跃值: (249)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
yimingqpa 这也太简单了吧.....
大哥,是C语言,不是c++啊
2020-1-21 21:57
0
雪    币: 7465
活跃值: (4196)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4

最后于 2020-1-25 04:13 被htpidk编辑 ,原因:
2020-1-24 00:45
0
雪    币: 1156
活跃值: (249)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
yimingqpa 这也太简单了吧.....
对不起了老哥,c++我不会,所以看不懂啊,能用C语言帮我写一下吗??谢谢啦
2020-2-3 11:38
0
雪    币: 1432
活跃值: (599)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
char* p = arr;
for (int i = 0; i < 100; i++)
{//连续的读值,从char读到int
int* pp = (int*)(p + i);
       if (*pp == 100)
       {printf("%x\n", pp);}}
试试这个,我也是个小菜鸡
2020-2-3 12:48
0
雪    币: 1931
活跃值: (442)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
..刚做过,强转就行了,滴水练习题,我也在学
char data[]= {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,				

0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00,				

0x00,0x33,0x00,0x47,0x0C,0x0E,0x00,0x0D,0x00,0x11,				

0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00,				

0x00,0x00,0x64,0x10,0x00,0x00,0x00,0x00,0x00,0x00,				

0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00,				

0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00,				

0x00,0x02,0x74,0x0F,0x41,0x00,0x06,0x08,0x00,0x00,				

0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00,				

0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00				

};
// type: byte     num: data
void search(int type, int num)
{
	char *start = data;
	int length = sizeof(data)/sizeof(data[0]);
	int i=0;
	while(i< length-type)
	{
		if(type == 4)
		{
			if(*(int*)&data[i] == num)
			{
				printf("address:%x , data:%d\n",&data[i],(int)num);
			}
		}else if(type == 2)
		{
			if(*(short*)&data[i] == (short)num)
			{
				printf("address:%x , data:%d\n",&data[i],(short)num);
			}
		}else
		{
			if(*(char*)&data[i] == (char)num)
			{
				printf("address:%x , data:%d\n",&data[i],(char)num);
			}
		}
		i += 1;
		
	}
}


int main(int argc, char* argv[])
{
	printf("data start from:%x\n", data);
	search(4,100);
	return 0;
}
这是没解耦的,接下来解耦的,
对其进行解耦,接口不改变
char data[]= {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,				

0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00,				

0x00,0x33,0x00,0x47,0x0C,0x0E,0x00,0x0D,0x00,0x11,				

0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00,				

0x00,0x00,0x64,0x10,0x00,0x00,0x00,0x00,0x00,0x00,				

0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00,				

0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00,				

0x00,0x02,0x74,0x0F,0x41,0x00,0x06,0x08,0x00,0x00,				

0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00,				

0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00				

};
// type: byte     num: data
void search_int(int num, int length)
{
	int i=0;
	while(i<length-4)
	{
		if(*(int*)&data[i] == num)
		{
			printf("address:%x , data:%d\n",&data[i],(int)num);
		}
		i++;
	}
}
void search_short(int num, int length)
{
	int i=0;
	while(i<length-2)
	{
		if(*(short*)&data[i] == num)
		{
			printf("address:%x , data:%d\n",&data[i],(short)num);
		}
		i++;
	}
}

void search_char(int num, int length)
{
	
	int i=0;
	while(i<length-1)
	{
		if(*(char*)&data[i] == num)
		{
			printf("address:%x , data:%d\n",&data[i],(char)num);
		}
		i++;
	}
}
void search(int type, int num)
{
	int length = sizeof(data)/sizeof(data[0]);
	int i=0;
	typedef void (*funcptr)(int,int);
	funcptr p;
	if(type == 4)
	{
		p = search_int;
	}
	else if(type == 2)
	{
		p = search_short;
	}else
	{
		p = search_char;
	}
	p(num,length);
}


int main(int argc, char* argv[])
{
	printf("data start from:%x\n", data);
	search(4,0x64);
	return 0;
}


第二题
#include "string.h"
char data[]=
{
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,				
0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00,				
0x00,0x33,0x00,0x47,0x0C,0x0E,0x00,0x0D,0x00,0x11,				
0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00,				
0x00,0x00,0x64,0x10,0x00,0x00,0x00,0x00,0x00,0x00,				
0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00,				
0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00,				
0x00,0x02,0x57,0x4F,0x57,0x00,0x06,0x08,0x00,0x00,				
0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00,				
0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00
};

char* FindRoleNameAddr(char* pData,char* pRoleName)
{
	int length = strlen(pRoleName);
	int all = sizeof(data)/sizeof(pData[0]);
	int i=0; 
	while(i < all -length)
	{
		if(strncmp(&pData[i],pRoleName,length) == 0)
		{
			return &pData[i];
			break;
		}

		i++;
	}
	return NULL;
}

int main(int argc, char* argv[])
{
	char *result = FindRoleNameAddr(data,"WOW");
	if(result != NULL)
		printf("%p\n", result);
	else
		printf("not found\n");
	return 0;
}

2020-2-3 14:00
0
雪    币: 1156
活跃值: (249)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
谢谢大家的回答了,在此谢谢大家了
2020-2-4 13:47
0
雪    币: 399
活跃值: (68)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
不错不错,刚好也可以参考学习一下,感谢
2020-2-4 16:03
0
游客
登录 | 注册 方可回帖
返回
//