hexdump in kernel mode

  

  
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;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值