public static string returnType(this Java_Method method) { var returnType = ""; if (method.GenericSignature.isNull()) { returnType = method.ReturnType; } if (returnType.inValid()) { returnType = method.GenericSignature.subString_After("java/util/Set<") .removeLastChar().removeLastChar() .replace("/", ".").trim(); } if (returnType.inValid()) { returnType = method.GenericSignature.subString_After("java/util/Collection<") .removeLastChar().removeLastChar() .replace("/", ".").trim(); } return((returnType.starts("L")) ? returnType.removeFirstChar().removeLastChar() : returnType); }
public static TreeNode add_ConstantsPool(this TreeNode treeNode, Java_Method method, Java_Class methodClass) { var constantsPoolNode = treeNode.add_Node("_ConstantsPool"); foreach (var item in method.constantsPool_byType(methodClass)) { constantsPoolNode.add_Node(item.Key, item.Value, true); } return(treeNode); }
public static Dictionary <int, List <Java_Variable> > variables_byIndex(this Java_Method method) { var variables_byIndex = new Dictionary <int, List <Java_Variable> >(); foreach (var variable in method.Variables) { variables_byIndex.add(variable.Index, variable); } return(variables_byIndex); }
public static Dictionary <int, Java_Instruction> instructions_byPc(this Java_Method method) { var instructions_byPc = new Dictionary <int, Java_Instruction>(); foreach (var instruction in method.Instructions) { instructions_byPc.Add(instruction.Pc, instruction); } return(instructions_byPc); }
public static List <string> methodRefs_old(this Java_Class methodClass, Java_Method method) { var constants_byType = method.constantsPool_byType(methodClass); if (constants_byType.hasKey("Methodref")) { return(constants_byType["Methodref"].values()); } return(new List <string>()); }
public static TreeNode add_Variables(this TreeNode treeNode, Java_Method method) { if (method.Variables.size() > 0) { var variablesNode = treeNode.add_Node("_Variables"); foreach (var variable in method.Variables) { variablesNode.add_Node("{0} : {1}".format(variable.Name, variable.Descriptor), variable); } } return(treeNode); }
public static TreeNode add_Instructions(this TreeNode treeNode, Java_Method method, Java_Class methodClass) { var values = methodClass.ConstantsPool.getDictionaryWithValues(); foreach (var instruction in method.Instructions) { var nodeText = "[line:{0}] \t {1}".format(instruction.Line_Number, instruction.OpCode); if (instruction.Target_Index > 0 && values.hasKey(instruction.Target_Index)) { nodeText = "{0} {1}".format(nodeText, values[instruction.Target_Index]); } treeNode.add_Node(nodeText, instruction) .color(Color.DarkGreen); } return(treeNode); }
public static Java_Class map_Methods(this Java_Class javaClass, object classFile) { var mappedConstantsPools = javaClass.ConstantsPool.getDictionaryWithValues(); var methods = (IEnumerable)classFile.prop("Methods"); foreach (var method in methods) { var javaMethod = new Java_Method { Name = method.prop("Name").str(), ParametersAndReturnType = method.prop("Signature").str(), ClassName = javaClass.Signature, IsAbstract = method.prop("IsAbstract").str().toBool(), IsClassInitializer = method.prop("IsClassInitializer").str().toBool(), IsNative = method.prop("IsNative").str().toBool(), IsPublic = method.prop("IsPublic").str().toBool(), IsStatic = method.prop("IsStatic").str().toBool() }; javaMethod.SimpleSignature = "{0}{1}".format(javaMethod.Name, javaMethod.ParametersAndReturnType); javaMethod.ReturnType = javaMethod.ParametersAndReturnType.subString_After(")"); javaMethod.Signature = "{0}.{1}".format(javaMethod.ClassName, javaMethod.SimpleSignature); if (method.prop("GenericSignature").notNull()) { javaMethod.GenericSignature = method.prop("GenericSignature").str(); } javaMethod.map_Annotations(method) .map_Variables(method); var instructions = (IEnumerable)method.prop("Instructions"); if (instructions.notNull()) { foreach (var instruction in instructions) { var javaInstruction = new Java_Instruction(); javaInstruction.Pc = instruction.prop("PC").str().toInt(); javaInstruction.OpCode = instruction.prop("NormalizedOpCode").str(); javaInstruction.Target_Index = instruction.prop("TargetIndex").str().toInt(); javaMethod.Instructions.Add(javaInstruction); } } javaClass.Methods.Add(javaMethod); } return(javaClass); }
public static Java_Method map_Annotations(this Java_Method javaMethod, object method) { var annotations = (Object[])method.prop("Annotations"); if (annotations.notNull()) { javaMethod.Annotations = annotations; } var parameterAnnotations = (Object[])method.prop("ParameterAnnotations"); if (parameterAnnotations.notNull()) { javaMethod.ParameterAnnotations = parameterAnnotations; } return(javaMethod); }
public static Java_Method map_Variables(this Java_Method javaMethod, object method) { var localVariablesTable = (IEnumerable)method.prop("LocalVariableTableAttribute"); if (localVariablesTable.notNull()) { foreach (var localVariable in localVariablesTable) { javaMethod.Variables.Add(new Java_Variable { Descriptor = localVariable.field("descriptor").str(), Index = localVariable.field("index").str().toInt(), Length = localVariable.field("length").str().toInt(), Name = localVariable.field("name").str(), Start_Pc = localVariable.field("start_pc").str().toInt() }); } } return(javaMethod); }
public static List <Java_Method> implementations(this Java_Method method, Dictionary <string, List <Java_Class> > classesImplementations) { var implementations = new List <Java_Method>(); if (classesImplementations.hasKey(method.ClassName)) { foreach (var _class in classesImplementations[method.ClassName]) { foreach (var implementationMethod in _class.Methods) { if (method.SimpleSignature == implementationMethod.SimpleSignature) { implementations.Add(implementationMethod); break; } } } } return(implementations); }
public static List <MethodCall> methodRefs(this Java_Method method, Java_Class methodClass) { var file = methodClass.file(); var constants_byType = method.constantsPool_byType(methodClass); if (constants_byType.hasKey("Methodref") || constants_byType.hasKey("InterfaceMethodref")) { var methodRefs_AtLines = method.getConstantsPoolUsage_byIndex_WithLineNumbers(); var methodRefs = new List <MethodCall>(); if (constants_byType.hasKey("Methodref")) { methodRefs.AddRange(constants_byType["Methodref"].get_MethodsRef_FromContantsPool(file, false, methodRefs_AtLines)); } if (constants_byType.hasKey("InterfaceMethodref")) { methodRefs.AddRange(constants_byType["InterfaceMethodref"].get_MethodsRef_FromContantsPool(file, true, methodRefs_AtLines)); } return(methodRefs); } return(new List <MethodCall>()); }
public static ascx_SourceCodeViewer showInCodeViewer(this ascx_SourceCodeViewer codeViewer, Java_Class _class, Java_Method method) { codeViewer.editor().showInCodeEditor(_class, method); return(codeViewer); }
public static SourceCodeEditor showInCodeEditor(this SourceCodeEditor codeEditor, Java_Class _class, Java_Method method) { //var _class = classes_bySignature[classSignature]; var file = _class.file(); codeEditor.open(file); var lineNumber = 0; if (method.isNull() || method.LineNumbers.isNull()) { return(codeEditor); } foreach (var item in method.LineNumbers) { if (item.Line_Number > 1) { if (lineNumber == 0 || item.Line_Number < lineNumber) { lineNumber = item.Line_Number; } } } //this to match the method name to the location (vs the first method) var sourceCodeLines = codeEditor.getSourceCode().lines(false); if (method.Name.regEx("<.*init*.>").isFalse()) { for (int i = 0; i < 10; i++) { if (lineNumber > i && sourceCodeLines.size() > lineNumber - i) { var line = sourceCodeLines[lineNumber - i]; if (sourceCodeLines[lineNumber - i].contains(method.Name) && line.regEx("public|private|internal|protected")) { lineNumber = lineNumber - i + 1; break; } } } } codeEditor.gotoLine(lineNumber, 4); return(codeEditor); }
public static Dictionary<string,List<ConstantPool>> getDictionary_byType(this List<ConstantPool> constantsPool, Java_Method method) { var usedInMethod = method.uniqueTargetIndexes(); //show.info(usedInMethod); var mappedByIndex = constantsPool.getDictionary_byIndex(); //show.info(mappedByIndex); var dictionary = new Dictionary<string,List<ConstantPool>>(); foreach(var index in usedInMethod) { if (mappedByIndex.hasKey(index)) { var constantPool = mappedByIndex[index]; dictionary.add(constantPool.Type, constantPool); } } return dictionary; }
public static Java_Class map_Methods(this Java_Class javaClass, object classFile) { var mappedConstantsPools = javaClass.ConstantsPool.getDictionaryWithValues(); var methods = (IEnumerable)classFile.prop("Methods"); foreach(var method in methods) { var javaMethod = new Java_Method { Name = method.prop("Name").str(), ParametersAndReturnType = method.prop("Signature").str(), ClassName = javaClass.Signature, IsAbstract = method.prop("IsAbstract").str().toBool(), IsClassInitializer = method.prop("IsClassInitializer").str().toBool(), IsNative = method.prop("IsNative").str().toBool(), IsPublic = method.prop("IsPublic").str().toBool(), IsStatic = method.prop("IsStatic").str().toBool() }; javaMethod.SimpleSignature = "{0}{1}".format(javaMethod.Name,javaMethod.ParametersAndReturnType); javaMethod.ReturnType = javaMethod.ParametersAndReturnType.subString_After(")"); javaMethod.Signature = "{0}.{1}".format(javaMethod.ClassName, javaMethod.SimpleSignature); if (method.prop("GenericSignature").notNull()) javaMethod.GenericSignature = method.prop("GenericSignature").str(); javaMethod.map_Annotations(method) .map_Variables(method); var instructions = (IEnumerable) method.prop("Instructions"); if (instructions.notNull()) { foreach(var instruction in instructions) { var javaInstruction = new Java_Instruction(); javaInstruction.Pc = instruction.prop("PC").str().toInt(); javaInstruction.OpCode = instruction.prop("NormalizedOpCode").str(); javaInstruction.Target_Index = instruction.prop("TargetIndex").str().toInt(); javaMethod.Instructions.Add(javaInstruction); } } javaClass.Methods.Add(javaMethod); } return javaClass; }
public static Dictionary <string, List <ConstantPool> > getDictionary_byType(this List <ConstantPool> constantsPool, Java_Method method) { var usedInMethod = method.uniqueTargetIndexes(); //show.info(usedInMethod); var mappedByIndex = constantsPool.getDictionary_byIndex(); //show.info(mappedByIndex); var dictionary = new Dictionary <string, List <ConstantPool> >(); foreach (var index in usedInMethod) { if (mappedByIndex.hasKey(index)) { var constantPool = mappedByIndex[index]; dictionary.add(constantPool.Type, constantPool); } } return(dictionary); }
public static TreeNode add_Instructions(this TreeNode treeNode, Java_Method method, Java_Class methodClass) { var values = methodClass.ConstantsPool.getDictionaryWithValues(); foreach(var instruction in method.Instructions) { var nodeText = "[line:{0}] \t {1}".format(instruction.Line_Number,instruction.OpCode); if (instruction.Target_Index > 0 && values.hasKey(instruction.Target_Index)) nodeText = "{0} {1}".format(nodeText , values[instruction.Target_Index]); treeNode.add_Node(nodeText, instruction) .color(Color.DarkGreen); } return treeNode; }
public static Dictionary <string, List <ConstantPool> > constantsPool_byType(this Java_Method method, Java_Class _class) { return(_class.ConstantsPool.getDictionary_byType(method)); }
public static Dictionary <int, List <Java_Instruction> > getConstantsPoolUsage_byIndex_WithLineNumbers(this Java_Method method) { var dictionary = new Dictionary <int, List <Java_Instruction> >(); foreach (var instruction in method.Instructions) { if (instruction.Target_Index > 0) { dictionary.add(instruction.Target_Index, instruction); } } return(dictionary); }
public static TreeNode add_ConstantsPool(this TreeNode treeNode, Java_Method method, Java_Class methodClass) { var constantsPoolNode = treeNode.add_Node("_ConstantsPool"); foreach(var item in method.constantsPool_byType(methodClass)) constantsPoolNode.add_Node(item.Key, item.Value, true); return treeNode; }
public static TreeNode add_Variables(this TreeNode treeNode, Java_Method method) { if (method.Variables.size()>0) { var variablesNode = treeNode.add_Node("_Variables"); foreach(var variable in method.Variables) variablesNode.add_Node("{0} : {1}".format(variable.Name , variable.Descriptor),variable); } return treeNode; }
public static ascx_SourceCodeViewer showInCodeViewer(this ascx_SourceCodeViewer codeViewer ,Java_Class _class, Java_Method method) { codeViewer.editor().showInCodeEditor(_class, method); return codeViewer; }
public static List<string> methodRefs_old(this Java_Class methodClass, Java_Method method) { var constants_byType = method.constantsPool_byType(methodClass); if (constants_byType.hasKey("Methodref")) return constants_byType["Methodref"].values(); return new List<string>(); }
public static SourceCodeEditor showInCodeEditor(this SourceCodeEditor codeEditor ,Java_Class _class, Java_Method method) { //var _class = classes_bySignature[classSignature]; var file = _class.file(); codeEditor.open(file); var lineNumber = 0; if (method.isNull() ||method.LineNumbers.isNull()) return codeEditor; foreach(var item in method.LineNumbers) if (item.Line_Number > 1) if (lineNumber == 0 || item.Line_Number < lineNumber) lineNumber = item.Line_Number; //this to match the method name to the location (vs the first method) var sourceCodeLines = codeEditor.getSourceCode().lines(false); if (method.Name.regEx("<.*init*.>").isFalse()) { for(int i=0 ; i < 10 ; i++) { if (lineNumber > i && sourceCodeLines.size() > lineNumber-i) { var line = sourceCodeLines[lineNumber-i]; if (sourceCodeLines[lineNumber-i].contains(method.Name) && line.regEx("public|private|internal|protected")) { lineNumber = lineNumber -i + 1; break; } } } } codeEditor.gotoLine(lineNumber,4); return codeEditor; }
public static List <int> uniqueTargetIndexes(this Java_Method method) { return((from instruction in method.Instructions where instruction.Target_Index > 0 select instruction.Target_Index).Distinct().toList()); }
public static Method_CallMapping callMapping(this Java_Method method) { return(method.Signature.callMapping()); }