From e17a425dfb3382310fb5863f516dacdca9f44956 Mon Sep 17 00:00:00 2001 From: leshe4ka46 Date: Sun, 19 Oct 2025 14:47:59 +0300 Subject: fuck the unipdf licencing --- unipdf/sanitize/sanitize.go | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 unipdf/sanitize/sanitize.go (limited to 'unipdf/sanitize/sanitize.go') diff --git a/unipdf/sanitize/sanitize.go b/unipdf/sanitize/sanitize.go new file mode 100644 index 0000000..1f66a90 --- /dev/null +++ b/unipdf/sanitize/sanitize.go @@ -0,0 +1,72 @@ +// +// Copyright 2020 FoxyUtils ehf. All rights reserved. +// +// This is a commercial product and requires a license to operate. +// A trial license can be obtained at https://unidoc.io +// +// DO NOT EDIT: generated by unitwist Go source code obfuscator. +// +// Use of this source code is governed by the UniDoc End User License Agreement +// terms that can be accessed at https://unidoc.io/eula/ + +package sanitize ;import (_a "github.com/unidoc/unipdf/v4/common";_dd "github.com/unidoc/unipdf/v4/core";); + +// SanitizationOpts specifies the objects to be removed during sanitization. +type SanitizationOpts struct{ + +// JavaScript specifies wether JavaScript action should be removed. JavaScript Actions, section 12.6.4.16 of PDF32000_2008 +JavaScript bool ; + +// URI specifies if URI actions should be removed. 12.6.4.7 URI Actions, PDF32000_2008. +URI bool ; + +// GoToR removes remote GoTo actions. 12.6.4.3 Remote Go-To Actions, PDF32000_2008. +GoToR bool ; + +// GoTo specifies wether GoTo actions should be removed. 12.6.4.2 Go-To Actions, PDF32000_2008. +GoTo bool ; + +// RenditionJS enables removing of `JS` entry from a Rendition Action. +// The `JS` entry has a value of text string or stream containing a JavaScript script that shall be executed when the action is triggered. +// 12.6.4.13 Rendition Actions Table 214, PDF32000_2008. +RenditionJS bool ; + +// OpenAction removes OpenAction entry from the document catalog. +OpenAction bool ; + +// Launch specifies wether Launch Action should be removed. +// A launch action launches an application or opens or prints a document. +// 12.6.4.5 Launch Actions, PDF32000_2008. +Launch bool ;};func (_eec *Sanitizer )analyze (_ef []_dd .PdfObject ){_dca :=map[string ]int {};for _ ,_bgd :=range _ef {switch _gf :=_bgd .(type ){case *_dd .PdfIndirectObject :_cbd ,_gd :=_dd .GetDict (_gf .PdfObject );if _gd {if _eb ,_ea :=_dd .GetName (_cbd .Get ("\u0054\u0079\u0070\u0065")); +_ea &&*_eb =="\u0043a\u0074\u0061\u006c\u006f\u0067"{if _ ,_bb :=_dd .GetIndirect (_cbd .Get ("\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e"));_bb {_dca ["\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e"]++;};}else if _bcg ,_gb :=_dd .GetName (_cbd .Get ("\u0053")); +_gb {_adf :=_bcg .String ();if _adf =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"||_adf =="\u0055\u0052\u0049"||_adf =="\u0047\u006f\u0054\u006f"||_adf =="\u0047\u006f\u0054o\u0052"||_adf =="\u004c\u0061\u0075\u006e\u0063\u0068"{_dca [_adf ]++; +}else if _adf =="\u0052e\u006e\u0064\u0069\u0074\u0069\u006fn"{if _ ,_fbc :=_dd .GetStream (_cbd .Get ("\u004a\u0053"));_fbc {_dca [_adf ]++;};};}else if _eece :=_cbd .Get ("\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074");_eece !=nil {_dca ["\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"]++; +}else if _df ,_dcaa :=_dd .GetIndirect (_cbd .Get ("\u0050\u0061\u0072\u0065\u006e\u0074"));_dcaa {if _ec ,_eg :=_dd .GetDict (_df .PdfObject );_eg {if _gge ,_ag :=_dd .GetDict (_ec .Get ("\u0041\u0041"));_ag {_bca :=_gge .Get ("\u004b");_gbg ,_ff :=_dd .GetIndirect (_bca ); +if _ff {if _fcg ,_fef :=_dd .GetDict (_gbg .PdfObject );_fef {if _ceg ,_egd :=_dd .GetName (_fcg .Get ("\u0053"));_egd &&*_ceg =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"{_dca ["\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"]++; +}else if _ ,_ba :=_dd .GetString (_fcg .Get ("\u004a\u0053"));_ba {_dca ["\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"]++;}else {_gff :=_gge .Get ("\u0046");if _gff !=nil {_abb ,_eeg :=_dd .GetIndirect (_gff );if _eeg {if _gbf ,_bf :=_dd .GetDict (_abb .PdfObject ); +_bf {if _cbg ,_dgab :=_dd .GetName (_gbf .Get ("\u0053"));_dgab {_fcc :=_cbg .String ();_dca [_fcc ]++;};};};};};};};};};};};};};_eec ._dg =_dca ;};func (_b *Sanitizer )processObjects (_cb []_dd .PdfObject )([]_dd .PdfObject ,error ){_bc :=[]_dd .PdfObject {}; +_cba :=_b ._c ;for _ ,_e :=range _cb {switch _fe :=_e .(type ){case *_dd .PdfIndirectObject :_ee ,_fd :=_dd .GetDict (_fe );if _fd {if _fa ,_dga :=_dd .GetName (_ee .Get ("\u0054\u0079\u0070\u0065"));_dga &&*_fa =="\u0043a\u0074\u0061\u006c\u006f\u0067"{if _ ,_fda :=_dd .GetIndirect (_ee .Get ("\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e")); +_fda &&_cba .OpenAction {_ee .Remove ("\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e");};}else if _cc ,_ad :=_dd .GetName (_ee .Get ("\u0053"));_ad {switch *_cc {case "\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074":if _cba .JavaScript {if _g ,_be :=_dd .GetStream (_ee .Get ("\u004a\u0053")); +_be {_gc :=[]byte {};_ca ,_ed :=_dd .MakeStream (_gc ,nil );if _ed ==nil {*_g =*_ca ;};};_a .Log .Debug ("\u004a\u0061\u0076\u0061\u0073\u0063\u0072\u0069\u0070\u0074\u0020a\u0063\u0074\u0069\u006f\u006e\u0020\u0073\u006b\u0069\u0070p\u0065\u0064\u002e"); +continue ;};case "\u0055\u0052\u0049":if _cba .URI {_a .Log .Debug ("\u0055\u0052\u0049\u0020ac\u0074\u0069\u006f\u006e\u0020\u0073\u006b\u0069\u0070\u0070\u0065\u0064\u002e");continue ;};case "\u0047\u006f\u0054\u006f":if _cba .GoTo {_a .Log .Debug ("G\u004fT\u004f\u0020\u0061\u0063\u0074\u0069\u006f\u006e \u0073\u006b\u0069\u0070pe\u0064\u002e"); +continue ;};case "\u0047\u006f\u0054o\u0052":if _cba .GoToR {_a .Log .Debug ("R\u0065\u006d\u006f\u0074\u0065\u0020G\u006f\u0054\u004f\u0020\u0061\u0063\u0074\u0069\u006fn\u0020\u0073\u006bi\u0070p\u0065\u0064\u002e");continue ;};case "\u004c\u0061\u0075\u006e\u0063\u0068":if _cba .Launch {_a .Log .Debug ("\u004a\u0061\u0076\u0061\u0073\u0063\u0072\u0069\u0070\u0074\u0020a\u0063\u0074\u0069\u006f\u006e\u0020\u0073\u006b\u0069\u0070p\u0065\u0064\u002e"); +continue ;};case "\u0052e\u006e\u0064\u0069\u0074\u0069\u006fn":if _gg ,_cca :=_dd .GetStream (_ee .Get ("\u004a\u0053"));_cca {_af :=[]byte {};_cd ,_eee :=_dd .MakeStream (_af ,nil );if _eee ==nil {*_gg =*_cd ;};};};}else if _aa :=_ee .Get ("\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"); +_aa !=nil &&_cba .JavaScript {continue ;}else if _fdd ,_edc :=_dd .GetName (_ee .Get ("\u0054\u0079\u0070\u0065"));_edc &&*_fdd =="\u0041\u006e\u006eo\u0074"&&_cba .JavaScript {if _bd ,_cg :=_dd .GetIndirect (_ee .Get ("\u0050\u0061\u0072\u0065\u006e\u0074")); +_cg {if _ga ,_dde :=_dd .GetDict (_bd .PdfObject );_dde {if _bdg ,_ccag :=_dd .GetDict (_ga .Get ("\u0041\u0041"));_ccag {_ge ,_eda :=_dd .GetIndirect (_bdg .Get ("\u004b"));if _eda {if _bg ,_ab :=_dd .GetDict (_ge .PdfObject );_ab {if _ce ,_cgc :=_dd .GetName (_bg .Get ("\u0053")); +_cgc &&*_ce =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"{_bg .Clear ();}else if _dc :=_bdg .Get ("\u0046");_dc !=nil {if _fb ,_bdga :=_dd .GetIndirect (_dc );_bdga {if _gce ,_cef :=_dd .GetDict (_fb .PdfObject );_cef {if _cefb ,_dcc :=_dd .GetName (_gce .Get ("\u0053")); +_dcc &&*_cefb =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"{_gce .Clear ();};};};};};};};};};};};case *_dd .PdfObjectStream :_a .Log .Debug ("\u0070d\u0066\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0073t\u0072e\u0061m\u0020\u0074\u0079\u0070\u0065\u0020\u0025T",_fe ); +case *_dd .PdfObjectStreams :_a .Log .Debug ("\u0070\u0064\u0066\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020s\u0074\u0072\u0065\u0061\u006d\u0073\u0020\u0074\u0079\u0070e\u0020\u0025\u0054",_fe );default:_a .Log .Debug ("u\u006e\u006b\u006e\u006fwn\u0020p\u0064\u0066\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0025\u0054",_fe ); +};_bc =append (_bc ,_e );};_b .analyze (_bc );return _bc ,nil ;}; + +// GetSuspiciousObjects returns a count of each detected suspicious object. +func (_fg *Sanitizer )GetSuspiciousObjects ()map[string ]int {return _fg ._dg }; + +// Sanitizer represents a sanitizer object. +// It implements the Optimizer interface to access the objects field from the writer. +type Sanitizer struct{_c SanitizationOpts ;_dg map[string ]int ;}; + +// Optimize optimizes `objects` and returns updated list of objects. +func (_f *Sanitizer )Optimize (objects []_dd .PdfObject )([]_dd .PdfObject ,error ){return _f .processObjects (objects );}; + +// New returns a new sanitizer object. +func New (opts SanitizationOpts )*Sanitizer {return &Sanitizer {_c :opts }}; \ No newline at end of file -- cgit v1.2.3