/*
 *    linux/zBoot/piggyback.c
 *
 *    (C) 1993 Hannu Savolainen
 */

/*
 *    This program reads the compressed system image from stdin and
 *    encapsulates it into an object file written to the stdout.
 */
//这个程序读取压缩的system映像文件从标准输入然后压缩后写入标准输出
#include <stdio.h>
#include <unistd.h>
#include <a.out.h>

//主函数
int main(int argc, char *argv[])
{
    int c, n=0, len=0;
    //定义缓冲区
    char tmp_buf[512*1024];
    
    //可执行文件头
    struct exec obj = {0x00640107};    /* object header */
    //输入的数据和输入的长度
    char string_names[] = {"_input_data\0_input_len\0"};

//标号表,变量名
    struct nlist var_names[2] = /* Symbol table */
        {    
            {    /* _input_data    */
                (char *)4, 7, 0, 0, 0
            },
            {    /* _input_len */
                (char *)16, 7, 0, 0, 0
            }
        };

len = 0;
    //从标准输入中读取数据到缓冲区
    while ((n = read(0, &tmp_buf[len], sizeof(tmp_buf)-len+1)) > 0)
          len += n;

//校验读取的长度
    if (n==-1)
    {
        perror("stdin");
        exit(-1);
    }

if (len >= sizeof(tmp_buf))
    {
        fprintf(stderr, "%s: Input too large\n", argv[0]);
        exit(-1);
    }

//输出长度信息
    fprintf(stderr, "Compressed size %d.\n", len);

/*
 *    Output object header
 */
    //输出对象头
    obj.a_data = len + sizeof(long);
    obj.a_syms = sizeof(var_names);
    write(1, (char *)&obj, sizeof(obj));

/*
 *    Output data segment (compressed system & len)
 */
    //输出数据段
    write(1, tmp_buf, len);
    write(1, (char *)&len, sizeof(len));

/*
 *    Output symbol table
 */
    //输出符号表
    var_names[1].n_value = len;
    write(1, (char *)&var_names, sizeof(var_names));

/*
 *    Output string table
 */
    //输出字符表
    len = sizeof(string_names) + sizeof(len);
    write(1, (char *)&len, sizeof(len));
    write(1, string_names, sizeof(string_names));

exit(0);

}

最新文章

  1. 【Java EE 学习 48】【Hibernate学习第五天】【抓取策略】【二级缓存】【HQL】
  2. a chip multiprocessor
  3. 使用PS过程
  4. SQL Server已提交读快照隔离级别的设置
  5. Number of Digit One
  6. AlwaysOn可用组基础知识
  7. 使用socket方式连接Nginx优化php-fpm性能
  8. NSPredicate谓词
  9. frame动画
  10. Java中的Enum的使用与分析
  11. 你真的了解javascript吗
  12. RR 和RC隔离问题
  13. WinDbg分析DUMP文件
  14. xml学习(1)xml的几种文件格式
  15. 让pip使用python3而不是python2
  16. JavaScript 函数闭包
  17. C#基础知识之字符串比较方法:“==”操作符;RefernceEquals;String.Equals方法;String.Compare方法;String.CompareOrdinal方法。
  18. 02:安装 Kerberos
  19. 完美解决windows+ngnix+phpcgi自动退出的问题
  20. Interview Common Sample Codes

热门文章

  1. subString用法,字符串保持一定位数,不足补0
  2. synergy配置 Ubuntu作Server, Win 7作client
  3. CSS基本特性
  4. [转] Linux内核代码风格 CodingStyle [CH]
  5. WordPress 4.0 “Benny” 正式发布
  6. node.js 学习书籍推荐
  7. ibatis 的 &quot;This SQL map does not contain a MappedStatement&quot;的错误
  8. CODEVS1073 家族 (并查集)
  9. C#使用Fixed创建固定大小的缓冲区
  10. MySQL 基本函数