Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
87owo authored Sep 10, 2024
1 parent a2f4a72 commit 857f184
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 40 deletions.
5 changes: 3 additions & 2 deletions PYAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
self.pyas = sys.argv[0].replace("\\", "/")
self.dir = os.path.dirname(self.pyas)
self.pyae_version = "AI Engine"
self.pyas_version = "3.1.8"
self.pyas_version = "3.1.9"
self.first_startup = True
self.init_data_base()
self.init_tray_icon()
Expand Down Expand Up @@ -1333,7 +1333,8 @@ def handle_new_process(self, p):
elif self.memory_scan(p):
self.kill_process("記憶體攔截", p, file, False)
elif ":/Windows" not in file and ":/Program" not in file:
if os.path.exists(file):
ftype = str(f".{file.split('.')[-1]}").lower()
if os.path.exists(file) and ftype in slist:
self.track_proc = p, file, True
except:
pass
Expand Down
57 changes: 23 additions & 34 deletions PYAS_Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ def __init__(self):
self.network = []

def load_rules(self, file_path):
ftype = str(f".{file_path.split('.')[-1]}").lower()
if ftype in [".yara", ".yar"]:
self.rules[file_path] = yara.compile(file_path)
elif ftype in [".yc", ".yrc"]:
self.rules[file_path] = yara.load(file_path)
elif ftype in [".ip", ".ips"]:
with open(file_path, "r") as f:
self.network += [l.strip() for l in f.readlines()]
try:
ftype = str(f".{file_path.split('.')[-1]}").lower()
if ftype in [".yara", ".yar"]:
self.rules[file_path] = yara.compile(file_path)
elif ftype in [".yc", ".yrc"]:
self.rules[file_path] = yara.load(file_path)
elif ftype in [".ip", ".ips"]:
with open(file_path, "r") as f:
self.network += [l.strip() for l in f.readlines()]
except:
pass

def yr_scan(self, file_path):
try:
Expand All @@ -41,33 +44,19 @@ def load_model(self, file_path):
if ftype in [".json", ".txt"]:
with open(file_path, 'r') as f:
self.class_names = json.load(f)
elif ftype in [".onnx"]:
self.models[file_path] = onnxruntime.InferenceSession(file_path)
self.values = self.class_names['Values']
self.detect = self.class_names['Detect']
available_providers = onnxruntime.get_available_providers()
preferred_providers = [
'CUDAExecutionProvider', 'ROCmExecutionProvider',
'OpenVINOExecutionProvider', 'DirectMLExecutionProvider',
'AzureExecutionProvider', 'CPUExecutionProvider']
providers = [p for p in preferred_providers if p in available_providers]
for model in self.class_names['Models']:
model_path = os.path.join(os.path.dirname(file_path), model)
try:
self.models[model] = onnxruntime.InferenceSession(
model_path, providers=providers)
except Exception as e:
self.models[model] = onnxruntime.InferenceSession(
model_path, providers=['CPUExecutionProvider'])
except Exception as e:
except:
pass

def dl_scan(self, file_path):
try:
if isinstance(file_path, str):
file_data = self.check_file_type(file_path)
else:
file_data = file_path
file_path = self.check_file_type(file_path)
target_size, sim = tuple(self.class_names['Pixels']), {}
image = self.preprocess_image(file_data, target_size)
image = self.preprocess_image(file_path, target_size)
image_array = numpy.array(image).astype('float32') / 255.0
image_expand = numpy.expand_dims(image_array, axis=0)
for model_name, model in self.models.items():
Expand All @@ -81,24 +70,24 @@ def dl_scan(self, file_path):
local_level = sim_sum / len(self.models)
return local_label, local_level * 100
return False, False
except Exception as e:
except:
return False, False

def check_file_type(self, file_path):
try:
ftype = str(f".{file_path.split('.')[-1]}").lower()
if ftype in [".exe", ".dll", ".sys", ".com"]:
if ftype in [".exe", ".dll", ".sys"]:
with pefile.PE(file_path, fast_load=True) as pe:
for section in pe.sections:
if (section.Characteristics & pefile.SECTION_CHARACTERISTICS['IMAGE_SCN_MEM_EXECUTE'] and
section.Characteristics & pefile.SECTION_CHARACTERISTICS['IMAGE_SCN_MEM_READ'] and
if (section.Characteristics & pefile.SECTION_CHARACTERISTICS['IMAGE_SCN_MEM_READ'] and
section.Characteristics & pefile.SECTION_CHARACTERISTICS['IMAGE_SCN_MEM_EXECUTE'] and
section.SizeOfRawData > 0 and section.Name.decode().strip('\x00').lower() in [".text"]):
return section.get_data()
elif ftype in [".bat", ".cmd", ".vbs", ".ps1"]:
elif ftype in [".bat", ".vbs", ".ps1"]:
with open(file_path, 'rb') as f:
return f.read()
return False
except Exception as e:
return matching_data if matching_data else False
except:
return False

def preprocess_image(self, file_data, target_size):
Expand Down
7 changes: 4 additions & 3 deletions PYAS_Suffixes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
slist = [".exe",".dll",".com",".msi",".scr",
".js",".bat",".cmd",".ps1",".vbs"]
slist = [".exe",".dll",".sys",".com",".scr",
".bat",".ps1",".vbs",".cmd",".js"]

alist = [".exe",".dll",".zip",".7z",".rar",
alist = [".exe",".dll",".sys",".com",".scr",
".zip",".7z",".rar",".tar",".gz",
".js",".bat",".cmd",".ps1",".vbs",
".ppt",".pptx",".wps",".txt",".rtf",
".pdf",".xls",".xlsx",".doc",".docx",
Expand Down
2 changes: 1 addition & 1 deletion PYAS_Version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pyinstaller_versionfile.create_versionfile(
output_file="versionfile.txt",
version='3.1.8',
version='3.1.9',
company_name="PYAS Security",
file_description="Python Antivirus Software",
internal_name="PYAS",
Expand Down

0 comments on commit 857f184

Please sign in to comment.