├── src ├── bins │ ├── py3 │ │ ├── tmps │ │ │ └── com.tigisoftware.Filza.png │ │ ├── lsdevs.py │ │ ├── obtainAppLocation.py │ │ ├── fastSpawn.py │ │ ├── lsapps.py │ │ ├── dump_oem.py │ │ └── dump_oem.js │ ├── iOS │ │ └── open │ ├── local │ │ ├── lsdevs │ │ └── idsyslog │ └── generateBinPackCodes.sh ├── test │ ├── suite │ │ ├── extension.test.ts │ │ └── index.ts │ └── runTest.ts ├── extension.ts ├── Utils.ts ├── iDevices.ts ├── iDeviceToolbox.ts ├── iDeviceConnections.ts ├── iDeviceFileSystem.ts └── iDeviceApplications.ts ├── .gitignore ├── images ├── icon.png └── main.png ├── .vscodeignore ├── .vscode ├── sftp.json ├── extensions.json ├── tasks.json ├── settings.json └── launch.json ├── requirements.txt ├── tslint.json ├── .gitlab-ci.yml ├── tsconfig.json ├── res ├── shell.svg ├── info.svg ├── file.svg ├── dir.svg ├── safe.svg ├── password.svg ├── log.svg ├── kill.svg ├── ports.svg ├── ios.svg ├── reload.svg ├── debug.svg ├── package.svg ├── connect.svg ├── pid.svg ├── location.svg ├── id.svg ├── download.svg ├── exchange.svg ├── upload.svg ├── pass.svg ├── start.svg ├── create.svg ├── delete.svg ├── icon.svg ├── terminate.svg ├── copy.svg ├── bundle.svg ├── xcode.svg ├── passr.svg ├── app.svg ├── pig.svg ├── rocket.svg └── error.svg ├── .github └── workflows │ └── nodejs.yml ├── CHANGELOG.md ├── README.md ├── package.json └── LICENSE /src/bins/py3/tmps/com.tigisoftware.Filza.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test/ 4 | *.vsix 5 | .DS_Store -------------------------------------------------------------------------------- /images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lakr233/iOSreExtension/HEAD/images/icon.png -------------------------------------------------------------------------------- /images/main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lakr233/iOSreExtension/HEAD/images/main.png -------------------------------------------------------------------------------- /src/bins/iOS/open: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lakr233/iOSreExtension/HEAD/src/bins/iOS/open -------------------------------------------------------------------------------- /src/bins/local/lsdevs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lakr233/iOSreExtension/HEAD/src/bins/local/lsdevs -------------------------------------------------------------------------------- /src/bins/local/idsyslog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lakr233/iOSreExtension/HEAD/src/bins/local/idsyslog -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | src/** 5 | .gitignore 6 | vsc-extension-quickstart.md 7 | **/tsconfig.json 8 | **/tslint.json 9 | **/*.map 10 | **/*.ts -------------------------------------------------------------------------------- /.vscode/sftp.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "iOS", 3 | "host": "localhost", 4 | "protocol": "sftp", 5 | "port": 2222, 6 | "username": "root", 7 | "remotePath": "/", 8 | "uploadOnSave": true 9 | } 10 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "ms-vscode.vscode-typescript-tslint-plugin" 6 | ] 7 | } -------------------------------------------------------------------------------- /src/bins/generateBinPackCodes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd "$(dirname "$0")" 3 | 4 | mkdir ./bins 5 | 6 | cp -r ./iOS ./bins 7 | cp -r ./local ./bins 8 | cp -r ./py3 ./bins 9 | 10 | zip -r ./bin.zip ./bins 11 | echo $(base64 ./bin.zip) > ./bincodes.txt 12 | 13 | rm -f ./bin.zip 14 | rm -rf ./bins -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | bcrypt>=3.1.7 2 | cffi>=1.14.0 3 | colorama>=0.4.3 4 | cryptography>=2.8 5 | frida>=12.8.15 6 | frida-tools>=7.1.0 7 | paramiko>=2.7.1 8 | prompt-toolkit>=3.0.4 9 | pycparser>=2.20 10 | Pygments>=2.6.1 11 | PyNaCl>=1.3.0 12 | scp>=0.13.2 13 | six>=1.14.0 14 | tqdm>=4.43.0 15 | wcwidth>=0.1.8 16 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-string-throw": true, 4 | "no-unused-expression": true, 5 | "no-duplicate-variable": true, 6 | "curly": true, 7 | "class-name": true, 8 | "semicolon": [ 9 | true, 10 | "always" 11 | ], 12 | "triple-equals": true 13 | }, 14 | "defaultSeverity": "warning" 15 | } 16 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false // set this to true to hide the "out" folder with the compiled JS files 5 | }, 6 | "search.exclude": { 7 | "out": true // set this to false to include "out" folder in search results 8 | }, 9 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 10 | "typescript.tsc.autoDetect": "off" 11 | } -------------------------------------------------------------------------------- /src/test/suite/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from 'vscode'; 6 | // import * as myExtension from '../extension'; 7 | 8 | suite('Extension Test Suite', () => { 9 | vscode.window.showInformationMessage('Start all tests.'); 10 | 11 | test('Sample test', () => { 12 | assert.equal(-1, [1, 2, 3].indexOf(5)); 13 | assert.equal(-1, [1, 2, 3].indexOf(0)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | cache: 2 | paths: 3 | - node_modules/ 4 | 5 | before_script: 6 | - uname -a 7 | - whoami 8 | - pwd 9 | - npm -v 10 | 11 | build: 12 | artifacts: 13 | paths: 14 | - artifacts 15 | tags: 16 | - npm 17 | script: 18 | - rm -rf artifacts && mkdir artifacts 19 | - npm --registry https://registry.npm.taobao.org install 20 | - npm --registry https://registry.npm.taobao.org install typescript vsce 21 | - npm run compile 22 | - node_modules/vsce/out/vsce package -o ./artifacts/ 23 | - ls -la ./artifacts/ 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "outDir": "out", 6 | "lib": [ 7 | "es6" 8 | ], 9 | "sourceMap": true, 10 | "rootDir": "src", 11 | "strict": true /* enable all strict type-checking options */ 12 | /* Additional Checks */ 13 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 14 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 15 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 16 | }, 17 | "exclude": [ 18 | "node_modules", 19 | ".vscode-test" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /res/shell.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/bins/py3/lsdevs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # Author : Lakr Aream, AloneMonkey(frida-iOS-dump) 5 | # me 233: https://www.qaq.wiki, Twitter: @Lak233 6 | # big uncle: http://www.alonemonkey.com 7 | 8 | # 非常感谢庆总让iOS逆向的门槛降低到无脑级别 9 | 10 | import frida 11 | 12 | def get_usb_iphone(): 13 | Type = 'usb' 14 | if int(frida.__version__.split('.')[0]) < 12: 15 | Type = 'tether' 16 | device_manager = frida.get_device_manager() 17 | devices = [dev for dev in device_manager.enumerate_devices() if dev.type == Type] 18 | 19 | it = iter(devices) 20 | for item in it: 21 | print(item.id) 22 | 23 | return 24 | 25 | get_usb_iphone() -------------------------------------------------------------------------------- /res/info.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/runTest.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | 3 | import { runTests } from 'vscode-test'; 4 | 5 | async function main() { 6 | try { 7 | // The folder containing the Extension Manifest package.json 8 | // Passed to `--extensionDevelopmentPath` 9 | const extensionDevelopmentPath = path.resolve(__dirname, '../../'); 10 | 11 | // The path to test runner 12 | // Passed to --extensionTestsPath 13 | const extensionTestsPath = path.resolve(__dirname, './suite/index'); 14 | 15 | // Download VS Code, unzip it and run the integration test 16 | await runTests({ extensionDevelopmentPath, extensionTestsPath }); 17 | } catch (err) { 18 | console.error('Failed to run tests'); 19 | process.exit(1); 20 | } 21 | } 22 | 23 | main(); 24 | -------------------------------------------------------------------------------- /res/file.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /res/dir.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [10.x, 12.x] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v1 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | - run: npm ci 28 | - run: npm run compile --if-present 29 | env: 30 | CI: true 31 | -------------------------------------------------------------------------------- /res/safe.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/suite/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import * as Mocha from 'mocha'; 3 | import * as glob from 'glob'; 4 | 5 | export function run(): Promise { 6 | // Create the mocha test 7 | const mocha = new Mocha({ 8 | ui: 'tdd', 9 | }); 10 | mocha.useColors(true); 11 | 12 | const testsRoot = path.resolve(__dirname, '..'); 13 | 14 | return new Promise((c, e) => { 15 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { 16 | if (err) { 17 | return e(err); 18 | } 19 | 20 | // Add files to the test suite 21 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); 22 | 23 | try { 24 | // Run the mocha test 25 | mocha.run(failures => { 26 | if (failures > 0) { 27 | e(new Error(`${failures} tests failed.`)); 28 | } else { 29 | c(); 30 | } 31 | }); 32 | } catch (err) { 33 | e(err); 34 | } 35 | }); 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /res/password.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/log.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/kill.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/ports.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/ios.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/reload.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/debug.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/package.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ], 16 | "outFiles": [ 17 | "${workspaceFolder}/out/**/*.js" 18 | ], 19 | "preLaunchTask": "${defaultBuildTask}" 20 | }, 21 | { 22 | "name": "Extension Tests", 23 | "type": "extensionHost", 24 | "request": "launch", 25 | "runtimeExecutable": "${execPath}", 26 | "args": [ 27 | "--extensionDevelopmentPath=${workspaceFolder}", 28 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" 29 | ], 30 | "outFiles": [ 31 | "${workspaceFolder}/out/test/**/*.js" 32 | ], 33 | "preLaunchTask": "${defaultBuildTask}" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /res/connect.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/pid.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/location.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/id.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/download.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/exchange.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/upload.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/bins/py3/obtainAppLocation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # obtainAppLocation.py 6 | # iOSreExtension 7 | # 8 | # Created by Lakr Aream on 3/6/20. 9 | # Copyright 2020 Lakr Aream. All rights reserved. 10 | # 11 | 12 | import os 13 | import sys 14 | import frida 15 | 16 | targetDeviceUDID = sys.argv[1] 17 | targetPID = int(sys.argv[2]) 18 | 19 | if (not targetPID) or (not targetDeviceUDID): 20 | print("./obtainAppLocation device_udid com.bundle.id") 21 | exit(-1) 22 | 23 | def get_usb_iphone(): 24 | Type = 'usb' 25 | if int(frida.__version__.split('.')[0]) < 12: 26 | Type = 'tether' 27 | device_manager = frida.get_device_manager() 28 | devices = [dev for dev in device_manager.enumerate_devices() if dev.type == Type] 29 | 30 | it = iter(devices) 31 | for item in it: 32 | if (item.id == targetDeviceUDID): 33 | return item 34 | print("-> iDevice Not Found") 35 | exit(-1) 36 | 37 | targetDevice = get_usb_iphone() 38 | 39 | session = targetDevice.attach(targetPID) 40 | if not session: 41 | print("-> Failed attach") 42 | exit(-1) 43 | 44 | ss = """ 45 | console.log(ObjC.classes.NSBundle.mainBundle().bundlePath().toString()) 46 | console.log(ObjC.classes.NSProcessInfo.processInfo().environment().objectForKey_("HOME").toString()) 47 | """ 48 | 49 | script = session.create_script(ss) 50 | script.load() 51 | -------------------------------------------------------------------------------- /res/pass.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/start.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/create.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/delete.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/bins/py3/fastSpawn.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # 5 | # fastSpawn.py 6 | # iOSreExtension 7 | # 8 | # Created by Lakr Aream on 3/6/20. 9 | # Copyright 2020 Lakr Aream. All rights reserved. 10 | # 11 | 12 | import os 13 | import sys 14 | import frida 15 | import subprocess 16 | 17 | targetDeviceUDID = sys.argv[1] 18 | targetNameOrBundleID = sys.argv[2] 19 | 20 | def get_usb_iphone(): 21 | Type = 'usb' 22 | if int(frida.__version__.split('.')[0]) < 12: 23 | Type = 'tether' 24 | device_manager = frida.get_device_manager() 25 | devices = [dev for dev in device_manager.enumerate_devices() if dev.type == Type] 26 | 27 | it = iter(devices) 28 | for item in it: 29 | if (item.id == targetDeviceUDID): 30 | return item 31 | print("-> iDevice Not Found") 32 | exit(-1) 33 | 34 | targetDevice = get_usb_iphone() 35 | 36 | def open_target_app(device, name_or_bundleid): 37 | 38 | bundle_identifier = '' 39 | for application in device.enumerate_applications(): 40 | if name_or_bundleid == application.identifier or name_or_bundleid == application.name: 41 | bundle_identifier = application.identifier 42 | break 43 | 44 | # nope! 45 | # os.system("frida -f " + bundle_identifier + " --device " + targetDeviceUDID + " --no-pause") 46 | p = subprocess.Popen(["frida", "-f", bundle_identifier, "--device", targetDeviceUDID, "--no-pause"]) 47 | try: 48 | p.wait(3) 49 | except subprocess.TimeoutExpired: 50 | p.kill() 51 | 52 | open_target_app(targetDevice, targetNameOrBundleID) -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # http://iosre.com/t/vs/16450/ 2 | 3 | ## 1.2.18 4 | 5 | - npm security update 6 | 7 | ## 1.2.16 8 | 9 | - Update for iproxy 2.0.3 10 | 11 | ## 1.2.15 12 | 13 | - Update for iproxy 2.0.3 14 | 15 | ## 1.2.14 16 | 17 | - Deprecated frida-iOS-dump and changed to bagbak 18 | - Match the version from local and remotes 19 | 20 | ## 1.2.10 21 | 22 | - Security Update - CVE-2020-7598 23 | 24 | ## 1.2.9 25 | 26 | - Better command name 27 | 28 | ## 1.2.8 29 | 30 | - App files location now cached 31 | 32 | ### 1.2.7 33 | 34 | - Fixed a bug when loading device config for the first time 35 | 36 | ### 1.2.6 37 | 38 | - Fixed a bug caused by me when forgetting to save file 39 | 40 | ### 1.2.5 41 | 42 | - Fixed a bug when changing ssh password 43 | - Make our requirements.txt clean 44 | 45 | ### 1.2.4 46 | 47 | - Fixed lldb session failed to attach 48 | 49 | ### 1.2.3 50 | 51 | - A better solution when vscode doesnt support editing downloaded file 52 | 53 | ### 1.2.2 54 | 55 | - Support remote file editing and upload changes 56 | - Add command extension.iOSreAction-replaceFile 57 | 58 | ### 1.2.1 59 | 60 | - Support non-frida spawn application 61 | 62 | ### 1.2.0 63 | 64 | - Integrated file manager based on ssh 65 | 66 | ### 1.1.9 67 | 68 | - Bug fixes and improvements 69 | - Add "Obtain App Location" function 70 | - Update binpack payload 71 | 72 | ### 1.1.3 73 | 74 | - Prevent history to be record in termianl shared history 75 | 76 | ### 1.1.2 77 | 78 | - Fix problem if your device only allow one ssh session 79 | - Add "Shutdown All iProxy" and "Add iProxy" 80 | - Fix a crash if your ssh takes too long to finish jobs -------------------------------------------------------------------------------- /res/icon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/terminate.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/copy.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/bundle.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/xcode.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/passr.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/app.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 11 | 17 | 27 | 28 | -------------------------------------------------------------------------------- /res/pig.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/bins/py3/lsapps.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # Author : Lakr Aream, AloneMonkey(frida-iOS-dump) 5 | # me 233: https://www.qaq.wiki, Twitter: @Lak233 6 | # big uncle: http://www.alonemonkey.com 7 | 8 | # 非常感谢庆总让iOS逆向的门槛降低到无脑级别 9 | 10 | import os 11 | import sys 12 | import frida 13 | import base64 14 | import zlib, struct 15 | 16 | # Cpoied from @CodeColorist 17 | def encode(buf, width, height): 18 | """ buf: must be bytes or a bytearray in Python3.x, 19 | a regular string in Python2.x. 20 | """ 21 | 22 | width_byte_4 = width * 4 23 | raw_data = b''.join( 24 | b'\x00' + buf[span:span + width_byte_4] 25 | for span in range(0, (height - 1) * width_byte_4, width_byte_4) 26 | ) 27 | 28 | def png_pack(png_tag, data): 29 | chunk_head = png_tag + data 30 | return (struct.pack("!I", len(data)) + 31 | chunk_head + 32 | struct.pack("!I", 0xFFFFFFFF & zlib.crc32(chunk_head))) 33 | 34 | return b''.join([ 35 | b'\x89PNG\r\n\x1a\n', 36 | png_pack(b'IHDR', struct.pack("!2I5B", width, height, 8, 6, 0, 0, 0)), 37 | png_pack(b'IDAT', zlib.compress(raw_data, 9)), 38 | png_pack(b'IEND', b'')]) 39 | 40 | def tobase64Uri(icon): 41 | if not icon: 42 | return None 43 | 44 | assert icon.rowstride == icon.width * 4 45 | buf = encode(icon.pixels, icon.width, icon.height) 46 | return 'data:image/png;base64,' + base64.b64encode(buf).decode('ascii') 47 | 48 | if (len(sys.argv) < 2): 49 | print("-> ./lsapps.py [iDevices UDID]") 50 | exit(-1) 51 | 52 | if (len(sys.argv) > 2): 53 | print("-> ./lsapps.py [iDevices UDID]x1") 54 | exit(-1) 55 | 56 | def get_usb_iphone(): 57 | Type = 'usb' 58 | if int(frida.__version__.split('.')[0]) < 12: 59 | Type = 'tether' 60 | device_manager = frida.get_device_manager() 61 | devices = [dev for dev in device_manager.enumerate_devices() if dev.type == Type] 62 | 63 | it = iter(devices) 64 | for item in it: 65 | if (item.id == sys.argv[1]): 66 | return item 67 | print("-> iDevice Not Found") 68 | exit(-1) 69 | 70 | vdev = get_usb_iphone() 71 | try: 72 | applications = vdev.enumerate_applications() 73 | except Exception as e: 74 | sys.exit('-> Failed to enumerate applications: %s' % e) 75 | 76 | ita = iter(applications) 77 | 78 | for app in ita: 79 | smallicon = tobase64Uri(app.get_small_icon()) 80 | formatter = str(app.name) + "|" + str(app.identifier) + "|" + str(app.pid) + "|" + str(smallicon) 81 | print(formatter) 82 | 83 | -------------------------------------------------------------------------------- /res/rocket.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iOSreExtension 2 | 3 | A fast and elegant extension for VSCode used for iOSre projects. 4 | 5 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Co2333/iOSreExtension/pulls) 6 | [![Platform](https://img.shields.io/badge/Platform-%20macOS%20-brightgreen.svg)](https://github.com/Co2333/iOSreExtension/projects/1) 7 | 8 | 9 | #### [Open In VSC Market Place](https://marketplace.visualstudio.com/items?itemName=Lakr233.wikiqaqiosre) 10 | 11 | ## Recommended Packages to Install with 12 | 13 | - Huacat Pink Theme 14 | - [xia0LLDB](https://github.com/4ch12dy/xia0LLDB) 15 | 16 | ## Contributor 17 | 18 | Contributor in this project may not show in commit history due to sync with my private GitLab instance for CI/CD operations, but will be listed here. 19 | 20 | - [@Lakr233](https://twitter.com/Lakr233) 21 | - [onewayticket255](https://github.com/onewayticket255) 22 | - [@Anonymous](https://twitter.com/wang_liangc) 23 | 24 | ## Features 25 | 26 | A powerfull tool for iOSre projects, but must be some tall to ride or you will panic your device running some you dont know shell command. With great power comes great responsibility, just like what we are doing with root/kernel permission. If you really did to panic your deivce, 🎉, navigate to issue tab and lets have a talk. 27 | 28 | ![Hi](https://github.com/Co2333/iOSreExtension/raw/master/images/main.png) 29 | 30 | - [x] Multiple iOS device management 31 | - [x] Save device configurations 32 | - [x] Applications management - launch, debug, decrypt... 33 | - [x] Obtain applications information 34 | - [x] Remote file management over SSH 35 | - [x] Remote file editing 36 | - [x] Some useful tools like copy device information, install deb packages... 37 | 38 | ## Requirements 39 | 40 | There are some tools that you need to install on your own listed below. Again, must be some tall to ride 🐎. 41 | 42 | - Xcode command line tools (Swift runtime and developer image is required) 43 | - Frida (both on macOS with pip & iOS with deb package from build.frida.re) 44 | - NEWEST libimobiledevice, iproxy (installed with brew from source) 45 | - sshpass 46 | - node js and bagbak (make sure to upgrade to newest version [Learn More](https://github.com/ChiChou/bagbak/issues/45)) 47 | - python3 and pip3 with requirements located at [requirements.txt](./requirements.txt) 48 | 49 | 50 | Command line tips are below, remember to download [requirements.txt](./requirements.txt) and install Xcode CLI on your own. 51 | 52 | - ```brew uninstall --ignore-dependencies libimobiledevice usbmuxd``` 53 | - ```brew install -v --HEAD --build-from-source usbmuxd libimobiledevice``` 54 | - ```brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb``` 55 | - ```pip3 install -r ./requirements.txt``` 56 | - ```brew install nodejs && npm install -g bagbak``` 57 | 58 | If you failed to build libimobiledevice or usbmuxd, try to reinstall libplist from source. [Learn More](https://github.com/Co2333/iOSreExtension/issues/10) 59 | 60 | - ```git clone https://github.com/libimobiledevice/libplist.git``` 61 | - ```cd libplist``` 62 | - ```./autogen.sh --prefix=/opt/local --without-cython``` 63 | - ```make && sudo make install``` 64 | 65 | To build libplist, you may want to install Xcode CommandLine Tool first along with some pre-requirements. 66 | 67 | -> If you want to develop this extension, clone to somewhere else then ~/.vscode otherwise it would be replaced by VSC market place automatically and our binpack would be messed. 68 | 69 | ## Extension Settings 70 | 71 | There should be none confuguration hiding away from GUI so go and select that camera then you will find out. 72 | 73 | ## Road Maps 74 | 75 | Check out our GitHub Project page for help-wanted features. 76 | 77 | 2020-05-20 Lakr Aream 78 | -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import { iDeviceNodeProvider} from './iDeviceConnections'; 3 | import { ToolboxNodeProvider} from './iDeviceToolbox'; 4 | import { ApplicationNodeProvider } from './iDeviceApplications'; 5 | import { LKutils } from './Utils'; 6 | import { execSync } from 'child_process'; 7 | import { LKBootStrap } from './LKBootstrap'; 8 | import { iDevices } from './iDevices'; 9 | import { FileItem, FileSystemNodeProvider } from './iDeviceFileSystem'; 10 | import { read } from 'fs'; 11 | import { stringify } from 'querystring'; 12 | 13 | export function activate(context: vscode.ExtensionContext) { 14 | 15 | console.log('Bootstraping "wiki.qaq.iosre" extension!'); 16 | 17 | let cp = context.globalStoragePath; 18 | LKutils.shared.execute("mkdir -p \'" + cp + "\'"); 19 | LKutils.shared.setStoragePath(context.globalStoragePath); 20 | let ret = execSync("cd ~ && echo $(pwd)"); 21 | LKutils.shared.setUserHome(ret.toString()); 22 | LKBootStrap.shared.ensureLocalBins(cp); 23 | 24 | iDeviceNodeProvider.init(); 25 | ToolboxNodeProvider.init(); 26 | ApplicationNodeProvider.init(); 27 | FileSystemNodeProvider.init(); 28 | 29 | context.subscriptions.push(vscode.commands.registerCommand('iDeviceSelect', (deviceObject) => { 30 | iDeviceNodeProvider.nodeProvider.performSelector(deviceObject); 31 | })); 32 | context.subscriptions.push(vscode.commands.registerCommand('ToolboxCalled', (ToolObject) => { 33 | ToolboxNodeProvider.nodeProvider.performSelector(ToolObject); 34 | })); 35 | context.subscriptions.push(vscode.commands.registerCommand('ApplicationSelected', (AppObject) => { 36 | ApplicationNodeProvider.nodeProvider.performSelector(AppObject); 37 | })); 38 | context.subscriptions.push(vscode.commands.registerCommand('iFileSelected', (FileObject) => { 39 | FileSystemNodeProvider.nodeProvider.performSelector(FileObject); 40 | })); 41 | 42 | let disposable1 = vscode.commands.registerCommand('extension.iOSreAction-ShowVersion', () => { 43 | vscode.window.showInformationMessage("I dont know lol"); 44 | }); 45 | context.subscriptions.push(disposable1); 46 | 47 | let disposable2 = vscode.commands.registerCommand('extension.iOSreAction-replaceFile', () => { 48 | 49 | let path = vscode.window.activeTextEditor?.document.uri.path; 50 | if (path === undefined || path === "") { 51 | vscode.window.showWarningMessage("No file being opened"); 52 | return; 53 | } 54 | let blockpath = path; 55 | 56 | let readRecord = LKutils.shared.readKeyPairValue(path); 57 | if (readRecord === "" || readRecord === undefined) { 58 | vscode.window.showWarningMessage("Could not find record for this file, operation aborted"); 59 | return; 60 | } 61 | 62 | let deviceUDID = ""; 63 | let terminater = 0; 64 | let targetLocation = ""; 65 | let charset = readRecord.split(""); 66 | for (let i = 0; i < readRecord.length; i++) { 67 | let c = charset[i]; 68 | if (c === "|") { 69 | terminater = i; 70 | break; 71 | } 72 | deviceUDID += c; 73 | } 74 | targetLocation = readRecord.substring(terminater + 1, readRecord.length); 75 | if (!targetLocation.startsWith("/") || targetLocation === "") { 76 | vscode.window.showWarningMessage("Target location " + targetLocation + " invaild, operation aborted"); 77 | return; 78 | } 79 | if (iDevices.shared.getDevice()?.udid !== deviceUDID) { 80 | vscode.window.showWarningMessage("Selected device mismatch, operation aborted"); 81 | return; 82 | } 83 | 84 | vscode.window.showInformationMessage("Upload and replace will save your file first", "Contunie", "Cancel").then((str) => { 85 | if (str !== "Contunie") { 86 | return; 87 | } 88 | vscode.window.activeTextEditor?.document.save(); 89 | if (iDevices.shared.getDevice()?.udid !== deviceUDID) { 90 | vscode.window.showWarningMessage("Selected device mismatch, operation aborted"); 91 | return; 92 | } 93 | FileSystemNodeProvider.nodeProvider._fso_replace(blockpath, targetLocation); 94 | }); 95 | 96 | }); 97 | context.subscriptions.push(disposable2); 98 | 99 | } 100 | 101 | // this method is called when your extension is deactivated 102 | export function deactivate() {} 103 | -------------------------------------------------------------------------------- /src/Utils.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import * as fs from 'fs'; 3 | 4 | export class LKutils { 5 | 6 | public static shared = new LKutils(); 7 | public storagePath: string | undefined; 8 | public userHome: String | undefined; 9 | 10 | constructor() { } 11 | 12 | public setStoragePath(location: string | undefined) { 13 | console.log("[i] setStoragePath called with: " + location); 14 | if (this.storagePath !== undefined) { 15 | vscode.window.showErrorMessage("storagePath Already Exists"); 16 | return; 17 | } 18 | if (location === undefined) { 19 | if (this.userHome === undefined) { 20 | vscode.window.showErrorMessage("No where to save docs"); 21 | } 22 | this.storagePath = (this.userHome as string) + "/iOSre"; 23 | return; 24 | } 25 | this.storagePath = location; 26 | } 27 | 28 | public setUserHome(location: string) { 29 | console.log("[i] setUserHome called with: " + location); 30 | if (this.userHome !== undefined) { 31 | vscode.window.showErrorMessage("userHome Already Exists"); 32 | return; 33 | } 34 | this.userHome = location; 35 | } 36 | 37 | public execute(cmd: string): Promise { 38 | var promise = new Promise(resolve => { 39 | const cp = require('child_process'); 40 | cp.exec(cmd, (err: string, stdout: string, stderr: string) => { 41 | if (err) { 42 | vscode.window.showErrorMessage("EXECUTE_COMMAND_ERROR -> stderr:" + stderr + " -> stdout:" + stdout + " -> whenExec:" + cmd + " ==> Install dependency may solve the problem."); 43 | } 44 | resolve(stdout); 45 | }); 46 | }); 47 | return promise; 48 | } 49 | 50 | public python(executable: string, arg: string): Promise { 51 | var promise = new Promise(resolve => { 52 | const cp = require('child_process'); 53 | if (executable.startsWith("\'")) { 54 | cp.exec("python3 " + executable + " " + arg, (err: string, stdout: string, stderr: string) => { 55 | if (err) { 56 | vscode.window.showErrorMessage("EXECUTE_PYTHON_ERROR -> stderr:" + stderr + " -> stdout:" + stdout + " -> whenExec:" + executable + " " + arg + " ==> Install dependency may solve the problem."); 57 | } 58 | resolve(stdout); 59 | }); 60 | } else { 61 | cp.exec("python3 \'" + executable + "\' " + arg, (err: string, stdout: string, stderr: string) => { 62 | if (err) { 63 | vscode.window.showErrorMessage("EXECUTE_PYTHON_ERROR -> stderr:" + stderr + " -> stdout:" + stdout + " -> whenExec:" + executable + " " + arg + " ==> Install dependency may solve the problem."); 64 | } 65 | resolve(stdout); 66 | }); 67 | } 68 | }); 69 | return promise; 70 | } 71 | 72 | // '"KEY"':'"VALUE" 73 | public saveKeyPairValue(key: string, val: string) { 74 | if (!fs.existsSync(this.storagePath as string)) { 75 | fs.mkdirSync(this.storagePath as string); 76 | } 77 | const jsonFile = (this.storagePath as string) + "/envs.json"; 78 | if (!fs.existsSync(jsonFile)) { 79 | fs.closeSync(fs.openSync(jsonFile, 'w')); 80 | } 81 | console.log("[i] Write key pair value: " + key + " " + val); // + " to " + jsonFile); 82 | let read = fs.readFileSync(jsonFile, 'utf8'); 83 | if (read === "") { 84 | let papapa = {"" : ""}; 85 | let json = JSON.stringify(papapa); 86 | fs.writeFileSync(jsonFile, json, 'utf8'); 87 | read = fs.readFileSync(jsonFile, 'utf8'); 88 | } 89 | let readJson = JSON.parse(read); 90 | readJson[key] = val; 91 | var json = JSON.stringify(readJson); 92 | fs.writeFileSync(jsonFile, json, 'utf8'); 93 | } 94 | 95 | public readKeyPairValue(key: string): string { 96 | if (!fs.existsSync(this.storagePath as string)) { 97 | fs.mkdirSync(this.storagePath as string); 98 | } 99 | const jsonFile = (this.storagePath as string) + "/envs.json"; 100 | if (!fs.existsSync(jsonFile)) { 101 | fs.closeSync(fs.openSync(jsonFile, 'w')); 102 | } 103 | let read = fs.readFileSync(jsonFile, 'utf8'); 104 | if (read === "") { 105 | let papapa = {"" : ""}; 106 | let json = JSON.stringify(papapa); 107 | fs.writeFileSync(jsonFile, json, 'utf8'); 108 | read = fs.readFileSync(jsonFile, 'utf8'); 109 | } 110 | let readJson = JSON.parse(read); 111 | let ret = readJson[key]; 112 | console.log("[i] Read key pair value: " + key + " " + ret); // + " from " + jsonFile); 113 | return ret; 114 | } 115 | 116 | public makeid(howlong: Number): string { 117 | var result = ''; 118 | var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 119 | var charactersLength = characters.length; 120 | for ( var i = 0; i < howlong; i++ ) { 121 | result += characters.charAt(Math.floor(Math.random() * charactersLength)); 122 | } 123 | return result; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/iDevices.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import * as iDeviceDeps from './iDeviceConnections'; 3 | 4 | import { LKutils } from './Utils'; 5 | import { ToolboxNodeProvider } from './iDeviceToolbox'; 6 | import { iDeviceNodeProvider } from './iDeviceConnections'; 7 | import { ApplicationNodeProvider } from './iDeviceApplications'; 8 | import { FileSystemNodeProvider, FileItem } from './iDeviceFileSystem'; 9 | 10 | import { writeFileSync } from 'fs'; 11 | import { execSync, exec, ChildProcess } from 'child_process'; 12 | 13 | // tslint:disable-next-line: class-name 14 | export class iDevices { 15 | 16 | public static shared: iDevices = new iDevices(); 17 | private selectedDevice: iDeviceDeps.iDeviceItem | null = null; 18 | 19 | constructor() { 20 | 21 | } 22 | 23 | public setDevice(devObject: iDeviceDeps.iDeviceItem | null) { 24 | if (this.selectedDevice === devObject) { 25 | console.log("[i] this.selectedDevice === devObject"); 26 | return; 27 | } 28 | if (this.selectedDevice?.udid === devObject?.udid) { 29 | console.log("[i] this.selectedDevice?.udid === devObject?.udid"); 30 | this.bootstrapDeviceConfig(); 31 | return; 32 | } 33 | if (devObject?.udid === undefined || devObject.udid === null || devObject.udid === "") { 34 | return; 35 | } 36 | this.selectedDevice = devObject; 37 | this.bootstrapDeviceConfig(); 38 | this.reloadDevice(); 39 | const vdev = devObject as iDeviceDeps.iDeviceItem; 40 | if (devObject === null) { 41 | console.log("[E] iDevice Selection Invalid"); 42 | vscode.window.showErrorMessage("setDevice (null)"); 43 | return; 44 | } 45 | console.log("[*] User selected device: " + devObject.udid); 46 | vscode.window.showInformationMessage("Selected device: " + devObject.udid.substring(0, 16).toUpperCase() + " +"); 47 | } 48 | 49 | public getDevice(): iDeviceDeps.iDeviceItem | null { 50 | return this.selectedDevice; 51 | } 52 | 53 | public bootstrapDeviceConfig() { 54 | let device = this.selectedDevice; 55 | if (device === undefined || device === null) { 56 | return; 57 | } 58 | device.iSSH_devicePort = Number(LKutils.shared.readKeyPairValue(device.udid + "iSSH_devicePort")); 59 | device.iSSH_mappedPort = Number(LKutils.shared.readKeyPairValue(device.udid + "iSSH_mappedPort")); 60 | device.iSSH_password = LKutils.shared.readKeyPairValue(device.udid + "iSSH_password"); 61 | 62 | // VAILD THIS CONFIG FIRST 63 | if (isNaN(device.iSSH_devicePort) || device.iSSH_devicePort < 1 || device.iSSH_devicePort > 65533) { 64 | device.iSSH_devicePort = 22; 65 | LKutils.shared.saveKeyPairValue(device.udid + "iSSH_devicePort", "22"); 66 | } 67 | if (isNaN(device.iSSH_mappedPort) || device.iSSH_mappedPort < 1 || device.iSSH_mappedPort > 65533) { 68 | device.iSSH_mappedPort = 2222; 69 | LKutils.shared.saveKeyPairValue(device.udid + "iSSH_mappedPort", "2222"); 70 | } 71 | if (device.iSSH_password === "") { 72 | device.iSSH_password = "alpine"; 73 | LKutils.shared.saveKeyPairValue(device.udid + "iSSH_password", "alpine"); 74 | } 75 | } 76 | 77 | private reloadDevice() { 78 | ApplicationNodeProvider.nodeProvider.refresh(); 79 | ToolboxNodeProvider.nodeProvider.refresh(); 80 | FileSystemNodeProvider.nodeProvider.refresh(); 81 | } 82 | 83 | public executeOnDevice(cmd: string): string { 84 | if (this.selectedDevice === undefined) { 85 | vscode.window.showErrorMessage("No device selected"); 86 | return ""; 87 | } 88 | let selection = this.selectedDevice as iDeviceDeps.iDeviceItem; 89 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 90 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 91 | writeFileSync(passpath, selection.iSSH_password); 92 | let terminalCommands: Array = []; 93 | terminalCommands.push(" export SSHPASSWORD=$(cat \'" + passpath + "\')"); 94 | terminalCommands.push(" rm -f \'" + passpath + "\'"); 95 | terminalCommands.push(" ssh-keygen -R \"[127.0.0.1]:" + selection.iSSH_mappedPort + "\" &> /dev/null"); 96 | terminalCommands.push(" sshpass -p $SSHPASSWORD ssh -oStrictHostKeyChecking=no -p " + String(selection.iSSH_mappedPort) + " root@127.0.0.1 \'" + cmd + "\'"); 97 | let bashScript = ""; 98 | let bashpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 99 | terminalCommands.forEach((cmd) => { 100 | bashScript += "\n"; 101 | bashScript += cmd; 102 | }); 103 | writeFileSync(bashpath, bashScript, 'utf8'); 104 | let realCmd = "/bin/bash -C \'" + bashpath + "\' && exit"; 105 | let executeObject = execSync(realCmd); 106 | return executeObject.toString(); 107 | } 108 | 109 | public executeOnDeviceAsync(cmd: string): ChildProcess | undefined { 110 | // console.log("[W] executeOnDeviceAsync may cause executionLock errors!"); 111 | if (this.selectedDevice === undefined) { 112 | vscode.window.showErrorMessage("No device selected"); 113 | return; 114 | } 115 | // while (iDevices.executionLock) { } 116 | // iDevices.executionLock = true; 117 | let selection = this.selectedDevice as iDeviceDeps.iDeviceItem; 118 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 119 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 120 | writeFileSync(passpath, selection.iSSH_password); 121 | let terminalCommands: Array = []; 122 | terminalCommands.push(" export SSHPASSWORD=$(cat \'" + passpath + "\')"); 123 | // terminalCommands.push(" rm -f \'" + passpath + "\'"); 124 | terminalCommands.push(" ssh-keygen -R \"[127.0.0.1]:" + selection.iSSH_mappedPort + "\" &> /dev/null"); 125 | terminalCommands.push(" sshpass -p $SSHPASSWORD ssh -oStrictHostKeyChecking=no -p " + String(selection.iSSH_mappedPort) + " root@127.0.0.1 \'" + cmd + "\'"); 126 | let bashScript = ""; 127 | let bashpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 128 | terminalCommands.forEach((cmd) => { 129 | bashScript += "\n"; 130 | bashScript += cmd; 131 | }); 132 | writeFileSync(bashpath, bashScript, 'utf8'); 133 | let realCmd = "/bin/bash -C \'" + bashpath + "\'"; 134 | let executeObject = exec(realCmd); 135 | // iDevices.executionLock = false; 136 | return executeObject; 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wikiqaqiosre", 3 | "publisher": "Lakr233", 4 | "repository": "https://github.com/Co2333/iOSreExtension", 5 | "displayName": "iOSre Extension", 6 | "description": "A fast and elegant VSCode extension used for iOSre projects. (READ README BEFORE INSTALL)", 7 | "license": "MIT", 8 | "version": "1.2.18", 9 | "icon": "images/icon.png", 10 | "engines": { 11 | "vscode": "^1.43.0" 12 | }, 13 | "categories": [ 14 | "Other" 15 | ], 16 | "activationEvents": [ 17 | "onView:iosreIDtabSectioniDevices" 18 | ], 19 | "main": "./out/extension.js", 20 | "contributes": { 21 | "commands": [ 22 | { 23 | "command": "extension.iOSreAction-ShowVersion", 24 | "title": "iOSre - Action - ShowVersion" 25 | }, 26 | { 27 | "command": "extension.iOSreAction-replaceFile", 28 | "title": "iOSre - FileCommand - Replace Remote File With Curren Opened File" 29 | }, 30 | { 31 | "command": "iosreIDtabSectioniDevices.refreshEntry", 32 | "title": "Refresh", 33 | "icon": { 34 | "light": "res/reload.svg", 35 | "dark": "res/reload.svg" 36 | } 37 | }, 38 | { 39 | "command": "iosreIDtabSectionApplications.refreshEntry", 40 | "title": "Refresh", 41 | "icon": { 42 | "light": "res/reload.svg", 43 | "dark": "res/reload.svg" 44 | } 45 | }, 46 | { 47 | "command": "iosreIDtabSectionFileSystem.refreshEntry", 48 | "title": "Refresh", 49 | "icon": { 50 | "light": "res/reload.svg", 51 | "dark": "res/reload.svg" 52 | } 53 | }, 54 | { 55 | "command": "iosreIDtabSectionFileSystem.create", 56 | "title": "iOSre - FileCommand - 0 - New Folder", 57 | "icon": { 58 | "light": "res/create.svg", 59 | "dark": "res/create.svg" 60 | } 61 | }, 62 | { 63 | "command": "iosreIDtabSectionFileSystem.download", 64 | "title": "iOSre - FileCommand - 1 - Downlaod", 65 | "icon": { 66 | "light": "res/download.svg", 67 | "dark": "res/download.svg" 68 | } 69 | }, 70 | { 71 | "command": "iosreIDtabSectionFileSystem.upload", 72 | "title": "iOSre - FileCommand - 2 - Upload", 73 | "icon": { 74 | "light": "res/upload.svg", 75 | "dark": "res/upload.svg" 76 | } 77 | }, 78 | { 79 | "command": "iosreIDtabSectionFileSystem.delete", 80 | "title": "iOSre - FileCommand - 3 - Delete", 81 | "icon": { 82 | "light": "res/delete.svg", 83 | "dark": "res/delete.svg" 84 | } 85 | }, 86 | { 87 | "command": "iosreIDtabSectionFileSystem.replace", 88 | "title": "iOSre - FileCommand - 4 - Replace", 89 | "icon": { 90 | "light": "res/exchange.svg", 91 | "dark": "res/exchange.svg" 92 | } 93 | } 94 | ], 95 | "viewsContainers": { 96 | "activitybar": [ 97 | { 98 | "id": "iosreIDtabbarEntry", 99 | "title": "iOSre", 100 | "icon": "res/icon.svg" 101 | } 102 | ] 103 | }, 104 | "views": { 105 | "iosreIDtabbarEntry": [ 106 | { 107 | "id": "iosreIDtabSectioniDevices", 108 | "name": "iDevices", 109 | "when": "" 110 | }, 111 | { 112 | "id": "iosreIDtabSectionApplications", 113 | "name": "Applications", 114 | "when": "" 115 | }, 116 | { 117 | "id": "iosreIDtabSectionFileSystem", 118 | "name": "FileSystem", 119 | "when": "" 120 | }, 121 | { 122 | "id": "iosreIDtabSectionToolboxs", 123 | "name": "Toolbox", 124 | "when": "" 125 | } 126 | ] 127 | }, 128 | "menus": { 129 | "view/title": [ 130 | { 131 | "command": "iosreIDtabSectioniDevices.refreshEntry", 132 | "when": "view == iosreIDtabSectioniDevices", 133 | "group": "navigation" 134 | }, 135 | { 136 | "command": "iosreIDtabSectionApplications.refreshEntry", 137 | "when": "view == iosreIDtabSectionApplications", 138 | "group": "navigation" 139 | }, 140 | { 141 | "command": "iosreIDtabSectionFileSystem.refreshEntry", 142 | "when": "view == iosreIDtabSectionFileSystem", 143 | "group": "navigation" 144 | } 145 | ], 146 | "view/item/context": [ 147 | { 148 | "command": "iosreIDtabSectionFileSystem.create", 149 | "when": "view == iosreIDtabSectionFileSystem", 150 | "group": "inline" 151 | }, 152 | { 153 | "command": "iosreIDtabSectionFileSystem.download", 154 | "when": "view == iosreIDtabSectionFileSystem", 155 | "group": "inline" 156 | }, 157 | { 158 | "command": "iosreIDtabSectionFileSystem.upload", 159 | "when": "view == iosreIDtabSectionFileSystem", 160 | "group": "inline" 161 | }, 162 | { 163 | "command": "iosreIDtabSectionFileSystem.delete", 164 | "when": "view == iosreIDtabSectionFileSystem", 165 | "group": "inline" 166 | }, 167 | { 168 | "command": "iosreIDtabSectionFileSystem.replace", 169 | "when": "view == iosreIDtabSectionFileSystem", 170 | "group": "inline" 171 | } 172 | ] 173 | } 174 | }, 175 | "scripts": { 176 | "vscode:prepublish": "npm run compile", 177 | "compile": "tsc -p ./", 178 | "watch": "tsc -watch -p ./", 179 | "pretest": "npm run compile", 180 | "test": "node ./out/test/runTest.js" 181 | }, 182 | "devDependencies": { 183 | "@types/glob": "^7.1.1", 184 | "@types/mocha": "^5.2.7", 185 | "@types/node": "^12.12.35", 186 | "@types/vscode": "^1.43.0", 187 | "glob": "^7.1.6", 188 | "mocha": "^6.2.3", 189 | "tslint": "^5.20.1", 190 | "typescript": "^3.8.3", 191 | "vscode-test": "^1.3.0" 192 | }, 193 | "dependencies": { 194 | "adm-zip": "^0.4.14" 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /res/error.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/iDeviceToolbox.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import { join } from 'path'; 3 | import { LKutils } from './Utils'; 4 | import { iDevices } from './iDevices'; 5 | import { iDeviceItem, iDeviceNodeProvider } from './iDeviceConnections'; 6 | import { writeFileSync } from 'fs'; 7 | import { url } from 'inspector'; 8 | 9 | 10 | export class ToolItem extends vscode.TreeItem { 11 | 12 | constructor( 13 | public readonly label: string, 14 | private version: string, 15 | public readonly collapsibleState: vscode.TreeItemCollapsibleState 16 | ) { 17 | super(label, collapsibleState); 18 | this.iconPath = this.getToolIcon(label); 19 | } 20 | 21 | private getToolIcon(name: String): vscode.Uri { 22 | if (name === "Copy UDID" || name === "Copy ECID") { 23 | return vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'copy.svg')); 24 | } else if (name === "sbreload" || name === "ldrestart") { 25 | return vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'reload.svg')); 26 | } else if (name === "Safemode") { 27 | return vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'safe.svg')); 28 | } else if (name === "Shutdown iProxy") { 29 | return vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'kill.svg')); 30 | } else if (name === "Add iProxy") { 31 | return vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'connect.svg')); 32 | } else if (name === "Install deb") { 33 | return vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'package.svg')); 34 | } else { 35 | return vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'ios.svg')); 36 | } 37 | } 38 | 39 | command = { 40 | title: this.label, 41 | command: 'ToolboxCalled', 42 | tooltip: this.label, 43 | arguments: [ 44 | this, 45 | ] 46 | }; 47 | 48 | } 49 | 50 | export class ToolboxNodeProvider implements vscode.TreeDataProvider { 51 | 52 | public static tools = ["Copy UDID", "Copy ECID", "Install deb", "sbreload", "ldrestart", "Safemode", "Shutdown iProxy", "Add iProxy"]; 53 | public static nodeProvider: ToolboxNodeProvider; 54 | 55 | public static init() { 56 | const np = new ToolboxNodeProvider(); 57 | vscode.window.registerTreeDataProvider('iosreIDtabSectionToolboxs', np); 58 | this.nodeProvider = np; 59 | } 60 | 61 | public performSelector(toolObject: ToolItem) { 62 | if (iDevices.shared.getDevice() === null) { 63 | vscode.window.showErrorMessage("iDevice not selected"); 64 | return; 65 | } 66 | const vdev = iDevices.shared.getDevice() as iDeviceItem; 67 | if (toolObject.label === "Copy UDID") { 68 | vscode.window.showInformationMessage("UDID Copied + " + vdev?.udid.substring(0, 8) + "..."); 69 | vscode.env.clipboard.writeText(vdev?.udid); 70 | return; 71 | } 72 | if (toolObject.label === "Copy ECID") { 73 | vscode.window.showInformationMessage("ECID Copied + " + vdev?.ecid + "..."); 74 | vscode.env.clipboard.writeText(vdev?.ecid); 75 | return; 76 | } 77 | if (toolObject.label === "Install deb") { 78 | const options: vscode.OpenDialogOptions = { 79 | canSelectMany: false, 80 | canSelectFolders: false, 81 | canSelectFiles: true, 82 | openLabel: 'deb pls', 83 | filters: { 84 | 'DEBIAN Package': ['deb'] 85 | } 86 | }; 87 | vscode.window.showOpenDialog(options).then((uri) => { 88 | if (uri === undefined || uri === null) { 89 | return; 90 | } 91 | let selection = iDevices.shared.getDevice() as iDeviceItem; 92 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 93 | let terminal = vscode.window.createTerminal("Install DEB"); 94 | terminal.show(); 95 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 96 | writeFileSync(passpath, selection.iSSH_password); 97 | terminal.show(); 98 | let script = "#!/bin/bash\n"; 99 | let items = []; 100 | items.push(" export SSHPASSWORD=$(cat \'" + passpath + "\')"); 101 | items.push(" rm -f \'" + passpath + "\'"); 102 | items.push(" ssh-keygen -R \"[127.0.0.1]:" + selection.iSSH_mappedPort + "\" &> /dev/null"); 103 | items.push(" sshpass -p $SSHPASSWORD ssh -oStrictHostKeyChecking=no -p " + selection.iSSH_mappedPort + " root@127.0.0.1 \'rm -rf /var/mobile/Media/DEBIAN && mkdir -p /var/mobile/Media/DEBIAN\'"); 104 | uri.forEach((sel) => { 105 | items.push(" sshpass -p $SSHPASSWORD scp -oStrictHostKeyChecking=no -r -P" + selection.iSSH_mappedPort + " \"" + sel.path + "\" \"root@127.0.0.1:/var/mobile/Media/DEBIAN\""); 106 | }); 107 | items.push(" sshpass -p $SSHPASSWORD ssh -oStrictHostKeyChecking=no -p " + selection.iSSH_mappedPort + " root@127.0.0.1 \'dpkg -i /var/mobile/Media/DEBIAN/*.deb\'"); 108 | items.forEach((line) => { 109 | script += line + "\n"; 110 | }); 111 | let scriptpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 112 | writeFileSync(scriptpath, script); 113 | terminal.sendText(" chmod +x \"" + scriptpath + "\""); 114 | terminal.sendText(" \"" + scriptpath + "\""); 115 | }); 116 | return; 117 | } 118 | if (toolObject.label === "sbreload") { 119 | iDeviceNodeProvider.nodeProvider.ensureiProxy(vdev); 120 | iDevices.shared.executeOnDevice("sbreload"); 121 | return; 122 | } 123 | if (toolObject.label === "ldrestart") { 124 | iDeviceNodeProvider.nodeProvider.ensureiProxy(vdev); 125 | iDevices.shared.executeOnDevice("( ldrestart & )"); 126 | return; 127 | } 128 | if (toolObject.label === "Safemode") { 129 | iDeviceNodeProvider.nodeProvider.ensureiProxy(vdev); 130 | iDevices.shared.executeOnDevice("killall -SEGV SpringBoard"); 131 | return; 132 | } 133 | if (toolObject.label === "Shutdown iProxy") { 134 | Object.keys(iDeviceNodeProvider.iProxyPool).forEach(element => { 135 | let child = iDeviceNodeProvider.iProxyPool[element]!; 136 | child.kill(); 137 | }); 138 | iDeviceNodeProvider.iProxyPool = {}; 139 | iDeviceNodeProvider.nodeProvider.refresh(); 140 | LKutils.shared.execute("killall iproxy"); // last thing because if some stderr job will kill over refresh 141 | return; 142 | } 143 | if (toolObject.label === "Add iProxy") { 144 | vscode.window.showInputBox({prompt: "Which port to map?"}).then((val => { 145 | let port = Number(val); 146 | let device = iDevices.shared.getDevice()!; 147 | let terminal = vscode.window.createTerminal("iProxy => " + String(port) + device.udid); 148 | terminal.show(); 149 | terminal.sendText(" iproxy " + String(port) + " " + String(port) + " -u " + device.udid); 150 | terminal.sendText(" exit"); 151 | })); 152 | return; 153 | } 154 | } 155 | 156 | private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); 157 | readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; 158 | 159 | getTreeItem(element: ToolItem): vscode.TreeItem { 160 | return element; 161 | } 162 | 163 | refresh() { 164 | ToolboxNodeProvider.nodeProvider._onDidChangeTreeData.fire(); 165 | } 166 | 167 | getChildren(element?: ToolItem | undefined): vscode.ProviderResult { 168 | 169 | let dev = iDevices.shared.getDevice(); 170 | if (dev === undefined || dev === null) { 171 | return [new ToolItem("NO SELECTION", "", vscode.TreeItemCollapsibleState.None)]; 172 | } 173 | 174 | let ret: Array = []; 175 | ret.push(new ToolItem("SELECTED " + dev.udid.substr(0, 8).toLocaleUpperCase(), "", vscode.TreeItemCollapsibleState.None)); 176 | ToolboxNodeProvider.tools.forEach((str) => { 177 | ret.push(new ToolItem(str, "", vscode.TreeItemCollapsibleState.None)); 178 | }); 179 | return ret; 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /src/bins/py3/dump_oem.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # Author : Lakr Aream, AloneMonkey(frida-iOS-dump) 5 | # me 233: https://www.qaq.wiki, Twitter: @Lak233 6 | # big uncle: http://www.alonemonkey.com 7 | 8 | # 非常感谢庆总让iOS逆向的门槛降低到无脑级别 9 | 10 | 11 | import sys 12 | import codecs 13 | import frida 14 | import threading 15 | import os 16 | import shutil 17 | import time 18 | import argparse 19 | import tempfile 20 | import subprocess 21 | import re 22 | 23 | import paramiko 24 | from paramiko import SSHClient 25 | from scp import SCPClient 26 | from tqdm import tqdm 27 | import traceback 28 | 29 | script_dir = os.path.dirname(os.path.realpath(__file__)) 30 | 31 | DUMP_JS = os.path.join(script_dir, 'dump_oem.js') 32 | 33 | # ./dump_oem.py UDIDXXXXX TARGET.BUNDLE.ID ROOTPASSWORD PORT IPALOCATION 34 | if (len(sys.argv) != 6): 35 | print("-> this script is OEM only") 36 | exit(-1) 37 | 38 | User = 'root' 39 | Password = sys.argv[3] 40 | Host = 'localhost' 41 | Port = sys.argv[4] 42 | 43 | TEMP_DIR = tempfile.gettempdir() 44 | PAYLOAD_DIR = 'Payload' 45 | PAYLOAD_PATH = os.path.join(TEMP_DIR, PAYLOAD_DIR) 46 | file_dict = {} 47 | 48 | finished = threading.Event() 49 | 50 | 51 | def get_usb_iphone(): 52 | Type = 'usb' 53 | if int(frida.__version__.split('.')[0]) < 12: 54 | Type = 'tether' 55 | device_manager = frida.get_device_manager() 56 | devices = [dev for dev in device_manager.enumerate_devices() if dev.type == Type] 57 | it = iter(devices) 58 | for dev in it: 59 | if (dev.id == sys.argv[1]): 60 | return dev 61 | print("-> iDevice not found") 62 | exit(-1) 63 | 64 | 65 | def generate_ipa(path, display_name): 66 | ipa_filename = display_name + '.ipa' 67 | 68 | print('Generating "{}"'.format(ipa_filename)) 69 | try: 70 | app_name = file_dict['app'] 71 | 72 | for key, value in file_dict.items(): 73 | from_dir = os.path.join(path, key) 74 | to_dir = os.path.join(path, app_name, value) 75 | if key != 'app': 76 | shutil.move(from_dir, to_dir) 77 | 78 | target_dir = './' + PAYLOAD_DIR 79 | zip_args = ('zip', '-qr', os.path.join(os.getcwd(), ipa_filename), target_dir) 80 | subprocess.check_call(zip_args, cwd=TEMP_DIR) 81 | shutil.rmtree(PAYLOAD_PATH) 82 | except Exception as e: 83 | print(e) 84 | finished.set() 85 | 86 | def on_message(message, data): 87 | t = tqdm(unit='B',unit_scale=True,unit_divisor=1024,miniters=1) 88 | last_sent = [0] 89 | 90 | def progress(filename, size, sent): 91 | t.desc = os.path.basename(filename).decode("utf-8") 92 | t.total = size 93 | t.update(sent - last_sent[0]) 94 | last_sent[0] = 0 if size == sent else sent 95 | 96 | if 'payload' in message: 97 | payload = message['payload'] 98 | if 'dump' in payload: 99 | origin_path = payload['path'] 100 | dump_path = payload['dump'] 101 | 102 | scp_from = dump_path 103 | scp_to = PAYLOAD_PATH + '/' 104 | 105 | with SCPClient(ssh.get_transport(), progress = progress, socket_timeout = 60) as scp: 106 | scp.get(scp_from, scp_to) 107 | 108 | chmod_dir = os.path.join(PAYLOAD_PATH, os.path.basename(dump_path)) 109 | chmod_args = ('chmod', '655', chmod_dir) 110 | try: 111 | subprocess.check_call(chmod_args) 112 | except subprocess.CalledProcessError as err: 113 | print(err) 114 | 115 | index = origin_path.find('.app/') 116 | file_dict[os.path.basename(dump_path)] = origin_path[index + 5:] 117 | 118 | if 'app' in payload: 119 | app_path = payload['app'] 120 | 121 | scp_from = app_path 122 | scp_to = PAYLOAD_PATH + '/' 123 | with SCPClient(ssh.get_transport(), progress = progress, socket_timeout = 60) as scp: 124 | scp.get(scp_from, scp_to, recursive=True) 125 | 126 | chmod_dir = os.path.join(PAYLOAD_PATH, os.path.basename(app_path)) 127 | chmod_args = ('chmod', '755', chmod_dir) 128 | try: 129 | subprocess.check_call(chmod_args) 130 | except subprocess.CalledProcessError as err: 131 | print(err) 132 | 133 | file_dict['app'] = os.path.basename(app_path) 134 | 135 | if 'done' in payload: 136 | finished.set() 137 | t.close() 138 | 139 | def compare_applications(a, b): 140 | a_is_running = a.pid != 0 141 | b_is_running = b.pid != 0 142 | if a_is_running == b_is_running: 143 | if a.name > b.name: 144 | return 1 145 | elif a.name < b.name: 146 | return -1 147 | else: 148 | return 0 149 | elif a_is_running: 150 | return -1 151 | else: 152 | return 1 153 | 154 | 155 | def cmp_to_key(mycmp): 156 | """Convert a cmp= function into a key= function""" 157 | 158 | class K: 159 | def __init__(self, obj): 160 | self.obj = obj 161 | 162 | def __lt__(self, other): 163 | return mycmp(self.obj, other.obj) < 0 164 | 165 | def __gt__(self, other): 166 | return mycmp(self.obj, other.obj) > 0 167 | 168 | def __eq__(self, other): 169 | return mycmp(self.obj, other.obj) == 0 170 | 171 | def __le__(self, other): 172 | return mycmp(self.obj, other.obj) <= 0 173 | 174 | def __ge__(self, other): 175 | return mycmp(self.obj, other.obj) >= 0 176 | 177 | def __ne__(self, other): 178 | return mycmp(self.obj, other.obj) != 0 179 | 180 | return K 181 | 182 | 183 | def get_applications(device): 184 | try: 185 | applications = device.enumerate_applications() 186 | except Exception as e: 187 | sys.exit('Failed to enumerate applications: %s' % e) 188 | 189 | return applications 190 | 191 | 192 | def list_applications(device): 193 | applications = get_applications(device) 194 | 195 | if len(applications) > 0: 196 | pid_column_width = max(map(lambda app: len('{}'.format(app.pid)), applications)) 197 | name_column_width = max(map(lambda app: len(app.name), applications)) 198 | identifier_column_width = max(map(lambda app: len(app.identifier), applications)) 199 | else: 200 | pid_column_width = 0 201 | name_column_width = 0 202 | identifier_column_width = 0 203 | 204 | header_format = '%' + str(pid_column_width) + 's ' + '%-' + str(name_column_width) + 's ' + '%-' + str( 205 | identifier_column_width) + 's' 206 | print(header_format % ('PID', 'Name', 'Identifier')) 207 | print('%s %s %s' % (pid_column_width * '-', name_column_width * '-', identifier_column_width * '-')) 208 | line_format = '%' + str(pid_column_width) + 's ' + '%-' + str(name_column_width) + 's ' + '%-' + str( 209 | identifier_column_width) + 's' 210 | for application in sorted(applications, key=cmp_to_key(compare_applications)): 211 | if application.pid == 0: 212 | print(line_format % ('-', application.name, application.identifier)) 213 | else: 214 | print(line_format % (application.pid, application.name, application.identifier)) 215 | 216 | 217 | def load_js_file(session, filename): 218 | source = '' 219 | with codecs.open(filename, 'r', 'utf-8') as f: 220 | source = source + f.read() 221 | script = session.create_script(source) 222 | script.on('message', on_message) 223 | script.load() 224 | 225 | return script 226 | 227 | 228 | def create_dir(path): 229 | path = path.strip() 230 | path = path.rstrip('\\') 231 | if os.path.exists(path): 232 | shutil.rmtree(path) 233 | try: 234 | os.makedirs(path) 235 | except os.error as err: 236 | print(err) 237 | 238 | 239 | def open_target_app(device, name_or_bundleid): 240 | print('Start the target app {}'.format(name_or_bundleid)) 241 | 242 | pid = '' 243 | session = None 244 | display_name = '' 245 | bundle_identifier = '' 246 | for application in get_applications(device): 247 | if name_or_bundleid == application.identifier or name_or_bundleid == application.name: 248 | pid = application.pid 249 | display_name = application.name 250 | bundle_identifier = application.identifier 251 | 252 | try: 253 | if not pid: 254 | pid = device.spawn([bundle_identifier]) 255 | session = device.attach(pid) 256 | device.resume(pid) 257 | else: 258 | session = device.attach(pid) 259 | except Exception as e: 260 | print(e) 261 | 262 | return session, display_name, bundle_identifier 263 | 264 | 265 | def start_dump(session, ipa_name): 266 | print('Dumping {} to {}'.format(display_name, TEMP_DIR)) 267 | 268 | script = load_js_file(session, DUMP_JS) 269 | script.post('dump') 270 | finished.wait() 271 | 272 | generate_ipa(PAYLOAD_PATH, ipa_name) 273 | 274 | if session: 275 | session.detach() 276 | 277 | return 278 | 279 | 280 | device = get_usb_iphone() 281 | 282 | # ./dump_oem.py UDIDXXXXX TARGET.BUNDLE.ID ROOTPASSWORD PORT IPALOCATION 283 | name_or_bundleid = sys.argv[2] 284 | output_ipa = sys.argv[5] 285 | 286 | try: 287 | ssh = paramiko.SSHClient() 288 | ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 289 | ssh.connect(Host, port=Port, username=User, password=Password) 290 | 291 | create_dir(PAYLOAD_PATH) 292 | (session, display_name, bundle_identifier) = open_target_app(device, name_or_bundleid) 293 | if output_ipa is None: 294 | output_ipa = display_name 295 | output_ipa = re.sub('\.ipa$', '', output_ipa) 296 | if session: 297 | start_dump(session, output_ipa) 298 | except paramiko.ssh_exception.NoValidConnectionsError as e: 299 | print(e) 300 | exit(-4) 301 | except paramiko.AuthenticationException as e: 302 | print(e) 303 | exit(-5) 304 | except Exception as e: 305 | print('*** Caught exception: %s: %s' % (e.__class__, e)) 306 | traceback.print_exc() 307 | exit(-6) 308 | 309 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2020] [Lakr Aream] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/bins/py3/dump_oem.js: -------------------------------------------------------------------------------- 1 | Module.ensureInitialized('Foundation'); 2 | 3 | var O_RDONLY = 0; 4 | var O_WRONLY = 1; 5 | var O_RDWR = 2; 6 | var O_CREAT = 512; 7 | 8 | var SEEK_SET = 0; 9 | var SEEK_CUR = 1; 10 | var SEEK_END = 2; 11 | 12 | function allocStr(str) { 13 | return Memory.allocUtf8String(str); 14 | } 15 | 16 | function putStr(addr, str) { 17 | if (typeof addr == "number") { 18 | addr = ptr(addr); 19 | } 20 | return Memory.writeUtf8String(addr, str); 21 | } 22 | 23 | function getByteArr(addr, l) { 24 | if (typeof addr == "number") { 25 | addr = ptr(addr); 26 | } 27 | return Memory.readByteArray(addr, l); 28 | } 29 | 30 | function getU8(addr) { 31 | if (typeof addr == "number") { 32 | addr = ptr(addr); 33 | } 34 | return Memory.readU8(addr); 35 | } 36 | 37 | function putU8(addr, n) { 38 | if (typeof addr == "number") { 39 | addr = ptr(addr); 40 | } 41 | return Memory.writeU8(addr, n); 42 | } 43 | 44 | function getU16(addr) { 45 | if (typeof addr == "number") { 46 | addr = ptr(addr); 47 | } 48 | return Memory.readU16(addr); 49 | } 50 | 51 | function putU16(addr, n) { 52 | if (typeof addr == "number") { 53 | addr = ptr(addr); 54 | } 55 | return Memory.writeU16(addr, n); 56 | } 57 | 58 | function getU32(addr) { 59 | if (typeof addr == "number") { 60 | addr = ptr(addr); 61 | } 62 | return Memory.readU32(addr); 63 | } 64 | 65 | function putU32(addr, n) { 66 | if (typeof addr == "number") { 67 | addr = ptr(addr); 68 | } 69 | return Memory.writeU32(addr, n); 70 | } 71 | 72 | function getU64(addr) { 73 | if (typeof addr == "number") { 74 | addr = ptr(addr); 75 | } 76 | return Memory.readU64(addr); 77 | } 78 | 79 | function putU64(addr, n) { 80 | if (typeof addr == "number") { 81 | addr = ptr(addr); 82 | } 83 | return Memory.writeU64(addr, n); 84 | } 85 | 86 | function getPt(addr) { 87 | if (typeof addr == "number") { 88 | addr = ptr(addr); 89 | } 90 | return Memory.readPointer(addr); 91 | } 92 | 93 | function putPt(addr, n) { 94 | if (typeof addr == "number") { 95 | addr = ptr(addr); 96 | } 97 | if (typeof n == "number") { 98 | n = ptr(n); 99 | } 100 | return Memory.writePointer(addr, n); 101 | } 102 | 103 | function malloc(size) { 104 | return Memory.alloc(size); 105 | } 106 | 107 | function getExportFunction(type, name, ret, args) { 108 | var nptr; 109 | nptr = Module.findExportByName(null, name); 110 | if (nptr === null) { 111 | console.log("cannot find " + name); 112 | return null; 113 | } else { 114 | if (type === "f") { 115 | var funclet = new NativeFunction(nptr, ret, args); 116 | if (typeof funclet === "undefined") { 117 | console.log("parse error " + name); 118 | return null; 119 | } 120 | return funclet; 121 | } else if (type === "d") { 122 | var datalet = Memory.readPointer(nptr); 123 | if (typeof datalet === "undefined") { 124 | console.log("parse error " + name); 125 | return null; 126 | } 127 | return datalet; 128 | } 129 | } 130 | } 131 | 132 | var NSSearchPathForDirectoriesInDomains = getExportFunction("f", "NSSearchPathForDirectoriesInDomains", "pointer", ["int", "int", "int"]); 133 | var wrapper_open = getExportFunction("f", "open", "int", ["pointer", "int", "int"]); 134 | var read = getExportFunction("f", "read", "int", ["int", "pointer", "int"]); 135 | var write = getExportFunction("f", "write", "int", ["int", "pointer", "int"]); 136 | var lseek = getExportFunction("f", "lseek", "int64", ["int", "int64", "int"]); 137 | var close = getExportFunction("f", "close", "int", ["int"]); 138 | var remove = getExportFunction("f", "remove", "int", ["pointer"]); 139 | var access = getExportFunction("f", "access", "int", ["pointer", "int"]); 140 | var dlopen = getExportFunction("f", "dlopen", "pointer", ["pointer", "int"]); 141 | 142 | function getDocumentDir() { 143 | var NSDocumentDirectory = 9; 144 | var NSUserDomainMask = 1; 145 | var npdirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, 1); 146 | return ObjC.Object(npdirs).objectAtIndex_(0).toString(); 147 | } 148 | 149 | function open(pathname, flags, mode) { 150 | if (typeof pathname == "string") { 151 | pathname = allocStr(pathname); 152 | } 153 | return wrapper_open(pathname, flags, mode); 154 | } 155 | 156 | var modules = null; 157 | function getAllAppModules() { 158 | modules = new Array(); 159 | var tmpmods = Process.enumerateModulesSync(); 160 | for (var i = 0; i < tmpmods.length; i++) { 161 | if (tmpmods[i].path.indexOf(".app") != -1) { 162 | modules.push(tmpmods[i]); 163 | } 164 | } 165 | return modules; 166 | } 167 | 168 | var FAT_MAGIC = 0xcafebabe; 169 | var FAT_CIGAM = 0xbebafeca; 170 | var MH_MAGIC = 0xfeedface; 171 | var MH_CIGAM = 0xcefaedfe; 172 | var MH_MAGIC_64 = 0xfeedfacf; 173 | var MH_CIGAM_64 = 0xcffaedfe; 174 | var LC_SEGMENT = 0x1; 175 | var LC_SEGMENT_64 = 0x19; 176 | var LC_ENCRYPTION_INFO = 0x21; 177 | var LC_ENCRYPTION_INFO_64 = 0x2C; 178 | 179 | function pad(str, n) { 180 | return Array(n-str.length+1).join("0")+str; 181 | } 182 | 183 | function swap32(value) { 184 | value = pad(value.toString(16),8) 185 | var result = ""; 186 | for(var i = 0; i < value.length; i=i+2){ 187 | result += value.charAt(value.length - i - 2); 188 | result += value.charAt(value.length - i - 1); 189 | } 190 | return parseInt(result,16) 191 | } 192 | 193 | function dumpModule(name) { 194 | if (modules == null) { 195 | modules = getAllAppModules(); 196 | } 197 | 198 | var targetmod = null; 199 | for (var i = 0; i < modules.length; i++) { 200 | if (modules[i].path.indexOf(name) != -1) { 201 | targetmod = modules[i]; 202 | break; 203 | } 204 | } 205 | if (targetmod == null) { 206 | console.log("Cannot find module"); 207 | return; 208 | } 209 | var modbase = modules[i].base; 210 | var modsize = modules[i].size; 211 | var newmodname = modules[i].name; 212 | var newmodpath = getDocumentDir() + "/" + newmodname + ".fid"; 213 | var oldmodpath = modules[i].path; 214 | 215 | 216 | if(!access(allocStr(newmodpath),0)){ 217 | remove(allocStr(newmodpath)); 218 | } 219 | 220 | var fmodule = open(newmodpath, O_CREAT | O_RDWR, 0); 221 | var foldmodule = open(oldmodpath, O_RDONLY, 0); 222 | 223 | if (fmodule == -1 || foldmodule == -1) { 224 | console.log("Cannot open file" + newmodpath); 225 | return; 226 | } 227 | 228 | var is64bit = false; 229 | var size_of_mach_header = 0; 230 | var magic = getU32(modbase); 231 | var cur_cpu_type = getU32(modbase.add(4)); 232 | var cur_cpu_subtype = getU32(modbase.add(8)); 233 | if (magic == MH_MAGIC || magic == MH_CIGAM) { 234 | is64bit = false; 235 | size_of_mach_header = 28; 236 | }else if (magic == MH_MAGIC_64 || magic == MH_CIGAM_64) { 237 | is64bit = true; 238 | size_of_mach_header = 32; 239 | } 240 | 241 | var BUFSIZE = 4096; 242 | var buffer = malloc(BUFSIZE); 243 | 244 | read(foldmodule, buffer, BUFSIZE); 245 | 246 | var fileoffset = 0; 247 | var filesize = 0; 248 | magic = getU32(buffer); 249 | if(magic == FAT_CIGAM || magic == FAT_MAGIC){ 250 | var off = 4; 251 | var archs = swap32(getU32(buffer.add(off))); 252 | for (var i = 0; i < archs; i++) { 253 | var cputype = swap32(getU32(buffer.add(off + 4))); 254 | var cpusubtype = swap32(getU32(buffer.add(off + 8))); 255 | if(cur_cpu_type == cputype && cur_cpu_subtype == cpusubtype){ 256 | fileoffset = swap32(getU32(buffer.add(off + 12))); 257 | filesize = swap32(getU32(buffer.add(off + 16))); 258 | break; 259 | } 260 | off += 20; 261 | } 262 | 263 | if(fileoffset == 0 || filesize == 0) 264 | return; 265 | 266 | lseek(fmodule, 0, SEEK_SET); 267 | lseek(foldmodule, fileoffset, SEEK_SET); 268 | for(var i = 0; i < parseInt(filesize / BUFSIZE); i++) { 269 | read(foldmodule, buffer, BUFSIZE); 270 | write(fmodule, buffer, BUFSIZE); 271 | } 272 | if(filesize % BUFSIZE){ 273 | read(foldmodule, buffer, filesize % BUFSIZE); 274 | write(fmodule, buffer, filesize % BUFSIZE); 275 | } 276 | }else{ 277 | var readLen = 0; 278 | lseek(foldmodule, 0, SEEK_SET); 279 | lseek(fmodule, 0, SEEK_SET); 280 | while(readLen = read(foldmodule, buffer, BUFSIZE)) { 281 | write(fmodule, buffer, readLen); 282 | } 283 | } 284 | 285 | var ncmds = getU32(modbase.add(16)); 286 | var off = size_of_mach_header; 287 | var offset_cryptid = -1; 288 | var crypt_off = 0; 289 | var crypt_size = 0; 290 | var segments = []; 291 | for (var i = 0; i < ncmds; i++) { 292 | var cmd = getU32(modbase.add(off)); 293 | var cmdsize = getU32(modbase.add(off + 4)); 294 | if (cmd == LC_ENCRYPTION_INFO || cmd == LC_ENCRYPTION_INFO_64) { 295 | offset_cryptid = off + 16; 296 | crypt_off = getU32(modbase.add(off + 8)); 297 | crypt_size = getU32(modbase.add(off + 12)); 298 | } 299 | off += cmdsize; 300 | } 301 | 302 | if (offset_cryptid != -1) { 303 | var tpbuf = malloc(8); 304 | putU64(tpbuf, 0); 305 | lseek(fmodule, offset_cryptid, SEEK_SET); 306 | write(fmodule, tpbuf, 4); 307 | lseek(fmodule, crypt_off, SEEK_SET); 308 | write(fmodule, modbase.add(crypt_off), crypt_size); 309 | } 310 | 311 | close(fmodule); 312 | close(foldmodule); 313 | return newmodpath 314 | } 315 | 316 | function loadAllDynamicLibrary(app_path) { 317 | var defaultManager = ObjC.classes.NSFileManager.defaultManager(); 318 | var errorPtr = Memory.alloc(Process.pointerSize); 319 | Memory.writePointer(errorPtr, NULL); 320 | var filenames = defaultManager.contentsOfDirectoryAtPath_error_(app_path, errorPtr); 321 | for (var i = 0, l = filenames.count(); i < l; i++) { 322 | var file_name = filenames.objectAtIndex_(i); 323 | var file_path = app_path.stringByAppendingPathComponent_(file_name); 324 | if (file_name.hasSuffix_(".framework")) { 325 | var bundle = ObjC.classes.NSBundle.bundleWithPath_(file_path); 326 | if (bundle.isLoaded()) { 327 | console.log("[frida-ios-dump]: " + file_name + " has been loaded. "); 328 | } else { 329 | if (bundle.load()) { 330 | console.log("[frida-ios-dump]: Load " + file_name + " success. "); 331 | } else { 332 | console.log("[frida-ios-dump]: Load " + file_name + " failed. "); 333 | } 334 | } 335 | } else if (file_name.hasSuffix_(".bundle") || 336 | file_name.hasSuffix_(".momd") || 337 | file_name.hasSuffix_(".strings") || 338 | file_name.hasSuffix_(".appex") || 339 | file_name.hasSuffix_(".app") || 340 | file_name.hasSuffix_(".lproj") || 341 | file_name.hasSuffix_(".storyboardc")) { 342 | continue; 343 | } else { 344 | var isDirPtr = Memory.alloc(Process.pointerSize); 345 | Memory.writePointer(isDirPtr,NULL); 346 | defaultManager.fileExistsAtPath_isDirectory_(file_path, isDirPtr); 347 | if (Memory.readPointer(isDirPtr) == 1) { 348 | loadAllDynamicLibrary(file_path); 349 | } else { 350 | if (file_name.hasSuffix_(".dylib")) { 351 | var is_loaded = 0; 352 | for (var j = 0; j < modules.length; j++) { 353 | if (modules[j].path.indexOf(file_name) != -1) { 354 | is_loaded = 1; 355 | console.log("[frida-ios-dump]: " + file_name + " has been dlopen."); 356 | break; 357 | } 358 | } 359 | 360 | if (!is_loaded) { 361 | if (dlopen(allocStr(file_path.UTF8String()), 9)) { 362 | console.log("[frida-ios-dump]: dlopen " + file_name + " success. "); 363 | } else { 364 | console.log("[frida-ios-dump]: dlopen " + file_name + " failed. "); 365 | } 366 | } 367 | } 368 | } 369 | } 370 | } 371 | } 372 | 373 | function handleMessage(message) { 374 | modules = getAllAppModules(); 375 | var app_path = ObjC.classes.NSBundle.mainBundle().bundlePath(); 376 | loadAllDynamicLibrary(app_path); 377 | // start dump 378 | modules = getAllAppModules(); 379 | for (var i = 0; i < modules.length; i++) { 380 | console.log("start dump " + modules[i].path); 381 | var result = dumpModule(modules[i].path); 382 | send({ dump: result, path: modules[i].path}); 383 | } 384 | send({app: app_path.toString()}); 385 | send({done: "ok"}); 386 | recv(handleMessage); 387 | } 388 | 389 | recv(handleMessage); -------------------------------------------------------------------------------- /src/iDeviceConnections.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import { join } from 'path'; 3 | import { LKutils } from './Utils'; 4 | import { iDevices } from './iDevices'; 5 | import { ApplicationItem, ApplicationNodeProvider } from './iDeviceApplications'; 6 | import { writeFileSync } from 'fs'; 7 | import { exec, ChildProcess } from 'child_process'; 8 | import { LKBootStrap } from './LKBootstrap'; 9 | import { FileSystemNodeProvider } from './iDeviceFileSystem'; 10 | 11 | // tslint:disable-next-line: class-name 12 | export class iDeviceItem extends vscode.TreeItem { 13 | 14 | iSSH_devicePort = 22; 15 | iSSH_mappedPort = 2222; 16 | iSSH_password = "alpine"; 17 | iSSH_iProxyPID = 0; 18 | 19 | constructor( 20 | public readonly label: string, 21 | public readonly udid: string, 22 | public readonly ecid: string, 23 | public readonly isinSubContext: Boolean, 24 | public readonly collapsibleState: vscode.TreeItemCollapsibleState 25 | ) { 26 | super(label, collapsibleState); 27 | if (udid !== "") { 28 | this.tooltip = udid; 29 | } 30 | } 31 | 32 | father: iDeviceItem | undefined; 33 | 34 | iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'ios.svg')); 35 | 36 | command = { 37 | title: this.label, 38 | command: 'iDeviceSelect', 39 | tooltip: this.udid, 40 | arguments: [ 41 | this, 42 | ] 43 | }; 44 | 45 | } 46 | 47 | // tslint:disable-next-line: class-name 48 | export class iDeviceNodeProvider implements vscode.TreeDataProvider { 49 | 50 | public deviceInfoList: Array = []; // 储存udid 51 | public static nodeProvider: iDeviceNodeProvider; 52 | public static iProxyPool: {[key: string]: ChildProcess} = {}; 53 | 54 | public static init() { 55 | const np = new iDeviceNodeProvider(); 56 | vscode.window.registerTreeDataProvider('iosreIDtabSectioniDevices', np); 57 | vscode.commands.registerCommand("iosreIDtabSectioniDevices.refreshEntry", () => np.refresh()); 58 | this.nodeProvider = np; 59 | } 60 | 61 | public async performSelector(iDeviceObject: iDeviceItem) { 62 | if (!iDeviceObject.isinSubContext) { 63 | iDevices.shared.setDevice(iDeviceObject); 64 | return; 65 | } 66 | if (iDeviceObject.label.startsWith("Set devicePort:")) { 67 | vscode.window.showInputBox({prompt: "Set on device SSH port, default to 22"}).then((val => { 68 | let port = Number(val); 69 | if (port < 1) { 70 | port = 22; 71 | } 72 | LKutils.shared.saveKeyPairValue(iDeviceObject.udid + "iSSH_devicePort", String(port)); 73 | this.refresh(); 74 | iDevices.shared.bootstrapDeviceConfig(); 75 | })); 76 | return; 77 | } 78 | if (iDeviceObject.label.startsWith("Set mappedPort:")) { 79 | vscode.window.showInputBox({prompt: "Set local linker SSH port, default to 2222"}).then((val => { 80 | let port = Number(val); 81 | if (port < 1) { 82 | port = 2222; 83 | } 84 | LKutils.shared.saveKeyPairValue(iDeviceObject.udid + "iSSH_mappedPort", String(port)); 85 | this.refresh(); 86 | iDevices.shared.bootstrapDeviceConfig(); 87 | })); 88 | return; 89 | } 90 | if (iDeviceObject.label.startsWith("Set root Password")) { 91 | vscode.window.showInputBox({prompt: "Set SSH password for this device, default to alpine"}).then((val => { 92 | let pass = val; 93 | if (pass === undefined || pass === "") { 94 | pass = "alpine"; 95 | } 96 | LKutils.shared.saveKeyPairValue(iDeviceObject.udid + "iSSH_password", pass); 97 | this.refresh(); 98 | iDevices.shared.bootstrapDeviceConfig(); 99 | })); 100 | return; 101 | } 102 | if (iDeviceObject.label.startsWith("iProxy:")) { 103 | let element = iDeviceObject.father as iDeviceItem; 104 | if (iDeviceNodeProvider.iProxyPool[element.udid] === undefined) { 105 | this.ensureiProxy(element); 106 | } else { 107 | iDeviceNodeProvider.iProxyPool[element.udid].kill(); 108 | delete iDeviceNodeProvider.iProxyPool[element.udid]; 109 | } 110 | this.refresh(); 111 | iDevices.shared.bootstrapDeviceConfig(); 112 | return; 113 | } 114 | if (iDeviceObject.label.startsWith("SSH Connect")) { 115 | iDevices.shared.bootstrapDeviceConfig(); 116 | let element = iDeviceObject.father as iDeviceItem; 117 | this.ensureiProxy(element); 118 | let terminal = vscode.window.createTerminal("SSH =>" + element.label); 119 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 120 | writeFileSync(passpath, element.iSSH_password); 121 | terminal.show(); 122 | // iDevices.executionLock = true; 123 | terminal.sendText(" export SSHPASSWORD=$(cat \'" + passpath + "\')"); 124 | terminal.sendText(" rm -f \'" + passpath + "\'"); 125 | terminal.sendText(" ssh-keygen -R \"[127.0.0.1]:" + element.iSSH_mappedPort + "\" &> /dev/null"); 126 | terminal.sendText(" sshpass -p $SSHPASSWORD ssh root@127.0.0.1 -oStrictHostKeyChecking=no -p " + element.iSSH_mappedPort); 127 | // iDevices.executionLock = false; 128 | return; 129 | } 130 | } 131 | 132 | public ensureiProxy(element: iDeviceItem) { 133 | if (iDeviceNodeProvider.iProxyPool[element.udid] === undefined) { 134 | let dp = (element).iSSH_devicePort; 135 | let mp = (element).iSSH_mappedPort; 136 | console.log("[*] Starting iProxy " + mp + ":" + dp + " -u " + element.udid + " &"); 137 | let execObject = exec("iproxy " + mp + ":" + dp + " -u " + element.udid + "", (err, stdout, stderr) => { 138 | console.log(stdout + stderr); 139 | this.refresh(); 140 | }); 141 | iDeviceNodeProvider.iProxyPool[element.udid] = execObject; 142 | this.refresh(); 143 | ApplicationNodeProvider.nodeProvider.refresh(); 144 | FileSystemNodeProvider.nodeProvider.refresh(); 145 | } 146 | } 147 | 148 | private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); 149 | readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; 150 | 151 | getTreeItem(element: iDeviceItem): vscode.TreeItem { 152 | return element; 153 | } 154 | 155 | refresh() { 156 | iDeviceNodeProvider.nodeProvider._onDidChangeTreeData.fire(); 157 | } 158 | 159 | async getChildren(element?: iDeviceItem): Promise { 160 | 161 | if (element !== undefined && !(element as iDeviceItem).isinSubContext) { 162 | 163 | let device = element; 164 | device.iSSH_devicePort = Number(LKutils.shared.readKeyPairValue(device.udid + "iSSH_devicePort")); 165 | device.iSSH_mappedPort = Number(LKutils.shared.readKeyPairValue(device.udid + "iSSH_mappedPort")); 166 | device.iSSH_password = LKutils.shared.readKeyPairValue(device.udid + "iSSH_password"); 167 | 168 | // VAILD THIS CONFIG FIRST 169 | if (isNaN(device.iSSH_devicePort) || device.iSSH_devicePort < 1 || device.iSSH_devicePort > 65533) { 170 | device.iSSH_devicePort = 22; 171 | LKutils.shared.saveKeyPairValue(device.udid + "iSSH_devicePort", "22"); 172 | } 173 | if (isNaN(device.iSSH_mappedPort) || device.iSSH_mappedPort < 1 || device.iSSH_mappedPort > 65533) { 174 | device.iSSH_mappedPort = 2222; 175 | LKutils.shared.saveKeyPairValue(device.udid + "iSSH_mappedPort", "2222"); 176 | } 177 | if (device.iSSH_password === "") { 178 | device.iSSH_password = "alpine"; 179 | LKutils.shared.saveKeyPairValue(device.udid + "iSSH_password", "alpine"); 180 | } 181 | 182 | let details: Array = []; 183 | let sshp = new iDeviceItem("Set devicePort: " + device.iSSH_devicePort, device.udid, device.ecid, true, vscode.TreeItemCollapsibleState.None); 184 | sshp.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'ports.svg')); 185 | details.push(sshp); 186 | let sshpp = new iDeviceItem("Set mappedPort: " + device.iSSH_mappedPort, device.udid, device.ecid, true, vscode.TreeItemCollapsibleState.None); 187 | sshpp.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'ports.svg')); 188 | details.push(sshpp); 189 | let pass = new iDeviceItem("Set root Password ", device.udid, device.ecid, true, vscode.TreeItemCollapsibleState.None); 190 | pass.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'password.svg')); 191 | details.push(pass); 192 | let pp = new iDeviceItem("iProxy: " + device.iSSH_iProxyPID, device.udid, device.ecid, true, vscode.TreeItemCollapsibleState.None); 193 | pp.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'id.svg')); 194 | pp.father = element; 195 | details.push(pp); 196 | let ssh = new iDeviceItem("SSH Connect ", device.udid, device.ecid, true, vscode.TreeItemCollapsibleState.None); 197 | ssh.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'shell.svg')); 198 | ssh.father = element; 199 | details.push(ssh); 200 | return details; 201 | } 202 | 203 | let lsd = "\'" + LKBootStrap.shared.getBinPath() + "/bins/local/lsdevs\'"; //vscode.Uri.file(join(__filename,'..', '..' ,'src', 'bins', 'local', 'lsdevs')).path; 204 | let read = await LKutils.shared.execute(lsd); 205 | 206 | this.deviceInfoList = []; 207 | read.split("\n").forEach(element => { 208 | if (element === "") { 209 | return; 210 | } 211 | var found = false; 212 | for(var i = 0; i < this.deviceInfoList.length; i++) { 213 | if (this.deviceInfoList[i] === element) { 214 | found = true; 215 | break; 216 | } 217 | } 218 | if (!found) { 219 | this.deviceInfoList.push(element); 220 | } 221 | }); 222 | 223 | console.log("[*] Reloading device lists..."); 224 | for(var i = 0; i < this.deviceInfoList.length; i++) { 225 | console.log(" -> %s", this.deviceInfoList[i]); 226 | } 227 | let wasADevice = 0; 228 | let foundSelectedDevice: iDeviceItem | undefined; 229 | let privSelected = iDevices.shared.getDevice(); 230 | let ret: Array = []; 231 | this.deviceInfoList.forEach( 232 | item => { 233 | let elements = item.split("|"); 234 | let dev: iDeviceItem | undefined; 235 | if (elements.length === 1) { 236 | let udid = elements[0]; 237 | dev = new iDeviceItem(("ID: " + item.substring(0, 8).toUpperCase()), udid, "", false, vscode.TreeItemCollapsibleState.Expanded); 238 | ret.push(dev); 239 | } else if (elements.length === 2) { 240 | let udid = elements[0]; 241 | let ecid = elements[1]; 242 | dev = new iDeviceItem(("ID: " + item.substring(0, 8).toUpperCase()), udid, ecid, false, vscode.TreeItemCollapsibleState.Expanded); 243 | ret.push(dev); 244 | } else if (elements.length === 3) { 245 | let udid = elements[0]; 246 | let ecid = elements[1]; 247 | let name = elements[2]; 248 | dev = new iDeviceItem(name, udid, ecid, false, vscode.TreeItemCollapsibleState.Expanded); 249 | ret.push(dev); 250 | } else { 251 | return; 252 | } 253 | wasADevice += 1; 254 | if (privSelected !== null && (privSelected as iDeviceItem).udid === elements[0]) { 255 | foundSelectedDevice = dev; 256 | } 257 | // let readdevport = LKutils.shared.readKeyPairValue(dev.udid + "iSSH_devicePort"); 258 | // if (readdevport === undefined || readdevport === "" || Number(readdevport) < 1) { 259 | // dev.iSSH_devicePort = 22; 260 | // } else { 261 | // dev.iSSH_devicePort = Number(readdevport); 262 | // } 263 | // let readmapport = LKutils.shared.readKeyPairValue(dev.udid + "iSSH_mappedPort"); 264 | // if (readmapport === undefined || readmapport === "" || Number(readmapport) < 1) { 265 | // dev.iSSH_mappedPort = 2222; 266 | // } else { 267 | // dev.iSSH_mappedPort = Number(readmapport); 268 | // } 269 | // let password = LKutils.shared.readKeyPairValue(dev.udid + "iSSH_password"); 270 | // if (password === undefined || password === "") { 271 | // dev.iSSH_password = password; 272 | // } else { 273 | // dev.iSSH_password = password; 274 | // } 275 | if (iDeviceNodeProvider.iProxyPool[dev.udid] !== undefined) { 276 | dev.iSSH_iProxyPID = iDeviceNodeProvider.iProxyPool[dev.udid].pid; 277 | } 278 | } 279 | ); 280 | if (wasADevice === 0) { 281 | ret = [new iDeviceItem("No Device Connected", "", "", false, vscode.TreeItemCollapsibleState.None)]; 282 | ret[0].iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'pig.svg')); 283 | } else if (wasADevice === 1) { 284 | iDevices.shared.setDevice(ret[0]); 285 | iDevices.shared.bootstrapDeviceConfig(); 286 | } 287 | if (foundSelectedDevice === undefined && privSelected !== null) { 288 | iDevices.shared.setDevice(null); 289 | } else if (foundSelectedDevice !== undefined) { 290 | iDevices.shared.setDevice(foundSelectedDevice); 291 | iDevices.shared.bootstrapDeviceConfig(); 292 | } 293 | 294 | return Promise.resolve(ret); 295 | } 296 | 297 | } 298 | 299 | -------------------------------------------------------------------------------- /src/iDeviceFileSystem.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import { join } from 'path'; 3 | import { iDevices } from './iDevices'; 4 | import { iDeviceItem, iDeviceNodeProvider } from './iDeviceConnections'; 5 | import { LKutils } from './Utils'; 6 | import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from 'constants'; 7 | import { writeFileSync } from 'fs'; 8 | import { URL } from 'url'; 9 | import { execFileSync, execSync } from 'child_process'; 10 | 11 | export class FileItem extends vscode.TreeItem { 12 | 13 | // used for caches and future use 14 | public infoObject: {[key: string]: string} = {}; 15 | public iconPath = this.collapsibleState === vscode.TreeItemCollapsibleState.None ? join(__filename, '..', '..', 'res', 'file.svg') : join(__filename, '..', '..', 'res', 'dir.svg'); 16 | 17 | // DO NOT USE LABEL TO STORE INFOMATION 18 | // LABEL IS USED FOR USER FRIENDLY OBJECTS 19 | 20 | constructor( 21 | public label: string, // if sym link, set it 22 | public name: string, 23 | public location: string, 24 | public isLink: Boolean, 25 | public parent: FileItem | null, 26 | public readonly collapsibleState: vscode.TreeItemCollapsibleState, 27 | ) { 28 | super(label, collapsibleState); 29 | } 30 | 31 | public getExtension(): string | undefined { 32 | if (this.contextValue === "dirItems") { 33 | return undefined; 34 | } 35 | let read = this.name.split("."); 36 | if (read.length > 1) { 37 | return read.pop(); 38 | } 39 | return undefined; 40 | } 41 | 42 | public getpath(): string { 43 | if (!this.location.endsWith("/")) { 44 | this.location += "/"; 45 | } 46 | let ret = this.location + this.name; 47 | // console.log(ret); 48 | return ret; 49 | } 50 | 51 | // returns f: file, d: dir, l: link, u: unkown (maybe user friendly hints) 52 | public getType(): string { 53 | if (this.iconPath === join(__filename, '..', '..', 'res', 'file.svg')) { 54 | return "f"; 55 | } 56 | if (this.iconPath === join(__filename, '..', '..', 'res', 'dir.svg')) { 57 | return "d"; 58 | } 59 | if (this.iconPath === join(__filename, '..', '..', 'res', 'connect.svg')) { 60 | return "l"; 61 | } 62 | return "u"; 63 | } 64 | 65 | 66 | command = { 67 | title: this.label, 68 | command: 'iFileSelected', 69 | tooltip: this.getpath(), 70 | arguments: [ 71 | this, 72 | ] 73 | }; 74 | 75 | } 76 | 77 | 78 | 79 | export class FileSystemNodeProvider implements vscode.TreeDataProvider{ 80 | 81 | public static nodeProvider: FileSystemNodeProvider; 82 | private workingRoot: string = "/"; 83 | 84 | constructor( 85 | 86 | ){ 87 | 88 | } 89 | 90 | public static vetoList = [ 91 | "", 92 | " ", 93 | "/", 94 | "/Developer", 95 | "/User", 96 | "/boot", 97 | "/etc", 98 | "/private", 99 | "/usr", 100 | "/Library", 101 | "/lib", 102 | "/sbin", 103 | "/var", 104 | "/Applications", 105 | "/System", 106 | "/bin", 107 | "/dev", 108 | "/mnt", 109 | ]; 110 | 111 | public static init() { 112 | const np = new FileSystemNodeProvider(); 113 | vscode.window.registerTreeDataProvider('iosreIDtabSectionFileSystem', np); 114 | vscode.commands.registerCommand("iosreIDtabSectionFileSystem.refreshEntry", () => np.refresh()); 115 | this.nodeProvider = np; 116 | vscode.commands.registerCommand("iosreIDtabSectionFileSystem.download", (item) => np.fso_download(item)); 117 | vscode.commands.registerCommand("iosreIDtabSectionFileSystem.upload", (item) => np.fso_upload(item)); 118 | vscode.commands.registerCommand("iosreIDtabSectionFileSystem.delete", (item) => np.fso_delete(item)); 119 | vscode.commands.registerCommand("iosreIDtabSectionFileSystem.replace", (item) => np.fso_replace(item)); 120 | vscode.commands.registerCommand("iosreIDtabSectionFileSystem.create", (item) => np.fso_newfolder(item)); 121 | } 122 | 123 | private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); 124 | readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; 125 | 126 | getTreeItem(element: FileItem): vscode.TreeItem { 127 | return element; 128 | } 129 | 130 | refresh(): void { 131 | this._onDidChangeTreeData.fire(); 132 | } 133 | 134 | public pushToDir(whereto: string) { 135 | this.workingRoot = whereto; 136 | this.refresh(); 137 | } 138 | 139 | async getChildren(element?: FileItem | undefined): Promise { 140 | 141 | let device = iDevices.shared.getDevice(); 142 | if (device === undefined || device === null) { 143 | let ret = new FileItem("No Device Selected", "No Device Selected", "No Device Selected", false, null, vscode.TreeItemCollapsibleState.None); 144 | ret.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'pig.svg')).path; 145 | return [ret]; 146 | } 147 | if (iDeviceNodeProvider.iProxyPool[device!.udid] === undefined) { 148 | let ret = new FileItem("iProxy Required", "iProxy Required", "iProxy Required", false, null, vscode.TreeItemCollapsibleState.None); 149 | ret.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'pig.svg')).path; 150 | return [ret]; 151 | } 152 | 153 | // root items 154 | if (!element) { 155 | let ret = []; 156 | ret.push(new FileItem("working root: " + this.workingRoot, "", this.workingRoot, false, null, vscode.TreeItemCollapsibleState.Expanded)); 157 | if (this.workingRoot !== "/") { 158 | let back = new FileItem("Go back to /", "", "", false, null, vscode.TreeItemCollapsibleState.None); 159 | back.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'rocket.svg')).path; 160 | ret.unshift(back); 161 | } 162 | return ret; 163 | } 164 | 165 | let read = iDevices.shared.executeOnDevice("ls -la \"" + element.getpath() + "\""); 166 | return this.lswrapper(element, read); 167 | 168 | } 169 | 170 | public lswrapper(object: FileItem, read: string): Array { 171 | let line = read.split("\n"); 172 | let ret: Array = []; 173 | line.forEach((str) => { 174 | if (!str.startsWith("d") && !str.startsWith("-") && !str.startsWith("l")) { 175 | return; 176 | } 177 | if (str.endsWith(" .") || str.endsWith(" ..")) { 178 | return; 179 | } 180 | if (str.split(" -> ").length > 2) { 181 | return; // 淦 爬 *see possible data feed below* 182 | } 183 | 184 | while (str.endsWith("\r") || str.endsWith("\r\n") || str.endsWith("\n")) { 185 | str = str.substring(0, str.length - 1); 186 | } 187 | 188 | let inSpace = false; 189 | let inSpaceCount = 0; 190 | let prefixLenth = 0; 191 | let finalPrefixLenth = 0; 192 | let charset = str.split(""); 193 | charset.forEach((char) => { 194 | if (inSpace && char === ' ') { 195 | prefixLenth += 1; 196 | return; 197 | } 198 | if (!inSpace && char === ' ') { 199 | prefixLenth += 1; 200 | inSpaceCount += 1; 201 | inSpace = true; 202 | return; 203 | } 204 | inSpace = false; 205 | prefixLenth += 1; 206 | if (inSpaceCount > 7 && finalPrefixLenth === 0) { 207 | finalPrefixLenth = prefixLenth; 208 | } 209 | }); 210 | 211 | let name = str.substring(finalPrefixLenth - 1, str.length); 212 | if (str.startsWith("l")) { 213 | let cut = name.split(" -> "); 214 | if (cut.length < 1) { 215 | return; // ???????? 216 | } 217 | let item = new FileItem(name, cut[0], object.getpath(), true, object, vscode.TreeItemCollapsibleState.None); 218 | item.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'connect.svg')).path; 219 | ret.push(item); 220 | return; 221 | } 222 | 223 | if (str.startsWith("d")) { 224 | let item = new FileItem(name, name, object.getpath(), true, object, vscode.TreeItemCollapsibleState.Collapsed); 225 | ret.push(item); 226 | return; 227 | } 228 | 229 | let item = new FileItem(name, name, object.getpath(), true, object, vscode.TreeItemCollapsibleState.None); 230 | ret.push(item); 231 | return; // Id love to 232 | }); 233 | return ret; 234 | } 235 | 236 | // fso stands for File System Operation 237 | private lastSelected: string = ""; 238 | public performSelector(fileObject: FileItem) { 239 | if (fileObject.label === "Go back to /") { 240 | FileSystemNodeProvider.nodeProvider.pushToDir("/"); 241 | return; 242 | } 243 | if (this.lastSelected === fileObject.getpath() && (fileObject.getType() !== "u")) { 244 | vscode.window.showInformationMessage("Copy file/dir path or Open file/dir?", "Cancel", "Open", "Copy Path").then((selection) => { 245 | if (selection === "Cancel" || selection === undefined) { 246 | return; 247 | } 248 | if (selection === "Copy Path") { 249 | vscode.env.clipboard.writeText(fileObject.getpath()); 250 | return; 251 | } 252 | if (fileObject.getType() === "l") { 253 | vscode.window.showWarningMessage("Open file/dir does not support sym links"); 254 | return; 255 | } 256 | // TODO 257 | if (fileObject.getType() !== "f") { 258 | vscode.window.showWarningMessage("Open file/dir only support regular file"); 259 | return; 260 | } 261 | // Download to temp dir 262 | let sessionID = LKutils.shared.makeid(10); 263 | let sessionLocation = LKutils.shared.storagePath + "/" + sessionID; 264 | execSync("mkdir -p \"" + sessionLocation + "\""); 265 | this._fso_download(fileObject, sessionLocation); 266 | // Wait for terminal 267 | vscode.window.onDidCloseTerminal((isthisone) => { 268 | let check = "Download => " + fileObject.getpath(); 269 | if (isthisone.name === check) { 270 | // Write file info to key pair value key:udid+filepath value:localFilePath 271 | let fullpath = sessionLocation + "/" + fileObject.name; 272 | // Open file send to work space 273 | if (fileObject.getType() === "f") { 274 | let uri: vscode.Uri = vscode.Uri.parse(fullpath); 275 | // try { 276 | vscode.workspace.openTextDocument(uri).then((whatisthis) => { 277 | vscode.window.showTextDocument(whatisthis, 1, true).then((e) => { 278 | vscode.window.showInformationMessage("After editing file, press command + shit + P and type replace to upload changes to iDevices"); 279 | }); 280 | }); 281 | // } catch (error) { 282 | // console.log(error); 283 | // } 284 | // save info if we need to upload it again 285 | let device = iDevices.shared.getDevice(); 286 | if (device === undefined || device === null) { 287 | return; 288 | } 289 | LKutils.shared.saveKeyPairValue(uri.path, device.udid + "|" + fileObject.location); 290 | vscode.window.showInformationMessage("Does the file open? If not, try to open it with another app", "Open", "Cancel").then((str) => { 291 | if (str === "Open") { 292 | let terminal = vscode.window.createTerminal("Open => " + uri.path); 293 | terminal.show(); 294 | terminal.sendText("open \"" + uri.path + "\""); 295 | } 296 | }); 297 | } else if (fileObject.getType() === "d") { 298 | // TODO 299 | } 300 | // Dont forget to resiger command of upload and replace 301 | } 302 | }); 303 | 304 | }); 305 | return; 306 | } 307 | this.lastSelected = fileObject.getpath(); 308 | } 309 | 310 | public _fso_download(remoteFileObject: FileItem, toLocation: string) { 311 | let selection = iDevices.shared.getDevice() as iDeviceItem; 312 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 313 | let terminal = vscode.window.createTerminal("Download => " + remoteFileObject.getpath()); 314 | terminal.show(); 315 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 316 | writeFileSync(passpath, selection.iSSH_password); 317 | terminal.show(); 318 | terminal.sendText(" export SSHPASSWORD=$(cat \'" + passpath + "\')"); 319 | terminal.sendText(" rm -f \'" + passpath + "\'"); 320 | terminal.sendText(" ssh-keygen -R \"[127.0.0.1]:" + selection.iSSH_mappedPort + "\" &> /dev/null"); 321 | terminal.sendText(" sshpass -p $SSHPASSWORD scp -oStrictHostKeyChecking=no -r -P" + selection.iSSH_mappedPort + " \"root@127.0.0.1:" + remoteFileObject.getpath() + "\" \"" + toLocation + "/\""); 322 | terminal.sendText("exit"); 323 | } 324 | 325 | public fso_download(fileObject: FileItem) { 326 | if (fileObject.getpath() === undefined || fileObject.getpath() === "") { 327 | return; 328 | } 329 | const options: vscode.OpenDialogOptions = { 330 | canSelectMany: false, 331 | canSelectFolders: true, 332 | canSelectFiles: false, 333 | openLabel: 'Put Here', 334 | filters: { 335 | 'All files': ['*'] 336 | } 337 | }; 338 | vscode.window.showOpenDialog(options).then((uri) => { 339 | if (uri === undefined || uri === null || uri.length !== 1) { 340 | return; 341 | } 342 | let path = uri.shift()?.path; 343 | if (path === undefined || path === null || path === "") { 344 | return; 345 | } 346 | this._fso_download(fileObject, path); 347 | }); 348 | 349 | } 350 | 351 | public fso_upload(fileObject: FileItem) { 352 | if (fileObject.getpath() === undefined || fileObject.getpath() === "") { 353 | return; 354 | } 355 | if (fileObject.getType() !== "d") { 356 | vscode.window.showWarningMessage("Upload only available for directories"); 357 | return; 358 | } 359 | const options: vscode.OpenDialogOptions = { 360 | canSelectMany: true, 361 | canSelectFolders: true, 362 | canSelectFiles: true, 363 | openLabel: 'Put Here', 364 | filters: { 365 | 'All files': ['*'] 366 | } 367 | }; 368 | vscode.window.showOpenDialog(options).then((uri) => { 369 | if (uri === undefined || uri === null) { 370 | return; 371 | } 372 | let selection = iDevices.shared.getDevice() as iDeviceItem; 373 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 374 | let terminal = vscode.window.createTerminal("Upload => " + fileObject.getpath()); 375 | terminal.show(); 376 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 377 | writeFileSync(passpath, selection.iSSH_password); 378 | terminal.show(); 379 | let script = "#!/bin/bash\n"; 380 | let items = []; 381 | items.push(" export SSHPASSWORD=$(cat \'" + passpath + "\')"); 382 | items.push(" rm -f \'" + passpath + "\'"); 383 | items.push(" ssh-keygen -R \"[127.0.0.1]:" + selection.iSSH_mappedPort + "\" &> /dev/null"); 384 | uri.forEach((sel) => { 385 | items.push(" sshpass -p $SSHPASSWORD scp -oStrictHostKeyChecking=no -r -P" + selection.iSSH_mappedPort + " \"" + sel.path + "\" \"root@127.0.0.1:" + fileObject.getpath() + "/\""); 386 | }); 387 | items.push(" exit"); 388 | items.forEach((line) => { 389 | script += line + "\n"; 390 | }); 391 | let scriptpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 392 | writeFileSync(scriptpath, script); 393 | terminal.sendText(" chmod +x \"" + scriptpath + "\""); 394 | terminal.sendText(" \"" + scriptpath + "\""); 395 | // let sleep = 0; 396 | // while (sleep < 1000000) { 397 | // sleep += 1; 398 | // } 399 | terminal.sendText(" exit"); 400 | vscode.window.onDidCloseTerminal((isthisone) => { 401 | if (isthisone.name === "Upload => " + fileObject.getpath()) { 402 | FileSystemNodeProvider.nodeProvider.refresh(); 403 | } 404 | }); 405 | 406 | }); 407 | 408 | } 409 | 410 | public fso_delete(fileObject: FileItem) { 411 | let path = fileObject.getpath(); 412 | if (path === undefined || path === "") { 413 | return; 414 | } 415 | if (FileSystemNodeProvider.vetoList.includes(path)) { 416 | vscode.window.showWarningMessage("This file is protected or required by system: " + path); 417 | return; 418 | } 419 | vscode.window.showInformationMessage("Are you sure? The delete operation can not be undo on: " + path, "Contunie", "Stop").then((str) => { 420 | if (str !== "Contunie") { 421 | return; 422 | } 423 | iDevices.shared.executeOnDevice("rm -rf \"" + path + "\""); 424 | this.refresh(); 425 | }); 426 | } 427 | 428 | public _fso_replace(localFile: string, remoteFileLocationNotWithName: string) { 429 | let selection = iDevices.shared.getDevice() as iDeviceItem; 430 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 431 | let terminal = vscode.window.createTerminal("Replace => " + remoteFileLocationNotWithName); 432 | terminal.show(); 433 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 434 | writeFileSync(passpath, selection.iSSH_password); 435 | terminal.show(); 436 | terminal.sendText(" export SSHPASSWORD=$(cat \'" + passpath + "\')"); 437 | terminal.sendText(" rm -f \'" + passpath + "\'"); 438 | terminal.sendText(" ssh-keygen -R \"[127.0.0.1]:" + selection.iSSH_mappedPort + "\" &> /dev/null"); 439 | terminal.sendText(" sshpass -p $SSHPASSWORD scp -oStrictHostKeyChecking=no -r -P" + selection.iSSH_mappedPort + " \"" + localFile + "\" \"root@127.0.0.1:" + remoteFileLocationNotWithName + "\""); 440 | terminal.sendText(" exit"); 441 | vscode.window.onDidCloseTerminal((isthisone) => { 442 | if (isthisone.name === "Replace => " + remoteFileLocationNotWithName) { 443 | FileSystemNodeProvider.nodeProvider.refresh(); 444 | } 445 | }); 446 | } 447 | 448 | public fso_replace(fileObject: FileItem) { 449 | let path = fileObject.getpath(); 450 | if (path === undefined || path === "") { 451 | return; 452 | } 453 | if (FileSystemNodeProvider.vetoList.includes(path)) { 454 | vscode.window.showWarningMessage("This file is protected or required by system: " + path); 455 | return; 456 | } 457 | const options: vscode.OpenDialogOptions = { 458 | canSelectMany: false, 459 | canSelectFolders: true, 460 | canSelectFiles: true, 461 | openLabel: 'Put Here', 462 | filters: { 463 | 'All files': ['*'] 464 | } 465 | }; 466 | iDevices.shared.executeOnDevice("rm -rf \"" + path + "\""); 467 | vscode.window.showOpenDialog(options).then((uri) => { 468 | if (uri === undefined || uri === null || uri.length !== 1) { 469 | return; 470 | } 471 | let uploadpath = uri.shift()?.path; 472 | if (uploadpath === undefined || uploadpath === null || uploadpath === "") { 473 | return; 474 | } 475 | 476 | this._fso_replace(uploadpath, fileObject.location); 477 | 478 | }); 479 | 480 | } 481 | 482 | public fso_newfolder(fileObject: FileItem) { 483 | if (fileObject.getpath() === undefined || fileObject.getpath() === "") { 484 | return; 485 | } 486 | if (fileObject.getType() !== "d") { 487 | vscode.window.showWarningMessage("Create new folder only available under directories"); 488 | return; 489 | } 490 | vscode.window.showInputBox({prompt: "New folder's name here, press ESC to cancel."}).then((val => { 491 | if (val === undefined || val === null || val === " " || val.includes("/")) { 492 | return; 493 | } 494 | let fullpath = fileObject.location + "/" + val; 495 | iDevices.shared.executeOnDevice("mkdir \"" + fullpath + "\""); 496 | this.refresh(); 497 | })); 498 | } 499 | 500 | /* 501 | 1 2 3 4 5 6 7 8 9 502 | drwxr-xr-x 28 root wheel 896 Mar 5 05:35 . 503 | drwxr-xr-x 28 root wheel 896 Mar 5 05:35 .. 504 | -rw-r--r-- 1 root wheel 0 Dec 5 13:22 .Trashes 505 | drwx------ 2 root wheel 64 Dec 5 13:08 .ba 506 | ---------- 1 root admin 0 Dec 5 13:09 .file 507 | drwx------ 2 root wheel 64 Dec 5 13:08 .mb 508 | -rwxr----- 1 root wheel 0 Feb 26 20:35 .mount_rw 509 | drwxr-xr-x 2 root wheel 64 Feb 27 21:12 AppleInternal 510 | drwxr-xr-x 28 root wheel 896 Feb 28 15:46 sbin 511 | lrwxr-xr-x 1 root admin 11 Dec 5 13:22 var -> private/var 512 | -rw-r--r-- 1 qaq staff 0 Mar 7 19:29 hi hi hi 513 | -rw-r--r-- 1 qaq staff 0 Mar 7 19:31 hi -> hi //草 口吐芬芳 514 | lrwxr-xr-x 1 qaq staff 13 Mar 7 19:32 ln -> ln -> ./filelist.py // 再见 这种用户咱们就放弃吧 515 | */ 516 | 517 | } 518 | -------------------------------------------------------------------------------- /src/iDeviceApplications.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import { join } from 'path'; 3 | import { LKutils } from './Utils'; 4 | import { iDevices } from './iDevices'; 5 | import { iDeviceItem, iDeviceNodeProvider } from './iDeviceConnections'; 6 | import { writeFileSync } from 'fs'; 7 | import { execSync, exec } from 'child_process'; 8 | import { LKBootStrap } from './LKBootstrap'; 9 | import { FileSystemNodeProvider} from './iDeviceFileSystem'; 10 | 11 | 12 | // tslint:disable-next-line: class-name 13 | export class ApplicationItem extends vscode.TreeItem { 14 | 15 | constructor( 16 | public readonly label: string, 17 | public isinSubContext: Boolean, 18 | public infoObject: Array, 19 | public readonly collapsibleState: vscode.TreeItemCollapsibleState 20 | ) { 21 | super(label, collapsibleState); 22 | this.tooltip = infoObject[1]; 23 | this.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'bundle.svg')); 24 | 25 | if (infoObject.length > 3) { 26 | let tryImageUri = vscode.Uri.parse(infoObject[3]); 27 | if (tryImageUri !== undefined && tryImageUri !== null) { 28 | this.iconPath = tryImageUri; 29 | } 30 | } 31 | } 32 | 33 | command = { 34 | title: this.label, 35 | command: 'ApplicationSelected', 36 | arguments: [ 37 | this, 38 | ] 39 | }; 40 | 41 | } 42 | 43 | // tslint:disable-next-line: class-name 44 | export class ApplicationNodeProvider implements vscode.TreeDataProvider { 45 | 46 | public deviceList: Array = []; // 储存udid 47 | public static nodeProvider: ApplicationNodeProvider; 48 | 49 | public static init() { 50 | const np = new ApplicationNodeProvider(); 51 | vscode.window.registerTreeDataProvider('iosreIDtabSectionApplications', np); 52 | vscode.commands.registerCommand("iosreIDtabSectionApplications.refreshEntry", () => np.refresh()); 53 | this.nodeProvider = np; 54 | } 55 | 56 | private hasOpenedLLDBSession: {[key: string]: string} = {}; // device + bundleid 57 | public performSelector(ApplicationObject: ApplicationItem) { 58 | if (!ApplicationObject.isinSubContext) { 59 | return; 60 | } 61 | if (ApplicationObject.label === "- Decrypt & Dump") { 62 | vscode.window.showInformationMessage("Continue Dump " + ApplicationObject.infoObject[0] + " ?", "Yes", "No").then((str) => { 63 | if (str !== "Yes") { 64 | return; 65 | } 66 | let selection = iDevices.shared.getDevice() as iDeviceItem; 67 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 68 | let terminal = vscode.window.createTerminal("Decrypt => " + ApplicationObject.infoObject[1]); 69 | terminal.show(); 70 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 71 | writeFileSync(passpath, selection.iSSH_password); 72 | terminal.show(); 73 | let terminalCommands: Array = []; 74 | terminalCommands.push(" echo 'If any thing went wrong, try npm install -g bagbak'"); 75 | terminalCommands.push(" mkdir -p ~/Documents/iOSre"); 76 | terminalCommands.push(" rm -rf ~/Documents/iOSre/" + ApplicationObject.infoObject[1]); 77 | terminalCommands.push(" rm -f ~/Documents/iOSre/" + ApplicationObject.infoObject[1] + ".ipa"); 78 | terminalCommands.push(" bagbak -f --uuid " + String(selection.udid) + " --output " + "~/Documents/iOSre/" + ApplicationObject.infoObject[1] + " " + ApplicationObject.infoObject[1]); 79 | let bashScript = ""; 80 | let bashpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 81 | terminalCommands.forEach((cmd) => { 82 | bashScript += "\n"; 83 | bashScript += cmd; 84 | }); 85 | writeFileSync(bashpath, bashScript, 'utf8'); 86 | terminal.sendText(" /bin/bash -C \'" + bashpath + "\'"); 87 | vscode.window.onDidCloseTerminal((isthisone) => { 88 | if (isthisone.name === "Decrypt => " + ApplicationObject.infoObject[1]) { 89 | vscode.window.showInformationMessage("Decrypt " + ApplicationObject.infoObject[0] + " has finished", "open").then((selection) => { 90 | if (selection === "open") { 91 | LKutils.shared.execute("open ~/Documents/iOSre/" + ApplicationObject.infoObject[1]); 92 | } 93 | }); 94 | } 95 | }); 96 | }); 97 | return; 98 | } 99 | if (ApplicationObject.label === "- Frida Spawn") { 100 | let selection = iDevices.shared.getDevice() as iDeviceItem; 101 | let fastSpawn = "\'" + LKBootStrap.shared.getBinPath() + "/bins/py3/fastSpawn.py\'"; 102 | let args = selection.udid + " " + ApplicationObject.infoObject[1]; 103 | LKutils.shared.python(fastSpawn, args).then((_) => { 104 | this.refresh(); 105 | }); 106 | return; 107 | } 108 | if (ApplicationObject.label === "- Fast Open") { 109 | vscode.window.showInformationMessage("Fast open will kill the process, contunie?", "Contunie", "Safe Stop").then((str) => { 110 | if (str !== "Contunie") { 111 | return; 112 | } 113 | let selection = iDevices.shared.getDevice() as iDeviceItem; 114 | let fastSpawn = "\'" + LKBootStrap.shared.getBinPath() + "/bins/py3/fastSpawn.py\'"; 115 | let args = selection.udid + " " + ApplicationObject.infoObject[1]; 116 | LKutils.shared.python(fastSpawn, args).then((_) => { 117 | this.refresh(); 118 | }); 119 | }); 120 | return; 121 | } 122 | if (ApplicationObject.label === "- Open" || ApplicationObject.label === "- dyld Start") { 123 | let selection = iDevices.shared.getDevice() as iDeviceItem; 124 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 125 | let terminal = vscode.window.createTerminal("Starting => " + ApplicationObject.infoObject[1]); 126 | terminal.show(); 127 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 128 | writeFileSync(passpath, selection.iSSH_password); 129 | terminal.show(); 130 | let aopen = "\'" + LKBootStrap.shared.getBinPath() + "/bins/iOS/open\'"; 131 | let terminalCommands: Array = []; 132 | terminalCommands.push(" export SSHPASSWORD=$(cat \'" + passpath + "\')"); 133 | terminalCommands.push(" rm -f \'" + passpath + "\'"); 134 | terminalCommands.push(" ssh-keygen -R \"[127.0.0.1]:" + selection.iSSH_mappedPort + "\" &> /dev/null"); 135 | terminalCommands.push(" sshpass -p $SSHPASSWORD scp -oStrictHostKeyChecking=no -P" + selection.iSSH_mappedPort + " " + aopen + " root@127.0.0.1:/bin/"); 136 | terminalCommands.push(" sshpass -p $SSHPASSWORD ssh -oStrictHostKeyChecking=no -p " + selection.iSSH_mappedPort + " root@127.0.0.1 \'ldid -S /bin/ &> /dev/null\'"); 137 | terminalCommands.push(" sshpass -p $SSHPASSWORD ssh -oStrictHostKeyChecking=no -p " + selection.iSSH_mappedPort + " root@127.0.0.1 /bin/open " + ApplicationObject.infoObject[1]); 138 | let bashScript = ""; 139 | let bashpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 140 | terminalCommands.forEach((cmd) => { 141 | bashScript += "\n"; 142 | bashScript += cmd; 143 | }); 144 | writeFileSync(bashpath, bashScript, 'utf8'); 145 | terminal.sendText(" /bin/bash -C \'" + bashpath + "\' && exit"); 146 | vscode.window.onDidCloseTerminal((isthisone) => { 147 | if (isthisone.name === "Starting => " + ApplicationObject.infoObject[1]) { 148 | this.refresh(); 149 | } 150 | }); 151 | return; 152 | } 153 | if (ApplicationObject.label === "- Terminate") { 154 | let selection = iDevices.shared.getDevice() as iDeviceItem; 155 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 156 | let terminal = vscode.window.createTerminal("Terminate => " + ApplicationObject.infoObject[1]); 157 | terminal.show(); 158 | let passpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 159 | writeFileSync(passpath, selection.iSSH_password); 160 | terminal.show(); 161 | let terminalCommands: Array = []; 162 | terminalCommands.push(" export SSHPASSWORD=$(cat \'" + passpath + "\')"); 163 | terminalCommands.push(" rm -f \'" + passpath + "\'"); 164 | terminalCommands.push(" ssh-keygen -R \"[127.0.0.1]:" + selection.iSSH_mappedPort + "\""); 165 | terminalCommands.push(" sshpass -p $SSHPASSWORD ssh -o StrictHostKeyChecking=no -p " + selection.iSSH_mappedPort + " root@127.0.0.1 kill -9 " + ApplicationObject.infoObject[2]); 166 | let bashScript = ""; 167 | let bashpath = LKutils.shared.storagePath + "/" + LKutils.shared.makeid(10); 168 | terminalCommands.forEach((cmd) => { 169 | bashScript += "\n"; 170 | bashScript += cmd; 171 | }); 172 | writeFileSync(bashpath, bashScript, 'utf8'); 173 | terminal.sendText(" /bin/bash -C \'" + bashpath + "\' && exit"); 174 | vscode.window.onDidCloseTerminal((isthisone) => { 175 | if (isthisone.name === "Terminate => " + ApplicationObject.infoObject[1]) { 176 | this.refresh(); 177 | } 178 | }); 179 | return; 180 | } 181 | if (ApplicationObject.label === "- Watch Logs") { 182 | let selection = iDevices.shared.getDevice() as iDeviceItem; 183 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 184 | let terminal = vscode.window.createTerminal("Watch => " + ApplicationObject.infoObject[1]); 185 | terminal.show(); 186 | let readps = iDevices.shared.executeOnDevice("ps -e"); 187 | let processName: string | undefined; 188 | readps.split("\n").forEach((line) => { 189 | let dude = line; 190 | while (dude.startsWith(" ")) { 191 | dude = dude.substring(1, dude.length); 192 | } 193 | if (dude.startsWith(String(ApplicationObject.infoObject[2]))) { 194 | let sp = line.split("/"); 195 | let name = sp[sp.length - 1]; 196 | console.log("[*] Captured name : " + name); 197 | processName = name; 198 | } 199 | }); 200 | if (processName === undefined) { 201 | vscode.window.showErrorMessage("Error obtain executable name: " + ApplicationObject.infoObject[1]); 202 | return; 203 | } 204 | let watcherbin = "\'" + LKBootStrap.shared.getBinPath() + "/bins/local/idsyslog\'"; // vscode.Uri.file(join(__filename,'..', '..' ,'src' ,'bins' ,'local' ,'idsyslog')); 205 | terminal.sendText(" " + watcherbin + " " + selection.udid + " \'" + processName + "\'"); 206 | return; 207 | } 208 | if (ApplicationObject.label === "- Debugger > Frida") { 209 | let selection = iDevices.shared.getDevice() as iDeviceItem; 210 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 211 | let terminal = vscode.window.createTerminal("Frida => " + ApplicationObject.infoObject[1]); 212 | terminal.show(); 213 | terminal.sendText(" frida --device=" + selection.udid + " -p " + ApplicationObject.infoObject[2]); 214 | return; 215 | } 216 | if (ApplicationObject.label === "- Debugger > lldb") { 217 | let selection = iDevices.shared.getDevice() as iDeviceItem; 218 | if (this.hasOpenedLLDBSession[selection.udid] === ApplicationObject.infoObject[1]) { 219 | vscode.window.showInformationMessage("The lldb session is in creating, are you sure about recreating a new one?", "Contunie", "Cancel").then((str) => { 220 | if (str !== "Contunie") { 221 | return; 222 | } 223 | this.hasOpenedLLDBSession[selection.udid] = ""; 224 | this.performSelector(ApplicationObject); 225 | }); 226 | return; 227 | } 228 | this.hasOpenedLLDBSession[selection.udid] = ApplicationObject.infoObject[1]; 229 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 230 | let terminal = vscode.window.createTerminal("lldb => " + ApplicationObject.infoObject[1]); 231 | let randport = Math.floor(Math.random() * 2000) + 2000; 232 | iDevices.shared.executeOnDeviceAsync("debugserver localhost:" + String(randport) + " --attach=" + ApplicationObject.infoObject[2] + " &"); 233 | terminal.show(); 234 | terminal.sendText(" echo 'If anything went wrong, make sure to have debugserver installed on your iDevice then restart the app and try again'"); 235 | terminal.sendText(" iproxy " + String(randport) + " " + String(randport) + " &"); 236 | terminal.sendText(" lldb"); 237 | execSync("sleep 3"); 238 | terminal.sendText(" process connect connect://127.0.0.1:" + String(randport) + ""); 239 | return; 240 | } 241 | if (ApplicationObject.label === "- Load Path" || ApplicationObject.label === "- Refresh Path") { 242 | vscode.window.showInformationMessage("Load app bundle and document path requires the target app to be run as foreground, otherwise the extension may crash.", "Contunie", "Stop").then((str) => { 243 | if (str === "Stop" || str === undefined) { 244 | return; 245 | } 246 | let selection = iDevices.shared.getDevice() as iDeviceItem; 247 | let obtainer = "\'" + LKBootStrap.shared.getBinPath() + "/bins/py3/obtainAppLocation.py\'"; 248 | let cmd = obtainer + " " + selection.udid + " " + ApplicationObject.infoObject[2]; 249 | let read = execSync(cmd).toString(); 250 | while (read.endsWith("\n")) { 251 | read = read.substring(0, read.length - 1); 252 | } 253 | let wrapper = read.split("\n"); 254 | if (wrapper.length !== 2) { 255 | vscode.window.showErrorMessage("Invalid read back: " + read); 256 | return; 257 | } 258 | this.appBundleLocationInfo[ApplicationObject.infoObject[1]] = wrapper[0]; 259 | this.appDocumentLocationInfo[ApplicationObject.infoObject[1]] = wrapper[1]; 260 | 261 | LKutils.shared.saveKeyPairValue(selection.udid + "|" + ApplicationObject.infoObject[2] + "|bundle", wrapper[0]); 262 | LKutils.shared.saveKeyPairValue(selection.udid + "|" + ApplicationObject.infoObject[2] + "|documents", wrapper[1]); 263 | 264 | this.refresh(); 265 | }); 266 | return; 267 | } 268 | if (ApplicationObject.label.match("/private/var")){ 269 | vscode.window.showInformationMessage("[Push] to file system tab or [Copy] pwd?", "Cancel", "Push", "Copy").then((str) => { 270 | if (str === "Cancel" || str === undefined) { 271 | return; 272 | } 273 | if (str === "Push") { 274 | FileSystemNodeProvider.nodeProvider.pushToDir(ApplicationObject.label); 275 | return; 276 | } 277 | vscode.env.clipboard.writeText(ApplicationObject.label); 278 | vscode.window.showInformationMessage("Cpoied Item: " + ApplicationObject.label); 279 | }); 280 | return; 281 | } 282 | vscode.env.clipboard.writeText(ApplicationObject.label); 283 | vscode.window.showInformationMessage("Cpoied Item: " + ApplicationObject.label); 284 | } 285 | 286 | private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); 287 | readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; 288 | 289 | getTreeItem(element: ApplicationItem): vscode.TreeItem { 290 | return element; 291 | } 292 | 293 | refresh() { 294 | ApplicationNodeProvider.nodeProvider._onDidChangeTreeData.fire(); 295 | } 296 | 297 | private treeItemCache: Array = []; // this is dealing with error when getting SpringBoard PID form device 298 | private appBundleLocationInfo: {[key: string]: string} = {}; 299 | private appDocumentLocationInfo: {[key: string]: string} = {}; 300 | 301 | async getChildren(element?: ApplicationItem): Promise { 302 | 303 | if (element) { 304 | let details: Array = []; 305 | let pid:string = element.infoObject[2]; 306 | if (pid !== "0") { 307 | let po = new ApplicationItem(pid, true, [], vscode.TreeItemCollapsibleState.None); 308 | po.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'id.svg')); 309 | details.push(po); 310 | } 311 | let id:string = element.infoObject[1]; 312 | let bid = new ApplicationItem(id, true, [], vscode.TreeItemCollapsibleState.None); 313 | bid.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'xcode.svg')); 314 | details.push(bid); 315 | 316 | // ------ INSERT APP DOCUMENT INFO IF EXISTS ------ 317 | let isRefreshSignal = false; 318 | // if (element.label === "SpringBoard") { 319 | if (false) { 320 | // let bli = new ApplicationItem("/System/Library/CoreServices/SpringBoard.app", true, [], vscode.TreeItemCollapsibleState.None); 321 | // bli.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'location.svg')); 322 | // details.push(bli); 323 | } else { 324 | 325 | // Load location info from disk 326 | let selection = iDevices.shared.getDevice(); 327 | if (selection !== undefined && selection !== null) { 328 | let bundle = LKutils.shared.readKeyPairValue(selection.udid + "|" + element.infoObject[2] + "|bundle"); 329 | let docume = LKutils.shared.readKeyPairValue(selection.udid + "|" + element.infoObject[2] + "|documents"); 330 | 331 | if (bundle !== "") { 332 | this.appBundleLocationInfo[element.infoObject[1]] = bundle; 333 | } 334 | if (docume !== "") { 335 | this.appDocumentLocationInfo[element.infoObject[1]] = docume; 336 | } 337 | 338 | if (this.appBundleLocationInfo[element.infoObject[1]] !== undefined){ 339 | let bli = new ApplicationItem(this.appBundleLocationInfo[element.infoObject[1]], true, [], vscode.TreeItemCollapsibleState.None); 340 | bli.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'location.svg')); 341 | details.push(bli); 342 | isRefreshSignal = true; 343 | } 344 | if (this.appDocumentLocationInfo[element.infoObject[1]] !== undefined){ 345 | let dli = new ApplicationItem(this.appDocumentLocationInfo[element.infoObject[1]], true, [], vscode.TreeItemCollapsibleState.None); 346 | dli.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'location.svg')); 347 | details.push(dli); 348 | isRefreshSignal = true; 349 | } 350 | } 351 | } 352 | 353 | if (element.label !== "SpringBoard") { 354 | if (pid !== "0") { 355 | let start = new ApplicationItem("- Open", true, [], vscode.TreeItemCollapsibleState.None); 356 | start.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'rocket.svg')); 357 | start.infoObject = element.infoObject; 358 | details.push(start); 359 | let fa = new ApplicationItem("- Fast Open", true, [], vscode.TreeItemCollapsibleState.None); 360 | fa.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'rocket.svg')); 361 | fa.infoObject = element.infoObject; 362 | details.push(fa); 363 | } else { 364 | let start = new ApplicationItem("- dyld Start", true, [], vscode.TreeItemCollapsibleState.None); 365 | start.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'rocket.svg')); 366 | start.infoObject = element.infoObject; 367 | details.push(start); 368 | let fa = new ApplicationItem("- Frida Spawn", true, [], vscode.TreeItemCollapsibleState.None); 369 | fa.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'rocket.svg')); 370 | fa.infoObject = element.infoObject; 371 | details.push(fa); 372 | } 373 | } 374 | if (Number(element.infoObject[2]) > 0) { 375 | let stop = new ApplicationItem("- Terminate", true, [], vscode.TreeItemCollapsibleState.None); 376 | stop.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'terminate.svg')); 377 | stop.infoObject = element.infoObject; 378 | details.push(stop); 379 | let log = new ApplicationItem("- Watch Logs", true, [], vscode.TreeItemCollapsibleState.None); 380 | log.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'log.svg')); 381 | log.infoObject = element.infoObject; 382 | details.push(log); 383 | let frida = new ApplicationItem("- Debugger > Frida", true, [], vscode.TreeItemCollapsibleState.None); 384 | frida.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'debug.svg')); 385 | frida.infoObject = element.infoObject; 386 | details.push(frida); 387 | let lldb = new ApplicationItem("- Debugger > lldb", true, [], vscode.TreeItemCollapsibleState.None); 388 | lldb.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'debug.svg')); 389 | lldb.infoObject = element.infoObject; 390 | details.push(lldb); 391 | } 392 | // if (element.label !== "SpringBoard") { 393 | if (true) { 394 | let dmp = new ApplicationItem("- Decrypt & Dump", true, [], vscode.TreeItemCollapsibleState.None); 395 | dmp.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'exchange.svg')); 396 | dmp.infoObject = element.infoObject; 397 | details.push(dmp); 398 | if (isRefreshSignal) { 399 | let load = new ApplicationItem("- Refresh Path", true, [], vscode.TreeItemCollapsibleState.None); 400 | load.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'location.svg')); 401 | load.infoObject = element.infoObject; 402 | details.push(load); 403 | } else { 404 | let load = new ApplicationItem("- Load Path", true, [], vscode.TreeItemCollapsibleState.None); 405 | load.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'location.svg')); 406 | load.infoObject = element.infoObject; 407 | details.push(load); 408 | } 409 | } 410 | 411 | return details; 412 | } 413 | 414 | if (this.treeItemCache.length > 0) { 415 | let copy = this.treeItemCache; 416 | this.treeItemCache = []; 417 | return copy; 418 | } 419 | 420 | let ret: ApplicationItem[] = []; 421 | if (iDevices.shared.getDevice() === null) { 422 | const piggy = new ApplicationItem("No Application", false, [], vscode.TreeItemCollapsibleState.None); 423 | piggy.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'pig.svg')); 424 | ret.push(piggy); 425 | return Promise.resolve(ret); 426 | } 427 | 428 | const pyb = "\'" + LKBootStrap.shared.getBinPath() + "/bins/py3/lsapps.py\'"; // vscode.Uri.file(join(__filename,'..', '..' ,'src' ,'bins' ,'py3' ,'lsapps.py')).path; 429 | let read = await LKutils.shared.python(pyb, iDevices.shared.getDevice()?.udid as string) as String; 430 | 431 | let haveApp = false; 432 | let sp = read.split("\n"); 433 | sp = sp.sort((obj1: string, obj2: string) => { 434 | let x1 = obj1.split("|"); 435 | let x2 = obj2.split("|"); 436 | if (x1.length < 3 || x2.length < 3) { 437 | return 1; 438 | } 439 | if (x1[0] < x2[0]) { 440 | return -1; 441 | } 442 | return 1; 443 | }); 444 | sp.forEach((item: string) => { 445 | const sp = item.split("|"); 446 | if (item === "") { 447 | return; 448 | } 449 | if (sp.length < 3) { 450 | console.log("[E] Application descriptor invalid: " + item); 451 | return; 452 | } 453 | haveApp = true; 454 | if (Number(sp[2]) > 0) { 455 | ret.push(new ApplicationItem(sp[0], false, sp, vscode.TreeItemCollapsibleState.Collapsed)); 456 | } 457 | }); 458 | read.split("\n").forEach((item: string) => { 459 | if (item === "") { 460 | return; 461 | } 462 | const sp = item.split("|"); 463 | if (sp.length < 3) { 464 | console.log("[E] Application descriptor invalid: " + item); 465 | return; 466 | } 467 | haveApp = true; 468 | if (Number(sp[2]) === 0) { 469 | ret.push(new ApplicationItem(sp[0], false, sp, vscode.TreeItemCollapsibleState.Collapsed)); 470 | } 471 | }); 472 | if (!haveApp) { 473 | const piggy = new ApplicationItem("No Application", false, [], vscode.TreeItemCollapsibleState.None); 474 | piggy.iconPath = vscode.Uri.file(join(__filename,'..', '..' ,'res' ,'pig.svg')); 475 | ret.push(piggy); 476 | return Promise.resolve(ret); 477 | } 478 | 479 | 480 | let passCache = Object.assign([], ret); 481 | 482 | let str = String("Failed Getting PID"); 483 | let spbInfo = ["SpringBoard", "com.apple.springboard", str, 484 | "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAB20lEQVQ4T6WSvWsUURTFz3lkhYBBEBZLYWcImBnFaCM2EUlhZSr/gDS2AYm6OxNMBPclgiCpBCsFQdBOCxsx2oiIiu7uENCZGEGws1EUv96RmXFDXLbY6O3eO+f93rmXS/xnMX+/6jcmBuX8hIo3ee1Nlx6yXYsWaEhIewaBCDlBX0l+cXC3CoABFKzZ84MAup7Ei2cdfz37Z0Dbb0SAHpctECbM7LktJahF8864R2UCshJkzbgfIPHnjktuGdA6YJ4COkNqCo7jBSCpRfMyGA5TW+8H6HjRW9FMG6gKpzFR9wHeoHBtAwBye5A1T/cCOl58EtBsmNnRllc/mOv7sqXniRe9FnElTO3lboIdYWpPbQa0/foRylxwcDPk0IhxbsIZcAha+SF9NuAlB14vAKB2BtniTB/A3TCzIy0/nqLTeK4boxdBunin4zVWAHOzTABURa3nw4RTBWC5bURFwmS4Zg+V7QBh1rzaqUVPCNzLd6cwJl79mGC+iU69czAyk0Fm5xI/PpFrQdq83fGiB2Fmj5Z//Km2Fx821IIc3nTvRASQ3pMcBWgA9wniMIjVMLPTfwHywys/OtCb4GO6rbVr9/fq2Dv7Idde+meD/enFpOvbSLCVLdzs/Q0NO9PSniFXWwAAAABJRU5ErkJggg=="]; 485 | let spb = new ApplicationItem("SpringBoard", false, spbInfo, vscode.TreeItemCollapsibleState.Collapsed); 486 | ret.unshift(spb); 487 | 488 | this.loadSpringBoard(passCache); // doing it async will prevent any error when sub routine dead 489 | 490 | return Promise.resolve(ret); 491 | } 492 | 493 | async loadSpringBoard(pass: Array) { 494 | let str = String(this.getPIDviaProcessName("SpringBoard")); 495 | let spbInfo = ["SpringBoard", "com.apple.springboard", str, 496 | "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAB20lEQVQ4T6WSvWsUURTFz3lkhYBBEBZLYWcImBnFaCM2EUlhZSr/gDS2AYm6OxNMBPclgiCpBCsFQdBOCxsx2oiIiu7uENCZGEGws1EUv96RmXFDXLbY6O3eO+f93rmXS/xnMX+/6jcmBuX8hIo3ee1Nlx6yXYsWaEhIewaBCDlBX0l+cXC3CoABFKzZ84MAup7Ei2cdfz37Z0Dbb0SAHpctECbM7LktJahF8864R2UCshJkzbgfIPHnjktuGdA6YJ4COkNqCo7jBSCpRfMyGA5TW+8H6HjRW9FMG6gKpzFR9wHeoHBtAwBye5A1T/cCOl58EtBsmNnRllc/mOv7sqXniRe9FnElTO3lboIdYWpPbQa0/foRylxwcDPk0IhxbsIZcAha+SF9NuAlB14vAKB2BtniTB/A3TCzIy0/nqLTeK4boxdBunin4zVWAHOzTABURa3nw4RTBWC5bURFwmS4Zg+V7QBh1rzaqUVPCNzLd6cwJl79mGC+iU69czAyk0Fm5xI/PpFrQdq83fGiB2Fmj5Z//Km2Fx821IIc3nTvRASQ3pMcBWgA9wniMIjVMLPTfwHywys/OtCb4GO6rbVr9/fq2Dv7Idde+meD/enFpOvbSLCVLdzs/Q0NO9PSniFXWwAAAABJRU5ErkJggg=="]; 497 | let spb = new ApplicationItem("SpringBoard", false, spbInfo, vscode.TreeItemCollapsibleState.Collapsed); 498 | pass.unshift(spb); 499 | this.treeItemCache = pass; 500 | this.refresh(); // if ssh dead in getPIDviaProcessName, this wont be called. other wise, "iProxy Required" still need a refresh 501 | } 502 | 503 | /* 504 | Let me explain this refresh call chain again. 505 | 506 | When no iProxy available 507 | -> getChild: Failed Getting PID 508 | --> loadSpringBoard: 509 | ---> getPIDviaProcessName: "iProxy Required" 510 | ----> trigger refresh {} + 511 | 512 | When iProxy exists but device not reachable via ssh 513 | -> getChild: Failed Getting PID 514 | --> loadSpringBoard: 515 | ---> getPIDviaProcessName: DEAD! 516 | ----> NO SUB ROUTINE //trigger refresh 517 | 518 | When we successfully get them all 519 | -> getChild: Failed Getting PID 520 | --> loadSpringBoard: 521 | ---> getPIDviaProcessName: "666" 522 | ----> trigger refresh 523 | 524 | */ 525 | 526 | public getPIDviaProcessName(name: String): String { 527 | if (name === undefined || name === null) { 528 | return "0"; 529 | } 530 | let device = iDevices.shared.getDevice(); 531 | if (device === undefined || iDeviceNodeProvider.iProxyPool[device!.udid] === undefined) { 532 | // Do nothing if there is no iProxy instance 533 | return "iProxy Required"; 534 | } 535 | let nameRead: string = name.toLowerCase(); 536 | let selection = iDevices.shared.getDevice() as iDeviceItem; 537 | iDeviceNodeProvider.nodeProvider.ensureiProxy(selection); 538 | let readps = iDevices.shared.executeOnDevice("ps -e"); 539 | let processName: string | undefined; 540 | let items = readps.split("\n"); 541 | for (const index in items) { 542 | let trimmed = items[index]; 543 | while (trimmed.endsWith(" ")) { 544 | trimmed = trimmed.substr(0, trimmed.length - 1); 545 | } 546 | while (trimmed.startsWith(" ")) { 547 | trimmed = trimmed.substr(1, trimmed.length); 548 | } 549 | if (trimmed.toLocaleLowerCase().endsWith(nameRead)) { 550 | let pidstr = trimmed.split(" ")[0]; 551 | console.log("[*] -> " + nameRead + " has PID " + pidstr); 552 | return pidstr; 553 | } 554 | } 555 | vscode.window.showErrorMessage("SSH Connection Invalid"); 556 | return "0"; 557 | } 558 | 559 | } 560 | --------------------------------------------------------------------------------