1260684Skaiw/*- 2367466Sdim * Copyright (c) 2006,2008,2018 Joseph Koshy 3260684Skaiw * All rights reserved. 4260684Skaiw * 5260684Skaiw * Redistribution and use in source and binary forms, with or without 6260684Skaiw * modification, are permitted provided that the following conditions 7260684Skaiw * are met: 8260684Skaiw * 1. Redistributions of source code must retain the above copyright 9260684Skaiw * notice, this list of conditions and the following disclaimer. 10260684Skaiw * 2. Redistributions in binary form must reproduce the above copyright 11260684Skaiw * notice, this list of conditions and the following disclaimer in the 12260684Skaiw * documentation and/or other materials provided with the distribution. 13260684Skaiw * 14260684Skaiw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15260684Skaiw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16260684Skaiw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17260684Skaiw * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18260684Skaiw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19260684Skaiw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20260684Skaiw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21260684Skaiw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22260684Skaiw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23260684Skaiw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24260684Skaiw * SUCH DAMAGE. 25260684Skaiw */ 26260684Skaiw 27260684Skaiw#include <gelf.h> 28260684Skaiw#include <libelf.h> 29260684Skaiw#include <string.h> 30260684Skaiw 31260684Skaiw#include "_libelf.h" 32260684Skaiw 33367466SdimELFTC_VCSID("$Id: gelf_xlate.c 3632 2018-10-10 21:12:43Z jkoshy $"); 34260684Skaiw 35260684SkaiwElf_Data * 36260684Skaiwelf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding) 37260684Skaiw{ 38367466Sdim return _libelf_xlate(dst, src, encoding, ELFCLASS32, EM_NONE, 39367466Sdim ELF_TOFILE); 40260684Skaiw} 41260684Skaiw 42260684SkaiwElf_Data * 43260684Skaiwelf64_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned int encoding) 44260684Skaiw{ 45367466Sdim return _libelf_xlate(dst, src, encoding, ELFCLASS64, EM_NONE, 46367466Sdim ELF_TOFILE); 47260684Skaiw} 48260684Skaiw 49260684SkaiwElf_Data * 50260684Skaiwelf32_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding) 51260684Skaiw{ 52367466Sdim return _libelf_xlate(dst, src, encoding, ELFCLASS32, EM_NONE, 53367466Sdim ELF_TOMEMORY); 54260684Skaiw} 55260684Skaiw 56260684SkaiwElf_Data * 57260684Skaiwelf64_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned int encoding) 58260684Skaiw{ 59367466Sdim return _libelf_xlate(dst, src, encoding, ELFCLASS64, EM_NONE, 60367466Sdim ELF_TOMEMORY); 61260684Skaiw} 62260684Skaiw 63260684SkaiwElf_Data * 64260684Skaiwgelf_xlatetom(Elf *e, Elf_Data *dst, const Elf_Data *src, 65260684Skaiw unsigned int encoding) 66260684Skaiw{ 67260684Skaiw if (e != NULL) 68260684Skaiw return (_libelf_xlate(dst, src, encoding, e->e_class, 69367466Sdim _libelf_elfmachine(e), ELF_TOMEMORY)); 70260684Skaiw LIBELF_SET_ERROR(ARGUMENT, 0); 71260684Skaiw return (NULL); 72260684Skaiw} 73260684Skaiw 74260684SkaiwElf_Data * 75260684Skaiwgelf_xlatetof(Elf *e, Elf_Data *dst, const Elf_Data *src, 76260684Skaiw unsigned int encoding) 77260684Skaiw{ 78260684Skaiw if (e != NULL) 79260684Skaiw return (_libelf_xlate(dst, src, encoding, e->e_class, 80367466Sdim _libelf_elfmachine(e), ELF_TOFILE)); 81260684Skaiw LIBELF_SET_ERROR(ARGUMENT, 0); 82260684Skaiw return (NULL); 83260684Skaiw} 84