malwareDetector 0.1.9__tar.gz → 0.1.11__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.9
3
+ Version: 0.1.11
4
4
  Summary: Malware detector specification for NTUST isLab
5
5
  Author: PO-LIN LAI
6
6
  Author-email: bolin8017@gmail.com
@@ -25,6 +25,7 @@ class PathConfig(BaseModel, extra=Extra.allow):
25
25
  '''
26
26
  input: str = DEFAULT_INPUT_PATH
27
27
  output: str = DEFAULT_OUT_PATH
28
+ config: str = DEFAULT_CONFIG_PATH
28
29
 
29
30
  def set_param(self, __name: str, __value: Any):
30
31
  if hasattr(self, __name):
@@ -185,6 +186,12 @@ def parameter_parser(config: Config) -> Config:
185
186
  help="Embeddings path."
186
187
  )
187
188
 
189
+ parser.add_argument("--config-path","-c",
190
+ dest="config_path",
191
+ nargs="?",
192
+ default=DEFAULT_CONFIG_PATH,
193
+ help="Configuration file path.")
194
+
188
195
  parser.add_argument("--dimensions",
189
196
  dest="dimensions",
190
197
  type=int,
@@ -241,7 +248,7 @@ def parameter_parser(config: Config) -> Config:
241
248
  help='Select the model(KNN, LR, MLP, RF, SVM).'
242
249
  )
243
250
 
244
- parser.add_argument('--classify', '-c',
251
+ parser.add_argument('--classify', '-f',
245
252
  dest="classify",
246
253
  action='store_true',
247
254
  default=DEFAULT_CLASSIFY,
@@ -251,6 +258,7 @@ def parameter_parser(config: Config) -> Config:
251
258
  args = parser.parse_args()
252
259
  config.path.input = args.input_path
253
260
  config.path.output = args.output_path
261
+ config.path.config = args.config_path
254
262
  config.model.dimensions = args.dimensions
255
263
  config.model.workers = args.workers
256
264
  config.model.epochs = args.epochs
@@ -263,58 +271,62 @@ def parameter_parser(config: Config) -> Config:
263
271
 
264
272
  return config
265
273
 
266
- def write_config_to_file(config: Config):
274
+ def write_config_to_file(config: Config, config_file_path=DEFAULT_CONFIG_PATH):
267
275
  '''
268
- Writes the parameter settings of
269
- the config object to a JSON file in
270
- the execution folder with the
271
- default name `config.json`.
276
+ Writes the parameter settings of the config object to a JSON file
277
+ in the execution folder with the default path `"./config.json."`
278
+ or you can specify the path by passing the `config_file_path` parameter.
272
279
  '''
273
280
 
274
- with open(CONFIG_FILE_NAME, "w", encoding="utf8") as file:
281
+ with open(config_file_path, "w", encoding="utf8") as file:
275
282
  file.write(config.json(exclude={"folder": {"folder_list"}}))
276
283
 
277
- def detect_config_file() -> None:
284
+ def detect_config_file(config_file_path=DEFAULT_CONFIG_PATH) -> None:
278
285
  '''
279
286
  If you run Python using the IPython approach,
280
287
  the command line parsing functionality will not be enabled.
281
288
  On the other hand, if you execute Python in the regular way,
282
289
  it will utilize argparse to read the parameters passed through the command line.
290
+ default config.json will be created in the local folder if it does not exist.
291
+ `config_file_path` is the path to the config file.
283
292
  '''
284
293
 
285
294
  if 'ipykernel' not in sys.modules and len(sys.argv) > 1:
286
295
  logging.info(
287
296
  "Creating local config file by argparse."
288
297
  )
289
- write_config_to_file(parameter_parser(Config()))
290
- logging.info(f"{CONFIG_FILE_NAME} created!")
291
- elif CONFIG_FILE_NAME in os.listdir():
292
- logging.info(f"{CONFIG_FILE_NAME} detected!")
298
+ config = parameter_parser(Config())
299
+ config_file_path = config.path.config
300
+ write_config_to_file(config, config.path.config)
301
+ logging.info(f"{config_file_path} created!")
302
+ elif config_file_path in os.listdir():
303
+ logging.info(f"{config_file_path} detected!")
293
304
  else:
294
305
  logging.info(
295
306
  "config file not found. creating local config file by default config."
296
307
  )
297
- write_config_to_file(Config())
298
- logging.info(f"{CONFIG_FILE_NAME} created!")
308
+ write_config_to_file(Config(), config_file_path)
309
+ logging.info(f"{config_file_path} created!")
310
+ return config_file_path
299
311
 
300
- def read_config(count=1) -> Config:
312
+ def read_config(config_file_path=DEFAULT_CONFIG_PATH, count=1) -> Config:
301
313
  '''
302
- Reads the settings from the `config.json` file.
314
+ Reads the settings from config_file_path and returns a Config object.
303
315
  '''
316
+
304
317
  if count > 3:
305
318
  logging.warning("Failed to read config, returning default config")
306
319
  return Config()
307
320
  if count != 1:
308
321
  logging.info(f"Trying to read config time:{count}")
309
322
  try:
310
- with open(CONFIG_FILE_NAME, encoding="utf-8") as file:
323
+ config_file_path = detect_config_file(config_file_path=config_file_path)
324
+ with open(config_file_path, encoding="utf-8") as file:
311
325
  config = Config.parse_raw(file.read())
312
326
  config.folder.update_folder_list()
313
327
  return config
314
328
  except Exception as err:
315
329
  logging.warning(err)
316
- detect_config_file(argparse=False)
317
- return read_config(count=count+1)
330
+ return read_config(config_file_path=config_file_path, count=count+1)
318
331
 
319
- detect_config_file()
320
332
  logging.info("config.py got executed")
@@ -1,10 +1,10 @@
1
1
  '''
2
2
  Save the variables of the system's default constants.
3
3
  '''
4
- CONFIG_FILE_NAME="config.json"
5
4
 
6
5
  DEFAULT_INPUT_PATH="./Dataset/malware"
7
6
  DEFAULT_OUT_PATH="./Feature/feature.csv"
7
+ DEFAULT_CONFIG_PATH="./config.json"
8
8
  DEFAULT_MODEL_NAME="SVM"
9
9
  DEFAULT_DIMENSIONS=128
10
10
  DEFAULT_WORKERS=4
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: malwareDetector
3
- Version: 0.1.9
3
+ Version: 0.1.11
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.9',
14
+ version='0.1.11',
15
15
  description='Malware detector specification for NTUST isLab',
16
16
  long_description=long_description,
17
17
  long_description_content_type="text/markdown",