Skip to content

Instantly share code, notes, and snippets.

@zhaofengli
Created December 14, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhaofengli/0b023952840ea0b0b2c92fb2594f9e81 to your computer and use it in GitHub Desktop.
Save zhaofengli/0b023952840ea0b0b2c92fb2594f9e81 to your computer and use it in GitHub Desktop.
esafenet.py
diff --git a/esafenet.py b/esafenet.py
index e91c284..80cf7dc 100644
--- a/esafenet.py
+++ b/esafenet.py
@@ -124,10 +124,28 @@ class Esafenet:
if not os.path.isdir(dest_folder + "/" + nr + d):
os.mkdir(dest_folder + "/" + nr + d)
for f in files:
- fl = open(root + "/" + f, "rb")
- dec = Esafenet.decrypt_file(fl.read(), key)
+ # It's dirty and I know it
+ try:
+ fl = open(root + "/" + f, "rb")
+ except:
+ continue
+
+ fbyte = fl.read(3)
+ if len(fbyte) >= 3:
+ fchar = struct.unpack('ccc', fbyte)
+ fl.seek(0)
+
+ if fchar[0] == 'b' and fchar[2] == '#':
+ # Encrypted
+ dec = Esafenet.decrypt_file(fl.read(), key)
+ with open(dest_folder + "/" + nr + f, "wb") as fh:
+ fh.write(dec)
+
+ continue
+
+ # Not encrypted
with open(dest_folder + "/" + nr + f, "wb") as fh:
- fh.write(dec)
+ fh.write(fl.read())
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment