diff --git a/run/lib/PDF.pm b/run/lib/PDF.pm index 70db8d693e7..4a1404fe91b 100644 --- a/run/lib/PDF.pm +++ b/run/lib/PDF.pm @@ -1204,7 +1204,11 @@ sub DecryptInit($$$) $$encrypt{_meta} = 1; } - printf("\$pdf\$%d*%d*%d*%d*%d*%d*", $ver, $rev, $$encrypt{Length} || 40, $$encrypt{P}, $$encrypt{_meta} || 0, length($id)); + # PDF /P is a signed 32-bit integer + my $perm = $$encrypt{P}; + $perm -= 4294967296 if $perm >= 2147483648; + + printf("\$pdf\$%d*%d*%d*%d*%d*%d*", $ver, $rev, $$encrypt{Length} || 40, $perm, $$encrypt{_meta} || 0, length($id)); my $str = $id; $str =~ s/(.)/ sprintf '%02x', ord $1 /seg; printf("%s*", $str); diff --git a/run/pdf2john.py b/run/pdf2john.py index 299714e9946..01b2b72fe29 100755 --- a/run/pdf2john.py +++ b/run/pdf2john.py @@ -73,6 +73,8 @@ def __init__(self, file_name: str, strict: bool = False): self.algorithm: int = self.encrypt_dict.get("/V") self.length: int = self.encrypt_dict.get("/Length", 40) self.permissions: int = self.encrypt_dict["/P"] + if self.permissions >= 2**31: + self.permissions -= 2**32 self.revision: int = self.encrypt_dict["/R"] @property