中兴微 zxic 随身wifi UZ901 程序分析 加入短信转发

在上篇博客中,我们详细探讨了系统启动过程中的几个关键程序。本文将继续深入分析这些程序的功能及其在系统中的作用。

关键程序概览

  • zte_ufi:作为主程序,负责系统的核心功能。
  • goahead:一个嵌入式Web服务器,处理来自Web端的请求。
  • iccid_check:负责ICCID校验。若想使用自己的SIM卡,需注释掉此启动项。
~ # cat /proc/sysvipc/msg
       key      msqid perms      cbytes       qnum lspid lrpid   uid   gid  cuid  cgid      stime      rtime      ctime
      4134          0   600           0          0   626   643     0     0     0     0  562895921  562895921  562884420
      4118      32769   600           0          0   626   635     0     0     0     0  562884472  562884472  562884420
      4103      65538   600           0          0     0     0     0     0     0     0          0          0  562884420
         0      98307   600           0          0   626   643     0     0     0     0  562895921  562895921  562884420
      4130     131076   600           0          0     0     0     0     0     0     0          0          0  562884420
      4111     163845   600           0          0   626   626     0     0     0     0  562895872  562895872  562884420
      5461     196614   600           0          0     0     0     0     0     0     0          0          0  562884420
      4102     229383   600           0          0   626   639     0     0     0     0  562884427  562884427  562884420
      4129     262152   600           0          0     0     0     0     0     0     0          0          0  562884420
      4099     294921   600           0          0   626   626     0     0     0     0  562884423  562884423  562884420
      4108     327690   600           0          0     0     0     0     0     0     0          0          0  562884420
      5459     360459   600           0          0   626   638     0     0     0     0  562884472  562884472  562884420
      4101     393228   600           0          0   626   626     0     0     0     0  562895918  562895918  562884420
      4104   11501581   600           0          0     0     0     0     0     0     0          0          0  562895907
      4105   11534350   600           0          0     0     0     0     0     0     0          0          0  562895907

通过查看操作系统的消息队列,我们可以了解到 goahead 负责处理Web端的请求,并通过消息队列将请求发送给 zte_ufi 进行处理。

SMS转发功能添加
在研究MF833U1固件时,我们发现其启动项中包含SMS和电话簿功能。虽然成功提取并运行了相关文件,但收到的短信并未在网页上显示。初步分析认为这可能是由于版本差异较大所致。

/tmp # ./sms
[SMS] zte_sms:/etc_rw/config/sms_db does not exist,socreate it.
[SMS] zte_sms:failed to create db dir.
[SMS] zUfiSms_CheckstoreDir failed.
zUfiSms_ExecSql: try_times=1, SQL=SELECT count(*) FROM sms WHERE Tag='1';, Errmsg=out of memory
sms app init finished, will to receive msg, msgid:11501581

通过 msgid:11501581,我们反推出 key=4104 (0x1008)。为了更好地处理短信,我们决定停止SMS进程,并编写一个程序来接收和处理消息。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

#define MSG_SIZE 4112

// 定义消息结构体
struct msg_buffer {
    long msg_type;
    char msg_text[MSG_SIZE];
};

void print_hex(const char *data, int length) {
    int i = 0 ;
    for (i = 0; i < length; i++) {
        printf("%02x ", (unsigned char)data[i]);
    }
    printf("\n");
}


int main(int argc, char *argv[]) {
    int msqid;
    struct msg_buffer message;

    // 获取或创建消息队列,并返回消息队列ID
    if ((msqid = msgget(0x1008, 0x380)) == -1) {
        perror("msgget");
        exit(EXIT_FAILURE);
    }

    printf("MSQID: %d\n", msqid);
    printf("Waiting for messages...\n");

    // 循环接收消息
    while (1) {
        // 接收消息
        if (msgrcv(msqid, &message, sizeof(message.msg_text), 0, 0) == -1) {
            perror("msgrcv");
            continue;
        }

        // 打印接收到的消息
        printf("Received message: \n");
        printf("msg_type: %ld\n", message.msg_type);
        print_hex(message.msg_text,MSG_SIZE);
    }

    return EXIT_SUCCESS;
}

下一步写个解析PDU的程序,然后发到webhook上就好了

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容