Ejemplo n.º 1
0
        /// <summary>
        /// Builds a list of addresses that will be used as a jump or call vector.
        /// </summary>
        /// <param name="addrTable">The address at which the table starts.</param>
        /// <param name="limit">The number of bytes that comprise the table</param>
        /// <param name="permutation">If not null, a permutation of the items in the table</param>
        /// <param name="stride">The size of the individual addresses in the table.</param>
        /// <param name="state">Current processor state.</param>
        /// <returns></returns>
        private List <Address> BuildTable(Address addrTable, int limit, int[] permutation, int stride, ProcessorState state)
        {
            List <Address> vector = new List <Address>();

            if (permutation != null)
            {
                int cbEntry = stride;
                int iMax    = 0;
                for (int i = 0; i < permutation.Length; ++i)
                {
                    if (permutation[i] > iMax)
                    {
                        iMax = permutation[i];
                    }
                    var entryAddr = (uint)(addrTable - program.Image.BaseAddress) + (uint)(permutation[i] * cbEntry);
                    var addr      = Address.Ptr32(program.Image.ReadLeUInt32(entryAddr));                //$BUG: will fail on 64-bit arch.
                    vector.Add(addr);
                }
            }
            else
            {
                ImageReader rdr    = scanner.CreateReader(addrTable);
                int         cItems = limit / (int)stride;
                var         image  = program.Image;
                var         arch   = program.Architecture;
                for (int i = 0; i < cItems; ++i)
                {
                    var entryAddr = program.Architecture.ReadCodeAddress(stride, rdr, state);
                    if (!image.IsValidAddress(entryAddr))
                    {
                        scanner.Warn(addrTable, "The call or jump table has invalid addresses; stopping.");
                        break;
                    }
                    vector.Add(entryAddr);
                }
                cbTable = limit;
            }
            return(vector);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds a list of addresses that will be used as a jump or call vector.
        /// </summary>
        /// <param name="addrTable">The address at which the table starts.</param>
        /// <param name="limit">The number of bytes that comprise the table</param>
        /// <param name="permutation">If not null, a permutation of the items in the table</param>
        /// <param name="stride">The size of the individual addresses in the table.</param>
        /// <param name="state">Current processor state.</param>
        /// <returns>The target addresses reached by the vector</returns>
        public List <Address> BuildTable(Address addrTable, int limit, int[] permutation, int stride, ProcessorState state)
        {
            List <Address> vector = new List <Address>();

            if (permutation != null)
            {
                int cbEntry = stride;
                int iMax    = 0;
                for (int i = 0; i < permutation.Length; ++i)
                {
                    if (permutation[i] > iMax)
                    {
                        iMax = permutation[i];
                    }
                    var entryAddr = addrTable + (uint)(permutation[i] * cbEntry);
                    var addr      = program.Architecture.ReadCodeAddress(0, program.CreateImageReader(entryAddr), state);
                    vector.Add(addr);
                }
            }
            else
            {
                ImageReader rdr      = scanner.CreateReader(addrTable);
                int         cItems   = limit / stride;
                var         imageMap = program.ImageMap;
                var         arch     = program.Architecture;
                for (int i = 0; i < cItems; ++i)
                {
                    var entryAddr = program.Architecture.ReadCodeAddress(stride, rdr, state);
                    if (!imageMap.IsValidAddress(entryAddr))
                    {
                        scanner.Warn(addrTable, "The call or jump table has invalid addresses; stopping.");
                        break;
                    }
                    vector.Add(entryAddr);
                }
                TableByteSize = limit;
            }
            return(vector);
        }