Skip to content

Commit 3a4eef3

Browse files
committed
formatting & minor fixes
1 parent e1b8e11 commit 3a4eef3

File tree

12 files changed

+39
-28
lines changed

12 files changed

+39
-28
lines changed

refinery/lib/patterns/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __getattr__(self, name):
163163
R'-----END(?:\s[A-Z0-9]+)+-----'
164164
).format(n=R'(?:\r\n|\n\r|\n)', b=R'[0-9a-zA-Z\+\/]')
165165

166-
__all__ = [
166+
__all__ = [
167167
'pattern',
168168
'alphabet',
169169
'tokenize',

refinery/lib/patterns/tlds.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#!/usr/bin/env python3
32
# -*- coding: utf-8 -*-
43
tlds = ['xn\\-\\-vermgensberatung\\-pwb',

refinery/units/crypto/keyderive/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class HashAlgorithms(Enum):
2424
MD2 = MD2
2525
MD4 = MD4
2626
MD5 = MD5
27+
SHA1 = SHA1
2728
SHA256 = SHA256
2829
SHA512 = SHA512
2930
SHA224 = SHA224

refinery/units/formats/__init__.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ class PathExtractorUnit(Unit):
2727

2828
@classmethod
2929
def interface(cls, argp):
30-
argp.add_argument('paths', metavar='path', nargs='*', default=['*'], type=pathspec,
31-
help=(
32-
'A path from which data is to be extracted. Each item is returned '
33-
' as a separate output of this unit. Paths may contain wildcards. '
34-
'The default is a single asterix, which means that every item will '
35-
'be extracted.'
36-
)
37-
)
30+
argp.add_argument('paths', metavar='path', nargs='*', default=['*'], type=pathspec, help=(
31+
'A path from which data is to be extracted. Each item is returned '
32+
' as a separate output of this unit. Paths may contain wildcards. '
33+
'The default is a single asterix, which means that every item will '
34+
'be extracted.'
35+
))
3836
return super().interface(argp)
3937

4038
def _check_reachable(self, path: str) -> bool:

refinery/units/formats/deserialize_java.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from .. import Unit
1111

12+
1213
class JavaEncoder(json.JSONEncoder):
1314

1415
def encode(self, obj):
@@ -24,6 +25,7 @@ def default(self, obj):
2425
return str(obj)
2526
raise
2627

28+
2729
class dsjava(Unit):
2830
"""
2931
Deserialize Java serialized data and re-serialize as JSON.

refinery/units/formats/pe/pemeta.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from functools import lru_cache
66
from contextlib import suppress
7-
from pefile import PE
7+
from pefile import PE, DIRECTORY_ENTRY
88
from datetime import datetime, timezone
99
from asn1crypto import cms
1010
from asn1crypto import x509
@@ -22,8 +22,8 @@ class pemeta(Unit):
2222
- Timestamps
2323
- If present, .NET header information
2424
"""
25-
def __init__(self,
26-
all : arg('-c', '--custom',
25+
def __init__(
26+
self, all : arg('-c', '--custom',
2727
help='Unless enabled, everything will be extracted.') = True,
2828
version : arg('-V', help='Parse the VERSION resource.') = False,
2929
timestamps : arg('-T', help='Extract time stamps.') = False,
@@ -50,7 +50,7 @@ def _parse_pedict(self, bin):
5050

5151
@lru_cache(maxsize=1, typed=False)
5252
def _getpe(self, data: bytearray) -> PE:
53-
return PE(data=data)
53+
return PE(data=data, fast_load=True)
5454

5555
def parse_signature(self, data: bytearray) -> dict:
5656
"""
@@ -130,7 +130,9 @@ def parse_file_info(self, data: bytearray) -> dict:
130130
the version resource of an input PE file, if available.
131131
"""
132132
try:
133-
FileInfoList = self._getpe(data).FileInfo
133+
pe = self._getpe(data)
134+
pe.parse_data_directories(directories=[DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_RESOURCE']])
135+
FileInfoList = pe.FileInfo
134136
except AttributeError:
135137
return None
136138
for FileInfo in FileInfoList:
@@ -163,6 +165,13 @@ def dt(ts):
163165
return datetime.fromtimestamp(ts, tz=timezone.utc).replace(tzinfo=None)
164166

165167
pe = self._getpe(data)
168+
pe.parse_data_directories(directories=[
169+
DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_IMPORT'],
170+
DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_EXPORT'],
171+
DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_DEBUG'],
172+
DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_RESOURCE']
173+
])
174+
166175
info = {}
167176

168177
with suppress(AttributeError):

refinery/units/meta/couple.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def __init__(
2828
type=str,
2929
help='Part of an arbitrary command line to be executed.',
3030
metavar='token'),
31-
buffer : arg.switch('-b', help='Buffer the command output for one execution rather than streaming it.') = False,
32-
timeout : arg('-t', metavar='T', help='Set an execution timeout as a floating point number in seconds, there is none by default.') = 0.0
31+
buffer: arg.switch('-b', help='Buffer the command output for one execution rather than streaming it.') = False,
32+
timeout: arg('-t', metavar='T',
33+
help='Set an execution timeout as a floating point number in seconds, there is none by default.') = 0.0
3334
) -> Unit: pass
3435

3536
def process(self, data):

refinery/units/meta/emit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def process(self, data):
3838

3939
@classmethod
4040
def run(cls, argv=None, stream=None):
41-
super(emit, cls).run(argv=argv,
41+
super(emit, cls).run(
42+
argv=argv,
4243
stream=stream or open(__import__('os').devnull, 'rb')
4344
)

refinery/units/obfuscation/ps1/securestring.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import re
44

55
from .. import Deobfuscator
6-
from . import string_quote, string_escape
76
from ...crypto.cipher.secstr import secstr
87
from ...blockwise.pack import pack
98
from ....lib.patterns import formats
@@ -43,7 +42,6 @@ def _decrypt_block(self, data, match):
4342
self._secstr.args.key = self._pack(match.group(5).encode(self.codec))
4443
decoded = self._secstr(match.group(2).encode(self.codec))
4544
decoded = decoded.decode(self.codec)
46-
#result = string_quote(string_escape(decoded))
4745
result = F'\n\n{decoded}\n\n'
4846
brackets = match.group(6).count(')')
4947
start = match.start()

refinery/units/pattern/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __call__(self, match):
7272
try:
7373
fmt = fmt.decode('UNICODE_ESCAPE')
7474
except AttributeError:
75-
if type(fmt) != str:
75+
if not isinstance(fmt, str):
7676
raise
7777

7878
fmt = fmt.encode('UTF8')
@@ -272,9 +272,10 @@ def __init__(
272272
self, regex : arg(type=regexp, help='Regular expression to match.'),
273273
# TODO: Use positional only in Python 3.8
274274
# /,
275-
multiline : arg.switch('-M', help='caret and dollar match the beginning and end of a line, the dot does not match line breaks.') = False,
276-
ignorecase : arg.switch('-I', help='ignore capitalization for alphabetic characters.') = False,
277-
utf16 : arg.switch('-u', help='search for unicode patterns instead of ascii.') = False,
275+
multiline : arg.switch('-M', help='Caret and dollar match the beginning and end of '
276+
'a line, a dot does not match line breaks.') = False,
277+
ignorecase : arg.switch('-I', help='Ignore capitalization for alphabetic characters.') = False,
278+
utf16 : arg.switch('-u', help='Search for unicode patterns instead of ascii.') = False,
278279
min=1, max=None, len=None, whitespace=False, unique=False, longest=False, take=None
279280
):
280281
super().__init__(

0 commit comments

Comments
 (0)