Exemple #1
0
        static void Main(string[] args)
        {
            NidList list = NidList.FromFile("psplibdoc.xml");

            List <string> paths = new List <string>();

            paths.AddRange(new string[] {
                //@"C:\Dev\Noxa.Emulation\pspsdk\src",
                @"C:\Dev\pspsdk\src",
            });
            CodeFinder finder = new CodeFinder();

            foreach (string path in paths)
            {
                finder.AddPath(path);
            }

            // These are ones that give us trouble
            List <string> functionIgnores = new List <string>();

            if (UseIgnores == true)
            {
                foreach (string ignore in File.ReadAllLines(IgnoreList))
                {
                    if (ignore.Length == 0)
                    {
                        continue;
                    }
                    string trimmed = ignore.Trim();
                    if (functionIgnores.Contains(trimmed) == false)
                    {
                        functionIgnores.Add(trimmed);
                    }
                }

                Console.WriteLine(" - Loaded a list of {0} functions to ignore", functionIgnores.Count);
            }

            // PRXs we don't want
            List <string> prxIgnores = new List <string>();

            prxIgnores.Add("kd/vaudio.prx");                    // we just want kd/vaudio_game.prx

            List <string> prxForces = new List <string>();

            Dictionary <string, PrxLibrary> dupeList = new Dictionary <string, PrxLibrary>(1000);

            foreach (PrxFile prx in list.Files)
            {
                if (prxIgnores.Contains(prx.FileName) == true)
                {
                    Console.WriteLine(" - Ignoring PRX {0} ({1})", prx.Name, prx.FileName);
                    continue;
                }

                bool force = (FullDump == true) || (prxForces.Contains(prx.FileName) == true);

                foreach (PrxLibrary library in prx.Libraries)
                {
                    if (force == false)
                    {
                        if ((library.Flags & PrxLibrary.UserFlag) == 0x0)
                        {
                            Console.WriteLine(" - Ignoring library {0} in prx {1}; flags {2:X8}", library.Name, prx.Name, library.Flags);
                            continue;
                        }
                    }

                    foreach (PrxFunction function in library.Functions)
                    {
                        if ((functionIgnores.Contains(function.Name) == true) ||
                            (function.Name.StartsWith("_") == true))
                        {
                            function.Ignored = true;
                            continue;
                        }

                        if (IgnoreNonScePrefixed == true)
                        {
                            if (function.Name.StartsWith("sce") == false)
                            {
                                Console.WriteLine(" - Ignoring {0}::{1} because non-sce", library.Name, function.Name);
                                function.Ignored = true;
                            }
                        }

                        if (dupeList.ContainsKey(function.Name) == true)
                        {
                            PrxLibrary existing = dupeList[function.Name];
                            Console.WriteLine("!! duplicate function found");
                            function.Ignored = true;
                            //Debugger.Break();
                        }
                        else
                        {
                            dupeList.Add(function.Name, library);
                            finder.AddRequest(string.Format(" {0}(", function.Name), function);
                        }
                    }
                }
            }

            finder.Search();

            Console.WriteLine("Found {0} references, missing {1}.", finder.FoundRequests.Count, finder.PendingRequests.Count);

            using (StreamWriter writer = new StreamWriter("hooks.txt"))
            {
                foreach (PrxFile prx in list.Files)
                {
                    if (prxIgnores.Contains(prx.FileName) == true)
                    {
                        continue;
                    }

                    foreach (PrxLibrary library in prx.Libraries)
                    {
                        if (FullDump == false)
                        {
                            if ((library.Flags & PrxLibrary.UserFlag) == 0x0)
                            {
                                continue;
                            }
                        }

                        foreach (PrxFunction function in library.Functions)
                        {
                            if (function.Ignored == true)
                            {
                                continue;
                            }

                            if (function.Source != null)
                            {
                                string returnType;
                                string argFormat = string.Empty;
                                try
                                {
                                    string[] argTypes;
                                    string   transformed = TransformDeclaration(function.Name, function.Source.DeclarationBlock, out returnType, out argTypes);
                                    foreach (string arg in argTypes)
                                    {
                                        argFormat += EncodeType(arg);
                                    }
                                }
                                catch
                                {
                                    argFormat  = "xxxxxx";
                                    returnType = "int";
                                }
                                //Debug.WriteLine( string.Format( "{0} -> {1};{2}", function.Source.DeclarationBlock, argFormat, EncodeType( returnType ) ) );
                                writer.WriteLine("0;{0};0x{1:X8};{2};{3};{4}", prx.Name, function.NID, function.Name, (argFormat.Length == 0) ? "v" : argFormat, EncodeType(returnType));
                            }
                            else
                            {
                                // Not found
                                //Debug.WriteLine( string.Format( "{0}::{1} not found", prx.Name, function.NID ) );
                                writer.WriteLine("0;{0};0x{1:X8};{2};{3};{4}", prx.Name, function.NID, function.Name, "xxxxxx", "x");
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static NidList FromFile(string xmlFile)
        {
            if (File.Exists(xmlFile) == false)
            {
                Console.WriteLine("NidList: File not found: {0}", xmlFile);
                return(null);
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(xmlFile);
            }
            catch (Exception ex)
            {
                Console.WriteLine("NidList: Could not load XML document {0}; possibly malformed.", xmlFile);
                Console.WriteLine(ex.ToString());
                return(null);
            }

            NidList list = new NidList();

            list.Files = new List <PrxFile>(1024);
            int fileCount     = 0;
            int libraryCount  = 0;
            int functionCount = 0;

            foreach (XmlElement fileElement in doc.SelectNodes("/PSPLIBDOC/PRXFILES/PRXFILE"))
            {
                PrxFile file = new PrxFile();
                file.FileName = fileElement.SelectSingleNode("PRX").InnerText;
                file.Name     = fileElement.SelectSingleNode("PRXNAME").InnerText;
                Debug.Assert((file.Name != null) && (file.Name.Length > 0));

                file.Libraries = new List <PrxLibrary>(10);
                foreach (XmlElement libraryElement in fileElement.SelectNodes("LIBRARIES/LIBRARY"))
                {
                    PrxLibrary lib = new PrxLibrary();
                    lib.File = file;

                    lib.Name = libraryElement.SelectSingleNode("NAME").InnerText;
                    Debug.Assert((lib.Name != null) && (lib.Name.Length > 0));
                    lib.Flags = Convert.ToInt32(libraryElement.SelectSingleNode("FLAGS").InnerText, 16);

                    lib.Functions = new List <PrxFunction>(64);
                    foreach (XmlElement functionElement in libraryElement.SelectNodes("FUNCTIONS/FUNCTION"))
                    {
                        PrxFunction func = new PrxFunction();
                        func.Library = lib;

                        func.Name = functionElement.SelectSingleNode("NAME").InnerText;
                        Debug.Assert((func.Name != null) && (func.Name.Length > 0));
                        func.NID = Convert.ToInt32(functionElement.SelectSingleNode("NID").InnerText, 16);

                        functionCount++;
                        lib.Functions.Add(func);
                    }

                    libraryCount++;
                    file.Libraries.Add(lib);
                }

                fileCount++;
                list.Files.Add(file);
            }

            Console.WriteLine("NidList: Loaded {0} functions in {1} libraries from {2} prxs", functionCount, libraryCount, fileCount);

            return(list);
        }
Exemple #3
0
        public static NidList FromFile( string xmlFile )
        {
            if( File.Exists( xmlFile ) == false )
            {
                Console.WriteLine( "NidList: File not found: {0}", xmlFile );
                return null;
            }

            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load( xmlFile );
            }
            catch( Exception ex )
            {
                Console.WriteLine( "NidList: Could not load XML document {0}; possibly malformed.", xmlFile );
                Console.WriteLine( ex.ToString() );
                return null;
            }

            NidList list = new NidList();
            list.Files = new List<PrxFile>( 1024 );
            int fileCount = 0;
            int libraryCount = 0;
            int functionCount = 0;

            foreach( XmlElement fileElement in doc.SelectNodes( "/PSPLIBDOC/PRXFILES/PRXFILE" ) )
            {
                PrxFile file = new PrxFile();
                file.FileName = fileElement.SelectSingleNode( "PRX" ).InnerText;
                file.Name = fileElement.SelectSingleNode( "PRXNAME" ).InnerText;
                Debug.Assert( ( file.Name != null ) && ( file.Name.Length > 0 ) );

                file.Libraries = new List<PrxLibrary>( 10 );
                foreach( XmlElement libraryElement in fileElement.SelectNodes( "LIBRARIES/LIBRARY" ) )
                {
                    PrxLibrary lib = new PrxLibrary();
                    lib.File = file;

                    lib.Name = libraryElement.SelectSingleNode( "NAME" ).InnerText;
                    Debug.Assert( ( lib.Name != null ) && ( lib.Name.Length > 0 ) );
                    lib.Flags = Convert.ToInt32( libraryElement.SelectSingleNode( "FLAGS" ).InnerText, 16 );

                    lib.Functions = new List<PrxFunction>( 64 );
                    foreach( XmlElement functionElement in libraryElement.SelectNodes( "FUNCTIONS/FUNCTION" ) )
                    {
                        PrxFunction func = new PrxFunction();
                        func.Library = lib;

                        func.Name = functionElement.SelectSingleNode( "NAME" ).InnerText;
                        Debug.Assert( ( func.Name != null ) && ( func.Name.Length > 0 ) );
                        func.NID = Convert.ToInt32( functionElement.SelectSingleNode( "NID" ).InnerText, 16 );

                        functionCount++;
                        lib.Functions.Add( func );
                    }

                    libraryCount++;
                    file.Libraries.Add( lib );
                }

                fileCount++;
                list.Files.Add( file );
            }

            Console.WriteLine( "NidList: Loaded {0} functions in {1} libraries from {2} prxs", functionCount, libraryCount, fileCount );

            return list;
        }