test.c
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;
}
随机推荐
- Razor:从aspx到cshtml常见错误及正确书写方法
http://blog.csdn.net/cheny_com/article/details/6298496 从aspx转到chshtml还是有很多要适应的地方的,本帖是个人学习笔记帖不断更新.每天开 ...
- 团体程序设计天梯赛-练习集 L1-031. 到底是不是太胖了
比较两个实型的数: 若两者相等,也许用a>/b会出错... 我又想到了codeforces有很多这样的坑... #include <stdio.h> #include <std ...
- lumen 使用 dingo API 在 phpunit 中 404 的解决方法, 以及鉴权问题
1. phpunit.xml 中添加 dingo 相关配置 <env name="API_STANDARDS_TREE" value="x"/> & ...
- shell参数代表什么,如何调试shell?
$0就是该bash文件名$?是上一指令的返回值$*所有位置参数的内容:就是调用调用本bash shell的参数.$@基本上与上面相同.只不过是“$*”返回的是一个字符串,字符串中存在多外空格.“$@” ...
- 题解【bzoj1503 [NOI2004]郁闷的出纳员】
Description 给出一个下限 \(m\) ,要求维护以下操作 插入一个数(如果小于下限就不加) 给每个数加上一个数 给每个数减去一个数,并且删除掉 \(< m\) 的所有数 求目前第 \ ...
- python 资产扫描01
本地建立的三个文件: Asset1.txt 用来保存扫描到的资产 Asset2.txt 用来导入给定的资产 Repeat.txt 保存重复的资产 程序的功能: 1.资产扫描,以 位置:资产 格式保存到 ...
- HDU 5928 DP 凸包graham
给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...
- 关于node的setTimeout的延时最大限制
node的setTimeout有最大值限制,最大值为2^31-1.一旦超过了最大值,其效果就跟延时值为0的情况一样,也就是马上执行.chrome测试并未发现该问题,解决方案如下,重写setTimeou ...
- 20155236 2016-2017-2 《Java程序设计》第四周学习总结
20155236 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 1.继承基本上就是避免多个类间重复定义共同行为. 继承的三个好处:减少代码冗余:维护变得简单 ...
- react页面间传递参数
react-router页面跳转,带请求参数 this.context.router.push({pathname:'/car_datail',state:{item:"hello" ...