Exemplo n.º 1
0
        /// <summary>
        /// Find the difference of the two loaded file and add to lists the results
        /// </summary>
        private void FindDifference()
        {
            ClearUI();

            if (FirstFile.FileName == string.Empty || SecondFile.FileName == string.Empty)
            {
                return;
            }

            FileDiffBlockList.Children.Clear();

            //load the difference
            _differences = FirstFile.Compare(SecondFile).ToList();

            //Load list of difference
            var cbb = new CustomBackgroundBlock();
            int j   = 0;

            foreach (ByteDifference byteDifference in _differences)
            {
                //create or update custom background block
                if (j == 0)
                {
                    cbb = new CustomBackgroundBlock(byteDifference.BytePositionInStream, ++j, RandomBrushes.PickBrush());
                }
                else
                {
                    cbb.Length = ++j;
                }

                if (!_differences.Any(c => c.BytePositionInStream == byteDifference.BytePositionInStream + 1))
                {
                    j = 0;

                    new BlockListItem(cbb).With(c =>
                    {
                        c.PatchButtonClick += BlockItem_PatchButtonClick;
                        c.Click            += BlockItem_Click;
                        _blockListItem.Add(c);
                    });

                    //add to hexeditor
                    FirstFile.CustomBackgroundBlockItems.Add(cbb);
                    SecondFile.CustomBackgroundBlockItems.Add(cbb);
                }
            }

            //Update progressbar
            BlockItemProgress.Maximum = _blockListItem.Count();
            UpdateListofBlockItem();

            //refresh editor
            FirstFile.RefreshView();
            SecondFile.RefreshView();

            //Enable patch button
            PatchButton.IsEnabled = true;
        }
        public void Update(MetaDataTagItem.Data data, TableDefinitionModel tableDef)
        {
            if (data == null)
            {
                SelectedItemSize      = 0;
                ByteStream            = null;
                SelectedItemBytesLeft = 0;
                HasUniformByteSize    = false;
                BackgroundBlocks.Clear();

                for (int i = 0; i < Fields.Count; i++)
                {
                    UpdateViewModel(Fields[i], new byte[0], 0);
                }

                return;
            }

            HasUniformByteSize = _activeMetaDataContent.SelectedTagType.DataItems.Select(x => x.Size).Distinct().Count() == 1;
            SelectedItemSize   = data.Size;

            ByteStream = new MemoryStream(data.Bytes, data.Start, data.Size);
            BackgroundBlocks.Clear();

            int counter  = 0;
            var endIndex = tableDef.Definition.ColumnDefinitions.Count();
            int index    = data.Start;

            for (int i = 0; i < endIndex; i++)
            {
                if (i < endIndex)
                {
                    var byteParserType = tableDef.Definition.ColumnDefinitions[i].Type;
                    var parser         = ByteParserFactory.Create(byteParserType);
                    parser.TryDecode(data.Bytes, index, out _, out var bytesRead, out _);
                    index += bytesRead;

                    var block = new CustomBackgroundBlock()
                    {
                        Description = tableDef.Definition.ColumnDefinitions[i].Name,
                        Color       = counter % 2 == 0 ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Yellow),
                        Length      = bytesRead,
                        StartOffset = index - bytesRead - data.Start,
                    };
                    BackgroundBlocks.Add(block);

                    counter++;
                }
            }

            SelectedItemBytesLeft = SelectedItemSize - (index - data.Start);

            for (int i = 0; i < Fields.Count; i++)
            {
                UpdateViewModel(Fields[i], data.Bytes, index);
            }
        }
        private void FindDifference()
        {
            ClearUI();

            if (FirstFile.FileName == string.Empty || SecondFile.FileName == string.Empty)
            {
                return;
            }

            var cbb = new CustomBackgroundBlock();
            int j   = 0;

            _differences = FirstFile.Compare(SecondFile)
                           .ToList()
                           .OrderBy(c => c.BytePositionInStream);

            long previousPosition = _differences.First().BytePositionInStream;

            //Load list of difference

            ///////////// NOT COMPLETED... IS IN DEBUG....

            foreach (ByteDifference byteDifference in _differences)
            {
                if (j == 0)
                {
                    cbb = new CustomBackgroundBlock(byteDifference.BytePositionInStream, ++j, RandomBrushes.PickBrush());
                }
                else
                {
                    cbb.Length = ++j;
                }

                if (byteDifference.BytePositionInStream != previousPosition + 1)
                {
                    j = 0;

                    new BlockListItem(cbb).With(c =>
                    {
                        c.PatchButtonClick += BlockItem_PatchButtonClick;

                        FileDiffBlockList.Items.Add(c);
                    });

                    //add to hexeditor
                    FirstFile.CustomBackgroundBlockItems.Add(cbb);
                    SecondFile.CustomBackgroundBlockItems.Add(cbb);
                }

                previousPosition = byteDifference.BytePositionInStream;
            }

            //refresh editor
            FirstFile.RefreshView();
            SecondFile.RefreshView();
        }
Exemplo n.º 4
0
        /// <summary>
        /// NOT COMPLETED... bugged and need optimisation ;)
        /// </summary>
        private void FindDifference()
        {
            ClearUI();

            if (FirstFile.FileName == string.Empty || SecondFile.FileName == string.Empty)
            {
                return;
            }

            var cbb = new CustomBackgroundBlock();
            int j   = 0;

            _differences = FirstFile.Compare(SecondFile).ToList();

            //Load list of difference
            foreach (ByteDifference byteDifference in _differences.OrderBy(c => c.BytePositionInStream))
            {
                //create or update custom background block
                if (j == 0)
                {
                    cbb = new CustomBackgroundBlock(byteDifference.BytePositionInStream, ++j, RandomBrushes.PickBrush());
                }
                else
                {
                    cbb.Length = ++j;
                }


                if (_differences.Any(c => c.BytePositionInStream == byteDifference.BytePositionInStream + 1))
                {
                    j = 0;

                    new BlockListItem(cbb).With(c =>
                    {
                        c.PatchButtonClick += BlockItem_PatchButtonClick;

                        FileDiffBlockList.Items.Add(c);
                    });

                    //add to hexeditor
                    FirstFile.CustomBackgroundBlockItems.Add(cbb);
                    SecondFile.CustomBackgroundBlockItems.Add(cbb);
                }
            }

            //refresh editor
            FirstFile.RefreshView();
            SecondFile.RefreshView();
        }
Exemplo n.º 5
0
 public CustomBackgroundBlockEventArgs(CustomBackgroundBlock customBlock) => CustomBlock = customBlock;
Exemplo n.º 6
0
        public BlockListItem(CustomBackgroundBlock cbb)
        {
            InitializeComponent();

            CustomBlock = cbb;
        }