Spaces:
Runtime error
Runtime error
Commit
·
87737b2
1
Parent(s):
524171c
changes
Browse files- PE_main.py +1 -18
- app.py +3 -3
PE_main.py
CHANGED
@@ -78,7 +78,7 @@ def get_version_info(pe):
|
|
78 |
#extract the info for a given file using pefile
|
79 |
def extract_infos(file):
|
80 |
res = {}
|
81 |
-
pe = pefile.PE(
|
82 |
res['Machine'] = pe.FILE_HEADER.Machine
|
83 |
res['SizeOfOptionalHeader'] = pe.FILE_HEADER.SizeOfOptionalHeader
|
84 |
res['Characteristics'] = pe.FILE_HEADER.Characteristics
|
@@ -182,20 +182,3 @@ def extract_infos(file):
|
|
182 |
res['VersionInformationSize'] = 0
|
183 |
return res
|
184 |
|
185 |
-
|
186 |
-
if __name__ == '__main__':
|
187 |
-
|
188 |
-
#Loading the classifier.pkl and features.pkl
|
189 |
-
clf = joblib.load('Classifier/classifier.pkl')
|
190 |
-
features = pickle.loads(open(os.path.join('Classifier/features.pkl'),'rb').read())
|
191 |
-
|
192 |
-
#extracting features from the PE file mentioned in the argument
|
193 |
-
data = extract_infos(sys.argv[1])
|
194 |
-
|
195 |
-
#matching it with the features saved in features.pkl
|
196 |
-
pe_features = list(map(lambda x:data[x], features))
|
197 |
-
print("Features used for classification: ", pe_features)
|
198 |
-
|
199 |
-
#prediciting if the PE is malicious or not based on the extracted features
|
200 |
-
res= clf.predict([pe_features])[0]
|
201 |
-
print ('The file %s is %s' % (os.path.basename(sys.argv[1]),['malicious', 'legitimate'][res]))
|
|
|
78 |
#extract the info for a given file using pefile
|
79 |
def extract_infos(file):
|
80 |
res = {}
|
81 |
+
pe = pefile.PE(file)
|
82 |
res['Machine'] = pe.FILE_HEADER.Machine
|
83 |
res['SizeOfOptionalHeader'] = pe.FILE_HEADER.SizeOfOptionalHeader
|
84 |
res['Characteristics'] = pe.FILE_HEADER.Characteristics
|
|
|
182 |
res['VersionInformationSize'] = 0
|
183 |
return res
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -117,7 +117,7 @@ def encode_quantize(test_file, eval_key, encodings):
|
|
117 |
# features = pickle.loads(open(os.path.join("features.pkl"), "rb").read())
|
118 |
|
119 |
|
120 |
-
encodings = extract_infos(test_file)
|
121 |
|
122 |
encodings = list(map(lambda x: encodings[x], ugly))
|
123 |
|
@@ -302,7 +302,7 @@ if __name__ == "__main__":
|
|
302 |
gr.Markdown(
|
303 |
"Upload a file you want to scan for malware. ClairVault will encrypt it locally before sending it to the cloud."
|
304 |
)
|
305 |
-
file_input = gr.File(label="Upload a file:")
|
306 |
|
307 |
gr.Markdown("# 📥 Step 3: Extract executable file features")
|
308 |
|
@@ -348,7 +348,7 @@ if __name__ == "__main__":
|
|
348 |
scan_result = gr.Textbox(label="Scan Result:")
|
349 |
|
350 |
# Button for key generation
|
351 |
-
b_gen_key.click(keygen(eval_key), inputs=[], outputs=[])
|
352 |
|
353 |
# Button to extract vector
|
354 |
b_extract.click(
|
|
|
117 |
# features = pickle.loads(open(os.path.join("features.pkl"), "rb").read())
|
118 |
|
119 |
|
120 |
+
encodings = extract_infos(test_file.name)
|
121 |
|
122 |
encodings = list(map(lambda x: encodings[x], ugly))
|
123 |
|
|
|
302 |
gr.Markdown(
|
303 |
"Upload a file you want to scan for malware. ClairVault will encrypt it locally before sending it to the cloud."
|
304 |
)
|
305 |
+
file_input = gr.File(label="Upload a file:", live=True, file_count = "single")
|
306 |
|
307 |
gr.Markdown("# 📥 Step 3: Extract executable file features")
|
308 |
|
|
|
348 |
scan_result = gr.Textbox(label="Scan Result:")
|
349 |
|
350 |
# Button for key generation
|
351 |
+
b_gen_key.click(keygen(eval_key), inputs=[], outputs=[evaluation_key])
|
352 |
|
353 |
# Button to extract vector
|
354 |
b_extract.click(
|