def start_gui(self):
'''
@summary: Initialises and launches the ransomware GUI screen
'''
# Get Crypter start_time
start_time = self.get_start_time()
app = wx.App()
# TODO Update this to new path and place in __init__
#sys._MEIPASS = "..\\build\\images"
crypter_gui = Gui.Gui(
image_path=sys._MEIPASS,
start_time=start_time,
decrypter=self,
config=self.__config)
crypter_gui.Show()
app.MainLoop()
python类_MEIPASS的实例源码
def readDiscoveryFile(api_version):
disc_filename = u'%s.json' % (api_version)
disc_file = os.path.join(GM.Globals[GM.GAM_PATH], disc_filename)
if hasattr(sys, u'_MEIPASS'):
pyinstaller_disc_file = os.path.join(sys._MEIPASS, disc_filename)
else:
pyinstaller_disc_file = None
if os.path.isfile(disc_file):
json_string = readFile(disc_file, continueOnError=True, displayError=True)
elif pyinstaller_disc_file:
json_string = readFile(pyinstaller_disc_file, continueOnError=True, displayError=True)
else:
json_string = None
if not json_string:
invalidDiscoveryJsonExit(disc_file)
try:
discovery = json.loads(json_string)
return (disc_file, discovery)
except ValueError:
invalidDiscoveryJsonExit(disc_file)
def initGDataObject(gdataObj, api):
if hasattr(sys, u'_MEIPASS') and not GM.Globals[GM.CACERTS_TXT]:
GM.Globals[GM.CACERTS_TXT] = os.path.join(sys._MEIPASS, u'httplib2', u'cacerts.txt')
os.environ['REQUESTS_CA_BUNDLE'] = GM.Globals[GM.CACERTS_TXT]
os.environ['DEFAULT_CA_BUNDLE_PATH'] = GM.Globals[GM.CACERTS_TXT]
_, _, api_version, cred_family = API.getVersion(api)
disc_file, discovery = readDiscoveryFile(api_version)
GM.Globals[GM.CURRENT_API_USER] = None
credentials = getClientCredentials(cred_family)
try:
GM.Globals[GM.CURRENT_API_SCOPES] = list(set(list(discovery[u'auth'][u'oauth2'][u'scopes'])).intersection(credentials.scopes))
except KeyError:
invalidDiscoveryJsonExit(disc_file)
if not GM.Globals[GM.CURRENT_API_SCOPES]:
systemErrorExit(NO_SCOPES_FOR_API_RC, Msg.NO_SCOPES_FOR_API.format(discovery.get(u'title', api_version)))
getGDataOAuthToken(gdataObj, credentials)
if GC.Values[GC.DEBUG_LEVEL] > 0:
gdataObj.debug = True
return gdataObj
def run():
app = QtWidgets.QApplication(sys.argv)
# Translates standard-buttons (Ok, Cancel) and mac menu bar to german
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
path = os.path.join(base_path, 'bin', 'qtbase_de.qm')
translator = QtCore.QTranslator()
translator.load(path)
app.installTranslator(translator)
window = MainWindow()
window.show()
app.exec_()
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
# Last character is stripped in C-loader. We have to add
# '/' or '\\' at the end.
os.putenv('_MEIPASS2', sys._MEIPASS + os.sep)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
def main():
# This is required so that app.quit can be invoked when the quickview
# is closed. If it is not present then the app does not exit. It is
# possibly a bug in PyQt or Qt.
global app
app = QtWidgets.QApplication(sys.argv)
quickview = QtQuick.QQuickView()
if getattr(sys, 'frozen', None):
basedir = sys._MEIPASS
else:
basedir = os.path.dirname(__file__)
# The app dir is in the default import path but we can't put the QtQuick
# import lib dirs there because of a name clash (on OSX) with the QtQuick
# dll.
print(("Qt5 Qml import paths: " \
+ unicode(quickview.engine().importPathList())))
quickview.setSource(QtCore.QUrl('qrc:/hello.qml'))
quickview.engine().quit.connect(app.quit)
quickview.show()
app.exec_()
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def GetResource(frozen_loc,resource_loc,resource_name):
''' Get resource by location and name. This will compensate for frozen or not.
args:
frozen_loc: location of resource when frozen
resource_loc: location of resource in package (not frozen)
resource_name: name of the file
returns:
location: The abs location
'''
location = None
if getattr(sys,'frozen',False):
location = os.path.join(sys._MEIPASS,frozen_loc)
location = os.path.join(location,resource_name)
location = os.path.abspath(location)
else:
location = os.path.abspath(
pkg_resources.resource_filename(
resource_loc,
resource_name
)
)
return location
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def readDiscoveryFile(api_version):
disc_filename = u'%s.json' % (api_version)
disc_file = os.path.join(GM.Globals[GM.GAM_PATH], disc_filename)
if hasattr(sys, u'_MEIPASS'):
pyinstaller_disc_file = os.path.join(sys._MEIPASS, disc_filename)
else:
pyinstaller_disc_file = None
if os.path.isfile(disc_file):
json_string = readFile(disc_file, continueOnError=True, displayError=True)
elif pyinstaller_disc_file:
json_string = readFile(pyinstaller_disc_file, continueOnError=True, displayError=True)
else:
json_string = None
if not json_string:
invalidDiscoveryJsonExit(disc_file)
try:
discovery = json.loads(json_string)
return (disc_file, discovery)
except ValueError:
invalidDiscoveryJsonExit(disc_file)
def initGDataObject(gdataObj, api):
if hasattr(sys, u'_MEIPASS') and not GM.Globals[GM.CACERTS_TXT]:
GM.Globals[GM.CACERTS_TXT] = os.path.join(sys._MEIPASS, u'httplib2', u'cacerts.txt')
os.environ['REQUESTS_CA_BUNDLE'] = GM.Globals[GM.CACERTS_TXT]
os.environ['DEFAULT_CA_BUNDLE_PATH'] = GM.Globals[GM.CACERTS_TXT]
_, _, api_version, cred_family = API.getVersion(api)
disc_file, discovery = readDiscoveryFile(api_version)
GM.Globals[GM.CURRENT_API_USER] = None
credentials = getClientCredentials(cred_family)
try:
GM.Globals[GM.CURRENT_API_SCOPES] = list(set(list(discovery[u'auth'][u'oauth2'][u'scopes'])).intersection(credentials.scopes))
except KeyError:
invalidDiscoveryJsonExit(disc_file)
if not GM.Globals[GM.CURRENT_API_SCOPES]:
systemErrorExit(NO_SCOPES_FOR_API_RC, Msg.NO_SCOPES_FOR_API.format(discovery.get(u'title', api_version)))
getGDataOAuthToken(gdataObj, credentials)
if GC.Values[GC.DEBUG_LEVEL] > 0:
gdataObj.debug = True
return gdataObj
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
enhance_goodreads_export_gui.py 文件源码
项目:Enhance-GoodReads-Export
作者: PaulKlinger
项目源码
文件源码
阅读 55
收藏 0
点赞 0
评论 0
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
pyi_multiprocess_forking.py 文件源码
项目:mac-package-build
作者: persepolisdm
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
# Last character is stripped in C-loader. We have to add
# '/' or '\\' at the end.
os.putenv('_MEIPASS2', sys._MEIPASS + os.sep)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
def main():
# This is required so that app.quit can be invoked when the quickview
# is closed. If it is not present then the app does not exit. It is
# possibly a bug in PyQt or Qt.
global app
app = QtWidgets.QApplication(sys.argv)
quickview = QtQuick.QQuickView()
if getattr(sys, 'frozen', None):
basedir = sys._MEIPASS
else:
basedir = os.path.dirname(__file__)
# The app dir is in the default import path but we can't put the QtQuick
# import lib dirs there because of a name clash (on OSX) with the QtQuick
# dll.
print(("Qt5 Qml import paths: " \
+ unicode(quickview.engine().importPathList())))
quickview.setSource(QtCore.QUrl('qrc:/hello.qml'))
quickview.engine().quit.connect(app.quit)
quickview.show()
app.exec_()
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
def get_version():
global osName
global bits
pf = platform.platform()
if 'Windows' in pf:
osName = 'w'
elif 'Linux' in pf:
osName = 'l'
else:
osName = 'osx'
bits, _ = platform.architecture()
if '64' in bits:
bits = '64'
else:
bits = '86'
if osName == 'osx':
bits = ''
# sys.path.append(sys._MEIPASS)
def setEnvironment(caller):
get_version()
global javaCallCommand
if caller == "GUI":
# try:
# base_path = sys._MEIPASS
# except:
# base_path = os.path.abspath(".")
cwd = os.getcwd()
if osName == 'w':
# full_path = os.path.join(base_path, "FuncParser.exe")
javaCallCommand = os.path.join(cwd, "FuncParser-opt.exe ")
elif osName == 'l' or osName == "osx":
# full_path = os.path.join(base_path, "FuncParser.jar")
# javaCallCommand = "java -Xmx1024m -jar " + full_path + " "
javaCallCommand = "java -Xmx1024m -jar \"" + os.path.join(cwd, "FuncParser-opt.jar") + "\" "
else:
if osName == 'w':
javaCallCommand = "FuncParser-opt.exe "
elif osName == 'l' or osName == "osx":
javaCallCommand = "java -Xmx1024m -jar \"FuncParser-opt.jar\" "
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
if hasattr(sys, '_MEIPASS'):
return path.join(sys._MEIPASS, relative_path)
return path.join(path.abspath("."), relative_path)
def resource_path(basePath, relativePath):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
basePath = sys._MEIPASS
except Exception:
basePath = os.path.abspath(".")
finalPath = os.path.join(basePath, relativePath)
if sys.platform != 'win32':
finalPath = finalPath.replace('\\', '/')
return finalPath
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def get_tools_path():
if getattr(sys, 'frozen', False):
# we are running in a bundle
bundle_dir = sys._MEIPASS
else:
# we are running in a normal Python environment
bundle_dir = os.path.dirname(os.path.abspath(__file__))
if sys.platform == "win32":
return os.path.join(bundle_dir, "tools", "win" + BITS)
elif sys.platform == "linux" or sys.platform == "linux2":
return os.path.join(bundle_dir, "tools", "linux" + BITS)