1da0c48c4Sopenharmony_ci/* Copyright (C) 2008 Red Hat, Inc. 2da0c48c4Sopenharmony_ci This file is part of elfutils. 3da0c48c4Sopenharmony_ci 4da0c48c4Sopenharmony_ci This file is free software; you can redistribute it and/or modify 5da0c48c4Sopenharmony_ci it under the terms of the GNU General Public License as published by 6da0c48c4Sopenharmony_ci the Free Software Foundation; either version 3 of the License, or 7da0c48c4Sopenharmony_ci (at your option) any later version. 8da0c48c4Sopenharmony_ci 9da0c48c4Sopenharmony_ci elfutils is distributed in the hope that it will be useful, but 10da0c48c4Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 11da0c48c4Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12da0c48c4Sopenharmony_ci GNU General Public License for more details. 13da0c48c4Sopenharmony_ci 14da0c48c4Sopenharmony_ci You should have received a copy of the GNU General Public License 15da0c48c4Sopenharmony_ci along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16da0c48c4Sopenharmony_ci 17da0c48c4Sopenharmony_ci#ifdef HAVE_CONFIG_H 18da0c48c4Sopenharmony_ci# include <config.h> 19da0c48c4Sopenharmony_ci#endif 20da0c48c4Sopenharmony_ci 21da0c48c4Sopenharmony_ci#include <errno.h> 22da0c48c4Sopenharmony_ci#include <fcntl.h> 23da0c48c4Sopenharmony_ci#include <gelf.h> 24da0c48c4Sopenharmony_ci#include <stdio.h> 25da0c48c4Sopenharmony_ci#include <stdlib.h> 26da0c48c4Sopenharmony_ci#include "system.h" 27da0c48c4Sopenharmony_ci 28da0c48c4Sopenharmony_ciint 29da0c48c4Sopenharmony_cimain (int argc, char *argv[]) 30da0c48c4Sopenharmony_ci{ 31da0c48c4Sopenharmony_ci if (argc < 2) 32da0c48c4Sopenharmony_ci error (1, 0, "Usage: %s FILE OFFSET", argv[0]); 33da0c48c4Sopenharmony_ci 34da0c48c4Sopenharmony_ci /* Set the ELF version. */ 35da0c48c4Sopenharmony_ci elf_version (EV_CURRENT); 36da0c48c4Sopenharmony_ci 37da0c48c4Sopenharmony_ci /* Open the archive. */ 38da0c48c4Sopenharmony_ci int fd = open (argv[1], O_RDONLY); 39da0c48c4Sopenharmony_ci if (fd < 0) 40da0c48c4Sopenharmony_ci error (1, errno, "cannot open '%s'", argv[1]); 41da0c48c4Sopenharmony_ci 42da0c48c4Sopenharmony_ci Elf *elf = elf_begin (fd, ELF_C_READ, NULL); 43da0c48c4Sopenharmony_ci if (elf == NULL) 44da0c48c4Sopenharmony_ci error (2, 0, "elf_begin: %s", elf_errmsg (-1)); 45da0c48c4Sopenharmony_ci 46da0c48c4Sopenharmony_ci Elf_Scn *scn = gelf_offscn (elf, strtoull (argv[2], NULL, 0)); 47da0c48c4Sopenharmony_ci if (scn == NULL) 48da0c48c4Sopenharmony_ci error (3, 0, "gelf_offscn: %s", elf_errmsg (-1)); 49da0c48c4Sopenharmony_ci 50da0c48c4Sopenharmony_ci elf_end (elf); 51da0c48c4Sopenharmony_ci return 0; 52da0c48c4Sopenharmony_ci} 53