builder.c

来自「别人的根据linux0.11改的一个小的操作系统」· C语言 代码 · 共 42 行

C
42
字号
/* * Builder.c * * Author : Ming Pengli * Date : * * Description: This routine build the biniary system image file . *              At here ,we knew the start address at 0x1000,so we  *              directly locate the position that we will read.  */#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <io.h>#include <unistd.h>int main(int argc,char **argv){	FILE *in,*out;	char ch;	if(argc!=3){		printf("Usage:builder src_file dest_file");		return 0;	}	if((in=fopen(argv[1],"rb"))==NULL){                /* Open the .exe file as read and biniary. */		printf("open input file error...\n");		return 0;	}	fseek(in,0x1000,SEEK_SET);                         /* The _TEXT segment start at 0x1000 */	if((out=fopen(argv[2],"wb"))==NULL){               /* Create a new .bin file */		printf("open output file error...\n");		return 0;	}	while(!feof(in)){                                  /* Read from .exe file,and write into .bin file */		ch=getc(in);		putc(ch,out);	}	fclose(in);	fclose(out);	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?