redballoonsecurity / ofrak

OFRAK: unpack, modify, and repack binaries.
https://ofrak.com
Other
1.85k stars 126 forks source link

Source install hurdles on WSL2/Ubuntu #340

Open Jepson2k opened 1 year ago

Jepson2k commented 1 year ago

What is the problem? (Here is where you provide a complete Traceback.) Following the instruction outline on the website for installing from source (running make develop in each of the recommended directories), but ran into a few hurdles that could be fixed to provide a smoother install experience.

Issues with the ofrak_patch_maker Makefile:

Issues with the ofrak_core Makefile:

Please provide some information about your environment. At minimum we would like the following information on your platform and Python environment:

If you've discovered it, what is the root cause of the problem? Permission issues and packages missing.

How often does the issue happen? On source install on fresh-ish installation of Ubuntu 20.04

What are the steps to reproduce the issue? Install ubuntu -> follow steps outlined on website to install from source.

How would you implement this fix? Here are some possible untested fixes for the ofrak_patch_maker and ofrak_core Makefiles:

PYTHON=python3
PIP=pip3
SUDO:=$(shell which sudo)
SUDO_USER:=$(shell whoami)

# toolchain.conf is a file mapping ID to the various binaries responsible for preprocessing,
#  assembling, compiling, linking, analyzing binaries for each currently supported toolchain.
.PHONY: toolchain_conf
toolchain_conf:
ifeq ($(SUDO_USER), root)
        cp ofrak_patch_maker/toolchain.conf /etc/toolchain.conf
else
ifdef SUDO
        $(SUDO) cp ofrak_patch_maker/toolchain.conf /etc/toolchain.conf
else
        @echo "Not root and sudo not found. Can't copy the file to /etc/toolchain.conf"
endif
endif
        mv ofrak_patch_maker/toolchain.conf ofrak_patch_maker/toolchain.conf.bak

.PHONY: install
install: toolchain_conf
        $(PIP) install .

.PHONY: develop
develop: toolchain_conf
        $(PIP) install -e .[test]

.PHONY: inspect
inspect:
        mypy

.PHONY: test
test: inspect
        $(PYTHON) -m pytest -n auto --cov=ofrak_patch_maker --cov-report=term-missing ofrak_patch_maker_test
        fun-coverage --cov-fail-under=100
PYTHON=python3
PIP=pip3
NPM:=$(shell which npm)
SUDO:=$(shell which sudo)
SUDO_USER:=$(shell whoami)
PKG_MANAGER:=$(shell command -v apt || command -v yum || command -v dnf || command -v brew)

.PHONY: install
install: ofrak/gui/public
        $(PIP) install .

.PHONY: develop
develop: ofrak/gui/public
        $(PIP) install -e .[docs,test]

.PHONY: inspect
inspect:
        mypy

.PHONY: test
test: inspect
        $(PYTHON) -m pytest -n auto test_ofrak --cov=ofrak --cov-report=term-missing
        fun-coverage --cov-fail-under=100

ofrak/gui/public:
        if [ -d /ofrak_gui ] ; then \
                cp -r /ofrak_gui ofrak/gui/public ; \
        elif [ -d ../frontend ]; then \
ifeq ($(SUDO_USER), root)
                echo "Running as root" ; \
ifdef NPM
                echo "npm is already installed" ; \
else
                echo "npm is not installed, installing npm..." ; \
                $(PKG_MANAGER) install npm -y ; \
endif
else
ifdef SUDO
                echo "Running as non-root, sudo available" ; \
ifdef NPM
                echo "npm is already installed" ; \
else
                echo "npm is not installed, installing npm..." ; \
                $(SUDO) $(PKG_MANAGER) install npm -y ; \
endif
else
                echo "Not root and sudo not found. Can't install npm. Please install manually." ; \
endif
endif
                cd ../frontend && \
                npm install && \
                npm run build && \
                cd ../ofrak_core && \
                cp -r ../frontend/public ofrak/gui/public ; \
        fi

Are there any (reasonable) alternative approaches? Yes, many. Are you interested in implementing it yourself? Sure

ANogin commented 1 year ago

https://github.com/redballoonsecurity/ofrak/pull/314 partially addresses the first part (allowing the toolchain to not go into /etc)