mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-06-05 22:09:39 +02:00
Implementation for contains_javascript
This commit is contained in:
@ -3831,14 +3831,36 @@ let write_images device res quality boxname annots antialias downsample spec pdf
|
||||
|
||||
let remove_javascript pdf =
|
||||
(* Find /S /JavaScript and empty the /JS string. Also, Empty out any /URI (javascript). *)
|
||||
Pdf.objselfmap (fun o -> o) pdf
|
||||
Pdf.objselfmap (fun o -> o) pdf;
|
||||
(* Process the /Root -> /Names -> /JavaScript *)
|
||||
(*Pdf.remove_chain pdf ["/Root"; "/Names"; "/JavaScript"];*)
|
||||
ignore (Pdf.remove_chain pdf ["/Root"; "/Names"; "/JavaScript"])
|
||||
|
||||
let contains_javascript pdf =
|
||||
let found = ref false in
|
||||
(* Any dictionary with /S /JavaScript or any /URI (javascript:...) *)
|
||||
let rec contains_javascript_single_object f pdf = function
|
||||
| (Pdf.Dictionary d) -> f (Pdf.recurse_dict (contains_javascript_single_object f pdf) d)
|
||||
| (Pdf.Stream {contents = (Pdf.Dictionary dict, data)}) ->
|
||||
f (Pdf.Stream {contents = (Pdf.recurse_dict (contains_javascript_single_object f pdf) dict, data)})
|
||||
| Pdf.Array a -> Pdf.recurse_array (contains_javascript_single_object f pdf) a
|
||||
| x -> x
|
||||
in
|
||||
let f d =
|
||||
begin match Pdf.lookup_direct pdf "/S" d with
|
||||
| Some (Pdf.String "/JavaScript") -> set found
|
||||
| _ -> ()
|
||||
end;
|
||||
begin match Pdf.lookup_direct pdf "/URI" d with
|
||||
| Some (Pdf.String s) when String.length s >= 11 && String.sub s 0 11 = "javascript:" -> set found; d
|
||||
| _ -> d
|
||||
end
|
||||
in
|
||||
Pdf.objiter (fun _ obj -> ignore (contains_javascript_single_object f pdf obj)) pdf;
|
||||
(* Any /Root -> /Names -> /JavaScript *)
|
||||
begin match Pdf.lookup_chain pdf pdf.Pdf.trailerdict ["/Root"; "/Names"; "/JavaScript"] with
|
||||
| Some _ -> set found
|
||||
| None -> ()
|
||||
end;
|
||||
print_string (Printf.sprintf "%b" !found)
|
||||
|
||||
(* Main function *)
|
||||
|
Reference in New Issue
Block a user