private static string GetFixedValue(IByteProvider provider, long start, long length, int fixed_length, bool reverse, Func <byte[], string> func)
            {
                long max_length = provider.Length - start;

                if (max_length < fixed_length)
                {
                    return(string.Empty);
                }
                byte[] ba = new byte[fixed_length];
                if (reverse)
                {
                    for (int i = 0; i < fixed_length; ++i)
                    {
                        ba[fixed_length - i - 1] = provider.ReadByte(i + start);
                    }
                }
                else
                {
                    for (int i = 0; i < fixed_length; ++i)
                    {
                        ba[i] = provider.ReadByte(i + start);
                    }
                }

                return(func(ba));
            }
Example #2
0
            string GetValue(IByteProvider provider, long pos, long length)
            {
                // Read out the bytes
                if ((_hasher != null) && (provider != null) && (pos + length <= provider.Length))
                {
                    byte[] data = new byte[length];

                    for (long i = 0; i < length; i++)
                    {
                        data[i] = provider.ReadByte(pos + i);
                    }

                    byte[] hash = _hasher.ComputeHash(data);

                    StringBuilder builder = new StringBuilder();

                    foreach (byte b in hash)
                    {
                        builder.AppendFormat("{0:X02}", b);
                    }

                    return(builder.ToString());
                }
                else
                {
                    return("");
                }
            }
Example #3
0
        public long Address()
        {
            long k = 1;

            for (long i = 0; i < Provider.Length; ++i)
            {
                int j = 0;
                for (; j < PatternSize; ++j)
                {
                    if (Mask[j] == 0x01)
                    {
                        continue;
                    }
                    if ((Provider.ReadByte(i + j) ^ ByteArray[j]) != 0)
                    {
                        break;
                    }
                }

                if (j == PatternSize)
                {
                    if (k == Result)
                    {
                        return(i);
                    }
                    else
                    {
                        ++k;
                        continue;
                    }
                }
            }

            return(-1);
        }
Example #4
0
        /// <summary>
        /// Shows the bits for the current byte
        /// </summary>
        /// <returns>A string that is like "Bits of byte n° XXX : XXXXXXXX"</returns>
        string Core_ShowBits()
        {
            string result = "";

            byte?         currentByte = null;
            IByteProvider currentFile = CurrentTabIsROM() ?
                                        MainHexBox.ByteProvider :
                                        FileHexBoxes[CurrentTab].ByteProvider;
            uint selection = CurrentAddress;

            if (selection < currentFile.Length)
            {
                currentByte = currentFile.ReadByte(selection);
            }

            BitInfo bitInfo = (currentByte == null) ? null :
                              new BitInfo((byte)currentByte, selection);

            if (bitInfo != null)
            {
                byte currentByteNotNull = (byte)currentByte;
                result = "Bits: " + bitInfo.ToString();
            }

            return(result);
        }
Example #5
0
 private byte[] ByteProviderToArray(IByteProvider b)
 {
     byte[] data = new byte[b.Length];
     for (int i = 0; i < b.Length; i++)
     {
         data[i] = b.ReadByte(i);
     }
     return(data);
 }
Example #6
0
        private byte[] getSelectedBytes(int len)
        {
            IByteProvider p = hexBox1.ByteProvider;

            byte[] b = new byte[len];

            for (int i = 0; i < len; i++)
            {
                b[i] = p.ReadByte(hexBox1.SelectionStart + i);
            }

            return b;
        }
Example #7
0
        private static byte[] GetBytesFromProvider(IByteProvider provider, long pos, long length)
        {
            byte[] data = null;

            // Read out the bytes
            if ((provider != null) && (pos + length <= provider.Length))
            {
                data = new byte[length];

                for (long i = 0; i < length; i++)
                {
                    data[i] = provider.ReadByte(pos + i);
                }
            }

            return(data);
        }
Example #8
0
            string GetValue(IByteProvider provider, long pos, long length)
            {
                ulong ret     = 0;
                int   bytePos = 0;

                while (pos < provider.Length)
                {
                    byte b = provider.ReadByte(pos++);
                    ret |= ((ulong)b & 0x7F) << (bytePos++ *7);
                    if ((b & 0x80) == 0)
                    {
                        break;
                    }
                }

                return(string.Format("{0}/0x{0:X08}", ret));
            }
Example #9
0
            string GetValue(IByteProvider provider, long pos, long length)
            {
                // Read out the bytes
                if ((provider != null) && (pos + length <= provider.Length))
                {
                    byte[] data = new byte[length];

                    for (long i = 0; i < length; i++)
                    {
                        data[i] = provider.ReadByte(pos + i);
                    }

                    return(GetChecksumString(data));
                }
                else
                {
                    return("");
                }
            }
Example #10
0
 public byte ReadByte(long pos)
 {
     return(_provider.ReadByte(pos));
 }
Example #11
0
        /// <summary>
        /// Find and select a range of bytes
        /// </summary>
        /// <param name="data">The data to find</param>
        /// <param name="next">Whether to find the next match or previous match</param>
        /// <returns>True to indicate we found a match</returns>
        public bool FindAndSelect(byte[] data, bool next)
        {
            bool ret = false;

            if ((_provider != null) && (data.Length <= _provider.Length))
            {
                long foundIndex = -1;
                long pos        = hexBox.SelectionStart;

                if (next)
                {
                    if (pos < 0)
                    {
                        pos = 0;
                    }
                    else
                    {
                        pos = pos + 1;
                    }

                    while ((pos + data.Length) <= _provider.Length)
                    {
                        foundIndex = pos;
                        for (long i = 0; i < data.Length; ++i)
                        {
                            if (_provider.ReadByte(i + pos) != data[i])
                            {
                                foundIndex = -1;
                                break;
                            }
                        }

                        if (foundIndex >= 0)
                        {
                            break;
                        }

                        pos++;
                    }
                }
                else
                {
                    if (pos > 0)
                    {
                        pos = pos - 1;

                        while (pos >= 0)
                        {
                            if ((pos + data.Length) < _provider.Length)
                            {
                                foundIndex = pos;
                                for (long i = 0; i < data.Length; ++i)
                                {
                                    if (_provider.ReadByte(i + pos) != data[i])
                                    {
                                        foundIndex = -1;
                                        break;
                                    }
                                }
                            }

                            if (foundIndex >= 0)
                            {
                                break;
                            }

                            pos--;
                        }
                    }
                }

                if (foundIndex >= 0)
                {
                    hexBox.Select(pos, data.Length);
                    hexBox.ScrollByteIntoView(pos + data.Length);
                    hexBox.ScrollByteIntoView(pos);
                    ret = true;
                }
            }

            return(ret);
        }