Ejemplo n.º 1
0
        ///<summary>
        /// Updates the selection status bar with data from the specified DataView,
        /// if the specified DataView is active
        ///</summary>
        public void UpdateSelection(DataView dv)
        {
            if (dataBook.NPages == 0)
            {
                return;
            }

            DataView curdv = ((DataViewDisplay)dataBook.CurrentPageWidget).View;

            if (curdv != dv)
            {
                return;
            }

            Bless.Util.Range sel = dv.Selection;

            SelectionStatusbar.Pop(0);
            string str;

            if (sel.IsEmpty() == true)
            {
                str = Catalog.GetString("Selection: None");
            }
            else
            {
                string startString = BaseConverter.ConvertToString(sel.Start, numberBase, true, true, 1);
                string endString   = BaseConverter.ConvertToString(sel.End, numberBase, true, true, 1);
                string sizeString  = BaseConverter.ConvertToString(sel.Size, numberBase, true, true, 1);

                str = string.Format(Catalog.GetString("Selection: {0} to {1}") + " " + Catalog.GetPluralString("({2} byte)", "({2} bytes)", (int)sel.Size),
                                    startString, endString, sizeString);
            }

            SelectionStatusbar.Push(0, str);
        }
Ejemplo n.º 2
0
        protected override void DoOperation()
        {
            Util.Range m;
            match      = new Util.Range();
            firstMatch = null;

            numReplaced = 0;

            strategy.Buffer.BeginActionChaining();
            strategy.Buffer.ModifyAllowed         = false;
            strategy.Buffer.FileOperationsAllowed = false;
            strategy.Buffer.EmitEvents            = false;

            while ((m = strategy.FindNext()) != null)
            {
                if (firstMatch == null)
                {
                    firstMatch = new Util.Range(m);
                }

                match.Start = m.Start;
                match.End   = m.End;

                lock (strategy.Buffer.LockObj) {
                    strategy.Buffer.ModifyAllowed = true;
                    strategy.Buffer.Replace(m.Start, m.End, replacePattern);
                    strategy.Buffer.ModifyAllowed = false;
                }

                // start next search after the replaced pattern
                strategy.Position = m.Start + replacePattern.Length;

                numReplaced++;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the current selection. It makes sure that the selection is sorted.
        /// </summary>
        public void SetSelection(long start, long end)
        {
            AreaGroup areaGroup = dvDisplay.Layout.AreaGroup;

            // check whether the selection has really
            // changed...
            if (areaGroup.Areas.Count <= 0)
            {
                return;
            }

            Bless.Util.IRange sel = areaGroup.Selection;

            // if there is no change, don't do anything
            if (sel.Start == start && sel.End == end)
            {
                return;
            }

            Bless.Util.Range newSel = new Bless.Util.Range(start, end);
            newSel.Sort();

            areaGroup.Selection = newSel;

            if (SelectionChanged != null)
            {
                SelectionChanged(this);
            }
        }
Ejemplo n.º 4
0
        public void SplitAtomicTest()
        {
            Range r = new Range(0, 10);
            Range s = new Range(4, 6);

            Range[] ra = new Range[] { new Range(), new Range(), new Range() };

            Assert.IsTrue(r.Equals(new Range(0, 10)), "#0");

            Range.SplitAtomic(ra, r, s);
            Assert.AreEqual(new Range(0, 3), ra[0], "#1.0");
            Assert.AreEqual(new Range(4, 6), ra[1], "#1.1");
            Assert.AreEqual(new Range(7, 10), ra[2], "#1.2");

            s = new Range(0, 4);
            Range.SplitAtomic(ra, r, s);
            Assert.AreEqual(new Range(), ra[0], "#2.0");
            Assert.AreEqual(new Range(0, 4), ra[1], "#2.1");
            Assert.AreEqual(new Range(5, 10), ra[2], "#2.2");

            s = new Range(6, 10);
            Range.SplitAtomic(ra, r, s);
            Assert.AreEqual(new Range(0, 5), ra[0], "#3.0");
            Assert.AreEqual(new Range(6, 10), ra[1], "#3.1");
            Assert.AreEqual(new Range(), ra[2], "#3.2");

            s = new Range(0, 10);
            Range.SplitAtomic(ra, r, s);
            Assert.AreEqual(new Range(), ra[0], "#4.0");
            Assert.AreEqual(new Range(0, 10), ra[1], "#4.1");
            Assert.AreEqual(new Range(), ra[2], "#4.2");
        }
Ejemplo n.º 5
0
        private void UpdateSelection(bool abyss)
        {
            //System.Console.WriteLine("* (1) Start: {0},{1},{2} End: {3},{4},{5}", selStartPos.First, selStartPos.Second, selStartPos.Digit, selEndPos.First, selEndPos.Second, selEndPos.Digit);
            Bless.Util.Range r;
            if (selStartPos.Second <= selEndPos.First)
            {
                r = new Bless.Util.Range(ValidateOffset(selStartPos.Second), ValidateOffset(selEndPos.First));
            }
            else
            {
                r = new Bless.Util.Range(ValidateOffset(selEndPos.Second), ValidateOffset(selStartPos.First));
            }

            //System.Console.WriteLine("Selection is ({0}, {1}) Expected ({2}, {3})", dataView.Selection.Start, dataView.Selection.End, r.Start, r.End);
            // if nothing is selected and cursor position has changed externally
            if (dataView.Selection.IsEmpty() && dataView.CursorOffset != selStartPos.Second)
            {
                long offset = dataView.CursorOffset;
                selStartPos.First  = offset - (abyss ? 1 : 0);
                selStartPos.Second = offset;
                selStartPos.Digit  = dataView.CursorDigit;
                selEndPos          = selStartPos;
                //System.Console.WriteLine("* (2) Start: {0},{1},{2} End: {3},{4},{5}", selStartPos.First, selStartPos.Second, selStartPos.Digit, selEndPos.First, selEndPos.Second, selEndPos.Digit);
            }
            else if (!dataView.Selection.IsEmpty() && !r.Equals(dataView.Selection))
            {
                selStartPos.Second = dataView.Selection.Start;
                selStartPos.First  = selStartPos.Second - 1;
                selEndPos.First    = dataView.Selection.End;
                selEndPos.Second   = selEndPos.First + 1;
            }
            //System.Console.WriteLine("* Selection is ({0}, {1}) Expected ({2}, {3}) Fixed ({4}, {5})", dataView.Selection.Start, dataView.Selection.End, r.Start, r.End, selStartPos.Second, selEndPos.First);
        }
Ejemplo n.º 6
0
        ///<summary>
        /// Called when an asynchronous Find Next/Previous operation finishes.
        ///</summary>
        void FindAsyncCallback(IAsyncResult ar)
        {
            GenericFindOperation state = (GenericFindOperation)ar.AsyncState;

            ThreadedAsyncOperation.OperationResult result = state.Result;
            Range match = state.Match;

            DataView dv = null;

            // find DataView that owns bb
            foreach (DataViewDisplay dvtemp in dataBook.Children)
            {
                if (dvtemp.View.Buffer == strategy.Buffer)
                {
                    dv = dvtemp.View;
                    break;
                }
            }

            // decide what to do based on the result of the find operation
            switch (result)
            {
            case ThreadedAsyncOperation.OperationResult.Finished:
                if (match != null)
                {
                    lastFound = match;
                    dv.SetSelection(match.Start, match.End);                    //System.Console.WriteLine("Found at {0}-{1}", r.Start, r.End);
                    dv.MoveCursor(match.End + 1, 0);
                    dv.Display.MakeOffsetVisible(match.Start, DataViewDisplay.ShowType.Closest);
                }
                else
                {
                    lastFound.Clear();
                }
                break;

            case ThreadedAsyncOperation.OperationResult.Cancelled:
                dv.MoveCursor(strategy.Position, 0);
                dv.Display.MakeOffsetVisible(strategy.Position, DataViewDisplay.ShowType.Closest);
                break;

            case ThreadedAsyncOperation.OperationResult.CaughtException:
                break;

            default:
                break;
            }

            inUse = false;

            // if user provided a callback, call it now
            if (userFindAsyncCallback != null)
            {
                userFindAsyncCallback(ar);
            }

            // notify that the find operation has finished
            findFinishedEvent.Set();
        }
Ejemplo n.º 7
0
        public GenericFindOperation(IFindStrategy ifs, ProgressCallback pc,
                                    AsyncCallback ac) : base(pc, ac, true)
        {
            strategy = ifs;

            strategy.Cancelled = false;
            match = null;
        }
Ejemplo n.º 8
0
        public DataBookFinder(DataBook db, ProgressCallback pc)
        {
            // connect with databook
            dataBook         = db;
            lastFound        = new Bless.Util.Range();
            firstTime        = true;
            inUse            = false;
            progressCallback = pc;

            // initialize events
            findFinishedEvent = new AutoResetEvent(false);
        }
Ejemplo n.º 9
0
        private void OnCopyOffsetActivated(object o, EventArgs args)
        {
            if (dataBook.NPages == 0)
            {
                return;
            }
            DataView dv = ((DataViewDisplay)dataBook.CurrentPageWidget).View;

            saved_offset    = dv.CursorOffset;
            saved_selection = dv.Selection;

            clipboard.SetWithData(clipboardTargets, new ClipboardGetFunc(OnClipboardGet),
                                  new ClipboardClearFunc(OnClipboardClear));
        }
Ejemplo n.º 10
0
        public CopyOffsetPlugin(Window mw, UIManager uim)
        {
            mainWindow        = mw;
            uiManager         = uim;
            pluginPreferences = new CopyOffsetPreferences();
            number_base       = 10;
            saved_offset      = 0;
            saved_selection   = new Bless.Util.Range();

            name        = "CopyOffset";
            author      = "Alexandros Frantzis";
            description = "Adds to copy the current offset (or range)";
            loadAfter.Add("EditOperations");
        }
Ejemplo n.º 11
0
        ///<summary>
        /// Called when an asynchronous Replace All operation finishes.
        ///</summary>
        void ReplaceAllAsyncCallback(IAsyncResult ar)
        {
            ReplaceAllOperation state = (ReplaceAllOperation)ar.AsyncState;

            ThreadedAsyncOperation.OperationResult result = state.Result;
            Range firstMatch = state.FirstMatch;

            DataView dv = null;

            // find DataView that owns bb
            foreach (DataViewDisplay dvtemp in dataBook.Children)
            {
                if (dvtemp.View.Buffer == strategy.Buffer)
                {
                    dv = dvtemp.View;
                    break;
                }
            }

            // decide what to do based on the result of the Replace All operation
            if (result == ThreadedAsyncOperation.OperationResult.Cancelled)
            {
                dv.Buffer.Undo();
            }
            // if we have replaced at least one occurence,
            else if (result == ThreadedAsyncOperation.OperationResult.Finished && firstMatch != null)
            {
                lastFound = state.Match;
                // save the cursor state for undo/redo
                dv.CursorUndoDeque.AddFront(new CursorState(firstMatch.Start, 0, lastFound.Start + state.ReplacePattern.Length, 0));

                // move cursor after final replacement
                dv.SetSelection(-1, -1);
                dv.MoveCursor(lastFound.Start + state.ReplacePattern.Length, 0);
                dv.Display.MakeOffsetVisible(lastFound.Start + state.ReplacePattern.Length, DataViewDisplay.ShowType.Closest);
            }

            inUse = false;

            // if user provided a callback, call it now
            if (userFindAsyncCallback != null)
            {
                userFindAsyncCallback(ar);
            }

            // notify that the replace all operation has finished
            findFinishedEvent.Set();
        }
Ejemplo n.º 12
0
        ///<summary>Load the widget with data from the DataView's selection</summary>
        public void LoadWithSelection(DataView dv)
        {
            // load selection only if it isn't very large
            if (dv.Selection.Size > 0)
            {
                Bless.Util.Range sel = dv.Selection;

                FromEntry.Text = sel.Start.ToString();
                ToEntry.Text   = sel.End.ToString();
            }
            else
            {
                FromEntry.Text = dv.CursorOffset.ToString();
            }

            FromEntry.GrabFocus();
        }
Ejemplo n.º 13
0
        public void SplitAtomic1Test()
        {
            Range r = new Range(10, 20);
            Range s = new Range(8, 13);

            Range[] ra = new Range[] { new Range(), new Range(), new Range() };

            Range.SplitAtomic(ra, r, s);
            Assert.AreEqual(new Range(), ra[0], "#1.0");
            Assert.AreEqual(new Range(8, 13), ra[1], "#1.1");
            Assert.AreEqual(new Range(14, 20), ra[2], "#1.2");

            s = new Range(16, 26);
            Range.SplitAtomic(ra, r, s);
            Assert.AreEqual(new Range(10, 15), ra[0], "#2.0");
            Assert.AreEqual(new Range(16, 26), ra[1], "#2.1");
            Assert.AreEqual(new Range(), ra[2], "#2.2");
        }
Ejemplo n.º 14
0
        public void DifferenceTest()
        {
            Range r1 = new Range(5, 10);
            Range r2 = new Range(6, 9);
            Range r3 = new Range();

            r1.Difference(r2, r3);
            Assert.AreEqual(5, r1.Start, "#1");
            Assert.AreEqual(5, r1.End, "#2");

            Assert.AreEqual(10, r3.Start, "#3");
            Assert.AreEqual(10, r3.End, "#4");

            Range r4 = new Range(5, 10);
            Range r5 = new Range(5, 8);

            r4.Difference(r5, r3);
            Assert.AreEqual(9, r4.Start, "#5");
            Assert.AreEqual(10, r4.End, "#6");
            Assert.AreEqual(true, r3.IsEmpty(), "#7");
        }
Ejemplo n.º 15
0
        public void IntersectTest()
        {
            Range r1 = new Range(5, 10);
            Range r2 = new Range(6, 9);

            r1.Intersect(r2);
            Assert.AreEqual(6, r1.Start);
            Assert.AreEqual(9, r1.End);

            Range r3 = new Range(5, 10);
            Range r4 = new Range(4, 8);

            r3.Intersect(r4);
            Assert.AreEqual(5, r3.Start);
            Assert.AreEqual(8, r4.End);

            Range r5 = new Range(5, 10);
            Range r6 = new Range(10, 14);

            r5.Intersect(r6);
            Assert.AreEqual(10, r5.Start);
            Assert.AreEqual(10, r5.End);
        }
Ejemplo n.º 16
0
        ///<summary>Check if the specified range of bytes in a ByteBuffer equals a byte pattern</summary>
        bool RangeEqualsPattern(ByteBuffer bb, Bless.Util.Range sel, byte[] pattern)
        {
            int i   = 0;
            int len = pattern.Length;

            if (sel.IsEmpty())
            {
                return(false);
            }

            while (i < len && pattern[i] == bb[sel.Start + i])
            {
                i++;
            }

            if (i != len)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 17
0
        ///<summary>Load the widget with data from the DataView's selection</summary>
        public void LoadWithSelection(DataView dv)
        {
            ByteBuffer bb = dv.Buffer;

            // load selection only if it isn't very large
            if (this.Sensitive == true && dv.Selection.Size <= 1024 && dv.Selection.Size > 0)
            {
                Bless.Util.Range sel = dv.Selection;

                byte[] ba = new byte[sel.Size];
                for (int i = 0; i < sel.Size; i++)
                {
                    ba[i] = bb[sel.Start + i];
                }

                bool decodingOk  = false;
                Area focusedArea = dv.FocusedArea;

                if (focusedArea != null)
                {
                    switch (focusedArea.Type)
                    {
                    case "ascii":
                        string result = Encoding.ASCII.GetString(ba);
                        // if the byte sequence cannot be displayed correctly
                        // as ascii, eg it contains a zero byte, use hexadecimal
                        if (result.IndexOf('\x00') != -1)
                        {
                            decodingOk = false;
                        }
                        else
                        {
                            SearchAsComboBox.Active = (int)ComboIndex.Text;
                            SearchPatternEntry.Text = result;
                            decodingOk = true;
                        }
                        break;

                    case "decimal":
                        SearchAsComboBox.Active = (int)ComboIndex.Decimal;
                        SearchPatternEntry.Text = ByteArray.ToString(ba, 10);
                        decodingOk = true;
                        break;

                    case "octal":
                        SearchAsComboBox.Active = (int)ComboIndex.Octal;
                        SearchPatternEntry.Text = ByteArray.ToString(ba, 8);
                        decodingOk = true;
                        break;

                    case "binary":
                        SearchAsComboBox.Active = (int)ComboIndex.Binary;
                        SearchPatternEntry.Text = ByteArray.ToString(ba, 2);
                        decodingOk = true;
                        break;
                    }            // end switch
                }

                if (!decodingOk)
                {
                    SearchAsComboBox.Active = (int)ComboIndex.Hexadecimal;
                    SearchPatternEntry.Text = ByteArray.ToString(ba, 16);
                }
            }
        }
Ejemplo n.º 18
0
 protected override void DoOperation()
 {
     match = strategy.FindNext();
 }