Skip to content

Commit

Permalink
Merge pull request #51 from ba1man/main
Browse files Browse the repository at this point in the history
remove previous commits
  • Loading branch information
Lynn-Dai authored May 27, 2023
2 parents 9a69a16 + c928811 commit 9ae4972
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 150 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Usage: enre_java [-hs] [-a=<aidl>] [-e=<external>] [-hd=<hidden>]
The output file name, default is projectName-out
-s, --slim The slim output version, which removing the location and
external entity info.
-k, --sdkPath The external sdk source code directory paths if you want the external sdk library classes to be analyzed as well.
```

To increase the memory heap, you can add -Xmx before -jar, like:
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/client/EnreCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class EnreCommand {
private String outputFile;
@Option(names = {"-h","--help"}, usageHelp = true, description = "Display this help and exit")
public boolean help;
@Option(names = {"-k", "--sdkPath"}, description = "The external sdk source code directory paths if you want the external sdk library classes to be analyzed as well.")
private String[] sdkSourcePaths = new String[]{};
@Option(names = {"-e","--external"}, description = "The third party APIs which need to identify")
private String external;
@Option(names = {"-s", "--slim"}, description = "The slim output version, which removing the location and external entity info. ")
Expand Down Expand Up @@ -77,14 +75,6 @@ public void setHidden(String hidden) {
this.hidden = hidden;
}

public String[] getSdkSourcePaths() {
return sdkSourcePaths;
}

public void setSdkSourcePaths(String[] sdkSourcePaths) {
this.sdkSourcePaths = sdkSourcePaths;
}

public String getHidden() {
return hidden;
}
Expand Down
29 changes: 2 additions & 27 deletions src/main/java/client/IdentifyEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class IdentifyEntities {
private String project_name;
private ArrayList<String> additional_path = new ArrayList<>();
private String aidl_path = null;
private String[] sdkSourcePaths;

public IdentifyEntities(String project_path, String project_name){
this.project_path = PathUtil.unifyPath(project_path);
Expand Down Expand Up @@ -53,14 +52,6 @@ public IdentifyEntities(String project_path, String project_name, String aidl_pa
}
}

public String[] getSdkSourcePaths() {
return sdkSourcePaths;
}

public void setSdkSourcePaths(String[] sdkSourcePaths) {
this.sdkSourcePaths = sdkSourcePaths;
}

public String getProject_path() {
return PathUtil.unifyPath(this.project_path);
}
Expand Down Expand Up @@ -88,13 +79,6 @@ public void run(){


HashMap<Tuple<String, Integer>, ArrayList<String>> checkBin = new HashMap<>();
HashMap<Tuple<String, Integer>, ArrayList<String>> sdkCheckBin = new HashMap<>();
if (this.sdkSourcePaths != null) {
for (String sdkSourcePath : this.sdkSourcePaths) {
FileUtil sdkFile = new FileUtil(sdkSourcePath);
sdkCheckBin.put(new Tuple<>(sdkSourcePath, 1), sdkFile.getFileNameList());
}
}
// ArrayList<String> whole_file_list = current.getFileNameList();
checkBin.put(new Tuple<>(current.getProjectPath()+current.getCurrentProjectName(), 1), current.getFileNameList());

Expand Down Expand Up @@ -132,9 +116,6 @@ public void run(){

parser.setUnitName(current.getCurrentProjectName());
ArrayList<String> whole_file_list = new ArrayList<>();
for (Tuple<String, Integer> binPath: sdkCheckBin.keySet()){
whole_file_list.addAll(sdkCheckBin.get(binPath));
}
for (Tuple<String, Integer> binPath: checkBin.keySet()){
whole_file_list.addAll(checkBin.get(binPath));
}
Expand All @@ -149,13 +130,7 @@ public void run(){
FileASTRequestor requester = new FileASTRequestor() {
@Override
public void acceptAST(String source, CompilationUnit ast) {
String relativeFilePath;
if (source.contains(project_name)) {
relativeFilePath = PathUtil.getPathInProject(PathUtil.unifyPath(source), project_name);
} else {
relativeFilePath = PathUtil.unifyPath(source);
}
pairs.add(new CompilationUnitPair(relativeFilePath, ast));
pairs.add(new CompilationUnitPair(source, ast));
}
};
parser.createASTs(whole_file_list.toArray(new String[0]), null, new String[0], requester, null);
Expand Down Expand Up @@ -188,7 +163,7 @@ public void acceptAST(String source, CompilationUnit ast) {
break;
}
}
pair.ast.accept(new EntityVisitor(pair.source, pair.ast, fileBin));
pair.ast.accept(new EntityVisitor(PathUtil.getPathInProject(PathUtil.unifyPath(pair.source),this.project_name), pair.ast, fileBin));
// System.out.println(fileBinNum);
}
catch (EmptyStackException e){
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/client/TemplateWork.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void executeCommand(EnreCommand app) throws Exception {
String projectName = app.getProjectName();
String depMask = "111111111";
String aidlDir = app.getAidl();
String[] sdkSourcePaths = app.getSdkSourcePaths();
String hiddenDir = app.getHidden();

String[] additionDir = app.getDir();
Expand All @@ -75,7 +74,7 @@ public void executeCommand(EnreCommand app) throws Exception {
//Slim versin
boolean slim = app.isSlim();

config(lang, inputDir, projectName, sdkSourcePaths);
config(lang, inputDir, projectName);
String outputFile = configure.getAnalyzedProjectName()+ "-out";
if (app.getOutputFile() != null){
outputFile = app.getOutputFile();
Expand All @@ -100,7 +99,6 @@ public void executeCommand(EnreCommand app) throws Exception {
entityTreeBuilder = new IdentifyEntities(inputDir, projectName);
}
}
entityTreeBuilder.setSdkSourcePaths(sdkSourcePaths);
entityTreeBuilder.run();

// identify external
Expand Down Expand Up @@ -158,12 +156,11 @@ public void executeCommand(EnreCommand app) throws Exception {
* @param inputDir
* @param projectName
*/
private void config(String lang, String inputDir, String projectName, String[] sdkSourcePaths) {
private void config(String lang, String inputDir, String projectName) {
configure.setLang(lang);
configure.setInputSrcPath(inputDir);
configure.setAnalyzedProjectName(projectName);
configure.setDefault();
configure.setSdkSourcePaths(sdkSourcePaths);
}


Expand Down
13 changes: 0 additions & 13 deletions src/main/java/entity/ExternalEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,4 @@ public String getReturnType() {
public void setReturnType(String returnType) {
this.returnType = returnType;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ExternalEntity that = (ExternalEntity) o;
return Objects.equals(qualifiedName, that.qualifiedName);
}

@Override
public int hashCode() {
return Objects.hash(qualifiedName);
}
}
1 change: 1 addition & 0 deletions src/main/java/hianalyzer/HiDeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ private int findFile(int id) {
}

private int findFolder(int id) {
-k, --sdkPath The external sdk source code directory paths if you want the external sdk library classes to be analyzed as well.
while(id != -1 && !(singleCollect.getEntities().get(id) instanceof PackageEntity)) {
id = singleCollect.getEntities().get(id).getParentId();
}
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/util/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ public static Configure getConfigureInstance() {
public static final String OS_DOT_NAME = "os.name";

private String inputSrcPath;
private String[] sdkSourcePaths;
private String analyzedProjectName = "helloJDT";
private String lang = "java";
private String curr_pro_suffix = ".java";
Expand All @@ -226,14 +225,6 @@ public void setDefault() {
attributeName = analyzedProjectName + "-sdsm";
}

public String[] getSdkSourcePaths() {
return sdkSourcePaths;
}

public void setSdkSourcePaths(String[] sdkSourcePaths) {
this.sdkSourcePaths = sdkSourcePaths;
}

public String getInputSrcPath() {
return inputSrcPath;
}
Expand Down
23 changes: 2 additions & 21 deletions src/main/java/util/SingleCollect.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
*This class is aimed to collect all entities in a java project.
Expand All @@ -22,24 +17,10 @@

public class SingleCollect {

public static final Logger logger = Logger.getLogger(SingleCollect.class.getName());
private static final FileHandler handler;

static {
try {
handler = new FileHandler("enre.log");
logger.addHandler(handler);
SimpleFormatter formatter = new SimpleFormatter();
handler.setFormatter(formatter);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

//entities' id = index
private ArrayList<BaseEntity> entities = new ArrayList<BaseEntity>();

private Set<ExternalEntity> externalEntities = new HashSet<>();
private ArrayList<ExternalEntity> externalEntities = new ArrayList<>();

//packages' qualified name and id that already be created
private HashMap<String,Integer> createdPackage = new HashMap<String,Integer>();
Expand All @@ -64,7 +45,7 @@ public void addEntity(BaseEntity entity) {
this.entities.add(entity);
}

public Set<ExternalEntity> getExternalEntities() {
public ArrayList<ExternalEntity> getExternalEntities() {
return this.externalEntities;
}

Expand Down
64 changes: 4 additions & 60 deletions src/main/java/visitor/EntityVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,66 +180,10 @@ public void endVisit(TypeDeclaration node) {

@Override
public boolean visit(ClassInstanceCreation node) {
IMethodBinding constructorBinding = node.resolveConstructorBinding();
if (constructorBinding == null) {
return super.visit(node);
}
String methodName = constructorBinding.getName();
Location location = ProcessEntity.supplement_location(cu, node.getStartPosition(), node.getLength());
ArrayList<String> arguments = new ArrayList<>();
for (Object par : node.arguments()) {
arguments.add(par.toString());
}
Expression currentExpression = node.getExpression();
while (currentExpression instanceof MethodInvocation) {
currentExpression = ((MethodInvocation) currentExpression).getExpression();
}
while (currentExpression instanceof QualifiedName) {
currentExpression = ((QualifiedName) currentExpression).getQualifier();
}
int bindVar;
String bindVarName = "";
if (currentExpression instanceof SimpleName) {
bindVarName = currentExpression.toString();
bindVar = processVarInMethod(currentExpression.toString(), scopeStack.peek());
} else if (currentExpression instanceof FieldAccess) {
bindVarName = ((FieldAccess) currentExpression).getName().getIdentifier();
bindVar = processVarInMethod(((FieldAccess) currentExpression).getName().getIdentifier(), scopeStack.peek());
} else if (currentExpression instanceof ArrayAccess) {
bindVarName = ((ArrayAccess) currentExpression).getArray().toString();
bindVar = processVarInMethod(((ArrayAccess) currentExpression).getArray().toString(), scopeStack.peek());
} else {
if (currentExpression != null) {
bindVarName = currentExpression.toString();
}
bindVar = -1;
}
String declaringTypeQualifiedName;
if (constructorBinding != null) {
ITypeBinding declaringClass = constructorBinding.getDeclaringClass();
declaringTypeQualifiedName = declaringClass.getQualifiedName();
ArrayList<String> parTypes = new ArrayList<>();
ITypeBinding[] calledMethParTypes = constructorBinding.getParameterTypes();
for (ITypeBinding parType : calledMethParTypes) {
parTypes.add(parType.getQualifiedName());
}
if (singleCollect.getEntityById(scopeStack.peek()) instanceof ScopeEntity) {
if (bindVar != -1) {
((ScopeEntity) singleCollect.getEntityById(scopeStack.peek())).addCall(declaringTypeQualifiedName, methodName, location, bindVar, parTypes, arguments);
} else {
((ScopeEntity) singleCollect.getEntityById(scopeStack.peek())).addCall(declaringTypeQualifiedName, methodName, location, bindVarName, parTypes, arguments);
}
}
checkReflection(declaringTypeQualifiedName, methodName, bindVar, node.arguments(), location);
} else {
if (bindVar != -1) {
declaringTypeQualifiedName = singleCollect.getEntityById(bindVar).getRawType();
} else {
declaringTypeQualifiedName = bindVarName;
}
if (singleCollect.getEntityById(scopeStack.peek()) instanceof ScopeEntity) {
((ScopeEntity) singleCollect.getEntityById(scopeStack.peek())).addExternalCall(declaringTypeQualifiedName, methodName, location, bindVarName, bindVar, arguments);
}
try {
currentInstanceRawType = node.getType().resolveBinding().getQualifiedName();
}catch (NullPointerException e) {
currentInstanceRawType = node.getType().toString();
}
return super.visit(node);
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/visitor/ProcessEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,6 @@ public int processAnnotation(AnnotationTypeDeclaration node, int parentId, Compi
//add parent's children Id
singleCollect.getEntityById(parentId).addChildId(annotationId);

ITypeBinding binding = node.resolveBinding();
if (binding != null) {
annotationName = binding.getQualifiedName();
}
singleCollect.addCreatedAnt(annotationId, annotationName);

return annotationId;
Expand Down

0 comments on commit 9ae4972

Please sign in to comment.