14484Sbinkertn@umich.edu/*- 24484Sbinkertn@umich.edu * Copyright (c) 2006 Joseph Koshy 34484Sbinkertn@umich.edu * All rights reserved. 44484Sbinkertn@umich.edu * 54484Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without 64484Sbinkertn@umich.edu * modification, are permitted provided that the following conditions 74484Sbinkertn@umich.edu * are met: 84484Sbinkertn@umich.edu * 1. Redistributions of source code must retain the above copyright 94484Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer. 104484Sbinkertn@umich.edu * 2. Redistributions in binary form must reproduce the above copyright 114484Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the 124484Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution. 134484Sbinkertn@umich.edu * 144484Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 154484Sbinkertn@umich.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 164484Sbinkertn@umich.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 174484Sbinkertn@umich.edu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 184484Sbinkertn@umich.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 194484Sbinkertn@umich.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 204484Sbinkertn@umich.edu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 214484Sbinkertn@umich.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 224484Sbinkertn@umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 234484Sbinkertn@umich.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 244484Sbinkertn@umich.edu * SUCH DAMAGE. 254484Sbinkertn@umich.edu */ 264484Sbinkertn@umich.edu 274484Sbinkertn@umich.edu 284484Sbinkertn@umich.edu#include <ar.h> 294484Sbinkertn@umich.edu#include <assert.h> 304484Sbinkertn@umich.edu#include "libelf.h" 314484Sbinkertn@umich.edu 324484Sbinkertn@umich.edu#include "_libelf.h" 334484Sbinkertn@umich.edu 344484Sbinkertn@umich.educhar * 354484Sbinkertn@umich.eduelf_getident(Elf *e, size_t *sz) 364484Sbinkertn@umich.edu{ 374484Sbinkertn@umich.edu 384484Sbinkertn@umich.edu if (e == NULL) { 394484Sbinkertn@umich.edu LIBELF_SET_ERROR(ARGUMENT, 0); 404484Sbinkertn@umich.edu goto error; 414484Sbinkertn@umich.edu } 424484Sbinkertn@umich.edu 434484Sbinkertn@umich.edu if (e->e_cmd == ELF_C_WRITE && e->e_rawfile == NULL) { 444484Sbinkertn@umich.edu LIBELF_SET_ERROR(SEQUENCE, 0); 454484Sbinkertn@umich.edu goto error; 464484Sbinkertn@umich.edu } 474484Sbinkertn@umich.edu 484484Sbinkertn@umich.edu assert(e->e_kind != ELF_K_AR || e->e_cmd == ELF_C_READ); 494484Sbinkertn@umich.edu 504484Sbinkertn@umich.edu if (sz) { 514484Sbinkertn@umich.edu if (e->e_kind == ELF_K_AR) 524484Sbinkertn@umich.edu *sz = SARMAG; 534484Sbinkertn@umich.edu else if (e->e_kind == ELF_K_ELF) 544484Sbinkertn@umich.edu *sz = EI_NIDENT; 554484Sbinkertn@umich.edu else 564484Sbinkertn@umich.edu *sz = e->e_rawsize; 574484Sbinkertn@umich.edu } 584484Sbinkertn@umich.edu 594484Sbinkertn@umich.edu return (e->e_rawfile); 604484Sbinkertn@umich.edu 614484Sbinkertn@umich.edu error: 624484Sbinkertn@umich.edu if (sz) 634484Sbinkertn@umich.edu *sz = 0; 644484Sbinkertn@umich.edu return (NULL); 654484Sbinkertn@umich.edu} 66