123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687(**************************************************************************)(* This file is part of BINSEC. *)(* *)(* Copyright (C) 2016-2026 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file licenses/LGPLv2.1). *)(* *)(**************************************************************************)openBasic_types.IntegersopenLoader_typesmoduleSection=structtypet=bufferlethas_flagf_=matchfwithRead|Exec->true|Write->falsetypeheader=unitletheader_=()letsizet=letraw=Bigarray.Array1.dimtin{raw;virt=Z.of_intraw}letpos_={raw=0;virt=Virtual_address.create0}letname_=".raw"endmoduleSymbol=structtypet=unittypeheader=unitletname_=assertfalseletvalue_=assertfalseletheader_=assertfalseendmoduleImg=structtypeheader=unittypet={content:Section.t;sections:Section.tarray;arch:Machine.t}letsections{sections;_}=sectionsletsymbols_=[||]letarcht=t.archletheader_=()letentry_=Virtual_address.create0letcursor?att=Reader.of_bigarray?pos:at(Array.gett.sections0)letcontent_buf=bufletbuffer{content;_}=contentletppppf_=Format.pp_print_stringppf"Raw image"endletcheck_magic_=assertfalseletread_offsetimgi=tryInt.unsafe_to_uint8(Bigarray.Array1.getimg.Img.contenti)withInvalid_argument_->raiseNot_foundletread_addressimga=read_offsetimg(Virtual_address.to_inta)letloadcontent={Img.arch=Machine.unknown;content;sections=[|content|]}letload_file_descrfile_descr=loadBigarray.(array1_of_genarray(Unix.map_filefile_descrInt8_unsignedC_layoutfalse[|-1|]))letload_filepath=letfile_descr=Unix.openfilepath[Unix.O_RDONLY]0inletimg=load_file_descrfile_descrinUnix.closefile_descr;img