Class NativeHelper

  • All Implemented Interfaces:
    INativeHelper

    public final class NativeHelper
    extends java.lang.Object
    implements INativeHelper
    Helper class using JNA to provide native features.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected NativeHelper()
      Create helper.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canSetAccessible()
      Tests if the setAccessible() method can be used.
      java.lang.Class<?> defineClass​(java.lang.String name, byte[] b, java.lang.ClassLoader loader)
      Define a class in any ClassLoader.
      boolean isRootAdmin()
      Tests if the JVM is running as root/admin.
      static void main​(java.lang.String[] args)
      Test main
      void setAccessible​(java.lang.String flagname, java.lang.reflect.AccessibleObject accobj, boolean flag)
      Sets reflective object accessible without checks.
      boolean startInstrumentationAgent​(java.lang.String jarfile)
      Method for starting an instrumentation agent.
      boolean tryChangeUser​(java.lang.String username)
      Attempts to change the user of the process to the given name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NativeHelper

        protected NativeHelper()
        Create helper.
    • Method Detail

      • setAccessible

        public void setAccessible​(java.lang.String flagname,
                                  java.lang.reflect.AccessibleObject accobj,
                                  boolean flag)
        Sets reflective object accessible without checks.
        Specified by:
        setAccessible in interface INativeHelper
        Parameters:
        accobj - The accessible object.
        flag - The flag value.
      • canSetAccessible

        public boolean canSetAccessible()
        Tests if the setAccessible() method can be used.
        Specified by:
        canSetAccessible in interface INativeHelper
        Returns:
        True, if method can be used.
      • defineClass

        public java.lang.Class<?> defineClass​(java.lang.String name,
                                              byte[] b,
                                              java.lang.ClassLoader loader)
        Define a class in any ClassLoader.
        Specified by:
        defineClass in interface INativeHelper
      • tryChangeUser

        public boolean tryChangeUser​(java.lang.String username)
        Attempts to change the user of the process to the given name.
        Specified by:
        tryChangeUser in interface INativeHelper
        Parameters:
        username - The target user name.
        Returns:
        True, if successful, false if the attempt probably failed.
      • isRootAdmin

        public boolean isRootAdmin()
        Tests if the JVM is running as root/admin.
        Returns:
        True, if running as root.
      • startInstrumentationAgent

        public boolean startInstrumentationAgent​(java.lang.String jarfile)
        Method for starting an instrumentation agent.
        Specified by:
        startInstrumentationAgent in interface INativeHelper
        Parameters:
        jarfile - The path to the jar file of the agent.
        Returns:
        True, on successful start.
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Test main
        Throws:
        java.lang.Exception