< Summary

Class:SharpHoundRPC.Handles.BasePointer
Assembly:SharpHoundRPC
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\SharpHoundRPC\Handles\BasePointer.cs
Covered lines:0
Uncovered lines:39
Coverable lines:39
Total lines:68
Line coverage:0% (0 of 39)
Covered branches:0
Total branches:14
Branch coverage:0% (0 of 14)

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%100%
.ctor(...)100%100%
.ctor(...)100%100%
.ctor(...)100%100%
GetEnumerable()0%800%
GetData()0%600%
ReadInt32(...)100%100%
ReadInt64(...)100%100%
ReadIntPtr(...)100%100%

File(s)

D:\a\SharpHoundCommon\SharpHoundCommon\src\SharpHoundRPC\Handles\BasePointer.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Runtime.InteropServices;
 4using System.Security.Principal;
 5using Microsoft.Win32.SafeHandles;
 6
 7namespace SharpHoundRPC.Handles
 8{
 9    public abstract class BasePointer : SafeHandleZeroOrMinusOneIsInvalid
 10    {
 011        protected BasePointer() : base(true)
 012        {
 013        }
 14
 015        protected BasePointer(bool ownsHandle) : base(ownsHandle)
 016        {
 017        }
 18
 019        protected BasePointer(IntPtr handle) : base(true)
 020        {
 021            SetHandle(handle);
 022        }
 23
 024        protected BasePointer(IntPtr handle, bool ownsHandle) : base(ownsHandle)
 025        {
 026            SetHandle(handle);
 027        }
 28
 29        public IEnumerable<T> GetEnumerable<T>(int count)
 030        {
 031            for (var i = 0; i < count; i++)
 032                if (typeof(T) == typeof(int))
 033                    yield return (T) (object) ReadInt32(i);
 034                else if (typeof(T) == typeof(long))
 035                    yield return (T) (object) ReadInt64(i);
 036                else if (typeof(T) == typeof(SecurityIdentifier))
 037                    yield return (T) (object) new SecurityIdentifier(ReadIntPtr(i));
 38                else
 039                    yield return Marshal.PtrToStructure<T>(handle + Marshal.SizeOf<T>() * i);
 040        }
 41
 42        public T GetData<T>()
 043        {
 044            if (typeof(T) == typeof(int)) return (T) (object) ReadInt32();
 45
 046            if (typeof(T) == typeof(long)) return (T) (object) ReadInt64();
 47
 048            if (typeof(T) == typeof(SecurityIdentifier)) return (T) (object) new SecurityIdentifier(handle);
 49
 050            return Marshal.PtrToStructure<T>(handle);
 051        }
 52
 53        private int ReadInt32(int offset = 0)
 054        {
 055            return Marshal.ReadInt32(handle + offset * Marshal.SizeOf<int>());
 056        }
 57
 58        private long ReadInt64(int offset = 0)
 059        {
 060            return Marshal.ReadInt64(handle + offset * Marshal.SizeOf<long>());
 061        }
 62
 63        private IntPtr ReadIntPtr(int offset = 0)
 064        {
 065            return Marshal.ReadIntPtr(handle + offset * Marshal.SizeOf<IntPtr>());
 066        }
 67    }
 68}