Skip to content

Commit a11bdaa

Browse files
committed
added support for multiple platforms for ruby
1 parent d12a418 commit a11bdaa

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed

cSploit/jni

cSploit/src/org/csploit/android/core/UpdateService.java

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
public class UpdateService extends IntentService
7373
{
7474
// Resources defines
75-
private static final String REMOTE_RUBY_VERSION_URL = "https://gist.githubusercontent.com/tux-mind/e594b1cf923183cfcdfe/raw/ruby.json";
7675
private static final String REMOTE_GEMS_VERSION_URL = "http://gems.dsploit.net/atom.xml";
7776
private static final String REMOTE_GEM_SERVER = "http://gems.dsploit.net/";
7877
private static final Pattern GEM_FROM_LIST = Pattern.compile("^([^ ]+) \\(([^ ]+) ");
@@ -239,6 +238,7 @@ public static boolean isCoreUpdateAvailable() {
239238

240239
if(remoteURL == null) {
241240
Logger.warning(String.format("unsupported platform ( %s )", platform));
241+
return false;
242242
}
243243

244244
synchronized (mCoreInfo) {
@@ -254,9 +254,6 @@ public static boolean isCoreUpdateAvailable() {
254254

255255
exitForError = false;
256256

257-
if(remoteURL == null)
258-
return false;
259-
260257
if(localVersion == null)
261258
return true;
262259

@@ -287,41 +284,45 @@ public static String getRemoteCoreVersion() {
287284
* @return true if ruby can be updated, false otherwise
288285
*/
289286
public static boolean isRubyUpdateAvailable() {
290-
HttpURLConnection connection = null;
291-
BufferedReader reader = null;
292-
String line;
293287
boolean exitForError = true;
294288
String localVersion = System.getLocalRubyVersion();
289+
String platform = System.getPlatform();
290+
String remoteVersion, remoteURL;
295291

296292
try {
297-
synchronized (mRubyInfo) {
298-
if (mRubyInfo.version == null) {
299293

300-
HttpURLConnection.setFollowRedirects(true);
301-
URL url = new URL(REMOTE_RUBY_VERSION_URL);
302-
connection = (HttpURLConnection) url.openConnection();
303-
connection.connect();
294+
remoteVersion = GitHubParser.getRubyRepo().getLastReleaseVersion();
304295

305-
if (connection.getResponseCode() != 200)
306-
return false;
296+
if(remoteVersion == null)
297+
return false;
307298

308-
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
309-
StringBuilder sb = new StringBuilder();
299+
remoteURL = GitHubParser.getRubyRepo().getLastReleaseAssetUrl(platform + ".");
310300

311-
while ((line = reader.readLine()) != null) {
312-
sb.append(line);
313-
}
301+
if(remoteURL == null) {
302+
Logger.warning(String.format("unsupported platform ( %s )", platform));
314303

315-
JSONObject info = new JSONObject(sb.toString());
316-
mRubyInfo.url = info.getString("url");
317-
mRubyInfo.versionString = info.getString("version");
318-
mRubyInfo.version = Version.valueOf(mRubyInfo.versionString);
319-
mRubyInfo.path = String.format("%s/%s", System.getStoragePath(), info.getString("name"));
320-
mRubyInfo.archiver = archiveAlgorithm.valueOf(info.getString("archiver"));
321-
mRubyInfo.compression = compressionAlgorithm.valueOf(info.getString("compression"));
322-
mRubyInfo.md5 = info.getString("md5");
323-
mRubyInfo.sha1 = info.getString("sha1");
324-
}
304+
platform = System.getCompatiblePlatform();
305+
Logger.debug(String.format("trying with '%s'", platform));
306+
307+
remoteURL = GitHubParser.getCoreRepo().getLastReleaseAssetUrl(platform + ".");
308+
}
309+
310+
Logger.debug(String.format("localVersion = %s", localVersion));
311+
Logger.debug(String.format("remoteVersion = %s", remoteVersion));
312+
313+
if(remoteURL == null) {
314+
Logger.warning(String.format("unsupported platform ( %s )", platform));
315+
return false;
316+
}
317+
318+
synchronized (mRubyInfo) {
319+
mRubyInfo.url = remoteURL;
320+
mRubyInfo.versionString = remoteVersion;
321+
mRubyInfo.version = Version.valueOf(mRubyInfo.versionString);
322+
mRubyInfo.name = String.format("core-%s+%s.tar.xz", mRubyInfo.versionString, platform);
323+
mRubyInfo.path = String.format("%s/%s", System.getStoragePath(), mRubyInfo.name);
324+
mRubyInfo.archiver = archiveAlgorithm.tar;
325+
mRubyInfo.compression = compressionAlgorithm.xz;
325326

326327
mRubyInfo.outputDir = System.getRubyPath();
327328
mRubyInfo.executableOutputDir = ExecChecker.ruby().getRoot();
@@ -334,22 +335,18 @@ public static boolean isRubyUpdateAvailable() {
334335

335336
exitForError = false;
336337

337-
if (localVersion == null || mRubyInfo.version.compareTo(Version.valueOf(localVersion)) > 0)
338+
if(localVersion == null)
339+
return true;
340+
341+
// Compare versions
342+
Version installedVersion = Version.valueOf(localVersion);
343+
344+
if (mRubyInfo.version.compareTo(installedVersion) > 0)
338345
return true;
339346
}
340-
} catch (UnknownHostException e) {
341-
Logger.error(e.getMessage());
342347
} catch(Exception e){
343348
System.errorLogging(e);
344349
} finally {
345-
try {
346-
if (reader != null)
347-
reader.close();
348-
} catch (Exception e) {
349-
//ignored
350-
}
351-
if(connection!=null)
352-
connection.disconnect();
353350
if(exitForError)
354351
mRubyInfo.reset();
355352
}

cSploit/src/org/csploit/android/net/GitHubParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class GitHubParser {
5353
private static GitHubParser msfRepo = new GitHubParser("rapid7", "metasploit-framework");
5454
private static GitHubParser cSploitRepo = new GitHubParser("cSploit", "android");
5555
private static GitHubParser coreRepo = new GitHubParser("cSploit", "android.native");
56+
private static GitHubParser rubyRepo = new GitHubParser("cSploit", "android.native.ruby");
5657

5758
public static GitHubParser getMsfRepo() {
5859
return msfRepo;
@@ -66,6 +67,10 @@ public static GitHubParser getCoreRepo() {
6667
return coreRepo;
6768
}
6869

70+
public static GitHubParser getRubyRepo() {
71+
return rubyRepo;
72+
}
73+
6974
public GitHubParser(String username, String project) {
7075
this.username = username;
7176
this.project = project;

0 commit comments

Comments
 (0)