Esempio n. 1
0
        //UINT32 openflags() const { return m_openflags; }

        //-------------------------------------------------
        //  hash - returns the hash for a file
        //-------------------------------------------------
        public util.hash_collection hashes(string types)
        {
            // determine the hashes we already have
            string already_have = m_hashes.hash_types();

            // determine which hashes we need
            string needed = "";

            foreach (char scan in types)
            {
                if (already_have.find_first_of(scan) == npos)
                {
                    needed += scan;
                }
            }

            // if we need nothing, skip it
            if (string.IsNullOrEmpty(needed))
            {
                return(m_hashes);
            }

            // load the ZIP file if needed
            if (compressed_file_ready())
            {
                return(m_hashes);
            }

            if (m_file == null)
            {
                return(m_hashes);
            }

            // if we have ZIP data, just hash that directly
            if (!m_zipdata.empty())
            {
                m_hashes.compute(new Pointer <u8>(m_zipdata), (uint32_t)m_zipdata.size(), needed);  //m_hashes.compute(&m_zipdata[0], m_zipdata.size(), needed.c_str());
                return(m_hashes);
            }

            // read the data if we can
            MemoryU8 filedata = m_file.buffer();  //const u8 *filedata = (const u8 *)m_file->buffer();

            if (filedata == null)
            {
                return(m_hashes);
            }

            // compute the hash
            uint64_t length;

            if (!m_file.length(out length))
            {
                m_hashes.compute(new PointerU8(filedata), (uint32_t)length, needed);
            }

            return(m_hashes);
        }
Esempio n. 2
0
        //UINT32 openflags() const { return m_openflags; }

        //-------------------------------------------------
        //  hash - returns the hash for a file
        //-------------------------------------------------
        public util.hash_collection hashes(string types)
        {
            // determine the hashes we already have
            string already_have = m_hashes.hash_types();

            // determine which hashes we need
            string needed = "";

            for (int scanIdx = 0; scanIdx < types.Length; scanIdx++)
            {
                if (already_have.IndexOf(types[scanIdx], 0) == -1)
                {
                    needed += types[scanIdx];
                }
            }

            // if we need nothing, skip it
            if (string.IsNullOrEmpty(needed))
            {
                return(m_hashes);
            }

            // load the ZIP file if needed
            if (compressed_file_ready())
            {
                return(m_hashes);
            }

            if (m_file == null)
            {
                return(m_hashes);
            }

            // if we have ZIP data, just hash that directly
            if (!m_zipdata.empty())
            {
                m_hashes.compute(new ListBytesPointer(m_zipdata), (UInt32)m_zipdata.size(), needed.c_str());
                return(m_hashes);
            }

            // read the data if we can
            ListBytes filedata = m_file.buffer();

            if (filedata == null)
            {
                return(m_hashes);
            }

            // compute the hash
            m_hashes.compute(new ListBytesPointer(filedata), (UInt32)m_file.size(), needed);

            return(m_hashes);
        }