Skip to content

Instantly share code, notes, and snippets.

@Magneticdud
Last active May 7, 2022 10:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Magneticdud/89f5e7fca1d89ff0719d9013f3e736d7 to your computer and use it in GitHub Desktop.
Save Magneticdud/89f5e7fca1d89ff0719d9013f3e736d7 to your computer and use it in GitHub Desktop.
Download link generator for BlackBerry World 5.2.0.9
//Download link generator for BlackBerry World 5.2.0.9. Code by xsacha, found on crackberry
//not working anymore
//sauce: http://forums.crackberry.com/blackberry-10-apps-f274/bardownload-script-988098/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Bar Download Generator</title>
</head>
<body>
<?php
$mytoken= "";
if(isset($_POST['auth']) || isset($_POST['app'])) {
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_USERAGENT => 'AppWorld/5.2.0.9',
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, $defaults);
curl_setopt($ch, CURLOPT_HTTPHEADER, $options);
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
function startsWith($haystack, $needle) {
// search backwards starting from haystack length characters from the end
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
}
// validation expected data exists
if(!isset($_POST['app'])) {
$error_message = 'Missing required (*) information.';
}
else
{
$app = $_POST['app']; // required
$auth = $_POST['auth']; // not required
if (strlen($title) < 1) {
$title = $name;
}
$error_message = "";
$url_exp = '%((https?://)|(www\.))%i';
$string_exp = "/^[A-Za-z .'-]+$/";
$app = preg_replace('/[^0-9]/s', '', $app);
if(strlen($app) <= 0) {
$error_message .= 'An application ID is required.<br />';
} else if (!is_numeric($app)) {
$error_message .= 'Invalid ID number.<br />';
}
$token = $auth;
if(strlen($auth) <= 0) {
$token = $mytoken;
$error_message .= 'An Authorization token is required.<br />';
} else if(strlen($auth) < 50) {
$error_message .= 'Authorization token is too short.<br />';
} else if (!startsWith($auth, "AQ%3A")) {
$token = "AQ%3A".$token;
}
if(strlen($error_message) <= 0) {
$postoptions = array(
'contentid' => urlencode($app),
'clientver' => '5.2',
'model' => 'Imagination GPU',
'os' => '10.9.0',
'pin' => '0',
);
if (strlen($mcc) > 0) {
array_push($postoptions, 'currentmcc => '.str_pad($mcc, 3,'0',STR_PAD_LEFT));
}
if (strlen($mnc) > 0) {
array_push($postoptions, 'currentmnc => '.str_pad($mnc, 3,'0',STR_PAD_LEFT));
}
$curloptions = array(
'Content-Type: application/x-www-form-urlencoded',
'Accept-Encoding: gzip',
'Authorization: '.$token,
);
$downloadurl = 'http://appworld.blackberry.com/ClientAPI/usfdownload?';
$result = curl_post($downloadurl, $postoptions, $curloptions);
if (!startsWith($result, "<?xml")) {
$error_message .= 'Bad response from Blackberry';
} else {
$xml=false;
$xml=simplexml_load_string($result);
if ($xml === false) {
$error_message .= 'Failed to read response from Blackberry';
foreach(libxml_get_errors() as $error) {
$error_message .= "<br>". $error->message;
}
} else if (!empty($xml->error)) {
$error_message .= $xml->error;
} else { // && $token == $mytoken
if ($xml->link->content->prices->license['type'] != '1') {
$error_message .= 'You are restricted to FREE applications.';
} else if (count($xml->filebundle->file->attributes()) > 0) {
$size = bcdiv($xml->filebundle->file['size'], '1048576', 2);
$success .= 'Success. Download <a mimetype="application/bar" href="'.$xml->filebundle->file['url'].' ">'.$xml->filebundle->file['name'].'</a>
('.$size.' MB) v'.$xml->filebundle['pkgversion'];
} else {
$error_message .= 'Loaded the ID but was not given a download link.';
}
}
}
}
}
}
?>
<div id="wrapper">
<p align="center" class="quicksanddash"><font color="purple"><em>B</em></font>ar <font color="purple"><em>G</em></font>enerator</p><br>
<div id="boxtext" style="position: relative; left:20%; width:60%" align="left">
This tool provides a shortcut for you to download your applications directly from BBWorld via your BBID.
Enter the ID of the application you wish to download along with your Authorization code.
A personal link to the requested file on the content server will be generated using the BBWorld APIs.
</div>
<div id="head-1" align="center" >
<form name="contactform" method="post" action="bardownload.php">
<table width="450px">
<tr>
<td valign="center">
<label for="app">Application ID *</label>
</td>
<td valign="center">
<input type="text" name="app" <?php echo 'value="'.$_POST['app'].'"'; ?> maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="center">
<label for="mcc">Country (<a href="http://en.wikipedia.org/wiki/Mobile_country_code">MCC</a>)</label>
</td>
<td valign="center">
<input type="text" name="mcc" <?php echo 'value="'.$_POST['mcc'].'"'; ?> maxlength="3" size="30">
</td>
</tr>
<tr>
<td valign="center">
<label for="mnc">Carrier (<a href="http://en.wikipedia.org/wiki/Mobile_country_code">MNC</a>)</label>
</td>
<td valign="center">
<input type="text" name="mnc" <?php echo 'value="'.$_POST['mnc'].'"'; ?> maxlength="3" size="30">
</td>
</tr>
<tr>
<td valign="center">
<label for="auth"><a href="#token">Authorization token</a> *</label>
</td>
<td valign="center">
<textarea name="auth" maxlength="1000" cols="25" rows="6"><?php echo $_POST['auth']; ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
</div>
<br>
<?php
if(isset($_POST['auth']) || isset($_POST['app'])) {
if (strlen($error_message) > 0)
echo '<p style="position: relative; left:20%; width:60%" align="left"><font color="red">'.$error_message.'</font></p>';
if (strlen($success) > 0)
echo '<p style="position: relative; left:20%; width:60%" align="left"><font color="steelblue">'.$success.'</font></p>';
}
?>
<br>
<div id="boxtext" style="position: relative; left:20%; width:60%" align="left">Regarding the <b>redistribution of bar files</b>:
<p style="margin-left : 10%;">Any bar files for which you may find links to on this web page are distributed to you by BBWorld via its content servers.
Do not redistribute them outside of this framework.</p></div>
<br>
<a name="token"></a>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment