⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sect.c

📁 一款类linux的操作系统源码
💻 C
字号:
/* *  Roadrunner/pk *    Copyright (C) 1989-2001  Cornfed Systems, Inc. * *  The Roadrunner/pk operating system is free software; you can *  redistribute and/or modify it under the terms of the GNU General *  Public License, version 2, as published by the Free Software *  Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public *  License along with this program; if not, write to the Free *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, *  MA 02111-1307 USA * *  More information about the Roadrunner/pk operating system of *  which this file is a part is available on the World-Wide Web *  at: http://www.cornfed.com. * */#include <stdio.h>#include <string.h>#include <sys.h>#include <sys/load.h>#include <sys/mem.h>static intfind_section(sections_t s, char *section,int count){    Elf32_Ehdr *ehdr = s->ehdr;    Elf32_Shdr *shdrtab = s->shdrtab;    char *shstrtab = s->shstrtab;    int i,j;    j = 0;    for (i = 0; i < ehdr->e_shnum; i++){ 	    if (strcmp(shstrtab + shdrtab[i].sh_name, section) == 0){ 	       j++; 	       if(j == count)return i;	    }	}        if (i == ehdr->e_shnum)	return (-1);}intinit_sections(char *filebuf, sections_t s){    int i, ndx;    bzero(s, sizeof(struct sections));    s->ehdr = (Elf32_Ehdr *) filebuf;    s->shdrtab = (Elf32_Shdr *) (filebuf + s->ehdr->e_shoff);    s->shstrtab = filebuf + s->shdrtab[s->ehdr->e_shstrndx].sh_offset;#if _DEBUG    dump_ehdr(s);#endif    /* Symbol table */    ndx = find_section(s, SYMTAB,1);    s->symtab = (Elf32_Sym *) (filebuf + s->shdrtab[ndx].sh_offset);    s->symtabentries = s->shdrtab[ndx].sh_size / s->shdrtab[ndx].sh_entsize;    /* String table */    ndx = find_section(s, STRTAB,1);    s->strtab = filebuf + s->shdrtab[ndx].sh_offset;    /*     * XXX Assume there is at most one occurence of each of the following     * sections     */        s->textndx = find_section(s, TEXT,1);    s->datandx1 = find_section(s, DATA,1);    s->datandx2 = find_section(s, DATA,2);    s->datandx3 = find_section(s, DATA,3);    s->datandx4 = find_section(s, DATA,4);    return 0;}intload_sections(sections_t s, char *filebuf, char *prog){    Elf32_Shdr *shdrtab = s->shdrtab;    u_long offset;    s->textoff = (u_long) prog;#if _DEBUG    kprintf("load_sections: .text   %08x", s->textoff);#endif    bcopy(filebuf + shdrtab[s->textndx].sh_offset,	  (char *) s->textoff, shdrtab[s->textndx].sh_size);    offset = s->textoff + shdrtab[s->textndx].sh_size;    if (s->datandx1 >= 0) {	s->dataoff1 = offset;#if _DEBUG	kprintf(".data   %08x", s->dataoff1);#endif	bcopy(filebuf + shdrtab[s->datandx1].sh_offset,	      (char *) s->dataoff1, shdrtab[s->datandx1].sh_size);	offset += shdrtab[s->datandx1].sh_size;    }    if (s->datandx2 >= 0) {	s->dataoff1 = offset;#if _DEBUG	kprintf(".data   %08x", s->dataoff1);#endif	bcopy(filebuf + shdrtab[s->datandx2].sh_offset,	      (char *) s->dataoff1, shdrtab[s->datandx2].sh_size);	offset += shdrtab[s->datandx2].sh_size;    }    if (s->datandx3 >= 0) {	s->dataoff1 = offset;#if _DEBUG	kprintf(".data   %08x", s->dataoff1);#endif	bcopy(filebuf + shdrtab[s->datandx3].sh_offset,	      (char *) s->dataoff1, shdrtab[s->datandx3].sh_size);	offset += shdrtab[s->datandx3].sh_size;    }#if _DEBUG    //kprintf("\n");#endif    return 0;}

⌨️ 快捷键说明

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