Ejemplo n.º 1
0
        int IWbemServices_Old.GetObjectAsync_([In, MarshalAs(UnmanagedType.BStr)] string strObjectPath, [In] int lFlags, [In, MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In, MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler)
        {
            Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\"");

            if (!match.Success)
            {
                pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return(-2147217406);
            }
            string text1 = match.Groups[1].Value;
            string str   = match.Groups[2].Value;
            string str2  = match.Groups[3].Value;

            if (System.Management.Instrumentation.Instrumentation.ProcessIdentity != str2)
            {
                pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return(-2147217406);
            }
            int    num  = ((IConvertible)str).ToInt32((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(int)));
            object obj2 = null;

            try
            {
                InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1);
                obj2 = InstrumentedAssembly.mapIDToPublishedObject[num.ToString((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(int)))];
            }
            finally
            {
                InstrumentedAssembly.readerWriterLock.ReleaseReaderLock();
            }
            if (obj2 != null)
            {
                Type type = (Type)this.instrumentedAssembly.mapTypeToConverter[obj2.GetType()];
                if (type != null)
                {
                    object       target = Activator.CreateInstance(type);
                    ConvertToWMI owmi   = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), target, "ToWMI");
                    lock (obj2)
                    {
                        owmi(obj2);
                    }
                    IntPtr[] apObjArray = new IntPtr[] { (IntPtr)target.GetType().GetField("instWbemObjectAccessIP").GetValue(target) };
                    Marshal.AddRef(apObjArray[0]);
                    IWbemClassObjectFreeThreaded threaded = new IWbemClassObjectFreeThreaded(apObjArray[0]);
                    object pVal = num;
                    threaded.Put_("InstanceId", 0, ref pVal, 0);
                    pVal = System.Management.Instrumentation.Instrumentation.ProcessIdentity;
                    threaded.Put_("ProcessId", 0, ref pVal, 0);
                    pResponseHandler.Indicate_(1, apObjArray);
                    pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
                    Marshal.ReleaseComObject(pResponseHandler);
                    return(0);
                }
            }
            pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
            return(-2147217406);
        }
Ejemplo n.º 2
0
        int IWbemServices_Old.GetObjectAsync_([In][MarshalAs(UnmanagedType.BStr)]  string strObjectPath,
                                              [In] Int32 lFlags,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext pCtx,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemObjectSink pResponseHandler)
        {
//            pResponseHandler.SetStatus(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, null);
//            Marshal.ReleaseComObject(pResponseHandler);
//            return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND);

            Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\"");

            if (match.Success == false)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            string className  = match.Groups[1].Value;
            string instanceId = match.Groups[2].Value;
            string processId  = match.Groups[3].Value;


            if (Instrumentation.ProcessIdentity != processId)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            int    id        = ((IConvertible)instanceId).ToInt32((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.Int32)));
            Object theObject = null;

            try
            {
                InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1);
                theObject = InstrumentedAssembly.mapIDToPublishedObject[id.ToString((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.Int32)))];
            }
            finally
            {
                InstrumentedAssembly.readerWriterLock.ReleaseReaderLock();
            }

            if (theObject != null)
            {
                Type converterType = (Type)instrumentedAssembly.mapTypeToConverter[theObject.GetType()];
                if (converterType != null)
                {
                    Object       converter = Activator.CreateInstance(converterType);
                    ConvertToWMI func      = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), converter, "ToWMI");

                    //
                    // Regression: Reuters VSQFE#: 750, PS#141144    [marioh]
                    // GetObjectAsync was missed. Again, here we have to call ToWMI before retrieving the pointer to the object
                    // since we clone a new one during the ToWMI call. The code below was simply moved from a location further down
                    //
                    lock (theObject)
                        func(theObject);
                    //
                    // END: Regression: Reuters VSQFE#: 750, PS#141144    [marioh]


                    IntPtr[] objs = new IntPtr[] { (IntPtr)converter.GetType().GetField("instWbemObjectAccessIP").GetValue(converter) };
                    Marshal.AddRef(objs[0]);
                    IWbemClassObjectFreeThreaded inst = new IWbemClassObjectFreeThreaded(objs[0]);

                    Object o = id;
                    inst.Put_("InstanceId", 0, ref o, 0);
                    o = Instrumentation.ProcessIdentity;
                    inst.Put_("ProcessId", 0, ref o, 0);
                    //               ConvertFuncToWMI func = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[h.Target.GetType()];
                    //
                    // Reuters VSQFE#: 750, PS#141144    [marioh]
                    // The commented out code was moved up before accessing the object pointer in order to get the
                    // newly cloned one.
                    //
//                    lock(theObject)
//                        func(theObject);
                    pResponseHandler.Indicate_(1, objs);

                    pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
                    Marshal.ReleaseComObject(pResponseHandler);
                    return(0);
                }
            }
            pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
            return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));

#if xxx
            IWbemClassObject classObj = null;
            IWbemCallResult  result   = null;
            pNamespace.GetObject("TestInstance", 0, pCtx, ref classObj, ref result);
            IWbemClassObject inst;
            classObj.SpawnInstance(0, out inst);

            TestInstance testInstance = (TestInstance)mapNameToTestInstance[match.Groups[1].Value];

            Object o = (object)testInstance.name;
            inst.Put("name", 0, ref o, 0);
            o = (object)testInstance.value;
            inst.Put("value", 0, ref o, 0);

            pResponseHandler.Indicate(1, new IWbemClassObject[] { inst });
            pResponseHandler.SetStatus_(0, 0, IntPtr.Zero, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
#endif
        }
Ejemplo n.º 3
0
        int System.Management.IWbemServices_Old.GetObjectAsync_(string strObjectPath, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler)
        {
            Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\"");

            if (match.Success)
            {
                //match.Groups[1].Value;
                string value = match.Groups[2].Value;
                string str   = match.Groups[3].Value;
                if (Instrumentation.ProcessIdentity == str)
                {
                    int    num  = ((IConvertible)value).ToInt32((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(int)));
                    object item = null;
                    try
                    {
                        InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1);
                        item = InstrumentedAssembly.mapIDToPublishedObject[num.ToString((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(int)))];
                    }
                    finally
                    {
                        InstrumentedAssembly.readerWriterLock.ReleaseReaderLock();
                    }
                    if (item != null)
                    {
                        Type type = (Type)this.instrumentedAssembly.mapTypeToConverter[item.GetType()];
                        if (type != null)
                        {
                            object       obj          = Activator.CreateInstance(type);
                            ConvertToWMI convertToWMI = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), obj, "ToWMI");
                            lock (item)
                            {
                                convertToWMI(item);
                            }
                            IntPtr[] intPtrArray = new IntPtr[1];
                            intPtrArray[0] = (IntPtr)obj.GetType().GetField("instWbemObjectAccessIP").GetValue(obj);
                            IntPtr[] intPtrArray1 = intPtrArray;
                            Marshal.AddRef(intPtrArray1[0]);
                            IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = new IWbemClassObjectFreeThreaded(intPtrArray1[0]);
                            object processIdentity = num;
                            wbemClassObjectFreeThreaded.Put_("InstanceId", 0, ref processIdentity, 0);
                            processIdentity = Instrumentation.ProcessIdentity;
                            wbemClassObjectFreeThreaded.Put_("ProcessId", 0, ref processIdentity, 0);
                            pResponseHandler.Indicate_(1, intPtrArray1);
                            pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
                            Marshal.ReleaseComObject(pResponseHandler);
                            return(0);
                        }
                    }
                    pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero);
                    Marshal.ReleaseComObject(pResponseHandler);
                    return(-2147217406);
                }
                else
                {
                    pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero);
                    Marshal.ReleaseComObject(pResponseHandler);
                    return(-2147217406);
                }
            }
            else
            {
                pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return(-2147217406);
            }
        }
Ejemplo n.º 4
0
        int IWbemServices_Old.GetObjectAsync_([In][MarshalAs(UnmanagedType.BStr)]  string strObjectPath,
                                              [In] Int32 lFlags,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext pCtx,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemObjectSink pResponseHandler)
        {
//            pResponseHandler.SetStatus(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, null);
//            Marshal.ReleaseComObject(pResponseHandler);
//            return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND);

            Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\"");

            if (match.Success == false)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            string className  = match.Groups[1].Value;
            string instanceId = match.Groups[2].Value;
            string processId  = match.Groups[3].Value;


            if (Instrumentation.ProcessIdentity != processId)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            int    id        = ((IConvertible)instanceId).ToInt32(null);
            Object theObject = null;

            try
            {
                InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1);
                theObject = InstrumentedAssembly.mapIDToPublishedObject[id.ToString()];
            }
            finally
            {
                InstrumentedAssembly.readerWriterLock.ReleaseReaderLock();
            }

            if (theObject != null)
            {
                Type converterType = (Type)instrumentedAssembly.mapTypeToConverter[theObject.GetType()];
                if (converterType != null)
                {
                    Object       converter = Activator.CreateInstance(converterType);
                    ConvertToWMI func      = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), converter, "ToWMI");
                    IntPtr[]     objs      = new IntPtr[] { (IntPtr)converter.GetType().GetField("instWbemObjectAccessIP").GetValue(converter) };
                    Marshal.AddRef(objs[0]);
                    IWbemClassObjectFreeThreaded inst = new IWbemClassObjectFreeThreaded(objs[0]);

                    Object o = id;
                    inst.Put_("InstanceId", 0, ref o, 0);
                    o = Instrumentation.ProcessIdentity;
                    inst.Put_("ProcessId", 0, ref o, 0);
                    //                ConvertFuncToWMI func = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[h.Target.GetType()];
                    lock (theObject)
                        func(theObject);
                    pResponseHandler.Indicate_(1, objs);

                    pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
                    Marshal.ReleaseComObject(pResponseHandler);
                    return(0);
                }
            }
            pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
            return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));

#if xxx
            IWbemClassObject classObj = null;
            IWbemCallResult  result   = null;
            pNamespace.GetObject("TestInstance", 0, pCtx, ref classObj, ref result);
            IWbemClassObject inst;
            classObj.SpawnInstance(0, out inst);

            TestInstance testInstance = (TestInstance)mapNameToTestInstance[match.Groups[1].Value];

            Object o = (object)testInstance.name;
            inst.Put("name", 0, ref o, 0);
            o = (object)testInstance.value;
            inst.Put("value", 0, ref o, 0);

            pResponseHandler.Indicate(1, new IWbemClassObject[] { inst });
            pResponseHandler.SetStatus_(0, 0, IntPtr.Zero, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
#endif
        }
Ejemplo n.º 5
0
        int IWbemServices_Old.GetObjectAsync_([In][MarshalAs(UnmanagedType.BStr)]  string   strObjectPath,
            [In] Int32 lFlags,
            [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext   pCtx,
            [In][MarshalAs(UnmanagedType.Interface)]  IWbemObjectSink   pResponseHandler)
        {
//            pResponseHandler.SetStatus(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, null);
//            Marshal.ReleaseComObject(pResponseHandler);
//            return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND);

            Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\"");
            if(match.Success==false)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND);
            }

            string className = match.Groups[1].Value;
            string instanceId = match.Groups[2].Value;
            string processId = match.Groups[3].Value;


            if(Instrumentation.ProcessIdentity != processId)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND);
            }

            int id = ((IConvertible)instanceId).ToInt32((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.Int32)));
            Object theObject = null;

            try
            {
                InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1);
                theObject = InstrumentedAssembly.mapIDToPublishedObject[id.ToString((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.Int32)))];
            }
            finally
            {
                InstrumentedAssembly.readerWriterLock.ReleaseReaderLock();
            }

            if(theObject != null)
            {
                Type converterType = (Type)instrumentedAssembly.mapTypeToConverter[theObject.GetType()];
                if(converterType != null)
                {
                    Object converter = Activator.CreateInstance(converterType);
                    ConvertToWMI func = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), converter, "ToWMI");

            //
            // Regression: Reuters VSQFE#: 750, PS#141144    [marioh]
            // GetObjectAsync was missed. Again, here we have to call ToWMI before retrieving the pointer to the object
            // since we clone a new one during the ToWMI call. The code below was simply moved from a location further down
            // 
            lock(theObject)
                func(theObject);
            //
            // END: Regression: Reuters VSQFE#: 750, PS#141144    [marioh]

                    
                    IntPtr[] objs = new IntPtr[] {(IntPtr)converter.GetType().GetField("instWbemObjectAccessIP").GetValue(converter)};
                    Marshal.AddRef(objs[0]);
                    IWbemClassObjectFreeThreaded inst = new IWbemClassObjectFreeThreaded(objs[0]);

                    Object o = id;
                    inst.Put_("InstanceId", 0, ref o, 0);
                    o = Instrumentation.ProcessIdentity;
                    inst.Put_("ProcessId", 0, ref o, 0);
                    //               ConvertFuncToWMI func = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[h.Target.GetType()];
            //
            // Reuters VSQFE#: 750, PS#141144    [marioh]
            // The commented out code was moved up before accessing the object pointer in order to get the
            // newly cloned one.
            // 
//                    lock(theObject)
//                        func(theObject);
                    pResponseHandler.Indicate_(1, objs);

                    pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
                    Marshal.ReleaseComObject(pResponseHandler);
                    return 0;
                }
            }
            pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
            return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND);
#if xxx
            IWbemClassObject classObj = null;
            IWbemCallResult result = null;
            pNamespace.GetObject("TestInstance", 0, pCtx, ref classObj, ref result);
            IWbemClassObject inst;
            classObj.SpawnInstance(0, out inst);

            TestInstance testInstance = (TestInstance)mapNameToTestInstance[match.Groups[1].Value];

            Object o = (object)testInstance.name;
            inst.Put("name", 0, ref o, 0);
            o = (object)testInstance.value;
            inst.Put("value", 0, ref o, 0);

            pResponseHandler.Indicate(1, new IWbemClassObject[] {inst});
            pResponseHandler.SetStatus_(0, 0, IntPtr.Zero, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
#endif
        }