Beispiel #1
0
  private boolean obbIsCorrupted(String f, String main_pack_md5) {

    try {

      InputStream fis = new FileInputStream(f);

      // Create MD5 Hash
      byte[] buffer = new byte[16384];

      MessageDigest complete = MessageDigest.getInstance("MD5");
      int numRead;
      do {
        numRead = fis.read(buffer);
        if (numRead > 0) {
          complete.update(buffer, 0, numRead);
        }
      } while (numRead != -1);

      fis.close();
      byte[] messageDigest = complete.digest();

      // Create Hex String
      StringBuffer hexString = new StringBuffer();
      for (int i = 0; i < messageDigest.length; i++) {
        String s = Integer.toHexString(0xFF & messageDigest[i]);

        if (s.length() == 1) {
          s = "0" + s;
        }
        hexString.append(s);
      }
      String md5str = hexString.toString();

      // Log.d("GODOT","**PACK** - My MD5: "+hexString+" - APK md5: "+main_pack_md5);
      if (!md5str.equals(main_pack_md5)) {
        Log.d(
            "GODOT",
            "**PACK MD5 MISMATCH???** - MD5 Found: "
                + md5str
                + " "
                + Integer.toString(md5str.length())
                + " - MD5 Expected: "
                + main_pack_md5
                + " "
                + Integer.toString(main_pack_md5.length()));
        return true;
      }
      return false;
    } catch (Exception e) {
      e.printStackTrace();
      Log.d("GODOT", "**PACK FAIL**");
      return true;
    }
  }
 private String debugVersions() {
   StringBuffer sb = new StringBuffer();
   sb.append("bot=");
   sb.append(bottom);
   sb.append(" top=");
   sb.append(top);
   sb.append(" [");
   for (int i = 0; i < versions.size(); i++) {
     if (i > 0) sb.append(" ");
     sb.append(versions.get(i).version);
   }
   sb.append("]");
   return sb.toString();
 }
Beispiel #3
0
    public HTTPStream(HttpURLConnection connection_, int[] statusCode, StringBuffer responseHeaders)
        throws IOException {
      connection = connection_;

      try {
        inputStream = new BufferedInputStream(connection.getInputStream());
      } catch (IOException e) {
        if (connection.getResponseCode() < org.apache.http.HttpStatus.SC_BAD_REQUEST) throw e;
      } finally {
        statusCode[0] = connection.getResponseCode();
      }

      if (statusCode[0] >= org.apache.http.HttpStatus.SC_BAD_REQUEST)
        inputStream = connection.getErrorStream();
      else inputStream = connection.getInputStream();

      for (java.util.Map.Entry<String, java.util.List<String>> entry :
          connection.getHeaderFields().entrySet())
        if (entry.getKey() != null && entry.getValue() != null)
          responseHeaders.append(
              entry.getKey() + ": " + android.text.TextUtils.join(",", entry.getValue()) + "\n");
    }
Beispiel #4
0
  public static final HTTPStream createHTTPStream(
      String address,
      boolean isPost,
      byte[] postData,
      String headers,
      int timeOutMs,
      int[] statusCode,
      StringBuffer responseHeaders,
      int numRedirectsToFollow) {
    // timeout parameter of zero for HttpUrlConnection is a blocking connect (negative value for
    // juce::URL)
    if (timeOutMs < 0) timeOutMs = 0;
    else if (timeOutMs == 0) timeOutMs = 30000;

    // headers - if not empty, this string is appended onto the headers that are used for the
    // request. It must therefore be a valid set of HTML header directives, separated by newlines.
    // So convert headers string to an array, with an element for each line
    String headerLines[] = headers.split("\\n");

    for (; ; ) {
      try {
        HttpURLConnection connection = (HttpURLConnection) (new URL(address).openConnection());

        if (connection != null) {
          try {
            connection.setInstanceFollowRedirects(false);
            connection.setConnectTimeout(timeOutMs);
            connection.setReadTimeout(timeOutMs);

            // Set request headers
            for (int i = 0; i < headerLines.length; ++i) {
              int pos = headerLines[i].indexOf(":");

              if (pos > 0 && pos < headerLines[i].length()) {
                String field = headerLines[i].substring(0, pos);
                String value = headerLines[i].substring(pos + 1);

                if (value.length() > 0) connection.setRequestProperty(field, value);
              }
            }

            if (isPost) {
              connection.setRequestMethod("POST");
              connection.setDoOutput(true);

              if (postData != null) {
                OutputStream out = connection.getOutputStream();
                out.write(postData);
                out.flush();
              }
            }

            HTTPStream httpStream = new HTTPStream(connection, statusCode, responseHeaders);

            // Process redirect & continue as necessary
            int status = statusCode[0];

            if (--numRedirectsToFollow >= 0
                && (status == 301 || status == 302 || status == 303 || status == 307)) {
              // Assumes only one occurrence of "Location"
              int pos1 = responseHeaders.indexOf("Location:") + 10;
              int pos2 = responseHeaders.indexOf("\n", pos1);

              if (pos2 > pos1) {
                String newLocation = responseHeaders.substring(pos1, pos2);
                // Handle newLocation whether it's absolute or relative
                URL baseUrl = new URL(address);
                URL newUrl = new URL(baseUrl, newLocation);
                String transformedNewLocation = newUrl.toString();

                if (transformedNewLocation != address) {
                  address = transformedNewLocation;
                  // Clear responseHeaders before next iteration
                  responseHeaders.delete(0, responseHeaders.length());
                  continue;
                }
              }
            }

            return httpStream;
          } catch (Throwable e) {
            connection.disconnect();
          }
        }
      } catch (Throwable e) {
      }

      return null;
    }
  }