Пример #1
0
 public PluginAETE(int major, int minor, short suiteLevel, short suiteVersion, AETEEvent scriptEvent)
 {
     this.major        = major;
     this.minor        = minor;
     this.suiteLevel   = suiteLevel;
     this.suiteVersion = suiteVersion;
     this.scriptEvent  = scriptEvent;
 }
Пример #2
0
        private static unsafe bool EnumAETE(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam)
        {
            GCHandle  handle = GCHandle.FromIntPtr(lParam);
            QueryAETE query  = (QueryAETE)handle.Target;

            if (lpszName == query.resourceID)
            {
                IntPtr hRes = UnsafeNativeMethods.FindResourceW(hModule, lpszName, lpszType);
                if (hRes == IntPtr.Zero)
                {
                    return(false);
                }

                IntPtr loadRes = UnsafeNativeMethods.LoadResource(hModule, hRes);
                if (loadRes == IntPtr.Zero)
                {
                    return(false);
                }

                IntPtr lockRes = UnsafeNativeMethods.LockResource(loadRes);
                if (lockRes == IntPtr.Zero)
                {
                    return(false);
                }

                byte *ptr     = (byte *)lockRes.ToPointer() + 2;
                short version = *(short *)ptr;
                ptr += 2;

                int major = (version & 0xff);
                int minor = ((version >> 8) & 0xff);

                short lang = *(short *)ptr;
                ptr += 2;
                short script = *(short *)ptr;
                ptr += 2;
                short suiteCount = *(short *)ptr;
                ptr += 2;
                byte *propPtr = ptr;

                int stringLength = 0;

                if (suiteCount == 1)                 // There should only be one vendor suite
                {
                    string suiteVendor = StringUtil.FromPascalString(propPtr, out stringLength);
                    propPtr += stringLength;
                    string suiteDescription = StringUtil.FromPascalString(propPtr, out stringLength);
                    propPtr += stringLength;
                    uint suiteID = *(uint *)propPtr;
                    propPtr += 4;
                    short suiteLevel = *(short *)propPtr;
                    propPtr += 2;
                    short suiteVersion = *(short *)propPtr;
                    propPtr += 2;
                    short eventCount = *(short *)propPtr;
                    propPtr += 2;

                    if (eventCount == 1)                     // There should only be one scripting event
                    {
                        string eventVendor = StringUtil.FromPascalString(propPtr, out stringLength);
                        propPtr += stringLength;
                        string eventDescription = StringUtil.FromPascalString(propPtr, out stringLength);
                        propPtr += stringLength;
                        int eventClass = *(int *)propPtr;
                        propPtr += 4;
                        int eventType = *(int *)propPtr;
                        propPtr += 4;

                        uint replyType = *(uint *)propPtr;
                        propPtr += 7;
                        byte[] bytes = new byte[4];

                        int idx = 0;
                        while (*propPtr != 0)
                        {
                            if (*propPtr != 0x27)                             // The ' char, some filters encode the #ImR parameter type as '#'ImR.
                            {
                                bytes[idx] = *propPtr;
                                idx++;
                            }
                            propPtr++;
                        }
                        propPtr++;                         // skip the second null byte

                        uint paramType = BitConverter.ToUInt32(bytes, 0);

                        short eventFlags = *(short *)propPtr;
                        propPtr += 2;
                        short paramCount = *(short *)propPtr;
                        propPtr += 2;

                        AETEEvent evnt = new AETEEvent()
                        {
                            vendor     = eventVendor,
                            desc       = eventDescription,
                            eventClass = eventClass,
                            type       = eventType,
                            replyType  = replyType,
                            paramType  = paramType,
                            flags      = eventFlags
                        };

                        if (paramCount > 0)
                        {
                            AETEParameter[] parameters = new AETEParameter[paramCount];
                            for (int p = 0; p < paramCount; p++)
                            {
                                string name = StringUtil.FromPascalString(propPtr, out stringLength);
                                propPtr += stringLength;

                                uint key = *(uint *)propPtr;
                                propPtr += 4;

                                uint type = *(uint *)propPtr;
                                propPtr += 4;

                                string description = StringUtil.FromPascalString(propPtr, out stringLength);
                                propPtr += stringLength;

                                short parameterFlags = *(short *)propPtr;
                                propPtr += 2;

                                parameters[p] = new AETEParameter(name, key, type, description, parameterFlags);
                            }
                            evnt.parameters = parameters;
                        }

                        short classCount = *(short *)propPtr;
                        propPtr += 2;
                        if (classCount == 0)
                        {
                            short compOps = *(short *)propPtr;
                            propPtr += 2;
                            short enumCount = *(short *)propPtr;
                            propPtr += 2;
                            if (enumCount > 0)
                            {
                                AETEEnums[] enums = new AETEEnums[enumCount];
                                for (int enc = 0; enc < enumCount; enc++)
                                {
                                    uint type = *(uint *)propPtr;
                                    propPtr += 4;
                                    short count = *(short *)propPtr;
                                    propPtr += 2;

                                    AETEEnum[] values = new AETEEnum[count];

                                    for (int e = 0; e < count; e++)
                                    {
                                        string name = StringUtil.FromPascalString(propPtr, out stringLength);
                                        propPtr += stringLength;

                                        uint key = *(uint *)propPtr;
                                        propPtr += 4;

                                        string description = StringUtil.FromPascalString(propPtr, out stringLength);
                                        propPtr += stringLength;

                                        values[e] = new AETEEnum(name, key, description);
                                    }
                                    enums[enc] = new AETEEnums(type, count, values);
                                }
                                evnt.enums = enums;
                            }
                        }

                        if (evnt.parameters != null &&
                            major == PSConstants.AETEMajorVersion &&
                            minor == PSConstants.AETEMinorVersion &&
                            suiteLevel == PSConstants.AETESuiteLevel &&
                            suiteVersion == PSConstants.AETESuiteVersion)
                        {
                            query.enumAETE = new PluginAETE(major, minor, suiteLevel, suiteVersion, evnt);
                            handle.Target  = query;
                            lParam         = GCHandle.ToIntPtr(handle);
                        }
                    }
                }

                return(false);
            }

            return(true);
        }