Пример #1
0
        /**
         * Constructs a type froma stream
         *
         * @param inputStream An input stream
         * @param indexEntry  The index informations
         * @return The size of the read data
         * @throws IOException if an I/O error occurs.
         */
        public static INT8 readFromStream(java.io.DataInputStream inputStream,
                                          IndexEntry indexEntry)
        {//throws IOException {
            if (indexEntry.getType() != RPMIndexType.INT8)
            {
                throw new java.lang.IllegalArgumentException("Type <" + indexEntry.getType()
                                                             + "> does not match <" + RPMIndexType.INT8 + ">");
            }

            byte[] data = new byte[(int)indexEntry.getCount()];

            for (int pos = 0; pos < indexEntry.getCount(); pos++)
            {
                data[pos] = inputStream.readByte();
            }

            INT8 int8Object = new INT8(data);

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer(int8Object.toString());
            }

            // int8Object.size = indexEntry.getType().getSize()
            // * indexEntry.getCount();

            return(int8Object);
        }
Пример #2
0
        /**
         * Constructs a IndexEntry out of a InputStream. This will read the tag id,
         * the data type, the offset of the data and the number of elements of
         * data. Note that the number of elements varies in its meaning depending
         * on the data type.
         *
         * @param inputStream An InputStream containing a rpm file.
         * @throws IOException If an error occurs during reading from stream
         */
        public IndexEntry(java.io.DataInputStream inputStream)
        {//throws IOException {
            tag = inputStream.readInt();

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("tag:" + tag);
            }

            type = RPMIndexType.getRPMIndexType(inputStream.readInt());

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("type: " + type);
            }

            offset = inputStream.readInt();

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("offset: " + offset);
            }

            count = inputStream.readInt();

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("count: " + count);
            }

            check(!type.equals(RPMIndexType.UNKNOWN));
        }
Пример #3
0
        /**
         * Constructs a type froma stream
         *
         * @param inputStream An input stream
         * @param indexEntry  The index informations
         * @param length      the length of the data
         * @return The size of the read data
         * @throws IOException if an I/O error occurs.
         */
        public static I18NSTRING readFromStream(java.io.DataInputStream inputStream,
                                                IndexEntry indexEntry, long length)
        {//throws IOException {
            if (indexEntry.getType() != RPMIndexType.I18NSTRING)
            {
                throw new java.lang.IllegalArgumentException("Type <" + indexEntry.getType()
                                                             + "> does not match <" + RPMIndexType.I18NSTRING + ">");
            }

            // initialize temporary space for data
            byte[] stringData = new byte[(int)length];

            // and read it from stream
            inputStream.readFully(stringData);

            String[] data = new String[(int)indexEntry.getCount()];

            int off = 0;

            for (int pos = 0; pos < indexEntry.getCount(); pos++)
            {
                data[pos] = RPMUtil.cArrayToString(stringData, off);

                // offset for new string is stringlength + 1 for the \0 in c
                // strings
                if (data[pos].length() == 0)
                {
                    off += data[pos].length();
                }
                else
                {
                    off += (data[pos].length() + 1);
                }

                if (off > stringData.Length)
                {
                    throw new java.lang.IllegalStateException(
                              "Index wrong; Strings doesn't fit into data area. ["
                              + off + ", " + stringData.Length + "]");
                }
            }

            I18NSTRING stringObject = new I18NSTRING(data);

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer(stringObject.toString());
                if (stringObject.size != stringData.Length)
                {
                    logger.warning("STRING size differs (is:" + stringData.Length
                                   + ";should:" + stringObject.size + ")");
                }
            }

            stringObject.size = stringData.Length;

            return(stringObject);
        }
Пример #4
0
        /**
         * This method creates a rpm data type out of a input stream and an
         * IndexEntry. The object must at the current position of the input stream.
         * The length is only needed for string objects; the string objects will
         * read length bytes of the input stream and will try to convert the data
         * into a rpm data type.
         *
         * @param inputStream
         *            The input stream
         * @param indexEntry
         *            The IndexEntry that should be read
         * @param length
         *            The number of bytes to read for string objects
         *
         * @return One of the rpm data types coresponding with the type contained in
         *         the IndexEntry.
         *
         * @throws IOException
         *             if something was wrong during reading of the input stream
         */
        public static DataTypeIf createFromStream(
            java.io.DataInputStream inputStream, IndexEntry indexEntry,
            long length)
        {//throws IOException {
            DataTypeIf ret = null;

            switch ((int)indexEntry.getType().getId())
            {
            case RPMIndexType._NULL:
                ret = NULL.readFromStream(indexEntry);
                break;

            case RPMIndexType._CHAR:
                ret = CHAR.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._INT8:
                ret = INT8.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._INT16:
                ret = INT16.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._INT32:
                ret = INT32.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._INT64:
                ret = INT64.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._STRING:
                ret = STRING.readFromStream(inputStream, indexEntry, length);
                break;

            case RPMIndexType._BIN:
                ret = BIN.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._STRING_ARRAY:
                ret = STRING_ARRAY.readFromStream(inputStream, indexEntry, length);
                break;

            case RPMIndexType._I18NSTRING:
                ret = I18NSTRING.readFromStream(inputStream, indexEntry, length);
                break;

            default:
                // TODO: UNKNOWN
                break;
            }

            return(ret);
        }
Пример #5
0
        /**
         * Creates a new RPMSignature object from an input stream
         *
         * @param inputStream
         *                The input stream
         * @throws IOException
         *                 if an error occurs on reading informations out of the
         *                 stream
         */
        public RPMSignature(java.io.DataInputStream inputStream, Store store)
            ://throws IOException {
            base(inputStream, store)
        {
            // Make signature size modulo 8 = 0
            long fill = (size % 8L);

            if (fill != 0)
            {
                fill = 8 - fill;
            }

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("skip " + fill + " bytes for signature");
            }

            size += inputStream.skip(fill);
        }
Пример #6
0
        /**
         * Constructs a type froma stream
         *
         * @param inputStream An input stream
         * @param indexEntry  The index informations
         * @param length      the length of the data
         * @return The size of the read data
         * @throws IOException if an I/O error occurs.
         */
        public static STRING readFromStream(java.io.DataInputStream inputStream,
                                            IndexEntry indexEntry, long length)
        {//throws IOException {
            if (indexEntry.getType() != RPMIndexType.STRING)
            {
                throw new java.lang.IllegalArgumentException("Type <" + indexEntry.getType()
                                                             + "> does not match <" + RPMIndexType.STRING + ">");
            }

            if (indexEntry.getCount() != 1)
            {
                throw new java.lang.IllegalArgumentException(
                          "There can be only one string per tag of type STRING");
            }

            // initialize temporary space for data
            byte[] stringData = new byte[(int)length];

            // and read it from stream
            inputStream.readFully(stringData);

            String str          = RPMUtil.cArrayToString(stringData, 0);
            STRING stringObject = new STRING(str);

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer(stringObject.toString());
                if (stringObject.size != stringData.Length)
                {
                    logger.warning("STRING size differs (is:" + stringData.Length
                                   + ";should:" + stringObject.size + ")");
                }
            }

            stringObject.size = stringData.Length;

            return(stringObject);
        }
Пример #7
0
        /**
         * Create a header structure from an input stream. <p/> The header
         * structure of a signature or a header can be read and also the index
         * entries containing the tags for this rpm section (signature or
         * header). <p/> Unless we have a raw header from headerUnload or the
         * database, a header is read consisting of the following fields:
         * <code><pre>
         * byte magic[3];      (3  byte)  (8e ad e8)
         * int version;        (1  byte)
         * byte reserved[4];   (4  byte)
         * long num_index;     (4  byte)
         * long num_data;      (4  byte)
         * </pre></code> <p/> Afterwards the index entries are read and then the tags
         * and the correspondig data entries are read.
         *
         * @param inputStream
         *                An inputstream containing rpm file informations
         * @param rawHeader
         *                Are we a raw header (from headerUnload or rpmdb)
         * @throws IOException
         *                 if an error occurs on reading informations out of the
         *                 stream
         */
        public Header(java.io.DataInputStream inputStream, bool rawHeader, Store store)
        {//throws IOException {
            this.store = store;

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("Start Reading Header");
            }

            if (!rawHeader)
            {
                // Read header
                size = HEADER_LENGTH;

                int magic = 0;

                do
                {
                    magic = inputStream.readUnsignedByte();
                    if (magic == 0)
                    {
                        inputStream.skip(7);
                    }
                } while (magic == 0);

                check(magic == 0x8E, "Header magic 0x" + java.lang.Integer.toHexString(magic)
                      + " != 0x8E");
                magic = inputStream.readUnsignedByte();
                check(magic == 0xAD, "Header magic 0x" + java.lang.Integer.toHexString(magic)
                      + " != 0xAD");
                magic = inputStream.readUnsignedByte();
                check(magic == 0xE8, "Header magic 0x" + java.lang.Integer.toHexString(magic)
                      + " != 0xE8");
                version = inputStream.readUnsignedByte();

                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("version: " + version);
                }

                // skip reserved bytes
                inputStream.skipBytes(4);
            }

            indexNumber = inputStream.readInt();

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("indexes available: " + indexNumber);
            }

            indexDataSize = inputStream.readInt();

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("index data size: " + indexDataSize);
            }

            // Read indexes
            // make sure to sort them in order of offset to
            // be able to read the store without jumping arround in
            // the file
            java.util.TreeSet <IndexEntry> _indexes = new java.util.TreeSet <IndexEntry>(new IAC_IndexesComparator());

            for (int i = 0; i < this.indexNumber; i++)
            {
                IndexEntry index = new IndexEntry(inputStream);

                _indexes.add(index);
                size += index.getSize();
            }

            indexes = new IndexEntry[0];
            indexes = (IndexEntry[])_indexes.toArray(indexes);

            // Read store
            for (int i = 0; i < indexes.Length; i++)
            {
                IndexEntry index = indexes[i];

                // if (index.getType().equals(RPMIndexType.STRING_ARRAY) ||
                // index.getType().equals(RPMIndexType.STRING) ||
                // index.getType().equals(RPMIndexType.I18NSTRING)) {
                // if (i < (indexes.length - 1)) {
                // IndexEntry next = indexes[i + 1];
                //
                // length = next.getOffset() - index.getOffset();
                // } else {
                // length = indexDataSize - index.getOffset();
                // }
                //
                // // and initialize temporary space for data
                // stringData = new byte[(int) length];
                //
                // // and read it from stream
                // inputStream.readFully(stringData);
                // }
                DataTypeIf dataObject = null;

                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("Reading for tag '"
                                 + store.getTagNameForId(index.getTag()) + "' '"
                                 + index.getCount() + "' entries of type '"
                                 + index.getType().getName() + "'");
                }

                dataObject = TypeFactory
                             .createFromStream(inputStream, index,
                                               (i < (indexes.Length - 1)) ? (indexes[i + 1]
                                                                             .getOffset() - index.getOffset())
                            : (indexDataSize - index.getOffset()));

                // adjust size
                size += dataObject.getSize();

                store.setTag(index.getTag(), dataObject);
            }

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("");
            }

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("Finished Reading Header");
            }
        }
Пример #8
0
 /**
  * Construct a header structure for the given input stream.
  *
  * @param inputStream
  * @throws IOException
  */
 public Header(java.io.DataInputStream inputStream, Store store)
     :// throws IOException {
     this(inputStream, false, store)
 {
 }
Пример #9
0
 public RPMHeader(java.io.DataInputStream inputStream, bool raw, Store store)
     ://throws IOException {
     base(inputStream, raw, store)
 {
 }
Пример #10
0
        /**
         * Read informations of a rpm file out of an input stream.
         *
         * @param rpmInputStream The input stream representing the rpm file
         * @throws IOException if an error occurs during read of the rpm file
         */
        private void readFromStream(java.io.InputStream rpmInputStream)
        {//throws IOException {
            ByteCountInputStream allCountInputStream = new ByteCountInputStream(
                rpmInputStream);

            java.io.InputStream inputStream = new java.io.DataInputStream(allCountInputStream);

            lead      = new RPMLead((java.io.DataInputStream)inputStream);
            signature = new RPMSignature((java.io.DataInputStream)inputStream, store);

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("Signature Size: " + signature.getSize());
            }

            header = new RPMHeader((java.io.DataInputStream)inputStream, store);

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("Header Size: " + header.getSize());
            }

            DataTypeIf payloadTag    = getTag("PAYLOADFORMAT");
            String     payloadFormat = payloadTag != null?payloadTag.toString()
                                           : "cpio";

            DataTypeIf payloadCompressionTag = getTag("PAYLOADCOMPRESSOR");
            String     payloadCompressor     = payloadCompressionTag != null?payloadCompressionTag
                                               .toString()
                                                   : "gzip";

            if (payloadFormat.equals("cpio"))
            {
                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("PAYLOADCOMPRESSOR: " + payloadCompressor);
                }

                if (payloadCompressor.equals("gzip"))
                {
                    inputStream = new GzipCompressorInputStream(allCountInputStream);
                }
                else if (payloadCompressor.equals("bzip2"))
                {
                    inputStream = new BZip2CompressorInputStream(allCountInputStream);
                }
                else if (payloadCompressor.equals("lzma"))
                {
                    try
                    {
                        java.io.PipedOutputStream pout = new java.io.PipedOutputStream();
                        inputStream = new java.io.PipedInputStream(pout);
                        byte[] properties = new byte[5];
                        if (allCountInputStream.read(properties, 0, 5) != 5)
                        {
                            throw (new java.io.IOException("input .lzma is too short"));
                        }
                        SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();
                        decoder.SetDecoderProperties(properties);
                        long outSize = 0;
                        for (int i = 0; i < 8; i++)
                        {
                            int v = allCountInputStream.read();
                            if (v < 0)
                            {
                                throw (new java.io.IOException("lzma error : Can't Read 1"));
                            }
                            outSize |= ((long)v) << (8 * i);
                        }
                        if (outSize == -1)
                        {
                            outSize = java.lang.Long.MAX_VALUE;
                        }

                        Decode decoderRunnable = new Decode(decoder,
                                                            allCountInputStream, pout, outSize);
                        java.lang.Thread t = new java.lang.Thread(decoderRunnable, "LZMA Decoder");
                        t.start();
                    }
                    catch (java.lang.NoClassDefFoundError)
                    {
                        String message = "No LZMA library found. Attach p7zip library to classpath (http://p7zip.sourceforge.net/)";
                        logger.severe(message);
                        throw new java.io.IOException(message);
                    }
                }
                else if (payloadCompressor.equals("none"))
                {
                    inputStream = allCountInputStream;
                }
                else
                {
                    throw new java.io.IOException("Unsupported compressor type "
                                                  + payloadCompressor);
                }

                ByteCountInputStream    countInputStream = new ByteCountInputStream(inputStream);
                CpioArchiveInputStream  cpioInputStream  = new CpioArchiveInputStream(countInputStream);
                CpioArchiveEntry        readEntry;
                java.util.List <String> fileNamesList = new java.util.ArrayList <String>();
                String fileEntry;
                while ((readEntry = cpioInputStream.getNextCPIOEntry()) != null)
                {
                    if (logger.isLoggable(java.util.logging.Level.FINER))
                    {
                        logger.finer("Read CPIO entry: " + readEntry.getName()
                                     + " ;mode:" + readEntry.getMode());
                    }
                    if (readEntry.isRegularFile() || readEntry.isSymbolicLink() ||
                        readEntry.isDirectory())
                    {
                        fileEntry = readEntry.getName();
                        if (fileEntry.startsWith("./"))
                        {
                            fileEntry = fileEntry.substring(1);
                        }
                        fileNamesList.add(fileEntry);
                    }
                }
                store.setTag("FILENAMES", TypeFactory.createSTRING_ARRAY((String[])fileNamesList.toArray(new String[fileNamesList.size()])));

                setHeaderTagFromSignature("ARCHIVESIZE", "PAYLOADSIZE");
                // check ARCHIVESIZE with countInputStream.getCount();
                Object archiveSizeObject = getTag("ARCHIVESIZE");
                if (archiveSizeObject != null)
                {
                    if (archiveSizeObject is INT32)
                    {
                        int archiveSize = ((INT32)archiveSizeObject).getData()[0];
                        if (archiveSize != countInputStream.getCount())
                        {
                            new java.io.IOException("ARCHIVESIZE not correct");
                        }
                    }
                }
                store.setTag("J_ARCHIVESIZE", TypeFactory
                             .createINT64(new long[] { countInputStream.getCount() }));
            }
            else
            {
                throw new java.io.IOException("Unsupported Payload type " + payloadFormat);
            }

            // filling in signatures
            // TODO: check signatures!
            setHeaderTagFromSignature("SIGSIZE", "SIZE");
            setHeaderTagFromSignature("SIGLEMD5_1", "LEMD5_1");
            setHeaderTagFromSignature("SIGPGP", "PGP");
            setHeaderTagFromSignature("SIGLEMD5_2", "LEMD5_2");
            setHeaderTagFromSignature("SIGMD5", "MD5");
            setHeaderTagFromSignature("SIGGPG", "GPG");
            setHeaderTagFromSignature("SIGPGP5", "PGP5");
            setHeaderTagFromSignature("DSAHEADER", "DSA");
            setHeaderTagFromSignature("RSAHEADER", "RSA");
            setHeaderTagFromSignature("SHA1HEADER", "SHA1");

            store.setTag("J_FILESIZE", TypeFactory
                         .createINT64(new long[] { allCountInputStream.getCount() }));

            rpmInputStream.close();
        }
Пример #11
0
        protected internal RPMLead(java.io.DataInputStream inputStream)
        {//throws IOException {
            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("Start Reading Lead");
            }

            try
            {
                int magic = inputStream.readUnsignedByte();
                check(magic == 0xED, "Lead magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xED");
                magic = inputStream.readUnsignedByte();
                check(magic == 0xAB, "Lead magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xAB");
                magic = inputStream.readUnsignedByte();
                check(magic == 0xEE, "Lead magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xEE");
                magic = inputStream.readUnsignedByte();
                check(magic == 0xDB, "Lead magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xDB");
                major = inputStream.readUnsignedByte();
                check(major < 5, "Major Number should be less than 5");

                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("major: " + major);
                }

                minor = inputStream.readUnsignedByte();

                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("minor: " + minor);
                }

                int uS = inputStream.readUnsignedShort();
                //LeadType lt;
                type = LeadType.getLeadType(uS);
                //type = LeadType.getLeadType(inputStream.readUnsignedShort());

                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("type: " + type.getName());
                }
                arch = LeadArchitecture.getLeadArchitecture(inputStream.readUnsignedShort());

                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("arch: " + arch.getName());
                }

                byte[] nameBuf = new byte[66];

                inputStream.readFully(nameBuf);
                name = RPMUtil.cArrayToString(nameBuf, 0);

                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("name: " + name);
                }

                os = LeadOS.getLeadOS(inputStream.readUnsignedShort());

                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("os: " + os.getName());
                }

                sigType = LeadSignature.getLeadSignature(inputStream.readUnsignedShort());

                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("sigType: " + sigType.getName());
                }

                inputStream.skipBytes(16);

                check(!type.equals(LeadType.UNKNOWN), "Type is not specified");
                check(!sigType.equals(LeadType.UNKNOWN), "Signaturetype is not specified");
            }
            finally
            {
                if (logger.isLoggable(java.util.logging.Level.FINER))
                {
                    logger.finer("Finished Reading Lead");
                }
            }
        }