Пример #1
0
        public void BeginLibrary(PrxLibrary library)
        {
            _tempFile = Path.GetTempFileName();
            _writer   = new StreamWriter(_tempFile);

            _library = library;

            Regex  nameRegex = new Regex("{MODULENAME}");
            string myHeader  = nameRegex.Replace(_header, library.Name);

            _writer.Write(myHeader);

            // ----- Write header
        }
Пример #2
0
        public void BeginLibrary( PrxLibrary library )
        {
            _tempFile = Path.GetTempFileName();
            _writer = new StreamWriter( _tempFile );

            _library = library;

            Regex nameRegex = new Regex( "{MODULENAME}" );
            string myHeader = nameRegex.Replace( _header, library.Name );

            _writer.Write( myHeader );

            // ----- Write header
        }
Пример #3
0
        public string GenerateFileName(PrxLibrary library)
        {
            string fileName = library.Name;

            char[] badChars = Path.GetInvalidFileNameChars();
            for (int n = 0; n < badChars.Length; n++)
            {
                if (fileName.IndexOf(badChars[n]) >= 0)
                {
                    Debugger.Break();
                }
            }

            fileName += FileExt;
            return(Path.Combine(_outputPath, fileName));
        }
Пример #4
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);
            }

            //IOutput output = new FastHLEOutput( paths, @"C:\Dev\Noxa.Emulation\trunk\Noxa.Emulation.Psp.Bios.FastHLE\Modules\" );
            IOutput output = new ManagedHLEOutput(paths, @"C:\Dev\Noxa.Emulation\trunk\Noxa.Emulation.Psp.Bios.ManagedHLE\Modules\");

            // 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>();

            prxForces.Add("kd/usersystemlib.prx");               // Kernel_Library
            prxForces.Add("kd/libatrac3plus.prx");               // sceAtrac3plus
            prxForces.Add("kd/pspnet.prx");
            prxForces.Add("kd/pspnet_inet.prx");
            prxForces.Add("kd/pspnet_resolver.prx");
            prxForces.Add("kd/pspnet_apctl.prx");

            // Libraries that will be merged (in the form of source -> target
            Dictionary <string, string> libraryMerges = new Dictionary <string, string>();

            libraryMerges.Add("sceUtility_netparam_internal", "sceUtility");
            libraryMerges.Add("sceWlanDrv_lib", "sceWlanDrv");
            libraryMerges.Add("sceNetIfhandle_lib", "sceNetIfhandle");
            libraryMerges.Add("sceNetApctl_lib", "sceNetApctl");
            libraryMerges.Add("sceNetAdhocAuth_lib", "sceNetAdhocAuth");

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

            Dictionary <string, PrxLibrary> libraryLookup = new Dictionary <string, PrxLibrary>();

            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 = prxForces.Contains(prx.FileName);

                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;
                        }
                    }

                    libraryLookup.Add(library.Name, library);

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

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

                        if (dupeList.ContainsKey(function.Name) == true)
                        {
                            PrxLibrary existing = dupeList[function.Name];
                            Console.WriteLine("!! duplicate function found");
                            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);

            // Quick hack up to get merged on to parents
            List <PrxLibrary> skipLibraries = new List <PrxLibrary>();

            foreach (KeyValuePair <string, string> pair in libraryMerges)
            {
                PrxLibrary source = libraryLookup[pair.Key];
                PrxLibrary target = libraryLookup[pair.Value];
                target.Merged = source;
                skipLibraries.Add(source);
            }

            foreach (PrxFile prx in list.Files)
            {
                if (prxIgnores.Contains(prx.FileName) == true)
                {
                    continue;
                }

                foreach (PrxLibrary library in prx.Libraries)
                {
                    //if( ( library.Flags & PrxLibrary.UserFlag ) == 0x0 )
                    //    continue;
                    if (skipLibraries.Contains(library) == true)
                    {
                        continue;
                    }

                    bool hasBegun = false;

                    foreach (PrxFunction function in library.Functions)
                    {
                        if (hasBegun == false)
                        {
                            output.BeginLibrary(library);
                        }
                        hasBegun = true;

                        output.WriteFunction(function);
                    }

                    // Repeat for merged
                    if (library.Merged != null)
                    {
                        foreach (PrxFunction function in library.Merged.Functions)
                        {
                            if (hasBegun == false)
                            {
                                output.BeginLibrary(library);
                            }
                            hasBegun = true;

                            output.WriteFunction(function);
                        }
                    }

                    if (hasBegun == true)
                    {
                        output.EndLibrary();
                    }
                }
            }

            //foreach( FindRequest req in finder.FoundRequests )
            //{
            //    Debug.WriteLine( " -- " + ( req.Tag as PrxFunction ).Name );
            //    Debug.WriteLine( req.CommentBlock );
            //    Debug.WriteLine( req.DeclarationBlock );
            //}

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Пример #5
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);
        }
Пример #6
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;
        }
Пример #7
0
        public string GenerateFileName( PrxLibrary library )
        {
            string fileName = library.Name;
            char[] badChars = Path.GetInvalidFileNameChars();
            for( int n = 0; n < badChars.Length; n++ )
            {
                if( fileName.IndexOf( badChars[ n ] ) >= 0 )
                {
                    Debugger.Break();
                }
            }

            fileName += FileExt;
            return Path.Combine( _outputPath, fileName );
        }