test.c

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h> void dump_line(const unsigned char* buf, int w, int l)
{
#define YYYGET(X) ( X >= 32 && X <= 126) ? X : '.'
unsigned int i = 0;
printf("%08x: ", l);
for (; i < w; ++i)
printf((i % 8 == 7) ? "%02x " : "%02x ", *(buf+i));
if (w < 0x10)
{
for (i = 0; i < 0x10 - w; ++i) printf(" ");
printf(" ");
}
printf ("|");
for (i = 0; i < w; ++i)
printf ("%c", YYYGET(*(buf+i)));
if (w < 0x10)
for (i = 0; i < 0x10 - w; ++i) printf(" ");
printf ("|\n");
#undef YYYGET
} void dump_buffer(const unsigned char* buf, int max)
{
int l = max / 0x10 + ((max % 0x10) ? 1 : 0);
printf ("l = %d\n",l);
int i = 0;
int w = l - i > 1 ? 0x10 : max;
const unsigned char* ptr = buf;
for (; i < l; ++i,w = l - i > 1 ? 0x10 : max - 0x10 * i)
{
dump_line(ptr, w, i);
ptr += w;
}
} int main(int argc, char *argv[])
{
if (argc < 3)
{
printf ("Usage: %s FileName, number.\n", argv[0]);
exit(1);
} int fd = open(argv[1], O_RDONLY);
if (fd != -1)
{
int s = atoi(argv[2]);
unsigned char* buf = malloc(s+1);
memset(buf, 0, s+1);
read(fd, buf, s);
dump_buffer(buf, s);
}
return 0;
}

随机推荐

  1. supervisor 添加新配置不生效的问题

    supervisorctl reread supervisorctl reload (不运行这一步会导致启动不了) supervisorctl start xxx:* 提示:No config upd ...

  2. 模拟退火算法 R语言

    0 引言 模拟退火算法是用来解决TSP问题被提出的,用于组合优化. 1 原理 一种通用的概率算法,用来在一个打的搜索空间内寻找命题的最优解.它的原理就是通过迭代更新当前值来得到最优解.模拟退火通常使用 ...

  3. R画图

    画图函数中的参数: 1.图形元素参数: pch:用于显示点的坐标,可以是一个字符,也可以是0到25的一个整数.如:pch=“+”,pch=1 lty:线条类型.如:lty=2,lty=1 lwd:线条 ...

  4. linux操作系统位数

    方法1:getconf LONG_BIT 查看 如下例子所示: 32位Linux系统显示32, 64位Linux系统显示64.最简单.快捷的方法. [root@DB-Server ~]# getcon ...

  5. docker的优势

    基于微服务的架构已经成为一种流行趋势.而Docker则给微服务的蓬勃发展注入了更强的活力. docker的吸引能力主要来自两方面:快速和可移植. 1.快速 普通的虚拟机每次都需要启动一个完整的操作系统 ...

  6. 深入浅出CSS(三):隐藏BOSS大盘点之默认属性小总结

    写在前面 严重警告,本文包含大量文字,且无配图,请做好充分心理准备后,再进行阅读! 严重警告,本文包含大量文字,且无配图,请做好充分心理准备后,再进行阅读! 严重警告,本文包含大量文字,且无配图,请做 ...

  7. 3.Filter和interceptor的区别

    https://blog.csdn.net/qq_36411874/article/details/53996873

  8. [JSOI2007]字符加密Cipher

    bzoj 1031:[JSOI2007]字符加密Cipher Time Limit: 10 Sec  Memory Limit: 162 MB Description 喜欢钻研问题的JS同学,最近又迷 ...

  9. shell的父子进程

    2017年1月11日, 星期三 shell的父子进程   启动/执行方式: 当前shell:               #!/bin/bash 必须行首                        ...

  10. [转载]学习C语言基本思路与参考书籍

    http://zhuanlan.zhihu.com/linjr/19694823 计算机行业发展非常快,大学里的教育基本都跟不上实际的社会需求.如果你所在的学校还在指定大家使用谭浩强的教材,或使用VC ...