示例#1
0
        public static string ExportForDecompiling(string[] input, byte[] buff, uint address)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("# =============== S U B	R O U T	I N E =======================================");
            sb.AppendLine();
            sb.AppendLine("sub_" + address.ToString("X8") + ":");
            uint        pos          = address;
            List <uint> FoundTargets = new List <uint>();

            for (int i = 0; i < buff.Length; i += 4)
            {
                uint opc    = PPC.SwapEndian(BitConverter.ToUInt32(buff, i));
                uint target = 0;
                if (PPC.isBranchOpc(opc) && PPC.calcBranchTarget(opc, pos + (uint)i, out target) && target > address && target < address + buff.Length)
                {
                    FoundTargets.Add(target);
                }
            }
            foreach (string line in input)
            {
                if (FoundTargets.Contains(pos))
                {
                    sb.AppendLine("loc_" + pos.ToString("X8") + ":");
                }
                uint opc    = PPC.SwapEndian(BitConverter.ToUInt32(buff, (int)(pos - address)));
                uint target = 0;
                if (PPC.isBranchOpc(opc) && PPC.calcBranchTarget(opc, pos, out target))
                {
                    int    end = line.IndexOf("0x");
                    string tmp = line.Substring(0, end);
                    if (FoundTargets.Contains(target))
                    {
                        sb.AppendLine("\t\t" + tmp + "loc_" + target.ToString("X8"));
                    }
                    else
                    {
                        sb.AppendLine("\t\t" + tmp + "sub_" + target.ToString("X8"));
                    }
                }
                else
                {
                    sb.AppendLine("\t\t" + line);
                }
                pos += 4;
            }
            sb.AppendLine("# End of function sub_" + address.ToString("X8"));
            return(sb.ToString());
        }
示例#2
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;
            }
        }
示例#3
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);
                    }
                }
            }
        }