Skip to content

Commit

Permalink
Listing file formats
Browse files Browse the repository at this point in the history
  • Loading branch information
alterakey committed May 1, 2024
1 parent ec34c91 commit 4dd536c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
11 changes: 11 additions & 0 deletions trueseeing/app/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def __init__(self, target: Optional[str], *, abort_on_errors: bool = False, forc
'?':dict(e=self._help, n='?', d='help'),
'?@?':dict(e=self._help_mod, n='?@?', d='modifier help'),
'?o?':dict(e=self._help_opt, n='?o?', d='options help'),
'?f?':dict(e=self._help_formats, n='?f?', d='supported file formats'),
'!':dict(e=self._shell, n='!', d='shell'),
'o':dict(e=self._set_target, n='o /path/to/target', d='set target file'),
'q':dict(e=self._quit, n='q', d='quit'),
Expand Down Expand Up @@ -325,6 +326,16 @@ async def _help_on(self, topic: str, entries: Dict[str, Entry]) -> None:
f'{{n:<{width}s}}{{d}}'.format(n=e['n'], d=e['d'])
)

async def _help_formats(self, args: deque[str]) -> None:
from trueseeing.core.context import FileOpener
ui.success('File formats:')
formats = list(FileOpener().get_formats())
width = 2 + max([len(e['n']) for e in formats])
for e in formats:
ui.stderr(
f'{{n:<{width}s}}{{d}}'.format(n=e['n'], d=e['d'])
)

async def _shell(self, args: deque[str]) -> None:
from trueseeing.core.env import get_shell
from asyncio import create_subprocess_exec
Expand Down
5 changes: 5 additions & 0 deletions trueseeing/app/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def invoke(self) -> int:
args_mut1 = parser.add_mutually_exclusive_group()
parser.add_argument('fn', nargs='?', metavar='FILE', help='Target APK file')
parser.add_argument('--help-signatures', action='store_true', help='Show signatures')
parser.add_argument('--help-formats', action='store_true', help='Show supported file formats')
parser.add_argument('--version', action='store_true', help='Version information')
parser.add_argument('--norc', action='store_true', help='Ignore startup file')
parser.add_argument('--noext', action='store_true', help='Ignore extensions')
Expand Down Expand Up @@ -101,6 +102,10 @@ def invoke(self) -> int:
args.no_target = True
args.mode = 'batch'
cmdlines = ['?s?']
if args.help_formats:
args.no_target = True
args.mode = 'batch'
cmdlines = ['?f?']

ui.set_level(log_level)

Expand Down
10 changes: 7 additions & 3 deletions trueseeing/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from abc import ABC, abstractmethod

if TYPE_CHECKING:
from typing import List, Dict, Optional, Set, Literal, Any, Mapping, AsyncIterator, Tuple
from typing import List, Dict, Optional, Set, Literal, Any, Mapping, AsyncIterator, Tuple, Iterator
from typing_extensions import Self
from trueseeing.api import FormatEntry
from trueseeing.core.store import Store
Expand Down Expand Up @@ -52,12 +52,16 @@ def _key(x: Tuple[str, FormatEntry]) -> int:
return c
raise InvalidFileFormatError()

def get_formats(self) -> Iterator[Mapping[str, str]]:
for k,v in self._formats.items():
yield dict(n=k, d=v['d'])

def _init_formats(self) -> None:
from trueseeing.core.ext import Extension

self._formats.update({
'apk':dict(e=self._handle_apk, r=r'\.apk$', d='apk'),
'xapk':dict(e=self._handle_xapk, r=r'\.xapk$', d='xapk'),
'apk':dict(e=self._handle_apk, r=r'\.apk$', d='Android application package'),
'xapk':dict(e=self._handle_xapk, r=r'\.xapk$', d='Android appllication bundle'),
})

for clazz in Extension.get().get_fileformathandlers():
Expand Down

0 comments on commit 4dd536c

Please sign in to comment.