/// <summary> /// Initializes a new <see cref="BiosFunction"/> instance in the case of a missing function. /// </summary> /// <param name="module">Module containing the function.</param> /// <param name="nid">Unique ID of the function.</param> public BiosFunction(BiosModule module, uint nid) { this.Module = module; this.NID = nid; this.IsMissing = true; this.IsStateless = true; }
/// <summary> /// Initializes a new <see cref="BiosFunction"/> instance with the given parameters. /// </summary> /// <param name="module">Module containing the function.</param> /// <param name="moduleInstance">Current instance of the module containing the function.</param> /// <param name="nid">Unique ID of the function.</param> /// <param name="name">Human-friendly name of the function.</param> /// <param name="isImplemented"><c>true</c> if the function is implemented.</param> /// <param name="isStateless"><c>true</c> if the function does not change the BIOS state.</param> /// <param name="nativeImplementationSuggested"><c>true</c> if a native implementation is suggested.</param> /// <param name="dontTrace"><c>true</c> to not write this function to the trace.</param> /// <param name="methodInfo"><see cref="MethodInfo"/> of the managed implementation of the function.</param> /// <param name="nativePointer">Pointer to the native implementation of the function.</param> public BiosFunction(BiosModule module, IModule moduleInstance, uint nid, string name, bool isImplemented, bool isStateless, bool nativeImplementationSuggested, bool dontTrace, MethodInfo methodInfo, IntPtr nativePointer) { this.Module = module; this.ModuleInstance = moduleInstance; this.NID = nid; this.Name = name; this.IsImplemented = isImplemented; this.IsStateless = isStateless; this.NativeImplementationSuggested = nativeImplementationSuggested; this.DontTrace = dontTrace; this.MethodInfo = methodInfo; this.NativeMethod = nativePointer; ParameterInfo[] ps = methodInfo.GetParameters(); if (ps.Length > 0) { this.ParameterCount = ps.Length; if (ps[0].ParameterType == typeof(IMemory)) { this.ParameterCount--; this.UsesMemorySystem = true; } this.ParameterWidths = new BitArray(this.ParameterCount); int offset = (this.UsesMemorySystem == true) ? 1 : 0; for (int n = 0; n < (ps.Length - offset); n++) { ParameterWidths[n] = (ps[n + offset].ParameterType == typeof(long)); } #if DEBUG // Sanity check to make sure IMemory is always the first argument if (this.UsesMemorySystem == false) { for (int n = 0; n < ps.Length; n++) { Debug.Assert(ps[n].ParameterType != typeof(IMemory)); } } #endif } }
/// <summary> /// Initializes a new <see cref="BiosFunction"/> instance with the given parameters. /// </summary> /// <param name="module">Module containing the function.</param> /// <param name="moduleInstance">Current instance of the module containing the function.</param> /// <param name="nid">Unique ID of the function.</param> /// <param name="name">Human-friendly name of the function.</param> /// <param name="isImplemented"><c>true</c> if the function is implemented.</param> /// <param name="isStateless"><c>true</c> if the function does not change the BIOS state.</param> /// <param name="nativeImplementationSuggested"><c>true</c> if a native implementation is suggested.</param> /// <param name="dontTrace"><c>true</c> to not write this function to the trace.</param> /// <param name="methodInfo"><see cref="MethodInfo"/> of the managed implementation of the function.</param> /// <param name="nativePointer">Pointer to the native implementation of the function.</param> public BiosFunction( BiosModule module, IModule moduleInstance, uint nid, string name, bool isImplemented, bool isStateless, bool nativeImplementationSuggested, bool dontTrace, MethodInfo methodInfo, IntPtr nativePointer ) { this.Module = module; this.ModuleInstance = moduleInstance; this.NID = nid; this.Name = name; this.IsImplemented = isImplemented; this.IsStateless = isStateless; this.NativeImplementationSuggested = nativeImplementationSuggested; this.DontTrace = dontTrace; this.MethodInfo = methodInfo; this.NativeMethod = nativePointer; ParameterInfo[] ps = methodInfo.GetParameters(); if( ps.Length > 0 ) { this.ParameterCount = ps.Length; if( ps[ 0 ].ParameterType == typeof( IMemory ) ) { this.ParameterCount--; this.UsesMemorySystem = true; } this.ParameterWidths = new BitArray( this.ParameterCount ); int offset = ( this.UsesMemorySystem == true ) ? 1 : 0; for( int n = 0; n < ( ps.Length - offset ); n++ ) ParameterWidths[ n ] = ( ps[ n + offset ].ParameterType == typeof( long ) ); #if DEBUG // Sanity check to make sure IMemory is always the first argument if( this.UsesMemorySystem == false ) { for( int n = 0; n < ps.Length; n++ ) Debug.Assert( ps[ n ].ParameterType != typeof( IMemory ) ); } #endif } }
/// <summary> /// Initializes a new <see cref="BiosFunction"/> instance in the case of a missing function. /// </summary> /// <param name="module">Module containing the function.</param> /// <param name="nid">Unique ID of the function.</param> public BiosFunction( BiosModule module, uint nid ) { this.Module = module; this.NID = nid; this.IsMissing = true; this.IsStateless = true; }
private int LoadModule( IMediaFile file, Stream stream, int flags, int option ) { // Load! LoadParameters loadParams = new LoadParameters(); if( file != null ) { loadParams.Path = file.Parent; loadParams.FilePath = file.AbsolutePath; string fileName = file.Name.ToLowerInvariant(); foreach( string blacklisted in _moduleBlacklist ) { if( fileName == blacklisted ) { // Module is blacklisted - ignore Log.WriteLine( Verbosity.Normal, Feature.Bios, "LoadModule: module is blacklisted, ignoring" ); return FakeModuleUID; } } } #if DEBUG loadParams.AppendDatabase = true; #endif // Check to see if it's one we have a decoded version of string kernelLocation = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ); string prxLocation = Path.Combine( kernelLocation, "PRX" ); string lookasidePrx = Path.Combine( prxLocation, file.Name ); if( File.Exists( lookasidePrx ) == true ) { // Load ours instead Log.WriteLine( Verbosity.Normal, Feature.Bios, "LoadModule: lookaside prx found at {0}", lookasidePrx ); stream = File.OpenRead( lookasidePrx ); } Debug.Assert( stream != null ); if( stream == null ) { Log.WriteLine( Verbosity.Critical, Feature.Bios, "LoadModule: unable to load module {0}", file.Name ); return -1; } // Quick check to make sure it isn't encrypted before sending off to loader byte[] magicBytes = new byte[ 4 ]; stream.Read( magicBytes, 0, 4 ); stream.Seek( -4, SeekOrigin.Current ); // 0x7E, 0x50, 0x53, 0x50 = ~PSP bool encrypted = ( ( magicBytes[ 0 ] == 0x7E ) && ( magicBytes[ 1 ] == 0x50 ) && ( magicBytes[ 2 ] == 0x53 ) && ( magicBytes[ 3 ] == 0x50 ) ); //Debug::Assert( encrypted == false ); if( encrypted == true ) { Log.WriteLine( Verbosity.Critical, Feature.Bios, "LoadModule: module {0} is encrypted - unable to load", file.Name ); // We spoof the caller in to thinking we worked right... by just returning 0 ^_^ KModule fakemod = new KModule( _kernel, null ); fakemod.LoadParameters = loadParams; _kernel.AddHandle( fakemod ); if( Diag.IsAttached == true ) Diag.Instance.Client.OnModuleLoaded(); return ( int )fakemod.UID; } LoadResults results = _kernel.Bios._loader.LoadModule( ModuleType.Prx, stream, loadParams ); //Debug.Assert( results.Successful == true ); if( results.Successful == false ) { Log.WriteLine( Verbosity.Critical, Feature.Bios, "LoadModule: loader failed" ); return FakeModuleUID; } if( results.Ignored == true ) { // Faked Log.WriteLine( Verbosity.Normal, Feature.Bios, "LoadModule: ignoring module" ); return FakeModuleUID; } // Create a local representation of the module BiosModule module = new BiosModule( results.Name, results.Exports.ToArray() ); _kernel.Bios._metaModules.Add( module ); _kernel.Bios._metaModuleLookup.Add( module.Name, module ); KModule kmod = new KModule( _kernel, module ); kmod.UID = results.ModuleID; kmod.LoadParameters = loadParams; kmod.LoadResults = results; _kernel.UserModules.Add( kmod ); _kernel.AddHandle( kmod ); if( Diag.IsAttached == true ) Diag.Instance.Client.OnModuleLoaded(); return ( int )kmod.UID; }