Skip to content

Commit 561f3a8

Browse files
authored
Merge pull request #1150 from nullableVoidPtr/pkgutil
Rewrite package data reading
2 parents 09b69d5 + 9c6140d commit 561f3a8

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

.github/workflows/giteesync.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
jobs:
66
deploy:
77
runs-on: ubuntu-latest
8+
if: github.repository_owner == 'qilingframework'
89
steps:
910
- uses: actions/checkout@v2
1011
with:

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
- danielmoos
5555
- sigeryang
5656
- bet4it
57+
- nullableVoidPtr
5758

5859

5960
#### Legacy Core Developers

MANIFEST.in

Lines changed: 0 additions & 5 deletions
This file was deleted.

qiling/arch/evm/analysis/signatures.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import os
1+
import inspect
2+
from pathlib import Path
23
import re
34
import logging
45
import json
@@ -92,8 +93,8 @@ def analysis_func_sign(insns:list, engine_num=1):
9293
class signatures_engine_1:
9394
@staticmethod
9495
def find_signature(sign):
95-
path = os.path.split(os.path.realpath(__file__))[0] + '/signatures.json'
96-
with open(path) as data_file:
96+
path = Path(inspect.getfile(inspect.getframe())).parent / 'signatures.json'
97+
with path.open('r') as data_file:
9798
data = json.load(data_file)
9899

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

qiling/debugger/gdb/gdb.py

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

99
import struct, os, socket
10+
import inspect
11+
from pathlib import Path
1012
from binascii import unhexlify
1113
from typing import Iterator, Literal
1214

@@ -482,14 +484,13 @@ def handle_q(subcmd):
482484
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+")
483485
elif subcmd.startswith('Xfer:features:read'):
484486
xfercmd_file = subcmd.split(':')[3]
485-
xfercmd_abspath = os.path.dirname(os.path.abspath(__file__))
487+
xfercmd_abspath = Path(inspect.getfile(inspect.currentframe())).parent
486488
xml_folder = self.ql.arch.type.name.lower()
487-
xfercmd_file = os.path.join(xfercmd_abspath,"xml",xml_folder, xfercmd_file)
489+
xfercmd_file = xfercmd_abspath / 'xml' / xml_folder / xfercmd_file
488490

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+
if xfercmd_file.exists() and self.ql.os.type is not QL_OS.WINDOWS:
492+
with xfercmd_file.open('r') as f:
491493
file_contents = f.read()
492-
self.send("l%s" % file_contents)
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import csv
22
from typing import Mapping
3-
from os import path
3+
import inspect
4+
from pathlib import Path
45

56
def __init_guids_db() -> Mapping[str, str]:
67
"""Initialize GUIDs dictionary from a local database.
78
"""
89

9-
csv_path = path.dirname(path.abspath(__file__))
10-
csv_path = path.join(csv_path, 'guids.csv')
10+
csv_path = Path(inspect.getfile(inspect.currentframe())).parent / 'guids.csv'
1111

12-
with open(csv_path) as guids_file:
12+
with csv_path.open('r') as guids_file:
1313
guids_reader = csv.reader(guids_file)
1414

1515
return dict(tuple(entry) for entry in guids_reader)

qiling/utils.py

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

1111
from functools import partial
12-
import importlib, os
12+
from pathlib import Path
13+
import importlib, inspect, os
1314

1415
from configparser import ConfigParser
1516
from types import ModuleType
@@ -415,8 +416,8 @@ def profile_setup(ostype: QL_OS, filename: Optional[str]):
415416
config = {}
416417

417418
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')
419+
qiling_home = Path(inspect.getfile(inspect.currentframe())).parent
420+
os_profile = qiling_home / 'profiles' / f'{ostype.name.lower()}.ql'
420421

421422
profiles = [os_profile]
422423

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@
8484

8585
packages=find_packages(),
8686
scripts=['qltool'],
87-
include_package_data=True,
87+
package_data={
88+
'qiling': ['profiles/*.ql'],
89+
'qiling.debugger.gdb': ['xml/*/*'],
90+
'qiling.os.uefi': ['guids.csv'],
91+
'qiling.arch.evm.analysis': ['signatures.json']
92+
},
8893
install_requires=requirements,
8994
extras_require=extras,
9095
)

0 commit comments

Comments
 (0)