Skip to content

Commit

Permalink
client: package: support python3.13 and remove python3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Oct 20, 2024
1 parent a535645 commit b49a78a
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
python-version: [ 3.8, 3.9, "3.10", "3.11", "3.12" ]
python-version: [ 3.9, "3.10", "3.11", "3.12", "3.13" ]
os: [ macos-latest ]

steps:
Expand Down
12 changes: 6 additions & 6 deletions hilda/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from pathlib import Path
from typing import List, Optional
from typing import Optional

import click
import coloredlogs
Expand All @@ -23,7 +23,7 @@ def cli():
startup_files_option = click.option('-f', '--startup_files', multiple=True, help='Files to run on start')


def parse_envp(ctx: click.Context, param: click.Parameter, value: List[str]) -> List[str]:
def parse_envp(ctx: click.Context, param: click.Parameter, value: list[str]) -> list[str]:
env_list = []
for item in value:
try:
Expand All @@ -38,7 +38,7 @@ def parse_envp(ctx: click.Context, param: click.Parameter, value: List[str]) ->
@click.argument('hostname', default='localhost')
@click.argument('port', type=click.INT, default=DEFAULT_HILDA_PORT)
@startup_files_option
def remote(hostname: str, port: int, startup_files: List[str]) -> None:
def remote(hostname: str, port: int, startup_files: list[str]) -> None:
""" Connect to remote debugserver at given address """
with create_hilda_client_using_remote_attach(hostname, port) as hilda_client:
hilda_client.interact(startup_files=startup_files)
Expand All @@ -48,7 +48,7 @@ def remote(hostname: str, port: int, startup_files: List[str]) -> None:
@click.option('-n', '--name', help='process name to attach')
@click.option('-p', '--pid', type=click.INT, help='pid to attach')
@startup_files_option
def attach(name: Optional[str], pid: Optional[int], startup_files: List[str]) -> None:
def attach(name: Optional[str], pid: Optional[int], startup_files: list[str]) -> None:
""" Attach to given process and start a lldb shell """
if name is not None:
hilda_client = create_hilda_client_using_attach_by_name(name)
Expand Down Expand Up @@ -78,9 +78,9 @@ def cli_bare() -> None:
@click.option('--cwd', help='Set the working directory for the process')
@click.option('--flags', type=click.INT, default=0, help='Launch flags (bitmask)')
@startup_files_option
def launch(exec_path: str, argv: List[str], envp: List[str], stdin: Optional[Path],
def launch(exec_path: str, argv: list[str], envp: list[str], stdin: Optional[Path],
stdout: Optional[Path], stderr: Optional[Path], cwd: Optional[Path], flags: Optional[int],
startup_files: List[str]) -> None:
startup_files: list[str]) -> None:
""" Attach to a given process and start a lldb shell """
argv = list(argv)
envp = list(envp)
Expand Down
6 changes: 3 additions & 3 deletions hilda/common.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from datetime import datetime
from typing import Any, List, Mapping, Tuple, Union
from typing import Any, Union

import inquirer3
from inquirer3.themes import GreenPassion

CfSerializable = Union[
Mapping[str, Any], List, Tuple[Any, ...], str, bool, float, bytes, datetime, None]
dict[str, Any], list, tuple[Any, ...], str, bool, float, bytes, datetime, None]


def selection_prompt(options_list: List):
def selection_prompt(options_list: list):
question = [inquirer3.List('choice', message='choose device', choices=options_list, carousel=True)]
result = inquirer3.prompt(question, theme=GreenPassion(), raise_keyboard_interrupt=True)
return result['choice']
8 changes: 4 additions & 4 deletions hilda/hilda_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from datetime import datetime, timezone
from functools import cached_property, wraps
from pathlib import Path
from typing import Any, Callable, List, Optional, Union
from typing import Any, Callable, Optional, Union

import hexdump
import IPython
Expand Down Expand Up @@ -194,7 +194,7 @@ def lsof(self) -> dict:
# convert FDs into int
return {int(k): v for k, v in result.items()}

def bt(self, should_print: bool = False, depth: Optional[int] = None) -> List[Union[str, lldb.SBFrame]]:
def bt(self, should_print: bool = False, depth: Optional[int] = None) -> list[Union[str, lldb.SBFrame]]:
""" Print an improved backtrace. """
backtrace = []
for i, frame in enumerate(self.thread.frames):
Expand Down Expand Up @@ -987,7 +987,7 @@ def safe_malloc(self, size):
"""
block = self.symbols.malloc(size)
if block == 0:
raise IOError(f'failed to allocate memory of size: {size} bytes')
raise OSError(f'failed to allocate memory of size: {size} bytes')

try:
yield block
Expand Down Expand Up @@ -1095,7 +1095,7 @@ def bp(client: HildaClient, frame, bp_loc, options) -> None:
self.cont()

def interact(self, additional_namespace: Optional[typing.Mapping] = None,
startup_files: Optional[List[str]] = None) -> None:
startup_files: Optional[list[str]] = None) -> None:
""" Start an interactive Hilda shell """
if not self._dynamic_env_loaded:
self.init_dynamic_environment()
Expand Down
6 changes: 3 additions & 3 deletions hilda/launch_lldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from abc import ABC, abstractmethod
from threading import Thread
from typing import List, Optional
from typing import Optional

from hilda.exceptions import LLDBError
from hilda.hilda_client import HildaClient
Expand Down Expand Up @@ -146,7 +146,7 @@ def _create_process(self) -> lldb.SBProcess:


class LLDBLaunch(LLDBListenerThread):
def __init__(self, exec_path: str, argv: Optional[List[str]] = None, envp: Optional[List[str]] = None,
def __init__(self, exec_path: str, argv: Optional[list[str]] = None, envp: Optional[list[str]] = None,
stdin: Optional[str] = None,
stdout: Optional[str] = None, stderr: Optional[str] = None, wd: Optional[str] = None,
flags: Optional[int] = 0):
Expand Down Expand Up @@ -189,7 +189,7 @@ def create_hilda_client_using_remote_attach(


def create_hilda_client_using_launch(
exec_path: str, argv: Optional[List] = None, envp: Optional[List] = None, stdin: Optional[str] = None,
exec_path: str, argv: Optional[list] = None, envp: Optional[list] = None, stdin: Optional[str] = None,
stdout: Optional[str] = None, stderr: Optional[str] = None, wd: Optional[str] = None,
flags: Optional[int] = 0) -> HildaClient:
lldb_t = LLDBLaunch(exec_path, argv, envp, stdin, stdout, stderr, wd, flags)
Expand Down
2 changes: 1 addition & 1 deletion hilda/lldb_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def get_lldb_python_path() -> str:
result = subprocess.run(['lldb', '-P'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
result = subprocess.run(['lldb', '-P'], capture_output=True, text=True, check=True)
return result.stdout.strip()


Expand Down
4 changes: 2 additions & 2 deletions hilda/objective_c_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __str__(self):
return f'{prefix} {name}; // 0x{self.address:x} (returns: {self.return_type})\n'


class Class(object):
class Class:
"""
Wrapper for ObjectiveC Class object.
"""
Expand Down Expand Up @@ -273,7 +273,7 @@ def __dir__(self):
if method.is_class:
result.add(method.name.replace(':', '_'))

result.update(list(super(Class, self).__dir__()))
result.update(list(super().__dir__()))
return list(result)

def __str__(self):
Expand Down
10 changes: 5 additions & 5 deletions hilda/objective_c_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create(cls, value: int, client):
:return: ObjectiveCSymbol object.
:rtype: ObjectiveCSymbol
"""
symbol = super(ObjectiveCSymbol, cls).create(value, client)
symbol = super().create(value, client)
symbol.ivars = [] # type: List[Ivar]
symbol.properties = [] # type: List[Property]
symbol.methods = [] # type: List[Method]
Expand Down Expand Up @@ -183,12 +183,12 @@ def __dir__(self):
for method in sup.methods:
result.add(method.name.replace(':', '_'))

result.update(list(super(ObjectiveCSymbol, self).__dir__()))
result.update(list(super().__dir__()))
return list(result)

def __getitem__(self, item):
if isinstance(item, int):
return super(ObjectiveCSymbol, self).__getitem__(item)
return super().__getitem__(item)

# Ivars
for ivar in self.ivars:
Expand Down Expand Up @@ -217,7 +217,7 @@ def __getattr__(self, item: str):

def __setitem__(self, key, value):
if isinstance(key, int):
super(ObjectiveCSymbol, self).__setitem__(key, value)
super().__setitem__(key, value)
return

with suppress(SettingIvarError):
Expand All @@ -232,7 +232,7 @@ def __setattr__(self, key, value):
try:
self._set_ivar(key, value)
except SettingIvarError:
super(ObjectiveCSymbol, self).__setattr__(key, value)
super().__setattr__(key, value)

def __str__(self):
return self._to_str(False)
Expand Down
2 changes: 1 addition & 1 deletion hilda/registers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Registers(object):
class Registers:
"""
Wrapper for more convenient access to modify current frame's registers
"""
Expand Down
4 changes: 2 additions & 2 deletions hilda/snippets/macho/all_image_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
)


class AllImageInfos(object):
class AllImageInfos:
def reload(self):
with lldb.hilda_client.stopped(1):
all_image_infos_symbol = lldb.hilda_client.symbol(lldb.hilda_client.symbols.dyld_all_image_infos)
Expand Down Expand Up @@ -98,7 +98,7 @@ def __image_dependencies(images):
if len(unique_images) > 1:
image = AllImageInfos.__select_specific_image(unique_images)

dependencies = set([image_name.path for image_name in image.load_commands.dylib_commands])
dependencies = {image_name.path for image_name in image.load_commands.dylib_commands}

return dependencies

Expand Down
2 changes: 1 addition & 1 deletion hilda/snippets/macho/image_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)


class ImageInfo(object):
class ImageInfo:
def __init__(self, image_info_data):
self.__image_info_data = image_info_data
self.__file_path = image_info_data.imageFilePath
Expand Down
20 changes: 9 additions & 11 deletions hilda/snippets/macho/macho_load_commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

from construct import Array, Bytes, Enum, Hex, Int8ul, Int32ul, Int64ul, PaddedString, Pointer, Seek, Struct, Switch, \
Tell, this

Expand Down Expand Up @@ -142,7 +140,7 @@ def __lc_str_from_load_command(this):
)


class LoadCommand(object):
class LoadCommand:
def __init__(self, load_command_data):
self.__load_command_data = load_command_data
self.__cmd = load_command_data.cmd
Expand All @@ -160,7 +158,7 @@ def cmd_size(self):

class DylibCommand(LoadCommand):
def __init__(self, load_command_data):
super(DylibCommand, self).__init__(load_command_data)
super().__init__(load_command_data)
dylib_data = load_command_data.data.dylib

self.__path = dylib_data.lc_str.name
Expand All @@ -181,7 +179,7 @@ def path(self):

class Segment64Command(LoadCommand):
def __init__(self, load_command_data):
super(Segment64Command, self).__init__(load_command_data)
super().__init__(load_command_data)

self.__segname = load_command_data.data.segname
self.__vmaddr = load_command_data.data.vmaddr
Expand Down Expand Up @@ -210,7 +208,7 @@ def __repr__(self):

class UUIDCommand(LoadCommand):
def __init__(self, load_command_data):
super(UUIDCommand, self).__init__(load_command_data)
super().__init__(load_command_data)

self.__uuid = load_command_data.data.uuid

Expand All @@ -223,7 +221,7 @@ def __repr__(self):

class BuildVersionCommand(LoadCommand):
def __init__(self, load_command_data):
super(BuildVersionCommand, self).__init__(load_command_data)
super().__init__(load_command_data)

self.__platform = load_command_data.data.platform
self.__minos = load_command_data.data.platform
Expand Down Expand Up @@ -252,7 +250,7 @@ def sdk(self):

class UnimplementedCommand(LoadCommand):
def __init__(self, load_command_data):
super(UnimplementedCommand, self).__init__(load_command_data)
super().__init__(load_command_data)

self.__bytes = load_command_data.data

Expand Down Expand Up @@ -287,15 +285,15 @@ def all(self):
return self.__load_commands

@property
def segment_commands(self) -> List[Segment64Command]:
def segment_commands(self) -> list[Segment64Command]:
return [segment_command for segment_command in self.__load_commands if
isinstance(segment_command, Segment64Command)]

@property
def dylib_commands(self) -> List[DylibCommand]:
def dylib_commands(self) -> list[DylibCommand]:
return [dylib_command for dylib_command in self.__load_commands if isinstance(dylib_command, DylibCommand)]

def find(self, predicate=None) -> List[LoadCommand]:
def find(self, predicate=None) -> list[LoadCommand]:
if predicate is None:
return self.__load_commands

Expand Down
4 changes: 2 additions & 2 deletions hilda/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SymbolFormatField(FormatField):
"""

def __init__(self, client):
super(SymbolFormatField, self).__init__('<', 'Q')
super().__init__('<', 'Q')
self._client = client

def _parse(self, stream, context, path):
Expand Down Expand Up @@ -165,7 +165,7 @@ def seek(self, offset: int, whence: int = os.SEEK_SET) -> None:
elif whence == os.SEEK_SET:
self._offset = offset - self
else:
raise IOError('Unsupported whence')
raise OSError('Unsupported whence')

def read(self, count: int) -> bytes:
""" Construct compliance. """
Expand Down
11 changes: 5 additions & 6 deletions hilda/ui/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import shutil
from abc import abstractmethod
from typing import List, Mapping

from click import style
from lldb import SBAddress
Expand All @@ -9,7 +8,7 @@
WORD_SIZE = 8


def dict_diff(d1: Mapping, d2: Mapping) -> List[str]:
def dict_diff(d1: dict, d2: dict) -> list[str]:
""" Returns a list of keys whose values have changed """
changed_keys = []
if d1 is None or d2 is None:
Expand Down Expand Up @@ -59,7 +58,7 @@ def __init__(self, hilda_client, color_scheme, depth=DEFAULT_STACK_DEPTH):
"""
super().__init__(hilda_client, 'Stack', color_scheme)
self.depth = depth
self.prev: Mapping[int, str] = None
self.prev: dict[int, str] = None

def __str__(self) -> str:
""" Format stack view for printing """
Expand All @@ -80,7 +79,7 @@ def __str__(self) -> str:

return super().__str__() + '\n'.join(fmt_parts)

def _create_mapping(self) -> Mapping[int, str]:
def _create_mapping(self) -> dict[int, str]:
""" Generate mapping of stack address:data"""
base_addr = self.hilda.frame.sp
stack_mapping = {}
Expand All @@ -103,7 +102,7 @@ def __init__(self, hilda_client, color_scheme, rtype=DEFAULT_REGISTERS_TYPE):
`prev` saves the last registers stats inorder to perform diff check.
"""
super().__init__(hilda_client, 'Registers', color_scheme)
self.prev: Mapping[str, str] = None
self.prev: dict[str, str] = None
self.rtype = rtype

def __str__(self) -> str:
Expand Down Expand Up @@ -133,7 +132,7 @@ def __str__(self) -> str:

return super().__str__() + tabulate(list(zip(*list_of_lists)), tablefmt='plain', numalign='left')

def _create_mapping(self) -> Mapping[str, str]:
def _create_mapping(self) -> dict[str, str]:
""" Generate mapping of registers name:data"""
regs = self._get_registers()
regs_mapping = {}
Expand Down
Loading

0 comments on commit b49a78a

Please sign in to comment.