12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147(**************************************************************************)(* 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.IntegersmoduletypeARCH=sigvalget_defs:unit->(string*Dba.LValue.t)listvalget_return_address:unit->Dba.Expr.tvalget_arg:?syscall:bool->int->Dba.Expr.tvalget_ret:?syscall:bool->unit->Dba.LValue.tvalmake_return:?value:Dba.Expr.t->unit->Dhunk.tvalget_stack_pointer:unit->Dba.Var.t*Bitvector.tvalget_shortlived_flags:unit->Dba.Var.tlistvalget_dwarf_register:int->Dba.Expr.tvalcore:Loader_elf.Img.t->Virtual_address.t*(Dba.Var.t*Dba.Expr.t)listvalmax_instruction_len:Size.Byte.tendmoduleX86:ARCH=structletinfo=Dba.Var.Tag.Registerleteax=Dba.Var.create"eax"~bitsize:Size.Bit.bits32~tag:infoandebx=Dba.Var.create"ebx"~bitsize:Size.Bit.bits32~tag:infoandecx=Dba.Var.create"ecx"~bitsize:Size.Bit.bits32~tag:infoandedx=Dba.Var.create"edx"~bitsize:Size.Bit.bits32~tag:infoandedi=Dba.Var.create"edi"~bitsize:Size.Bit.bits32~tag:infoandesi=Dba.Var.create"esi"~bitsize:Size.Bit.bits32~tag:infoandesp=Dba.Var.create"esp"~bitsize:Size.Bit.bits32~tag:infoandebp=Dba.Var.create"ebp"~bitsize:Size.Bit.bits32~tag:infoletcs=Dba.Var.create"cs"~bitsize:Size.Bit.bits16~tag:infoandds=Dba.Var.create"ds"~bitsize:Size.Bit.bits16~tag:infoandes=Dba.Var.create"es"~bitsize:Size.Bit.bits16~tag:infoandfs=Dba.Var.create"fs"~bitsize:Size.Bit.bits16~tag:infoandfs_base=Dba.Var.create"fs_base"~bitsize:Size.Bit.bits32~tag:infoandgs=Dba.Var.create"gs"~bitsize:Size.Bit.bits16~tag:infoandgs_base=Dba.Var.create"gs_base"~bitsize:Size.Bit.bits32~tag:infoandss=Dba.Var.create"ss"~bitsize:Size.Bit.bits16~tag:infoletstx=Array.init8(funx->Dba.Var.create(Format.sprintf"st%d"x)~bitsize:Size.Bit.bits80~tag:info)letmmx=Array.init8(funx->Dba.Var.create(Format.sprintf"mm%d"x)~bitsize:Size.Bit.bits64~tag:info)letxmmx=Array.init8(funx->Dba.Var.create(Format.sprintf"xmm%d"x)~bitsize:Size.Bit.bits128~tag:info)letxmm0=Array.getxmmx0andxmm1=Array.getxmmx1andxmm2=Array.getxmmx2andxmm3=Array.getxmmx3andxmm4=Array.getxmmx4andxmm5=Array.getxmmx5andxmm6=Array.getxmmx6andxmm7=Array.getxmmx7letinfo=Dba.Var.Tag.Flagletcf=Dba.Var.create"CF"~bitsize:Size.Bit.bits1~tag:infoandpf=Dba.Var.create"PF"~bitsize:Size.Bit.bits1~tag:infoandaf=Dba.Var.create"AF"~bitsize:Size.Bit.bits1~tag:infoandzf=Dba.Var.create"ZF"~bitsize:Size.Bit.bits1~tag:infoandsf=Dba.Var.create"SF"~bitsize:Size.Bit.bits1~tag:infoandtf=Dba.Var.create"TF"~bitsize:Size.Bit.bits1~tag:infoandif'=Dba.Var.create"IF"~bitsize:Size.Bit.bits1~tag:infoanddf=Dba.Var.create"DF"~bitsize:Size.Bit.bits1~tag:infoandof'=Dba.Var.create"OF"~bitsize:Size.Bit.bits1~tag:infoandiopl=Dba.Var.create"IOPL"~bitsize:Size.Bit.bits2~tag:infoandnt=Dba.Var.create"NT"~bitsize:Size.Bit.bits1~tag:infoandrf=Dba.Var.create"RF"~bitsize:Size.Bit.bits1~tag:infoandvm=Dba.Var.create"VM"~bitsize:Size.Bit.bits1~tag:infoandac=Dba.Var.create"AC"~bitsize:Size.Bit.bits1~tag:infoandvif=Dba.Var.create"VIF"~bitsize:Size.Bit.bits1~tag:infoandvip=Dba.Var.create"VIP"~bitsize:Size.Bit.bits1~tag:infoandid=Dba.Var.create"ID"~bitsize:Size.Bit.bits1~tag:infoletdefs=[("eax",Dba.LValue.veax);("ebx",Dba.LValue.vebx);("ecx",Dba.LValue.vecx);("edx",Dba.LValue.vedx);("edi",Dba.LValue.vedi);("esi",Dba.LValue.vesi);("esp",Dba.LValue.vesp);("ebp",Dba.LValue.vebp);("al",Dba.LValue.restricteax07);("ah",Dba.LValue.restricteax815);("ax",Dba.LValue.restricteax015);("bl",Dba.LValue.restrictebx07);("bh",Dba.LValue.restrictebx815);("bx",Dba.LValue.restrictebx015);("cl",Dba.LValue.restrictecx07);("ch",Dba.LValue.restrictecx815);("cx",Dba.LValue.restrictecx015);("dl",Dba.LValue.restrictedx07);("dh",Dba.LValue.restrictedx815);("dx",Dba.LValue.restrictedx015);("di",Dba.LValue.restrictedi015);("si",Dba.LValue.restrictesi015);("sp",Dba.LValue.restrictesp015);("bp",Dba.LValue.restrictebp015);("cs",Dba.LValue.vcs);("ds",Dba.LValue.vds);("es",Dba.LValue.ves);("fs",Dba.LValue.vfs);("gs",Dba.LValue.vgs);("ss",Dba.LValue.vss);("fs_base",Dba.LValue.vfs_base);("gs_base",Dba.LValue.vgs_base);("CF",Dba.LValue.vcf);("PF",Dba.LValue.vpf);("AF",Dba.LValue.vaf);("ZF",Dba.LValue.vzf);("SF",Dba.LValue.vsf);("TF",Dba.LValue.vtf);("IF",Dba.LValue.vif');("DF",Dba.LValue.vdf);("OF",Dba.LValue.vof');("IOPL",Dba.LValue.viopl);("NT",Dba.LValue.vnt);("RF",Dba.LValue.vrf);("VM",Dba.LValue.vvm);("AC",Dba.LValue.vac);("VIF",Dba.LValue.vvif);("VIP",Dba.LValue.vvip);("ID",Dba.LValue.vid);("xmm0",Dba.LValue.restrictxmm00127);("xmm1",Dba.LValue.restrictxmm10127);("xmm2",Dba.LValue.restrictxmm20127);("xmm3",Dba.LValue.restrictxmm30127);("xmm4",Dba.LValue.restrictxmm40127);("xmm5",Dba.LValue.restrictxmm50127);("xmm6",Dba.LValue.restrictxmm60127);("xmm7",Dba.LValue.restrictxmm70127);]letshortlived_flags=[cf;pf;af;zf;sf;of']letget_shortlived_flags()=shortlived_flagsletget_defs()=defsletnotesimg=Array.fold_left(fun(entrypoint,defs)note->matchnotewith|{Loader_elf.Note.name="CORE";kind=1;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimginReader.advancecursor0x48;letrebx=Dba.Expr.constant(Reader.Read.bv32cursor)inletrecx=Dba.Expr.constant(Reader.Read.bv32cursor)inletredx=Dba.Expr.constant(Reader.Read.bv32cursor)inletresi=Dba.Expr.constant(Reader.Read.bv32cursor)inletredi=Dba.Expr.constant(Reader.Read.bv32cursor)inletrebp=Dba.Expr.constant(Reader.Read.bv32cursor)inletreax=Dba.Expr.constant(Reader.Read.bv32cursor)inletrds=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor2;letres=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor2;letrfs=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor2;letrgs=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor2;Reader.advancecursor4;letentrypoint=Virtual_address.of_bigint(Uint32.to_bigint(Reader.Read.u32cursor))inletrcs=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor2;leteflags=Uint32.to_int(Reader.Read.u32cursor)inletrcf=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr0)land0b1))andrpf=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr2)land0b1))andraf=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr4)land0b1))andrzf=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr6)land0b1))andrsf=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr7)land0b1))andrtf=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr8)land0b1))andrif=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr9)land0b1))andrdf=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr10)land0b1))androf=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr11)land0b1))andriopl=Dba.Expr.constant(Bitvector.of_int~size:2((eflagslsr12)land0b11))andrnt=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr14)land0b1))andrrf=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr16)land0b1))andrvm=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr17)land0b1))andrac=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr18)land0b1))andrvif=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr19)land0b1))andrvip=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr20)land0b1))andrid=Dba.Expr.constant(Bitvector.of_int~size:1((eflagslsr21)land0b1))inletresp=Dba.Expr.constant(Reader.Read.bv32cursor)inletrss=Dba.Expr.constant(Bitvector.of_int~size:16(Uint32.to_int(Reader.Read.u32cursor)))in(entrypoint,List.rev_append[(ebx,rebx);(ecx,recx);(edx,redx);(esi,resi);(edi,redi);(ebp,rebp);(eax,reax);(esp,resp);(ds,rds);(es,res);(fs,rfs);(gs,rgs);(cs,rcs);(ss,rss);(cf,rcf);(pf,rpf);(af,raf);(zf,rzf);(sf,rsf);(tf,rtf);(if',rif);(df,rdf);(of',rof);(iopl,riopl);(nt,rnt);(rf,rrf);(vm,rvm);(ac,rac);(vif,rvif);(vip,rvip);(id,rid);]defs)|{Loader_elf.Note.name="CORE";kind=2;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimginReader.advancecursor0xa0;(entrypoint,List.fold_left(fundefsreg->(reg,Dba.Expr.constant(Reader.Read.readcursor16))::defs)defs[xmm0;xmm1;xmm2;xmm3;xmm4;xmm5;xmm6;xmm7])|{Loader_elf.Note.name="PIN";kind=0;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimginletrgs_base=Dba.Expr.constant(Reader.Read.bv32cursor)in(entrypoint,(gs_base,rgs_base)::defs)|_->(entrypoint,defs))(Virtual_address.create0,[])(Loader_elf.notesimg)letcore=notesletret=Dba.LValue.veaxletesp_l=Dba.LValue.vespandesp_r=Dba.Expr.vespandeax_l=Dba.LValue.veaxandebx_r=Dba.Expr.vebxandecx_r=Dba.Expr.vecxandedx_r=Dba.Expr.vedxandesi_r=Dba.Expr.vesiandedi_r=Dba.Expr.vediandebp_r=Dba.Expr.vebpandfour=Dba.Expr.constant(Bitvector.of_int~size:324)letreturn_address=Dba.Expr.loadSize.Byte.fourLittleEndianesp_rletget_return_address()=return_addressletget_arg?(syscall=false)i=ifsyscallthenmatchiwith|0->ebx_r|1->ecx_r|2->edx_r|3->esi_r|4->edi_r|5->ebp_r|_->raise(Invalid_argument"syscall")elseDba.Expr.loadSize.Byte.fourLittleEndian(Dba.Expr.addesp_r(Dba.Expr.constant(Bitvector.of_int~size:32(4*(i+1)))))letget_ret?syscall:_()=retletvoid_return=Dhunk.init2(function|0->Dba.Instr.assignesp_l(Dba.Expr.addesp_rfour)1|_->Dba.Instr.dynamic_jump~tag:Return(Dba.Expr.loadSize.Byte.fourLittleEndian(Dba.Expr.subesp_rfour)))andval_returnvalue=Dhunk.init3(function|0->Dba.Instr.assigneax_lvalue1|1->Dba.Instr.assignesp_l(Dba.Expr.addesp_rfour)2|_->Dba.Instr.dynamic_jump~tag:Return(Dba.Expr.loadSize.Byte.fourLittleEndian(Dba.Expr.subesp_rfour)))letmake_return?value()=match(value:Dba.Expr.toption)with|None->void_return|Some(Varv)whenDba.Var.equalveax->void_return|Somevalue->val_returnvalueletget_stack_pointer()=(esp,Bitvector.of_int320xfff00000l)letmax_instruction_len=Size.Byte.fifteenleteax_r=Dba.Expr.veaxandeip_r=Dba.Expr.var"eip"32(* note that eip is not used nor updated by the DBA semantics -- do not use it outside of debug information *)andes_r=Dba.Expr.vesandcs_r=Dba.Expr.vcsandss_r=Dba.Expr.vssandds_r=Dba.Expr.vdsandfs_r=Dba.Expr.vfsandgs_r=Dba.Expr.vgsandstx_r=Array.mapDba.Expr.vstxandmmx_r=Array.mapDba.Expr.vmmxandxmmx_r=Array.mapDba.Expr.vxmmxletget_dwarf_register=function|0->eax_r|1->ecx_r|2->edx_r|3->ebx_r|4->esp_r|5->ebp_r|6->esi_r|7->edi_r|8->eip_r|(11|12|13|14|15|16|17|18)asx->Array.getstx_r(x-11)|(21|22|23|24|25|26|27|28)asx->Array.getxmmx_r(x-21)|(29|30|31|32|33|34|35|36)asx->Array.getmmx_r(x-29)|40->es_r|41->cs_r|42->ss_r|43->ds_r|44->fs_r|45->gs_r|n->Isa_logger.fatal"unable to map integer %d to a known DWARF register"nendmoduleAMD64:ARCH=structletinfo=Dba.Var.Tag.Registerletrax=Dba.Var.create"rax"~bitsize:Size.Bit.bits64~tag:infoandrbx=Dba.Var.create"rbx"~bitsize:Size.Bit.bits64~tag:infoandrcx=Dba.Var.create"rcx"~bitsize:Size.Bit.bits64~tag:infoandrdx=Dba.Var.create"rdx"~bitsize:Size.Bit.bits64~tag:infoandrdi=Dba.Var.create"rdi"~bitsize:Size.Bit.bits64~tag:infoandrsi=Dba.Var.create"rsi"~bitsize:Size.Bit.bits64~tag:infoandrsp=Dba.Var.create"rsp"~bitsize:Size.Bit.bits64~tag:infoandrbp=Dba.Var.create"rbp"~bitsize:Size.Bit.bits64~tag:infoandr8=Dba.Var.create"r8"~bitsize:Size.Bit.bits64~tag:infoandr9=Dba.Var.create"r9"~bitsize:Size.Bit.bits64~tag:infoandr10=Dba.Var.create"r10"~bitsize:Size.Bit.bits64~tag:infoandr11=Dba.Var.create"r11"~bitsize:Size.Bit.bits64~tag:infoandr12=Dba.Var.create"r12"~bitsize:Size.Bit.bits64~tag:infoandr13=Dba.Var.create"r13"~bitsize:Size.Bit.bits64~tag:infoandr14=Dba.Var.create"r14"~bitsize:Size.Bit.bits64~tag:infoandr15=Dba.Var.create"r15"~bitsize:Size.Bit.bits64~tag:infoletcs=Dba.Var.create"cs"~bitsize:Size.Bit.bits16~tag:infoandds=Dba.Var.create"ds"~bitsize:Size.Bit.bits16~tag:infoandes=Dba.Var.create"es"~bitsize:Size.Bit.bits16~tag:infoandfs=Dba.Var.create"fs"~bitsize:Size.Bit.bits16~tag:infoandgs=Dba.Var.create"gs"~bitsize:Size.Bit.bits16~tag:infoandss=Dba.Var.create"ss"~bitsize:Size.Bit.bits16~tag:infoandfs_base=Dba.Var.create"fs_base"~bitsize:Size.Bit.bits64~tag:infoandgs_base=Dba.Var.create"gs_base"~bitsize:Size.Bit.bits64~tag:infoletymm0=Dba.Var.create"ymm0"~bitsize:Size.Bit.bits256~tag:infoandymm1=Dba.Var.create"ymm1"~bitsize:Size.Bit.bits256~tag:infoandymm2=Dba.Var.create"ymm2"~bitsize:Size.Bit.bits256~tag:infoandymm3=Dba.Var.create"ymm3"~bitsize:Size.Bit.bits256~tag:infoandymm4=Dba.Var.create"ymm4"~bitsize:Size.Bit.bits256~tag:infoandymm5=Dba.Var.create"ymm5"~bitsize:Size.Bit.bits256~tag:infoandymm6=Dba.Var.create"ymm6"~bitsize:Size.Bit.bits256~tag:infoandymm7=Dba.Var.create"ymm7"~bitsize:Size.Bit.bits256~tag:infoandymm8=Dba.Var.create"ymm8"~bitsize:Size.Bit.bits256~tag:infoandymm9=Dba.Var.create"ymm9"~bitsize:Size.Bit.bits256~tag:infoandymm10=Dba.Var.create"ymm10"~bitsize:Size.Bit.bits256~tag:infoandymm11=Dba.Var.create"ymm11"~bitsize:Size.Bit.bits256~tag:infoandymm12=Dba.Var.create"ymm12"~bitsize:Size.Bit.bits256~tag:infoandymm13=Dba.Var.create"ymm13"~bitsize:Size.Bit.bits256~tag:infoandymm14=Dba.Var.create"ymm14"~bitsize:Size.Bit.bits256~tag:infoandymm15=Dba.Var.create"ymm15"~bitsize:Size.Bit.bits256~tag:infoletinfo=Dba.Var.Tag.Flagletcf=Dba.Var.create"cf"~bitsize:Size.Bit.bits1~tag:infoandpf=Dba.Var.create"pf"~bitsize:Size.Bit.bits1~tag:infoandaf=Dba.Var.create"af"~bitsize:Size.Bit.bits1~tag:infoandzf=Dba.Var.create"zf"~bitsize:Size.Bit.bits1~tag:infoandsf=Dba.Var.create"sf"~bitsize:Size.Bit.bits1~tag:infoandtf=Dba.Var.create"tf"~bitsize:Size.Bit.bits1~tag:infoandif'=Dba.Var.create"if"~bitsize:Size.Bit.bits1~tag:infoanddf=Dba.Var.create"df"~bitsize:Size.Bit.bits1~tag:infoandof'=Dba.Var.create"of"~bitsize:Size.Bit.bits1~tag:infoandiopl=Dba.Var.create"iopl"~bitsize:Size.Bit.bits2~tag:infoandnt=Dba.Var.create"nt"~bitsize:Size.Bit.bits1~tag:infoandrf=Dba.Var.create"rf"~bitsize:Size.Bit.bits1~tag:infoandvm=Dba.Var.create"vm"~bitsize:Size.Bit.bits1~tag:infoandac=Dba.Var.create"ac"~bitsize:Size.Bit.bits1~tag:infoandvif'=Dba.Var.create"vif"~bitsize:Size.Bit.bits1~tag:infoandvip=Dba.Var.create"vip"~bitsize:Size.Bit.bits1~tag:infoandid=Dba.Var.create"id"~bitsize:Size.Bit.bits1~tag:infoletdefs=[("rax",Dba.LValue.vrax);("rbx",Dba.LValue.vrbx);("rcx",Dba.LValue.vrcx);("rdx",Dba.LValue.vrdx);("rdi",Dba.LValue.vrdi);("rsi",Dba.LValue.vrsi);("rsp",Dba.LValue.vrsp);("rbp",Dba.LValue.vrbp);("r8",Dba.LValue.vr8);("r9",Dba.LValue.vr9);("r10",Dba.LValue.vr10);("r11",Dba.LValue.vr11);("r12",Dba.LValue.vr12);("r13",Dba.LValue.vr13);("r14",Dba.LValue.vr14);("r15",Dba.LValue.vr15);("eax",Dba.LValue.restrictrax031);("ebx",Dba.LValue.restrictrbx031);("ecx",Dba.LValue.restrictrcx031);("edx",Dba.LValue.restrictrdx031);("edi",Dba.LValue.restrictrdi031);("esi",Dba.LValue.restrictrsi031);("esp",Dba.LValue.restrictrsp031);("ebp",Dba.LValue.restrictrbp031);("r8d",Dba.LValue.restrictr8031);("r9d",Dba.LValue.restrictr9031);("r10d",Dba.LValue.restrictr10031);("r11d",Dba.LValue.restrictr11031);("r12d",Dba.LValue.restrictr12031);("r13d",Dba.LValue.restrictr13031);("r14d",Dba.LValue.restrictr14031);("r15d",Dba.LValue.restrictr15031);("al",Dba.LValue.restrictrax07);("ah",Dba.LValue.restrictrax815);("ax",Dba.LValue.restrictrax015);("bl",Dba.LValue.restrictrbx07);("bh",Dba.LValue.restrictrbx815);("bx",Dba.LValue.restrictrbx015);("cl",Dba.LValue.restrictrcx07);("ch",Dba.LValue.restrictrcx815);("cx",Dba.LValue.restrictrcx015);("dl",Dba.LValue.restrictrdx07);("dh",Dba.LValue.restrictrdx815);("dx",Dba.LValue.restrictrdx015);("dil",Dba.LValue.restrictrdi07);("di",Dba.LValue.restrictrdi015);("sil",Dba.LValue.restrictrsi07);("si",Dba.LValue.restrictrsi015);("spl",Dba.LValue.restrictrsp07);("sp",Dba.LValue.restrictrsp015);("bpl",Dba.LValue.restrictrbp07);("bp",Dba.LValue.restrictrbp015);("r8w",Dba.LValue.restrictr8031);("r9w",Dba.LValue.restrictr9031);("r10w",Dba.LValue.restrictr10015);("r11w",Dba.LValue.restrictr11015);("r12w",Dba.LValue.restrictr12015);("r13w",Dba.LValue.restrictr13015);("r14w",Dba.LValue.restrictr14015);("r15w",Dba.LValue.restrictr15015);("r8b",Dba.LValue.restrictr807);("r9b",Dba.LValue.restrictr907);("r10b",Dba.LValue.restrictr1007);("r11b",Dba.LValue.restrictr1107);("r12b",Dba.LValue.restrictr1207);("r13b",Dba.LValue.restrictr1307);("r14b",Dba.LValue.restrictr1407);("r15b",Dba.LValue.restrictr1507);("cs",Dba.LValue.vcs);("ds",Dba.LValue.vds);("es",Dba.LValue.ves);("fs",Dba.LValue.vfs);("gs",Dba.LValue.vgs);("ss",Dba.LValue.vss);("fs_base",Dba.LValue.vfs_base);("gs_base",Dba.LValue.vgs_base);("ymm0",Dba.LValue.vymm0);("ymm1",Dba.LValue.vymm1);("ymm2",Dba.LValue.vymm2);("ymm3",Dba.LValue.vymm3);("ymm4",Dba.LValue.vymm4);("ymm5",Dba.LValue.vymm5);("ymm6",Dba.LValue.vymm6);("ymm7",Dba.LValue.vymm7);("ymm8",Dba.LValue.vymm8);("ymm9",Dba.LValue.vymm9);("ymm10",Dba.LValue.vymm10);("ymm11",Dba.LValue.vymm11);("ymm12",Dba.LValue.vymm12);("ymm13",Dba.LValue.vymm13);("ymm14",Dba.LValue.vymm14);("ymm15",Dba.LValue.vymm15);("xmm0",Dba.LValue.restrictymm00127);("xmm1",Dba.LValue.restrictymm10127);("xmm2",Dba.LValue.restrictymm20127);("xmm3",Dba.LValue.restrictymm30127);("xmm4",Dba.LValue.restrictymm40127);("xmm5",Dba.LValue.restrictymm50127);("xmm6",Dba.LValue.restrictymm60127);("xmm7",Dba.LValue.restrictymm70127);("xmm8",Dba.LValue.restrictymm80127);("xmm9",Dba.LValue.restrictymm90127);("xmm10",Dba.LValue.restrictymm100127);("xmm11",Dba.LValue.restrictymm110127);("xmm12",Dba.LValue.restrictymm120127);("xmm13",Dba.LValue.restrictymm130127);("xmm14",Dba.LValue.restrictymm140127);("xmm15",Dba.LValue.restrictymm150127);("cf",Dba.LValue.vcf);("pf",Dba.LValue.vpf);("af",Dba.LValue.vaf);("zf",Dba.LValue.vzf);("sf",Dba.LValue.vsf);("tf",Dba.LValue.vtf);("if",Dba.LValue.vif');("df",Dba.LValue.vdf);("of",Dba.LValue.vof');("iopl",Dba.LValue.viopl);("nt",Dba.LValue.vnt);("rf",Dba.LValue.vrf);("vm",Dba.LValue.vvm);("ac",Dba.LValue.vac);("vif",Dba.LValue.vvif');("vip",Dba.LValue.vvip);("id",Dba.LValue.vid);]letshortlived_flags=[cf;pf;af;zf;sf;of']letget_shortlived_flags()=shortlived_flagsletget_defs()=defsletymmx=[ymm0;ymm1;ymm2;ymm3;ymm4;ymm5;ymm6;ymm7;ymm8;ymm9;ymm10;ymm11;ymm12;ymm13;ymm14;ymm15;]letnotesimg=letentrypoint,defs,lymmx,hymmx=Array.fold_left(fun((entrypoint,defs,lymmx,hymmx)asresult)->function|{Loader_elf.Note.name="CORE";kind=1;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimginReader.advancecursor0x70;letvr15=Dba.Expr.constant(Reader.Read.bv64cursor)inletvr14=Dba.Expr.constant(Reader.Read.bv64cursor)inletvr13=Dba.Expr.constant(Reader.Read.bv64cursor)inletvr12=Dba.Expr.constant(Reader.Read.bv64cursor)inletvrbp=Dba.Expr.constant(Reader.Read.bv64cursor)inletvrbx=Dba.Expr.constant(Reader.Read.bv64cursor)inletvr11=Dba.Expr.constant(Reader.Read.bv64cursor)inletvr10=Dba.Expr.constant(Reader.Read.bv64cursor)inletvr9=Dba.Expr.constant(Reader.Read.bv64cursor)inletvr8=Dba.Expr.constant(Reader.Read.bv64cursor)inletvrax=Dba.Expr.constant(Reader.Read.bv64cursor)inletvrcx=Dba.Expr.constant(Reader.Read.bv64cursor)inletvrdx=Dba.Expr.constant(Reader.Read.bv64cursor)inletvrsi=Dba.Expr.constant(Reader.Read.bv64cursor)inletvrdi=Dba.Expr.constant(Reader.Read.bv64cursor)inReader.advancecursor8;letvrip=Virtual_address.of_bitvector(Reader.Read.bv64cursor)inletvcs=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor6;letrflags_15_0=Uint16.to_int(Reader.Read.u16cursor)inletrflags_31_16=Uint16.to_int(Reader.Read.u16cursor)inReader.advancecursor4;letvrsp=Dba.Expr.constant(Reader.Read.bv64cursor)inletvss=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor6;letvfs_base=Dba.Expr.constant(Reader.Read.bv64cursor)inletvgs_base=Dba.Expr.constant(Reader.Read.bv64cursor)inletvds=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor6;letves=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor6;letvfs=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor6;letvgs=Dba.Expr.constant(Reader.Read.bv16cursor)inReader.advancecursor6;letvcf=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr0)land0b1))andvpf=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr2)land0b1))andvaf=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr4)land0b1))andvzf=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr6)land0b1))andvsf=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr7)land0b1))andvtf=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr8)land0b1))andvif=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr9)land0b1))andvdf=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr10)land0b1))andvof=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr11)land0b1))andviopl=Dba.Expr.constant(Bitvector.of_int~size:2((rflags_15_0lsr12)land0b11))andvnt=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_15_0lsr14)land0b1))andvrf=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_31_16lsr0)land0b1))andvvm=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_31_16lsr1)land0b1))andvac=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_31_16lsr2)land0b1))andvvif=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_31_16lsr3)land0b1))andvvip=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_31_16lsr4)land0b1))andvid=Dba.Expr.constant(Bitvector.of_int~size:1((rflags_31_16lsr5)land0b1))in(vrip,List.rev_append[(r15,vr15);(r14,vr14);(r13,vr13);(r12,vr12);(r11,vr11);(r10,vr10);(r9,vr9);(r8,vr8);(rbx,vrbx);(rcx,vrcx);(rdx,vrdx);(rsi,vrsi);(rdi,vrdi);(rbp,vrbp);(rax,vrax);(rsp,vrsp);(ds,vds);(es,ves);(fs,vfs);(gs,vgs);(cs,vcs);(ss,vss);(fs_base,vfs_base);(gs_base,vgs_base);(cf,vcf);(pf,vpf);(af,vaf);(zf,vzf);(sf,vsf);(tf,vtf);(if',vif);(df,vdf);(of',vof);(iopl,viopl);(nt,vnt);(rf,vrf);(vm,vvm);(ac,vac);(vif',vvif);(vip,vvip);(id,vid);]defs,lymmx,hymmx)|{Loader_elf.Note.name="CORE";kind=2;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimginReader.advancecursor0xa0;(entrypoint,defs,List.map(fun_->Dba.Expr.constant(Reader.Read.readcursor16))ymmx,hymmx)|{Loader_elf.Note.name="LINUX";kind=0x202;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimginReader.advancecursor0x200;letcomponent=Uint16.to_int(Reader.Peek.u16cursor)inlethymmx=ifcomponentland0b00000100<>0then(Reader.advancecursor0x40;List.map(fun_->Dba.Expr.constant(Reader.Read.readcursor16))ymmx)elsehymmxinletlymmx=ifcomponentland0b00000010<>0then(letcursor=Loader_elf.Img.cursor~atimginReader.advancecursor0xa0;List.map(fun_->Dba.Expr.constant(Reader.Read.readcursor16))ymmx)elselymmxin(entrypoint,defs,lymmx,hymmx)|_->result)(Virtual_address.create0,[],[],[])(Loader_elf.notesimg)inletvymmx=match(hymmx,lymmx)with|[],[]->[]|_,[]->List.map(funh->Dba.Expr.(appendh(zeros128)))hymmx|[],_->List.map(funl->Dba.Expr.uext256l)lymmx|_,_->List.map2(funhl->Dba.Expr.appendhl)hymmxlymmxin(entrypoint,ifvymmx<>[]thenList.fold_left2(fundefsrv->(r,v)::defs)defsymmxvymmxelsedefs)letcore=notesletret=Dba.LValue.vraxletrsp_l=Dba.LValue.vrspandrsp_r=Dba.Expr.vrspandrax_l=Dba.LValue.vraxandrax_r=Dba.Expr.vraxandrbx_r=Dba.Expr.vrbxandrbp_r=Dba.Expr.vrbpandrdi_r=Dba.Expr.vrdiandrsi_r=Dba.Expr.vrsiandrdx_r=Dba.Expr.vrdxandrcx_r=Dba.Expr.vrcxandr8_r=Dba.Expr.vr8andr9_r=Dba.Expr.vr9andr10_r=Dba.Expr.vr10andr11_r=Dba.Expr.vr11andr12_r=Dba.Expr.vr12andr13_r=Dba.Expr.vr13andr14_r=Dba.Expr.vr14andr15_r=Dba.Expr.vr15andeight=Dba.Expr.constant(Bitvector.of_int~size:648)letreturn_address=Dba.Expr.loadSize.Byte.eightLittleEndianrsp_rletget_return_address()=return_addressletget_arg?(syscall=false)i=ifsyscallthenmatchiwith|0->rdi_r|1->rsi_r|2->rdx_r|3->r10_r|4->r8_r|5->r9_r|_->raise(Invalid_argument"syscall")elsematchiwith|0->rdi_r|1->rsi_r|2->rdx_r|3->rcx_r|4->r8_r|5->r9_r|i->Dba.Expr.loadSize.Byte.eightLittleEndian(Dba.Expr.addrsp_r(Dba.Expr.constant(Bitvector.of_int~size:64(8*(i-5)))))letget_ret?syscall:_()=retletvoid_return=Dhunk.init2(function|0->Dba.Instr.assignrsp_l(Dba.Expr.addrsp_reight)1|_->Dba.Instr.dynamic_jump~tag:Return(Dba.Expr.loadSize.Byte.eightLittleEndian(Dba.Expr.subrsp_reight)))andval_returnvalue=Dhunk.init3(function|0->Dba.Instr.assignrax_lvalue1|1->Dba.Instr.assignrsp_l(Dba.Expr.addrsp_reight)2|_->Dba.Instr.dynamic_jump~tag:Return(Dba.Expr.loadSize.Byte.eightLittleEndian(Dba.Expr.subrsp_reight)))letmake_return?value()=match(value:Dba.Expr.toption)with|None->void_return|Some(Varv)whenDba.Var.equalvrax->void_return|Somevalue->val_returnvalueletget_stack_pointer()=(rsp,Bitvector.of_int640x7fff000000000000L)letget_dwarf_register=function|0->rax_r|1->rdx_r|2->rcx_r|3->rbx_r|4->rsi_r|5->rdi_r|6->rbp_r|7->rsp_r|8->r8_r|9->r9_r|10->r10_r|11->r11_r|12->r12_r|13->r13_r|14->r14_r|15->r15_r|n->Isa_logger.fatal"unable to map integer %d to a known DWARF register"nletmax_instruction_len=Size.Byte.fifteenendmoduleARM:ARCH=structletinfo=Dba.Var.Tag.Registerletrx=Array.init11(funi->Dba.Var.create(Format.sprintf"r%d"i)~bitsize:Size.Bit.bits32~tag:info)letr0=Array.getrx0andr1=Array.getrx1andr2=Array.getrx2andr3=Array.getrx3andr4=Array.getrx4andr5=Array.getrx5andr6=Array.getrx6andr7=Array.getrx7andr8=Array.getrx8andr9=Array.getrx9andr10=Array.getrx10andr11=Dba.Var.create"fp"~bitsize:Size.Bit.bits32~tag:infoandr12=Dba.Var.create"ip"~bitsize:Size.Bit.bits32~tag:infoandr13=Dba.Var.create"sp"~bitsize:Size.Bit.bits32~tag:infoandr14=Dba.Var.create"lr"~bitsize:Size.Bit.bits32~tag:infoandr15=Dba.Var.create"pc"~bitsize:Size.Bit.bits32~tag:info(* note that pc is not used nor updated by the DBA semantics -- do not use it outside of debug information *)letdx=Array.init32(funi->Dba.Var.create(Format.sprintf"d%d"i)~bitsize:Size.Bit.bits64~tag:info)letinfo=Dba.Var.Tag.Flagletn=Dba.Var.create"n"~bitsize:Size.Bit.bits1~tag:infoandz=Dba.Var.create"z"~bitsize:Size.Bit.bits1~tag:infoandc=Dba.Var.create"c"~bitsize:Size.Bit.bits1~tag:infoandv=Dba.Var.create"v"~bitsize:Size.Bit.bits1~tag:infoandt=Dba.Var.create"t"~bitsize:Size.Bit.bits1~tag:infoletdefs=[("r0",Dba.LValue.vr0);("r1",Dba.LValue.vr1);("r2",Dba.LValue.vr2);("r3",Dba.LValue.vr3);("r4",Dba.LValue.vr4);("r5",Dba.LValue.vr5);("r6",Dba.LValue.vr6);("r7",Dba.LValue.vr7);("r8",Dba.LValue.vr8);("r9",Dba.LValue.vr9);("r10",Dba.LValue.vr10);("r11",Dba.LValue.vr11);("r12",Dba.LValue.vr12);("r13",Dba.LValue.vr13);("r14",Dba.LValue.vr14);("r15",Dba.LValue.vr15);("fp",Dba.LValue.vr11);("ip",Dba.LValue.vr12);("sp",Dba.LValue.vr13);("lr",Dba.LValue.vr14);("pc",Dba.LValue.vr15);("n",Dba.LValue.vn);("z",Dba.LValue.vz);("c",Dba.LValue.vc);("v",Dba.LValue.vv);("t",Dba.LValue.vt);]letget_shortlived_flags()=[]letcoreimg=Array.fold_left(fun((entrypoint,defs)asresult)->function|{Loader_elf.Note.name="CORE";kind=1;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimginReader.advancecursor0x48;letvr0=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr1=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr2=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr3=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr4=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr5=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr6=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr7=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr8=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr9=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr10=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr11=Dba.Expr.constant(Reader.Read.bv32cursor)inletvr12=Dba.Expr.constant(Reader.Read.bv32cursor)inletvsp=Dba.Expr.constant(Reader.Read.bv32cursor)inletvlr=Dba.Expr.constant(Reader.Read.bv32cursor)inletvpc=Virtual_address.of_bitvector(Reader.Read.bv32cursor)inReader.advancecursor3;letspsr_31_24=Uint8.to_int(Reader.Read.u8cursor)inletvn=Dba.Expr.constant(Bitvector.of_int~size:1((spsr_31_24lsr7)land0b1))andvz=Dba.Expr.constant(Bitvector.of_int~size:1((spsr_31_24lsr6)land0b1))andvc=Dba.Expr.constant(Bitvector.of_int~size:1((spsr_31_24lsr5)land0b1))andvv=Dba.Expr.constant(Bitvector.of_int~size:1((spsr_31_24lsr4)land0b1))in(vpc,List.rev_append[(r0,vr0);(r1,vr1);(r2,vr2);(r3,vr3);(r4,vr4);(r5,vr5);(r6,vr6);(r7,vr7);(r8,vr8);(r9,vr9);(r10,vr10);(r11,vr11);(r12,vr12);(r13,vsp);(r14,vlr);(n,vn);(z,vz);(c,vc);(v,vv);]defs)|{Loader_elf.Note.name="LINUX";kind=0x400;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimgin(entrypoint,Array.fold_left(fundefsd->(d,Dba.Expr.constant(Reader.Read.readcursor8))::defs)defsdx)|_->result)(Virtual_address.create0,[])(Loader_elf.notesimg)letget_defs()=defsletr0_l=Dba.LValue.vr0andr0_r=Dba.Expr.vr0andr1_r=Dba.Expr.vr1andr2_r=Dba.Expr.vr2andr3_r=Dba.Expr.vr3andr13_r=Dba.Expr.vr13andr14_r=Dba.Expr.vr14andr15_r=Dba.Expr.vr15letret=r0_lletget_return_address()=r14_rletget_arg?(syscall=false)i=ifsyscallthenErrors.not_yet_implemented"syscall";matchiwith|0->r0_r|1->r1_r|2->r2_r|3->r3_r|i->Dba.Expr.loadSize.Byte.fourLittleEndian(Dba.Expr.addr13_r(Dba.Expr.constant(Bitvector.of_int~size:32(4*(i-4)))))letget_ret?syscall:_()=retletvoid_return=Dhunk.singleton(Dba.Instr.dynamic_jump~tag:Returnr14_r)andval_returnvalue=Dhunk.init2(function|0->Dba.Instr.assignr0_lvalue1|_->Dba.Instr.dynamic_jump~tag:Returnr14_r)letmake_return?value()=match(value:Dba.Expr.toption)with|None->void_return|Some(Varv)whenDba.Var.equalvr0->void_return|Somevalue->val_returnvalueletget_stack_pointer()=(r13,Bitvector.of_int320xfff00000l)letrx_r=Array.mapDba.Expr.vrxandsl_r=Dba.Expr.vr10andfp_r=Dba.Expr.vr11andip_r=Dba.Expr.vr12letget_dwarf_register=function|(0|1|2|3|4|5|6|7|8|9)asn->Array.getrx_rn|10->sl_r|11->fp_r|12->ip_r|13->r13_r|14->r14_r|15->r15_r|n->Isa_logger.fatal"unable to map integer %d to a known expression"nletmax_instruction_len=Size.Byte.fourendmoduleAARCH64:ARCH=structletinfo=Dba.Var.Tag.Registerletrx=Array.init31(funi->Dba.Var.create(Format.sprintf"x%d"i)~bitsize:Size.Bit.bits64~tag:info)letx0=Array.getrx0andx1=Array.getrx1andx2=Array.getrx2andx3=Array.getrx3andx4=Array.getrx4andx5=Array.getrx5andx6=Array.getrx6andx7=Array.getrx7andx8=Array.getrx8andx9=Array.getrx9andx10=Array.getrx10andx11=Array.getrx11andx12=Array.getrx12andx13=Array.getrx13andx14=Array.getrx14andx15=Array.getrx15andx16=Array.getrx16andx17=Array.getrx17andx18=Array.getrx18andx19=Array.getrx19andx20=Array.getrx20andx21=Array.getrx21andx22=Array.getrx22andx23=Array.getrx23andx24=Array.getrx24andx25=Array.getrx25andx26=Array.getrx26andx27=Array.getrx27andx28=Array.getrx28andx29=Array.getrx29andx30=Array.getrx30andsp=Dba.Var.create"sp"~bitsize:Size.Bit.bits64~tag:infoletinfo=Dba.Var.Tag.Flagletn=Dba.Var.create"n"~bitsize:Size.Bit.bits1~tag:infoandz=Dba.Var.create"z"~bitsize:Size.Bit.bits1~tag:infoandc=Dba.Var.create"c"~bitsize:Size.Bit.bits1~tag:infoandv=Dba.Var.create"v"~bitsize:Size.Bit.bits1~tag:infoletinfo=Dba.Var.Tag.Registerletqx=Array.init32(funi->Dba.Var.create(Format.sprintf"q%d"i)~bitsize:Size.Bit.bits128~tag:info)letq0=Array.getqx0andq1=Array.getqx1andq2=Array.getqx2andq3=Array.getqx3andq4=Array.getqx4andq5=Array.getqx5andq6=Array.getqx6andq7=Array.getqx7andq8=Array.getqx8andq9=Array.getqx9andq10=Array.getqx10andq11=Array.getqx11andq12=Array.getqx12andq13=Array.getqx13andq14=Array.getqx14andq15=Array.getqx15andq16=Array.getqx16andq17=Array.getqx17andq18=Array.getqx18andq19=Array.getqx19andq20=Array.getqx20andq21=Array.getqx21andq22=Array.getqx22andq23=Array.getqx23andq24=Array.getqx24andq25=Array.getqx25andq26=Array.getqx26andq27=Array.getqx27andq28=Array.getqx28andq29=Array.getqx29andq30=Array.getqx30andq31=Array.getqx31letdefs=[("r0",Dba.LValue.vx0);("r1",Dba.LValue.vx1);("r2",Dba.LValue.vx2);("r3",Dba.LValue.vx3);("r4",Dba.LValue.vx4);("r5",Dba.LValue.vx5);("r6",Dba.LValue.vx6);("r7",Dba.LValue.vx7);("r8",Dba.LValue.vx8);("r9",Dba.LValue.vx9);("r10",Dba.LValue.vx10);("r11",Dba.LValue.vx11);("r12",Dba.LValue.vx12);("r13",Dba.LValue.vx13);("r14",Dba.LValue.vx14);("r15",Dba.LValue.vx15);("r16",Dba.LValue.vx16);("r17",Dba.LValue.vx17);("r18",Dba.LValue.vx18);("r19",Dba.LValue.vx19);("r20",Dba.LValue.vx20);("r21",Dba.LValue.vx21);("r22",Dba.LValue.vx22);("r23",Dba.LValue.vx23);("r24",Dba.LValue.vx24);("r25",Dba.LValue.vx25);("r26",Dba.LValue.vx26);("r27",Dba.LValue.vx27);("r28",Dba.LValue.vx28);("r29",Dba.LValue.vx29);("r30",Dba.LValue.vx30);("x0",Dba.LValue.vx0);("x1",Dba.LValue.vx1);("x2",Dba.LValue.vx2);("x3",Dba.LValue.vx3);("x4",Dba.LValue.vx4);("x5",Dba.LValue.vx5);("x6",Dba.LValue.vx6);("x7",Dba.LValue.vx7);("x8",Dba.LValue.vx8);("x9",Dba.LValue.vx9);("x10",Dba.LValue.vx10);("x11",Dba.LValue.vx11);("x12",Dba.LValue.vx12);("x13",Dba.LValue.vx13);("x14",Dba.LValue.vx14);("x15",Dba.LValue.vx15);("x16",Dba.LValue.vx16);("x17",Dba.LValue.vx17);("x18",Dba.LValue.vx18);("x19",Dba.LValue.vx19);("x20",Dba.LValue.vx20);("x21",Dba.LValue.vx21);("x22",Dba.LValue.vx22);("x23",Dba.LValue.vx23);("x24",Dba.LValue.vx24);("x25",Dba.LValue.vx25);("x26",Dba.LValue.vx26);("x27",Dba.LValue.vx27);("x28",Dba.LValue.vx28);("x29",Dba.LValue.vx29);("x30",Dba.LValue.vx30);("sp",Dba.LValue.vsp);("w0",Dba.LValue.restrictx0031);("w1",Dba.LValue.restrictx1031);("w2",Dba.LValue.restrictx2031);("w3",Dba.LValue.restrictx3031);("w4",Dba.LValue.restrictx4031);("w5",Dba.LValue.restrictx5031);("w6",Dba.LValue.restrictx6031);("w7",Dba.LValue.restrictx7031);("w8",Dba.LValue.restrictx8031);("w9",Dba.LValue.restrictx9031);("w10",Dba.LValue.restrictx10031);("w11",Dba.LValue.restrictx11031);("w12",Dba.LValue.restrictx12031);("w13",Dba.LValue.restrictx13031);("w14",Dba.LValue.restrictx14031);("w15",Dba.LValue.restrictx15031);("w16",Dba.LValue.restrictx16031);("w17",Dba.LValue.restrictx17031);("w18",Dba.LValue.restrictx18031);("w19",Dba.LValue.restrictx19031);("w20",Dba.LValue.restrictx20031);("w21",Dba.LValue.restrictx21031);("w22",Dba.LValue.restrictx22031);("w23",Dba.LValue.restrictx23031);("w24",Dba.LValue.restrictx24031);("w25",Dba.LValue.restrictx25031);("w26",Dba.LValue.restrictx26031);("w27",Dba.LValue.restrictx27031);("w28",Dba.LValue.restrictx28031);("w29",Dba.LValue.restrictx29031);("w30",Dba.LValue.restrictx30031);("n",Dba.LValue.vn);("z",Dba.LValue.vz);("c",Dba.LValue.vc);("v",Dba.LValue.vv);("q0",Dba.LValue.vq0);("q1",Dba.LValue.vq1);("q2",Dba.LValue.vq2);("q3",Dba.LValue.vq3);("q4",Dba.LValue.vq4);("q5",Dba.LValue.vq5);("q6",Dba.LValue.vq6);("q7",Dba.LValue.vq7);("q8",Dba.LValue.vq8);("q9",Dba.LValue.vq9);("q10",Dba.LValue.vq10);("q11",Dba.LValue.vq11);("q12",Dba.LValue.vq12);("q13",Dba.LValue.vq13);("q14",Dba.LValue.vq14);("q15",Dba.LValue.vq15);("q16",Dba.LValue.vq16);("q17",Dba.LValue.vq17);("q18",Dba.LValue.vq18);("q19",Dba.LValue.vq19);("q20",Dba.LValue.vq20);("q21",Dba.LValue.vq21);("q22",Dba.LValue.vq22);("q23",Dba.LValue.vq23);("q24",Dba.LValue.vq24);("q25",Dba.LValue.vq25);("q26",Dba.LValue.vq26);("q27",Dba.LValue.vq27);("q28",Dba.LValue.vq28);("q29",Dba.LValue.vq29);("q30",Dba.LValue.vq30);("q31",Dba.LValue.vq31);("d0",Dba.LValue.restrictq0063);("d1",Dba.LValue.restrictq1063);("d2",Dba.LValue.restrictq2063);("d3",Dba.LValue.restrictq3063);("d4",Dba.LValue.restrictq4063);("d5",Dba.LValue.restrictq5063);("d6",Dba.LValue.restrictq6063);("d7",Dba.LValue.restrictq7063);("d8",Dba.LValue.restrictq8063);("d9",Dba.LValue.restrictq9063);("d10",Dba.LValue.restrictq10063);("d11",Dba.LValue.restrictq11063);("d12",Dba.LValue.restrictq12063);("d13",Dba.LValue.restrictq13063);("d14",Dba.LValue.restrictq14063);("d15",Dba.LValue.restrictq15063);("d16",Dba.LValue.restrictq16063);("d17",Dba.LValue.restrictq17063);("d18",Dba.LValue.restrictq18063);("d19",Dba.LValue.restrictq19063);("d20",Dba.LValue.restrictq20063);("d21",Dba.LValue.restrictq21063);("d22",Dba.LValue.restrictq22063);("d23",Dba.LValue.restrictq23063);("d24",Dba.LValue.restrictq24063);("d25",Dba.LValue.restrictq25063);("d26",Dba.LValue.restrictq26063);("d27",Dba.LValue.restrictq27063);("d28",Dba.LValue.restrictq28063);("d29",Dba.LValue.restrictq29063);("d30",Dba.LValue.restrictq30063);("d31",Dba.LValue.restrictq31063);("s0",Dba.LValue.restrictq0031);("s1",Dba.LValue.restrictq1031);("s2",Dba.LValue.restrictq2031);("s3",Dba.LValue.restrictq3031);("s4",Dba.LValue.restrictq4031);("s5",Dba.LValue.restrictq5031);("s6",Dba.LValue.restrictq6031);("s7",Dba.LValue.restrictq7031);("s8",Dba.LValue.restrictq8031);("s9",Dba.LValue.restrictq9031);("s10",Dba.LValue.restrictq10031);("s11",Dba.LValue.restrictq11031);("s12",Dba.LValue.restrictq12031);("s13",Dba.LValue.restrictq13031);("s14",Dba.LValue.restrictq14031);("s15",Dba.LValue.restrictq15031);("s16",Dba.LValue.restrictq16031);("s17",Dba.LValue.restrictq17031);("s18",Dba.LValue.restrictq18031);("s19",Dba.LValue.restrictq19031);("s20",Dba.LValue.restrictq20031);("s21",Dba.LValue.restrictq21031);("s22",Dba.LValue.restrictq22031);("s23",Dba.LValue.restrictq23031);("s24",Dba.LValue.restrictq24031);("s25",Dba.LValue.restrictq25031);("s26",Dba.LValue.restrictq26031);("s27",Dba.LValue.restrictq27031);("s28",Dba.LValue.restrictq28031);("s29",Dba.LValue.restrictq29031);("s30",Dba.LValue.restrictq30031);("s31",Dba.LValue.restrictq31031);("h0",Dba.LValue.restrictq0015);("h1",Dba.LValue.restrictq1015);("h2",Dba.LValue.restrictq2015);("h3",Dba.LValue.restrictq3015);("h4",Dba.LValue.restrictq4015);("h5",Dba.LValue.restrictq5015);("h6",Dba.LValue.restrictq6015);("h7",Dba.LValue.restrictq7015);("h8",Dba.LValue.restrictq8015);("h9",Dba.LValue.restrictq9015);("h10",Dba.LValue.restrictq10015);("h11",Dba.LValue.restrictq11015);("h12",Dba.LValue.restrictq12015);("h13",Dba.LValue.restrictq13015);("h14",Dba.LValue.restrictq14015);("h15",Dba.LValue.restrictq15015);("h16",Dba.LValue.restrictq16015);("h17",Dba.LValue.restrictq17015);("h18",Dba.LValue.restrictq18015);("h19",Dba.LValue.restrictq19015);("h20",Dba.LValue.restrictq20015);("h21",Dba.LValue.restrictq21015);("h22",Dba.LValue.restrictq22015);("h23",Dba.LValue.restrictq23015);("h24",Dba.LValue.restrictq24015);("h25",Dba.LValue.restrictq25015);("h26",Dba.LValue.restrictq26015);("h27",Dba.LValue.restrictq27015);("h28",Dba.LValue.restrictq28015);("h29",Dba.LValue.restrictq29015);("h30",Dba.LValue.restrictq30015);("h31",Dba.LValue.restrictq31015);("b0",Dba.LValue.restrictq007);("b1",Dba.LValue.restrictq107);("b2",Dba.LValue.restrictq207);("b3",Dba.LValue.restrictq307);("b4",Dba.LValue.restrictq407);("b5",Dba.LValue.restrictq507);("b6",Dba.LValue.restrictq607);("b7",Dba.LValue.restrictq707);("b8",Dba.LValue.restrictq807);("b9",Dba.LValue.restrictq907);("b10",Dba.LValue.restrictq1007);("b11",Dba.LValue.restrictq1107);("b12",Dba.LValue.restrictq1207);("b13",Dba.LValue.restrictq1307);("b14",Dba.LValue.restrictq1407);("b15",Dba.LValue.restrictq1507);("b16",Dba.LValue.restrictq1607);("b17",Dba.LValue.restrictq1707);("b18",Dba.LValue.restrictq1807);("b19",Dba.LValue.restrictq1907);("b20",Dba.LValue.restrictq2007);("b21",Dba.LValue.restrictq2107);("b22",Dba.LValue.restrictq2207);("b23",Dba.LValue.restrictq2307);("b24",Dba.LValue.restrictq2407);("b25",Dba.LValue.restrictq2507);("b26",Dba.LValue.restrictq2607);("b27",Dba.LValue.restrictq2707);("b28",Dba.LValue.restrictq2807);("b29",Dba.LValue.restrictq2907);("b30",Dba.LValue.restrictq3007);("b31",Dba.LValue.restrictq3107);]letget_shortlived_flags()=[]letcoreimg=Array.fold_left(fun((entrypoint,defs)asresult)->function|{Loader_elf.Note.name="CORE";kind=1;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimginReader.advancecursor0x70;letvx0=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx1=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx2=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx3=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx4=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx5=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx6=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx7=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx8=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx9=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx10=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx11=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx12=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx13=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx14=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx15=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx16=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx17=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx18=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx19=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx20=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx21=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx22=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx23=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx24=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx25=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx26=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx27=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx28=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx29=Dba.Expr.constant(Reader.Read.bv64cursor)inletvx30=Dba.Expr.constant(Reader.Read.bv64cursor)inletvsp=Dba.Expr.constant(Reader.Read.bv64cursor)inletvpc=Virtual_address.of_bitvector(Reader.Read.bv64cursor)inReader.advancecursor3;letspsr_31_24=Uint8.to_int(Reader.Read.u8cursor)inletvn=Dba.Expr.constant(Bitvector.of_int~size:1((spsr_31_24lsr7)land0b1))andvz=Dba.Expr.constant(Bitvector.of_int~size:1((spsr_31_24lsr6)land0b1))andvc=Dba.Expr.constant(Bitvector.of_int~size:1((spsr_31_24lsr5)land0b1))andvv=Dba.Expr.constant(Bitvector.of_int~size:1((spsr_31_24lsr4)land0b1))in(vpc,List.rev_append[(x0,vx0);(x1,vx1);(x2,vx2);(x3,vx3);(x4,vx4);(x5,vx5);(x6,vx6);(x7,vx7);(x8,vx8);(x9,vx9);(x10,vx10);(x11,vx11);(x12,vx12);(x13,vx13);(x14,vx14);(x15,vx15);(x16,vx16);(x17,vx17);(x18,vx18);(x19,vx19);(x20,vx20);(x21,vx21);(x22,vx22);(x23,vx23);(x24,vx24);(x25,vx25);(x26,vx26);(x27,vx27);(x28,vx28);(x29,vx29);(x30,vx30);(sp,vsp);(n,vn);(z,vz);(c,vc);(v,vv);]defs)|{Loader_elf.Note.name="CORE";kind=2;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimgin(entrypoint,Array.fold_left(fundefsq->(q,Dba.Expr.constant(Reader.Read.readcursor16))::defs)defsqx)|_->result)(Virtual_address.create0,[])(Loader_elf.notesimg)letget_defs()=defsletx0_l=Dba.LValue.vx0andx0_r=Dba.Expr.vx0andx1_r=Dba.Expr.vx1andx2_r=Dba.Expr.vx2andx3_r=Dba.Expr.vx3andx4_r=Dba.Expr.vx4andx5_r=Dba.Expr.vx5andx6_r=Dba.Expr.vx6andx7_r=Dba.Expr.vx7andx30_r=Dba.Expr.vx30andsp_r=Dba.Expr.vspletret=x0_lletget_return_address()=x30_rletget_arg?(syscall=false)i=ifsyscallthenErrors.not_yet_implemented"syscall";matchiwith|0->x0_r|1->x1_r|2->x2_r|3->x3_r|4->x4_r|5->x5_r|6->x6_r|7->x7_r|i->Dba.Expr.loadSize.Byte.fourLittleEndian(Dba.Expr.addsp_r(Dba.Expr.constant(Bitvector.of_int~size:64(8*(i-8)))))letget_ret?syscall:_()=retletvoid_return=Dhunk.singleton(Dba.Instr.dynamic_jump~tag:Returnx30_r)andval_returnvalue=Dhunk.init2(function|0->Dba.Instr.assignx0_lvalue1|_->Dba.Instr.dynamic_jump~tag:Returnx30_r)letmake_return?value()=match(value:Dba.Expr.toption)with|None->void_return|Some(Varv)whenDba.Var.equalvx0->void_return|Somevalue->val_returnvalueletrx_r=Array.mapDba.Expr.vrxandpc_r=Dba.Expr.var"pc"64letget_dwarf_register=function|(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30)asn->Array.getrx_rn|31->sp_r|32->pc_r|n->Isa_logger.fatal"unable to map integer %d to a known expression"nletget_stack_pointer()=(sp,Bitvector.of_int640x7fff000000000000L)letmax_instruction_len=Size.Byte.fourendmodulePPC64:ARCH=structletrx=Array.init32(funi->Dba.Var.create(Format.sprintf"r%d"i)~bitsize:Size.Bit.bits64~tag:Register)letreg=Array.getrxletctr=Dba.Var.create"ctr"~bitsize:Size.Bit.bits64~tag:Registerletlr=Dba.Var.create"lr"~bitsize:Size.Bit.bits64~tag:Registerletxer=Dba.Var.create"xer"~bitsize:Size.Bit.bits64~tag:Registerletcrx=Array.init32(funi->letn=i/4inletc=matchimod4with0->"lt"|1->"gt"|2->"eq"|_->"so"inDba.Var.create(Format.sprintf"cr%d%s"nc)~bitsize:Size.Bit.bits1~tag:Flag)letdefs=letpush:(string*Dba.LValue.t)list->Dba.Var.t->(string*Dba.LValue.t)list=fundefs({name;_}asr)->(name,Dba.LValue.vr)::defsinArray.fold_leftpush(Array.fold_leftpush[("ctr",Dba.LValue.vctr);("lr",Dba.LValue.vlr);("xer",Dba.LValue.vxer);]crx)rxletget_shortlived_flags()=[]letcoreimg=Array.fold_left(fun((_,defs)asresult)->function|{Loader_elf.Note.name="CORE";kind=1;offset=at;_}->letcursor=Loader_elf.Img.cursor~atimginletpush:(Dba.Var.t*Dba.Expr.t)list->Dba.Var.t->(Dba.Var.t*Dba.Expr.t)list=funaccr->(r,Dba.Expr.constant(Reader.Read.bv64cursor))::accinReader.advancecursor0x70;letdefs=Array.fold_leftpushdefsrxinletvpc=Virtual_address.of_bitvector(Reader.Read.bv64cursor)inReader.advancecursor0x10;letdefs=pushdefsctrinletdefs=pushdefslrinletdefs=pushdefsxerinletccr=Reader.Read.bv64cursorinletdefs=Array_utils.fold_lefti(funiacccr->(cr,Dba.Expr.constant(Bitvector.extract~hi:i~lo:iccr))::acc)defscrxin(vpc,defs)|_->result)(Virtual_address.create0,[])(Loader_elf.notesimg)letget_defs()=defsletr3_l=Dba.LValue.v(reg3)andr3_r=Dba.Expr.v(reg3)andr4_r=Dba.Expr.v(reg4)andr5_r=Dba.Expr.v(reg5)andr6_r=Dba.Expr.v(reg6)andr7_r=Dba.Expr.v(reg7)andr8_r=Dba.Expr.v(reg8)andr9_r=Dba.Expr.v(reg9)andr10_r=Dba.Expr.v(reg10)andlr_r=Dba.Expr.vlrandr1_r=Dba.Expr.v(reg1)letret=r3_lletget_return_address()=lr_rletget_arg?(syscall=false)i=ifsyscallthenErrors.not_yet_implemented"syscall";matchiwith|0->r3_r|1->r4_r|2->r5_r|3->r6_r|4->r7_r|5->r8_r|6->r9_r|7->r10_r|i->Dba.Expr.loadSize.Byte.fourLittleEndian(Dba.Expr.addr1_r(Dba.Expr.constant(Bitvector.of_int~size:64(8*(i-8)))))letget_ret?syscall:_()=retletvoid_return=Dhunk.singleton(Dba.Instr.dynamic_jump~tag:Returnlr_r)andval_returnvalue=Dhunk.init2(function|0->Dba.Instr.assignr3_lvalue1|_->Dba.Instr.dynamic_jump~tag:Returnlr_r)letmake_return?value()=match(value:Dba.Expr.toption)with|None->void_return|Some(Varv)whenDba.Var.equalv(reg3)->void_return|Somevalue->val_returnvalueletget_stack_pointer()=(reg1,Bitvector.of_int640x7fff000000000000L)letget_dwarf_register_=Errors.not_yet_implemented"PPC64 dwarf mapping"letmax_instruction_len=Size.Byte.fourendmoduleRISCV(C:sigvalsize:intend):ARCH=structletregisters=Array.map(funname->Dba.Var.createname~bitsize:(Size.Bit.createC.size)~tag:Dba.Var.Tag.Register)[|"ra";"sp";"gp";"tp";"t0";"t1";"t2";"s0";"s1";"a0";"a1";"a2";"a3";"a4";"a5";"a6";"a7";"s2";"s3";"s4";"s5";"s6";"s7";"s8";"s9";"s10";"s11";"t3";"t4";"t5";"t6";|]letregi=Array.getregisters(i-1)letdefs=Array.to_list(Array.map(fun(var:Dba.Var.t)->(var.name,Dba.LValue.vvar))registers)letget_shortlived_flags()=[]letget_defs()=defsletcoreimg=Array.fold_left(fun((_,defs)asresult)->function|{Loader_elf.Note.name="CORE";kind=1;offset=at;size}->letcursor=Loader_elf.Img.cursor~atimginletoffset,read,entsz=ifC.size=32then(0x48,Reader.Read.bv32,4)else(0x70,Reader.Read.bv64,8)inReader.advancecursoroffset;letvpc=Virtual_address.of_bitvector(readcursor)inletrecloopniacc=ifi=nthenaccelseloopn(i+1)((regi,Dba.Expr.constant(readcursor))::acc)in(vpc,loop(max(((size-offset)/entsz)-2)31)1defs)|_->result)(Virtual_address.create0,[])(Loader_elf.notesimg)leta0=reg10leta0_l=Dba.LValue.va0anda0_r=Dba.Expr.va0anda1_r=Dba.Expr.v(reg11)anda2_r=Dba.Expr.v(reg12)anda3_r=Dba.Expr.v(reg13)anda4_r=Dba.Expr.v(reg14)anda5_r=Dba.Expr.v(reg15)anda6_r=Dba.Expr.v(reg16)anda7_r=Dba.Expr.v(reg17)andra_r=Dba.Expr.v(reg1)andsp_r=Dba.Expr.v(reg2)letbytesize=Size.Byte.create(C.size/8)letret=a0_lletget_return_address()=ra_rletget_arg?(syscall=false)i=ifsyscallthenErrors.not_yet_implemented"syscall";matchiwith|0->a0_r|1->a1_r|2->a2_r|3->a3_r|4->a4_r|5->a5_r|6->a6_r|7->a7_r|i->Dba.Expr.loadbytesizeLittleEndian(Dba.Expr.addsp_r(Dba.Expr.constant(Bitvector.of_int~size:C.size(C.size/8*(i-8)))))letget_ret?syscall:_()=retletvoid_return=Dhunk.singleton(Dba.Instr.dynamic_jump~tag:Returnra_r)andval_returnvalue=Dhunk.init2(function|0->Dba.Instr.assigna0_lvalue1|_->Dba.Instr.dynamic_jump~tag:Returnra_r)letmake_return?value()=match(value:Dba.Expr.toption)with|None->void_return|Some(Varv)whenDba.Var.equalva0->void_return|Somevalue->val_returnvalueletget_stack_pointer()=(reg2,matchC.sizewith|32->Bitvector.of_int320xfff00000l|64->Bitvector.of_int640x7fff000000000000L|_->raise(Errors.not_yet_implemented"incomplete architecture definition"))letget_dwarf_register_=Errors.not_yet_implemented"RISCV dwarf mapping"letmax_instruction_len=Size.Byte.fourendmoduleRISCV32=RISCV(structletsize=32end)moduleRISCV64=RISCV(structletsize=64end)moduleSPARCV8:ARCH=structletinfo=Dba.Var.Tag.Registerletrr=Array.init32(funi->Dba.Var.create(Format.sprintf"%c%d"(String.get"goli"(i/8))(imod8))~bitsize:Size.Bit.bits32~tag:info)letr0=Array.getrr0andr1=Array.getrr1andr2=Array.getrr2andr3=Array.getrr3andr4=Array.getrr4andr5=Array.getrr5andr6=Array.getrr6andr7=Array.getrr7andr8=Array.getrr8andr9=Array.getrr9andr10=Array.getrr10andr11=Array.getrr11andr12=Array.getrr12andr13=Array.getrr13andr14=Array.getrr14andr15=Array.getrr15andr16=Array.getrr16andr17=Array.getrr17andr18=Array.getrr18andr19=Array.getrr19andr20=Array.getrr20andr21=Array.getrr21andr22=Array.getrr22andr23=Array.getrr23andr24=Array.getrr24andr25=Array.getrr25andr26=Array.getrr26andr27=Array.getrr27andr28=Array.getrr28andr29=Array.getrr29andr30=Array.getrr30andr31=Array.getrr31letinfo=Dba.Var.Tag.Flagletn=Dba.Var.create"n"~bitsize:Size.Bit.bits1~tag:infoandz=Dba.Var.create"z"~bitsize:Size.Bit.bits1~tag:infoandc=Dba.Var.create"c"~bitsize:Size.Bit.bits1~tag:infoandv=Dba.Var.create"v"~bitsize:Size.Bit.bits1~tag:infoletdefs=[("r0",Dba.LValue.vr0);("r1",Dba.LValue.vr1);("r2",Dba.LValue.vr2);("r3",Dba.LValue.vr3);("r4",Dba.LValue.vr4);("r5",Dba.LValue.vr5);("r6",Dba.LValue.vr6);("r7",Dba.LValue.vr7);("r8",Dba.LValue.vr8);("r9",Dba.LValue.vr9);("r10",Dba.LValue.vr10);("r11",Dba.LValue.vr11);("r12",Dba.LValue.vr12);("r13",Dba.LValue.vr13);("r14",Dba.LValue.vr14);("r15",Dba.LValue.vr15);("r16",Dba.LValue.vr16);("r17",Dba.LValue.vr17);("r18",Dba.LValue.vr18);("r19",Dba.LValue.vr19);("r20",Dba.LValue.vr20);("r21",Dba.LValue.vr21);("r22",Dba.LValue.vr22);("r23",Dba.LValue.vr23);("r24",Dba.LValue.vr24);("r25",Dba.LValue.vr25);("r26",Dba.LValue.vr26);("r27",Dba.LValue.vr27);("r28",Dba.LValue.vr28);("r29",Dba.LValue.vr29);("r30",Dba.LValue.vr30);("r31",Dba.LValue.vr31);("g0",Dba.LValue.vr0);("g1",Dba.LValue.vr1);("g2",Dba.LValue.vr2);("g3",Dba.LValue.vr3);("g4",Dba.LValue.vr4);("g5",Dba.LValue.vr5);("g6",Dba.LValue.vr6);("g7",Dba.LValue.vr7);("o0",Dba.LValue.vr8);("o1",Dba.LValue.vr9);("o2",Dba.LValue.vr10);("o3",Dba.LValue.vr11);("o4",Dba.LValue.vr12);("o5",Dba.LValue.vr13);("o6",Dba.LValue.vr14);("o7",Dba.LValue.vr15);("l0",Dba.LValue.vr16);("l1",Dba.LValue.vr17);("l2",Dba.LValue.vr18);("l3",Dba.LValue.vr19);("l4",Dba.LValue.vr20);("l5",Dba.LValue.vr21);("l6",Dba.LValue.vr22);("l7",Dba.LValue.vr23);("i0",Dba.LValue.vr24);("i1",Dba.LValue.vr25);("i2",Dba.LValue.vr26);("i3",Dba.LValue.vr27);("i4",Dba.LValue.vr28);("i5",Dba.LValue.vr29);("i6",Dba.LValue.vr30);("i7",Dba.LValue.vr31);("sp",Dba.LValue.vr14);("fp",Dba.LValue.vr30);("n",Dba.LValue.vn);("z",Dba.LValue.vz);("c",Dba.LValue.vc);("v",Dba.LValue.vv);]letget_shortlived_flags()=[]letcore_=Errors.not_yet_implemented"SPARC core"letget_defs()=defsleto0_l=Dba.LValue.vr8ando0_r=Dba.Expr.vr8ando1_r=Dba.Expr.vr9ando2_r=Dba.Expr.vr10ando3_r=Dba.Expr.vr11ando4_r=Dba.Expr.vr12ando5_r=Dba.Expr.vr13andsp=r14letret=o0_lletreturn_address=Dba.Expr.add(Dba.Expr.vr15)(Dba.Expr.constant(Bitvector.of_int~size:328))letget_return_address()=return_addressletget_arg?(syscall=false)i=ifsyscallthenErrors.not_yet_implemented"syscall";matchiwith|0->o0_r|1->o1_r|2->o2_r|3->o3_r|4->o4_r|5->o5_r|_->Errors.not_yet_implemented"SPARC calling convention"letget_ret?syscall:_()=retletvoid_return=Dhunk.singleton(Dba.Instr.dynamic_jump~tag:Returnreturn_address)andval_returnvalue=Dhunk.init2(function|0->Dba.Instr.assigno0_lvalue1|_->Dba.Instr.dynamic_jump~tag:Returnreturn_address)letmake_return?value()=match(value:Dba.Expr.toption)with|None->void_return|Some(Varv)whenDba.Var.equalvr8->void_return|Somevalue->val_returnvalueletget_dwarf_register_=Errors.not_yet_implemented"SPARC DWARF register mapping"letget_stack_pointer()=(sp,Bitvector.of_int640x7fff000000000000L)letmax_instruction_len=Size.Byte.fourendmoduleZ80:ARCH=structletdefs=letaddrl=letname=Z80_arch.namerinletlval=Z80_arch.lvalrin(name,lval)::(String.lowercase_asciiname,lval)::linArray.fold_rightaddZ80_arch.registers16(Array.fold_rightaddZ80_arch.registers8(Array.fold_rightaddZ80_arch.flags[]))letget_shortlived_flags()=[]letget_defs()=defsletget_return_address()=Errors.not_yet_implemented"Z80 calling convention"letget_arg?syscall:__=Errors.not_yet_implemented"Z80 calling convention"letget_ret?syscall:_()=Errors.not_yet_implemented"Z80 calling convention"letmake_return?value:_()=Errors.not_yet_implemented"Z80 calling convention"letget_stack_pointer()=Errors.not_yet_implemented"Z80 definitions"letget_dwarf_register_=Errors.not_yet_implemented"Z80 dwarf mapping"letcore_=Errors.not_yet_implemented"Z80 core"letmax_instruction_len=Size.Byte.fourendmoduleUnknown:ARCH=structleterr=Invalid_argument"unknown architecture"letget_shortlived_flags()=raiseerrletget_defs()=raiseerrletget_return_address()=raiseerrletget_arg?syscall:__=raiseerrletget_ret?syscall:_()=raiseerrletmake_return?value:_()=raiseerrletget_stack_pointer()=raiseerrletget_dwarf_register_=raiseerrletcore_=raiseerrletmax_instruction_len=Size.Byte.oneendletget:Machine.t->(moduleARCH)=function|Unknown->(moduleUnknown)|X86{bits=`x32}->(moduleX86)|X86{bits=`x64}->(moduleAMD64)|ARM{rev=`v7_;endianness=LittleEndian}->(moduleARM)|ARM{rev=`v8;endianness=LittleEndian}->(moduleAARCH64)|PPC{bits=`x64;_}->(modulePPC64)|RISCV{bits=`x32}->(moduleRISCV32)|RISCV{bits=`x64}->(moduleRISCV64)|SPARC{rev=`v8}->(moduleSPARCV8)|Z80->(moduleZ80)|_->(* TODO *)Errors.not_yet_implemented"incomplete architecture definition"