Skip to content

Commit

Permalink
ofrak_patch_maker no longer looks for toolchain.conf in "/etc". (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
whyitfor committed Jun 29, 2023
1 parent 28b2680 commit 70c9200
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
2 changes: 2 additions & 0 deletions ofrak_patch_maker/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to `ofrak-patch-maker` will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/redballoonsecurity/ofrak/tree/master)
### Fixed
- Remove option to read or install toolchain.conf from/to "/etc/toolchain.conf" ([#342](https://github.com/redballoonsecurity/ofrak/pull/342))

## [4.0.1](https://github.com/redballoonsecurity/ofrak/compare/ofrak-patch-maker-v.4.0.0...ofrak-patch-maker-v.4.0.1)
### Added
Expand Down
11 changes: 2 additions & 9 deletions ofrak_patch_maker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ PYTHON=python3
PIP=pip3


# 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:
cp ofrak_patch_maker/toolchain.conf /etc/toolchain.conf
mv ofrak_patch_maker/toolchain.conf ofrak_patch_maker/toolchain.conf.bak

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

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

.PHONY: inspect
Expand Down
4 changes: 2 additions & 2 deletions ofrak_patch_maker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ as well as the [code references for PatchMaker](https://ofrak.com/docs/reference
## Dependencies
This Python package only includes the Python code for the PatchMaker and does not include any of the
toolchains which the PatchMaker utilizes! These would have to be
installed individually and added to a `toolchain.conf`, which by default is placed in `/etc`.
An example of the `toolchain.conf` can be found [here](https://github.com/redballoonsecurity/ofrak/blob/master/ofrak_patch_maker/toolchain.conf),
installed individually and added to `toolchain.conf`, which is bundled with this package.
An example of the `toolchain.conf` can be found [here](https://github.com/redballoonsecurity/ofrak/blob/master/ofrak_patch_maker/ofrak_patch_maker/toolchain.conf),
and examples of how to install the toolchains can be found [here](https://github.com/redballoonsecurity/ofrak/blob/master/ofrak_patch_maker/Dockerstub).

## Testing
Expand Down
19 changes: 4 additions & 15 deletions ofrak_patch_maker/ofrak_patch_maker/toolchain/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import configparser
import math
import os
import platform
from multiprocessing import Pool, cpu_count
from typing import Optional, Dict, Mapping, Tuple

import math

from ofrak_patch_maker.toolchain.model import BinFileType, Segment
from ofrak_type.error import NotFoundError
from ofrak_type.memory_permissions import MemoryPermissions
Expand All @@ -26,31 +26,20 @@ def get_file_format(path):

def get_repository_config(section: str, key: Optional[str] = None):
"""
Find config file and values. Look in user's `~/etc` directory followed by `/etc`.
Get config values from toolchain.conf.
:param section: section name in config file
:param key: key in `config[section]`
:raises SystemExit: If `config[section]` or `config[section][key]` not found.
:raises KeyError: If the `$HOME` environment variable is not found.
:return Union[str, List[Tuple[str, str]]]: the result of ``config.get(section, key)`` or
``config.items(section)``
"""

config = configparser.RawConfigParser()
config_name = "toolchain.conf"
if platform.system().find("CYGWIN") > -1 or platform.system().find("Windows") > -1:
config_root = "/winetc"
else:
config_root = "/etc"
local_config = os.path.join(os.path.dirname(__file__), os.path.pardir)
config_paths = [config_root, local_config]
try:
local_etc = os.path.join(os.environ["HOME"], "etc")
config_paths = [local_etc] + config_paths
except KeyError:
print("unable to find home directory")

config_paths = [local_config]
error_by_config_file: Dict[str, Exception] = dict()
for p in config_paths:
conf = os.path.join(p, config_name)
Expand Down

0 comments on commit 70c9200

Please sign in to comment.