Skip to content

Commit

Permalink
add -o, added github runner for signing, fix installing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
itsnebulalol committed Jul 24, 2022
1 parent 018a29a commit 510f6a0
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 32 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run script

on:
workflow_dispatch:
inputs:
ipa:
description: "Direct URL to IPA file"
required: true

jobs:
run:
runs-on: ubuntu-latest

steps:
# Checkout the latest code from the repo
- name: Checkout repo
uses: actions/checkout@v2

# Setup which version of Python to use
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9

# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Run script
- name: Run script
run: python main.py -u ${{ github.event.inputs.ipa }} -n -d
id: run_script

# Get name of app
- name: Get name of app
shell: python
run: |
s = """${{ steps.run_tests.outputs.* }}"""
print(s.splitlines()[-1].replace("[*] Output file: ", ""))
id: app_name

# Upload test artifact
- uses: actions/upload-artifact@v3
with:
name: ${{ steps.app_name.outputs.* }}
path: output/${{ steps.app_name.outputs.* }}
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: Run tests
name: Test script

on:
push:
paths-ignore:
- 'README.md'
branches:
- "main"
pull_request:
paths-ignore:
- 'README.md'
branches:
- "main"

Expand Down
56 changes: 38 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,20 +460,22 @@ def main(args):
if Path(f"output/{out_deb_name}.deb").exists():
os.remove(f"output/{out_deb_name}.deb")

global dpkg_cmd
if args.output:
dpkg_cmd = f"dpkg-deb -Zxz --root-owner-group -b {tmpfolder}/deb {args.output}"
else:
dpkg_cmd = f"dpkg-deb -Zxz --root-owner-group -b {tmpfolder}/deb output/{out_deb_name}.deb"

if dpkg_in_path:
if args.debug:
print(
f"[DEBUG] Running command: dpkg-deb -Zxz --root-owner-group -b {tmpfolder}/deb output/{out_deb_name}.deb")
print(f"[DEBUG] Running command: {dpkg_cmd}")

subprocess.run(
f"dpkg-deb -Zxz --root-owner-group -b {tmpfolder}/deb output/{out_deb_name}.deb".split(), stdout=subprocess.DEVNULL)
subprocess.run(f"{dpkg_cmd}".split(), stdout=subprocess.DEVNULL)
else:
if args.debug:
print(
f"[DEBUG] Running command: ./dpkg-deb -Zxz --root-owner-group -b {tmpfolder}/deb output/{out_deb_name}.deb")
print(f"[DEBUG] Running command: ./{dpkg_cmd}")

subprocess.run(
f"./dpkg-deb -Zxz --root-owner-group -b {tmpfolder}/deb output/{out_deb_name}.deb".split(), stdout=subprocess.DEVNULL)
subprocess.run(f"./{dpkg_cmd}".split(), stdout=subprocess.DEVNULL)

is_installed = False
if not args.noinstall:
Expand All @@ -492,7 +494,7 @@ def main(args):
print("Did not find a connected device")
else:
print("Found a connected device")
Installer.install_deb(args)
Installer.install_deb(args, out_deb_name)
is_installed = True
except ConnectionRefusedError:
print("Did not find a connected device")
Expand All @@ -503,43 +505,61 @@ def main(args):
stdout=PIPE, stderr=PIPE)
if p.returncode == 0 or 'password' in p.stderr.decode():
print("User is in sudoers, using sudo command")
subprocess.run(
f"sudo dpkg -i output/{out_deb_name}.deb".split(), stdout=PIPE, stderr=PIPE)
if args.output:
subprocess.run(
f"sudo dpkg -i {args.output}".split(), stdout=PIPE, stderr=PIPE)
else:
subprocess.run(
f"sudo dpkg -i output/{out_deb_name}.deb".split(), stdout=PIPE, stderr=PIPE)

subprocess.run(
f"sudo apt install -f".split(), stdout=PIPE, stderr=PIPE)
else:
print("User is not in sudoers, using su instead")
subprocess.run(
f"su root -c 'dpkg -i output/{out_deb_name}.deb'".split(), stdout=PIPE, stderr=PIPE)
if args.output:
subprocess.run(
f"su root -c 'dpkg -i {args.output}'".split(), stdout=PIPE, stderr=PIPE)
else:
subprocess.run(
f"su root -c 'dpkg -i output/{out_deb_name}.deb'".split(), stdout=PIPE, stderr=PIPE)

subprocess.run(
f"su root -c 'apt install -f'".split(), stdout=PIPE, stderr=PIPE)

# Done!!!
print()
print("[*] We are finished!")

if is_installed:
print(
"[*] The application was installed to your device, no further steps are required!")
else:
print("[*] Copy the newly created deb from the output folder to your jailbroken iDevice and install it!")

print("[*] The app will continue to work when rebooted to stock.")
print(f"[*] Output file: output/{out_deb_name}.deb")

if args.output:
print(f"[*] Output file: {args.output}")
else:
print(f"[*] Output file: output/{out_deb_name}.deb")


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--codesign', action='store_true',
help="uses codesign instead of ldid.")
help="uses codesign instead of ldid")
parser.add_argument('-d', '--debug', action='store_true',
help="shows some debug info, only useful for testing.")
help="shows some debug info, only useful for testing")
parser.add_argument('-u', '--url', type=str,
help="the direct URL of the IPA to be signed.")
help="the direct URL of the IPA to be signed")
parser.add_argument('-p', '--path', type=str,
help="the direct local path of the IPA to be signed.")
help="the direct local path of the IPA to be signed")
parser.add_argument('-i', '--install', action='store_true',
help="installs the application to your device")
parser.add_argument('-n', '--noinstall',
action='store_true', help="skips the install prompt")
parser.add_argument('-o', '--output', type=str,
help="specify output file")
args = parser.parse_args()

main(args)
42 changes: 29 additions & 13 deletions utils/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def treat_shell_output(args, shell):
s_output = get_shell_output(args, shell)
if 'password' in s_output.lower():
shell.send((getpass() + '\n').encode())
s_output = get_shell_output(args, shell)
s_output = Installer.get_shell_output(args, shell)
for line in s_output.splitlines():
print(line)

def install_deb(args):
def install_deb(args, out_deb_name):
print(f'[*] Installing {out_deb_name} to the device')
print("Relaying TCP connection")
if args.debug:
Expand All @@ -44,27 +44,43 @@ def install_deb(args):
look_for_keys=False,
compress=True)
with SCPClient(client.get_transport()) as scp:
print(f"Sending {out_deb_name}.deb to device")
scp.put(f'output/{out_deb_name}.deb',
remote_path='/var/mobile/Documents')
if args.output:
print(
f"Sending {args.output.split('/')[-1]} to device")
scp.put(f'{args.output}',
remote_path='/var/mobile/Documents')
else:
print(f"Sending {out_deb_name}.deb to device")
scp.put(f'output/{out_deb_name}.deb',
remote_path='/var/mobile/Documents')
stdin, stdout, stderr = client.exec_command('sudo -nv')
error = stderr.readline()
status = stdout.channel.recv_exit_status()
shell = client.invoke_shell()
if status == 0 or 'password' in error:
print("User is in sudoers, using sudo")
shell.send(
f"sudo dpkg -i /var/mobile/Documents/{out_deb_name}.deb\n".encode())
treat_shell_output(args, shell)
if args.output:
shell.send(
f"sudo dpkg -i /var/mobile/Documents/{args.output.split('/')[-1].replace('.deb', '')}.deb\n".encode())
else:
shell.send(
f"sudo dpkg -i /var/mobile/Documents/{out_deb_name}.deb\n".encode())

Installer.treat_shell_output(args, shell)
shell.send(f"sudo apt -f install\n".encode())
treat_shell_output(args, shell)
Installer.treat_shell_output(args, shell)
else:
print("User is not in sudoers, using su instead")
shell.send(
f"su root -c 'dpkg -i /var/mobile/Documents/{out_deb_name}.deb'\n".encode())
treat_shell_output(args, shell)
if args.output:
shell.send(
f"su root -c 'dpkg -i /var/mobile/Documents/{args.output.split('/')[-1].replace('.deb', '')}.deb'\n".encode())
else:
shell.send(
f"su root -c 'dpkg -i /var/mobile/Documents/{out_deb_name}.deb'\n".encode())

Installer.treat_shell_output(args, shell)
shell.send(f"su root -c 'apt -f install'\n".encode())
treat_shell_output(args, shell)
Installer.treat_shell_output(args, shell)
except (SSHException, NoValidConnectionsError, AuthenticationException) as e:
print(e)
finally:
Expand Down

0 comments on commit 510f6a0

Please sign in to comment.