Search in sources :

Example 1 with NameRegexFilter

use of com.shulie.instrument.simulator.api.filter.NameRegexFilter in project LinkAgent by shulieTech.

the class ScModule method sc.

@Command(value = "sc", description = "查找类")
public CommandResponse sc(final Map<String, String> param) {
    try {
        final String cnPattern = getParameter(param, "class");
        final String type = getParameter(param, "type");
        if (StringUtils.isBlank(type)) {
            Set<Class<?>> classes = loadedClassDataSource.find(new NameRegexFilter(cnPattern, ".*", true, true));
            List<String> classNames = new ArrayList<String>();
            for (Class<?> clazz : classes) {
                String name = clazz.getCanonicalName() + " " + clazz.getClassLoader().toString();
                classNames.add(name);
            }
            return CommandResponse.success(classNames);
        } else if (StringUtils.equals("s", type)) {
            Set<Class<?>> classes = loadedClassDataSource.find(new SuperNameRegexFilter(cnPattern, ".*", true, true));
            List<String> classNames = new ArrayList<String>();
            for (Class<?> clazz : classes) {
                String name = clazz.getCanonicalName() + " " + clazz.getClassLoader().toString();
                classNames.add(name);
            }
            return CommandResponse.success(classNames);
        } else if (StringUtils.equals("i", type)) {
            Set<Class<?>> classes = loadedClassDataSource.find(new InterfaceNameRegexFilter(cnPattern, ".*", true, true));
            List<String> classNames = new ArrayList<String>();
            for (Class<?> clazz : classes) {
                String name = clazz.getCanonicalName() + " " + clazz.getClassLoader().toString();
                classNames.add(name);
            }
            return CommandResponse.success(classNames);
        }
        return CommandResponse.failure("Unsupported type value:" + type);
    } catch (Throwable e) {
        return CommandResponse.failure(e);
    }
}
Also used : SuperNameRegexFilter(com.shulie.instrument.simulator.module.util.SuperNameRegexFilter) SuperNameRegexFilter(com.shulie.instrument.simulator.module.util.SuperNameRegexFilter) InterfaceNameRegexFilter(com.shulie.instrument.simulator.module.util.InterfaceNameRegexFilter) NameRegexFilter(com.shulie.instrument.simulator.api.filter.NameRegexFilter) Set(java.util.Set) ArrayList(java.util.ArrayList) InterfaceNameRegexFilter(com.shulie.instrument.simulator.module.util.InterfaceNameRegexFilter) ArrayList(java.util.ArrayList) List(java.util.List) Command(com.shulie.instrument.simulator.api.annotation.Command)

Example 2 with NameRegexFilter

use of com.shulie.instrument.simulator.api.filter.NameRegexFilter in project LinkAgent by shulieTech.

the class JadModule method jad.

@Command(value = "jad", description = "反编译")
public CommandResponse jad(final Map<String, String> param) {
    try {
        final String cnPattern = getParameter(param, "class");
        final String classloader = getParameter(param, "classloader");
        final boolean sourceOnly = getBooleanParameter(param, "source-only", false);
        if (logger.isInfoEnabled()) {
            logger.info("SIMULATOR: param.class={}", cnPattern);
            logger.info("SIMULATOR: param.classloader={}", classloader);
            logger.info("SIMULATOR: param.source-only={}", sourceOnly);
        }
        Set<Class<?>> matchedClasses = loadedClassDataSource.find(new NameRegexFilter(cnPattern, ".*", true, true));
        if (matchedClasses == null || matchedClasses.isEmpty()) {
            return processNoMatch(cnPattern);
        } else if (matchedClasses.size() > 1 && classloader == null) {
            return processMatches(matchedClasses, cnPattern);
        } else {
            // matchedClasses size is 1
            // find inner classes.
            Set<Class<?>> withInnerClasses = loadedClassDataSource.find(new NameRegexFilter(matchedClasses.iterator().next().getName() + "$*", "*", true, true));
            withInnerClasses = filter(withInnerClasses, classloader);
            if (withInnerClasses.isEmpty()) {
                withInnerClasses = matchedClasses;
            }
            return processExactMatch(matchedClasses, withInnerClasses, sourceOnly);
        }
    } catch (Throwable e) {
        return CommandResponse.failure(e);
    }
}
Also used : NameRegexFilter(com.shulie.instrument.simulator.api.filter.NameRegexFilter) Set(java.util.Set) HashSet(java.util.HashSet) Command(com.shulie.instrument.simulator.api.annotation.Command)

Aggregations

Command (com.shulie.instrument.simulator.api.annotation.Command)2 NameRegexFilter (com.shulie.instrument.simulator.api.filter.NameRegexFilter)2 Set (java.util.Set)2 InterfaceNameRegexFilter (com.shulie.instrument.simulator.module.util.InterfaceNameRegexFilter)1 SuperNameRegexFilter (com.shulie.instrument.simulator.module.util.SuperNameRegexFilter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1