text
stringlengths
12
786k
type section_details = { names : string list ; flags : string option ; args : string list }
let dwarf_sections_in_order ( ) = let sections = [ DWARF Debug_info ; DWARF Debug_abbrev ; DWARF Debug_aranges ; DWARF Debug_str ; DWARF Debug_line ] in let dwarf_version_dependent_sections = match ! Dwarf_flags . gdwarf_version with | Four -> [ DWARF Debug_loc ; DWARF Debug_ranges ] | Fi...
let details t ~ first_occurrence = let names , flags , args = match t , Target_system . derived_system ( ) with | DWARF dwarf , MacOS_like -> let name = match dwarf with | Debug_info -> " __debug_info " | Debug_abbrev -> " __debug_abbrev " | Debug_aranges -> " __debug_aranges " ...
let to_string t = let { names ; flags = _ ; args = _ } = details t ~ first_occurrence : true in String . concat " " names
let print ppf t = let str = match t with | DWARF Debug_info -> " ( DWARF Debug_info ) " | DWARF Debug_abbrev -> " ( DWARF Debug_abbrev ) " | DWARF Debug_aranges -> " ( DWARF Debug_aranges ) " | DWARF Debug_addr -> " ( DWARF Debug_addr ) " | DWARF Debug_loc -> " ( DWARF De...
let compare t1 t2 = Stdlib . compare t1 t2
let equal t1 t2 = Stdlib . compare t1 t2 = 0
let should_be_escaped = function | ' A ' . . ' Z ' | ' a ' . . ' z ' | ' 0 ' . . ' 9 ' | ' _ ' -> false | c -> true
module Thing = struct type t = string let compare = String . compare let equal = String . equal let hash = Hashtbl . hash let output chan t = Printf . fprintf chan " % s " t let print = Format . pp_print_string end
let create name = name
let escape name = let escaped_nb = ref 0 in for i = 0 to String . length name - 1 do if should_be_escaped ( String . unsafe_get name i ) then incr escaped_nb done ; if ! escaped_nb = 0 then name else let b = Buffer . create ( String . length name + ( 2 * ! escaped_nb ) ) in String ....
let symbol_prefix ( ) = match Target_system . architecture ( ) with | IA32 | X86_64 | AArch64 -> begin match Target_system . derived_system ( ) with | Linux | Win32 | Win64 | MinGW_32 | MinGW_64 | Cygwin | FreeBSD | NetBSD | OpenBSD | Generic_BSD | Solaris | BeOS | GNU | Dragonfly | ...
let to_escaped_string ? suffix ~ symbol_prefix t = let suffix = match suffix with None -> " " | Some suffix -> suffix in symbol_prefix ^ escape t ^ suffix
let encode ? without_prefix t = let symbol_prefix = match without_prefix with None -> symbol_prefix ( ) | Some ( ) -> " " in to_escaped_string ~ symbol_prefix t
module S = struct type ' a t = ' a Core . asn type ' a element = ' a Core . element type ' a sequence = ' a Core . sequence include Asn_combinators let ( error , parse_error ) = Core . ( error , parse_error ) end
type ' a t = ' a S . t
type encoding = { mk_decoder : ' a . ' a t -> Cstruct . t -> ' a * Cstruct . t ; mk_encoder : ' a . ' a t -> ' a -> Asn_writer . t }
let ber = { mk_decoder = Asn_ber_der . R . compile_ber ; mk_encoder = Asn_ber_der . W . ber_to_writer ; }
let der = { mk_decoder = Asn_ber_der . R . compile_der ; mk_encoder = Asn_ber_der . W . der_to_writer ; }
type ' a codec = Codec of ( Cstruct . t -> ( ' a * Cstruct . t ) ) * ( ' a -> Asn_writer . t )
let codec { mk_encoder ; mk_decoder } asn = let ( ) = Core . validate asn in Codec ( mk_decoder asn , mk_encoder asn )
let encode ( Codec ( _ , enc ) ) a = Asn_writer . to_cstruct ( enc a )
let encode_into ( Codec ( _ , enc ) ) a = Asn_writer . to_writer ( enc a )
let decode ( Codec ( dec , _ ) ) b = try Ok ( dec b ) with Core . Parse_error err -> Error err
let ( ) @? oa a = match oa with Some x -> x | None -> a
module Seq = struct type ' r f = { f : ' a . ' a -> ' a asn -> ' r -> ' r } let rec fold_with_value : type a . ' r f -> ' r -> a -> a sequence -> ' r = fun f r a -> function | Last ( Required ( _ , asn ) ) -> f . f a asn r | Last ( Optional ( _ , asn ) ) ...
module R = struct module G = Generic type config = { strict : bool } type coding = | Primitive of int | Constructed of int | Constructed_indefinite module Header = struct open Cstruct let error cs fmt = parse_error ( " Header : at % a : " ^^ fmt ) pp_cs cs let ck_redundant cs cfg ( n : int ...
module W = struct let ( ) <+> = Writer . ( ) <+> let e_big_tag tag = let cons x = function [ ] -> [ x ] | xs -> ( x lor 0x80 ) :: xs in let rec loop acc = function | 0 -> acc | n -> loop ( cons ( n land 0x7f ) acc ) ( n lsr 7 ) in loop [ ] tag let e_big_length le...
module Int = struct type t = int let compare ( a : t ) b = compare a b let equal ( a : t ) b = a = b end
let clone_cs cs = let open Cstruct in let ds = create_unsafe ( length cs ) in blit cs 0 ds 0 ( length cs ) ; cs
type cls = [ ` Universal | ` Application | ` Private ]
let fix f = Fix ( f , Asn_cache . variant ( ) )
let map ? random f g asn = Iso ( f , g , random , asn )
let to_tag id = function | Some ` Application -> Tag . Application id | Some ` Private -> Tag . Private id | Some ` Universal -> Tag . Universal id | None -> Tag . Context_specific id
let explicit ? cls id asn = Explicit ( to_tag id cls , asn )
let rec implicit : type a . ? cls : cls -> int -> a asn -> a asn = fun ? cls id -> function Fix ( f , _ ) as asn -> implicit ? cls id ( f asn ) | Iso ( f , g , r , asn ) -> Iso ( f , g , r , implicit ? cls id asn ) | Choice ( _ , _ ) as asn -> explicit ? cls id ...
let bool = Prim Bool
let string tag = implicit ~ cls ` : Universal tag character_string
let utf8_string = string 0x0c
let numeric_string = string 0x12
let ( utc_time , generalized_time ) = let open Asn_prim . Time in let time ~ frac tag ( f , g ) = map ~ random ( : random ~ frac ) f g @@ implicit ~ cls ` : Universal tag character_string in time ~ frac : false 0x17 ( utc_time_of_string , of_utc_time ) , time ~ frac : true 0x18...
let int = let f n = try Z . to_int n with Z . Overflow -> parse_error " INTEGER : int overflow : % a " Z . pp_print n in map f Z . of_int integer
let enumerated f g = map f g @@ implicit ~ cls ` : Universal 0x0a int
let bit_string = Prim . Bits . ( map to_array of_array ( Prim Bits ) ) let f = function | 0 , cs -> cs | clip , cs -> let n = Cstruct . length cs in let last = Cstruct . get_uint8 cs ( n - 1 ) in let cs = clone_cs cs and last = last land ( lnot ( 1 lsl clip - 1 ) ) in Cst...
let bit_string_flags ( type a ) ( xs : ( int * a ) list ) = let cmp = compare in let module M1 = Map . Make ( struct type t = a let compare = cmp end ) in let module M2 = Map . Make ( Int ) in let aix , ixa = List . fold_left ( fun ( m1 , m2 ) ( i , x ) -> M1 . add ...
let single a = Last a
let product2 fn a b = fn @@ a @ single b
let product3 fn a b c = map ( fun ( a , ( b , c ) ) -> ( a , b , c ) ) ( fun ( a , b , c ) -> ( a , ( b , c ) ) ) ( fn @@ a @ b @ single c )
let product4 fn a b c d = map ( fun ( a , ( b , ( c , d ) ) ) -> ( a , b , c , d ) ) ( fun ( a , b , c , d ) -> ( a , ( b , ( c , d ) ) ) ) ( fn @@ a @ b @ c @ single d )
let product5 fn a b c d e = map ( fun ( a , ( b , ( c , ( d , e ) ) ) ) -> ( a , b , c , d , e ) ) ( fun ( a , b , c , d , e ) -> ( a , ( b , ( c , ( d , e ) ) ) ) ) ( fn @@ a @ b @ c @ d @ single e )
let product6 fn a b c d e f = map ( fun ( a , ( b , ( c , ( d , ( e , f ) ) ) ) ) -> ( a , b , c , d , e , f ) ) ( fun ( a , b , c , d , e , f ) -> ( a , ( b , ( c , ( d , ( e , f ) ) ) ) ) ) ( fn @@ a @ b @ c @ d ...
let sequence seq = Sequence seq
let sequence2 a b = product2 sequence a b
let sequence_of asn = Sequence_of asn
let set seq = Set seq
let set2 a b = product2 set a b
let set_of asn = Set_of asn
let choice a b = Choice ( a , b )
let choice2 a b = map ( function L a -> ` C1 a | R b -> ` C2 b ) ( function ` C1 a -> L a | ` C2 b -> R b ) ( choice a b )
let choice3 a b c = map ( function L ( L a ) -> ` C1 a | L ( R b ) -> ` C2 b | R c -> ` C3 c ) ( function ` C1 a -> L ( L a ) | ` C2 b -> L ( R b ) | ` C3 c -> R c ) ( choice ( choice a b ) c )
let choice4 a b c d = map ( function | L ( L a ) -> ` C1 a | L ( R b ) -> ` C2 b | R ( L c ) -> ` C3 c | R ( R d ) -> ` C4 d ) ( function | ` C1 a -> L ( L a ) | ` C2 b -> L ( R b ) | ` C3 c -> R ( L c ) | ` C4 d -> R ( R d ) ) ( choice ( choi...
let choice5 a b c d e = map ( function | L ( L ( L a ) ) -> ` C1 a | L ( L ( R b ) ) -> ` C2 b | L ( R c ) -> ` C3 c | R ( L d ) -> ` C4 d | R ( R e ) -> ` C5 e ) ( function | ` C1 a -> L ( L ( L a ) ) | ` C2 b -> L ( L ( R b ) ) | ` C3 c...
let choice6 a b c d e f = map ( function | L ( L ( L a ) ) -> ` C1 a | L ( L ( R b ) ) -> ` C2 b | L ( R c ) -> ` C3 c | R ( L ( L d ) ) -> ` C4 d | R ( L ( R e ) ) -> ` C5 e | R ( R f ) -> ` C6 f ) ( function | ` C1 a -> L ( L ( L a ) ) ...
let id x = x
let const x _ = x
let ( . ) & f g x = f ( g x )
let opt def = function Some x -> x | _ -> def
type ' a endo = ' a -> ' a
type ( ' a , ' b ) sum = L of ' a | R of ' b
let ( strf , pf ) = Format . ( asprintf , fprintf )
let kstrf k fmt = Format . ( kfprintf ( fun _ -> flush_str_formatter ( ) |> k ) str_formatter fmt )
let invalid_arg fmt = Format . ksprintf invalid_arg fmt
let pp_list ~ sep pp ppf xs = let rec go ppf = function | [ ] -> ( ) | [ x ] -> pp ppf x | x :: xs -> pf ppf " % a % a @ " pp x sep ( ) ; go ppf xs in pf ppf " [ @% a ] " @ go xs
let pp_dump_list pp ppf xs = let sep ppf ( ) = Format . pp_print_string ppf " , " in pf ppf " [ [ @% a ] ] " @ ( pp_list ~ sep pp ) xs
let pp_cs ppf cs = let f ppf cs = for i = 0 to cs . Cstruct . len - 1 do if i mod 8 = 0 && i > 0 then pf ppf " @ " ; pf ppf " % 02x " ( Cstruct . get_uint8 cs i ) done in pf ppf " [ @% a ] " @ f cs
module Tag = struct type t = | Universal of int | Application of int | Context_specific of int | Private of int let compare t1 t2 = match ( t1 , t2 ) with | ( Universal a , Universal b ) | ( Application a , Application b ) | ( Context_specific a , Context_specific b ) | ( Private a ...
type tags = Tag . t list
module Generic = struct type t = | Cons of tag * t list | Prim of tag * Cstruct . t let tag = function Cons ( t , _ ) -> t | Prim ( t , _ ) -> t let pp_form_name ppf fsym = Format . pp_print_string ppf @@ match fsym with ` Cons -> " Constructed " | ` Prim -> " Primitive " |...
type bits = int * Cstruct . t
type ' a rand = unit -> ' a
type _ asn = | Iso : ( ' a -> ' b ) * ( ' b -> ' a ) * ' b rand option * ' a asn -> ' b asn | Fix : ( ' a asn -> ' a asn ) * ' a Asn_cache . var -> ' a asn | Sequence : ' a sequence -> ' a asn | Sequence_of : ' a asn -> ' a list asn | Set : ' a sequen...
let label = opt " "
let seq_tag = Tag . Universal 0x10
let tag_of_p : type a . a prim -> tag = let open Tag in function | Bool -> Universal 0x01 | Int -> Universal 0x02 | Bits -> Universal 0x03 | Octets -> Universal 0x04 | Null -> Universal 0x05 | OID -> Universal 0x06 | CharString -> Universal 0x1d
let rec tag_set : type a . a asn -> tags = function | Iso ( _ , _ , _ , asn ) -> tag_set asn | Fix ( f , _ ) as fix -> tag_set ( f fix ) | Sequence _ -> [ seq_tag ] | Sequence_of _ -> [ seq_tag ] | Set _ -> [ set_tag ] | Set_of _ -> [ set_tag ] | Choice ( ...
let rec tag : type a . a -> a asn -> tag = fun a -> function | Iso ( _ , g , _ , asn ) -> tag ( g a ) asn | Fix _ as fix -> tag a fix | Sequence _ -> seq_tag | Sequence_of _ -> seq_tag | Set _ -> set_tag | Set_of _ -> set_tag | Choice ( a1 , a2 ) -> ( match a with L a '...
type error = [ ` Parse of string ]
let pp_error ppf ( ` Parse err ) = pf ppf " Parse error : % s " err
let error err = raise ( Parse_error err )
let parse_error fmt = kstrf ( fun s -> error ( ` Parse s ) ) fmt
module FSet = struct type f = Fn : ( ' a -> ' b ) -> f include Set . Make ( struct type t = f let compare ( Fn f1 ) ( Fn f2 ) = Hashtbl . ( compare ( hash f1 ) ( hash f2 ) ) end ) let mem f s = mem ( Fn f ) s and add f s = add ( Fn f ) s end
let validate asn = let rec check : type a . ? tag : tag -> FSet . t -> a asn -> unit = fun ? tag fs -> function | Iso ( _ , _ , _ , a ) -> check ? tag fs a | Fix ( f , _ ) as fix -> if not ( FSet . mem f fs ) then check ? tag FSet . ( add f fs ) ( f fix ) | Seque...
type t = Oid of int * int * int list
let invalid_arg fmt = Format . ksprintf invalid_arg fmt
let ( ) <| ( Oid ( v1 , v2 , vs ) ) vn = if vn < 0 then invalid_arg " OID . ( ) <|: negative component : % d " vn ; Oid ( v1 , v2 , vs @ [ vn ] )
let ( ) <|| ( Oid ( v1 , v2 , vs ) ) vs ' = let f v = if v < 0 then invalid_arg " OID . ( ) <||: negative component : % d " v in List . iter f vs ; Oid ( v1 , v2 , vs @ vs ' )
let base v1 v2 = match v1 with | 0 | 1 when v2 >= 0 && v2 < 40 -> Oid ( v1 , v2 , [ ] ) | 2 when v2 >= 0 -> Oid ( v1 , v2 , [ ] ) | _ -> invalid_arg " OID . base : out of range : % d . % d " v1 v2
let base_opt v1 v2 = try Some ( base v1 v2 ) with Invalid_argument _ -> None
let to_nodes ( Oid ( v1 , v2 , vs ) ) = ( v1 , v2 , vs )
let of_nodes n1 n2 ns = try Some ( base n1 n2 <|| ns ) with Invalid_argument _ -> None