malwareDetector 0.1.7__tar.gz → 0.1.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of malwareDetector might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: malwareDetector
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: Malware detector specification for NTUST isLab
5
5
  Author: PO-LIN LAI
6
6
  Author-email: bolin8017@gmail.com
@@ -9,17 +9,33 @@ from pydantic import BaseModel, Extra
9
9
  from typing import List, Any
10
10
  from .const import *
11
11
 
12
- class PathConfig(BaseModel):
12
+ class PathConfig(BaseModel, extra=Extra.allow):
13
13
  '''
14
14
  The `PathConfig` class stores the input file path
15
15
  and output file path settings for the detector,
16
16
  which are obtained from `parameter_parser()`.
17
17
  If no additional settings are provided,
18
18
  default values will be used.
19
+
20
+ If you wish to create a customized parameter,
21
+ there has two methods to do it.
22
+ 1. please refer to the `set_param` and `del_param`
23
+ method of the `PathConfig` class.
24
+ 2. directly set the parameter in the `config.json` file.
19
25
  '''
20
26
  input: str = DEFAULT_INPUT_PATH
21
27
  output: str = DEFAULT_OUT_PATH
22
28
 
29
+ def set_param(self, __name: str, __value: Any):
30
+ if hasattr(self, __name):
31
+ raise AttributeError(f"Parameter {__name} already exists.")
32
+ else:
33
+ setattr(self, __name, __value)
34
+
35
+ def del_param(self, __name: str):
36
+ if hasattr(self, __name):
37
+ delattr(self, __name)
38
+
23
39
  class ModelConfig(BaseModel, extra=Extra.allow):
24
40
  '''
25
41
  The `ModelConfig` class stores the
@@ -29,8 +45,10 @@ class ModelConfig(BaseModel, extra=Extra.allow):
29
45
  default values will be used.
30
46
 
31
47
  If you wish to create a customized parameter,
32
- please refer to the `set_param` method of
33
- the `ModelConfig` class.
48
+ there has two methods to do it.
49
+ 1. please refer to the `set_param` and `del_param`
50
+ method of the `ModelConfig` class.
51
+ 2. directly set the parameter in the `config.json` file.
34
52
  '''
35
53
  modelName: str = DEFAULT_MODEL_NAME
36
54
  dimensions: int = DEFAULT_DIMENSIONS
@@ -56,19 +74,20 @@ class FolderConfig(BaseModel, extra=Extra.allow):
56
74
  The `FolderConfig` class stores the names
57
75
  of folders where the stored data is kept.
58
76
 
59
- If you wish to create a customized folder,
60
- please refer to the `set_folder` method of
61
- the `FolderConfig` class.
77
+ If you wish to create a customized parameter,
78
+ there has two methods to do it.
79
+ 1. please refer to the `set_folder` and `del_folder`
80
+ method of the `FolderConfig` class.
81
+ 2. directly set the parameter in the `config.json` file.
62
82
  '''
63
83
  dataset: str = DATASET_DIR
64
84
  feature: str = FEATURE_DIR
65
85
  vectorize: str = VECTORIZE_DIR
66
86
  model: str = MODEL_DIR
67
87
  predict: str = PREDICT_DIR
68
- folder_list: List[str] = [dataset, feature, vectorize, model, predict]
69
88
 
70
89
  def update_folder_list(self):
71
- self.folder_list = [self.dataset, self.feature, self.vectorize, self.model, self.predict]
90
+ self.folder_list = [getattr(self, folder) for folder in self.__dict__.keys()]
72
91
 
73
92
  def __iter__(self):
74
93
  return FolderClassIter(self.folder_list)
@@ -110,7 +129,7 @@ class FolderClassIter(object):
110
129
  return member
111
130
  raise StopIteration
112
131
 
113
- class Config(BaseModel):
132
+ class Config(BaseModel, extra=Extra.allow):
114
133
  '''
115
134
  The `Config` class stores all the external settings
116
135
  for the detector, which are obtained from `parameter_parser()`.
@@ -121,12 +140,28 @@ class Config(BaseModel):
121
140
  `FolderConfig`: Contains configurations for folders and directories.
122
141
  `ModelConfig`: Includes settings specific to the model.
123
142
  `classify`: Determines whether the task is malware family classification or simple malware detection.
143
+
144
+ If you wish to create a customized parameter,
145
+ there has two methods to do it.
146
+ 1. please refer to the `set_param` and `del_param`
147
+ method of the `Config` class.
148
+ 2. directly set the parameter in the `config.json` file.
124
149
  '''
125
150
  path: PathConfig = PathConfig()
126
151
  folder: FolderConfig = FolderConfig()
127
152
  model: ModelConfig = ModelConfig()
128
153
  classify: bool = DEFAULT_CLASSIFY
129
154
 
155
+ def set_param(self, __name: str, __value: Any):
156
+ if hasattr(self, __name):
157
+ raise AttributeError(f"Parameter {__name} already exists.")
158
+ else:
159
+ setattr(self, __name, __value)
160
+
161
+ def del_param(self, __name: str):
162
+ if hasattr(self, __name):
163
+ delattr(self, __name)
164
+
130
165
  def parameter_parser(config: Config) -> Config:
131
166
  '''
132
167
  A method for parsing command line parameters
@@ -233,10 +268,11 @@ def write_config_to_file(config: Config):
233
268
  Writes the parameter settings of
234
269
  the config object to a JSON file in
235
270
  the execution folder with the
236
- default name `"config.json."`
271
+ default name `config.json`.
237
272
  '''
273
+
238
274
  with open(CONFIG_FILE_NAME, "w", encoding="utf8") as file:
239
- file.write(config.json())
275
+ file.write(config.json(exclude={"folder": {"folder_list"}}))
240
276
 
241
277
  def detect_config_file() -> None:
242
278
  '''
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: malwareDetector
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: Malware detector specification for NTUST isLab
5
5
  Author: PO-LIN LAI
6
6
  Author-email: bolin8017@gmail.com
@@ -11,7 +11,7 @@ required_packages = [
11
11
  setup(
12
12
  name='malwareDetector',
13
13
  packages=find_packages(include=['malwareDetector']),
14
- version='0.1.7',
14
+ version='0.1.9',
15
15
  description='Malware detector specification for NTUST isLab',
16
16
  long_description=long_description,
17
17
  long_description_content_type="text/markdown",