mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-13 06:24:16 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -7,11 +7,14 @@ interface to ``ZipFile``. Only the read interface is implemented.
|
|||
Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
|
||||
ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import enum
|
||||
import os
|
||||
import struct
|
||||
from typing import IO, Optional, Tuple
|
||||
from typing import IO
|
||||
from typing import Optional
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
class ELFInvalid(ValueError):
|
||||
|
|
@ -45,12 +48,12 @@ class ELFFile:
|
|||
self._f = f
|
||||
|
||||
try:
|
||||
ident = self._read("16B")
|
||||
ident = self._read('16B')
|
||||
except struct.error:
|
||||
raise ELFInvalid("unable to parse identification")
|
||||
raise ELFInvalid('unable to parse identification')
|
||||
magic = bytes(ident[:4])
|
||||
if magic != b"\x7fELF":
|
||||
raise ELFInvalid(f"invalid magic: {magic!r}")
|
||||
if magic != b'\x7fELF':
|
||||
raise ELFInvalid(f'invalid magic: {magic!r}')
|
||||
|
||||
self.capacity = ident[4] # Format for program header (bitness).
|
||||
self.encoding = ident[5] # Data structure encoding (endianness).
|
||||
|
|
@ -60,15 +63,15 @@ class ELFFile:
|
|||
# p_fmt: Format for section header.
|
||||
# p_idx: Indexes to find p_type, p_offset, and p_filesz.
|
||||
e_fmt, self._p_fmt, self._p_idx = {
|
||||
(1, 1): ("<HHIIIIIHHH", "<IIIIIIII", (0, 1, 4)), # 32-bit LSB.
|
||||
(1, 2): (">HHIIIIIHHH", ">IIIIIIII", (0, 1, 4)), # 32-bit MSB.
|
||||
(2, 1): ("<HHIQQQIHHH", "<IIQQQQQQ", (0, 2, 5)), # 64-bit LSB.
|
||||
(2, 2): (">HHIQQQIHHH", ">IIQQQQQQ", (0, 2, 5)), # 64-bit MSB.
|
||||
(1, 1): ('<HHIIIIIHHH', '<IIIIIIII', (0, 1, 4)), # 32-bit LSB.
|
||||
(1, 2): ('>HHIIIIIHHH', '>IIIIIIII', (0, 1, 4)), # 32-bit MSB.
|
||||
(2, 1): ('<HHIQQQIHHH', '<IIQQQQQQ', (0, 2, 5)), # 64-bit LSB.
|
||||
(2, 2): ('>HHIQQQIHHH', '>IIQQQQQQ', (0, 2, 5)), # 64-bit MSB.
|
||||
}[(self.capacity, self.encoding)]
|
||||
except KeyError:
|
||||
raise ELFInvalid(
|
||||
f"unrecognized capacity ({self.capacity}) or "
|
||||
f"encoding ({self.encoding})"
|
||||
f'unrecognized capacity ({self.capacity}) or '
|
||||
f'encoding ({self.encoding})',
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
@ -85,13 +88,13 @@ class ELFFile:
|
|||
self._e_phnum, # Number of sections.
|
||||
) = self._read(e_fmt)
|
||||
except struct.error as e:
|
||||
raise ELFInvalid("unable to parse machine and section information") from e
|
||||
raise ELFInvalid('unable to parse machine and section information') from e
|
||||
|
||||
def _read(self, fmt: str) -> Tuple[int, ...]:
|
||||
def _read(self, fmt: str) -> tuple[int, ...]:
|
||||
return struct.unpack(fmt, self._f.read(struct.calcsize(fmt)))
|
||||
|
||||
@property
|
||||
def interpreter(self) -> Optional[str]:
|
||||
def interpreter(self) -> str | None:
|
||||
"""
|
||||
The path recorded in the ``PT_INTERP`` section header.
|
||||
"""
|
||||
|
|
@ -104,5 +107,5 @@ class ELFFile:
|
|||
if data[self._p_idx[0]] != 3: # Not PT_INTERP.
|
||||
continue
|
||||
self._f.seek(data[self._p_idx[1]])
|
||||
return os.fsdecode(self._f.read(data[self._p_idx[2]])).strip("\0")
|
||||
return os.fsdecode(self._f.read(data[self._p_idx[2]])).strip('\0')
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue