diff --git a/source/dumpntds/Program.cs b/source/dumpntds/Program.cs
index fc3ca25..7652948 100644
--- a/source/dumpntds/Program.cs
+++ b/source/dumpntds/Program.cs
@@ -20,57 +20,6 @@ internal static class Program
WriteIndented = true
};
- ///
- /// The columns from the "ntds" ESENT database, just the columns from the
- /// "datatable" table that are needed by the "ntdsxtract" script to parse
- /// the user details including password hashes
- ///
- private static readonly List userColumns = ["DNT_col",
- "PDNT_col",
- "time_col",
- "Ancestors_col",
- "ATTb590606",
- "ATTm3",
- "ATTm589825",
- "ATTk589826",
- "ATTl131074",
- "ATTl131075",
- "ATTq131091",
- "ATTq131192",
- "OBJ_col",
- "ATTi131120",
- "ATTb590605",
- "ATTr589970",
- "ATTm590045",
- "ATTm590480",
- "ATTj590126",
- "ATTj589832",
- "ATTq589876",
- "ATTq591520",
- "ATTq589983",
- "ATTq589920",
- "ATTq589873",
- "ATTj589993",
- "ATTj589836",
- "ATTj589922",
- "ATTk589914",
- "ATTk589879",
- "ATTk589918",
- "ATTk589984",
- "ATTk591734",
- "ATTk36",
- "ATTk589949",
- "ATTj589993",
- "ATTm590443",
- "ATTm590187",
- "ATTm590188",
- "ATTm591788",
- "ATTk591823",
- "ATTk591822",
- "ATTk591789",
- "ATTi590943",
- "ATTk590689"];
-
///
/// Application entry point
///
@@ -127,18 +76,7 @@ private static void ExportJson(Session session, JET_DBID dbid)
private static List> ExtractDatatableAsList(Session session, JET_DBID dbid)
{
var datatableValues = new List>();
-
- // Extract and cache the columns from the "datatable" table. Note
- // that we are only interested in the columns needed for "ntdsextract"
- var propertyNames = new List();
- foreach (var column in Api.GetTableColumns(session, dbid, "datatable"))
- {
- if (!userColumns.Contains(column.Name))
- {
- continue;
- }
- propertyNames.Add(column);
- }
+ var columns = new List(Api.GetTableColumns(session, dbid, "datatable"));
using (var table = new Table(session, dbid, "datatable", OpenTableGrbit.ReadOnly))
{
@@ -149,25 +87,25 @@ private static List> ExtractDatatableAsList(Session
while (Api.TryMoveNext(session, table))
{
var obj = new Dictionary();
- foreach (var property in propertyNames)
+ foreach (var column in columns)
{
- formattedData = GetFormattedValue(session, table, property);
+ formattedData = GetFormattedValue(session, table, column);
// The first row has a null "PDNT_col" value which causes issues with the "ntdsxtract" scripts.
// esedbexport seems to have some other value, esedbexport parses the data, rather than using the API
- if (property.Name == "PDNT_col")
+ if (column.Name == "PDNT_col")
{
if (formattedData.Length == 0)
{
- obj.Add(property.Name, "0");
+ obj.Add(column.Name, "0");
continue;
}
}
- var propertyValue = formattedData.Replace("\0", string.Empty);
+ var cellValue = formattedData.Replace("\0", string.Empty);
// Ignore emptry or null values
- if (!string.IsNullOrEmpty(propertyValue))
+ if (!string.IsNullOrEmpty(cellValue))
{
- obj.Add(property.Name, propertyValue);
+ obj.Add(column.Name, cellValue);
}
}
@@ -183,29 +121,25 @@ private static List> ExtractDatatableAsList(Session
private static List> ExtractLinkTableAsList(Session session, JET_DBID dbid)
{
var linktableValues = new List>();
+ var columns = new List(Api.GetTableColumns(session, dbid, "link_table"));
using (var table = new Table(session, dbid, "link_table", OpenTableGrbit.ReadOnly))
{
- // Extract and cache the columns from the "link_table" table
- var propertyNames = new List(Api.GetTableColumns(session, dbid, "link_table"));
-
Api.JetSetTableSequential(session, table, SetTableSequentialGrbit.None);
Api.MoveBeforeFirst(session, table);
- var temp = new List();
-
var formattedData = string.Empty;
while (Api.TryMoveNext(session, table))
{
var obj = new Dictionary();
- foreach (var property in propertyNames)
+ foreach (var column in columns)
{
- formattedData = GetFormattedValue(session, table, property);
- var propertyValue = formattedData.Replace("\0", string.Empty);
+ formattedData = GetFormattedValue(session, table, column);
+ var cellValue = formattedData.Replace("\0", string.Empty);
// Ignore emptry or null values
- if (!string.IsNullOrEmpty(propertyValue))
+ if (!string.IsNullOrEmpty(cellValue))
{
- obj.Add(property.Name, propertyValue);
+ obj.Add(column.Name, cellValue);
}
}
@@ -226,27 +160,19 @@ private static void ExportCsv(Session session, JET_DBID dbid)
private static void ExportDataTable(Session session, JET_DBID dbid)
{
- // Extract and cache the columns from the "datatable" table. Note
- // that we are only interested in the columns needed for "ntdsextract"
- var columns = new List();
- foreach (var column in Api.GetTableColumns(session, dbid, "datatable"))
- {
- if (!userColumns.Contains(column.Name))
- {
- continue;
- }
- columns.Add(column);
- }
using var file = new StreamWriter("datatable.csv");
using var table = new Table(session, dbid, "datatable", OpenTableGrbit.ReadOnly);
+
+ var columns = new List(Api.GetTableColumns(session, dbid, "datatable"));
+
// Write out the column headers
var index = 0;
- foreach (var property in userColumns)
+ foreach (var column in columns)
{
index++;
- file.Write(property);
- if (index != userColumns.Count)
+ file.Write(column.Name);
+ if (index != columns.Count)
{
file.Write("\t");
}
@@ -282,10 +208,10 @@ private static void ExportDataTable(Session session, JET_DBID dbid)
// Now write out each columns data
index = 0;
- foreach (var property in userColumns)
+ foreach (var column in columns)
{
index++;
- if (obj.TryGetValue(property, out var val))
+ if (obj.TryGetValue(column.Name, out var val))
{
file.Write(val);
}
@@ -293,7 +219,7 @@ private static void ExportDataTable(Session session, JET_DBID dbid)
{
file.Write(string.Empty);
}
- if (index != userColumns.Count)
+ if (index != columns.Count)
{
file.Write("\t");
}
@@ -308,6 +234,7 @@ private static void ExportLinkTable(Session session, JET_DBID dbid)
{
using var file = new StreamWriter("linktable.csv");
using var table = new Table(session, dbid, "link_table", OpenTableGrbit.ReadOnly);
+
// Extract and cache the columns from the "link_table" table
var columns = new List(Api.GetTableColumns(session, dbid, "link_table"));
@@ -327,8 +254,6 @@ private static void ExportLinkTable(Session session, JET_DBID dbid)
Api.JetSetTableSequential(session, table, SetTableSequentialGrbit.None);
Api.MoveBeforeFirst(session, table);
- var temp = new List();
-
var currentRow = 0;
var formattedData = string.Empty;
while (Api.TryMoveNext(session, table))
@@ -347,7 +272,15 @@ private static void ExportLinkTable(Session session, JET_DBID dbid)
foreach (var column in columns)
{
index++;
- file.Write(obj[column.Name]);
+ if (obj.TryGetValue(column.Name, out var val))
+ {
+ file.Write(val);
+ }
+ else
+ {
+ file.Write(string.Empty);
+ }
+
if (index != columns.Count)
{
file.Write("\t");