text stringlengths 12 786k |
|---|
let string_of_operation = function | Create x -> Printf . sprintf " Create :% Ld " x | Snapshot -> " Snapshot " | Write ( p , _ ) -> Printf . sprintf " Write :% s :% s " ( string_of_choice p . block ) ( string_of_choice p . sector ) |
let descr_of_program p = let lines = List . concat ( List . map descr_of_operation p ) in List . rev ( fst ( List . fold_left ( fun ( sofar , next ) line -> Printf . sprintf " % d % s " ( next * 10 ) line :: sofar , next + 1 ) ( [ ] , 1 ) lines ) ) |
let string_of_program p = String . concat " _ " ( List . map string_of_operation p ) |
let first_write_message = " This is a sector which contains simple data . \ n " |
let second_write_message = " All work and no play makes Dave a dull boy . \ n " |
let first_write p = Write ( p , first_write_message ) |
let second_write p = Write ( p , second_write_message ) |
let create_write_read = List . map ( fun ( size , p ) -> [ Create size ; first_write p ] ) ( allpairs sizes positions ) |
let create_write_read_leaf = List . map ( fun ( size , p ) -> [ Create size ; Snapshot ; first_write p ] ) ( allpairs sizes positions ) |
let create_write_read_parent = List . map ( fun ( size , p ) -> [ Create size ; first_write p ; Snapshot ] ) ( allpairs sizes positions ) |
let create_write_overwrite = List . map ( fun ( size , ( p1 , p2 ) ) -> [ Create size ; first_write p1 ; Snapshot ; second_write p2 ] ) ( allpairs sizes ( allpairs positions positions ) ) |
let programs = List . concat [ create_write_read ; create_write_read_leaf ; create_write_read_parent ; create_write_overwrite ; ] |
module Memory = struct let alloc bytes = if bytes = 0 then Cstruct . create 0 else let n = max 1 ( ( bytes + 4095 ) / 4096 ) in let pages = Io_page . ( to_cstruct ( get n ) ) in Cstruct . sub pages 0 bytes end |
let make_new_filename = let counter = ref 0 in fun ( ) -> let this = ! counter in incr counter ; disk_name_stem ^ ( string_of_int this ) ^ disk_suffix |
let _fill_sector_with pattern = let b = Memory . alloc 512 in for i = 0 to 511 do Cstruct . set_char b i ( pattern . [ i mod ( String . length pattern ) ] ) done ; b |
let _absolute_sector_of vhd _position { Vhd_format . Patterns . block ; sector } = let open F in if vhd . Vhd . header . Header . max_table_entries = 0 then None else let block = match block with | First -> 0 | Last -> vhd . Vhd . header . Header . max_table_entries - 1 in let sec... |
let cstruct_to_string c = String . escaped ( Cstruct . to_string c ) |
let check_written_sectors t expected = let y = Memory . alloc 512 in let rec loop = function | [ ] -> return ( ) | ( x , data ) :: xs -> Vhd_IO . read_sector t x y >>= fun empty -> ( match empty with | false -> fail ( Failure " read empty sector , expected data " ) | true ->... |
let empty_sector = Memory . alloc 512 |
let check_raw_stream_contents t expected = Vhd_input . raw t >>= fun stream -> fold_left ( fun offset x -> match x with | ` Empty y -> List . iter ( fun ( x , _ ) -> if x >= offset && x < ( Int64 . add offset y ) then failwith ( Printf . sprintf " Sector % Ld is not supposed to b... |
let verify t contents = let open F in let capacity = Int64 . ( shift_left ( of_int t . Vhd . header . Header . max_table_entries ) ( t . Vhd . header . Header . block_size_sectors_shift + sector_shift ) ) in ( if capacity < t . Vhd . footer . Footer . current_size then fail (... |
let error_matching ( ) = prerr_endline " Pattern matching failed " ; raise Toplevel |
let rec pattern_matching pattern obj ty = match pattern with P_dummy -> [ ] | P_variable var -> [ var , obj , ty ] | _ -> match ( Ctype . repr ty ) . desc with Tvar | Tarrow _ -> error_matching ( ) | Ttuple ( ty_list ) -> ( match pattern with P_tuple pattern_list -> pattern_ma... |
EXTEND GLOBAL : expr ; expr : LEVEL " top " [ [ n = box_type ; d = SELF ; " begin " ; el = LIST0 [ e = box_expr ; " ; " -> e ] ; " end " -> let el = [ <: expr < Format . $ lid " : open_ " ^ n $ $ d $ >> :: el ] in let el = el @ [ <: expr < Format ... |
type spat_comp = [ SpTrm of Loc . t and MLast . patt and option MLast . expr | SpNtr of Loc . t and MLast . patt and MLast . expr | SpStr of Loc . t and MLast . patt ] ; |
type sexp_comp = [ SeTrm of Loc . t and MLast . expr | SeNtr of Loc . t and MLast . expr ] ; match ( p , e ) with [ ( <: patt < $ lid : a $ , >> <: expr < $ lid : b $ ) >> -> a = b | ( <: patt < $ uid : a $ , >> <: expr < $ uid : b $ ) >> -> a = b | ( ... |
prerr_endline " Warning : pa_ifdef is deprecated since OCaml 3 . 07 . Use pa_macro instead . " ; |
type item_or_def ' a = [ SdStr of ' a | SdDef of string | SdUnd of string | SdNop ] ; List . fold_right ( fun e l -> if e = x then l else [ e :: l ] ) l [ ] ; EXTEND GLOBAL : Pcaml . expr Pcaml . str_item Pcaml . sig_item ; Pcaml . expr : LEVEL " top " [ [ " ifdef ... |
let desc = if Obj . is_block ( Obj . repr x ) then " tag = " ^ string_of_int ( Obj . tag ( Obj . repr x ) ) else " int_val = " ^ string_of_int ( Obj . magic x ) in failwith ( " pa_lefteval : not impl : " ^ name ^ " ; " ^ desc ^ " " ) > ; fun [ <: expr... |
let output_byte buf b = Buffer . add_char buf ' ' ; \\ Buffer . add_char buf ( Char . chr ( 48 + b / 100 ) ) ; Buffer . add_char buf ( Char . chr ( 48 + ( b / 10 ) mod 10 ) ) ; Buffer . add_char buf ( Char . chr ( 48 + b mod 10 ) ) |
let output_array v = let b = Buffer . create ( Array . length v * 3 ) in for i = 0 to Array . length v - 1 do output_byte b ( v . ( i ) land 0xFF ) ; output_byte b ( ( v . ( i ) asr 8 ) land 0xFF ) ; if i land 7 = 7 then Buffer . add_string b " \\\ n " done ; ... |
let output_byte_array v = let b = Buffer . create ( Array . length v * 2 ) in for i = 0 to Array . length v - 1 do output_byte b ( v . ( i ) land 0xFF ) ; if i land 15 = 15 then Buffer . add_string b " \\\ n " done ; let s = Buffer . contents b in <: expr < $ str : s $... |
let output_tables tbl = <: str_item < value lex_tables = { Lexing . lex_base = $ output_array tbl . tbl_base ; $ Lexing . lex_backtrk = $ output_array tbl . tbl_backtrk ; $ Lexing . lex_default = $ output_array tbl . tbl_default ; $ Lexing . lex_trans = $ output_array tbl . tbl_tr... |
let rec make_alias n = function | [ ] -> [ ] | h :: t -> ( h , " __ocaml_lex_arg_ " ^ ( string_of_int n ) ) :: ( make_alias ( succ n ) t ) |
let abstraction = List . fold_right ( fun ( p , a ) e -> <: expr < fun ( $ p $ as $ lid : a ) $ -> $ e $ ) >> |
let application = List . fold_left ( fun f ( _ , a ) -> <: expr < $ f $ $ lid : a $ ) >> |
let int i = <: expr < $ int : string_of_int i $ >> |
let output_memory_actions acts = let aux = function | Copy ( tgt , src ) -> lexbuf . Lexing . lex_mem . ( $ int src ) $ >> | Set tgt -> <: expr < lexbuf . Lexing . lex_mem . ( $ int tgt ) $ := lexbuf . Lexing . lex_curr_pos >> in <: expr < do { $ list : List . map au... |
let output_base_mem = function | Mem i -> <: expr < lexbuf . Lexing . lex_mem . ( $ int i ) $ >> | Start -> <: expr < lexbuf . Lexing . lex_start_pos >> | End -> <: expr < lexbuf . Lexing . lex_curr_pos >> |
let output_tag_access = function | Sum ( a , 0 ) -> output_base_mem a | Sum ( a , i ) -> <: expr < $ output_base_mem a $ + $ int i $ >> |
let rec output_env e = function | [ ] -> e | ( x , Ident_string ( o , nstart , nend ) ) :: rem -> <: expr < in $ output_env e rem $ >> | ( x , Ident_char ( o , nstart ) ) :: rem -> <: expr < in $ output_env e rem $ >> |
let output_entry e = let init_num , init_moves = e . auto_initial_state in let args = make_alias 0 ( e . auto_args @ [ <: patt < lexbuf >> ] ) in let f = " __ocaml_lex_rec_ " ^ e . auto_name ^ " _rec " in let call_f = application <: expr < $ lid : f $ >> args in let body_wrap... |
let output_lexdef tables entry_points = Printf . eprintf " pa_ocamllex : lexer found ; % d states , % d transitions , table size % d bytes \ n " ( Array . length tables . tbl_base ) ( Array . length tables . tbl_trans ) ( 2 * ( Array . length tables . tbl_base + Array . le... |
let char s = Char . code ( Token . eval_char s ) |
let named_regexps = ( Hashtbl . create 13 : ( string , regular_expression ) Hashtbl . t ) |
let regexp_for_string s = let rec re_string n = if n >= String . length s then Epsilon else if succ n = String . length s then Characters ( Cset . singleton ( Char . code s . [ n ] ) ) else Sequence ( Characters ( Cset . singleton ( Char . code s . [ n ] ) ) , re_string (... |
let char_class c1 c2 = Cset . interval c1 c2 |
let rec remove_as = function | Bind ( e , _ ) -> remove_as e | Epsilon | Eof | Characters _ as e -> e | Sequence ( e1 , e2 ) -> Sequence ( remove_as e1 , remove_as e2 ) | Alternative ( e1 , e2 ) -> Alternative ( remove_as e1 , remove_as e2 ) | Repetition e -> Repetition ( ... |
let ( ) = Hashtbl . add named_regexps " eof " ( Characters Cset . eof ) |
let let_regexp = Grammar . Entry . create Pcaml . gram " pa_ocamllex let " |
let header = Grammar . Entry . create Pcaml . gram " pa_ocamllex header " |
let lexer_def = Grammar . Entry . create Pcaml . gram " pa_ocaml lexerdef " EXTEND GLOBAL : Pcaml . str_item let_regexp header lexer_def ; let_regexp : [ [ x = LIDENT ; " " ; = r = regexp -> if Hashtbl . mem named_regexps x then Printf . eprintf " pa_ocamllex ( warning ) : mu... |
let standalone = let already = ref false in fun ( ) -> if not ( ! already ) then begin already := true ; Printf . eprintf " pa_ocamllex : stand - alone mode \ n " ; DELETE_RULE Pcaml . str_item : " pa_ocamllex " ; LIDENT " rule " ; lexer_def END ; DELETE_RULE Pcaml . str_ite... |
let ( ) = Pcaml . add_option " - ocamllex " ( Arg . Unit standalone ) " Activate ( standalone ) ocamllex emulation mode . " |
type spat_comp = [ SpTrm of Loc . t and MLast . patt and option MLast . expr | SpNtr of Loc . t and MLast . patt and MLast . expr | SpStr of Loc . t and MLast . patt ] ; |
type sexp_comp = [ SeTrm of Loc . t and MLast . expr | SeNtr of Loc . t and MLast . expr ] ; fun [ SpTrm _loc p wo -> ( <: expr < $ peek_fun _loc $ $ lid : strm_n $ , >> p , wo , <: expr < do { $ junk_fun _loc $ $ lid : strm_n ; $ $ skont $ } ) >> | SpNtr _loc p... |
type choice ' a ' b = [ Left of ' a | Right of ' b ] ; |
module Buff = struct value buff = ref ( String . create 80 ) ; value store len x = do { if len >= String . length buff . val then buff . val := buff . val ^ String . create ( String . length buff . val ) else ( ) ; buff . val . [ len ] := x ; succ len } ; value ge... |
type sexpr = [ Sacc of Loc . t and sexpr and sexpr | Schar of Loc . t and string | Sexpr of Loc . t and list sexpr | Sint of Loc . t and string | Sfloat of Loc . t and string | Slid of Loc . t and string | Slist of Loc . t and list sexpr | Sqid of Loc . t and string | Squot of Loc . t and s... |
Grammar . Unsafe . gram_reinit gram lexer ; Grammar . Unsafe . clear_entry interf ; Grammar . Unsafe . clear_entry implem ; Grammar . Unsafe . clear_entry top_phrase ; Grammar . Unsafe . clear_entry use_file ; Grammar . Unsafe . clear_entry module_type ; Grammar . Unsafe . clear_... |
type altern ' a ' b = [ Left of ' a | Right of ' b ] ; fun [ <: expr < do { $ list : el $ } >> -> el | e -> [ e ] ] ; let rec find_alpha v = let s = String . make 1 v in if List . mem_assoc s tpl then if v = ' z ' then None else find_alpha ( Char . chr ( Char . ... |
let ( ) = Printexc . record_backtrace true |
let verbose = ( Array . length Sys . argv ) = 2 && Sys . argv . ( 1 ) = " - v " [ %% cstruct |
type pcap_header = { magic_number : uint32_t ; version_major : uint16_t ; version_minor : uint16_t ; thiszone : uint32_t ; sigfigs : uint32_t ; snaplen : uint32_t ; network : uint32_t ; [ %% cstruct |
type pcap_packet = { ts_sec : uint32_t ; ts_usec : uint32_t ; incl_len : uint32_t ; orig_len : uint32_t ; |
let test_packet p len = match ( Dhcp_wire . pkt_of_buf p len ) with | Error e -> failwith e | Ok pkt -> if verbose then printf " DHCP : % s \ n " %! ( Dhcp_wire . pkt_to_string pkt ) ; let buf = Dhcp_wire . buf_of_pkt pkt in match ( Dhcp_wire . pkt_of_buf buf len ) with | Error e -... |
let test_pcap_packet ( hdr , pkt ) = let ts_sec = get_pcap_packet_ts_sec hdr in let ts_usec = get_pcap_packet_ts_usec hdr in let incl_len = get_pcap_packet_incl_len hdr in let orig_len = get_pcap_packet_orig_len hdr in if verbose then printf " ***** % lu . % lu bytes % lu ( of % lu ) \ n " %... |
let test_pcap_header buf = let magic = get_pcap_header_magic_number buf in let endian = match magic with | 0xa1b2c3d4l -> " bigendian " | 0xd4c3b2a1l -> " littlendian " | _ -> " not a pcap file " in let version_major = get_pcap_header_version_major buf in let version_minor = get_pcap_header_ve... |
let parse file = if verbose then printf " parsing % s \ n " %! file ; let fd = Unix . ( openfile file [ O_RDONLY ] 0 ) in let t = Unix_cstruct . of_fd fd in if verbose then printf " total pcap file length % d \ n " %! ( Cstruct . length t ) ; let header , body = Cstruct . sp... |
let testfiles = [ " dhcp . pcap " ; " dhcp2 . pcap " ] |
let t_pcap ( ) = List . iter parse testfiles |
let is_delimiter = function | ' ( ' | ' ) ' | ' ' < | ' ' > | ' [ ' | ' ] ' | ' { ' | ' } ' | ' ' % | ' ' / -> true | _ -> false |
type saved_encryption = { from_get_encryption_values : Pdfcryptprimitives . encryption * string * string * int32 * string * string option * string option ; encrypt_metadata : bool ; perms : string } |
type deferred_encryption = { crypt_type : Pdfcryptprimitives . encryption ; file_encryption_key : string option ; obj : int ; gen : int ; key : int array ; keylength : int ; r : int } |
let print_deferred_encryption e = begin match e . crypt_type with | Pdfcryptprimitives . ARC4 ( a , b ) -> Printf . printf " crypt_type = ARC4 ( % i , % i ) \ n " a b | Pdfcryptprimitives . AESV2 -> Printf . printf " crypt_type = AESV2 \ n " | Pdfcryptprimitives . AESV3 x ->... |
type toget_crypt = | NoChange | ToDecrypt of deferred_encryption |
type toget = { input : input ; position : int ; length : int ; crypt : toget_crypt } |
let toget ( ? crypt = NoChange ) input position length = { input = input ; position = position ; length = length ; crypt = crypt } |
let length_of_toget t = t . length |
let position_of_toget t = t . position |
let input_of_toget t = t . input |
type stream = | Got of bytes | ToGet of toget |
type pdfobject = | Null | Boolean of bool | Integer of int | Real of float | String of string | Name of string | Array of pdfobject list | Dictionary of ( string * pdfobject ) list | Stream of ( pdfobject * stream ) ref | Indirect of int |
let string_of_pdf : ( pdfobject -> string ) ref = ref ( function _ -> " " ) |
type objectdata = | Parsed of pdfobject | ParsedAlreadyDecrypted of pdfobject | ToParse | ToParseFromObjectStream of ( int , int list ) Hashtbl . t * int * int * ( int -> int list -> ( int * ( objectdata ref * int ) ) list ) |
type pdfobjmap = ( int , objectdata ref * int ) Hashtbl . t |
let pdfobjmap_empty ( ) : pdfobjmap = Hashtbl . create 500 |
let pdfobjmap_find key map = Hashtbl . find map key |
let pdfobjmap_add key value map = Hashtbl . replace map key value ; map |
let pdfobjmap_bindings_inorder map = let r = ref [ ] in Hashtbl . iter ( fun k v -> r := ( k , v ) ::! r ) map ; sort ( fun ( a , _ ) ( b , _ ) -> compare a b ) ! r |
let pdfobjmap_iter_inorder f map = iter ( function ( k , v ) -> f k v ) ( pdfobjmap_bindings_inorder map ) |
let pdfobjmap_bindings map = let r = ref [ ] in Hashtbl . iter ( fun k v -> r := ( k , v ) ::! r ) map ; ! r |
let pdfobjmap_remove key map = Hashtbl . remove map key ; map |
type pdfobjects = { mutable maxobjnum : int ; mutable parse : ( pdfobjmap_key -> pdfobject ) option ; mutable pdfobjects : pdfobjmap ; mutable object_stream_ids : ( int , int ) Hashtbl . t } |
type t = { mutable major : int ; mutable minor : int ; mutable root : int ; mutable objects : pdfobjects ; mutable trailerdict : pdfobject ; mutable was_linearized : bool ; mutable saved_encryption : saved_encryption option } |
let empty ( ) = { major = 1 ; minor = 1 ; root = 0 ; objects = { maxobjnum = 0 ; parse = None ; pdfobjects = pdfobjmap_empty ( ) ; object_stream_ids = null_hash ( ) } ; trailerdict = Dictionary [ ] ; was_linearized = false ; saved_encryption = None } |
let input_pdferror i s = Printf . sprintf " % s whilst reading file % s at position % i " s i . Pdfio . source ( i . Pdfio . pos_in ( ) ) |
let is_whitespace = function | ' \ 000 ' | ' \ 009 ' | ' \ 010 ' | ' \ 012 ' | ' ' | ' \ 013 ' -> true | _ -> false |
let is_not_whitespace = function | ' \ 000 ' | ' \ 009 ' | ' \ 010 ' | ' \ 012 ' | ' ' | ' \ 013 ' -> false | _ -> true |
let process_deferred_cryption toget_crypt data = match toget_crypt with NoChange -> data | ToDecrypt saved -> Pdfcryptprimitives . decrypt_stream_data saved . crypt_type false saved . file_encryption_key saved . obj saved . gen saved . key saved . keylength saved . r data |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.