diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..fb58fd9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,36 @@ +name: publish jar +on: + push: + tags: + - "v*" +permissions: + contents: write + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'adopt' + cache: 'maven' + - name: Set version + run: mvn versions:set -DnewVersion=${{ github.ref_name }} + - name: Build jar + run: mvn -B clean package -DskipTests + # - name: publish maven jar + # run: mvn -B deploy -DskipTests -DrepositoryId=github + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish GitHub release + uses: softprops/action-gh-release@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + files: target/qiushui-${{ github.ref_name }}.jar \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..77bf1c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +out/ +target/ +.idea/ +.class \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/artifacts/BytecodeScreen_jar.xml b/.idea/artifacts/BytecodeScreen_jar.xml deleted file mode 100644 index f82ffa7..0000000 --- a/.idea/artifacts/BytecodeScreen_jar.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - $PROJECT_DIR$/out/artifacts/BytecodeScreen_jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 07eb322..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 63e9001..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index abb532a..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 822cd19..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index a94156a..456b9fe 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Usage:
[options] ```python -h --help: 输出help页面属性。 --debug: 开启debug属性。 --j --targetpath : +-j --targetpath : 指定项目的主要扫描目标,最终结果由指定的路径决定(所有参数中出现的继承类和接口也需要被此处指明,如果扫描类为rt.jar包内,也可以加上--jar参数表示扫描rt.jar包内的类) 1.后面跟一个文件夹路径,会读取这个文件夹及子文件夹。例如: -j D:\Desktop\testts\target\classes 2.后面跟一个jar文件路径,会读取这个文件夹及子文件夹。例如: diff --git a/out/artifacts/BytecodeScreen_jar/BytecodeScreen.jar b/out/artifacts/BytecodeScreen_jar/BytecodeScreen.jar deleted file mode 100644 index 952d585..0000000 Binary files a/out/artifacts/BytecodeScreen_jar/BytecodeScreen.jar and /dev/null differ diff --git a/pom.xml b/pom.xml index 07654f2..873c621 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.example qiushui 1.0-SNAPSHOT - har + jar 1.8 diff --git a/src/main/java/app/MainScreen.java b/src/main/java/app/MainScreen.java index 7e7eb06..6d4dc4b 100644 --- a/src/main/java/app/MainScreen.java +++ b/src/main/java/app/MainScreen.java @@ -28,12 +28,12 @@ public class MainScreen { private static final Map classFileByName = new HashMap<>(); private static final Map> methodImpls = new HashMap<>(); - private static HashSet hassuperclass = new HashSet<>(); + private static final HashSet hassuperclass = new HashSet<>(); - private static HashSet resultclass = new HashSet<>(); - private static List hasinterfaces = new ArrayList<>(); + private static final HashSet resultclass = new HashSet<>(); + private static final List hasinterfaces = new ArrayList<>(); - private static List has_parameter = new ArrayList<>(); + private static final List has_parameter = new ArrayList<>(); public static void screen(String[] args) throws Exception { Logo.PrintLogo();//打印logo @@ -44,9 +44,9 @@ public static void screen(String[] args) throws Exception { if (command.help) { jc.usage(); }else{ - if (command.jarpath != null && command.jarpath != "") { + if (command.jarpath != null && !command.jarpath.equals("")) { List commondlist = new ArrayList<>(); - Boolean readbasicjar = false; + boolean readbasicjar = false; HashSet surperclassname = new HashSet<>(); if(command.isjar){ @@ -74,14 +74,11 @@ public static void screen(String[] args) throws Exception { } if (command.superclass != null) { - List supers = new ArrayList<>(); commondlist.add("superclass"); String superclassname1 = command.superclass.replace(".", "/"); surperclassname.add(superclassname1); has_superclass(surperclassname); - for(String superclass:hassuperclass){ - supers.add(superclass); - } + List supers = new ArrayList<>(hassuperclass); returnresults(supers); control_dubbomethod(supers); @@ -98,7 +95,7 @@ public static void screen(String[] args) throws Exception { String returnparameter = ""; String parameter = ""; String method = ""; - Boolean sta_tic = false; + boolean sta_tic = false; if(command.isstatic){ sta_tic = true; } @@ -112,10 +109,10 @@ public static void screen(String[] args) throws Exception { method = command.method; has_parameter_returns(method, parameter, returnparameter,sta_tic); List has_parlist = new ArrayList<>(); - for(int x = 0;x resultlist = new ArrayList<>(); - for(String ss :resultclass){ - resultlist.add(ss); - } + List resultlist = new ArrayList<>(resultclass); HashSet shs = new HashSet<>(); - for(int i =0 ;i classnames){ - Map methodMapdubbos = new HashMap<>(); if(methodMapdubbo.isEmpty()){ - for(int i =0;i handle:methodMap.entrySet()){ - if(handle.getKey().getClassReference().getName().equals(classnames.get(i))){ - methodMapdubbo.put(handle.getKey(),handle.getValue()); + for (String classname : classnames) { + for (Map.Entry handle : methodMap.entrySet()) { + if (handle.getKey().getClassReference().getName().equals(classname)) { + methodMapdubbo.put(handle.getKey(), handle.getValue()); } } } }else { - for(Map.Entry handle:methodMapdubbo.entrySet()){ - methodMapdubbos.put(handle.getKey(),handle.getValue()); - } + Map methodMapdubbos = new HashMap<>(methodMapdubbo); methodMapdubbo.clear(); - for(int i =0;i handle:methodMapdubbos.entrySet()){ - if(handle.getKey().getClassReference().getName().equals(classnames.get(i))){ - methodMapdubbo.put(handle.getKey(),handle.getValue()); + for (String classname : classnames) { + for (Map.Entry handle : methodMapdubbos.entrySet()) { + if (handle.getKey().getClassReference().getName().equals(classname)) { + methodMapdubbo.put(handle.getKey(), handle.getValue()); } } } } } - public static HashSet has_parameter_returns(String name ,String parameter,String returnparameter,Boolean isstaic){ + public static void has_parameter_returns(String name , String parameter, String returnparameter, Boolean isstaic){ HashSet hashSet = new HashSet<>(); List name1 = regex_out(name); @@ -244,9 +235,7 @@ public static HashSet has_parameter_returns(String name ,String paramete //多次--->判断最终结果是否为空 if(has_parameter.size() == 0){//最终结果为空 hashSet = targetclass(resultlist,methodname,methodparam,methodreturn); - for(String target:hashSet){ - has_parameter.add(target); - } + has_parameter.addAll(hashSet); }else {//最终结果不为空 HashSet hashSet1 = targetclass(resultlist,methodname,methodparam,methodreturn); for(String ii:has_parameter){ @@ -266,13 +255,10 @@ public static HashSet has_parameter_returns(String name ,String paramete } } has_parameter.clear(); - for(String s:hashSet){ - has_parameter.add(s); - } + has_parameter.addAll(hashSet); hashSet.clear(); } - return hashSet; } public static HashSet targetclass(List resultlist,String methodname,String methodparam,String methodreturn){ HashSet result = new HashSet<>(); @@ -283,13 +269,11 @@ public static HashSet targetclass(List resultlist,String methodn methodname = methodname.replace("*",""); if(methodMapdubbo.isEmpty()){ - for(Map.Entry handle:methodMap.entrySet()){ - methodMapdubbo.put(handle.getKey(),handle.getValue()); - } + methodMapdubbo.putAll(methodMap); } //name - if(resultlist.get(0) == "方法名模糊"){ + if(Objects.equals(resultlist.get(0), "方法名模糊")){ List list = new ArrayList<>(); HashSet hashSet = new HashSet<>(); for(Map.Entry handle:methodMapdubbo.entrySet()){ @@ -316,7 +300,7 @@ public static HashSet targetclass(List resultlist,String methodn //par - if(resultlist.get(1) == "参数模糊"){ + if(Objects.equals(resultlist.get(1), "参数模糊")){ List list = new ArrayList<>(); HashSet hashSet = new HashSet<>(); for(Map.Entry handle:methodMapdubbo.entrySet()){ @@ -327,7 +311,7 @@ public static HashSet targetclass(List resultlist,String methodn } parresult =getresult(hashSet,list); make_methoddunnolist(parresult); - }else if(resultlist.get(1) == "参数确定"){ + }else if(Objects.equals(resultlist.get(1), "参数确定")){ List list = new ArrayList<>(); HashSet hashSet = new HashSet<>(); for(Map.Entry handle:methodMapdubbo.entrySet()){ @@ -338,7 +322,7 @@ public static HashSet targetclass(List resultlist,String methodn } parresult = getresult(hashSet,list); make_methoddunnolist(parresult); - }else if(resultlist.get(1) == "没有参数"){ + }else if(Objects.equals(resultlist.get(1), "没有参数")){ List list = new ArrayList<>(); HashSet hashSet = new HashSet<>(); for(Map.Entry handle:methodMapdubbo.entrySet()){ @@ -352,7 +336,7 @@ public static HashSet targetclass(List resultlist,String methodn } //return - if(resultlist.get(2) == "返回值模糊"){ + if(Objects.equals(resultlist.get(2), "返回值模糊")){ List list = new ArrayList<>(); HashSet hashSet = new HashSet<>(); for(Map.Entry handle:methodMapdubbo.entrySet()){ @@ -363,7 +347,7 @@ public static HashSet targetclass(List resultlist,String methodn } returnresult = getresult(hashSet,list); make_methoddunnolist(returnresult); - } else if(resultlist.get(2) == "返回值确定") { + } else if(Objects.equals(resultlist.get(2), "返回值确定")) { List list = new ArrayList<>(); HashSet hashSet = new HashSet<>(); for(Map.Entry handle:methodMapdubbo.entrySet()){ @@ -374,7 +358,7 @@ public static HashSet targetclass(List resultlist,String methodn } returnresult = getresult(hashSet,list); make_methoddunnolist(returnresult); - }else if(resultlist.get(2) == "没有返回值") { + }else if(Objects.equals(resultlist.get(2), "没有返回值")) { List list = new ArrayList<>(); HashSet hashSet = new HashSet<>(); for(Map.Entry handle:methodMapdubbo.entrySet()){ @@ -388,7 +372,7 @@ public static HashSet targetclass(List resultlist,String methodn } //static - if(resultlist.get(3)=="nostatic"){ + if(Objects.equals(resultlist.get(3), "nostatic")){ List list = new ArrayList<>(); HashSet hashSet = new HashSet<>(); for(Map.Entry handle:methodMapdubbo.entrySet()){ @@ -400,7 +384,7 @@ public static HashSet targetclass(List resultlist,String methodn staticresult = getresult(hashSet,list); make_methoddunnolist(staticresult); } - if(resultlist.get(3)=="nostatic"){ + if(Objects.equals(resultlist.get(3), "nostatic")){ result = tarclass(nameresult,parresult,returnresult,staticresult); }else { result = tarclass(nameresult,parresult,returnresult); @@ -408,11 +392,8 @@ public static HashSet targetclass(List resultlist,String methodn return result; } public static void make_methoddunnolist(HashMap> hashMap){ - Map methodMapdubbos = new HashMap<>(); - for(Map.Entry handle:methodMapdubbo.entrySet()){ - methodMapdubbos.put(handle.getKey(),handle.getValue()); - } + Map methodMapdubbos = new HashMap<>(methodMapdubbo); methodMapdubbo.clear(); @@ -520,11 +501,11 @@ public static int appearNumber(String srcText, String findText) { } public static String control_parameter(String parameter){ String[] list = parameter.split(","); - String par = ""; - for(int i = 0;i has_superclass(HashSet superclass){ return has_superclass(hashSet); } } - public static List has_interfaces(List interfacea){ + public static void has_interfaces(List interfacea){ List hashSet = new ArrayList<>(); - for (int i = 0;i handle:classMap.entrySet()){ + for (String s : interfacea) { + if (hasinterfaces.size() == 0) { + for (Map.Entry handle : classMap.entrySet()) { List interfaces = handle.getValue().getInterfaces(); - if(interfaces !=null){ - for (int j=0;j handle:classMap.entrySet()){ + } else { + for (Map.Entry handle : classMap.entrySet()) { List interfaces = handle.getValue().getInterfaces(); - if(interfaces !=null){ - for (int j=0;j has_interfaces(List interfacea){ } } hasinterfaces.clear(); - for(String target :hashSet){ - hasinterfaces.add(target); - } + hasinterfaces.addAll(hashSet); hashSet.clear(); } } - return hashSet; } private static void inherit() { InheritanceMap inheritanceMap = InheritanceService.start(classMap);//key是每一个类classReference.getHandle,value是一个key为每一个class.handle,value其父类或者接口类handle的set集合 @@ -643,12 +622,13 @@ private static void getClassFileList(String path,boolean readjar,boolean readbas if(file.isFile()){ if(path.endsWith(".txt")){ List list = readUtil.readToString(path); - for(int i = 0;i jarfiles = readUtil.noRecursion(file,".jar"); - for(int i = 0;i jarfiles = ReadUtil.noRecursion(file,".jar"); + for (String jarfile : jarfiles) { + classFileList.addAll(ClassUtil.getAllClassesFromJars(Collections.singletonList(jarfile), readbasicjar)); } } } public static void returnresults(List target){ if(resultclass.size() == 0){ - for(String t:target){ - resultclass.add(t); - } + resultclass.addAll(target); }else{ - List middo = new ArrayList<>(); - for(String t:resultclass){ - middo.add(t); - } + List middo = new ArrayList<>(resultclass); resultclass.clear(); for(String s:middo){ - for(int i = 0;i - - - - - - - - - - diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF deleted file mode 100644 index f6bb0d7..0000000 --- a/target/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: ScreenApplication - diff --git a/target/classes/META-INF/jboss-service.xml b/target/classes/META-INF/jboss-service.xml deleted file mode 100644 index 6e8a625..0000000 --- a/target/classes/META-INF/jboss-service.xml +++ /dev/null @@ -1,7 +0,0 @@ - - jboss.jca:service=LocalTxCM,name=FoobarDS - java:/FoobarDS - java:/hibernate/SessionFactory - org.hibernate.dialect.HSQLDialect - update - diff --git a/target/classes/ScreenApplication.class b/target/classes/ScreenApplication.class deleted file mode 100644 index adf31ad..0000000 Binary files a/target/classes/ScreenApplication.class and /dev/null differ diff --git a/target/classes/app/Commands.class b/target/classes/app/Commands.class deleted file mode 100644 index e9a9f91..0000000 Binary files a/target/classes/app/Commands.class and /dev/null differ diff --git a/target/classes/app/Logo.class b/target/classes/app/Logo.class deleted file mode 100644 index 03ffd6b..0000000 Binary files a/target/classes/app/Logo.class and /dev/null differ diff --git a/target/classes/app/MainScreen.class b/target/classes/app/MainScreen.class deleted file mode 100644 index 1e96877..0000000 Binary files a/target/classes/app/MainScreen.class and /dev/null differ diff --git a/target/classes/basic_class/ClassFile.class b/target/classes/basic_class/ClassFile.class deleted file mode 100644 index 5e4596f..0000000 Binary files a/target/classes/basic_class/ClassFile.class and /dev/null differ diff --git a/target/classes/basic_class/ClassReference$Handle.class b/target/classes/basic_class/ClassReference$Handle.class deleted file mode 100644 index 0abdc1e..0000000 Binary files a/target/classes/basic_class/ClassReference$Handle.class and /dev/null differ diff --git a/target/classes/basic_class/ClassReference$Member.class b/target/classes/basic_class/ClassReference$Member.class deleted file mode 100644 index 6d0bd3a..0000000 Binary files a/target/classes/basic_class/ClassReference$Member.class and /dev/null differ diff --git a/target/classes/basic_class/ClassReference.class b/target/classes/basic_class/ClassReference.class deleted file mode 100644 index 3500579..0000000 Binary files a/target/classes/basic_class/ClassReference.class and /dev/null differ diff --git a/target/classes/basic_class/MethodReference$Handle.class b/target/classes/basic_class/MethodReference$Handle.class deleted file mode 100644 index e7c35c1..0000000 Binary files a/target/classes/basic_class/MethodReference$Handle.class and /dev/null differ diff --git a/target/classes/basic_class/MethodReference.class b/target/classes/basic_class/MethodReference.class deleted file mode 100644 index a24d528..0000000 Binary files a/target/classes/basic_class/MethodReference.class and /dev/null differ diff --git a/target/classes/classvisitor/DiscoveryClassVisitor.class b/target/classes/classvisitor/DiscoveryClassVisitor.class deleted file mode 100644 index 53cc835..0000000 Binary files a/target/classes/classvisitor/DiscoveryClassVisitor.class and /dev/null differ diff --git a/target/classes/inher/InheritanceMap.class b/target/classes/inher/InheritanceMap.class deleted file mode 100644 index 93c7003..0000000 Binary files a/target/classes/inher/InheritanceMap.class and /dev/null differ diff --git a/target/classes/inher/InheritanceUtil.class b/target/classes/inher/InheritanceUtil.class deleted file mode 100644 index 683f605..0000000 Binary files a/target/classes/inher/InheritanceUtil.class and /dev/null differ diff --git a/target/classes/services/DiscoveryService.class b/target/classes/services/DiscoveryService.class deleted file mode 100644 index 5d37970..0000000 Binary files a/target/classes/services/DiscoveryService.class and /dev/null differ diff --git a/target/classes/services/InheritanceService.class b/target/classes/services/InheritanceService.class deleted file mode 100644 index bd7b3ba..0000000 Binary files a/target/classes/services/InheritanceService.class and /dev/null differ diff --git a/target/classes/tools/ClassUtil.class b/target/classes/tools/ClassUtil.class deleted file mode 100644 index ac629d4..0000000 Binary files a/target/classes/tools/ClassUtil.class and /dev/null differ diff --git a/target/classes/tools/DirUtil.class b/target/classes/tools/DirUtil.class deleted file mode 100644 index 5d9b65f..0000000 Binary files a/target/classes/tools/DirUtil.class and /dev/null differ diff --git a/target/classes/tools/IOUtil.class b/target/classes/tools/IOUtil.class deleted file mode 100644 index 7649550..0000000 Binary files a/target/classes/tools/IOUtil.class and /dev/null differ diff --git a/target/classes/tools/JarUtil.class b/target/classes/tools/JarUtil.class deleted file mode 100644 index d0cfa84..0000000 Binary files a/target/classes/tools/JarUtil.class and /dev/null differ diff --git a/target/classes/tools/ReadUtil.class b/target/classes/tools/ReadUtil.class deleted file mode 100644 index 61156c3..0000000 Binary files a/target/classes/tools/ReadUtil.class and /dev/null differ