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

Refactor PE parser and rewrite WMIC .exe version extraction #79

Merged
merged 4 commits into from
Nov 3, 2022

Conversation

Luashine
Copy link
Contributor

@Luashine Luashine commented Oct 5, 2022

The PE version extraction was refactored.
dorkbox Parser was moved to its own class behind an interface. The WMIC extractor was reworked to call wmic.exe directly without creating temporary files, that should avoid potential issues with AV software and be faster.

Tests added that rely on local java.exe and cmd.exe.
Update: At last I made a C# binary with the version info: https://github.com/Luashine/dotnet-pe-version

Completely removed the cmd.exe/java.exe tests and now only use the embedded file. The WMIC test is skipped on non-Windows.


It's been a while since I last touched Java, I'd love to hear feedback and a review.

I wanted to tackle #62 so this is part 1 basically. Probably overengineered the IO part of WMIC (just a tiny bit :P). When I tried to reenable GameExeTest, it throws an exception on my system. I will continue in #62

The PE version extraction was refactored.
dorkbox Parser was moved to its own class behind an interface.
The WMIC extractor was reworked to call wmic.exe directly
without creating temporary files, that should avoid potential issues
with AV software and be faster.

Tests added that rely on local java.exe and cmd.exe.
@Frotty
Copy link
Member

Frotty commented Oct 5, 2022

Nice. I personally didn't care enough to fix this, because you just need to set a manual path once, but it would still be nice to have. Will check and test locally later. I see you are contributing to various open source wc3 projects, cool 👍

@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2022

Codecov Report

Merging #79 (5615c85) into master (d105145) will decrease coverage by 0.11%.
The diff coverage is 4.16%.

@@             Coverage Diff              @@
##             master      #79      +/-   ##
============================================
- Coverage     40.96%   40.85%   -0.12%     
- Complexity     1722     1724       +2     
============================================
  Files           432      437       +5     
  Lines         21996    22066      +70     
  Branches       1821     1824       +3     
============================================
+ Hits           9010     9014       +4     
- Misses        12437    12502      +65     
- Partials        549      550       +1     
Impacted Files Coverage Δ
.../java/net/moonlightflower/wc3libs/bin/GameExe.java 0.00% <0.00%> (ø)
.../misc/exeversion/CallableInputStreamProcessor.java 0.00% <0.00%> (ø)
...ightflower/wc3libs/misc/exeversion/ExeVersion.java 0.00% <0.00%> (ø)
...flower/wc3libs/misc/exeversion/ExeVersionWmic.java 0.00% <0.00%> (ø)
...bs/misc/exeversion/VersionExtractionException.java 0.00% <0.00%> (ø)
...htflower/wc3libs/misc/exeversion/ExeVersionPe.java 44.44% <44.44%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.


@Test()
public void extractExeVersionTest() throws VersionExtractionException, Exception {
// These tests need some static .exe files we don't carry around currently.
Copy link
Member

Choose a reason for hiding this comment

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

I think we should rather ship some .exe file in test resources, then it can also work on CircleCI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However not the WMIC part?.. The CI runs on Linux (or whatever but not Windows). I'm gonna look to create a small program with PE Version info.

Copy link
Member

Choose a reason for hiding this comment

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

Hi, any update on this? You can disable the wmic part of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes still "in progress". At first I wanted to create a cross-compiled executable from Linux, so replicatable builds would be easy. But I don't see any way at all, nor any tools, to modify Windows-specific PE data from Linux. I just finished cleaning up my workspace today, I will follow-up soon and make a simple static binary for tests. Cheers

Copy link
Contributor Author

@Luashine Luashine Nov 2, 2022

Choose a reason for hiding this comment

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

At last I made a C# binary with the version info: https://github.com/Luashine/dotnet-pe-version

Completely removed the cmd.exe/java.exe tests and now only use the embedded file. The WMIC test is skipped on non-Windows.

EDIT/PS: Maybe I should've kept the CMD.exe file test, because dorkbox PE fetched the more than just the Version field and that required manual removal.

Added a static binary so that the dorkbox peParser can always be tested.
Windows-specific WMIC test will be properly skipped if not running Windows.
@Luashine
Copy link
Contributor Author

Luashine commented Nov 2, 2022

src/test/java/wc3libs/bin/GameExeTest.java That test still fails for me (#62), I will fix it after this PR

@Frotty
Copy link
Member

Frotty commented Nov 3, 2022

Nice 👍

@Frotty Frotty merged commit daba09b into inwc3:master Nov 3, 2022
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