Example #1
0
        public static CrackModel CreateModelFromPit(DataModel dataModel)
        {
            CrackModel model = new CrackModel();

            model.Root = BuildFromElement(model, dataModel);

            return(model);
        }
Example #2
0
 public CrackNode(CrackModel model, DataElement element, long startBits, long stopBits)
 {
     Model       = model;
     DataElement = element;
     StartBits   = startBits;
     StopBits    = stopBits;
     Error       = false;
 }
Example #3
0
        private void toolStripButtonRefreshPit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(pitFileName))
            {
                return;
            }

            try
            {
                PitParser parser = new PitParser();
                Dom       dom;
                string    previouslySelectedModelName;
                int       newModelIndex;

                if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(pitFileName)))
                {
                    Directory.SetCurrentDirectory(Path.GetDirectoryName(pitFileName));
                }

                dom = parser.asParser(parserArgs, pitFileName);

                previouslySelectedModelName = (string)toolStripComboBoxDataModel.SelectedItem;

                toolStripComboBoxDataModel.Items.Clear();
                foreach (var model in dom.dataModels.Keys)
                {
                    toolStripComboBoxDataModel.Items.Add(model);
                }

                if ((previouslySelectedModelName != null) && toolStripComboBoxDataModel.Items.Contains(previouslySelectedModelName))
                {
                    newModelIndex = toolStripComboBoxDataModel.Items.IndexOf(previouslySelectedModelName);
                }
                else
                {
                    newModelIndex = toolStripComboBoxDataModel.Items.Count - 1;
                }

                if (toolStripComboBoxDataModel.Items.Count > 0)
                {
                    toolStripComboBoxDataModel.SelectedIndex = newModelIndex;
                }

                treeViewAdv1.BeginUpdate();
                crackModel         = CrackModel.CreateModelFromPit(dom.dataModels[newModelIndex]);
                treeViewAdv1.Model = crackModel;
                treeViewAdv1.EndUpdate();
                treeViewAdv1.Root.Children[0].Expand();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading file: " + ex.ToString());
            }
        }
Example #4
0
        private void toolStripComboBoxDataModel_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                dataModel = toolStripComboBoxDataModel.SelectedItem as string;

                PitParser parser = new PitParser();
                Dom       dom    = parser.asParser(parserArgs, pitFileName);

                treeViewAdv1.BeginUpdate();
                crackModel         = CrackModel.CreateModelFromPit(dom.dataModels[dataModel]);
                treeViewAdv1.Model = crackModel;
                treeViewAdv1.EndUpdate();
                treeViewAdv1.Root.Children[0].Expand();
            }
            catch
            {
            }
        }
Example #5
0
        public static CrackNode BuildFromElement(CrackModel model, DataElementContainer container)
        {
            CrackNode node = new CrackNode(model, container, 0, 0);

            if (container is Choice)
            {
                foreach (var child in ((Choice)container).choiceElements.Values)
                {
                    if (child is DataElementContainer)
                    {
                        var childNode = BuildFromElement(model, child as DataElementContainer);
                        childNode.Parent = node;
                        node.Children.Add(childNode);
                    }
                    else
                    {
                        var childNode = new CrackNode(model, child, 0, 0);
                        childNode.Parent = node;
                        node.Children.Add(childNode);
                    }
                }
            }

            foreach (var child in container)
            {
                if (child is DataElementContainer)
                {
                    var childNode = BuildFromElement(model, child as DataElementContainer);
                    childNode.Parent = node;
                    node.Children.Add(childNode);
                }
                else
                {
                    var childNode = new CrackNode(model, child, 0, 0);
                    childNode.Parent = node;
                    node.Children.Add(childNode);
                }
            }

            return(node);
        }
Example #6
0
        private void toolStripButtonRefreshSample_Click(object sender, EventArgs e)
        {
            var cursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                if (string.IsNullOrEmpty(dataModel) || string.IsNullOrEmpty(sampleFileName) || string.IsNullOrEmpty(pitFileName))
                {
                    return;
                }

                byte[] buff;
                using (Stream sin = new FileStream(sampleFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    buff = new byte[sin.Length];
                    sin.Read(buff, 0, buff.Length);
                }

                PitParser parser;
                Dom       dom;

                parser = new PitParser();
                dom    = parser.asParser(parserArgs, pitFileName);

                treeViewAdv1.BeginUpdate();
                treeViewAdv1.Model = null;
                crackModel         = new CrackModel();

                try
                {
                    BitStream   data    = new BitStream(buff);
                    DataCracker cracker = new DataCracker();
                    cracker.EnterHandleNodeEvent     += new EnterHandleNodeEventHandler(cracker_EnterHandleNodeEvent);
                    cracker.ExitHandleNodeEvent      += new ExitHandleNodeEventHandler(cracker_ExitHandleNodeEvent);
                    cracker.AnalyzerEvent            += new AnalyzerEventHandler(cracker_AnalyzerEvent);
                    cracker.ExceptionHandleNodeEvent += new ExceptionHandleNodeEventHandler(cracker_ExceptionHandleNodeEvent);
                    cracker.CrackData(dom.dataModels[dataModel], data);
                }
                catch (CrackingFailure ex)
                {
                    MessageBox.Show("Error cracking \"" + ex.element.fullName + "\".\n" + ex.Message, "Error Cracking");

                    long endPos = -1;
                    foreach (var element in exceptions)
                    {
                        CrackNode currentModel;
                        if (crackMap.TryGetValue(element, out currentModel))
                        {
                            currentModel.Error = true;

                            if (endPos == -1)
                            {
                                endPos = currentModel.StartBits;
                            }

                            currentModel.StopBits = endPos;

                            if (element.parent != null && crackMap.ContainsKey(element.parent))
                            {
                                crackMap[element.parent].Children.Add(currentModel);
                            }
                        }
                    }
                }

                foreach (var node in crackMap.Values)
                {
                    if (node.DataElement.parent != null)
                    {
                        node.Parent = crackMap[node.DataElement.parent];
                    }
                }

                crackModel.Root    = crackMap.Values.First().Root;
                treeViewAdv1.Model = crackModel;
                treeViewAdv1.EndUpdate();
                treeViewAdv1.Root.Children[0].Expand();

                // No longer needed
                crackMap.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error cracking file: " + ex.ToString());
            }
            finally
            {
                Cursor.Current = cursor;
            }
        }