zboot/xtract.c
/*
* linux/zBoot/xtract.c
*
* Copyright (C) 1993 Hannu Savolainen
*
* Extracts the system image and writes it to the stdout.
* based on tools/build.c by Linus Torvalds
*/
#include <stdio.h> /* fprintf */
#include <string.h>
#include <stdlib.h> /* contains exit */
#include <sys/types.h> /* unistd.h needs this */
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <unistd.h> /* contains read/write */
#include <fcntl.h>
#include <a.out.h>
#include <linux/config.h>
#define GCC_HEADER 1024
#define STRINGIFY(x) #x
//中断退出
void die(char * str)
{
fprintf(stderr,"%s\n",str);
exit(1);
}
//使用方法
void usage(void)
{
die("Usage: xtract system [ | gzip | piggyback > piggy.s]");
}
//主函数
int main(int argc, char ** argv)
{
int i,c,id, sz;
char buf[1024];
char major_root, minor_root;
struct stat sb;
//可执行文件指向缓冲区
struct exec *ex = (struct exec *)buf;
//参数一定是两个,否则提示使用方法
if (argc != 2)
usage();
//打开第二个参数指定的文件
if ((id=open(argv[1],O_RDONLY,0))<0)
die("Unable to open 'system'");
//读取GCC文件头
if (read(id,buf,GCC_HEADER) != GCC_HEADER)
die("Unable to read header of 'system'");
//校验
if (N_MAGIC(*ex) != ZMAGIC)
die("Non-GCC header of 'system'");
//计算系统长度
sz = N_SYMOFF(*ex) - GCC_HEADER + 4; /* +4 to get the same result than tools/build */
//输出系统长度
fprintf(stderr, "System size is %d\n", sz);
//遍历System文件
while (sz)
{
int l, n;
l = sz;
//如果剩余长度大于buff长度,那么取buff长度
if (l > sizeof(buf)) l = sizeof(buf);
//读取一定长度
if ((n=read(id, buf, l)) !=l)
{
if (n == -1)
perror(argv[1]);
else
fprintf(stderr, "Unexpected EOF\n");
die("Can't read system");
}
//将内容写入到标准输出中
write(1, buf, l);
sz -= l;
}
close(id);
return(0);
}
zboot/xtract.c的更多相关文章
- Linux1.0源代码编译过程
根据源代码包中的readme文件及http://chfj007.blog.163.com/blog/static/173145044201191195856806/?suggestedreading& ...
- zBoot/Makefile
#上层makefile调用执行make命令,执行的应该是第一个目标allHEAD = head.oSYSTEM = ../tools/zSystem#LD = gcc#TEST = -DTEST_DR ...
- zboot/piggyback.c
/* * linux/zBoot/piggyback.c * * (C) 1993 Hannu Savolainen */ /* * This program reads the c ...
- boot/setup.S
!! setup.S Copyright (C) 1991, 1992 Linus Torvalds!! setup.s is responsible for getting th ...
- 开源入侵检测系统OSSEC搭建之一:服务端安装
OSSEC是一款开源的多平台的入侵检测系统,可以运行于Windows, Linux, OpenBSD/FreeBSD, 以及 MacOS等操作系统中.主要功能有日志分析.完整性检查.rootkit检测 ...
- Ossec常用命令
启动并查看httpd服务 systemctl start httpd systemctl status httpd.service 启动并查看mysql服务 systemctl start maria ...
- OSSEC初探
OSSEC初探 概念: OSSEC是一款开源的基于主机的入侵检测系统(HIDS),它可以执行日志分析.完整性检验.windows注册表监控.隐匿性检测和实时告警.它可以运行在各种不同的操作系统上,包括 ...
- 全网最详细的最新稳定OSSEC搭建部署(ossec-server(CentOS7.X)和ossec-agent(CentOS7.X))(图文详解)
不多说,直接上干货! 前言 写在前面的话,网上能够找到一些关于ossec方面的资料,虽然很少,但是总比没有强,不过在实际的使用过程中还是会碰到许多稀奇古怪的问题.整理整理我的使用过程,就当做一篇笔记吧 ...
- 全网最详细的最新稳定OSSEC搭建部署(ossec-server(CentOS6.X)和ossec-agent(CentOS6.X))(图文详解)
不多说,直接上干货! 前言 写在前面的话,网上能够找到一些关于ossec方面的资料,虽然很少,但是总比没有强,不过在实际的使用过程中还是会碰到许多稀奇古怪的问题.整理整理我的使用过程,就当做一篇笔记吧 ...
随机推荐
- arm-linux-gcc-4.3.2安装步骤
安装交叉编译工具链: 1.首先以root用户登入 2.复制arm-linux-gcc-4.3.2.tgz到根目录下tmp文件夹里 3.解压命令tar xvzf arm-linux-gcc-4. ...
- 踏着前人的脚印学Hadoop——RPC源码
A simple RPC mechanism.A protocol is a Java interface. All parameters and return types must be one ...
- iOS多语言备选机制
近期伊书突然接到一些外国用户的投诉,说伊书界面变成了中文,但他们系统语言不是中文,是法文俄文日文等,伊书只支持中文跟英文,在不支持系统所用语言的时候,理应会自动选用英文,不知为什么会选成了中文,经过艰 ...
- NABCD分析
NABCD——今日事 N(Need):开创的成就系统可以在一定程度上督促用户坚持下来. A(Approach):做一个APP软件,是在android平台构建. B(Benefit):可以逐步改变用户的 ...
- python抓取性感尤物美女图
由于是只用标准库,装了python3运行本代码就能下载到多多的美女图... 写出代码前面部分的时候,我意识到自己的函数设计错了,强忍继续把代码写完. 测试发现速度一般,200K左右的下载速度,也没有很 ...
- lightoj1082 线段树
//Accepted 5596 KB 396 ms //线段树求区间最小值 #include <cstdio> #include <cstring> #include < ...
- 【转】FFMPEG 库移植到 VC 需要的步骤
原文:http://blog.csdn.net/leixiaohua1020/article/details/12747899 在VC下使用FFMPEG编译好的库,不仅仅是把.h,.lib,.dll拷 ...
- (转)innerHTML、innerText和outerHTML、outerText的区别
原文:http://walsh.iteye.com/blog/261966 innerHTML.innerText和outerHTML.outerText的区别 博客分类: CSS/ ...
- php大力力 [010节]PHP常量
2015-08-23 php大力力010. PHP常量 php大力力 [010节]PHP常量 设置 PHP 常量 如需设置常量,请使用 define() 函数 - 它使用三个参数: 首个参数定义常量的 ...
- Add a stylesheet link programmatically in ASP.NET
Here’s a code snippet used to programmatically insert a stylesheet link to an external CSS file: // ...