²¿·ÖÔ´´úÂ룺 ---------------------- --------------TEXTS------------------------------------------------- let ns = ref false let b = Buffer.create 0 let flush () = if !ns then begin if Buffer.length b > 2 then print_endline (Buffer.contents b); Buffer.reset b; ns := false end let rec loop e = match Enum.get e with None -> () | Some c -> flush (); begin match c with | '\x20'..'\x7f' -> Buffer.add_char b c | '\x81'..'\x9f' | '\xe0'..'\xef' | '\xf0'..'\xfc' when (match Enum.peek e with Some ('\x40'..'\x7e' | '\x80'..'\xfc') -> true | _ -> false) -> Buffer.add_char b c; Buffer.add_char b (Option.get (Enum.get e)) | _ -> ns := true end; loop e let () = loop (Std.input_chars stdin); flush () -------------------------------------PNGS-------------------------------------------------- { open Lexing let npoc = open_out_bin "notpng.dat" } rule lex idx = parse | "\137\080\078\071\013\010\026\010" { let oc = if Array.length Sys.argv < 2 || Sys.argv.(1) <> "nopng" then Printf.kprintf open_out_bin "img%04d.png" idx else open_out "/dev/null" in output_string oc "\137\080\078\071\013\010\026\010"; let rec loop () = if parse_chunk oc lexbuf then loop () in loop (); close_out oc; lex (idx + 1) lexbuf } | _ { String.iter (fun c -> output_char npoc (char_of_int (int_of_char c lxor 2))) (lexeme lexbuf); lex idx lexbuf } | eof {} and parse_chunk oc = parse | (_ as a) (_ as b) (_ as c) (_ as d) (_ _ _ _ as ctype) { output_string oc (lexeme lexbuf); let a = int_of_char a and b = int_of_char b and c = int_of_char c and d = int_of_char d in let len = (a lsl 24) lor (b lsl 16) lor (c lsl 8) lor d in dump oc (len + 3) lexbuf; ctype <> "IEND" } | _ | eof { assert false } and dump oc len = parse | _ | eof { output_string oc (lexeme lexbuf); if len > 0 then dump oc (len - 1) lexbuf } { lex 0 (from_channel stdin); close_out npoc } ---------------------------------------oggs------------------------------------------------ let ic = open_in_bin Sys.argv.(1) let is_OggS = let buffer = String.create 4 in fun pos -> seek_in ic pos; really_input ic buffer 0 4; buffer = "OggS" let is_Xiphophorus_libVorbis = let buffer = String.create 21 in fun pos -> seek_in ic pos; really_input ic buffer 0 21; buffer = "Xiphophorus libVorbis" let find_next pos = let rec loop lpos = if is_OggS lpos && is_Xiphophorus_libVorbis (lpos + 109) then lpos else loop (lpos + 1) in loop (pos + 200) let buffer = String.create 16384 let rec loop idx spos = let epos, cont = try find_next spos, true with End_of_file -> in_channel_length ic, false in let oc = Printf.ksprintf open_out_bin "%06d.ogg" idx in let rec copy rem = if rem = 0 then () else let max = if rem < 16384 then rem else 16384 in let count = input ic buffer 0 max in output oc buffer 0 count; copy (rem - count) in seek_in ic spos; copy (epos - spos); close_out oc; if cont then loop (idx + 1) epos let () = loop 0 0; close_in ic