Example #1
0
        private void StandardCodeAddressStuff(UInt32 address, UInt32 value, UInt32 add)
        {
            CodeContent nCode = CodeController.CodeTextBoxToCodeContent(textBoxCodeEntries.Text);
            //UInt32 cAddressR = 0x80000000;
            UInt32 rAddressR;
            UInt32 offset;

            // base address is masked differently than pointer offset
            if (radioButtonBA.Checked)
            {
                rAddressR = address & 0xFE000000;
            }
            else
            {
                // TODO the po doesn't actually have this restriction
                // but for now we keep it like the ba
                //rAddressR = address & 0xFEFFFFFF;
                rAddressR = address & 0xFE000000;
                add      += 0x10000000;
            }

            // Do we need to change the ba or po?
            bool changeBAorPO = false;

            if ((address & 0xFE000000) != 0x80000000)
            {
                changeBAorPO = true;
            }

            if (changeBAorPO)
            {
                if (radioButtonBA.Checked)
                {
                    nCode.addLine(0x42000000, rAddressR);
                }
                else
                {
                    nCode.addLine(0x4A000000, rAddressR);
                }
            }

            // Add the actual code
            offset = address - rAddressR + add;
            nCode.addLine(offset, value);

            // Add terminator if necessary
            if (changeBAorPO)
            {
                nCode.addLine(0xE0000000, 0x80008000);
            }

            textBoxCodeEntries.Text = CodeController.CodeContentToCodeTextBox(nCode);
        }
        private void StandardCodeAddressStuff(uint address, uint value, uint add)
        {
            CodeContent nCode = CodeController.CodeTextBoxToCodeContent(textBoxCodeEntries.Text);
            uint        rAddressR;
            uint        offset;

            if (radioButtonBA.Checked)
            {
                rAddressR = address & 0xFE000000;
            }
            else
            {
                rAddressR = address & 0xFE000000;
                add      += 0x10000000;
            }

            bool changeBAorPO = false;

            if ((address & 0xFE000000) != 0x80000000)
            {
                changeBAorPO = true;
            }

            if (changeBAorPO)
            {
                if (radioButtonBA.Checked)
                {
                    nCode.addLine(0x42000000, rAddressR);
                }
                else
                {
                    nCode.addLine(0x4A000000, rAddressR);
                }
            }

            offset = address - rAddressR + add;
            nCode.addLine(offset, value);

            if (changeBAorPO)
            {
                nCode.addLine(0xE0000000, 0x80008000);
            }

            textBoxCodeEntries.Text = CodeController.CodeContentToCodeTextBox(nCode);
        }
 public void AddCode(CodeContent content, int index)
 {
     if (index > -1 && index < codeOutput.Items.Count)
     {
         CodeContent newCode = new CodeContent();
         foreach (CodeLine line in content.lines)
         {
             newCode.addLine(line.left, line.right);
         }
         codeOutput.Items[index].Tag = newCode;
     }
     SendModified();
 }
Example #4
0
        private void enableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CodeContent code = GCTCodeContents[GCTCodeList.SelectedIndices[0]];
            CodeContent uncommentedCode = new CodeContent();
            for (int i = 0; i < code.lines.Count; i++)
            {
                uncommentedCode.addLine(code.lines[i].left, code.lines[i].right, true);
            }

            GCTCodeValues.Text = CodeController.CodeContentToCodeTextBox(uncommentedCode);
        }
Example #5
0
        private void existingGCTCodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // If there is no selected existing code, make a new one
            if (GCTCodeList.SelectedItems.Count == 0)
            {
                makeCode_Click(sender, e);
                return;
            }

            if (SearchResults.SelectedRows.Count == 0)
                return;
            List<UInt32> addresses = new List<UInt32>();
            UInt32 address;
            int i;
            for (i = 0; i < SearchResults.SelectedRows.Count; i++)
            {
                address = search.GetAddress(SearchResults.SelectedRows[i].Index);
                addresses.Add(address);
            }

            addresses.Sort();

            CodeContent nCode = new CodeContent();
            UInt32 cAddressR = 0x80000000;
            UInt32 rAddressR;
            UInt32 offset;
            bool firstLine = false;
            UInt32 add;
            switch (search.searchSize)
            {
                case SearchSize.Bit8:
                    add = 0;
                    break;
                case SearchSize.Bit16:
                    add = 0x02000000;
                    break;
                default:
                    add = 0x04000000;
                    break;
            }

            for (i = 0; i < addresses.Count; i++)
            {
                rAddressR = addresses[i] & 0xFE000000;
                if (firstLine && cAddressR != rAddressR && cAddressR != 0x80000000)
                    nCode.addLine(0xE0000000, 0x80008000);
                if (cAddressR != rAddressR)
                    if (rAddressR != 0x80000000)
                        nCode.addLine(0x42000000, rAddressR);
                cAddressR = rAddressR;

                offset = addresses[i] + add - rAddressR;
                nCode.addLine(offset, 0);

                firstLine = true;
            }
            if (cAddressR != 0x80000000)
                nCode.addLine(0xE0000000, 0x80008000);

            // Must de-select current item before changing it
            int index = GCTCodeList.SelectedItems[0].Index;

            GCTCodeList.Items[index].Selected = false;

            GCTCodeContents.AddCode(nCode, index);

            GCTCodeList.Items[index].Selected = true;

            MainControl.SelectedTab = GCTPage;
        }
Example #6
0
        private void disAssGCTCode_Click(object sender, EventArgs e)
        {
            try
            {
                UInt32 address = disassembler.disAddress;
                UInt32 value = gecko.peek(address);
                CodeContent nCode = new CodeContent();
                UInt32 memReg = address & 0xFE000000;
                bool addDelimiters = false;
                if (memReg != 0x80000000)
                    addDelimiters = true;
                if (addDelimiters)
                    nCode.addLine(0x42000000, memReg);
                address = address - memReg + 0x04000000;
                nCode.addLine(address, value);
                if (addDelimiters)
                    nCode.addLine(0xE0000000, 0x80008000);
                int nCodeId = GCTCodeContents.Count;
                String name;
                if (!InputBox.Show("Code name", "Insert code name", "New code", out name))
                {
                    name = "New code " + (nCodeId + 1).ToString();
                }
                //nCode.name = "New code " + (nCodeId + 1).ToString();
                GCTCodeContents.AddCode(nCode, name);

                GCTCodeList.Items[nCodeId].Selected = true;
                MainControl.SelectedTab = GCTPage;
            }
            catch (EUSBGeckoException exc)
            {
                exceptionHandling.HandleException(exc);
            }
        }
Example #7
0
        private void memViewAddGCTCode_Click(object sender, EventArgs e)
        {
            try
            {
                UInt32 vAdd = viewer.selectedAddress;
                UInt32 cRegion = vAdd & 0xFE000000;
                UInt32 value = gecko.peek(vAdd);
                vAdd = vAdd - cRegion + 0x04000000;
                int nCodeId = GCTCodeContents.Count;

                String name;
                if (!InputBox.Show("Code name", "Insert code name", "New code", out name))
                {
                    name = "New code " + (nCodeId + 1).ToString();
                }
                CodeContent nCode = new CodeContent();
                bool addlines = false;
                if (cRegion != 0x80000000)
                {
                    addlines = true;
                    nCode.addLine(0x42000000, cRegion);
                }
                nCode.addLine(vAdd, value);
                if (addlines)
                    nCode.addLine(0xE0000000, 0x80008000);

                GCTCodeContents.AddCode(nCode, name);
                MainControl.SelectedTab = GCTPage;
            }
            catch (EUSBGeckoException exc)
            {
                exceptionHandling.HandleException(exc);
            }
        }
Example #8
0
        private void makeCode_Click(object sender, EventArgs e)
        {
            if (SearchResults.SelectedRows.Count == 0)
                return;
            List<UInt32> addresses = new List<UInt32>();
            UInt32 address;
            int i;
            for (i = 0; i < SearchResults.SelectedRows.Count; i++)
            {
                address = search.GetAddress(SearchResults.SelectedRows[i].Index);
                addresses.Add(address);
            }

            addresses.Sort();

            CodeContent nCode = new CodeContent();
            UInt32 cAddressR = 0x80000000;
            UInt32 rAddressR;
            UInt32 offset;
            bool firstLine = false;
            UInt32 add;
            switch (search.searchSize)
            {
                case SearchSize.Bit8:
                    add = 0;
                    break;
                case SearchSize.Bit16:
                    add = 0x02000000;
                    break;
                default:
                    add = 0x04000000;
                    break;
            }

            int nCodeId = GCTCodeContents.Count;
            //nCode.name = "New code " + (nCodeId + 1).ToString();
            String name;
            if (!InputBox.Show("Code name", "Insert code name", "New code", out name))
            {
                name = "New code " + (nCodeId + 1).ToString();
            }
            for (i = 0; i < addresses.Count; i++)
            {
                rAddressR = addresses[i] & 0xFE000000;
                if (firstLine && cAddressR != rAddressR && cAddressR != 0x80000000)
                    nCode.addLine(0xE0000000, 0x80008000);
                if (cAddressR != rAddressR)
                    if (rAddressR != 0x80000000)
                        nCode.addLine(0x42000000, rAddressR);
                cAddressR = rAddressR;

                offset = addresses[i] + add - rAddressR;
                nCode.addLine(offset, search.GetNewValueFromAddress(addresses[i]));

                firstLine = true;
            }
            if (cAddressR != 0x80000000)
                nCode.addLine(0xE0000000, 0x80008000);
            GCTCodeContents.AddCode(nCode, name);

            GCTCodeList.Items[nCodeId].Selected = true;
            MainControl.SelectedTab = GCTPage;
        }
        public static CodeContent CodeTextBoxToCodeContent(string codeInput)
        {
            string parsedCode     = string.Empty;
            string stripedUnknown = string.Empty;
            int    i;

            for (i = 0; i < codeInput.Length; i++)
            {
                char analyze = codeInput.ToUpper()[i];

                if (char.IsDigit(analyze) || (analyze == '-' || analyze == '/') || ((analyze >= 'A') && (analyze <= 'F')))
                {
                    stripedUnknown += analyze;
                }
            }

            int        deactSigns = 0;
            List <int> deactCodes = new List <int>();

            for (i = 0; i < stripedUnknown.Length; i++)
            {
                char analyze = stripedUnknown[i];

                if (analyze == '-' || analyze == '/')
                {
                    int pos = (i - deactSigns) / 16;
                    if (!deactCodes.Contains(pos))
                    {
                        deactCodes.Add(pos);
                    }
                    deactSigns++;
                }
                else
                {
                    parsedCode += analyze;
                }
            }

            CodeContent ncode = new CodeContent();

            if (parsedCode.Length % 16 != 0)
            {
                MessageBox.Show("Adding 0s to fill up the code");
                int loopCount = 16 - parsedCode.Length % 16;
                for (int j = 0; j < loopCount; j++)
                {
                    parsedCode += "0";
                }
            }

            string hexString;
            uint   left, right;
            bool   enabled;

            for (i = 0; i < parsedCode.Length / 16; i++)
            {
                hexString = parsedCode.Substring(i * 16, 8);
                left      = Convert.ToUInt32(hexString, 16);

                hexString = parsedCode.Substring(i * 16 + 8, 8);
                right     = Convert.ToUInt32(hexString, 16);

                enabled = !deactCodes.Contains(i);

                ncode.addLine(left, right, enabled);
            }

            return(ncode);
        }
 //codeOutput.Items[i].Tag = value;
 // Adds a Code to the indexed code
 public void AddCode(CodeContent content, int index)
 {
     if (index > -1 && index < codeOutput.Items.Count)
     {
         //CodeContent oldCode = (CodeContent)(codeOutput.Items[index].Tag);
         CodeContent newCode = new CodeContent();
         //foreach (CodeLine line in oldCode.lines)
         //{
         //    newCode.addLine(line.left, line.right);
         //}
         foreach (CodeLine line in content.lines)
         {
             newCode.addLine(line.left, line.right);
         }
         codeOutput.Items[index].Tag = newCode;
     }
     SendModified();
 }
        public static CodeContent CodeTextBoxToCodeContent(String codeInput)
        {
            String parsedCode = "";
            String stripedUnknown = "";
            int i;

            // Check the text for a valid code
            for (i = 0; i < codeInput.Length; i++)
            {
                Char analyze = codeInput.ToUpper()[i];

                if (Char.IsDigit(analyze) || (analyze == '-' || analyze == '/') || ((analyze >= 'A') && (analyze <= 'F')))
                    stripedUnknown += analyze;
            }

            // Deactivating codes?
            int deactSigns = 0;
            List<int> deactCodes = new List<int>();
            for (i = 0; i < stripedUnknown.Length; i++)
            {
                Char analyze = stripedUnknown[i];

                if (analyze == '-' || analyze == '/')
                {
                    int pos = (i - deactSigns) / 16;
                    if (!deactCodes.Contains(pos))
                        deactCodes.Add(pos);
                    deactSigns++;
                }
                else
                    parsedCode += analyze;
            }

             CodeContent ncode = new CodeContent();

            // Make sure it's the right size too
            if (parsedCode.Length % 16 != 0)
            {
                MessageBox.Show("Adding 0s to fill up the code");
                int loopCount = 16 - parsedCode.Length % 16;
                for (int j = 0; j < loopCount; j++) parsedCode += "0";
            }

            String hexString;
            UInt32 left, right;
            bool enabled;

            for (i = 0; i < parsedCode.Length / 16; i++)
            {
                hexString = parsedCode.Substring(i * 16, 8);
                left = Convert.ToUInt32(hexString, 16);

                hexString = parsedCode.Substring(i * 16 + 8, 8);
                right = Convert.ToUInt32(hexString, 16);

                enabled = !deactCodes.Contains(i);

                ncode.addLine(left, right, enabled);
            }

            return ncode;
        }