Example #1
0
        public void GotoAddress(uint address)
        {
            currAddress = address;
            uint pos = address;

            listBox2.Items.Clear();
            byte[]   buf      = GetFunctionBytes(address, toolStripButton6.Checked);
            string[] opDisAsm = Disassembler.Disassemble(buf, pb1);
            for (uint i = 0; i < opDisAsm.Length; i++)
            {
                string opBytes = buf[i * 4].ToString("X2") + " " + buf[i * 4 + 1].ToString("X2") + " " + buf[i * 4 + 2].ToString("X2") + " " + buf[i * 4 + 3].ToString("X2");
                string hasBP   = Debugger.breakPoints.Contains(pos) ? "* " : "";
                string comment = "";
                uint   u       = PPC.SwapEndian(BitConverter.ToUInt32(buf, (int)i * 4));
                uint   target;
                if (PPC.isBranchOpc(u) && PPC.calcBranchTarget(u, pos, out target))
                {
                    comment = "\t#[loc_" + target.ToString("X8") + "]";
                }
                listBox2.Items.Add(hasBP + pos.ToString("X8") + "\t: " + opBytes + "\t" + opDisAsm[i] + comment);
                pos += 4;
            }
        }
Example #2
0
        public static int DFSBranchSearch(byte[] buff, uint start, int pos)
        {
            if (DFSLookUp.ContainsKey((uint)(start + pos * 4)))
            {
                return(DFSLookUp[(uint)(start + pos * 4)]);
            }
            uint target = 0;
            uint opc    = PPC.SwapEndian(BitConverter.ToUInt32(buff, pos * 4));

            if (PPC.hintSubReturn(opc))
            {
                DFSLookUp.Add((uint)(start + pos * 4), pos);
                return(pos);
            }
            if (!PPC.isBranchOpc(opc))
            {
                int next = pos + 1;
                while (true)
                {
                    if (next * 4 >= buff.Length)
                    {
                        next = buff.Length / 4 - 1;
                        DFSLookUp.Add((uint)(start + pos * 4), next);
                        return(next);
                    }
                    uint tmp = PPC.SwapEndian(BitConverter.ToUInt32(buff, next * 4));
                    if (PPC.hintSubReturn(tmp))
                    {
                        DFSLookUp.Add((uint)(start + pos * 4), next);
                        return(next);
                    }
                    if (PPC.isBranchOpc(tmp))
                    {
                        int result = DFSBranchSearch(buff, start, next);
                        DFSLookUp.Add((uint)(start + pos * 4), result);
                        return(result);
                    }
                    next++;
                }
            }
            else
            {
                uint type = PPC.getOPCD(opc);
                int  nextN, nextT;
                if (PPC.calcBranchTarget(opc, start + (uint)pos * 4, out target) && target >= start && target < start + buff.Length)
                {
                    if (target >= start + pos * 4)
                    {
                        int next = (int)(target - start) / 4;
                        if (PPC.getLK(opc) || type != 18)
                        {
                            nextT = DFSBranchSearch(buff, start, next);
                            nextN = DFSBranchSearch(buff, start, pos + 1);
                            int result = getBiggest(new int[] { nextT, nextN });
                            DFSLookUp.Add((uint)(start + pos * 4), result);
                            return(result);
                        }
                        else
                        {
                            int result = DFSBranchSearch(buff, start, next);
                            DFSLookUp.Add((uint)(start + pos * 4), result);
                            return(result);
                        }
                    }
                    else
                    {
                        if (PPC.getLK(opc) || type != 18)
                        {
                            int result = DFSBranchSearch(buff, start, pos + 1);
                            DFSLookUp.Add((uint)(start + pos * 4), result);
                            return(result);
                        }
                        else
                        {
                            DFSLookUp.Add((uint)(start + pos * 4), pos);
                            return(pos);
                        }
                    }
                }
                else
                {
                    if (pos < buff.Length / 4 - 1 && (PPC.getLK(opc) || type != 18))
                    {
                        int result = DFSBranchSearch(buff, start, pos + 1);
                        DFSLookUp.Add((uint)(start + pos * 4), result);
                        return(result);
                    }
                    else
                    {
                        DFSLookUp.Add((uint)(start + pos * 4), pos);
                        return(pos);
                    }
                }
            }
        }