Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. using System;
  2. using System.Security;
  3. using System.Runtime.InteropServices;
  4.  
  5. namespace consoletest
  6. {
  7.  
  8. class Program
  9. {
  10. [DllImport("libc")]
  11. static extern int uname(IntPtr buf);
  12.  
  13. [SuppressUnmanagedCodeSecurity]
  14. [DllImport("/usr/lib/libdl.so")]
  15. static extern IntPtr dlopen(string filename, int flags);
  16.  
  17. [DllImport("/usr/lib/libdl.so")]
  18. static extern IntPtr dlerror();
  19.  
  20. [DllImport("/usr/lib/libdl.so")]
  21. static extern IntPtr dlsym(IntPtr handle, String symbol);
  22.  
  23. static string GetUname()
  24. {
  25. var buffer = Marshal.AllocHGlobal(8192);
  26. try
  27. {
  28. if (uname(buffer) == 0)
  29. {
  30. return Marshal.PtrToStringAnsi(buffer);
  31. }
  32. return string.Empty;
  33. }
  34. catch
  35. {
  36. return string.Empty;
  37. }
  38. finally
  39. {
  40. if (buffer != IntPtr.Zero)
  41. {
  42. Marshal.FreeHGlobal(buffer);
  43. }
  44. }
  45. }
  46.  
  47. static void Main(string[] args)
  48. {
  49. Console.WriteLine("Hello World! from: " + GetUname());
  50.  
  51. var ret = dlopen("/usr/local/lib/libpng.so", 2);
  52. if (ret == IntPtr.Zero)
  53. {
  54. var errorMsg = Marshal.PtrToStringAnsi(dlerror());
  55. Console.WriteLine(errorMsg);
  56. }
  57.  
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement