Skip to content

Commit

Permalink
Grab config from execution dir
Browse files Browse the repository at this point in the history
  • Loading branch information
emtuls committed May 23, 2024
1 parent 2e3e99e commit 824e945
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion fakenet/diverters/diverterbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,14 @@ def parse_diverter_config(self):
sys.exit(1)

if self.is_set('dumppackets'):
self.pcap_filename = '%s_%s.pcap' % (self.getconfigval(
pcap_filename = '%s_%s.pcap' % (self.getconfigval(
'dumppacketsfileprefix', 'packets'),
time.strftime('%Y%m%d_%H%M%S'))
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
out_dir = os.path.dirname(sys.executable)
else:
out_dir = os.path.dirname(__file__)
self.pcap_filename = os.path.join(out_dir, pcap_filename)
self.logger.info('Capturing traffic to %s', self.pcap_filename)
self.pcap = dpkt.pcap.Writer(open(self.pcap_filename, 'wb'),
linktype=dpkt.pcap.DLT_RAW)
Expand Down
2 changes: 1 addition & 1 deletion fakenet/fakenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, logging_level = logging.INFO):
def parse_config(self, config_filename):
# Handling Pyinstaller bundle scenario: https://pyinstaller.org/en/stable/runtime-information.html
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
dir_path = os.getcwd()
dir_path = os.path.dirname(sys.executable)
else:
dir_path = os.path.dirname(__file__)

Expand Down
2 changes: 1 addition & 1 deletion fakenet/listeners/ListenerBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def abs_config_path(path):
return abspath

if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
relpath = os.path.join(os.getcwd(), path)
relpath = os.path.join(os.path.dirname(sys.executable), path)
else:

# Try to locate the location relative to application path
Expand Down
2 changes: 1 addition & 1 deletion fakenet/listeners/TFTPListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def handle_data(self, socket, data):
if hasattr(self.server, 'filename_path') and self.server.filename_path:

safe_file = self.server.tftp_file_prefix + "_" + urllib.parse.quote(self.server.filename_path, '')
output_file = ListenerBase.safe_join(os.getcwd(),
output_file = ListenerBase.safe_join(os.path.dirname(sys.executable),
safe_file)
f = open(output_file, 'ab')
f.write(data[4:])
Expand Down

0 comments on commit 824e945

Please sign in to comment.