Skip to content

Commit

Permalink
Improved python3 compatibility of analysis plugin tests log2timeline#…
Browse files Browse the repository at this point in the history
…1927 (log2timeline#1930)

* Improved python3 compatibility of analysis plugin tests log2timeline#1927
  • Loading branch information
Onager committed Jun 11, 2018
1 parent 12454e4 commit 5fe5562
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
14 changes: 6 additions & 8 deletions plaso/analysis/chrome_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,20 @@ def _GetTitleFromChromeWebStore(self, extension_identifier):
self.NAME, extension_identifier))
return None

first_line, _, _ = page_content.partition(b'\n')
first_line, _, _ = page_content.partition('\n')
match = self._TITLE_RE.search(first_line)
name = None
if match:
title = match.group(1)
if title.startswith(b'Chrome Web Store - '):
if title.startswith('Chrome Web Store - '):
name = title[19:]
elif title.endswith(b'- Chrome Web Store'):
elif title.endswith('- Chrome Web Store'):
name = title[:-19]

if not name:
self._extensions[extension_identifier] = 'UNKNOWN'
return None

name = name.decode('utf-8', errors='replace')
self._extensions[extension_identifier] = name
return name

Expand Down Expand Up @@ -199,12 +198,11 @@ def ExamineEvent(self, mediator, event):
else:
user = 'Not found ({0:s})'.format(filename)

extension = self._GetTitleFromChromeWebStore(extension_identifier)
if not extension:
extension = extension_identifier
extension_string = self._GetTitleFromChromeWebStore(extension_identifier)
if not extension_string:
extension_string = extension_identifier

self._results.setdefault(user, [])
extension_string = extension.decode('utf-8', errors='ignore')
if (extension_string, extension_identifier) not in self._results[user]:
self._results[user].append((extension_string, extension_identifier))

Expand Down
2 changes: 1 addition & 1 deletion plaso/analysis/nsrlsvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _GetSocket(self):
'Unable to connect to nsrlsvr with error: {0!s}.'.format(exception))

def _QueryHash(self, nsrl_socket, digest):
"""Queries nsrlsvr for a specfic hash.
"""Queries nsrlsvr for a specific hash.
Args:
nsrl_socket (socket._socketobject): socket of connection to nsrlsvr.
Expand Down
6 changes: 3 additions & 3 deletions plaso/analysis/windows_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ def FromEvent(cls, service_event):
"""
_, _, name = service_event.key_path.rpartition(
WindowsService._REGISTRY_KEY_PATH_SEPARATOR)
service_type = service_event.regvalue.get('Type')
image_path = service_event.regvalue.get('ImagePath')
start_type = service_event.regvalue.get('Start')
service_type = service_event.regvalue.get('Type', '')
image_path = service_event.regvalue.get('ImagePath', '')
start_type = service_event.regvalue.get('Start', '')
service_dll = service_event.regvalue.get('ServiceDll', '')
object_name = service_event.regvalue.get('ObjectName', '')

Expand Down
14 changes: 14 additions & 0 deletions plaso/containers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ def __init__(self):
# TODO: add a solution for event_data_entry_index,
# event_data_stream_number and event_data_row_identifier

# This method is necessary for heap sort.
def __lt__(self, other):
"""Compares if the event attribute container is less than the other.
Events are compared by timestamp.
Args:
other (EventObject): event attribute container to compare to.
Returns:
bool: True if the event attribute container is less than the other.
"""
return self.timestamp < other.timestamp

def GetEventDataIdentifier(self):
"""Retrieves the identifier of the event data associated with the event.
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/nsrlsvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def recv(self, unused_buffer_size):
self._data = None

if expected_data:
return 'OK 1'
return b'OK 1'

return 'OK 0'
return b'OK 0'

def sendall(self, data):
"""Mocks the socket.sendall method"""
Expand Down

0 comments on commit 5fe5562

Please sign in to comment.