forked from KJCracks/Brake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrackProcess.cs
121 lines (108 loc) · 4.59 KB
/
CrackProcess.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using Renci.SshNet;
using Renci.SshNet.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Brake
{
public partial class CrackProcess : Form
{
private static Container xml;
private IPAInfo ipaInfo;
delegate void LogCallback(string text);
private void log(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (logBox.InvokeRequired)
{
LogCallback d = new LogCallback(log);
this.Invoke(d, new object[] { text });
}
else
{
logBox.AppendText(text + Environment.NewLine);
Console.WriteLine("log: " + text);
}
}
delegate void PercentStatusCallback(string text, int percent);
private void PercentStatus(string text, int percent)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (logBox.InvokeRequired)
{
PercentStatusCallback d = new PercentStatusCallback(PercentStatus);
this.Invoke(d, new object[] { text, percent });
}
else
{
statusLabel.Text = "status: " + text + " (" + percent + "%)";
progressBar1.Value = percent;
}
}
public void beginCracking()
{
log("beginning cracking process..");
var connectionInfo = new PasswordConnectionInfo (xml.Config.host, xml.Config.port, "root", xml.Config.Password);
using (var sftp = new SftpClient(connectionInfo))
{
using (var ssh = new SshClient(connectionInfo))
{
PercentStatus("Establishing SSH connection", 5);
ssh.Connect();
PercentStatus("Establishing SFTP connection", 10);
sftp.Connect();
log("Cracking " + ipaInfo.AppName);
PercentStatus("Preparing IPA", 25);
String ipalocation = AppHelper.extractIPA(ipaInfo);
using (var file = File.OpenRead(ipalocation))
{
log("Uploading IPA to device..");
PercentStatus("Uploading IPA", 40);
sftp.UploadFile(file, "Upload.ipa");
}
log("Cracking! (This might take a while)");
PercentStatus("Cracking", 50);
String binaryLocation = ipaInfo.BinaryLocation.Replace("Payload/", "");
String TempDownloadBinary = Path.Combine(AppHelper.GetTemporaryDirectory(), "crackedBinary");
var crack = ssh.RunCommand("Clutch -i 'Upload.ipa' " + binaryLocation + " /tmp/crackedBinary");
log("Clutch -i 'Upload.ipa' " + binaryLocation + " /tmp/crackedBinary");
log("cracking output: " + crack.Result);
using (var file = File.OpenWrite(TempDownloadBinary))
{
log("Downloading cracked binary..");
PercentStatus("Downloading cracked binary", 80);
try
{
sftp.DownloadFile("/tmp/crackedBinary", file);
}
catch (SftpPathNotFoundException e)
{
log("Could not find file, help!!!!!");
return;
}
}
PercentStatus("Repacking IPA", 90);
String repack = AppHelper.repack(ipaInfo, TempDownloadBinary);
PercentStatus("Done!", 100);
log("Cracking completed, file at " + repack);
}
}
}
public CrackProcess(IPAInfo ipaInfo)
{
xml = Brake.Container.getContainer();
this.ipaInfo = ipaInfo;
InitializeComponent();
}
}
}