[FEATURE][EXPERIMENTAL] Проверка Stacktrace в агента

This commit is contained in:
Gravit 2019-09-30 08:40:32 +07:00
parent efd58d66c7
commit 8e1000ec41
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -32,18 +32,33 @@ public boolean isAgentStarted() {
public static void premain(String agentArgument, Instrumentation instrumentation) {
System.out.println("Launcher Agent");
checkAgentStacktrace();
inst = instrumentation;
SafeExitJVMLegacy.class.getName();
SafeExitJVM.class.getName();
NativeJVMHalt.class.getName();
NativeJVMHalt.initFunc();
boolean bad = false;
try {
for (StackTraceElement e : new Throwable().getStackTrace())
if (Class.forName(e.getClassName()).getClassLoader() != Runtime.class.getClassLoader() && Class.forName(e.getClassName()) != LauncherAgent.class) bad = true;
} catch(Throwable e) { bad = true; }
if (bad) NativeJVMHalt.haltA(-17);
else isAgentStarted = true;
//SafeExitJVMLegacy.class.getName();
//SafeExitJVM.class.getName();
//NativeJVMHalt.class.getName();
//NativeJVMHalt.initFunc();
isAgentStarted = true;
}
public static void checkAgentStacktrace()
{
RuntimeException ex = new SecurityException("Error check agent stacktrace");
boolean isFoundNative = false;
boolean foundPreMain = false;
for(StackTraceElement e : ex.getStackTrace())
{
if(e.isNativeMethod())
{
if(!isFoundNative) isFoundNative = true;
else throw ex;
}
if(e.getMethodName().equals("premain"))
{
if(!foundPreMain) foundPreMain = true;
else throw ex;
}
}
if(!isFoundNative || !foundPreMain) throw ex;
}
public static boolean isStarted() {