mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 15:10:43 +08:00
feat: logRemover support Logger.info and warning
This commit is contained in:
@@ -42,7 +42,9 @@ public class LogRemoveMethodVisitor implements AsmVisitorWrapper.ForDeclaredMeth
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
|
||||
if ((opcode == INVOKEVIRTUAL && owner.equals("java/io/PrintStream") && name.equals("println"))
|
||||
|| (opcode == INVOKEVIRTUAL && owner.endsWith("Exception") && name.equals("printStackTrace"))) {
|
||||
|| (opcode == INVOKEVIRTUAL && owner.endsWith("Exception") && name.equals("printStackTrace"))
|
||||
|| (opcode == INVOKEVIRTUAL && owner.equals("java/util/logging/Logger") && (name.equals("info") || name.equals("warning")))
|
||||
) {
|
||||
String[] args = descriptor.substring(1, descriptor.indexOf(')')).split(";");
|
||||
for (String arg : args) {
|
||||
if (StringUtils.isNotBlank(arg)) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@@ -94,19 +95,26 @@ class LogRemoveVisitorWrapperTest {
|
||||
}
|
||||
|
||||
public static class TestClass {
|
||||
static Logger logger = Logger.getLogger(TestClass.class.getName());
|
||||
public TestClass() {
|
||||
}
|
||||
|
||||
public void methodWithLogs() {
|
||||
public static void methodWithLogs() {
|
||||
System.out.println("This should be removed");
|
||||
String test = "test";
|
||||
int length = test.length();
|
||||
logger.info(test);
|
||||
try {
|
||||
System.out.println("hello");
|
||||
throw new RuntimeException("hello");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logger.warning("wa");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
methodWithLogs();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user