1100894Srwatson/*- 2100894Srwatson * Copyright (c) 2006,2008 Joseph Koshy 3100894Srwatson * All rights reserved. 4100894Srwatson * 5100894Srwatson * Redistribution and use in source and binary forms, with or without 6100894Srwatson * modification, are permitted provided that the following conditions 7100894Srwatson * are met: 8100894Srwatson * 1. Redistributions of source code must retain the above copyright 9100894Srwatson * notice, this list of conditions and the following disclaimer. 10106392Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11106392Srwatson * notice, this list of conditions and the following disclaimer in the 12106392Srwatson * documentation and/or other materials provided with the distribution. 13106392Srwatson * 14100894Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15100894Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16100894Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17100894Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18100894Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19100894Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20100894Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21100894Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22100894Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23100894Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24100894Srwatson * SUCH DAMAGE. 25100894Srwatson */ 26100894Srwatson 27100894Srwatson#include <gelf.h> 28100894Srwatson#include <libelf.h> 29100894Srwatson#include <string.h> 30100894Srwatson 31100894Srwatson#include "_libelf.h" 32100894Srwatson 33100894SrwatsonELFTC_VCSID("$Id: gelf_xlate.c 3174 2015-03-27 17:13:41Z emaste $"); 34100894Srwatson 35100894SrwatsonElf_Data * 36100894Srwatsonelf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding) 37100894Srwatson{ 38100894Srwatson return _libelf_xlate(dst, src, encoding, ELFCLASS32, ELF_TOFILE); 39100894Srwatson} 40100894Srwatson 41100894SrwatsonElf_Data * 42100894Srwatsonelf64_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding) 43100894Srwatson{ 44100894Srwatson return _libelf_xlate(dst, src, encoding, ELFCLASS64, ELF_TOFILE); 45100894Srwatson} 46104300Sphk 47101173SrwatsonElf_Data * 48100894Srwatsonelf32_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding) 49106856Srwatson{ 50100979Srwatson return _libelf_xlate(dst, src, encoding, ELFCLASS32, ELF_TOMEMORY); 51106468Srwatson} 52100979Srwatson 53100979SrwatsonElf_Data * 54102949Sbdeelf64_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding) 55100979Srwatson{ 56100979Srwatson return _libelf_xlate(dst, src, encoding, ELFCLASS64, ELF_TOMEMORY); 57101712Srwatson} 58100979Srwatson 59100979SrwatsonElf_Data * 60100894Srwatsongelf_xlatetom(Elf *e, Elf_Data *dst, const Elf_Data *src, 61100894Srwatson unsigned int encoding) 62100979Srwatson{ 63100979Srwatson if (e != NULL) 64100979Srwatson return (_libelf_xlate(dst, src, encoding, e->e_class, 65100979Srwatson ELF_TOMEMORY)); 66100979Srwatson LIBELF_SET_ERROR(ARGUMENT, 0); 67100979Srwatson return (NULL); 68100979Srwatson} 69100979Srwatson 70100894SrwatsonElf_Data * 71100979Srwatsongelf_xlatetof(Elf *e, Elf_Data *dst, const Elf_Data *src, 72100979Srwatson unsigned int encoding) 73100979Srwatson{ 74100979Srwatson if (e != NULL) 75100979Srwatson return (_libelf_xlate(dst, src, encoding, e->e_class, 76100979Srwatson ELF_TOFILE)); 77100979Srwatson LIBELF_SET_ERROR(ARGUMENT, 0); 78100979Srwatson return (NULL); 79100979Srwatson} 80100979Srwatson