Can you do a code injection in asp.net with Debug.assert()?
I am trying to understand code injection in different technologies.
In the case of asp.net, is it possible to be vulnerable to code injection if i am using Debug.assert?
E.g.-
Debug.Assert(maliciousUserInput == null);
See also questions close to this topic
-
Convert CSV file data from any language to English in C#
I would like to convert CSV file data from multi languages such as Spanish, Russian, European etc to English language in C# program.
Convert all characters like Ó, É to English characters.
Thanks.
-
I get an error when solving this problem, How can I fix?
I am trying to solve the Climbstairs problem but in reverse, where I want to know the number of steps I have to take to go down.
I can go down 1, 2, 3 or 4 steps at the same time. That is, if I am at step i, I can go down to step i - a for any of the values 1, 2, 3 or 4 of a.
I have the following code but I don't know what happens:
I got this error: System.IndexOutOfRangeException in this line:
steps[i] += steps[i - a];
Why I have this error?
public static int DownStairs(int n) { int[] steps = new int[n + 1]; steps[n] = 1; steps[n - 1] = 1; for (int i = n-2; i>=0; i--) { for(int a = 1; a<=4; a++) { steps[i] += steps[i - a]; } } return steps[n]; } static void Main(string[] args) { int n = 5; DownStairs(n); }
-
How to delete multiple blank lines in a WPF DataGrid imported from an Excel file
I have a WPF DataGrid which I fill with imported data from an Excel file (*. Xlsx) through a class, the problem is that multiple blank lines are added to the end of the DataGrid that I don't see how to delete. I attach my code.
<DataGrid Name="dgvMuros" Height="210" Margin="8" VerticalAlignment="Top" Padding="5,6" ColumnWidth="50" IsReadOnly="False" AlternatingRowBackground="Azure" GridLinesVisibility="All" HeadersVisibility="Column" Loaded="dgvMuros_Loaded" CellEditEnding="DataGrid_CellEditEnding" ItemsSource="{Binding Data}" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" > </DataGrid>
With this method I import the data from the Excel file.
public void ImportarMuros() { ExcelData dataFronExcel = new ExcelData(); this.dgvMuros.DataContext = dataFronExcel; txtTotMuros.Text = dataFronExcel.numMuros.ToString(); cmdAgregarMuros.IsEnabled = false; cmdBorrarMuros.IsEnabled = false; cmdImportar.IsEnabled = false; } public class ExcelData { public int numMuros { get; set; } public DataView Data { get { Excel.Application excelApp = new Excel.Application(); Excel.Workbook workbook; Excel.Worksheet worksheet; Excel.Range range; workbook = excelApp.Workbooks.Open(Environment.CurrentDirectory + "\\MurosEjemplo.xlsx"); worksheet = (Excel.Worksheet)workbook.Sheets["DatMuros"]; int column = 0; int row = 0; range = worksheet.UsedRange; DataTable dt = new DataTable(); dt.Columns.Add("Muro"); dt.Columns.Add("Long"); dt.Columns.Add("Esp"); dt.Columns.Add("X(m)"); dt.Columns.Add("Y(m)"); dt.Columns.Add("Dir"); for (row = 2; row < range.Rows.Count; row++) { DataRow dr = dt.NewRow(); for (column = 1; column <= range.Columns.Count; column++) { dr[column - 1] = Convert.ToString((range.Cells[row, column] as Excel.Range).Value); } dt.Rows.Add(dr); dt.AcceptChanges(); numMuros = dt.Rows.Count; } workbook.Close(true, Missing.Value, Missing.Value); excelApp.Quit(); return dt.DefaultView; } } }
-
Huge amount of logon attempts when loading a page (without cache)
I notice in the Performance Monitor of Windows Server 2012 that there are spikes in logon attempts per second under Web Service -> Logon Attempts/sec. These spikes go from about 0 to 50.
I've traced this down to a page refresh. Loading a page with no cache that is. An average page load does about 50 requests (images, scripts, etc). Now apparently these 50 requests are shown as logon attempts.
Is this normal?
Note that this page does not require the visitor to be logged in.
-
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3\
When warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {e43b756a-2818-4898-8730-5e8e0f230be7} may be persisted to storage in unencrypted form.
info: IdentityServer4.Startup[0]
Starting IdentityServer4 version 4.1.1+cebd52f5bc61bdefc262fd20739d4d087c6f961f
info: IdentityServer4.Startup[0]
You are using the in-memory version of the persisted grant store. This will store consent decisions, authorization codes, refresh and reference tokens in memory only. If you are using any of those features in production, you want to switch to a different store implementation.
info: IdentityServer4.Startup[0]
Using the default authentication scheme Identity.Application for IdentityServer
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://[::]:8081
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:8080
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
info: IdentityServer4.Hosting.IdentityServerMiddleware[0]
Invoking IdentityServer endpoint: IdentityServer4.Endpoints.TokenEndpoint for /connect/token
info: IdentityServer4.AspNetIdentity.ResourceOwnerPasswordValidator[0]
Credentials validated for username: muthu
info: IdentityServer4.Validation.TokenRequestValidator[0]
Token request validation success, {
"ClientId": "sdgfsdsgsdg",
"ClientName": "Swagger UI",
"GrantType": "password",
"Scopes": "api",
"AuthorizationCode": "********",
"RefreshToken": "********",
"UserName": "sample",
"Raw": {
"grant_type": "password",
"username": "sample",
"password": "REDACTED"
}
}
fail: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3]
Exception occurred while processing message.
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'http://*:8080/.well-known/openid-configuration'.
---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'http://*:8080/.well-known/openid-configuration'.
---> System.UriFormatException: Invalid URI: The hostname could not be parsed.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
fail: IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler[0]
IDX20803: Unable to obtain configuration from: 'http://*:8080/.well-known/openid-configuration'.
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'http://*:8080/.well-known/openid-configuration'.
---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'http://*:8080/.well-known/openid-configuration'.
---> System.UriFormatException: Invalid URI: The hostname could not be parsed.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler.HandleAuthenticateAsync()
info: IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler[7]
Bearer was not authenticated. Failure message: IDX20803: Unable to obtain configuration from: 'http://*:8080/.well-known/openid-configuration'.
info: IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler[12]
AuthenticationScheme: Bearer was challenged.
-
ASP.NET using return RedirectToAction(" ", " ") how to use this to redirect to a cshtml
I can not find a useable tutorial that explains how to redirect using REdirectToAction. can someone share a link that that explains ALL the steps needed to use this? I think I am having a hard time understanding how the parameters are given can find an HTML file with a model in the parameter? or is it a controller? I am very lost on how they communicate. please someone if you can help.
-
How do I split a string by spaces except if in single or double quotes
I realize this question has been asked many times here. I have looked at and tried many of the answers but none of them work for me.
I am creating an application using C# that can accept command line arguments. e.g.
Start -p:SomeNameValue -h
DisplayMessage -m:Hello
DisplayMessage -m:'Hello World'
DisplayMessage -m:"Hello World"
My args come in as a single string. I need to split by spaces except where there are single or double quotes. So the above would end up as
Start
-p:SomeNameValue
-h
DisplayMessage
-m:Hello
DisplayMessage
-m:'Hello World'
DisplayMessage
-m:"Hello World"
The answers I have found on here seem to break. e.g. They remove the
:
character or just don't work at all. Some of the code I've tried as follows:var res1 = Regex.Matches(payload, @"[\""].+?[\""]|[^ ]+") .Cast<Match>() .Select(m => m.Value) .ToList();
var res2 = payload.Split('"') .Select((element, index) => index % 2 == 0 ? element.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { element }) // Keep the entire item .SelectMany(element => element).ToList();
var res3 = Regex .Matches(payload, @"\w+|""[\w\s]*""") .Cast<Match>() .Select(m => m.Groups["match"].Value) .ToList();
string[] res4 = Regex.Split(payload, ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
Regex regex = new Regex(@"\w+|""[\w\s]*"""); var res5 = regex.Matches(payload).Cast<Match>().ToList();
I simply want to split the arg into blocks as per above.
-
ZipArchiveEntry to create xlsx file, but found it'll lost `CompressionOption` and `ContentType` and `Uri` and `Package` information
I try to use
ZipArchive
andZipArchiveEntry
to create xlsx file, but found it'll lostCompressionOption
andContentType
andUri
andPackage
information.normal information like :
but I used below code to and read
create xlsx code:
private static FileStream CreateZipFileStream(string path, Dictionary<string, object> filesTree) { using (FileStream stream = new FileStream(path, FileMode.CreateNew)) { using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create)) { foreach (var fileTree in filesTree) { ZipArchiveEntry entry = archive.CreateEntry(fileTree.Key); using (var zipStream = entry.Open()) { var bytes = Encoding.ASCII.GetBytes(fileTree.Value.ToString()); zipStream.Write(bytes, 0, bytes.Length); } } } return stream; } }
read xlsx:
using (Package xlsxPackage = Package.Open(fileName, FileMode.Open, FileAccess.Read)) { var allParts = xlsxPackage.GetParts(); //... }
It'll show I lost information
How can I add this information to xlsx? thanks!
-
AesGcm Class in Microsoft C#
I wonder if someone can explain these two functions from AES-GCM class of C#
public static byte[] Encrypt(byte[] toEncrypt, byte[] key, byte[] associatedData = null) { byte[] tag = new byte[KEY_BYTES]; byte[] nonce = new byte[NONCE_BYTES]; byte[] cipherText = new byte[toEncrypt.Length]; using (var cipher = new AesGcm(key)) { cipher.Encrypt(nonce, toEncrypt, cipherText, tag, associatedData); return Concat(tag, Concat(nonce, cipherText)); } } public static byte[] Decrypt(byte[] cipherText, byte[] key, byte[] associatedData = null) { byte[] tag = SubArray(cipherText, 0, KEY_BYTES); byte[] nonce = SubArray(cipherText, KEY_BYTES, NONCE_BYTES); byte[] toDecrypt = SubArray(cipherText, KEY_BYTES + NONCE_BYTES, cipherText.Length - tag.Length - nonce.Length); byte[] decryptedData = new byte[toDecrypt.Length]; using (var cipher = new AesGcm(key)) { cipher.Decrypt(nonce, toDecrypt, tag, decryptedData, associatedData); return decryptedData; } }
I know for AES-GCM we are generating two IVs and two encryption keys (client to server) and (server to client)
Let's say
- Key A: client to server initial IV
- Key C: client to server encryption
- Key B: server to client initial IV
- Key D: server to client encryption
Can we put 16 bytes of key and 12 bytes of IV directly as input into the above functions?
If not what are the right key and IV we should feed as inputs to above functions
-
Server not responding to scapy script
I have written a short script that is supposed to intercept a file by putting it in a netfilterqueue, change the file extension, and then send the file. This is my script:
#!/usr/bin/env python import netfilterqueue import scapy.all as scapy def process_packet(packet): scapy_packet = scapy.IP(packet.get_payload()) if scapy_packet.haslayer(scapy.Raw): if scapy_packet[scapy.TCP].dport == 80: load = str(scapy_packet[scapy.Raw].load).replace(".jpg", ".php") scapy_packet[scapy.Raw].load = load #print(scapy_packet.show()) packet.set_payload(str(scapy_packet)) packet.accept() queue = netfilterqueue.NetfilterQueue() queue.bind(0, process_packet) queue.run()
I am not getting an error when executing, but the Server is not responding to the request (TCP/IP). It seems to have something to do with how I change the package, since everything works fine when I do not edit the package. However, the package looks fine to me right before sending it. Could anyone tell me, why the server will not respond?
-
Manipulate php/sql with javascript
I have a simple web application. There is an input form where I can enter script tag (HTML too but not PHP). The goal is to modify the SQL database.
Can I execute PHP functions on the server side with client side javascript?
-
How to check if a process is "injectable"
I have following problem: I need to inject a DLL into a process. The injection is working fine if the process is running, respectively if the process (its a game) is in a loading screen. The problem now is, that I cant inject the dll when it just starting up. So even if the lenth of the ProcessName != null, but the process is not fully started the Injection does not work. U guys have any idea how to determine if the process is startet correctly. Mabye get the RAM usage or stuff like that? Code for the injection:
class Injector { public const int MAX_PATH = 260; private const int INVALID_HANDLE_VALUE = -1; [Flags] public enum ProcessAccessFlags : uint { All = 0x001F0FFF, Terminate = 0x00000001, CreateThread = 0x00000002, VirtualMemoryOperation = 0x00000008, VirtualMemoryRead = 0x00000010, VirtualMemoryWrite = 0x00000020, DuplicateHandle = 0x00000040, CreateProcess = 0x000000080, SetQuota = 0x00000100, SetInformation = 0x00000200, QueryInformation = 0x00000400, QueryLimitedInformation = 0x00001000, Synchronize = 0x00100000 } [Flags] private enum SnapshotFlags : uint { HeapList = 0x00000001, Process = 0x00000002, Thread = 0x00000004, Module = 0x00000008, Module32 = 0x00000010, Inherit = 0x80000000, All = 0x0000001F, NoHeaps = 0x40000000 } [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr OpenProcess(ProcessAccessFlags processAccess, bool bInheritHandle, int processId); [StructLayout(LayoutKind.Sequential)] public struct PROCESSENTRY32 { public uint dwSize; public uint cntUsage; public uint th32ProcessID; public IntPtr th32DefaultHeapID; public uint th32ModuleID; public uint cntThreads; public uint th32ParentProcessID; public int pcPriClassBase; public uint dwFlags; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szExeFile; }; [StructLayout(LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Ansi)] public struct MODULEENTRY32 { internal uint dwSize; internal uint th32ModuleID; internal uint th32ProcessID; internal uint GlblcntUsage; internal uint ProccntUsage; internal IntPtr modBaseAddr; internal uint modBaseSize; internal IntPtr hModule; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] internal string szModule; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] internal string szExePath; } [DllImport("kernel32.dll", SetLastError = true)] public static extern bool ReadProcessMemory( IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesRead); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool WriteProcessMemory( IntPtr hProcess, IntPtr lpBaseAddress, [MarshalAs(UnmanagedType.AsAny)] object lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten); [DllImport("kernel32.dll")] private static extern bool Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe); [DllImport("kernel32.dll")] private static extern bool Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe); [DllImport("kernel32.dll")] private static extern bool Module32First(IntPtr hSnapshot, ref MODULEENTRY32 lpme); [DllImport("kernel32.dll")] private static extern bool Module32Next(IntPtr hSnapshot, ref MODULEENTRY32 lpme); [DllImport("kernel32.dll", SetLastError = true)] private static extern bool CloseHandle(IntPtr hHandle); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr GetModuleHandle(string moduleName); [DllImport("kernel32.dll", SetLastError = true)] private static extern IntPtr CreateToolhelp32Snapshot(SnapshotFlags dwFlags, int th32ProcessID); [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] private static extern IntPtr GetProcAddress(IntPtr hModule, string procName); [DllImport("kernel32.dll")] private static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, out IntPtr lpThreadId); [Flags] public enum AllocationType { Commit = 0x1000, Reserve = 0x2000, Decommit = 0x4000, Release = 0x8000, Reset = 0x80000, Physical = 0x400000, TopDown = 0x100000, WriteWatch = 0x200000, LargePages = 0x20000000 } [Flags] public enum MemoryProtection { Execute = 0x10, ExecuteRead = 0x20, ExecuteReadWrite = 0x40, ExecuteWriteCopy = 0x80, NoAccess = 0x01, ReadOnly = 0x02, ReadWrite = 0x04, WriteCopy = 0x08, GuardModifierflag = 0x100, NoCacheModifierflag = 0x200, WriteCombineModifierflag = 0x400 } [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] private static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect); public static IntPtr GetModuleBaseAddress(Process proc, string modName) { IntPtr addr = IntPtr.Zero; foreach (ProcessModule m in proc.Modules) { if (m.ModuleName == modName) { addr = m.BaseAddress; break; } } return addr; } public static IntPtr GetModuleBaseAddress(int procId, string modName) { IntPtr modBaseAddr = IntPtr.Zero; IntPtr hSnap = CreateToolhelp32Snapshot(SnapshotFlags.Module | SnapshotFlags.Module32, procId); if (hSnap.ToInt64() != INVALID_HANDLE_VALUE) { MODULEENTRY32 modEntry = new MODULEENTRY32(); modEntry.dwSize = (uint)Marshal.SizeOf(typeof(MODULEENTRY32)); if (Module32First(hSnap, ref modEntry)) { do { if (modEntry.szModule.Equals(modName)) { modBaseAddr = modEntry.modBaseAddr; break; } } while (Module32Next(hSnap, ref modEntry)); } } CloseHandle(hSnap); return modBaseAddr; } public static int GetProcId(string procname) { int procid = 0; IntPtr hSnap = CreateToolhelp32Snapshot(SnapshotFlags.Process, 0); if (hSnap.ToInt64() != INVALID_HANDLE_VALUE) { PROCESSENTRY32 procEntry = new PROCESSENTRY32(); procEntry.dwSize = (uint)Marshal.SizeOf(typeof(PROCESSENTRY32)); if (Process32First(hSnap, ref procEntry)) { do { if (procEntry.szExeFile.Equals(procname)) { procid = (int)procEntry.th32ProcessID; break; } } while (Process32Next(hSnap, ref procEntry)); } } CloseHandle(hSnap); return procid; } public static IntPtr FindDMAAddy(IntPtr hProc, IntPtr ptr, int[] offsets) { var buffer = new byte[IntPtr.Size]; foreach (int i in offsets) { ReadProcessMemory(hProc, ptr, buffer, buffer.Length, out var read); ptr = (IntPtr.Size == 4) ? IntPtr.Add(new IntPtr(BitConverter.ToInt32(buffer, 0)), i) : ptr = IntPtr.Add(new IntPtr(BitConverter.ToInt64(buffer, 0)), i); } return ptr; } public static bool InjectDLL(string dllpath, string procname) { Process[] procs = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(procname)); if (procs.Length == 0) { return false; } Process proc = procs[0]; //redundant native method example - GetProcessesByName will automatically open a handle int procid = GetProcId(procname); IntPtr hProc = OpenProcess(ProcessAccessFlags.All, false, proc.Id); //System.Windows.Forms.MessageBox.Show(Convert.ToString(hProc)); // if (proc.Handle != IntPtr.Zero) { //proc.Handle = managed IntPtr loc = VirtualAllocEx(proc.Handle, IntPtr.Zero, MAX_PATH, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ReadWrite); if (loc.Equals(0)) { return false; } IntPtr bytesRead = IntPtr.Zero; bool result = WriteProcessMemory(proc.Handle, loc, dllpath.ToCharArray(), dllpath.Length, out bytesRead); if (!result || bytesRead.Equals(0)) { return false; } IntPtr loadlibAddy = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA"); //redundant native method example - MUST BE CASE SENSITIVE CORRECT loadlibAddy = GetProcAddress(GetModuleBaseAddress(proc.Id, "KERNEL32.DLL"), "LoadLibraryA"); IntPtr hThread = CreateRemoteThread(proc.Handle, IntPtr.Zero, 0, loadlibAddy, loc, 0, out _); if (!hThread.Equals(0)) //native method example CloseHandle(hThread); else return false; } else return false; //this will CloseHandle automatically using the managed method proc.Dispose(); return true; } }