private void InitializeMessage(PortMessage existingMessage, MemoryRegion data, short dataLength) { if (dataLength > Win32.PortMessageMaxDataLength) throw new ArgumentOutOfRangeException("Data length is too large."); if (dataLength < 0) throw new ArgumentOutOfRangeException("Data length cannot be negative."); _message = new PortMessageStruct { DataLength = dataLength, TotalLength = (short)(PortMessageStruct.SizeOf + dataLength), DataInfoOffset = 0 }; if (existingMessage != null) { _message.ClientId = existingMessage.ClientId; _message.MessageId = existingMessage.MessageId; } _data = data; _referencedData = data; _referencedData.Reference(); }
public void Reset() { IRQ.Unset(); memoryBuffer = new MemoryRegion[NumberOfPackets]; for(var i = 0; i < memoryBuffer.Length; ++i) { memoryBuffer[i] = new MemoryRegion(); } rxFifo.Clear(); txFifo.Clear(); sentFifo.Clear(); currentBank = Bank.Bank0; transmitControl = 0x0000; receiveControl = 0x0000; configuration = 0xA0B1; generalPurposeRegister = 0x0000; control = 0x1210; packetNumber = 0x00; allocationResult = 0x0; pointer = 0x0000; interruptMask = 0x0; interruptStatus = TxEmptyInterrupt; earlyReceive = 0x001f; Update(); }
public SymbolNode( string name, int index, int functionIndex, Type datatype, bool isArgument, int runtimeIndex, MemoryRegion memregion = MemoryRegion.InvalidRegion, int scope = -1, CompilerDefinitions.AccessModifier access = CompilerDefinitions.AccessModifier.Public, bool isStatic = false, int codeBlockId = Constants.kInvalidIndex) { this.name = name; isTemp = name.StartsWith("%"); isSSATemp = name.StartsWith(Constants.kSSATempPrefix); this.index = index; this.functionIndex = functionIndex; this.absoluteFunctionIndex = functionIndex; this.datatype = datatype; this.isArgument = isArgument; this.memregion = memregion; this.classScope = scope; this.absoluteClassScope = scope; runtimeTableIndex = runtimeIndex; this.access = access; this.isStatic = isStatic; this.codeBlockId = codeBlockId; }
internal PortMessage(MemoryRegion headerAndData) { _message = headerAndData.ReadStruct<PortMessageStruct>(); _data = new MemoryRegion(headerAndData, _portMessageSize, _message.DataLength); _referencedData = headerAndData; _referencedData.Reference(); }
public SymbolNode() { name = string.Empty; memregion = MemoryRegion.InvalidRegion; classScope = Constants.kInvalidIndex; functionIndex = Constants.kGlobalScope; absoluteClassScope = Constants.kGlobalScope; absoluteFunctionIndex = Constants.kGlobalScope; isStatic = false; isTemp = false; }
internal SsObjectAttributes(MemoryRegion data) { KphSsObjectAttributes oaInfo = data.ReadStruct<KphSsObjectAttributes>(); if (oaInfo.ObjectNameOffset != 0) this.ObjectName = new SsUnicodeString(new MemoryRegion(data, oaInfo.ObjectNameOffset)); this.Original = oaInfo.ObjectAttributes; if (oaInfo.RootDirectoryOffset != 0) this.RootDirectory = new SsHandle(new MemoryRegion(data, oaInfo.RootDirectoryOffset)); }
public static void UnpackCredentials( MemoryRegion buffer, CredPackFlags flags, out string domainName, out string userName, out string password ) { using (var domainNameBuffer = new MemoryAlloc(0x100)) using (var userNameBuffer = new MemoryAlloc(0x100)) using (var passwordBuffer = new MemoryAlloc(0x100)) { int domainNameSize = domainNameBuffer.Size / 2 - 1; int userNameSize = userNameBuffer.Size / 2 - 1; int passwordSize = passwordBuffer.Size / 2 - 1; if (!Win32.CredUnPackAuthenticationBuffer( flags, buffer, buffer.Size, userNameBuffer, ref userNameSize, domainNameBuffer, ref domainNameSize, passwordBuffer, ref passwordSize )) { domainNameBuffer.ResizeNew(domainNameSize * 2 + 2); userNameBuffer.ResizeNew(userNameSize * 2 + 2); passwordBuffer.ResizeNew(passwordSize * 2 + 2); if (!Win32.CredUnPackAuthenticationBuffer( flags, buffer, buffer.Size, userNameBuffer, ref userNameSize, domainNameBuffer, ref domainNameSize, passwordBuffer, ref passwordSize )) Win32.Throw(); } domainName = domainNameBuffer.ReadUnicodeString(0); userName = userNameBuffer.ReadUnicodeString(0); password = passwordBuffer.ReadUnicodeString(0); } }
internal SsUnicodeString(MemoryRegion data) { KphSsUnicodeString unicodeStringInfo = data.ReadStruct<KphSsUnicodeString>(); this.Original = new UnicodeString() { Length = unicodeStringInfo.Length, MaximumLength = unicodeStringInfo.MaximumLength, Buffer = unicodeStringInfo.Pointer }; this.String = data.ReadUnicodeString( KphSsUnicodeString.BufferOffset, unicodeStringInfo.Length / 2 ); }
public SsBytes(MemoryRegion data) { KphSsBytes bytes; byte[] buffer; bytes = data.ReadStruct<KphSsBytes>(); buffer = new byte[bytes.Length]; System.Runtime.InteropServices.Marshal.Copy( data.Memory.Increment(KphSsBytes.BufferOffset), buffer, 0, buffer.Length ); this.Bytes = buffer; }
internal SsHandle(MemoryRegion data) { KphSsHandle handleInfo = data.ReadStruct<KphSsHandle>(0, KphSsHandle.SizeOf, 0); if (handleInfo.TypeNameOffset != 0) { this.TypeName = SsLogger.ReadWString(new MemoryRegion(data, handleInfo.TypeNameOffset)); } if (handleInfo.NameOffset != 0) { this.Name = SsLogger.ReadWString(new MemoryRegion(data, handleInfo.NameOffset)); } this.ProcessId = handleInfo.ClientId.ProcessId; this.ThreadId = handleInfo.ClientId.ThreadId; }
public SecurityDescriptor() { NtStatus status; _memory = new MemoryAlloc(Win32.SecurityDescriptorMinLength); if ((status = Win32.RtlCreateSecurityDescriptor( _memory, Win32.SecurityDescriptorRevision )) >= NtStatus.Error) { _memory.Dispose(); _memory = null; this.DisableOwnership(false); Win32.ThrowLastError(status); } _memory.Reference(); _memory.Dispose(); }
public Ace(IntPtr memory, bool copy) : base(copy) { if (copy) { Ace existingAce = new Ace(memory); _memory = new MemoryAlloc(existingAce.Size); _memory.WriteMemory(0, existingAce, 0, existingAce.Size); } else { _memory = new MemoryRegion(memory); } this.Read(); }
public void EnumLocks(DebugEnumLocksDelegate callback) { var debugInfo = this.GetDebugInformation(); if (debugInfo.Locks == IntPtr.Zero) throw new InvalidOperationException("Lock information does not exist."); MemoryRegion locksInfo = new MemoryRegion(debugInfo.Locks); var locks = locksInfo.ReadStruct<RtlProcessLocks>(); for (int i = 0; i < locks.NumberOfLocks; i++) { var lock_ = locksInfo.ReadStruct<RtlProcessLockInformation>(sizeof(int), i); if (!callback(new LockInformation(lock_))) break; } }
public void EnumHeaps(DebugEnumHeapsDelegate callback) { var debugInfo = this.GetDebugInformation(); if (debugInfo.Heaps == IntPtr.Zero) throw new InvalidOperationException("Heap information does not exist."); MemoryRegion heapInfo = new MemoryRegion(debugInfo.Heaps); var heaps = heapInfo.ReadStruct<RtlProcessHeaps>(); for (int i = 0; i < heaps.NumberOfHeaps; i++) { var heap = heapInfo.ReadStruct<RtlHeapInformation>(RtlProcessHeaps.HeapsOffset, i); if (!callback(new HeapInformation(heap))) break; } }
public SymbolNode( string name, int index, int heapIndex, int functionIndex, ProtoCore.Type datatype, ProtoCore.Type enforcedType, int size, int datasize, bool isArgument, int runtimeIndex, MemoryRegion memregion = MemoryRegion.kInvalidRegion, bool isArray = false, List<int> arraySizeList = null, int scope = -1, ProtoCore.CompilerDefinitions.AccessModifier access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic, bool isStatic = false, int codeBlockId = ProtoCore.DSASM.Constants.kInvalidIndex) { this.name = name; isTemp = name.StartsWith("%"); this.index = index; this.functionIndex = functionIndex; this.absoluteFunctionIndex = functionIndex; this.datatype = datatype; this.staticType = enforcedType; this.size = size; this.datasize = datasize; this.isArgument = isArgument; this.arraySizeList = arraySizeList; this.memregion = memregion; this.classScope = scope; this.absoluteClassScope = scope; runtimeTableIndex = runtimeIndex; this.access = access; this.isStatic = isStatic; this.codeBlockId = codeBlockId; }
internal void SetHeader(MemoryRegion data) { _message = data.ReadStruct<PortMessageStruct>(); }
private void BufferWorkerThreadStart() { int cursor = 0; _bufferWorkerThreadHandle = ThreadHandle.OpenCurrent(ThreadAccess.All); _bufferWorkerThreadReadyEvent.Set(); while (!_terminating) { NtStatus status; KphSsBlockHeader blockHeader; status = _readSemaphore.Wait(true); if (status == NtStatus.Alerted) return; if (_buffer.Size - cursor < Marshal.SizeOf(typeof(KphSsBlockHeader))) cursor = 0; blockHeader = _buffer.ReadStruct<KphSsBlockHeader>(cursor, 0); if (blockHeader.Type == KphSsBlockType.Reset) { cursor = 0; blockHeader = _buffer.ReadStruct<KphSsBlockHeader>(cursor, 0); } if (blockHeader.Type == KphSsBlockType.Event) { var eventBlock = _buffer.ReadStruct<KphSsEventBlock>(cursor, 0); int[] arguments; IntPtr[] stackTrace; arguments = new int[eventBlock.NumberOfArguments]; stackTrace = new IntPtr[eventBlock.TraceCount]; for (int i = 0; i < arguments.Length; i++) arguments[i] = _buffer.ReadInt32(cursor + eventBlock.ArgumentsOffset, i); for (int i = 0; i < stackTrace.Length; i++) stackTrace[i] = _buffer.ReadIntPtr(cursor + eventBlock.TraceOffset, i); SsEvent ssEvent = new SsEvent(); ssEvent.Time = DateTime.FromFileTime(eventBlock.Time); ssEvent.ThreadId = eventBlock.ClientId.ThreadId; ssEvent.ProcessId = eventBlock.ClientId.ProcessId; ssEvent.Arguments = arguments; ssEvent.StackTrace = stackTrace; ssEvent.ArgumentsCopyFailed = (eventBlock.Flags & KphSsEventFlags.CopyArgumentsFailed) == KphSsEventFlags.CopyArgumentsFailed; ssEvent.ArgumentsProbeFailed = (eventBlock.Flags & KphSsEventFlags.ProbeArgumentsFailed) == KphSsEventFlags.ProbeArgumentsFailed; ssEvent.CallNumber = eventBlock.Number; if ((eventBlock.Flags & KphSsEventFlags.UserMode) == KphSsEventFlags.UserMode) ssEvent.Mode = KProcessorMode.UserMode; else ssEvent.Mode = KProcessorMode.KernelMode; if (this.EventBlockReceived != null) this.EventBlockReceived(ssEvent); } else if (blockHeader.Type == KphSsBlockType.Argument) { var argBlock = _buffer.ReadStruct<KphSsArgumentBlock>(cursor, 0); MemoryRegion dataRegion; SsData ssArg = null; dataRegion = new MemoryRegion(_buffer, cursor + KphSsArgumentBlock.DataOffset); switch (argBlock.Type) { case KphSsArgumentType.Int8: { SsSimple simpleArg = new SsSimple(); simpleArg.Argument = argBlock.Data.Int8; simpleArg.Type = typeof(Byte); ssArg = simpleArg; } break; case KphSsArgumentType.Int16: { SsSimple simpleArg = new SsSimple(); simpleArg.Argument = argBlock.Data.Int16; simpleArg.Type = typeof(Int16); ssArg = simpleArg; } break; case KphSsArgumentType.Int32: { SsSimple simpleArg = new SsSimple(); simpleArg.Argument = argBlock.Data.Int32; simpleArg.Type = typeof(Int32); ssArg = simpleArg; } break; case KphSsArgumentType.Int64: { SsSimple simpleArg = new SsSimple(); simpleArg.Argument = argBlock.Data.Int64; simpleArg.Type = typeof(Int64); ssArg = simpleArg; } break; case KphSsArgumentType.Handle: { ssArg = new SsHandle(dataRegion); } break; case KphSsArgumentType.UnicodeString: { ssArg = new SsUnicodeString(dataRegion); } break; case KphSsArgumentType.ObjectAttributes: { ssArg = new SsObjectAttributes(dataRegion); } break; case KphSsArgumentType.ClientId: { ssArg = new SsClientId(dataRegion); } break; } ssArg.Index = argBlock.Index; if (ssArg != null) { if (this.ArgumentBlockReceived != null) this.ArgumentBlockReceived(ssArg); } } cursor += blockHeader.Size; _writeSemaphore.Release(); } }
internal static string ReadWString(MemoryRegion data) { KphSsWString wString = data.ReadStruct<KphSsWString>(); return data.ReadUnicodeString(KphSsWString.BufferOffset, wString.Length / 2); }
internal MemoryRegion[] GetMemoryRanges() { MemoryRegion[] regions = new MemoryRegion[ranges.Length]; for (int i = 0; i < regions.Length; i++) regions[i] = new MemoryRegion { BaseAddress = ranges[i].MemoryStart, MemoryEnd = ranges[i].MemoryEnd }; return regions; }
/// <summary> /// Creates a security descriptor from memory. /// </summary> /// <param name="memory">The memory region to use. This object will be referenced.</param> public SecurityDescriptor(MemoryRegion memory) { _memory = memory; _memory.Reference(); this.Read(); }
public SsClientId(MemoryRegion data) { this.Original = data.ReadStruct<ClientId>(); }
public object GetProfileData(MemoryRegion buffer) { return null; }
public void ReadAuthData(MemoryRegion buffer) { Msv1_0_InteractiveLogon info = buffer.ReadStruct<Msv1_0_InteractiveLogon>(); // Fix up relative addresses. if (info.LogonDomainName.Buffer.CompareTo(buffer.Size) < 0) info.LogonDomainName.Buffer = info.LogonDomainName.Buffer.Increment(buffer); if (info.UserName.Buffer.CompareTo(buffer.Size) < 0) info.UserName.Buffer = info.UserName.Buffer.Increment(buffer); if (info.Password.Buffer.CompareTo(buffer.Size) < 0) info.Password.Buffer = info.Password.Buffer.Increment(buffer); _domainName = info.LogonDomainName.Text; _userName = info.UserName.Text; _password = info.Password.Text; }
public AsyncIoContext BeginTransceive(MemoryRegion inBuffer, MemoryRegion outBuffer) { return this.BeginFsControl(FsCtlTransceive, inBuffer, outBuffer); }
private SymbolNode Allocate( int classIndex, // In which class table this variable will be allocated to ? int classScope, // Variable's class scope. For example, it is a variable in base class int funcIndex, // In which function this variable is defined? string ident, ProtoCore.Type datatype, bool isStatic = false, ProtoCore.CompilerDefinitions.AccessModifier access = ProtoCore.CompilerDefinitions.AccessModifier.Public, MemoryRegion region = MemoryRegion.MemStack, int line = -1, int col = -1, GraphNode graphNode = null ) { bool allocateForBaseVar = classScope < classIndex; bool isProperty = classIndex != Constants.kInvalidIndex && funcIndex == Constants.kInvalidIndex; if (!allocateForBaseVar && !isProperty && core.ClassTable.IndexOf(ident) != ProtoCore.DSASM.Constants.kInvalidIndex) buildStatus.LogSemanticError(String.Format(Resources.ClassNameAsVariableError, ident), null, line, col, graphNode); ProtoCore.DSASM.SymbolNode symbolnode = new ProtoCore.DSASM.SymbolNode(); symbolnode.name = ident; symbolnode.isTemp = ident.StartsWith("%"); symbolnode.isSSATemp = CoreUtils.IsSSATemp(ident); symbolnode.functionIndex = funcIndex; symbolnode.absoluteFunctionIndex = funcIndex; symbolnode.datatype = datatype; symbolnode.staticType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Var, Constants.kArbitraryRank); symbolnode.isArgument = false; symbolnode.memregion = region; symbolnode.classScope = classScope; symbolnode.absoluteClassScope = classScope; symbolnode.runtimeTableIndex = codeBlock.symbolTable.RuntimeIndex; symbolnode.isStatic = isStatic; symbolnode.access = access; symbolnode.codeBlockId = codeBlock.codeBlockId; if (this.isEmittingImportNode) symbolnode.ExternLib = core.CurrentDSFileName; int symbolindex = ProtoCore.DSASM.Constants.kInvalidIndex; if (IsInLanguageBlockDefinedInFunction()) { symbolnode.classScope = Constants.kGlobalScope; symbolnode.functionIndex = Constants.kGlobalScope; } if (ProtoCore.DSASM.Constants.kInvalidIndex != classIndex && !IsInLanguageBlockDefinedInFunction()) { // NOTE: the following comment and code is OBSOLETE - member // variable is not supported now // // Yu Ke: it is possible that class table contains same-named // symbols if a class inherits some member variables from base // class, so we need to check name + class index + function // index. // //if (core.classTable.list[classIndex].symbols.IndexOf(ident, classIndex, funcIndex) != (int)ProtoCore.DSASM.Constants.kInvalidIndex) // return null; symbolindex = core.ClassTable.ClassNodes[classIndex].Symbols.IndexOf(ident); if (symbolindex != ProtoCore.DSASM.Constants.kInvalidIndex) { ProtoCore.DSASM.SymbolNode node = core.ClassTable.ClassNodes[classIndex].Symbols.symbolList[symbolindex]; if (node.functionIndex == ProtoCore.DSASM.Constants.kGlobalScope && funcIndex == ProtoCore.DSASM.Constants.kGlobalScope) return null; } symbolindex = core.ClassTable.ClassNodes[classIndex].Symbols.Append(symbolnode); if (symbolindex == ProtoCore.DSASM.Constants.kInvalidIndex) { return null; } if (isStatic) { Validity.Assert(funcIndex == ProtoCore.DSASM.Constants.kGlobalScope); ProtoCore.DSASM.SymbolNode staticSymbolnode = new ProtoCore.DSASM.SymbolNode(); staticSymbolnode.name = ident; staticSymbolnode.isTemp = ident.StartsWith("%"); staticSymbolnode.isSSATemp = CoreUtils.IsSSATemp(ident); staticSymbolnode.functionIndex = funcIndex; staticSymbolnode.datatype = datatype; staticSymbolnode.staticType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Var, Constants.kArbitraryRank); staticSymbolnode.isArgument = false; staticSymbolnode.memregion = region; staticSymbolnode.classScope = classScope; staticSymbolnode.runtimeTableIndex = codeBlock.symbolTable.RuntimeIndex; staticSymbolnode.isStatic = isStatic; staticSymbolnode.access = access; staticSymbolnode.codeBlockId = codeBlock.codeBlockId; if (this.isEmittingImportNode) staticSymbolnode.ExternLib = core.CurrentDSFileName; // If inherits a static property from base class, that propery // symbol should have been added to code block's symbol table, // so we just update symbolTableIndex int staticSymbolindex = codeBlock.symbolTable.IndexOf(ident, classScope); if (staticSymbolindex == ProtoCore.DSASM.Constants.kInvalidIndex) { AllocateVar(staticSymbolnode); staticSymbolindex = codeBlock.symbolTable.Append(staticSymbolnode); if (staticSymbolindex == ProtoCore.DSASM.Constants.kInvalidIndex) { return null; } staticSymbolnode.symbolTableIndex = staticSymbolindex; } symbolnode.symbolTableIndex = staticSymbolindex; } else { AllocateVar(symbolnode); } } else { AllocateVar(symbolnode); symbolindex = codeBlock.symbolTable.Append(symbolnode); if (symbolindex == ProtoCore.DSASM.Constants.kInvalidIndex) { return null; } symbolnode.symbolTableIndex = symbolindex; } if (ProtoCore.DSASM.Constants.kInvalidIndex == symbolindex) { return null; } return symbolnode; }
public PortMessage(MemoryRegion data, short dataLength) : this(null, data, dataLength) { }
public PortMessage(PortMessage existingMessage, MemoryRegion data, short dataLength) { this.InitializeMessage(existingMessage, data, dataLength); }
public static SecPkgInfo[] GetSSPackages() { int result; int count; IntPtr packages; result = Win32.EnumerateSecurityPackages(out count, out packages); if (result != 0) Win32.Throw(result); var alloc = new MemoryRegion(packages); try { SecPkgInfo[] array = new SecPkgInfo[count]; for (int i = 0; i < count; i++) array[i] = alloc.ReadStruct<SecPkgInfo>(i); return array; } finally { Win32.FreeContextBuffer(packages); } }
public static string GetMessage(IntPtr dllHandle, int messageTableId, int messageLanguageId, int messageId) { NtStatus status; IntPtr messageEntry; string message; status = Win32.RtlFindMessage( dllHandle, messageTableId, messageLanguageId, messageId, out messageEntry ); if (status.IsError()) return null; var region = new MemoryRegion(messageEntry); var entry = region.ReadStruct<MessageResourceEntry>(); // Read the message, depending on format. if ((entry.Flags & MessageResourceFlags.Unicode) == MessageResourceFlags.Unicode) { message = region.ReadUnicodeString(MessageResourceEntry.TextOffset); } else { message = region.ReadAnsiString(MessageResourceEntry.TextOffset); } return message; }
public static AceType GetType(IntPtr ace) { MemoryRegion memory = new MemoryRegion(ace); return memory.ReadStruct<AceHeader>().AceType; }