/** Given a new expression (Jimple NewExpr or String) return the corresponding AllocNode. */ public IAllocNode getAllocNode(Object newExpr, Context context) { InsensitiveAllocNode insens = null; if (newExpr instanceof NewMultiArrayExpr) { NewMultiArrayExpr newArr = (NewMultiArrayExpr) newExpr; ArrayType type = (ArrayType) newArr.getType(); Integer i = type.numDimensions; Pair pair = new Pair(newArr, i); insens = newToAllocNodeMap.get(pair); } else { if (!newToAllocNodeMap.containsKey(newExpr)) { System.out.println("Not in new -> alloc map: " + newExpr); return null; } insens = newToAllocNodeMap.get(newExpr); } // handle no context case if (k == 0) return insens; return insens.context(context); }
/** Create the bi map of NewExpr <-> AllocNode */ private void createNewToAllocMap() { newToAllocNodeMap = HashBiMap.create(); allAllocNodes = new LinkedHashSet<AllocNode>(); Map<SootClass, Integer> nodeCount = new LinkedHashMap<SootClass, Integer>(); int realSize = 0; for (AllocNode node : ptsProvider.getAllocNodes()) { if (!(node instanceof InsensitiveAllocNode)) { logger.error("Found non-insensitive node in ptsProvider.getAllocNodes()"); droidsafe.main.Main.exit(1); } InsensitiveAllocNode insNode = (InsensitiveAllocNode) node; newToAllocNodeMap.put(node.getNewExpr(), insNode); realSize++; allAllocNodes.add(node); // countNode(nodeCount, node); for (Map.Entry<Context, ObjectSensitiveAllocNode> entry : insNode.getContextNodeMap().entrySet()) { allAllocNodes.add(entry.getValue()); // countNode(nodeCount, node); } } System.out.println("Alloc node size (insensitive objects): " + realSize); /* used to print a sorted list of alloc nodes created Map<SootClass, Integer> sortedNodeCount = SootUtils.sortByValue(nodeCount); for (Map.Entry<SootClass, Integer> entry : sortedNodeCount.entrySet()) { System.out.println(entry.getValue() + " " + entry.getKey()); } */ }
public Set<IAllocNode> getAllocNodeIns(Object newExpr) { InsensitiveAllocNode insens = null; if (newExpr instanceof NewMultiArrayExpr) { NewMultiArrayExpr newArr = (NewMultiArrayExpr) newExpr; ArrayType type = (ArrayType) newArr.getType(); Integer i = type.numDimensions; Pair pair = new Pair(newArr, i); insens = newToAllocNodeMap.get(pair); } else { if (!newToAllocNodeMap.containsKey(newExpr)) { System.out.println("Not in new -> alloc map: " + newExpr); return null; } insens = newToAllocNodeMap.get(newExpr); } Set<IAllocNode> nodes = new LinkedHashSet<IAllocNode>(); nodes.add(insens); nodes.addAll(insens.getContextNodeMap().values()); return nodes; }