Skip to content

Commit

Permalink
Improve typing stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Oct 15, 2023
1 parent b8409a7 commit 3ade273
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 93 deletions.
4 changes: 2 additions & 2 deletions api/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ endmacro()
if (LIEF_EXTERNAL_NANOBINDS)
find_package(nanobind REQUIRED)
else()
set(NANOBIND_VERSION 1.6.2.r7.gb4c5af0)
set(NANOBIND_SHA256 SHA256=b0c84f3729ba231b7539ca9484b7cc1bf32cce877cc29fa875e9f7919ef5b874)
set(NANOBIND_VERSION 1.6.2.r20.g46ed29e)
set(NANOBIND_SHA256 SHA256=fd91abf745de6b67edf87f9549df5380b666a66218b0bf170e27313d3a726ee7)
set(NANOBIND_URL "${THIRD_PARTY_DIRECTORY}/nanobind-${NANOBIND_VERSION}.zip" CACHE STRING "URL to the Nanobind")
FetchContent_Declare(nanobind
URL ${NANOBIND_URL}
Expand Down
7 changes: 3 additions & 4 deletions api/python/lief/ART.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any, ClassVar
from typing import Any, ClassVar, Optional

from typing import overload
import lief # type: ignore
import lief.ART # type: ignore
import lief.Android # type: ignore

Expand Down Expand Up @@ -62,9 +61,9 @@ class STORAGE_MODES:

def android_version(art_version: int) -> lief.Android.ANDROID_VERSIONS: ...
@overload
def parse(filename: str) -> lief.ART.File: ...
def parse(filename: str) -> Optional[lief.ART.File]: ...
@overload
def parse(raw: list[int], name: str = ...) -> lief.ART.File: ...
def parse(raw: list[int], name: str = ...) -> Optional[lief.ART.File]: ...
@overload
def parse(io: object, name: str = ...) -> object: ...
@overload
Expand Down
13 changes: 9 additions & 4 deletions api/python/lief/DEX.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from typing import Any, ClassVar
from typing import Any, ClassVar, Optional

from typing import overload
import lief # type: ignore
import lief.DEX # type: ignore
import lief.DEX.Class # type: ignore
import lief.DEX.File # type: ignore
import lief.DEX.MapItem # type: ignore
import lief.DEX.MapList # type: ignore
import lief.DEX.Prototype # type: ignore
import lief.DEX.Type # type: ignore

class ACCESS_FLAGS:
ABSTRACT: ClassVar[ACCESS_FLAGS] = ...
Expand Down Expand Up @@ -336,9 +341,9 @@ class Type(lief.Object):
def value(self) -> object: ...

@overload
def parse(filename: str) -> lief.DEX.File: ...
def parse(filename: str) -> Optional[lief.DEX.File]: ...
@overload
def parse(raw: list[int], name: str = ...) -> lief.DEX.File: ...
def parse(raw: list[int], name: str = ...) -> Optional[lief.DEX.File]: ...
@overload
def parse(io: object, name: str = ...) -> object: ...
@overload
Expand Down
30 changes: 20 additions & 10 deletions api/python/lief/ELF.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
from typing import Any, ClassVar, Iterable, Iterator, Optional
from typing import Any, ClassVar, Iterable, Iterator, Optional, Union

from typing import overload
import io
import lief # type: ignore
import lief.ELF # type: ignore
import lief.ELF.Binary # type: ignore
import lief.ELF.Builder # type: ignore
import lief.ELF.CoreAuxv # type: ignore
import lief.ELF.CoreFile # type: ignore
import lief.ELF.CorePrStatus # type: ignore
import lief.ELF.Section # type: ignore
import lief.ELF.Segment # type: ignore
import lief.ELF.SymbolVersionDefinition # type: ignore
import lief.ELF.SymbolVersionRequirement # type: ignore

class ARCH:
AARCH64: ClassVar[ARCH] = ...
Expand Down Expand Up @@ -319,7 +329,7 @@ class Binary(lief.Binary):
def __iter__(self) -> lief.ELF.Binary.it_symbols_version_requirement: ...
def __len__(self) -> int: ...
def __next__(self) -> lief.ELF.SymbolVersionRequirement: ...
interpreter: Any
interpreter: str
overlay: memoryview
def __init__(self, *args, **kwargs) -> None: ...
@overload
Expand Down Expand Up @@ -466,7 +476,7 @@ class Binary(lief.Binary):
@property
def has_overlay(self) -> bool: ...
@property
def header(self) -> lief.ELF.Header: ...
def header(self) -> lief.ELF.Header: ... # type: ignore
@property
def imagebase(self) -> int: ...
@property
Expand All @@ -488,13 +498,13 @@ class Binary(lief.Binary):
@property
def relocations(self) -> lief.ELF.Binary.it_relocations: ...
@property
def sections(self) -> lief.ELF.Binary.it_sections: ...
def sections(self) -> lief.ELF.Binary.it_sections: ... # type: ignore
@property
def segments(self) -> lief.ELF.Binary.it_segments: ...
@property
def static_symbols(self) -> lief.ELF.Binary.it_symbols: ...
@property
def strings(self) -> list[str]: ...
def strings(self) -> list[Union[str,bytes]]: ...
@property
def symbols(self) -> lief.ELF.Binary.it_dyn_static_symbols: ...
@property
Expand Down Expand Up @@ -2434,7 +2444,7 @@ class Section(lief.Section):
entry_size: int
file_offset: int
flags: int
information: Any
information: int
link: int
type: lief.ELF.SECTION_TYPES
@overload
Expand Down Expand Up @@ -2525,7 +2535,7 @@ class Symbol(lief.Symbol):
@property
def is_variable(self) -> bool: ...
@property
def section(self) -> Any: ...
def section(self) -> lief.ELF.Section: ...
@property
def symbol_version(self) -> lief.ELF.SymbolVersion: ...

Expand Down Expand Up @@ -2601,8 +2611,8 @@ class VERSION:
def value(self) -> int: ...

@overload
def parse(filename: str, config: lief.ELF.ParserConfig = ...) -> lief.ELF.Binary | None: ...
def parse(filename: str, config: lief.ELF.ParserConfig = ...) -> Optional[lief.ELF.Binary]: ...
@overload
def parse(raw: list[int], config: lief.ELF.ParserConfig = ...) -> lief.ELF.Binary | None: ...
def parse(raw: list[int], config: lief.ELF.ParserConfig = ...) -> Optional[lief.ELF.Binary]: ...
@overload
def parse(io: object, config: lief.ELF.ParserConfig = ...) -> lief.ELF.Binary | None: ...
def parse(io: io.IOBase, config: lief.ELF.ParserConfig = ...) -> lief.ELF.Binary | None: ...
50 changes: 32 additions & 18 deletions api/python/lief/MachO.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
from typing import Any, ClassVar
from typing import Any, ClassVar, Optional

from typing import overload
import io
import lief # type: ignore
import lief.MachO # type: ignore
import lief.MachO.Binary # type: ignore
import lief.MachO.BuildToolVersion # type: ignore
import lief.MachO.BuildVersion # type: ignore
import lief.MachO.Builder # type: ignore
import lief.MachO.DataCodeEntry # type: ignore
import lief.MachO.DyldChainedFixups # type: ignore
import lief.MachO.DyldInfo # type: ignore
import lief.MachO.FatBinary # type: ignore
import lief.MachO.SegmentCommand # type: ignore
import lief.MachO.Symbol # type: ignore
import lief.MachO.TwoLevelHints # type: ignore

class ARM64_RELOCATION:
ADDEND: ClassVar[ARM64_RELOCATION] = ...
Expand Down Expand Up @@ -304,13 +316,13 @@ class Binary(lief.Binary):
@property
def has_version_min(self) -> bool: ...
@property
def header(self) -> lief.MachO.Header: ...
def header(self) -> lief.MachO.Header: ... # type: ignore
@property
def imagebase(self) -> int: ...
@property
def imported_symbols(self) -> lief.MachO.Binary.it_filter_symbols: ...
@property
def libraries(self) -> lief.MachO.Binary.it_libraries: ...
def libraries(self) -> lief.MachO.Binary.it_libraries: ... # type: ignore
@property
def linker_opt_hint(self) -> lief.MachO.LinkerOptHint: ...
@property
Expand All @@ -326,7 +338,7 @@ class Binary(lief.Binary):
@property
def rpaths(self) -> lief.MachO.Binary.it_rpaths: ...
@property
def sections(self) -> lief.MachO.Binary.it_sections: ...
def sections(self) -> lief.MachO.Binary.it_sections: ... # type: ignore
@property
def segment_split_info(self) -> lief.MachO.SegmentSplitInfo: ...
@property
Expand Down Expand Up @@ -779,7 +791,7 @@ class FatBinary:
def __init__(self, *args, **kwargs) -> None: ...
def at(self, index: int) -> lief.MachO.Binary: ...
def raw(self) -> list[int]: ...
def take(self, cpu: lief.MachO.CPU_TYPES) -> lief.MachO.Binary: ...
def take(self, cpu: lief.MachO.CPU_TYPES) -> Optional[lief.MachO.Binary]: ...
def write(self, filename: str) -> None: ...
def __getitem__(self, arg: int, /) -> lief.MachO.Binary: ...
def __iter__(self) -> lief.MachO.FatBinary.it_binaries: ...
Expand Down Expand Up @@ -842,7 +854,7 @@ class Header(lief.Object):
cpu_subtype: int
cpu_type: lief.MachO.CPU_TYPES
file_type: lief.MachO.FILE_TYPES
flags: Any
flags: int
magic: lief.MachO.MACHO_TYPES
nb_cmds: int
reserved: int
Expand Down Expand Up @@ -1223,17 +1235,17 @@ class SubFramework(LoadCommand):
def __init__(self, *args, **kwargs) -> None: ...

class Symbol(lief.Symbol):
class TOOLS:
EXTERNAL: ClassVar[Symbol.TOOLS] = ...
INDIRECT_ABS: ClassVar[Symbol.TOOLS] = ...
INDIRECT_LOCAL: ClassVar[Symbol.TOOLS] = ...
LOCAL: ClassVar[Symbol.TOOLS] = ...
NONE: ClassVar[Symbol.TOOLS] = ...
UNDEFINED: ClassVar[Symbol.TOOLS] = ...
class CATEGORY:
EXTERNAL: ClassVar[Symbol.CATEGORY] = ...
INDIRECT_ABS: ClassVar[Symbol.CATEGORY] = ...
INDIRECT_LOCAL: ClassVar[Symbol.CATEGORY] = ...
LOCAL: ClassVar[Symbol.CATEGORY] = ...
NONE: ClassVar[Symbol.CATEGORY] = ...
UNDEFINED: ClassVar[Symbol.CATEGORY] = ...
__name__: Any
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def from_value(arg: int, /) -> lief.MachO.Symbol.TOOLS: ...
def from_value(arg: int, /) -> lief.MachO.Symbol.CATEGORY: ...
@property
def value(self) -> int: ...
description: int
Expand All @@ -1243,6 +1255,8 @@ class Symbol(lief.Symbol):
@property
def binding_info(self) -> lief.MachO.BindingInfo: ...
@property
def category(self) -> lief.MachO.Symbol.CATEGORY: ...
@property
def demangled_name(self) -> str: ...
@property
def export_info(self) -> lief.MachO.ExportInfo: ...
Expand Down Expand Up @@ -1348,9 +1362,9 @@ def check_layout(file: lief.MachO.FatBinary) -> tuple[bool,str]: ...
def is_64(file: str) -> bool: ...
def is_fat(file: str) -> bool: ...
@overload
def parse(filename: str, config: lief.MachO.ParserConfig = ...) -> lief.MachO.FatBinary | None: ...
def parse(filename: str, config: lief.MachO.ParserConfig = ...) -> Optional[lief.MachO.FatBinary]: ...
@overload
def parse(raw: list[int], config: lief.MachO.ParserConfig = ...) -> lief.MachO.FatBinary | None: ...
def parse(raw: list[int], config: lief.MachO.ParserConfig = ...) -> Optional[lief.MachO.FatBinary]: ...
@overload
def parse(io: object, config: lief.MachO.ParserConfig = ...) -> lief.MachO.FatBinary | None: ...
def parse_from_memory(address: int, config: lief.MachO.ParserConfig = ...) -> lief.MachO.FatBinary: ...
def parse(io: io.IOBase, config: lief.MachO.ParserConfig = ...) -> lief.MachO.FatBinary | None: ...
def parse_from_memory(address: int, config: lief.MachO.ParserConfig = ...) -> Optional[lief.MachO.FatBinary]: ...
12 changes: 7 additions & 5 deletions api/python/lief/OAT.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Any, ClassVar
from typing import Any, ClassVar, Optional

from typing import overload
import lief # type: ignore
import lief.Android # type: ignore
import lief.DEX # type: ignore
import lief.ELF # type: ignore
import lief.OAT # type: ignore
import lief.OAT.Binary # type: ignore
import lief.OAT.Class # type: ignore
import lief.OAT.Header # type: ignore

class Binary(lief.ELF.Binary):
class it_classes:
Expand Down Expand Up @@ -224,11 +226,11 @@ class OAT_CLASS_TYPES:

def android_version(arg: int, /) -> lief.Android.ANDROID_VERSIONS: ...
@overload
def parse(oat_file: str) -> lief.OAT.Binary: ...
def parse(oat_file: str) -> Optional[lief.OAT.Binary]: ...
@overload
def parse(oat_file: str, vdex_file: str) -> lief.OAT.Binary: ...
def parse(oat_file: str, vdex_file: str) -> Optional[lief.OAT.Binary]: ...
@overload
def parse(raw: list[int]) -> lief.OAT.Binary: ...
def parse(raw: list[int]) -> Optional[lief.OAT.Binary]: ...
@overload
def parse(io: object) -> object: ...
@overload
Expand Down
Loading

0 comments on commit 3ade273

Please sign in to comment.