Skip to content

Provide an option to install right click menu option for Windows #970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ This means that Python will load the FLOSS module from this local
This is good, because it is easy for us to modify files and see the
effects reflected immediately.
But be careful not to remove this directory unless uninstalling FLOSS!
If you encounter the error `ERROR: Project has a 'pyproject.toml' and its build backend is missing the 'build_editable' hook.`,
please ensure that you have upgraded to the latest versions of pip and setuptools.


- Install FLOSS:

Expand Down
14 changes: 14 additions & 0 deletions floss/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from time import time
from typing import Set, List, Optional
from pathlib import Path
import platform

import halo
import viv_utils
Expand Down Expand Up @@ -144,6 +145,19 @@ def make_parser(argv):
)
parser.register("action", "extend", floss.utils.ExtendAction)
parser.add_argument("-H", action="help", help="show advanced options and exit")

if platform.system() == "Windows":
parser.add_argument(
"--install-right-click-menu",
action=floss.utils.InstallContextMenu,
help="install FLOSS to the right-click context menu for Windows Explorer and exit"
)

parser.add_argument(
"--uninstall-right-click-menu",
action=floss.utils.UninstallContextMenu,
help="uninstall FLOSS from the right-click context menu for Windows Explorer and exit"
)

parser.add_argument(
"-n",
Expand Down
35 changes: 35 additions & 0 deletions floss/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Set, Tuple, Iterable, Optional
from pathlib import Path
from collections import OrderedDict
import sys

import tqdm
import tabulate
Expand Down Expand Up @@ -42,6 +43,40 @@ def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, items)


class InstallContextMenu(argparse.Action):
def __init__(self, option_strings, dest, nargs=None, **kwargs):
super(InstallContextMenu, self).__init__(option_strings, dest, nargs=0, **kwargs)

def __call__(self, parser, namespace, values, option_string=None):
import winreg as reg
menu_name = 'Open with FLOSS'
menu_command = f'C:\\windows\\system32\\cmd.exe /K "python -m floss ^"%1^""'

shell_key = reg.OpenKey(reg.HKEY_CURRENT_USER, r'Software\\Classes\\*\\shell', 0, reg.KEY_SET_VALUE)
reg.SetValue(shell_key, menu_name, reg.REG_SZ, menu_name)

menu_key = reg.OpenKey(shell_key, menu_name, 0, reg.KEY_SET_VALUE)
reg.SetValueEx(menu_key, 'AppliesTo', 0, reg.REG_SZ, 'System.ItemName:exe')
reg.SetValue(menu_key, 'command', reg.REG_SZ, menu_command)
sys.exit(0)


class UninstallContextMenu(argparse.Action):
def __init__(self, option_strings, dest, nargs=None, **kwargs):
super(UninstallContextMenu, self).__init__(option_strings, dest, nargs=0, **kwargs)

def __call__(self, parser, namespace, values, option_string=None):
import winreg as reg
menu_name = 'Open with FLOSS'

shell_key = reg.OpenKey(reg.HKEY_CURRENT_USER, r'Software\\Classes\\*\\shell')
menu_key = reg.OpenKey(shell_key, menu_name)

reg.DeleteKey(menu_key, 'command')
reg.DeleteKey(shell_key, menu_name)
sys.exit(0)


def set_vivisect_log_level(level) -> None:
logging.getLogger("vivisect").setLevel(level)
logging.getLogger("vivisect.base").setLevel(level)
Expand Down