98 lines
3.2 KiB
C#
98 lines
3.2 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2011 - 2014 All Rights Reserved.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Intel.Manageability;
|
|
using Intel.Manageability.AccessMonitor;
|
|
using Intel.Manageability.Exceptions;
|
|
using Common.Utils;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace AccessMonitorSample
|
|
{
|
|
class Program
|
|
{
|
|
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool SetDefaultDllDirectories(int directoryFlags);
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
// set default dll lookup directory to system
|
|
SetDefaultDllDirectories(0x00000800); //LOAD_LIBRARY_SEARCH_SYSTEM32
|
|
|
|
IAMTInstance amt = null;
|
|
ConnectionInfoEX ci = null;
|
|
|
|
try
|
|
{
|
|
// Check if JSON path was provided as an argument. If not, default path would be used.
|
|
try
|
|
{
|
|
ci = ProgramInput.DeserializeJsonToStruct(args.Length > 0 ? args[0] : null);
|
|
}
|
|
catch (IOException e)
|
|
{
|
|
Console.WriteLine($"Could not read argument file: {e.Message}");
|
|
return;
|
|
}
|
|
|
|
amt = AMTInstanceFactory.CreateEX(ci);
|
|
}
|
|
|
|
catch (ManageabilityException e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
AccessMonitorFunctionality.SetLogSignature(amt);
|
|
|
|
AccessMonitorFunctionality.GetAccessMonitorSettings(amt);
|
|
|
|
AccessMonitorFunctionality.SetEventStoragePolicy(amt, EventsStoragePolicy.NoRollOver);
|
|
|
|
AccessMonitorFunctionality.GetRegisteredEvents(amt);
|
|
|
|
// Register AuditEvents.NetworkTime.AMTTimeSet event.
|
|
List<EventDetails> eventsDetails = new List<EventDetails>();
|
|
eventsDetails.Add(new EventDetails(AuditEvents.NetworkTime.AMTTimeSet, EventPolicy.None));
|
|
AccessMonitorFunctionality.RegisterToLog(amt, eventsDetails);
|
|
|
|
// Create AMTTimeSet event record in the log.
|
|
amt.TimeSynchronization.SetUtcNetworkTime();
|
|
|
|
AccessMonitorFunctionality.ReadLog(amt);
|
|
|
|
AccessMonitorFunctionality.ReadLogSignature(amt);
|
|
|
|
AccessMonitorFunctionality.ReadLogAuthentication(amt);
|
|
|
|
AccessMonitorFunctionality.UnregisterToLog(amt, AuditEvents.NetworkTime.AMTTimeSet);
|
|
|
|
AccessMonitorFunctionality.ClearLog(amt);
|
|
|
|
uint lockHandle = AccessMonitorFunctionality.LockLog(amt, LogLockType.UnprovisioningLock, 30);
|
|
|
|
// Perform unprovisioning AMT....
|
|
|
|
AccessMonitorFunctionality.UnlockLog(amt, lockHandle);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
amt?.Dispose();
|
|
}
|
|
}
|
|
}
|
|
} |