-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/mas6y6/CipherOS
- Loading branch information
Showing
9 changed files
with
281 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- mode: python ; coding: utf-8 -*- | ||
|
||
|
||
a = Analysis( | ||
['main.py'], | ||
pathex=[], | ||
binaries=[], | ||
datas=[], | ||
hiddenimports=[], | ||
hookspath=[], | ||
hooksconfig={}, | ||
runtime_hooks=[], | ||
excludes=['cipher'], | ||
noarchive=False, | ||
optimize=0, | ||
) | ||
pyz = PYZ(a.pure) | ||
|
||
exe = EXE( | ||
pyz, | ||
a.scripts, | ||
a.binaries, | ||
a.datas, | ||
[], | ||
name='cipher', | ||
debug=False, | ||
bootloader_ignore_signals=False, | ||
strip=False, | ||
upx=True, | ||
upx_exclude=[], | ||
runtime_tmpdir=None, | ||
console=True, | ||
disable_windowed_traceback=False, | ||
argv_emulation=False, | ||
target_arch=None, | ||
codesign_identity=None, | ||
entitlements_file=None, | ||
icon=['icon.ico'], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import sys, platform, os, ctypes | ||
|
||
def is_root(): | ||
system = platform.system() | ||
if system in ["Linux", "Darwin"]: | ||
try: | ||
return os.getuid() == 0 | ||
except AttributeError: | ||
return False | ||
elif system == "Windows": | ||
try: | ||
return ctypes.windll.shell32.IsUserAnAdmin() != 0 | ||
except AttributeError: | ||
return False | ||
else: | ||
raise NotImplementedError(f"Unsupported OS: {system}") | ||
|
||
def elevate(show_console=True, graphical=True): | ||
""" | ||
Re-launch the current process with root/admin privileges | ||
When run as root, this function does nothing. | ||
When not run as root, this function replaces the current process (Linux, | ||
macOS) or creates a child process, waits, and exits (Windows). | ||
:param show_console: (Windows only) if True, show a new console for the | ||
child process. Ignored on Linux / macOS. | ||
:param graphical: (Linux / macOS only) if True, attempt to use graphical | ||
programs (gksudo, etc). Ignored on Windows. | ||
""" | ||
if sys.platform.startswith("win"): | ||
from elevate.windows import elevate | ||
else: | ||
from elevate.posix import elevate | ||
elevate(show_console, graphical) | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import errno | ||
import os | ||
import sys | ||
try: | ||
from shlex import quote | ||
except ImportError: | ||
from pipes import quote | ||
|
||
|
||
def quote_shell(args): | ||
return " ".join(quote(arg) for arg in args) | ||
|
||
|
||
def quote_applescript(string): | ||
charmap = { | ||
"\n": "\\n", | ||
"\r": "\\r", | ||
"\t": "\\t", | ||
"\"": "\\\"", | ||
"\\": "\\\\", | ||
} | ||
return '"%s"' % "".join(charmap.get(char, char) for char in string) | ||
|
||
|
||
def elevate(show_console=True, graphical=True): | ||
if os.getuid() == 0: | ||
return | ||
|
||
args = [sys.executable] + sys.argv | ||
commands = [] | ||
|
||
if graphical: | ||
if sys.platform.startswith("darwin"): | ||
commands.append([ | ||
"osascript", | ||
"-e", | ||
"do shell script %s " | ||
"with administrator privileges " | ||
"without altering line endings" | ||
% quote_applescript(quote_shell(args))]) | ||
|
||
if sys.platform.startswith("linux") and os.environ.get("DISPLAY"): | ||
commands.append(["pkexec"] + args) | ||
commands.append(["gksudo"] + args) | ||
commands.append(["kdesudo"] + args) | ||
|
||
commands.append(["sudo"] + args) | ||
|
||
for args in commands: | ||
try: | ||
os.execlp(args[0], *args) | ||
except OSError as e: | ||
if e.errno != errno.ENOENT or args[0] == "sudo": | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import ctypes | ||
from ctypes import POINTER, c_ulong, c_char_p, c_int, c_void_p | ||
from ctypes.wintypes import HANDLE, BOOL, DWORD, HWND, HINSTANCE, HKEY | ||
from ctypes import windll | ||
import subprocess | ||
import sys | ||
|
||
# Constant defintions | ||
|
||
|
||
SEE_MASK_NOCLOSEPROCESS = 0x00000040 | ||
SEE_MASK_NO_CONSOLE = 0x00008000 | ||
|
||
|
||
# Type definitions | ||
|
||
PHANDLE = ctypes.POINTER(HANDLE) | ||
PDWORD = ctypes.POINTER(DWORD) | ||
|
||
|
||
class ShellExecuteInfo(ctypes.Structure): | ||
_fields_ = [ | ||
('cbSize', DWORD), | ||
('fMask', c_ulong), | ||
('hwnd', HWND), | ||
('lpVerb', c_char_p), | ||
('lpFile', c_char_p), | ||
('lpParameters', c_char_p), | ||
('lpDirectory', c_char_p), | ||
('nShow', c_int), | ||
('hInstApp', HINSTANCE), | ||
('lpIDList', c_void_p), | ||
('lpClass', c_char_p), | ||
('hKeyClass', HKEY), | ||
('dwHotKey', DWORD), | ||
('hIcon', HANDLE), | ||
('hProcess', HANDLE)] | ||
|
||
def __init__(self, **kw): | ||
super(ShellExecuteInfo, self).__init__() | ||
self.cbSize = ctypes.sizeof(self) | ||
for field_name, field_value in kw.items(): | ||
setattr(self, field_name, field_value) | ||
|
||
|
||
PShellExecuteInfo = POINTER(ShellExecuteInfo) | ||
|
||
|
||
# Function definitions | ||
|
||
ShellExecuteEx = windll.shell32.ShellExecuteExA | ||
ShellExecuteEx.argtypes = (PShellExecuteInfo, ) | ||
ShellExecuteEx.restype = BOOL | ||
|
||
WaitForSingleObject = windll.kernel32.WaitForSingleObject | ||
WaitForSingleObject.argtypes = (HANDLE, DWORD) | ||
WaitForSingleObject.restype = DWORD | ||
|
||
CloseHandle = windll.kernel32.CloseHandle | ||
CloseHandle.argtypes = (HANDLE, ) | ||
CloseHandle.restype = BOOL | ||
|
||
|
||
# At last, the actual implementation! | ||
|
||
def elevate(show_console=True, graphical=True): | ||
if windll.shell32.IsUserAnAdmin(): | ||
return | ||
|
||
params = ShellExecuteInfo( | ||
fMask=SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE, | ||
hwnd=None, | ||
lpVerb=b'runas', | ||
lpFile=sys.executable.encode('cp1252'), | ||
lpParameters=subprocess.list2cmdline(sys.argv).encode('cp1252'), | ||
nShow=int(show_console)) | ||
|
||
if not ShellExecuteEx(ctypes.byref(params)): | ||
raise ctypes.WinError() | ||
|
||
handle = params.hProcess | ||
ret = DWORD() | ||
WaitForSingleObject(handle, -1) | ||
|
||
if windll.kernel32.GetExitCodeProcess(handle, ctypes.byref(ret)) == 0: | ||
raise ctypes.WinError() | ||
|
||
CloseHandle(handle) | ||
sys.exit(ret.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ ping3 | |
netifaces | ||
markdown | ||
rich | ||
hostprobe | ||
hostprobe |