Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First you need to read the ELF specification and then read the function elf_core_dump() in the linux/fs/binfmt_elf.c to get to know how the coredump file is organised. But anyway, you can check the following program.</p> <pre><code> #include &lt;stdio.h&gt; #include &lt;elf.h&gt; #include &lt;sys/types.h&gt; #include &lt;unistd.h&gt; #include &lt;fcntl.h&gt; #include &lt;stdlib.h&gt; #include &lt;sys/procfs.h&gt; int main (int argc, char **arg) { Elf32_Ehdr *elfh; Elf32_Shdr *elfsh; Elf32_Phdr *elfphdr; char *p = NULL; char buf[1000], sbuf[1000]; int ret, fd, i = 0, size; if (argc &lt; 2) { printf("\nUsage: corenotes &lt;core&gt;\n"); return 0; } fd = open(arg[1], O_RDONLY); if (fd &lt; 0) { perror("open"); return 0; } /* Read ELF header*/ ret = read(fd, buf, sizeof(*elfh)); if (!ret) { perror("Error Reading the ELF Header"); goto cl; } elfh = (Elf32_Ehdr *) buf; /* Is it ELF*/ if ((elfh-&gt;e_ident[0] != 0x7f) || (elfh-&gt;e_ident[1] != 'E') || (elfh-&gt;e_ident[2] != 'L') || (elfh-&gt;e_ident[3] != 'F')) { printf("\nUnrecongised File Format"); goto cl; } /* * read program headers and print */ size = elfh-&gt;e_phnum * elfh-&gt;e_phentsize; p = malloc(size); lseek(fd, elfh-&gt;e_phoff, SEEK_SET); ret = read(fd, p, size); if (ret != size) { printf("\nCannot read Program Header"); goto cl; } elfphdr = (Elf32_Phdr *)p; for (i = 0; i &lt; elfh-&gt;e_phnum; i++) { if (elfphdr-&gt;p_type == PT_NOTE) { unsigned char *pdata; struct note { unsigned int namesz; unsigned int descsz; unsigned int type; }; struct note *not; int pad; pdata = malloc(elfphdr-&gt;p_filesz); lseek(fd, elfphdr-&gt;p_offset, SEEK_SET); ret = read(fd, pdata, elfphdr-&gt;p_filesz); not = (struct note *) pdata; printf("\n%s", pdata + sizeof (*not)); pad = 4 - (not-&gt;namesz % 4); if (not-&gt;type == NT_PRSTATUS) { struct elf_prstatus *prs; prs = (struct elf_prstatus *)(pdata + sizeof(*not) + not-&gt;namesz + pad); printf("\nProgram Received %d", prs-&gt;pr_cursig); printf("\nPending Signals %08x", prs-&gt;pr_sigpend); printf("\nHold Signals %08x", prs-&gt;pr_sighold); printf("\nPID of the process %d", prs-&gt;pr_pid); printf("\nPPID of the process %d", prs-&gt;pr_ppid); printf("\nEBX: %08x", prs-&gt;pr_reg[0]); printf("\nECX: %08x", prs-&gt;pr_reg[1]); printf("\nEDX: %08x", prs-&gt;pr_reg[2]); printf("\nESI: %08x", prs-&gt;pr_reg[3]); printf("\nEDI: %08x", prs-&gt;pr_reg[4]); printf("\nEBP: %08x", prs-&gt;pr_reg[5]); printf("\nEAX: %08x", prs-&gt;pr_reg[6]); printf("\nXDS: %08x", prs-&gt;pr_reg[7]); printf("\nXES: %08x", prs-&gt;pr_reg[8]); printf("\nXFS: %08x", prs-&gt;pr_reg[9]); printf("\nXGS: %08x", prs-&gt;pr_reg[10]); printf("\nORG_EAX: %08x", prs-&gt;pr_reg[11]); printf("\nEIP: %08x", prs-&gt;pr_reg[12]); printf("\nECS: %08x", prs-&gt;pr_reg[13]); printf("\nEFLAGS: %08x", prs-&gt;pr_reg[14]); printf("\nESP: %08x", prs-&gt;pr_reg[15]); printf("\nXSS: %08x", prs-&gt;pr_reg[16]); pdata = pdata + sizeof(*not) + not-&gt;namesz + pad + sizeof(struct elf_prstatus); } not = (struct note *)pdata; if (not-&gt;type == NT_PRPSINFO) { struct elf_prpsinfo *prs; printf("\n\nNT_PRPSINF\n"); pad = 4 - (not-&gt;namesz % 4); prs = (struct elf_prpsinfo *)(pdata + sizeof(*not) + not-&gt;namesz + pad); printf("\nName of the Exe %s", prs-&gt;pr_fname); } // free(pdata); } elfphdr++; } free(p); printf("\n\n"); cl: close(fd); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload