123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138(**************************************************************************)(* 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). *)(* *)(**************************************************************************)openTypesmoduletypeDRIVER=sigtypepathtypeoutcomevalstep:path->([`Step],path)fiber->outcomevalassign:path->([`Assign],path)fiber->outcomevalclobber:path->([`Clobber],path)fiber->outcomevalload:path->([`Load],path)fiber->outcomevalstore:path->([`Store],path)fiber->outcomevalsymbolize:path->([`Symbolize],path)fiber->outcomevalapply:path->([`Apply],path)fiber->outcomevalassume:path->([`Assume],path)fiber->outcomevalcheck:path->([`Assert],path)fiber->outcomevalite:path->([`Branch],path)fiber->outcomevalgoto:path->([`Goto],path)fiber->outcomevaljump:path->([`Jump],path)fiber->outcomevalcall:path->([`Call],path)fiber->outcomevaltail_call:path->([`Tail_call],path)fiber->outcomeendtype('path,'outcome)driver=(moduleDRIVERwithtypepath='pathandtypeoutcome='outcome)letdispatch:typepathoutcome.path->([`All],path)fiber->(path,outcome)driver->outcome=funpathfiberdriver->letopen(valdriver)inmatchfiberwith|Step_asfiber->steppathfiber|Assign_asfiber->assignpathfiber|Clobber_asfiber->clobberpathfiber|Load_asfiber->loadpathfiber|Store_asfiber->storepathfiber|Symbolize_asfiber->symbolizepathfiber|Apply_asfiber->applypathfiber|Assume_asfiber->assumepathfiber|Assert_asfiber->checkpathfiber|Branch_asfiber->itepathfiber|Goto_asfiber->gotopathfiber|Jump_asfiber->jumppathfiber|Call_asfiber->callpathfiber|Tail_call_asfiber->tail_callpathfibermoduleConcrete(P:PATH)(D:DRIVERwithtypepath=P.tandtypeoutcome=P.tcontinuation):DRIVERwithtypepath=P.tandtypeoutcome=P.tcontinuation=structtypepath=P.ttypeoutcome=pathcontinuationletstep:path->([`Step],path)fiber->outcome=funpath(Step{addr;succ;_})->P.set_pcpathaddr;(dispatch[@tailcall])pathsucc(moduleD)letassign:path->([`Assign],path)fiber->outcome=funpath(Assign{var;rval;succ})->P.assignpathvarrval;(dispatch[@tailcall])pathsucc(moduleD)letclobber:path->([`Clobber],path)fiber->outcome=funpath(Clobber{var;succ})->P.clobberpathvar;(dispatch[@tailcall])pathsucc(moduleD)letload:path->([`Load],path)fiber->outcome=funpath(Load{var;base;addr;dir;succ})->P.loadpathvarbase~addrdir;(dispatch[@tailcall])pathsucc(moduleD)letstore:path->([`Store],path)fiber->outcome=funpath(Store{base;addr;dir;rval;succ})->P.storepathbase~addrrvaldir;(dispatch[@tailcall])pathsucc(moduleD)letsymbolize:path->([`Symbolize],path)fiber->outcome=funpath(Symbolize{var;succ})->P.symbolizepathvar;(dispatch[@tailcall])pathsucc(moduleD)letapply:path->([`Apply],path)fiber->outcome=funpath(Apply{f;succ})->fpath;(dispatch[@tailcall])pathsucc(moduleD)letassume:path->([`Assume],path)fiber->outcome=funpath(Assume{test;succ})->ifBitvector.is_zero(P.evalpathtest)thenSignalUnsatisfiable_assumptionelse(dispatch[@tailcall])pathsucc(moduleD)letcheck:path->([`Assert],path)fiber->outcome=funpath(Assert{test;succ})->ifBitvector.is_zero(P.evalpathtest)thenSignalAssertion_failureelse(dispatch[@tailcall])pathsucc(moduleD)letite:path->([`Branch],path)fiber->outcome=funpath(Branch{test;taken;fallthrough})->(dispatch[@tailcall])path(ifBitvector.is_zero(P.evalpathtest)thenfallthroughelsetaken)(moduleD)letgoto:path->([`Goto],path)fiber->outcome=fun_(Goto_asfiber)->Continuefiberletjump:path->([`Jump],path)fiber->outcome=funpath(Jumptarget)->Continue(Goto(Virtual_address.of_bitvector(P.evalpathtarget)))letcall:path->([`Call],path)fiber->outcome=fun_(Call{f;succ})->Call(f,Continuesucc)lettail_call:path->([`Tail_call],path)fiber->outcome=fun_(Tail_callf)->Tail_callfend