Skip to content

Commit

Permalink
linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
itsnebulalol committed Aug 30, 2022
1 parent a8da4ab commit 2a0085a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 34 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ on:
branches:
- "main"

workflow_dispatch:

jobs:
autopep8:
runs-on: ubuntu-latest
Expand All @@ -25,7 +27,7 @@ jobs:
- name: autopep8
uses: peter-evans/autopep8@v1
with:
args: --recursive --in-place .
args: --recursive --in-place --global-config ".pep8" .

- uses: stefanzweifel/git-auto-commit-action@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .pep8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pycodestyle]
max_line_length = 130
ignore = ["E701", "E70", "E722", "E402", "E301", "E302", "E266", "E265", "E26", "E501", "E231"]
max-line-length = 130
ignore = E701, E70, E722, E402, E301, E302, E266, E265, E26, E501, E231
in-place = true
recursive = true
6 changes: 3 additions & 3 deletions permasigner/dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def package(self) -> Path:
self.tmpfolder / "deb/Applications",
self.tmpfolder / "deb/DEBIAN/control",
self.tmpfolder / "deb/DEBIAN/postinst",
self.tmpfolder / "deb/DEBIAN/prerm")
self.tmpfolder / "deb/DEBIAN/prerm"
)


class Deb:
Expand All @@ -74,8 +75,7 @@ def extract_with_dpkg(self) -> None:
# Extract deb contents with dpkg-deb -X
logger.log("Extracting deb file...\n", color=colors["yellow"])
logger.debug(f"Running command: dpkg-deb -X {self.src} {self.dest}", self.debug)
subprocess.run(
["dpkg-deb", "-X", self.src, self.dest], stdout=subprocess.DEVNULL)
subprocess.run(["dpkg-deb", "-X", self.src, self.dest], stdout=subprocess.DEVNULL)

def extract_with_ar(self) -> None:
logger.log("Extracting deb file...\n", color=colors["yellow"])
Expand Down
24 changes: 8 additions & 16 deletions permasigner/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ def install_with_sudo_on_ios(output_path: Path, debug: bool) -> bool:
logger.debug("User is in sudoers file", debug)
logger.debug(f"Running command: sudo dpkg -i {output_path}", debug)

subprocess.run(
["sudo", "dpkg", "-i", f"{output_path}"], stdin=PIPE, capture_output=True)
subprocess.run(["sudo", "dpkg", "-i", f"{output_path}"], stdin=PIPE, capture_output=True)

# This is needed on elucuratus bootstrap
# Otherwise the package will end up in a half installed state
logger.debug(f"Running command: sudo apt-get install -f", debug)
subprocess.run(
['sudo', 'apt-get', 'install', '-f'], stdin=PIPE, capture_output=True)
subprocess.run(['sudo', 'apt-get', 'install', '-f'], stdin=PIPE, capture_output=True)

return True

Expand All @@ -52,14 +50,12 @@ def install_with_su_on_ios(output_path: Path, debug: bool) -> bool:
logger.debug("User is not in sudoers, will use su instead", debug)

logger.debug(f"Running command: su root -c 'dpkg -i {output_path}'", debug)
subprocess.run(
f"su root -c 'dpkg -i {output_path}'".split(), stdin=PIPE, capture_output=True)
subprocess.run(f"su root -c 'dpkg -i {output_path}'".split(), stdin=PIPE, capture_output=True)

# This is needed on elucuratus bootstrap
# Otherwise the package will end up in half installed state
logger.debug(f"Running command: su root -c 'apt-get install -f'", debug)
subprocess.run(
"su root -c 'apt-get install -f'".split(), stdin=PIPE, capture_output=True)
subprocess.run("su root -c 'apt-get install -f'".split(), stdin=PIPE, capture_output=True)

return True

Expand Down Expand Up @@ -92,8 +88,7 @@ def install_from_pc(path: Path, args: Namespace) -> bool:
time.sleep(1)

# Get user password to establish the SSH connection
password = getpass(
prompt="Please provide your user password (default = alpine): ")
password = getpass(prompt="Please provide your user password (default = alpine): ")

# Default to 'alpine' on empty input
if len(password.strip()) == 0:
Expand Down Expand Up @@ -134,8 +129,7 @@ def install_from_pc(path: Path, args: Namespace) -> bool:
if "password" in stderr.read().decode():
command = f"sudo dpkg -i /var/mobile/Documents/{filename}"
logger.debug(f"Running command: {command}", args.debug)
stdin, stdout, stderr = client.exec_command(
f"{command}", get_pty=True)
stdin, stdout, stderr = client.exec_command(f"{command}", get_pty=True)

# Sleep to prevent echoing password
time.sleep(0.2)
Expand Down Expand Up @@ -190,8 +184,7 @@ def install_from_pc(path: Path, args: Namespace) -> bool:
else:
# Install with dpkg by invoking su as root user
logger.debug(f"Running command: su root -c 'dpkg -i /var/mobile/Documents/{filename}", args.debug)
stdin, stdout, stderr = client.exec_command(
f"su root -c 'dpkg -i /var/mobile/Documents/{filename}", get_pty=True)
stdin, stdout, stderr = client.exec_command(f"su root -c 'dpkg -i /var/mobile/Documents/{filename}", get_pty=True)

# Read output from the channel
output = stdout.channel.recv(2048)
Expand All @@ -212,8 +205,7 @@ def install_from_pc(path: Path, args: Namespace) -> bool:

# Needed on elucuratus
# to prevent half-installed state
stdin, stdout, stderr = client.exec_command(
"su root -c 'apt-get install -f'", get_pty=True)
stdin, stdout, stderr = client.exec_command("su root -c 'apt-get install -f'", get_pty=True)
time.sleep(0.2)

# Write password to stdin
Expand Down
3 changes: 1 addition & 2 deletions permasigner/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def log(message, color=None):

def debug(message, dbg):
if dbg:
print(
colors["lightcyan"] + colors["bold"] + "[DEBUG] " + colors["reset"] + colors["lightcyan"] + f"{message}" + colors["reset"])
print(colors["lightcyan"] + colors["bold"] + "[DEBUG] " + colors["reset"] + colors["lightcyan"] + f"{message}" + colors["reset"])


def error(message):
Expand Down
3 changes: 1 addition & 2 deletions permasigner/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ def sign_with_ldid(self, ldid: str) -> None:
def sign_with_codesign(self) -> None:
# Import the certificate
logger.debug(f"Running command: security import {self.cert} -P password -A", self.args.debug)
subprocess.run(
['security', 'import', self.cert, '-P', 'password', '-A'], stdout=subprocess.DEVNULL)
subprocess.run(['security', 'import', self.cert, '-P', 'password', '-A'], stdout=subprocess.DEVNULL)

# Sign with codesign using imported certificate
logger.debug(f"Running command: codesign -s 'We Do A Little Trolling iPhone OS Application Signing "
Expand Down
12 changes: 4 additions & 8 deletions permasigner/tcprelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def _unpack(self, resp, payload):
if resp == self.TYPE_RESULT:
return {'Number': struct.unpack("I", payload)[0]}
elif resp == self.TYPE_DEVICE_ADD:
devid, usbpid, serial, pad, location = struct.unpack(
"IH256sHI", payload)
devid, usbpid, serial, pad, location = struct.unpack("IH256sHI", payload)
serial = serial.decode().split("\0")[0]
return {'DeviceID': devid,
'Properties': {'LocationID': location, 'SerialNumber': serial, 'ProductID': usbpid}}
Expand Down Expand Up @@ -127,8 +126,7 @@ def getpacket(self):
body = self.socket.recv(dlen - 4)
version, resp, tag = struct.unpack("3I", body[:0xc])
if version != self.VERSION:
raise MuxVersionError(
f"Version mismatch: expected {self.VERSION}, got {version}")
raise MuxVersionError(f"Version mismatch: expected {self.VERSION}, got {version}")
payload = self._unpack(resp, body[0xc:])
return resp, tag, payload

Expand Down Expand Up @@ -159,8 +157,7 @@ def sendpacket(self, req, tag, payload=None):
req = [self.TYPE_CONNECT, self.TYPE_LISTEN][req - 2]
payload['MessageType'] = req
payload['ProgName'] = 'tcprelay'
BinaryProtocol.sendpacket(
self, self.TYPE_PLIST, tag, plistlib.dumps(payload))
BinaryProtocol.sendpacket(self, self.TYPE_PLIST, tag, plistlib.dumps(payload))

def getpacket(self):
resp, tag, payload = BinaryProtocol.getpacket(self)
Expand Down Expand Up @@ -229,8 +226,7 @@ def listen(self):

def process(self, timeout=None):
if self.proto.connected:
raise MuxError(
"Socket is connected, cannot process listener events")
raise MuxError("Socket is connected, cannot process listener events")
rlo, wlo, xlo = select([self.socket.sock], [], [
self.socket.sock], timeout)
if xlo:
Expand Down

0 comments on commit 2a0085a

Please sign in to comment.