Skip to content

Instantly share code, notes, and snippets.

@hackingbutlegal
Created February 25, 2013 02:51
Show Gist options
  • Select an option

  • Save hackingbutlegal/5027100 to your computer and use it in GitHub Desktop.

Select an option

Save hackingbutlegal/5027100 to your computer and use it in GitHub Desktop.
Perl script to remove protection from a PDF.
# Usage: perl invalidate-signing-certs.pl <in.pdf >out.pdf
binmode(STDIN);
binmode(STDOUT);
$/ = "\0";
while(<>) {
s#(/Perms<</DocMDP.*?>>)#' ' x length $1#ge;
s#(/Ff 1)(?=.*?/Lock )#' ' x length $1#ge;
s#(?<=/Lock)(.*?)(/Ff 1)#"$1" . ' ' x length $2#ge;
s#(/Lock .*?)(?=/)#' ' x length $1#ge;
s#( obj<<)([^>\rendobj)#$1 . (‘ ‘ x length $2) . $3#ge;
print $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment