Title: Interop.cs minor changes · Issue #41 · GhostPack/SharpDPAPI · GitHub
Open Graph Title: Interop.cs minor changes · Issue #41 · GhostPack/SharpDPAPI
X Title: Interop.cs minor changes · Issue #41 · GhostPack/SharpDPAPI
Description: Hi, I just wanted to leave this here in case anyone is interested in adding this. It may not be suitable due to compatibility requirements on the project, but the changes get rid of some warnings for newer C# and .NET. diff --git a/Inter...
Open Graph Description: Hi, I just wanted to leave this here in case anyone is interested in adding this. It may not be suitable due to compatibility requirements on the project, but the changes get rid of some warnings f...
X Description: Hi, I just wanted to leave this here in case anyone is interested in adding this. It may not be suitable due to compatibility requirements on the project, but the changes get rid of some warnings f...
Opengraph URL: https://github.com/GhostPack/SharpDPAPI/issues/41
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Interop.cs minor changes","articleBody":"Hi,\r\n\r\nI just wanted to leave this here in case anyone is interested in adding this. It may not be suitable due to compatibility requirements on the project, but the changes get rid of some warnings for newer C# and .NET.\r\n\r\n```patch\r\ndiff --git a/Interop.cs b/Interop.cs\r\nindex 99544ba..c864c8c 100644\r\n--- a/Interop.cs\r\n+++ b/Interop.cs\r\n@@ -1,16 +1,10 @@\r\n-using System;\r\n-using System.Collections.Generic;\r\n-using System.ComponentModel;\r\n-using System.Diagnostics;\r\n-using System.Linq;\r\n+using System.ComponentModel;\r\n using System.Runtime.InteropServices;\r\n-using System.Security.Principal;\r\n using System.Text;\r\n-using System.Text.RegularExpressions;\r\n \r\n namespace SharpDPAPI\r\n {\r\n public class Interop\r\n {\r\n public enum CryptAlgClass : uint\r\n {\r\n@@ -164,15 +158,15 @@ namespace SharpDPAPI\r\n {\r\n Marshal.FreeHGlobal(buffer);\r\n buffer = IntPtr.Zero;\r\n }\r\n \r\n public override string ToString()\r\n {\r\n- return Marshal.PtrToStringUni(buffer);\r\n+ return Marshal.PtrToStringUni(buffer) ?? \"\";\r\n }\r\n }\r\n \r\n // From Vincent LE TOUX' \"MakeMeEnterpriseAdmin\"\r\n // https://github.com/vletoux/MakeMeEnterpriseAdmin/blob/master/MakeMeEnterpriseAdmin.ps1#L1773-L1794\r\n [StructLayout(LayoutKind.Sequential)]\r\n public struct KERB_ECRYPT\r\n@@ -280,15 +274,15 @@ namespace SharpDPAPI\r\n {\r\n Marshal.FreeHGlobal(buffer);\r\n buffer = IntPtr.Zero;\r\n }\r\n \r\n public override string ToString()\r\n {\r\n- return Marshal.PtrToStringUni(buffer);\r\n+ return Marshal.PtrToStringUni(buffer) ?? \"\";\r\n }\r\n }\r\n \r\n [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]\r\n public struct DOMAIN_CONTROLLER_INFO\r\n {\r\n [MarshalAs(UnmanagedType.LPTStr)]\r\n@@ -545,29 +539,33 @@ namespace SharpDPAPI\r\n public static extern int NetApiBufferFree(IntPtr Buffer);\r\n \r\n \r\n public static string GetDCName()\r\n {\r\n // retrieves the current domain controller name\r\n // adapted from https://www.pinvoke.net/default.aspx/netapi32.dsgetdcname\r\n- DOMAIN_CONTROLLER_INFO domainInfo;\r\n+ DOMAIN_CONTROLLER_INFO? domainInfo;\r\n const int ERROR_SUCCESS = 0;\r\n IntPtr pDCI = IntPtr.Zero;\r\n \r\n int val = DsGetDcName(\"\", \"\", 0, \"\",\r\n DSGETDCNAME_FLAGS.DS_DIRECTORY_SERVICE_REQUIRED |\r\n DSGETDCNAME_FLAGS.DS_RETURN_DNS_NAME |\r\n DSGETDCNAME_FLAGS.DS_IP_REQUIRED, out pDCI);\r\n \r\n if (ERROR_SUCCESS == val)\r\n {\r\n- domainInfo = (DOMAIN_CONTROLLER_INFO)Marshal.PtrToStructure(pDCI, typeof(DOMAIN_CONTROLLER_INFO));\r\n- string dcName = domainInfo.DomainControllerName;\r\n+ domainInfo = (DOMAIN_CONTROLLER_INFO?)Marshal.PtrToStructure(pDCI, typeof(DOMAIN_CONTROLLER_INFO));\r\n+ if (domainInfo is null)\r\n+ {\r\n+ return \"\";\r\n+ }\r\n+ string? dcName = domainInfo?.DomainControllerName;\r\n NetApiBufferFree(pDCI);\r\n- return dcName.Trim('\\\\');\r\n+ return dcName?.Trim('\\\\') ?? \"\";\r\n }\r\n else\r\n {\r\n string errorMessage = new Win32Exception((int)val).Message;\r\n Console.WriteLine(\"\\r\\n [X] Error {0} retrieving domain controller : {1}\", val, errorMessage);\r\n NetApiBufferFree(pDCI);\r\n return \"\";\r\n```\r\n\r\nSame patch as zipped up .diff file: [patch.zip](https://github.com/user-attachments/files/17559677/patch.zip).\r\n\r\nPS: this should apply cleanly to 4428263fe85bb1fde1640b6208d11dff6db4fb55.","author":{"url":"https://github.com/exoosh","@type":"Person","name":"exoosh"},"datePublished":"2024-10-29T15:52:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/41/SharpDPAPI/issues/41"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f763b553-7718-6a82-ab09-537d89a77d15 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E696:344520:3CE90F8:511E754:6981AD73 |
| html-safe-nonce | 6110c846e87fbbe5efd79c15c60b63351deb3d5cae08c21768a06cb1ae0b0304 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjk2OjM0NDUyMDozQ0U5MEY4OjUxMUU3NTQ6Njk4MUFENzMiLCJ2aXNpdG9yX2lkIjoiMTkyNTc2MDQwNDExMDI5MDI5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fa94c78508158ab769b5965734c5306551e155d6b98357eed211399a0696f2e2 |
| hovercard-subject-tag | issue:2621681224 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/GhostPack/SharpDPAPI/41/issue_layout |
| twitter:image | https://opengraph.githubassets.com/65ec3e485921324548a23391584d1572ae0a9fabfd4063ef0eab1635d7bd602d/GhostPack/SharpDPAPI/issues/41 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/65ec3e485921324548a23391584d1572ae0a9fabfd4063ef0eab1635d7bd602d/GhostPack/SharpDPAPI/issues/41 |
| og:image:alt | Hi, I just wanted to leave this here in case anyone is interested in adding this. It may not be suitable due to compatibility requirements on the project, but the changes get rid of some warnings f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | exoosh |
| hostname | github.com |
| expected-hostname | github.com |
| None | e137814e266030874fd2c86863529d0622b13889eeda04148c57654b6ea84ad6 |
| turbo-cache-control | no-preview |
| go-import | github.com/GhostPack/SharpDPAPI git https://github.com/GhostPack/SharpDPAPI.git |
| octolytics-dimension-user_id | 41304335 |
| octolytics-dimension-user_login | GhostPack |
| octolytics-dimension-repository_id | 145742418 |
| octolytics-dimension-repository_nwo | GhostPack/SharpDPAPI |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 145742418 |
| octolytics-dimension-repository_network_root_nwo | GhostPack/SharpDPAPI |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | dd58d68a7813bbec9c91422c8c35f4af33832d70 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width