none.gif

夜神鸦羽

GF  2019-01-04 14:41

重金求个大佬程序员来教我作业,计算机系统基础的ELF加载监控

没办法了,病急乱投医,到处都问问
链接:[https://pan.baidu.com/s/11e3gKbne9qVEbniw_4IMzw]
提取码:pypp
课程代码和题目如度盘链接内所示所示

但是我直接就卡在第一步的make做不下去了
有没大佬来教下我的啊啊啊啊
此帖悬赏结束
最佳答案: 1000 SP币
最佳答案获得者: 074f8cf5

977176.png

ras

B1F  2019-01-04 18:33
(RUA)
makefile就编译了main.c和hello.c,你看看elf文件就会了
最佳答案奖励: (+1000) SP币

378177.jpg

思弹音

B2F  2019-01-04 15:03
有那本事的人跑着来无聊~!你也不想想~!
热心助人奖励: (+1) SP币

none.gif

traum

B3F  2019-01-04 16:46
尝试去csdn发贴问问啊,愿意花钱,淘宝更快
热心助人奖励: (+1) SP币

none.gif

任白

B4F  2019-01-04 17:06
楼主是真的秀
热心助人奖励: (+1) SP币

1047139.jpg

John

B5F  2019-01-04 18:16
(R-18G爱好者请和我联系~萌新求带~)
没办法,非码农专业
热心助人奖励: (+1) SP币

376472.jpg

残香覆睫

B6F  2019-01-04 18:39
(落花流水虽有意,白云出岫本无心)

回 5楼(ras) 的帖子

elf文件是你头像的那种文件吗(手动滑稽
热心助人奖励: (+1) SP币

811636.png

shion

B7F  2019-01-04 19:32
(help!)
看不懂 精神支持
热心助人奖励: (+1) SP币

none.gif

夜神鸦羽

B8F  2019-01-04 19:05

回 5楼(ras) 的帖子

第一个问题我靠自己解决了,现在要补充一个LOAD()类让他能够扫描程序头表,装载各装载段到虚拟内存这个我是真的做不来啊……
void loader(char *filename)

{

    FILE *fp = fopen(filename, "r");

  assert(fp != NULL);



  Elf32_Ehdr *elf;

  Elf32_Phdr *ph = NULL, *eph;



  uint8_t buf[4096];

  int ret = fread(buf, 4096, 1, fp);

  assert(ret == 1);

  

none.gif

夜神鸦羽

B9F  2019-01-04 19:08
void init_address_space(void) {

  void *ret = mmap((void *)AS_START, AS_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE,

      MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);

  assert(ret != MAP_FAILED);



  uint32_t *p = ret;

  int i;

  for (i = 0; i < AS_SIZE / sizeof(uint32_t); i ++) {

    p = rand();

  }

}

void segv_handler(int signum, siginfo_t *siginfo, void *ucontext) {

  printf("catch SIGSEGV\n");



  // get ebp and eip from the context

  int *regs = ((ucontext_t *)ucontext)->uc_mcontext.gregs;

  uint32_t ebp = regs[REG_EBP];

  uint32_t eip = regs[REG_EIP];



  printf("ebp = %x, eip = %x\n", ebp, eip);



  bt(ebp, eip);



  exit(0);

}

void load_elf_tables(char *filename) {

    int ret;



    FILE *fp = fopen(filename, "rb");

    assert(fp != NULL);



    uint8_t buf[sizeof(Elf32_Ehdr)];

    ret = fread(buf, sizeof(Elf32_Ehdr), 1, fp);

    assert(ret == 1);



    // the first several bytes contain the ELF header

    Elf32_Ehdr *elf = (void *)buf;

    char magic[] = {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3};



    // check ELF header

    assert(memcmp(elf->e_ident, magic, 4) == 0);        // magic number

    assert(elf->e_ident[EI_CLASS] == ELFCLASS32);        // 32-bit architecture

    assert(elf->e_ident[EI_DATA] == ELFDATA2LSB);        // littel-endian

    assert(elf->e_ident[EI_VERSION] == EV_CURRENT);        // current version

    assert(elf->e_ident[EI_OSABI] == ELFOSABI_SYSV ||     // UNIX System V ABI

            elf->e_ident[EI_OSABI] == ELFOSABI_LINUX);     // UNIX - GNU

    assert(elf->e_ident[EI_ABIVERSION] == 0);            // should be 0

    assert(elf->e_type == ET_EXEC);                        // executable file

    assert(elf->e_machine == EM_386);                    // Intel 80386 architecture

    assert(elf->e_version == EV_CURRENT);                // current version



    // load section header table

    uint32_t sh_size = elf->e_shentsize * elf->e_shnum;

    Elf32_Shdr *sh = malloc(sh_size);

    fseek(fp, elf->e_shoff, SEEK_SET);

    ret = fread(sh, sh_size, 1, fp);

    assert(ret == 1);



    // load section header string table

    char *shstrtab = malloc(sh[elf->e_shstrndx].sh_size);

    fseek(fp, sh[elf->e_shstrndx].sh_offset, SEEK_SET);

    ret = fread(shstrtab, sh[elf->e_shstrndx].sh_size, 1, fp);

    assert(ret == 1);



    int i;

    for(i = 0; i < elf->e_shnum; i ++) {

        if(sh.sh_type == SHT_SYMTAB &&

                strcmp(shstrtab + sh.sh_name, ".symtab") == 0) {

            // load symbol table

            symtab = malloc(sh.sh_size);

            fseek(fp, sh.sh_offset, SEEK_SET);

            ret = fread(symtab, sh.sh_size, 1, fp);

            assert(ret == 1);

            nr_symtab_entry = sh.sh_size / sizeof(symtab[0]);

        }

        else if(sh.sh_type == SHT_STRTAB &&

                strcmp(shstrtab + sh.sh_name, ".strtab") == 0) {

            // load string table

            strtab = malloc(sh.sh_size);

            fseek(fp, sh.sh_offset, SEEK_SET);

            ret = fread(strtab, sh.sh_size, 1, fp);

            assert(ret == 1);

        }

    }



    free(sh);

    free(shstrtab);



    assert(strtab != NULL && symtab != NULL);



    fclose(fp);

}

none.gif

夜神鸦羽

B10F  2019-01-04 19:08
const char* find_fun_name(uint32_t eip) {

  static const char not_found[] = "???";



  int i;

  for(i = 0; i < nr_symtab_entry; i ++) {

    if(ELF32_ST_TYPE(symtab.st_info) == STT_FUNC &&

        eip >= symtab.st_value && eip < symtab.st_value + symtab.st_size) {

      return strtab + symtab.st_name;

    }

  }



  return not_found;

}

none.gif

夜神鸦羽

B11F  2019-01-04 19:08
题目给出的参考代码

none.gif

夜神鸦羽

B12F  2019-01-12 11:40
反正截止日期早过了,随便找个人最佳算了

977176.png

ras

B13F  2019-01-12 17:26
(RUA)
那天随便回了一句就准备期末考试去了,后来就忘了。。。