コード例 #1
0
        public static void SetCurrentVariable(string name, string value)
        {
            NtStatus status;
            UnicodeString nameStr;
            UnicodeString valueStr;

            nameStr = new UnicodeString(name);

            try
            {
                valueStr = new UnicodeString(value);

                try
                {
                    if ((status = Win32.RtlSetEnvironmentVariable(
                        IntPtr.Zero,
                        ref nameStr,
                        ref valueStr
                        )) >= NtStatus.Error)
                        Win32.Throw(status);
                }
                finally
                {
                    valueStr.Dispose();
                }
            }
            finally
            {
                nameStr.Dispose();
            }
        }
コード例 #2
0
 /**
  * This Is the starting point where strings are constructed.  Note that
  * strings may span across multiple continuations. Read the SST record
  * carefully before beginning to hack.
  */
 public void ManufactureStrings(int stringCount, RecordInputStream in1)
 {
     for (int i = 0; i < stringCount; i++)
     {
         // Extract exactly the count of strings from the SST record.
         UnicodeString str;
         if (in1.Available() == 0 && !in1.HasNextRecord)
         {
             System.Console.WriteLine("Ran out of data before creating all the strings! String at index " + i + "");
             str = new UnicodeString("");
         }
         else
         {
             str = new UnicodeString(in1);
         }
         AddToStringTable(strings, str);
     }
 }
コード例 #3
0
        public static void SetCurrentVariable(string name, string value)
        {
            UnicodeString nameStr = new UnicodeString(name);
            UnicodeString valueStr = new UnicodeString(value);

            try
            {
                Win32.RtlSetEnvironmentVariable(
                    IntPtr.Zero,
                    ref nameStr,
                    ref valueStr
                    ).ThrowIf();
            }
            finally
            {
                valueStr.Dispose();
                nameStr.Dispose();
            }
        }
コード例 #4
0
        public void SetVariable(string name, string value)
        {
            NtStatus status;
            IntPtr environment = _environment;
            UnicodeString nameStr;
            UnicodeString valueStr;

            nameStr = new UnicodeString(name);

            try
            {
                valueStr = new UnicodeString(value);

                try
                {
                    if ((status = Win32.RtlSetEnvironmentVariable(
                        ref environment,
                        ref nameStr,
                        ref valueStr
                        )) >= NtStatus.Error)
                        Win32.ThrowLastError(status);
                }
                finally
                {
                    valueStr.Dispose();
                }
            }
            finally
            {
                nameStr.Dispose();
            }

            _environment = environment;
        }
コード例 #5
0
 public static extern NtStatus RtlAnsiStringToUnicodeString(
     ref UnicodeString DestinationString,
     [In] ref AnsiString SourceString,
     [In] bool AllocateDestinationString
     );
コード例 #6
0
 public static extern NtStatus RtlQueryEnvironmentVariable_U(
     [In] [Optional] IntPtr Environment,
     [In] ref UnicodeString Name,
     ref UnicodeString Value
     );
 internal static extern NtStatus LsaEnumerateAccountsWithUserRight(
     SafeLsaHandle PolicyHandle,
     UnicodeString UserRight,
     out SafeLsaMemoryBuffer Buffer,
     out int CountReturned
     );
コード例 #8
0
ファイル: DVRecord.cs プロジェクト: missxiaohuang/Weekly
 private static void SerializeUnicodeString(UnicodeString us, ILittleEndianOutput out1)
 {
     StringUtil.WriteUnicodeString(out1, us.String);
 }
コード例 #9
0
ファイル: 40763.cs プロジェクト: zeroscience/exploit-database
 static extern int NtCreateSymbolicLinkObject(
     out IntPtr LinkHandle,
     GenericAccessRights DesiredAccess,
     ObjectAttributes ObjectAttributes,
     UnicodeString DestinationName
     );
コード例 #10
0
 private static void ConfirmSize(int expectedSize, UnicodeString s)
 {
     ConfirmSize(expectedSize, s, 0);
 }
 internal static extern NtStatus SamLookupDomainInSamServer(
     SafeSamHandle ServerHandle,
     UnicodeString Name,
     out SafeSamMemoryBuffer DomainId
     );
 internal static extern NtStatus SamConnect(
     UnicodeString ServerName,
     out SafeSamHandle ServerHandle,
     AccessMask DesiredAccess,
     ObjectAttributes ObjectAttributes
     );
 internal static extern NtStatus LsaCreateSecret(
     SafeLsaHandle PolicyHandle,
     [In] UnicodeString SecretName,
     LsaSecretAccessRights DesiredAccess,
     out SafeLsaHandle SecretHandle
     );
 internal static extern NtStatus LsaRetrievePrivateData(
     SafeLsaHandle PolicyHandle,
     [In] UnicodeString KeyName,
     out SafeLsaMemoryBuffer PrivateData // PLSA_UNICODE_STRING
     );
 internal static extern NtStatus LsaStorePrivateData(
     SafeLsaHandle PolicyHandle,
     [In] UnicodeString KeyName,
     UnicodeStringBytesSafeBuffer PrivateData
     );
コード例 #16
0
 static public void AddToStringTable(IntMapper<UnicodeString> strings, UnicodeString str)
 {
     strings.Add(str);
 }
コード例 #17
0
        /// <summary>
        /// Unloads a driver.
        /// </summary>
        /// <param name="serviceName">The service name of the driver.</param>
        public static void UnloadDriver(string serviceName)
        {
            UnicodeString str = new UnicodeString("\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\" + serviceName);

            try
            {
                Win32.NtUnloadDriver(ref str).ThrowIf();
            }
            finally
            {
                str.Dispose();
            }
        }
コード例 #18
0
 internal static extern NtStatus LsaGetAppliedCAPIDs(
     UnicodeString SystemName,
     out SafeLsaMemoryBuffer CAPIDs,
     out int CAPIDCount
     );
コード例 #19
0
ファイル: DVRecord.cs プロジェクト: missxiaohuang/Weekly
        public DVRecord(int validationType, int operator1, int errorStyle, bool emptyCellAllowed,
            bool suppressDropDownArrow, bool isExplicitList,
            bool showPromptBox, String promptTitle, String promptText,
            bool showErrorBox, String errorTitle, String errorText,
            Ptg[] formula1, Ptg[] formula2,
            CellRangeAddressList regions)
        {

            int flags = 0;
            flags = opt_data_type.SetValue(flags, validationType);
            flags = opt_condition_operator.SetValue(flags, operator1);
            flags = opt_error_style.SetValue(flags, errorStyle);
            flags = opt_empty_cell_allowed.SetBoolean(flags, emptyCellAllowed);
            flags = opt_suppress_dropdown_arrow.SetBoolean(flags, suppressDropDownArrow);
            flags = opt_string_list_formula.SetBoolean(flags, isExplicitList);
            flags = opt_show_prompt_on_cell_selected.SetBoolean(flags, showPromptBox);
            flags = opt_show_error_on_invalid_value.SetBoolean(flags, showErrorBox);
            _option_flags = flags;
            _promptTitle = ResolveTitleText(promptTitle);
            _promptText = ResolveTitleText(promptText);
            _errorTitle = ResolveTitleText(errorTitle);
            _errorText = ResolveTitleText(errorText);
            _formula1 = LF.Utils.NPOI.SS.Formula.Formula.Create(formula1);
            _formula2 = LF.Utils.NPOI.SS.Formula.Formula.Create(formula2);
            _regions = regions;
        }
コード例 #20
0
 private static extern NtStatus SamLookupDomainInSamServer(SafeSamHandle serverHandle, [In] ref UnicodeString domainName, [MarshalAs(UnmanagedType.LPArray, SizeConst = 24)] out byte[] domainId);
コード例 #21
0
        public void SetVariable(string name, string value)
        {
            IntPtr environment = _environment;

            UnicodeString nameStr = new UnicodeString(name);
            UnicodeString valueStr = new UnicodeString(value);

            try
            {
                Win32.RtlSetEnvironmentVariable(
                    ref environment,
                    ref nameStr,
                    ref valueStr
                    ).ThrowIf();
            }
            finally
            {
                valueStr.Dispose();
                nameStr.Dispose();
            }

            _environment = environment;
        }
コード例 #22
0
 private static extern NtStatus LsaOpenPolicy([In] ref UnicodeString systemName, [In] ref LsaObjectAttributes objectAttributes, LsaPolicyAccessMask desiredAccess, out SafeLsaPolicyHandle policyHandle);
コード例 #23
0
 public static extern NtStatus NtQuerySymbolicLinkObject(
     [In] IntPtr LinkHandle,
     ref UnicodeString LinkName,
     [Out] [Optional] out int ReturnLength
     );
コード例 #24
0
 private static extern NtStatus SamConnect([In] ref UnicodeString serverName, out SafeSamHandle serverHandle, SamServerAccessMask accessMask, IntPtr objectAttributes);
コード例 #25
0
 public static extern NtStatus RtlConvertSidToUnicodeString(
     ref UnicodeString UnicodeString,
     [In] IntPtr Sid,
     [In] bool AllocateDestinationString
     );
コード例 #26
0
 private static extern NtStatus SamConnectWithCreds([In] ref UnicodeString serverName, out SafeSamHandle serverHandle, SamServerAccessMask accessMask, IntPtr objectAttributes, SafeRpcAuthIdentityHandle authIdentity, [MarshalAs(UnmanagedType.LPWStr)] string servicePrincipalName, out uint unknown);
コード例 #27
0
ファイル: Windows.cs プロジェクト: andyvand/ProcessHacker
        /// <summary>
        /// Unloads a driver.
        /// </summary>
        /// <param name="serviceName">The service name of the driver.</param>
        public static void UnloadDriver(string serviceName)
        {
            var str = new UnicodeString(
                "\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\" + serviceName);

            try
            {
                NtStatus status;

                if ((status = Win32.NtUnloadDriver(ref str)) >= NtStatus.Error)
                    Win32.ThrowLastError(status);
            }
            finally
            {
                str.Dispose();
            }
        }
コード例 #28
0
ファイル: HSSFRichTextString.cs プロジェクト: twxstar/npoi
 /// <summary>
 /// Removes any formatting that may have been applied to the string.
 /// </summary>
 public void ClearFormatting()
 {
     _string = CloneStringIfRequired();
     _string.ClearFormatting();
     AddToSSTIfRequired();
 }
コード例 #29
0
        public string GetVariable(string name)
        {
            NtStatus status;
            UnicodeString nameStr;
            UnicodeString valueStr;

            nameStr = new UnicodeString(name);

            try
            {
                using (var data = new MemoryAlloc(100))
                {
                    valueStr = new UnicodeString();
                    valueStr.Buffer = data;
                    valueStr.MaximumLength = (ushort)data.Size;

                    status = Win32.RtlQueryEnvironmentVariable_U(
                        this,
                        ref nameStr,
                        ref valueStr
                        );

                    if (status == NtStatus.BufferTooSmall)
                    {
                        // Resize and try again (+2 for the null terminator).
                        data.ResizeNew(valueStr.Length + 2);
                        valueStr.Buffer = data;
                        valueStr.MaximumLength = (ushort)(valueStr.Length + 2);

                        status = Win32.RtlQueryEnvironmentVariable_U(
                            this,
                            ref nameStr,
                            ref valueStr
                            );
                    }

                    if (status >= NtStatus.Error)
                        Win32.Throw(status);

                    return valueStr.Read();
                }
            }
            finally
            {
                nameStr.Dispose();
            }
        }
コード例 #30
0
ファイル: HSSFCell.cs プロジェクト: xewn/Npoi.Core
        /// <summary>
        /// Sets the cell type. The SetValue flag indicates whether to bother about
        /// trying to preserve the current value in the new record if one is Created.
        /// The SetCellValue method will call this method with false in SetValue
        /// since it will overWrite the cell value later
        /// </summary>
        /// <param name="cellType">Type of the cell.</param>
        /// <param name="setValue">if set to <c>true</c> [set value].</param>
        /// <param name="row">The row.</param>
        /// <param name="col">The col.</param>
        /// <param name="styleIndex">Index of the style.</param>
        private void SetCellType(CellType cellType, bool setValue, int row, int col, short styleIndex)
        {
            if (cellType > CellType.Error)
            {
                throw new Exception("I have no idea what type that Is!");
            }
            switch (cellType)
            {
            case CellType.Formula:
                FormulaRecordAggregate frec = null;

                if (cellType != this.cellType)
                {
                    frec = _sheet.Sheet.RowsAggregate.CreateFormula(row, col);
                }
                else
                {
                    frec = (FormulaRecordAggregate)_record;
                }
                frec.Column = col;
                if (setValue)
                {
                    frec.FormulaRecord.Value = NumericCellValue;
                }
                frec.XFIndex = styleIndex;
                frec.Row     = row;
                _record      = frec;
                break;

            case CellType.Numeric:
                NumberRecord nrec = null;

                if (cellType != this.cellType)
                {
                    nrec = new NumberRecord();
                }
                else
                {
                    nrec = (NumberRecord)_record;
                }
                nrec.Column = col;
                if (setValue)
                {
                    nrec.Value = NumericCellValue;
                }
                nrec.XFIndex = styleIndex;
                nrec.Row     = row;
                _record      = nrec;
                break;

            case CellType.String:
                LabelSSTRecord lrec = null;

                if (cellType != this.cellType)
                {
                    lrec = new LabelSSTRecord();
                }
                else
                {
                    lrec = (LabelSSTRecord)_record;
                }
                lrec.Column  = col;
                lrec.Row     = row;
                lrec.XFIndex = styleIndex;
                if (setValue)
                {
                    String str      = ConvertCellValueToString();
                    int    sstIndex = book.Workbook.AddSSTString(new UnicodeString(str));
                    lrec.SSTIndex = (sstIndex);
                    UnicodeString us = book.Workbook.GetSSTString(sstIndex);
                    stringValue = new HSSFRichTextString();
                    stringValue.UnicodeString = us;
                }
                _record = lrec;
                break;

            case CellType.Blank:
                BlankRecord brec = null;

                if (cellType != this.cellType)
                {
                    brec = new BlankRecord();
                }
                else
                {
                    brec = (BlankRecord)_record;
                }
                brec.Column = col;

                // During construction the cellStyle may be null for a Blank cell.
                brec.XFIndex = styleIndex;
                brec.Row     = row;
                _record      = brec;
                break;

            case CellType.Boolean:
                BoolErrRecord boolRec = null;

                if (cellType != this.cellType)
                {
                    boolRec = new BoolErrRecord();
                }
                else
                {
                    boolRec = (BoolErrRecord)_record;
                }
                boolRec.Column = col;
                if (setValue)
                {
                    boolRec.SetValue(ConvertCellValueToBoolean());
                }
                boolRec.XFIndex = styleIndex;
                boolRec.Row     = row;
                _record         = boolRec;
                break;

            case CellType.Error:
                BoolErrRecord errRec = null;

                if (cellType != this.cellType)
                {
                    errRec = new BoolErrRecord();
                }
                else
                {
                    errRec = (BoolErrRecord)_record;
                }
                errRec.Column = col;
                if (setValue)
                {
                    errRec.SetValue((byte)HSSFErrorConstants.ERROR_VALUE);
                }
                errRec.XFIndex = styleIndex;
                errRec.Row     = row;
                _record        = errRec;
                break;
            }
            if (cellType != this.cellType &&
                this.cellType != CellType.Unknown)  // Special Value to indicate an Uninitialized Cell
            {
                _sheet.Sheet.ReplaceValueRecord(_record);
            }
            this.cellType = cellType;
        }
コード例 #31
0
 /// <summary>
 /// Removes any formatting that may have been applied to the string.
 /// </summary>
 public void ClearFormatting()
 {
     str = CloneStringIfRequired();
     str.ClearFormatting();
     AddToSSTIfRequired();
 }
コード例 #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HSSFRichTextString"/> class.
        /// </summary>
        /// <param name="book">The workbook.</param>
        /// <param name="record">The record.</param>
        public HSSFRichTextString(Workbook book, LabelSSTRecord record)
        {
            SetWorkbookReferences(book, record);

            this.str = book.GetSSTString(record.SSTIndex);
        }
コード例 #33
0
ファイル: SSTRecord.cs プロジェクト: missxiaohuang/Weekly
        /**
         * Add a string.
         *
         * @param string string to be Added
         *
         * @return the index of that string in the table
         */

        public int AddString(UnicodeString str)
        {
            field_1_num_strings++;
            UnicodeString ucs = (str == null) ? EMPTY_STRING
                    : str;
            int rval;
            int index = field_3_strings.GetIndex(ucs);

            if (index != -1)
            {
                rval = index;
            }
            else
            {
                // This is a new string -- we didn't see it among the
                // strings we've already collected
                rval = field_3_strings.Size;
                field_2_num_unique_strings++;
                SSTDeserializer.AddToStringTable(field_3_strings, ucs);
            }
            return rval;
        }
コード例 #34
0
ファイル: HSSFOptimiser.cs プロジェクト: FilRip/IMDEV.Commun
        /// <summary>
        /// Goes through the Workbook, optimising the fonts by
        /// removing duplicate ones.
        /// For now, only works on fonts used in HSSFCellStyle
        /// and HSSFRichTextString. Any other font uses
        /// (eg charts, pictures) may well end up broken!
        /// This can be a slow operation, especially if you have
        /// lots of cells, cell styles or rich text strings
        /// </summary>
        /// <param name="workbook">The workbook in which to optimise the fonts</param>
        public static void OptimiseFonts(HSSFWorkbook workbook)
        {
            // Where each font has ended up, and if we need to
            //  delete the record for it. Start off with no change
            short[] newPos =
                new short[workbook.Workbook.NumberOfFontRecords + 1];
            bool[] zapRecords = new bool[newPos.Length];
            for (int i = 0; i < newPos.Length; i++)
            {
                newPos[i]     = (short)i;
                zapRecords[i] = false;
            }

            // Get each font record, so we can do deletes
            //  without Getting confused
            FontRecord[] frecs = new FontRecord[newPos.Length];
            for (int i = 0; i < newPos.Length; i++)
            {
                // There is no 4!
                if (i == 4)
                {
                    continue;
                }

                frecs[i] = workbook.Workbook.GetFontRecordAt(i);
            }

            // Loop over each font, seeing if it is the same
            //  as an earlier one. If it is, point users of the
            //  later duplicate copy to the earlier one, and
            //  mark the later one as needing deleting
            // Note - don't change built in fonts (those before 5)
            for (int i = 5; i < newPos.Length; i++)
            {
                // Check this one for being a duplicate
                //  of an earlier one
                int earlierDuplicate = -1;
                for (int j = 0; j < i && earlierDuplicate == -1; j++)
                {
                    if (j == 4)
                    {
                        continue;
                    }

                    FontRecord frCheck = workbook.Workbook.GetFontRecordAt(j);
                    if (frCheck.SameProperties(frecs[i]))
                    {
                        earlierDuplicate = j;
                    }
                }

                // If we got a duplicate, mark it as such
                if (earlierDuplicate != -1)
                {
                    newPos[i]     = (short)earlierDuplicate;
                    zapRecords[i] = true;
                }
            }

            // Update the new positions based on
            //  deletes that have occurred between
            //  the start and them
            // Only need to worry about user fonts
            for (int i = 5; i < newPos.Length; i++)
            {
                // Find the number deleted to that
                //  point, and adjust
                short preDeletePos = newPos[i];
                short newPosition  = preDeletePos;
                for (int j = 0; j < preDeletePos; j++)
                {
                    if (zapRecords[j])
                    {
                        newPosition--;
                    }
                }

                // Update the new position
                newPos[i] = newPosition;
            }

            // Zap the un-needed user font records
            for (int i = 5; i < newPos.Length; i++)
            {
                if (zapRecords[i])
                {
                    workbook.Workbook.RemoveFontRecord(
                        frecs[i]
                        );
                }
            }

            // Tell HSSFWorkbook that it needs to
            //  re-start its HSSFFontCache
            workbook.ResetFontCache();

            // Update the cell styles to point at the
            //  new locations of the fonts
            for (int i = 0; i < workbook.Workbook.NumExFormats; i++)
            {
                ExtendedFormatRecord xfr = workbook.Workbook.GetExFormatAt(i);
                xfr.FontIndex = (
                    newPos[xfr.FontIndex]
                    );
            }

            // Update the rich text strings to point at
            //  the new locations of the fonts
            // Remember that one underlying unicode string
            //  may be shared by multiple RichTextStrings!
            ArrayList doneUnicodeStrings = new ArrayList();

            for (int sheetNum = 0; sheetNum < workbook.NumberOfSheets; sheetNum++)
            {
                NPOI.SS.UserModel.ISheet s = workbook.GetSheetAt(sheetNum);
                //IEnumerator rIt = s.GetRowEnumerator();
                //while (rIt.MoveNext())
                foreach (IRow row in s)
                {
                    //HSSFRow row = (HSSFRow)rIt.Current;
                    //IEnumerator cIt = row.GetEnumerator();
                    //while (cIt.MoveNext())
                    foreach (ICell cell in row)
                    {
                        //ICell cell = (HSSFCell)cIt.Current;
                        if (cell.CellType == NPOI.SS.UserModel.CellType.String)
                        {
                            HSSFRichTextString rtr = (HSSFRichTextString)cell.RichStringCellValue;
                            UnicodeString      u   = rtr.RawUnicodeString;

                            // Have we done this string already?
                            if (!doneUnicodeStrings.Contains(u))
                            {
                                // Update for each new position
                                for (short i = 5; i < newPos.Length; i++)
                                {
                                    if (i != newPos[i])
                                    {
                                        u.SwapFontUse(i, newPos[i]);
                                    }
                                }

                                // Mark as done
                                doneUnicodeStrings.Add(u);
                            }
                        }
                    }
                }
            }
        }
コード例 #35
0
ファイル: DVRecord.cs プロジェクト: missxiaohuang/Weekly
        /**
         * Constructs a DV record and Sets its fields appropriately.
         *
         * @param in the RecordInputstream to Read the record from
         */

        public DVRecord(RecordInputStream in1)
        {
            _option_flags = in1.ReadInt();

            _promptTitle = ReadUnicodeString(in1);
            _errorTitle = ReadUnicodeString(in1);
            _promptText = ReadUnicodeString(in1);
            _errorText = ReadUnicodeString(in1);

            int field_size_first_formula = in1.ReadUShort();
            _not_used_1 = in1.ReadShort();

            //read first formula data condition
            _formula1 = LF.Utils.NPOI.SS.Formula.Formula.Read(field_size_first_formula, in1);

            int field_size_sec_formula = in1.ReadUShort();
            _not_used_2 = in1.ReadShort();

            //read sec formula data condition
            _formula2 = LF.Utils.NPOI.SS.Formula.Formula.Read(field_size_sec_formula, in1);

            //read cell range address list with all affected ranges
            _regions = new CellRangeAddressList(in1);
        }
コード例 #36
0
ファイル: TestUnicodeString.cs プロジェクト: xewn/Npoi.Core
        public void TestContinuedStringSize()
        {
            UnicodeString s = MakeUnicodeString(MAX_DATA_SIZE - 2 - 1 + 20);

            ConfirmSize(MAX_DATA_SIZE + 4 + 1 + 20, s);
        }
コード例 #37
0
ファイル: DVRecord.cs プロジェクト: missxiaohuang/Weekly
 private static int GetUnicodeStringSize(UnicodeString us)
 {
     String str = us.String;
     return 3 + str.Length * (StringUtil.HasMultibyte(str) ? 2 : 1);
 }
コード例 #38
0
        /**
         * Adds a string to the SST table and returns its index (if its a duplicate
         * just returns its index and update the counts) ASSUMES compressed Unicode
         * (meaning 8bit)
         *
         * @param string the string to be Added to the SSTRecord
         *
         * @return index of the string within the SSTRecord
         */

        public int AddSSTString(UnicodeString str)
        {
            //if (log.Check(POILogger.DEBUG))
            //    log.Log(DEBUG, "Insert to sst string='", str);
            if (sst == null)
            {
                InsertSST();
            }
            return sst.AddString(str);
        }
コード例 #39
0
ファイル: NativeUtils.cs プロジェクト: andyvand/ProcessHacker
        public unsafe static void CopyProcessParameters(
            ProcessHandle processHandle,
            IntPtr peb,
            ProcessCreationFlags creationFlags,
            string imagePathName,
            string dllPath,
            string currentDirectory,
            string commandLine,
            EnvironmentBlock environment,
            string windowTitle,
            string desktopInfo,
            string shellInfo,
            string runtimeInfo,
            ref StartupInfo startupInfo
            )
        {
            UnicodeString imagePathNameStr;
            UnicodeString dllPathStr;
            UnicodeString currentDirectoryStr;
            UnicodeString commandLineStr;
            UnicodeString windowTitleStr;
            UnicodeString desktopInfoStr;
            UnicodeString shellInfoStr;
            UnicodeString runtimeInfoStr;

            // Create the unicode strings.

            imagePathNameStr = new UnicodeString(imagePathName);
            dllPathStr = new UnicodeString(dllPath);
            currentDirectoryStr = new UnicodeString(currentDirectory);
            commandLineStr = new UnicodeString(commandLine);
            windowTitleStr = new UnicodeString(windowTitle);
            desktopInfoStr = new UnicodeString(desktopInfo);
            shellInfoStr = new UnicodeString(shellInfo);
            runtimeInfoStr = new UnicodeString(runtimeInfo);

            try
            {
                NtStatus status;
                IntPtr processParameters;

                // Create the process parameter block.

                status = Win32.RtlCreateProcessParameters(
                    out processParameters,
                    ref imagePathNameStr,
                    ref dllPathStr,
                    ref currentDirectoryStr,
                    ref commandLineStr,
                    environment,
                    ref windowTitleStr,
                    ref desktopInfoStr,
                    ref shellInfoStr,
                    ref runtimeInfoStr
                    );

                if (status >= NtStatus.Error)
                    Win32.Throw(status);

                try
                {
                    // Allocate a new memory region in the remote process for 
                    // the environment block and copy it over.

                    int environmentLength;
                    IntPtr newEnvironment;

                    environmentLength = environment.GetLength();
                    newEnvironment = processHandle.AllocateMemory(
                        environmentLength,
                        MemoryProtection.ReadWrite
                        );

                    processHandle.WriteMemory(
                        newEnvironment,
                        environment,
                        environmentLength
                        );

                    // Copy over the startup info data.
                    RtlUserProcessParameters* paramsStruct = (RtlUserProcessParameters*)processParameters;

                    paramsStruct->Environment = newEnvironment;
                    paramsStruct->StartingX = startupInfo.X;
                    paramsStruct->StartingY = startupInfo.Y;
                    paramsStruct->CountX = startupInfo.XSize;
                    paramsStruct->CountY = startupInfo.YSize;
                    paramsStruct->CountCharsX = startupInfo.XCountChars;
                    paramsStruct->CountCharsY = startupInfo.YCountChars;
                    paramsStruct->FillAttribute = startupInfo.FillAttribute;
                    paramsStruct->WindowFlags = startupInfo.Flags;
                    paramsStruct->ShowWindowFlags = startupInfo.ShowWindow;

                    if ((startupInfo.Flags & StartupFlags.UseStdHandles) == StartupFlags.UseStdHandles)
                    {
                        paramsStruct->StandardInput = startupInfo.StdInputHandle;
                        paramsStruct->StandardOutput = startupInfo.StdOutputHandle;
                        paramsStruct->StandardError = startupInfo.StdErrorHandle;
                    }

                    // TODO: Add console support.

                    // Allocate a new memory region in the remote process for 
                    // the process parameters.

                    IntPtr newProcessParameters;
                    IntPtr regionSize = paramsStruct->Length.ToIntPtr();

                    newProcessParameters = processHandle.AllocateMemory(
                        IntPtr.Zero,
                        ref regionSize,
                        MemoryFlags.Commit,
                        MemoryProtection.ReadWrite
                        );

                    paramsStruct->MaximumLength = regionSize.ToInt32();

                    processHandle.WriteMemory(newProcessParameters, processParameters, paramsStruct->Length);

                    // Modify the process parameters pointer in the PEB.
                    processHandle.WriteMemory(
                        peb.Increment(Peb.ProcessParametersOffset),
                        &newProcessParameters,
                        IntPtr.Size
                        );
                }
                finally
                {
                    Win32.RtlDestroyProcessParameters(processParameters);
                }
            }
            finally
            {
                imagePathNameStr.Dispose();
                dllPathStr.Dispose();
                currentDirectoryStr.Dispose();
                commandLineStr.Dispose();
                windowTitleStr.Dispose();
                desktopInfoStr.Dispose();
                shellInfoStr.Dispose();
                runtimeInfoStr.Dispose();
            }
        }
 internal static extern NtStatus LsaOpenPolicy(
     UnicodeString SystemName,
     ObjectAttributes ObjectAttributes,
     LsaPolicyAccessRights DesiredAccess,
     out SafeLsaHandle PolicyHandle
     );