Skip to content

Commit

Permalink
Merge pull request #2044 from nbargnesi/no-more-package-name
Browse files Browse the repository at this point in the history
fix/rework private package configuration
  • Loading branch information
doomedraven authored Apr 5, 2024
2 parents a5e6bef + 808a950 commit 70a0f1e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions analyzer/windows/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def run(self):
except Exception as e:
log.exception(e)
# Initialize the package parent abstract.
Package(package_name)
Package()
# Enumerate the abstract subclasses.
try:
package_class = Package.__subclasses__()[0]
Expand All @@ -408,7 +408,7 @@ def run(self):

# Initialize the analysis package.
log.debug('Initializing analysis package "%s"...', package)
self.package = package_class(package_name, self.options, self.config)
self.package = package_class(self.options, self.config)
# log.debug('Initialized analysis package "%s"', package)

# Move the sample to the current working directory as provided by the
Expand Down
6 changes: 3 additions & 3 deletions analyzer/windows/lib/common/abstracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ class Package:
PATHS = []
default_curdir = None

def __init__(self, name: str, options=None, config=None):
def __init__(self, options=None, config=None):
"""@param options: options dict."""
self.name = name
if options is None:
options = {}
self.config = config
Expand Down Expand Up @@ -80,7 +79,8 @@ def configure_from_data(self, target: str):
- AttributeError if the module configure function is invalid.
- ModuleNotFoundError if the module does not support configuration from data
"""
module_name = f"data.packages.{self.name}"
package_module_name = self.__class__.__module__.split('.')[-1]
module_name = f"data.packages.{package_module_name}"
try:
m = importlib.import_module(module_name)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion analyzer/windows/tests/lib/common/test_abstracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestPackageConfiguration(unittest.TestCase):

def test_private_package_configuration(self):
# test analysis package
package_module = "configuration_package"
package_module = self.__class__.__module__
# and its private configuration module
module_name = f"data.packages.{package_module}"

Expand Down
4 changes: 2 additions & 2 deletions analyzer/windows/tests/modules/packages/test_ps1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_get_paths(self):
"""By default, the first path should be powershell.exe"""
package_name = "modules.packages.ps1"
__import__(package_name, globals(), locals(), ["dummy"])
ps1_module = PS1(package_name)
ps1_module = PS1()
paths = ps1_module.get_paths()
assert paths[0][-1] == "powershell.exe"
all_paths = set([path[-1] for path in paths])
Expand All @@ -19,7 +19,7 @@ def test_get_paths_powershell_core(self):
options = {"pwsh": True}
package_name = "modules.packages.ps1"
__import__(package_name, globals(), locals(), ["dummy"])
ps1_module = PS1(package_name, options=options)
ps1_module = PS1(options=options)
paths = ps1_module.get_paths()
assert paths[0][-1] == "pwsh.exe"
all_paths = set([path[-1] for path in paths])
Expand Down

0 comments on commit 70a0f1e

Please sign in to comment.