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方面的资料,虽然很少,但是总比没有强,不过在实际的使用过程中还是会碰到许多稀奇古怪的问题.整理整理我的使用过程,就当做一篇笔记吧 ...
随机推荐
- CSS 垂直居中。
1,display: table; display: table-cell <div style="border:solid red 1px ;height:200px;width:2 ...
- 使用OTT处理oracle中的对象(一) OTT配置
OTT是OCI中访问对象类型数据的重要工具,它将数据库中的对象数据类型或集合类型映射为C++中的结构体类型.OTT是Oracle自带的,但是使用前必须配置一下环境变量.在计算机->属性-> ...
- SharePoint安全 - 在Goolge和Bing中查找SharePoint相关内容
博客地址 http://blog.csdn.net/foxdave 本篇提供两个查询串字典,分别对应Google和Bing的搜索,用来查询SharePoint网站的相关内容 Google ShareP ...
- 登陆sqlserver及修改端口号 (转)
在一台计算机上面同时安装两个sql server数据库实例,第一次安装默认为机器名,端口号为1433 1.如果不知道服务器名,却想登陆的话可以直接输入127.0.0.1登陆之后,在新建查询中输入:SE ...
- JDK的下载与安装
一.下载 在Oracle公司的官方网站(www.oracle.com)下载. 二.安装 1.双击运行JDK程序,弹出JDK安装导向窗口,点击“下一步” 2.点击“更改",将安装地址修改为 C ...
- Event Handling on Mac
Keyboard/Mouse Event + Cocoa AppleEvent + Cocoa AppleEvent + CommandLine App(w/o UI) + CoreFoundatio ...
- stm32 dac库函数解读
1.简述: 12位数字输入,电压输出,DAC可以配置为8位或12位模式.有2个输出通道.在双DAC模式下,两个通道可以独立地工作. 特殊功能: 噪声波形生成,三角波形生成,外部触发转换,双DAC同时或 ...
- kali linux SET工具包
尝试使用SET生成Teensy脚本是出现问题 1.出现错误 [!] Something went wrong, printing the error: [Errno 2] No such file o ...
- Office word excel电子表格在线编辑的实现方法
Office xp之后的版本支持通过webdav协议(http的扩展)直接编辑服务器上的文件. IIS(6.0)支持webdav,这在IIS管理器的web服务扩展中可以看到.利用IIS作为webdav ...
- Python 3.x print 小结
Python 思想: “一切都是对象!” input("Press Enter") 就可以让程序运行完后停一下 输出的 print 函数总结: 1. 字符串和数值类型可以直接输出 ...