Skip to content

Commit d333629

Browse files
Use pkgutil instead of absolute paths
1 parent a03f6ce commit d333629

File tree

5 files changed

+24
-29
lines changed

5 files changed

+24
-29
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ recursive-include qiling/debugger/gdb/xml *
22
recursive-include qiling/extensions/windows_sdk/defs *
33
recursive-include qiling/profiles *
44
include qiling/os/uefi/guids.csv
5+
include qiling/arch/evm/analysis/signatures.json

qiling/arch/evm/analysis/signatures.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
import pkgutil
22
import re
33
import logging
44
import json
@@ -92,9 +92,8 @@ def analysis_func_sign(insns:list, engine_num=1):
9292
class signatures_engine_1:
9393
@staticmethod
9494
def find_signature(sign):
95-
path = os.path.split(os.path.realpath(__file__))[0] + '/signatures.json'
96-
with open(path) as data_file:
97-
data = json.load(data_file)
95+
data = pkgutil.get_data(__package__, 'signatures.json').decode()
96+
data = json.load(data)
9897

9998
list_name = [name for name, hexa in data.items() if hexa == sign]
10099

qiling/debugger/gdb/gdb.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# documentation: according to https://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Protocol.html#Remote-Protocol
88

99
import struct, os, socket
10+
import pkgutil
1011
from binascii import unhexlify
1112
from typing import Iterator, Literal
1213

@@ -481,15 +482,15 @@ def handle_q(subcmd):
481482
else:
482483
self.send("PacketSize=47ff;QPassSignals+;QProgramSignals+;QStartupWithShell+;QEnvironmentHexEncoded+;QEnvironmentReset+;QEnvironmentUnset+;QSetWorkingDir+;QCatchSyscalls+;qXfer:libraries-svr4:read+;augmented-libraries-svr4-read+;qXfer:auxv:read+;qXfer:siginfo:read+;qXfer:siginfo:write+;qXfer:features:read+;QStartNoAckMode+;qXfer:osdata:read+;multiprocess+;fork-events+;vfork-events+;exec-events+;QNonStop+;QDisableRandomization+;qXfer:threads:read+;ConditionalTracepoints+;TraceStateVariables+;TracepointSource+;DisconnectedTracing+;FastTracepoints+;StaticTracepoints+;InstallInTrace+;qXfer:statictrace:read+;qXfer:traceframe-info:read+;EnableDisableTracepoints+;QTBuffer:size+;tracenz+;ConditionalBreakpoints+;BreakpointCommands+;QAgent+;Qbtrace:bts+;Qbtrace-conf:bts:size+;Qbtrace:pt+;Qbtrace-conf:pt:size+;Qbtrace:off+;qXfer:btrace:read+;qXfer:btrace-conf:read+;swbreak+;hwbreak+;qXfer:exec-file:read+;vContSupported+;QThreadEvents+;no-resumed+")
483484
elif subcmd.startswith('Xfer:features:read'):
484-
xfercmd_file = subcmd.split(':')[3]
485-
xfercmd_abspath = os.path.dirname(os.path.abspath(__file__))
486-
xml_folder = self.ql.arch.type.name.lower()
487-
xfercmd_file = os.path.join(xfercmd_abspath,"xml",xml_folder, xfercmd_file)
488-
489-
if os.path.exists(xfercmd_file) and self.ql.os.type is not QL_OS.WINDOWS:
490-
with open(xfercmd_file, 'r') as f:
491-
file_contents = f.read()
485+
if self.ql.os.type is not QL_OS.WINDOWS:
486+
try:
487+
xfercmd_file = subcmd.split(':')[3]
488+
xml_folder = self.ql.arch.type.name.lower()
489+
file_contents = pkgutil.get_data(__package__, f"xml/{xml_folder}/{xfercmd_file}").decode()
492490
self.send("l%s" % file_contents)
491+
except:
492+
self.ql.log.info("gdb> Platform is not supported by xml or xml file not found: %s\n" % (xfercmd_file))
493+
self.send("l")
493494
else:
494495
self.ql.log.info("gdb> Platform is not supported by xml or xml file not found: %s\n" % (xfercmd_file))
495496
self.send("l")

qiling/os/uefi/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import csv
22
from typing import Mapping
3-
from os import path
3+
import pkgutil
44

55
def __init_guids_db() -> Mapping[str, str]:
66
"""Initialize GUIDs dictionary from a local database.
77
"""
88

9-
csv_path = path.dirname(path.abspath(__file__))
10-
csv_path = path.join(csv_path, 'guids.csv')
9+
guids_file = pkgutil.get_data(__package__, 'guids.csv').decode()
10+
guids_reader = csv.reader(guids_file.splitlines())
1111

12-
with open(csv_path) as guids_file:
13-
guids_reader = csv.reader(guids_file)
14-
15-
return dict(tuple(entry) for entry in guids_reader)
12+
return dict(tuple(entry) for entry in guids_reader)
1613

1714
guids_db = __init_guids_db()

qiling/utils.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
from functools import partial
12-
import importlib, os
12+
import importlib, pkgutil, os
1313

1414
from configparser import ConfigParser
1515
from types import ModuleType
@@ -415,19 +415,16 @@ def profile_setup(ostype: QL_OS, filename: Optional[str]):
415415
config = {}
416416

417417
else:
418-
qiling_home = os.path.dirname(os.path.abspath(__file__))
419-
os_profile = os.path.join(qiling_home, 'profiles', f'{ostype.name.lower()}.ql')
420-
421-
profiles = [os_profile]
422-
423-
if filename:
424-
profiles.append(filename)
425-
426418
# patch 'getint' to convert integers of all bases
427419
int_converter = partial(int, base=0)
428420

429421
config = ConfigParser(converters={'int': int_converter})
430-
config.read(profiles)
422+
423+
os_profile = pkgutil.get_data(__package__, f'profiles/{ostype.name.lower()}.ql').decode()
424+
config.read_string(os_profile)
425+
426+
if filename:
427+
config.read(filename)
431428

432429
return config
433430

0 commit comments

Comments
 (0)