Ejemplo n.º 1
0
        /// <summary>
        /// + Open MSysObjects
        /// + Enumerate columns
        ///
        /// We're only interested in attributes for ntds.dit
        /// </summary>
        /// <returns></returns>
        private MSysObjectsRow[] EnumColumns()
        {
            // 此处用了打开表时的只读属性,读的时候应该会快一点.
            wrn = Api.JetOpenTable(sesId, dbId, MSYSOBJECTS, null, 0, OpenTableGrbit.ReadOnly | OpenTableGrbit.Sequential, out _tableid);
            if (wrn == JET_wrn.Success)
            {
                //JET_COLUMNLIST columndef;
                // 检索有关表列的信息。将列名称映射到列ID的字典
                //Api.JetGetTableColumnInfo(sesId, _tableid, null, out columndef);
                var columnDictionary = Api.GetColumnDictionary(sesId, _tableid);

                // 循环遍历表,向字典添加属性ID和列名
                Api.MoveBeforeFirst(sesId, _tableid);
                while (Api.TryMoveNext(sesId, _tableid))
                {
                    var nameColumn = new Utf8StringColumnValue {
                        Columnid = columnDictionary["Name"]
                    };

                    Api.RetrieveColumns(sesId, _tableid, nameColumn);
                    if (nameColumn.Value.StartsWith("ATT", StringComparison.Ordinal))
                    {
                        mSysObjects.Add(new MSysObjectsRow
                        {
                            AttributeId = int.Parse(Regex.Replace(nameColumn.Value, "[A-Za-z-]", string.Empty, RegexOptions.None), CultureInfo.InvariantCulture),
                            ColumnName  = nameColumn.Value
                        });
                        // AttributeId = 2128564599
                        // ColumnName = ATTf-2128564599
                    }
                }
            }
            Api.JetCloseTable(sesId, _tableid);
            return(mSysObjects.ToArray());
        }
Ejemplo n.º 2
0
        private static MSysObjectsRow[] EnumerateMSysObjects(JetDb db)
        {
            Stopwatch stopwatch = null;

            if (ShowDebugOutput)
            {
                ConsoleEx.WriteDebug($"Called: {nameof(NtdsAudit)}::{nameof(EnumerateMSysObjects)}");
                stopwatch = new Stopwatch();
                stopwatch.Start();
            }

            var mSysObjects = new List <MSysObjectsRow>();

            using (var table = db.OpenJetDbTable(MSYSOBJECTS))
            {
                // Get a dictionary mapping column names to column ids
                var columnDictionary = table.GetColumnDictionary();

                // Loop over the table adding attribute ids and column names to the dictionary
                table.MoveBeforeFirst();
                while (table.TryMoveNext())
                {
                    var nameColumn = new Utf8StringColumnValue {
                        Columnid = columnDictionary["Name"]
                    };
                    table.RetrieveColumns(nameColumn);
                    if (nameColumn.Value.StartsWith("ATT", StringComparison.Ordinal))
                    {
                        mSysObjects.Add(new MSysObjectsRow
                        {
                            AttributeId = int.Parse(Regex.Replace(nameColumn.Value, "[A-Za-z-]", string.Empty, RegexOptions.None), CultureInfo.InvariantCulture),
                            ColumnName  = nameColumn.Value,
                        });
                    }
                }
            }

            if (ShowDebugOutput)
            {
                ConsoleEx.WriteDebug($"  Found {mSysObjects.Count} datatable column names");

                stopwatch.Stop();
                ConsoleEx.WriteDebug($"  Completed in {stopwatch.Elapsed}");
            }

            return(mSysObjects.ToArray());
        }