Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored setupapi parser #2717 #2718

Merged
merged 8 commits into from
Sep 2, 2019
Merged

Conversation

Onager
Copy link
Contributor

@Onager Onager commented Jul 14, 2019

Also changed the EncodedTextReader to not strip every line and updated parsers that relied on this behavior.

There's also more changes that I'd like make to the parser, but I've tried to keep changes to the tests minimal in this first round.

@codecov
Copy link

codecov bot commented Jul 15, 2019

Codecov Report

Merging #2718 into master will increase coverage by 0.07%.
The diff coverage is 92.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2718      +/-   ##
==========================================
+ Coverage   86.21%   86.28%   +0.07%     
==========================================
  Files         481      487       +6     
  Lines       32788    33062     +274     
==========================================
+ Hits        28268    28529     +261     
- Misses       4520     4533      +13
Impacted Files Coverage Δ
plaso/formatters/setupapi.py 100% <ø> (ø) ⬆️
plaso/parsers/text_parser.py 81.53% <100%> (ø) ⬆️
plaso/parsers/mac_wifi.py 90.55% <100%> (+0.07%) ⬆️
plaso/parsers/winfirewall.py 94.79% <100%> (+0.05%) ⬆️
plaso/parsers/iis.py 93.65% <100%> (+0.05%) ⬆️
plaso/parsers/setupapi.py 93.54% <91.37%> (+9.76%) ⬆️
plaso/output/shared_4n6time.py 83.33% <0%> (-1.48%) ⬇️
plaso/parsers/winreg_plugins/interface.py 96.29% <0%> (-0.93%) ⬇️
plaso/storage/fake/writer.py 84.7% <0%> (-0.55%) ⬇️
plaso/lib/definitions.py 100% <0%> (ø) ⬆️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d390dfe...e5808cb. Read the comment docs.

@Onager Onager requested a review from joachimmetz July 15, 2019 06:48
@Onager Onager assigned Onager and joachimmetz and unassigned Onager Jul 15, 2019
structure (pyparsing.ParseResults): structure of tokens derived from
log entry.
time_structure (pyparsing.ParseResults): structure of tokens derived from
a setupapi time stamp.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time stamp => date and time value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setupapi documents call this field a timestamp: https://docs.microsoft.com/en-us/windows-hardware/drivers/install/format-of-a-text-log-section-header

Clarified this.


Returns:
dfdatetime.TimeElements: date and time extracted from the value or None
if the value does not represent a valid string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a valid string => a valid date and time value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


Returns:
bool: True if this is the correct parser, False otherwise.
"""
try:
structure = self._SETUPAPI_LINE.parseString(lines)
_ = self._LOG_HEADER_START.parseString(line)
Copy link
Member

@joachimmetz joachimmetz Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove '_ =', it is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -224,7 +224,7 @@ def VerifyStructure(self, parser_mediator, line):
"""
# TODO: Examine other versions of the file format and if this parser should
# support them.
return line == '#Version: 1.5'
return '#Version: 1.5' in line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the whitespace matching. Changed this to just have the newline.

@@ -101,8 +101,8 @@ def testParseSetupLog(self):

self.CheckTimestamp(event.timestamp, '2015-11-22 17:53:29.305000')

expected_message = ('Setup Plug and Play Device Install - START')
expected_short_message = ('START - Setup Plug and Play Device Install')
expected_message = ('Setup Plug and Play Device Install')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove bounding parenthesis

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@joachimmetz joachimmetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please address comments

@Onager Onager requested a review from joachimmetz July 15, 2019 09:26
@Onager Onager requested a review from dfjxs July 15, 2019 16:31
Copy link
Contributor

@dfjxs dfjxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Should we add this to the win_gen preset?

@Onager
Copy link
Contributor Author

Onager commented Jul 16, 2019

@js-forensic - good idea, I thought this had already been done

@dfjxs dfjxs mentioned this pull request Jul 16, 2019
3 tasks
@@ -224,7 +224,8 @@ def VerifyStructure(self, parser_mediator, line):
"""
# TODO: Examine other versions of the file format and if this parser should
# support them.
return line == '#Version: 1.5'
stripped_line = line.strip()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strip() => rstrip()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@joachimmetz joachimmetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make sure that the parser does not use state from a previous file it parsed

@Onager Onager requested a review from joachimmetz July 30, 2019 20:44
@joachimmetz
Copy link
Member

joachimmetz commented Jul 31, 2019

tox tests are failing:

testExamineEventAndCompileReportOnSystemFile (analysis.windows_services.WindowsServicesTest)
1614Tests the ExamineEvent and CompileReport functions on a SYSTEM file. ... free(): invalid next size (fast)
1615ERROR: InvocationError: '/plaso/.tox/py27/bin/coverage run --source=plaso --omit=*_test*,*__init__*,*test_lib* run_tests.py'

I'll restart them, no luck, seems to be an issue with a dependency #2727

@Onager
Copy link
Contributor Author

Onager commented Aug 19, 2019

Ping for @joachimmetz


def _ParseRecordLogline(self, parser_mediator, structure):
"""Parses a logline record structure and produces events.
def _BuildDatetime(self, time_structure):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change name of this method to _GetDateTime or equiv to keep it consistent with other parsers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@joachimmetz joachimmetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small remaining questions

Copy link
Member

@joachimmetz joachimmetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joachimmetz joachimmetz merged commit e22155f into log2timeline:master Sep 2, 2019
@Onager Onager deleted the setupapi branch November 30, 2019 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants