123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100(**************************************************************************)(* 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). *)(* *)(**************************************************************************)moduletypeBasic=sigtypemnemonictypet=private{size:Size.Byte.t;opcode:string;mnemonic:mnemonic}valcreate:int->string->mnemonic->tvalpp_opcode:Format.formatter->t->unitvalpp_mnemonic:Format.formatter->t->unitendmoduleMake(P:Sigs.PRINTABLE)=structtypemnemonic=P.ttypet={size:Size.Byte.t;opcode:string;mnemonic:mnemonic}letcreatesizeopcodemnemonic=letsize=Size.Byte.createsizein{size;opcode;mnemonic}letpp_opcodeppft=Format.fprintfppf"%s"t.opcodeletpp_mnemonicppft=Format.fprintfppf"%a"P.ppt.mnemonicendmoduleGeneric=Make(Mnemonic)typet={address:Virtual_address.t;size:Size.Byte.t;opcode:Binstream.t;mnemonic:Mnemonic.t;dba_block:Dhunk.t;}lethunkt=t.dba_blockletaddresst=t.addressletsizet=t.sizeletopcodet=t.opcodeletmnemonict=t.mnemonicletcreateaddresssizeopcodemnemonicdba_block={address;size;opcode;mnemonic;dba_block}letunsupportedaddresssizeopcodemnemonic=assert(letopenMnemonicinmatchmnemonicwithUnknown|Unsupported_->true|Supported_->false);createaddresssizeopcodemnemonicDhunk.emptyletof_generic_instructionaddressginstrdba_block=createaddressginstr.Generic.size(Binstream.of_nibblesginstr.Generic.opcode)ginstr.Generic.mnemonicdba_blockletof_dba_block?(mnemonic=Mnemonic.unsupported())addressdba_block=letsize=Size.Byte.create0inletopcode=Binstream.emptyincreateaddresssizeopcodemnemonicdba_blockletemptyaddress=letaddr=Dba_types.Caddress.base_valueaddressinof_dba_blockaddrDhunk.emptyletto_generic_instructione=Generic.create(Size.Byte.to_inte.size)(Binstream.to_stringe.opcode)e.mnemonicletset_dba_blocktdba_block={twithdba_block}letset_mnemonicmnemonict={twithmnemonic}letis_decodedt=not(Dhunk.is_emptyt.dba_block||Size.Byte.is_zerot.size)letget_caddresst=Dba_types.Caddress.block_startt.addressletstopvaddr=letdba_block=Dba.Instr.stop(SomeDba.OK)|>Dhunk.singletoninof_dba_blockvaddrdba_blockletstarti=Dhunk.starti.dba_blockletppppfi=Format.fprintfppf"@[<v 0>@[<h>%a/@ %a@]@ %a@]"Binstream.ppi.opcodeMnemonic.ppi.mnemonicDhunk.ppi.dba_block