hexdump in kernel mode

本文详细解析了一个用于内核环境的十六进制内存转储函数macdbg_dmphex_kernel。该函数能够将指定长度的内存缓冲区内容转换为十六进制形式,并在每行显示可打印字符。通过遍历内存缓冲区,函数按行输出内存地址、十六进制数据及对应的ASCII字符,便于调试和分析。

  

  
int macdbg_dmphex_kernel(const char* buff_in, int len)
{      
    int retval = 0; 
    int x, y, tot, lineoff;
    const char* curr;
    char buff[128];
    int index;
            
    //Ser_Printf("buff %x.\r\n", buff );
    lineoff = 0;
    curr = buff_in;
    tot = 0;
                             
    for( x = 0; x+16 < len; ){   
         index = 0x00;
         memset( buff, 0x00, sizeof(buff) );
         sprintf( &buff[index], "%x\t", lineoff );     
         index = strlen(buff);
         //printk("index = %d\n", index);
         
         for( y = 0; y < 16; y++ ){
              sprintf( &buff[index], "%02x ", (unsigned char)*(curr + y) );
              index = strlen(buff);
         }
         sprintf( &buff[index], "%s", "  " );  
         index = strlen(buff);
         for( y = 0; y < 16; y++ ){
              char c;
              c = *(curr + y);
              if( c > 31 && c < 127 ){
                  sprintf( &buff[index], "%c", c );
              }else{
                  sprintf( &buff[index], "%c", '.' );
              }
              index = strlen(buff);
              tot++;
           }
           curr += 16;
           x += 16;
           lineoff+=16;
           sprintf( &buff[index], "%s", "\r\n" );
           printk("%s", buff);
    }
           
    //do last line
    //Ser_Printf("tot %d.\r\n", tot );
    //Ser_Printf("len %d.\r\n", len );                                                  
    index = 0x00;
    memset( buff, 0x00, sizeof(buff) );
    if( tot < len ){
        curr = (buff_in + tot);
        sprintf( &buff[index], "%x\t", lineoff );     
        index = strlen(buff); 
        for( y = 0; y < (len - tot); y++ ){
             sprintf( &buff[index], "%02x ", (unsigned char)*(curr + y) );
             index = strlen(buff);
        }
        //padding with spaces
        //printk("(len - tot) %d.\r\n", (len - tot) );
        if( (len - tot) < 16 ){
            for( y = 0; y<(16-(len-tot)); y++ ){
                 sprintf( &buff[index], "%s", "   " );  
                 index = index + 3;   
            }
        }
        
        sprintf( &buff[index], "%s", "  " );  
        index = strlen(buff);           
        //Ser_Printf("(len - tot) %d.\r\n", (len - tot) );
        for( y = 0; y < (len - tot); y++ ){
             char c;
             c = *(curr + y);
             if( c > 31 && c < 127 ){
                 sprintf( &buff[index], "%c", c );
             }else{
                 sprintf( &buff[index], "%c", '.' );
             }
             index = strlen(buff);
        }
    }
    sprintf( &buff[index], "%s", "\r\n" );
    printk("%s", buff);       
    return retval;
}


int macdbg_dmphex_kernel(const char* buff_in, int len)
{      
    int retval = 0; 
    int x, y, tot, lineoff;
    const char* curr;
    char buff[128];
    int index;
            
    //Ser_Printf("buff %x.\r\n", buff );
    lineoff = 0;
    curr = buff_in;
    tot = 0;
                             
    for( x = 0; x+16 < len; ){   
         index = 0x00;
         memset( buff, 0x00, sizeof(buff) );
         sprintf( &buff[index], "%x\t", lineoff );     
         index = strlen(buff);
         //printk("index = %d\n", index);
         
         for( y = 0; y < 16; y++ ){
              sprintf( &buff[index], "%02x ", (unsigned char)*(curr + y) );
              index = strlen(buff);
         }
         sprintf( &buff[index], "%s", "  " );  
         index = strlen(buff);
         for( y = 0; y < 16; y++ ){
              char c;
              c = *(curr + y);
              if( c > 31 && c < 127 ){
                  sprintf( &buff[index], "%c", c );
              }else{
                  sprintf( &buff[index], "%c", '.' );
              }
              index = strlen(buff);
              tot++;
           }
           curr += 16;
           x += 16;
           lineoff+=16;
           sprintf( &buff[index], "%s", "\r\n" );
           printk("%s", buff);
    }
           
    //do last line
    //Ser_Printf("tot %d.\r\n", tot );
    //Ser_Printf("len %d.\r\n", len );                                                  
    index = 0x00;
    memset( buff, 0x00, sizeof(buff) );
    if( tot < len ){
        curr = (buff_in + tot);
        sprintf( &buff[index], "%x\t", lineoff );     
        index = strlen(buff); 
        for( y = 0; y < (len - tot); y++ ){
             sprintf( &buff[index], "%02x ", (unsigned char)*(curr + y) );
             index = strlen(buff);
        }
        //padding with spaces
        //printk("(len - tot) %d.\r\n", (len - tot) );
        if( (len - tot) < 16 ){
            for( y = 0; y<(16-(len-tot)); y++ ){
                 sprintf( &buff[index], "%s", "   " );  
                 index = index + 3;   
            }
        }
        
        sprintf( &buff[index], "%s", "  " );  
        index = strlen(buff);           
        //Ser_Printf("(len - tot) %d.\r\n", (len - tot) );
        for( y = 0; y < (len - tot); y++ ){
             char c;
             c = *(curr + y);
             if( c > 31 && c < 127 ){
                 sprintf( &buff[index], "%c", c );
             }else{
                 sprintf( &buff[index], "%c", '.' );
             }
             index = strlen(buff);
        }
    }
    sprintf( &buff[index], "%s", "\r\n" );
    printk("%s", buff);       
    return retval;
}

Configuration file: wifi.conf nl80211: Supported cipher 00-0f-ac:1 nl80211: Supported cipher 00-0f-ac:5 nl80211: Supported cipher 00-0f-ac:2 nl80211: Supported cipher 00-0f-ac:4 nl80211: Supported cipher 00-0f-ac:6 nl80211: Supported cipher 00-0f-ac:8 nl80211: Supported cipher 00-0f-ac:9 nl80211: Supported cipher 00-0f-ac:10 nl80211: Supported cipher 00-0f-ac:11 nl80211: Supported cipher 00-0f-ac:12 nl80211: Supported cipher 00-0f-ac:13 nl80211: Supported vendor command: vendor_id=0x1a11 subcmd=4106 nl80211: Supported vendor command: vendor_id=0x1a11 subcmd=4107 nl80211: Use separate P2P group interface (driver advertised support) nl80211: key_mgmt=0xf0f enc=0xfef auth=0x7 flags=0x8000009a407ac0 rrm_flags=0x0 probe_resp_offloads=0x0 max_station9 nl80211: interface wlan0 in phy phy0 nl80211: Set mode ifindex 5 iftype 3 (AP) nl80211: Setup AP(wlan0) - device_ap_sme=1 use_monitor=0 nl80211: Subscribe to mgmt frames with AP handle 0xb6ba5ed0 (device SME) nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=04 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=1): 04 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=0501 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 05 01 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=0503 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 05 03 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=0504 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 05 04 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=06 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=1): 06 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=08 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=1): 08 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=09 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=1): 09 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=0a multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=1): 0a nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=11 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=1): 11 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0xb6ba5ed0 match=7f multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=1): 7f nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it nl80211: Enable Probe Request reporting nl_preq=0xb6ba5ed0 nl80211: Register frame type=0x40 (WLAN_FC_STYPE_PROBE_REQ) nl_handle=0xb6ba5ed0 match= multicast=0 nl80211: Register frame command failed (type=64): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=0): [NULL] nl80211: Failed to enable Probe Request frame reporting in AP mode rfkill: initial event: idx=1 type=1 op=0 soft=0 hard=0 nl80211: Add own interface ifindex 5 (ifidx_reason -1) nl80211: if_indices[16]: 5(-1) phy: phy0 BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits) nl80211: Regulatory information - country=99 nl80211: 5170-5250 @ 80 MHz 20 mBm nl80211: 5735-5835 @ 80 MHz 20 mBm nl80211: Added 802.11b mode based on 802.11g information nl80211: Mode IEEE 802.11g: 2412[DISABLED] 2417[DISABLED] 2422[DISABLED] 2427[DISABLED] 2432[DISABLED] 2437[DISABLE] nl80211: Mode IEEE 802.11a: 5180 5200 5220 5240 5260[DISABLED] 5280[DISABLED] 5300[DISABLED] 5320[DISABLED] 5500[DI] nl80211: Mode IEEE 802.11b: 2412[DISABLED] 2417[DISABLED] 2422[DISABLED] 2427[DISABLED] 2432[DISABLED] 2437[DISABLE] Completing interface initialization Mode: IEEE 802.11a Channel: 36 Frequency: 5180 MHz DFS 0 channels required radar detection nl80211: Set freq 5180 (ht_enabled=0, vht_enabled=0, he_enabled=0, bandwidth=20 MHz, cf1=5180 MHz, cf2=0 MHz) * freq=5180 * he_enabled=0 * vht_enabled=0 * ht_enabled=0 * channel_type=0 nl80211: Failed to set channel (freq=5180): -16 (Resource busy) Could not set channel for kernel driver Interface initialization failed wlan0: interface state UNINITIALIZED->DISABLED wlan0: AP-DISABLED wlan0: Unable to setup interface. hostapd_interface_deinit_free(0xb6c4c950) hostapd_interface_deinit_free: num_bss=1 conf->num_bss=1 hostapd_interface_deinit(0xb6c4c950) wlan0: interface state DISABLED->DISABLED hostapd_bss_deinit: deinit bss wlan0 wlan0: Deauthenticate all stations nl80211: sta_remove -> DEL_STATION wlan0 ff:ff:ff:ff:ff:ff --> -22 (Invalid argument) wlan0: AP-DISABLED hostapd_cleanup(hapd=0xb6ba5510 (wlan0)) wlan0: CTRL-EVENT-TERMINATING hostapd_free_hapd_data: Interface wlan0 wasn't started hostapd_interface_deinit_free: driver=0xbb5b4 drv_priv=0xb6c4cf80 -> hapd_deinit nl80211: deinit ifname=wlan0 disabled_11b_rates=0 nl80211: Remove monitor interface: refcount=0 nl80211: Remove beacon (ifindex=5) netlink: Operstate: ifindex=5 linkmode=0 (kernel-control), operstate=6 (IF_OPER_UP) hostapd_interface_free(0xb6c4c950) hostapd_interface_free: free hapd 0xb6ba5510 hostapd_cleanup_iface(0xb6c4c950) hostapd_cleanup_iface_partial(0xb6c4c950) hostapd_cleanup_iface: free iface=0xb6c4c950
05-30
# wpa_supplicant -d -i wlan0 -c /tmp/wifi.conf wpa_supplicant v2.10 random: Trying to read entropy from /dev/random Successfully initialized wpa_supplicant Initializing interface 'wlan0' conf '/tmp/wifi.conf' driver 'default' ctrl_interface 'N/A' bridge 'N/A' Configuration file '/tmp/wifi.conf' -> '/tmp/wifi.conf' Reading configuration file '/tmp/wifi.conf' nl80211: Supported cipher 00-0f-ac:1 nl80211: Supported cipher 00-0f-ac:5 nl80211: Supported cipher 00-0f-ac:2 nl80211: Supported cipher 00-0f-ac:4 nl80211: Supported cipher 00-0f-ac:6 nl80211: Using driver-based off-channel TX nl80211: key_mgmt=0xd0f enc=0x10f auth=0x7 flags=0x800d0c0 rrm_flags=0x0 probe_resp_offloads=0x0 max_stations=0 max_remain_on_chan=5000 max_scan_ssids=9 nl80211: interface wlan0 in phy phy0 nl80211: Set mode ifindex 2 iftype 2 (STATION) nl80211: Subscribe to mgmt frames with non-AP handle 0x56ce68 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=0801 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 08 01 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=06 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=1): 06 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=0a07 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 0a 07 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=0a11 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 0a 11 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=1101 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 11 01 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=1102 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 11 02 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=0505 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 05 05 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=0500 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 05 00 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=1301 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 13 01 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=1305 multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=2): 13 05 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x56ce68 match=7e506f9a1a multicast=0 nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress) nl80211: Register frame match - hexdump(len=5): 7e 50 6f 9a 1a nl80211: Failed to register Action frame processing - ignore for now rfkill: initial event: idx=0 type=1 op=0 soft=0 hard=0 netlink: Operstate: ifindex=2 linkmode=1 (userspace-control), operstate=5 (IF_OPER_DORMANT) Add interface wlan0 to a new radio phy0 nl80211: Regulatory information - country=00 nl80211: 2402-2472 @ 40 MHz 20 mBm nl80211: 2457-2482 @ 20 MHz 20 mBm (no IR) nl80211: 2474-2494 @ 20 MHz 20 mBm (no OFDM) (no IR) nl80211: 5170-5250 @ 80 MHz 20 mBm (no IR) nl80211: 5250-5330 @ 80 MHz 20 mBm (DFS) (no IR) nl80211: 5490-5730 @ 160 MHz 20 mBm (DFS) (no IR) nl80211: 5735-5835 @ 80 MHz 20 mBm (no IR) nl80211: 57240-63720 @ 2160 MHz 0 mBm nl80211: Added 802.11b mode based on 802.11g information nl80211: Mode IEEE 802.11g: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467[NO_IR] 2472[NO_IR] 2484[DISABLED] nl80211: Mode IEEE 802.11b: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467[NO_IR] 2472[NO_IR] 2484[DISABLED] wlan0: Own MAC address: cc:b8:5e:f5:a6:86 wpa_driver_nl80211_set_key: ifindex=2 (wlan0) alg=0 addr=(nil) key_idx=0 set_tx=0 seq_len=0 key_len=0 key_flag=0x10 nl80211: DEL_KEY broadcast key wpa_driver_nl80211_set_key: ifindex=2 (wlan0) alg=0 addr=(nil) key_idx=1 set_tx=0 seq_len=0 key_len=0 key_flag=0x10 nl80211: DEL_KEY broadcast key wpa_driver_nl80211_set_key: ifindex=2 (wlan0) alg=0 addr=(nil) key_idx=2 set_tx=0 seq_len=0 key_len=0 key_flag=0x10 nl80211: DEL_KEY broadcast key wpa_driver_nl80211_set_key: ifindex=2 (wlan0) alg=0 addr=(nil) key_idx=3 set_tx=0 seq_len=0 key_len=0 key_flag=0x10 nl80211: DEL_KEY broadcast key
06-06
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值