Skip to content

Commit

Permalink
Merge pull request #3361 from trailofbits/3360-undocumented-ternary-o…
Browse files Browse the repository at this point in the history
…perator

Support for the undocumented `${x?:}` libMagic ternary operator
  • Loading branch information
ESultanik authored May 14, 2021
2 parents b0e4e95 + 85aa032 commit 004362f
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 174 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/check_version.yml

This file was deleted.

3 changes: 1 addition & 2 deletions polyfile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import nes, pdf, zipmatcher, trid, kaitaimatcher, polyfile
from .__main__ import main
from .version import __version__, VERSION_STRING

from .polyfile import __version__
16 changes: 8 additions & 8 deletions polyfile/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
from . import html
from . import logger
from . import polyfile
from . import trid
from . import version
from .fileutils import PathOrStdin
from .magic import MagicMatcher
from .magic import MagicMatcher, MatchContext
from .polyfile import __version__


log = logger.getStatusLogger("polyfile")
Expand Down Expand Up @@ -57,15 +56,16 @@ def main(argv=None):
parser.add_argument('--trace', '-dd', action='store_true', help='print extra verbose debug information')
parser.add_argument('--quiet', '-q', action='store_true', help='suppress all log output (overrides --debug)')
parser.add_argument('--version', '-v', action='store_true', help='print PolyFile\'s version information to STDERR')
parser.add_argument('-dumpversion', action='store_true', help='print PolyFile\'s raw version information to STDOUT and exit')
parser.add_argument('-dumpversion', action='store_true',
help='print PolyFile\'s raw version information to STDOUT and exit')

if argv is None:
argv = sys.argv

args = parser.parse_args(argv[1:])

if args.dumpversion:
print(' '.join(map(str, version.__version__)))
print(__version__)
exit(0)

if args.list:
Expand All @@ -74,7 +74,7 @@ def main(argv=None):
exit(0)

if args.version:
sys.stderr.write(f"PolyFile version {version.VERSION_STRING}\n")
sys.stderr.write(f"PolyFile version {__version__}\n")
if args.FILE == '-' and sys.stdin.isatty():
# No file argument was provided and it doesn't look like anything was piped into STDIN,
# so instead of blocking on STDIN just exit
Expand Down Expand Up @@ -122,7 +122,7 @@ def main(argv=None):
# figure out the longest MIME type so we can make sure the columns are aligned
longest_mimetype = max(len(mimetype) for mimetype in magic_matcher.mimetypes)
mimetypes = set()
for match in magic_matcher.match(f.read(), only_match_mime=True):
for match in magic_matcher.match(MatchContext.load(f, only_match_mime=True)):
new_mimetypes = match.mimetypes - mimetypes
mimetypes |= new_mimetypes
matches.extend(new_mimetypes)
Expand Down Expand Up @@ -202,7 +202,7 @@ def main(argv=None):
'fileName': filename,
'length': file_length,
'versions': {
'polyfile': version.VERSION_STRING
'polyfile': __version__
},
'struc': [
match.to_obj() for match in matches
Expand Down
3 changes: 2 additions & 1 deletion polyfile/kaitaimatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"application/vnd.tcpdump.pcap": "network/pcap.ksy",
"application/x-sqlite3": "database/sqlite3.ksy",
"application/x-rar": "archive/rar.ksy",
"font/sfnt": "font/ttf.ksy"
"font/sfnt": "font/ttf.ksy",
"application/x-pie-executable": "executable/elf.ksy"
}

IMAGE_MIMETYPES = {
Expand Down
Loading

0 comments on commit 004362f

Please sign in to comment.