private void cbProcedures_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbProcedures.SelectedIndex < 0)
            {
                return;
            }

#if false
            ProcedureItem item = (ProcedureItem)cbProcedures.SelectedItem;

            // Display only the rows that belong to this procedure.
            DisplayViewport(item.BeginRowIndex, item.EndRowIndex);

            // Navigate to the entry point of the procedure. Note that
            // this may not be the first instruction in the procedure's
            // range, though it usually is.
            Navigate(item.Procedure.EntryPoint, false, true);
#endif
        }
Exemple #2
0
        public ListingViewModel(BinaryImage image)
        {
            this.image = image;

            // Make a dictionary that maps a location to the error at that location.
            // TODO: there may be multiple errors at a single location.
            Dictionary <LinearPointer, Error> errorMap = new Dictionary <LinearPointer, Error>();

            foreach (Error error in image.Errors)
            {
                errorMap[error.Location.LinearAddress] = error;
            }

            // Display analyzed code and data.
            Pointer address = image.BaseAddress;

            for (var i = image.StartAddress; i < image.EndAddress;)
            {
                ByteProperties b = image[i];

                if (IsLeadByteOfCode(b))
                {
                    if (b.BasicBlock != null && b.BasicBlock.StartAddress == i)
                    {
                        rows.Add(new LabelListingRow(0, b.BasicBlock));
                    }

                    Instruction insn = image.DecodeInstruction(b.Address);
                    rows.Add(new CodeListingRow(0, b.Address, insn, image.GetBytes(i, insn.EncodedLength)));
                    address = b.Address + insn.EncodedLength;
                    i      += insn.EncodedLength;
                }
                else if (IsLeadByteOfData(b))
                {
                    var j = i + 1;
                    while (j < image.EndAddress &&
                           image[j].Type == ByteType.Data &&
                           !image[j].IsLeadByte)
                    {
                        j++;
                    }

                    rows.Add(new DataListingRow(0, b.Address, image.GetBytes(i, j - i)));
                    address = b.Address + (j - i);
                    i       = j;
                }
                else
                {
                    if (errorMap.ContainsKey(i))
                    {
                        //    rows.Add(new ErrorListingRow(errorMap[i]));
                    }
                    var j = i + 1;
                    while (j < image.EndAddress &&
                           !IsLeadByteOfCode(image[j]) &&
                           !IsLeadByteOfData(image[j]))
                    {
                        j++;
                    }

                    rows.Add(new BlankListingRow(0, address, image.GetBytes(i, j - i)));
                    try
                    {
                        address += (j - i);
                    }
                    catch (AddressWrappedException)
                    {
                        address = Pointer.Invalid;
                    }
                    i = j;
                }
            }

            // Create a sorted array containing the address of each row.
            rowAddresses = new LinearPointer[rows.Count];
            for (int i = 0; i < rows.Count; i++)
            {
                rowAddresses[i] = rows[i].Location.LinearAddress;
            }

            // Create a ProcedureItem view object for each non-empty
            // procedure.
            // TODO: display an error for empty procedures.
            foreach (Procedure proc in image.Procedures)
            {
                if (proc.IsEmpty)
                {
                    continue;
                }

                ProcedureItem item = new ProcedureItem(proc);
                //var range = proc.Bounds;
                //item.FirstRowIndex = FindRowIndex(range.Begin);
                //item.LastRowIndex = FindRowIndex(range.End - 1);

                // TBD: need to check broken instruction conditions
                // as well as leading/trailing unanalyzed bytes.
                procItems.Add(item);
            }

            // Create segment items.
            foreach (Segment segment in image.Segments)
            {
                segmentItems.Add(new SegmentItem(segment));
            }
        }