Example #1
0
        // Token: 0x06000329 RID: 809 RVA: 0x0000DA20 File Offset: 0x0000BC20
        internal static bool FormatMessageFromModule(string moduleName, uint msgId, out string msg, out int gle, params object[] objArguments)
        {
            string[] array = null;
            if (objArguments != null && objArguments.Length > 0)
            {
                array = new string[objArguments.Length];
                int num = 0;
                foreach (object obj in objArguments)
                {
                    string text = string.Empty;
                    if (obj != null)
                    {
                        text = obj.ToString();
                    }
                    array[num++] = text;
                }
            }
            bool result = false;

            msg = null;
            gle = 0;
            ModuleHandle moduleHandle = NativeMethods.LoadLibraryEx(moduleName, IntPtr.Zero, 2U);

            if (moduleHandle == null || moduleHandle.IsInvalid)
            {
                gle = Marshal.GetLastWin32Error();
                ExTraceGlobals.ReplayApiTracer.TraceError <string, uint, int>(0L, "Failed to LoadLibraryEx( {0} ) when interpreting {1}. Error code: {2}.", moduleName, msgId, gle);
                return(false);
            }
            IntPtr[] array2 = null;
            IntPtr   intPtr = IntPtr.Zero;

            try
            {
                uint dwFlags;
                if (array != null)
                {
                    int num2 = array.Length;
                    array2 = new IntPtr[num2];
                    for (int j = 0; j < num2; j++)
                    {
                        array2[j] = Marshal.StringToHGlobalUni(array[j]);
                    }
                    intPtr = Marshal.AllocHGlobal(num2 * IntPtr.Size);
                    Marshal.Copy(array2, 0, intPtr, num2);
                    dwFlags = 10496U;
                }
                else
                {
                    dwFlags = 2816U;
                }
                IntPtr zero = IntPtr.Zero;
                uint   num3 = NativeMethods.FormatMessage(dwFlags, moduleHandle, msgId, 0U, ref zero, 0U, intPtr);
                if (num3 != 0U && zero != IntPtr.Zero)
                {
                    msg = Marshal.PtrToStringUni(zero);
                    Marshal.FreeHGlobal(zero);
                    result = true;
                    ExTraceGlobals.ReplayApiTracer.TraceDebug <uint, string>(0L, "FormatMessage( {0} ) was successful. Message: {1}.", msgId, msg);
                }
                else
                {
                    gle = Marshal.GetLastWin32Error();
                    ExTraceGlobals.ReplayApiTracer.TraceError <uint, int>(0L, "FormatMessage( {0} ) failed with GLE = {1} .", msgId, gle);
                }
            }
            finally
            {
                if (array2 != null)
                {
                    for (int k = 0; k < array2.Length; k++)
                    {
                        Marshal.FreeHGlobal(array2[k]);
                    }
                    Marshal.FreeHGlobal(intPtr);
                }
                moduleHandle.Close();
            }
            return(result);
        }
Example #2
0
 internal static extern uint FormatMessage(uint dwFlags, ModuleHandle lpSource, uint dwMessageId, uint dwLanguageId, ref IntPtr bufferPointer, uint bufferSize, IntPtr arguments);