Just An Application

August 14, 2014

And Another One: Part Thirteen — JarFile.JarFileInputStream.read

The PackageParser.loadCertificates method creates a BufferedInputStream passing it the InputStream returned by the JarFile.getInputStream method.

As we have seen, when the file in the JAR has a digest entry in the Manifest and an associated entry in at least one signature file, the
InputStream will be an instance of the JarFile inner class JarFileInputStream.

JarFile.JarFileInputStream.read

File

    $(ANDROID_SRC)/libcore/luni/src/main/java/java/util/jar/JarFile.java

Source

    ...
        
        @Override
        public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
            if (done) {
                return -1;
            }
            if (count > 0) {
                int r = super.read(buffer, byteOffset, byteCount);
                if (r != -1) {
                    int size = r;
                    if (count < size) {
                        size = (int) count;
                    }
                    entry.write(buffer, byteOffset, size);
                    count -= size;
                } else {
                    count = 0;
                }
                if (count == 0) {
                    done = true;
                    entry.verify();
                }
                return r;
            } else {
                done = true;
                entry.verify();
                return -1;
            }
        }

    ...

The read method is effectively a wrapper around the super class method FilterInputStream.read.

It makes the contents of the file being read from the JAR available to the associated JarVerifier.VerifierEntry instance so that it can compute the digest.

Once the entire file has been read it calls the JarVerifier.VerifierEntry verify method.


Copyright (c) 2014 By Simon Lewis. All Rights Reserved.

Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.

Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.

Advertisements

1 Comment »

  1. […] to the JarFile.JarFileInputStream read methods result in the VerifierEntry being passed what has been read from the file via calls to its […]

    Pingback by And Another One: Part Fourteen — JarVerifier.VerifierEntry.verify | Just An Application — August 15, 2014 @ 8:03 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: