Search in sources :

Example 1 with JadInfo

use of com.shulie.instrument.simulator.module.model.jad.JadInfo in project LinkAgent by shulieTech.

the class JadModule method processExactMatch.

private CommandResponse processExactMatch(Set<Class<?>> matchedClasses, Set<Class<?>> withInnerClasses, boolean sourceOnly) {
    Class<?> c = matchedClasses.iterator().next();
    Set<Class<?>> allClasses = new HashSet<Class<?>>(withInnerClasses);
    allClasses.add(c);
    final Set<String> classNames = toClassName(allClasses);
    Filter filter = new MultiClassNameFilter(classNames, true);
    DumpResult dumpResult = null;
    try {
        dumpResult = moduleEventWatcher.dump(filter, new NoActionProgress());
        File classFile = dumpResult.getDumpResult().get(c.getName());
        String source = Decompiler.decompile(classFile.getAbsolutePath(), simulatorConfig.getSimulatorVersion());
        if (source != null) {
            source = pattern.matcher(source).replaceAll("");
        } else {
            return CommandResponse.failure("can't decompile class file.");
        }
        if (sourceOnly) {
            JadInfo jadInfo = new JadInfo();
            jadInfo.setSource(source);
            return CommandResponse.success(jadInfo);
        }
        JadInfo jadInfo = new JadInfo();
        jadInfo.setClassloader(drawClassLoader(c));
        jadInfo.setLocation(ClassUtils.getCodeSource(c.getProtectionDomain().getCodeSource()));
        jadInfo.setSource(source);
        return CommandResponse.success(jadInfo);
    } catch (Throwable t) {
        logger.error("SIMULATOR: jad: fail to decompile class: " + c.getName(), t);
        return CommandResponse.failure(t);
    } finally {
        if (dumpResult != null) {
            // 注销watchId
            moduleEventWatcher.delete(dumpResult.getWatchId());
        }
    }
}
Also used : MultiClassNameFilter(com.shulie.instrument.simulator.api.filter.MultiClassNameFilter) JadInfo(com.shulie.instrument.simulator.module.model.jad.JadInfo) Filter(com.shulie.instrument.simulator.api.filter.Filter) MultiClassNameFilter(com.shulie.instrument.simulator.api.filter.MultiClassNameFilter) NameRegexFilter(com.shulie.instrument.simulator.api.filter.NameRegexFilter) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

Filter (com.shulie.instrument.simulator.api.filter.Filter)1 MultiClassNameFilter (com.shulie.instrument.simulator.api.filter.MultiClassNameFilter)1 NameRegexFilter (com.shulie.instrument.simulator.api.filter.NameRegexFilter)1 JadInfo (com.shulie.instrument.simulator.module.model.jad.JadInfo)1 File (java.io.File)1 HashSet (java.util.HashSet)1