N
N
Nikita Evdokimov2018-04-09 22:55:18
C++ / C#
Nikita Evdokimov, 2018-04-09 22:55:18

How to read specific bytes from a file using C language?

I have the name of an executable file in the ELF format. I need to read from the header the address of the entry point, which, according to wikipedia, is stored from 24 to 28 bytes. If the task itself is interesting, here is https://stepik.org/lesson/44344/step/13?unit=22153.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SagePtr, 2018-04-09
@nikitae57

These functions will help: fopen fseek fread fclose
If this does not help, then programming is clearly not for you - either quit or [cut by Roskomnadzor].

J
jcmvbkbc, 2018-04-10
@jcmvbkbc

I need to read the entry point address from the header

Usually they start a structure describing the title, read the entire title into it, and then get the member of the structure of interest. In particular, on linux for ELF, definitions of the Elf32_Ehdr and Elf64_Ehdr headers can be found in /usr/include/linux/elf.h
Instead of reading into memory from a file, you can map part of the file into the process's address space, see man mmap .

C
CityCat4, 2018-04-10
@CityCat4

man open
man seek
man read
man close
:D

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question