1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| import java.util.Iterator;
import java.util.List;
import soot.*;
import soot.options.Options;
import soot.tagkit.Tag;
import soot.toolkits.graph.ExceptionalUnitGraph;
import soot.toolkits.graph.UnitGraph;
import lili.callGraph.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Enumeration;
import java.util.Properties;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Scanner;
import java.util.Hashtable;
public class Main extends JFrame {
/**
* @param args
* @throws IOException
*/
public static double euclidien (double w,double x) {
double distance;
distance= Math.pow(w, (1/x));
return distance ;
}
public static void main(String[] args) throws IOException {
JButton monBouton = new JButton();
JFrame monCadre = new JFrame();
System.out.println(" ---------------------------------------------------------------------------------------------------------------------");
System.out.println(" | GRAPHE D'APPELS |");
System.out.println(" ---------------------------------------------------------------------------------------------------------------------");
String processDir = "C://exemple";
String[] s = { "-pp", "-f", "n", "-cp", processDir, "-process-dir",
processDir };
PackManager.v().getPack("jtp").add(
new Transform("jtp.callGraphbuilder", CallGraphBuilder.v()));soot.Main.main(s);
CallGraph cg = CallGraph.v();
// For each class
JFrame fenetre = new JFrame();
fenetre.setSize(300, 300);
fenetre.setLocationRelativeTo(null);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setTitle("Call Graph");
DefaultMutableTreeNode racine = new DefaultMutableTreeNode(" Graphe d'appels ");
for (Iterator classIterator = Scene.v().getApplicationClasses()
.iterator(); classIterator.hasNext();)
{
SootClass sc = (SootClass) classIterator.next();
//for each method
for (Iterator methodIterator = sc.getMethods().iterator(); methodIterator
.hasNext();)
{
SootMethod sm = (SootMethod) methodIterator.next();
System.out.println(" ==== La méthode \" " + sm.getName() + " \" de la classe \" "+sm.getDeclaringClass()+" \" ==== ");//affiche le nom d la méthode
DefaultMutableTreeNode rep = new DefaultMutableTreeNode(sm);
System.out.println("\nLes méthodes appelées sont : ");
int count=0;
if (cg.getTargets(sm) != null)
{
// si la méthode n'a pas de cible on passe à la méthode suivante(voir contenue)
for (Iterator succ = cg.getTargets(sm).iterator(); succ //on récupère les cible
.hasNext();)
{
SootMethod sootMethod = (SootMethod) succ.next();
count++;
System.out.println(count+" : La méthode \" "+sootMethod.getName() + " \" de la classe \" "+sootMethod.getDeclaringClass()+" \"");// la ligne qui affiche les target(les méthode appelé par sm)
} }
System.out.println("\nLes méthodes appelantes sont : ");
int compteur=0;
if (cg.getCallers(sm) != null)
{
// si la méthode n'a pas de applan on passe à la méthode suivante(voir conteinue)
for (Iterator succ = cg.getCallers(sm).iterator(); succ //on récupère les appelan
.hasNext();)
{
SootMethod sootMethod = (SootMethod) succ.next();
compteur++;
DefaultMutableTreeNode rep2 = new DefaultMutableTreeNode(sootMethod.getName());
rep.add(rep2);
System.out.println(compteur+": La méthode \" "+sootMethod.getName()+ " \" de la classe \" "+sootMethod.getDeclaringClass()+" \" \n ");// la ligne qui affiche les target(les méthode appelé par sm
}
}
System.out.println("Nombre d'appels est : "+compteur+ "\n ");
racine.add(rep);
}
}
JTree arbre = new JTree(racine);
//Que nous plaçons sur le ContentPane de notre JFrame à l'aide d'un scroll
fenetre.getContentPane().add(new JScrollPane(arbre));
fenetre.setVisible(true);
System.out.println(" ---------------------------------------------------------------------------------------------------------------------");
System.out.println(" | ANALYSE CLUSTERING |");
System.out.println(" ---------------------------------------------------------------------------------------------------------------------");
Scanner entree = new Scanner(System.in);
System.out.println(" Veuillez saisir le nombre de clusters s'il vous plait :");
int str = entree.nextInt();
int k=1;//computer of cluster number
System.out.println("*******************************************************Itération 1************************************* ");
for (Iterator classIterator = Scene.v().getApplicationClasses()
.iterator(); classIterator.hasNext();)
{
int a =0;
SootClass sc = (SootClass) classIterator.next();
for (Iterator methodIterator = sc.getMethods().iterator(); methodIterator
.hasNext();)
{
SootMethod sm = (SootMethod) methodIterator.next();
if(sm.getName().startsWith("<")) //si c'est un constructeur on passe a la méthode suivante
continue;
System.out.println("Cluster numéro "+k+" : contenant la méthode " + sm.getName() + " dont le nombre d'appels est :"+cg.getNbrCall(sm)); //getNbrCall que nous vennons d'ajouté à callGraph
k++;
int b= cg.getNbrCall(sm);
}
}
int t=k-1;
int b;
System.out.println(t);
if ( str>= t)
System.out.println("Toutes les méthodes appartiennent au même cluster ");
else {
System.out.println("*************************************************Itération2************************************* ");
double h= euclidien(60,2);
int a =0;
int tab[] = null;
int y=0;
Hashtable hashtable = new Hashtable();
for (Iterator classIterator = Scene.v().getApplicationClasses()
.iterator(); classIterator.hasNext();)
{
SootClass sc = (SootClass) classIterator.next();
for (Iterator methodIterator = sc.getMethods().iterator(); methodIterator
.hasNext();)
{
SootMethod sm = (SootMethod) methodIterator.next();
if(sm.getName().startsWith("<"))
continue;
System.out.println("Cluster numéro "+k+" : contenant la méthode " + sm.getName() + " dont le nombre d'appels est :"+cg.getNbrCall(sm)); //getNbrCall que nous vennons d'ajouté à callGraph
k++;
b= cg.getNbrCall(sm);
int d = cg.getNbrCall(sm);
int c= d-a;
int o= (int) Math.pow(c, 2);
System.out.println(" dla premiere mithoud "+d+" tar7 "+c+ "gpoxw "+o);
hashtable.put( sm.getName(), cg.getNbrCall(sm) ); // adding value into hashtable
}
}
Enumeration e1 = hashtable.keys();
while( e1. hasMoreElements() )
{
System.out.println( e1.nextElement() );
}
System.out.println("Retriving all values from the Hashtable");
e1 = hashtable.elements();
while( e1. hasMoreElements() )
{
System.out.println( e1.nextElement() );
System.out.println( e1.nextElement() );
}
System.out.println( hashtable.remove("One") + " is removed from the Hashtable.");
Integer I=(Integer)hashtable.get(e1);
System.out.println(I);
}
}
} |
Partager