elf

Packing a file into an ELF executable

别说谁变了你拦得住时间么 提交于 2019-12-07 01:34:09
问题 I'm currently looking for a way to add data to an already compiled ELF executable, i.e. embedding a file into the executable without recompiling it. I could easily do that by using cat myexe mydata > myexe_with_mydata , but I couldn't access the data from the executable because I don't know the size of the original executable. Does anyone have an idea of how I could implement this ? I thought of adding a section to the executable or using a special marker ( 0xBADBEEFC0FFEE for example) to

Example of executable stack in Linux (i386 architecture)

╄→尐↘猪︶ㄣ 提交于 2019-12-07 00:52:00
问题 I found that when we use nested functions, GCC requires an executable stack for trampoline code. However, following code, when compiled using gcc doesn't show an executable stack. (I used execstack to verify if the stack is executable) #include <stdio.h> #include <unistd.h> int main() { int add( int a, int b) { return a + b; } return add(2, 3); } Why does this not result in a executable stack? And if it is not supposed to, then can someone give example of a code construct that does give an

Can a running C program access its own symbol table?

拟墨画扇 提交于 2019-12-06 19:03:19
问题 I have a linux C program that handles request sent to a TCP socket (bound to a particular port). I want to be able to query the internal state of the C program via a request to that port, but I dont want to hard code what global variables can be queried. Thus I want the query to contain the string name of a global and the C code to look that string up in the symbol table to find its address and then send its value back over the TCP socket. Of course the symbol table must not have been

bad ELF interpreter: No such file or directory

浪子不回头ぞ 提交于 2019-12-06 17:35:29
1、在64 系统 里执行32位程序如果出现/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory,安装下glic即可 yum install glibc.i686 2、error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory yum install zlib.i686 来源: https://www.cnblogs.com/qianzf/p/11996606.html

How are variables in shared libraries referenced by loader?

梦想与她 提交于 2019-12-06 13:21:58
I now understand how dynamic functions are referenced, by procedure linkage table like below: Dump of assembler code for function foo@plt: 0x0000000000400528 <foo@plt+0>: jmpq *0x2004d2(%rip) # 0x600a00 <_GLOBAL_OFFSET_TABLE_+40> 0x000000000040052e <foo@plt+6>: pushq $0x2 0x0000000000400533 <foo@plt+11>: jmpq 0x4004f8 (gdb) disas 0x4004f8 No function contains specified address. But I don't know how dynamic variables are referenced,though I found the values are populated in the GOT once started,but there's no stub like above,how does it work? The dynamic loader relocates all references to

How can I get the symbol name in struct “Elf64_Rela”

為{幸葍}努か 提交于 2019-12-06 12:11:55
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/mman.h> #include <errno.h> #include <fcntl.h> #include <elf.h> Elf64_Rela *retab; Elf64_Rela *retab_end; Elf64_Ehdr *ehdr; Elf64_Shdr *shdr; char *strtab; void elf_open(char *filename) { int fd = open(filename, O_RDONLY); struct stat sbuf; fstat(fd, &sbuf); void *maddr = mmap(NULL, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); close(fd); ehdr = maddr; shdr = (Elf64_Shdr *)(maddr + ehdr->e_shoff); for (int i = 0; i < ehdr->e_shnum; i++) { if (shdr[i].sh_type =

Can I combine all the sections “Objdump -S -d elf-file” generate into a re-assemble capable file?

烂漫一生 提交于 2019-12-06 10:59:35
问题 THe elf file is static linked and currently the objdump's output is something like: Disassembly of section: .init: xxxxxx Disassembly of section: .plt: xxxxxx Disassembly of section: .text: xxxxxx basically what I want to achieve is "elf-file -(disassemble by objdump)-> assemble file --(re-compile)--> same functionality " I don't need the re-compiled binary has the binary content same as the original one, only same functionality is enough. After a quick search, basically the answer is no ,

Reading ELF String Table on Linux from C

时光总嘲笑我的痴心妄想 提交于 2019-12-06 09:37:50
I want to write a program which reads the string table of a binary. Binary is in ELF running on REDHAT linux 32. I did the following - Read the Elf Header Read all the sections Below is the output of my progam. Entry Address of Binary - 0x8048340 Start of Program Header - 52 Start of section header - 3272 Size of header - 52 Number of section headers - 36 Size of each section headers - 40 Number of section headers - 36 Section header Offset - 3272 string tbl index for section[0] is 0 string tbl index for section[1] is 27 string tbl index for section[7] is 35 string tbl index for section

How does linker find shared library without SONAME

我的梦境 提交于 2019-12-06 06:04:56
问题 if I create a shared library without a SONAME like this gcc -shared libfoo.o -o libfoo.so and link against it, how does the linker find my shared library? Is the filename libfoo.so considered as default SONAME by the linker? 回答1: I think you're right. Here what ld man pages say: -soname=name When creating an ELF shared object, set the internal DT_SONAME field to the specified name. When an executable is linked with a shared object which has a DT_SONAME field, then when the executable is run

program loading/execution

孤者浪人 提交于 2019-12-06 05:54:32
问题 I'm a beginner in compilers but I'm very interested in learning about how a program is structured (the binary) and how it is read and loaded in memory for execution. What ebooks/books/tutorials do you guys suggest me reading for a quick start? 回答1: Compilers and executable binaries are remotely related. (the actual executable is built by the linker ld , not the compiler). On Linux systems, the linux kernel use copy-on-write and demand-paging techniques to lazily load the program pages, for