IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> IDA伪代码C语言复现调试(mqtt client) -> 正文阅读

[C++知识库]IDA伪代码C语言复现调试(mqtt client)

IDA伪代码分析

????????mqtt client在connect Broker成功后往往紧接着subscribe topics。

????????IDA反编译了一段mqtt client,找到subscribe部分的伪代码,力图复现代码里真实subscribe内容。

????????IDA 相关内容如下

?

?

????????粗略分析可以知道,这里要订阅 0x18(24)个topic。topic由8个“基本topic体”追加附上特定字符串构成。?

????????从第258和第268行,可以分析出“基本topic”体是8个什么样的字符串。

复现伪代码

在我之前的博客所用代码之sample/MQTTAsync_subscribe.c修改实现伪代码功能。

eclipse-paho.mqtt 本地编译与调试_晓翔仔的博客-CSDN博客下载安装下载eclipse-paho.mqtt.c的压缩包传至ubuntu Linux并解压下载地址:GitHub - eclipse/paho.mqtt.c: An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/解压后ubuntu@i...https://blog.csdn.net/qq_33163046/article/details/121382860

设置连接参数时,修改

	conn_opts.onSuccess = onConnect;

	conn_opts.onSuccess = OnConnect_subscribemany_24;

编写?OnConnect_subscribemany_24连接成功回调函数。

void OnConnect_subscribemany_24(void* context, MQTTAsync_successData* response)
{
	MQTTAsync c = (MQTTAsync)context;
	MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer;
	int rc;
	const char *MsgType[8]={
								"VEHICLE_0*",
								"VEHICLE_1*",
								"VEHICLE_2*",
								"VEHICLE_3*",
								"VEHICLE_4*",
								"VEHICLE_5*",
								"VEHICLE_6*",
								"VEHICLE_7*",
							};
	char type2[80];
	char type3[80];
	char suffix_2[15];
	char** topics;
    topics = (char**)malloc(sizeof(int*)*24);//为二维数组分配0x18行 
    for (int i = 0; i < 24; ++i)
    {//为每列分配0x32个大小空间 
        topics[i] = (char*)malloc(sizeof(char)*50);
    }
	strcpy(suffix_2, "/SP_1234/");
	for (int j = 0; j != 24; j += 3 )
    {
        int k = j/3;
    	strcpy(type2,MsgType[k]);
    	memcpy(&type2[strlen(type2)], "/123/",6);// VEHICLE_*/p2p/
    	strcpy(type3,MsgType[k]);
    	strcat(type3, suffix_2);             //  VEHICLE_*/SP_0X%X/
    	strcpy(topics[j], MsgType[k]);                 // v3[j] is VEHICLE_*
    	strcpy(topics[j + 1], type2);             // v3[j+1] is VEHICLE_*/123/
    	strcpy(topics[j + 2], type3);       // v3[j+2] is  VEHICLE_*/SP_1234/  
    }
	int qoss[24];
	for(int i=0; i<24; i++)
	{
		qoss[i]= 0;
	}
	printf("subscribemany ,all the 24 topics are:\n");
	for(int i=0; i<24; i++)
	{
		printf("%d topic:%s, qoss:%d\n",i+1,topics[i],qoss[i]);
	}

	printf( "[OnConnect_subscribemany24]In connect onSuccess callback for client c, context %p\n", context);
	opts.onSuccess = donSubscribe;
	opts.context = c;

	rc = MQTTAsync_subscribeMany(c, 24, topics, qoss, &opts);
	if (rc != MQTTASYNC_SUCCESS)
		printf("fail to MQTTAsync_subscribeMany,return code %d\n", rc);
	else
		printf("Sucess to MQTTAsync_subscribeMany,return code %d\n", rc);	
}

经过测试,可以成功订阅所有topic,测试日志如下

ubuntu@ip-172-*-*-20:~/soft/paho.mqtt.c-master/build/output/samples_in$ ./MQTTAsync_subscribe 
[harry] test async subscribe Sucess to create client, return code 0
[harry]Success to set callbacks, return code 0
[harry]Sucess to start connect, return code 0
[harry]subscribemany ,all the 24 topics are:
1 topic:VEHICLE_0*, qoss:0
[harry]subscribemany ,all the 24 topics are:
2 topic:VEHICLE_0*/123/, qoss:0
[harry]subscribemany ,all the 24 topics are:
3 topic:VEHICLE_0*/SP_1234/, qoss:0
[harry]subscribemany ,all the 24 topics are:
4 topic:VEHICLE_1*, qoss:0
[harry]subscribemany ,all the 24 topics are:
5 topic:VEHICLE_1*/123/, qoss:0
[harry]subscribemany ,all the 24 topics are:
6 topic:VEHICLE_1*/SP_1234/, qoss:0
[harry]subscribemany ,all the 24 topics are:
7 topic:VEHICLE_2*, qoss:0
[harry]subscribemany ,all the 24 topics are:
8 topic:VEHICLE_2*/123/, qoss:0
[harry]subscribemany ,all the 24 topics are:
9 topic:VEHICLE_2*/SP_1234/, qoss:0
[harry]subscribemany ,all the 24 topics are:
10 topic:VEHICLE_3*, qoss:0
[harry]subscribemany ,all the 24 topics are:
11 topic:VEHICLE_3*/p2p/, qoss:0
[harry]subscribemany ,all the 24 topics are:
12 topic:VEHICLE_3*/SP_1234/, qoss:0
[harry]subscribemany ,all the 24 topics are:
13 topic:VEHICLE_4*, qoss:0
[harry]subscribemany ,all the 24 topics are:
14 topic:VEHICLE_4*/123/, qoss:0
[harry]subscribemany ,all the 24 topics are:
15 topic:VEHICLE_4*/SP_1234/, qoss:0
[harry]subscribemany ,all the 24 topics are:
16 topic:VEHICLE_5*, qoss:0
[harry]subscribemany ,all the 24 topics are:
17 topic:VEHICLE_5*/p2p/, qoss:0
[harry]subscribemany ,all the 24 topics are:
18 topic:VEHICLE_5*/SP_1234/, qoss:0
[harry]subscribemany ,all the 24 topics are:
19 topic:VEHICLE_6*, qoss:0
[harry]subscribemany ,all the 24 topics are:
20 topic:VEHICLE_6*/123/, qoss:0
[harry]subscribemany ,all the 24 topics are:
21 topic:VEHICLE_6*/SP_1234/, qoss:0
[harry]subscribemany ,all the 24 topics are:
22 topic:VEHICLE_7*, qoss:0
[harry]subscribemany ,all the 24 topics are:
23 topic:VEHICLE_7*/123/, qoss:0
[harry]subscribemany ,all the 24 topics are:
24 topic:VEHICLE_7*/SP_1234/, qoss:0
[OnConnect_subscribemany24]In connect onSuccess callback for client c, context 0x55d5d0a37968
Sucess to MQTTAsync_subscribeMany,return code 0
In subscribe onSuccess callback for client d, 0x55d5d0a37968 granted qos -1275047528Message arrived
     topic: VEHICLE_7*/SP_1234/
   message: Hello World!

ubuntu@ip-172-*-*-20:~/soft/paho.mqtt.c-master/build/output/samples_out$ ./MQTTAsync_publish
test async publish[harry]Sucess to create client object, return code 0
Success to set callback, return code 0
Success to start connect, return code 0
Waiting for publication of Hello World!
on topic VEHICLE_*/SP_1234/ for client with ClientID: ExampleClientPub
Successful connection
Success to start sendMessage, return code 0
Message with token value 0 delivery confirmed
Successful disconnection

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2021-12-11 15:32:36  更:2021-12-11 15:33:32 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 11:55:38-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码