Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Security;
- using System.Runtime.InteropServices;
- namespace consoletest
- {
- class Program
- {
- [DllImport("libc")]
- static extern int uname(IntPtr buf);
- [SuppressUnmanagedCodeSecurity]
- [DllImport("/usr/lib/libdl.so")]
- static extern IntPtr dlopen(string filename, int flags);
- [DllImport("/usr/lib/libdl.so")]
- static extern IntPtr dlerror();
- [DllImport("/usr/lib/libdl.so")]
- static extern IntPtr dlsym(IntPtr handle, String symbol);
- static string GetUname()
- {
- var buffer = Marshal.AllocHGlobal(8192);
- try
- {
- if (uname(buffer) == 0)
- {
- return Marshal.PtrToStringAnsi(buffer);
- }
- return string.Empty;
- }
- catch
- {
- return string.Empty;
- }
- finally
- {
- if (buffer != IntPtr.Zero)
- {
- Marshal.FreeHGlobal(buffer);
- }
- }
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World! from: " + GetUname());
- var ret = dlopen("/usr/local/lib/libpng.so", 2);
- if (ret == IntPtr.Zero)
- {
- var errorMsg = Marshal.PtrToStringAnsi(dlerror());
- Console.WriteLine(errorMsg);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement