We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak due to missing call to Marshal.FreeHGlobal for oa.objectName in failure path.
Marshal.FreeHGlobal
oa.objectName
You may want to put the code that releases resources in a finally block to close them if an exception is raised.
public static void DRegHideManualMap(String hive = "HKCU", String subKey = @"\SOFTWARE", String keyName = "", String keyValue = "", bool hiddenKey = false, bool deleteKey = false) { DInvoke.Data.PE.PE_MANUAL_MAP mappedDLL = new DInvoke.Data.PE.PE_MANUAL_MAP(); mappedDLL = DInvoke.ManualMap.Map.MapModuleToMemory(@"C:\Windows\System32\ntdll.dll"); try { ... IntPtr oaObjectName = Marshal.AllocHGlobal(Marshal.SizeOf(UC_RegKey)); ! Alloc'd before the call to `NtOpenKey` Marshal.StructureToPtr(UC_RegKey, oaObjectName, true); oa.Length = Marshal.SizeOf(oa); oa.Attributes = (uint)STRUCTS.OBJ_ATTRIBUTES.CASE_INSENSITIVE; oa.objectName = oaObjectName; ... retValue = (DInvoke.Data.Native.NTSTATUS)DInvoke.DynamicInvoke.Generic.CallMappedDLLModuleExport(mappedDLL.PEINFO, mappedDLL.ModuleBase, "NtOpenKey", typeof(DELEGATES.NtOpenKey), ntOpenKeyParams, false); keyHandle = (IntPtr)ntOpenKeyParams[0]; if (retValue == DInvoke.Data.Native.NTSTATUS.Success) { ... Marshal.FreeHGlobal(oa.objectName); ! `FreeHGlobal` is only called in the success path. If `NtOpenKey` fails, this memory is leaked. object[] ntCloseParams = { keyHandle }; retValue = (DInvoke.Data.Native.NTSTATUS)DInvoke.DynamicInvoke.Generic.CallMappedDLLModuleExport(mappedDLL.PEINFO, mappedDLL.ModuleBase, "NtClose", typeof(DELEGATES.NtClose), ntCloseParams, false); } else { Console.WriteLine("Regkey not found"); }
https://github.com/NVISO-BE/DInvisibleRegistry/blob/99f637a5a813cadffd859ba98d04f43daad8d270/Program.cs#L219
The same issue exists in DRegHideWithDeception() and DRegHide()
DRegHideWithDeception()
DRegHide()
https://github.com/NVISO-BE/DInvisibleRegistry/blob/99f637a5a813cadffd859ba98d04f43daad8d270/Program.cs#L325 https://github.com/NVISO-BE/DInvisibleRegistry/blob/99f637a5a813cadffd859ba98d04f43daad8d270/Program.cs#L110
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Issue 1
Memory leak due to missing call to
Marshal.FreeHGlobal
foroa.objectName
in failure path.You may want to put the code that releases resources in a finally block to close them if an exception is raised.
https://github.com/NVISO-BE/DInvisibleRegistry/blob/99f637a5a813cadffd859ba98d04f43daad8d270/Program.cs#L219
The same issue exists in
DRegHideWithDeception()
andDRegHide()
https://github.com/NVISO-BE/DInvisibleRegistry/blob/99f637a5a813cadffd859ba98d04f43daad8d270/Program.cs#L325
https://github.com/NVISO-BE/DInvisibleRegistry/blob/99f637a5a813cadffd859ba98d04f43daad8d270/Program.cs#L110
The text was updated successfully, but these errors were encountered: