Skip to content

Commit

Permalink
更新了v4.0.1
Browse files Browse the repository at this point in the history
将核心代码都进行注释,将ui美化
  • Loading branch information
0Chencc committed Dec 7, 2021
1 parent 57200b4 commit 9f6b24b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 7 deletions.
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'org.ctfcracktools'
version '4.0.0'
version '4.0.1'

buildscript {
ext.kotlin_version = '1.4.10'
Expand All @@ -21,7 +21,9 @@ jar {
from{
configurations.runtime.collect{zipTree(it)}
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA','META-INF/LICENSE.txt','META-INF/NOTICE.txt','META-INF/*/*/*.class'
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA',
'META-INF/LICENSE.txt','META-INF/NOTICE.txt','META-INF/*/*/*.class',
'META-INF/LICENSE'
manifest{attributes 'Main-Class': 'org.ctfcracktools.Main'}
}

Expand All @@ -36,7 +38,6 @@ sourceSets{

repositories {
maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/'}
maven { url 'https://jitpack.io' }
mavenLocal()
mavenCentral()
}
Expand All @@ -51,7 +52,8 @@ dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.9'
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
compile 'com.github.atarw:material-ui-swing:v0.9.6'
// https://mvnrepository.com/artifact/com.formdev/flatlaf
compile group: 'com.formdev', name: 'flatlaf', version: '1.6.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
}

Expand Down
11 changes: 9 additions & 2 deletions src/org/ctfcracktools/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.ctfcracktools;

import java.awt.*;

import com.formdev.flatlaf.FlatLightLaf;
import org.ctfcracktools.ui.*;
import javax.swing.*;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
Expand All @@ -10,9 +12,14 @@
*/
public class Main {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel( new FlatLightLaf() );
} catch( Exception ex ) {
System.err.println( "Failed to initialize LaF" );
}
String title = "CTFCrackTools %s %s";
String version = "4.0.0";
String slogan = "";
String version = "4.0.1";
String slogan = "new UI";
JFrame f = new JFrame(String.format(title, version,slogan));
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
f.setBounds((int)(d.getWidth()-900)/2,(int)d.getWidth()/2-600,900,600);
Expand Down
36 changes: 36 additions & 0 deletions src/org/ctfcracktools/fuction/PythonFunc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ import java.util.*

class PythonFunc {
lateinit var interpreter:PythonInterpreter

/**
* 初始化
*/
init {
jythonLoad()
}

/**
* 加载jython
*/
private fun jythonLoad(){
val props = Properties()
val setting = SettingJson().parseJson()
Expand All @@ -24,8 +32,24 @@ class PythonFunc {
sysS.path.add(System.getProperty("user.dir") + "")
interpreter = PythonInterpreter()
}

/**
* 加载py脚本
* @param file 文件名(含目录)
*/
fun loadFile(file:String)= interpreter.execfile(file)

/**
* 加载要调用的函数
* @param interpreter PythonInterpreter
* @param funcName 函数名
*/
fun loadPythonFunc(interpreter: PythonInterpreter, funcName: String): PyFunction = interpreter[funcName, PyFunction::class.java]

/**
* 执行python脚本(无参数)
* @param function 配合loadPythonFunc将加载好文件目录、函数的解析成函数形式传入
*/
fun execFunc(function:PyFunction):Any?{
var pyObject:PyObject? = null
try{
Expand All @@ -35,6 +59,12 @@ class PythonFunc {
}
return pyObject!!.__tojava__(Any::class.java)
}

/**
* 执行python脚本(含参数)
* @param function 配合loadPythonFunc将加载好文件目录、函数的解析成函数形式传入
* @param values 多参数
*/
fun execFuncOfArr(function: PyFunction,vararg values: String?): Any? {
val strings = arrayOfNulls<PyString>(values.size)
for (i in strings.indices) {
Expand All @@ -48,6 +78,12 @@ class PythonFunc {
}
return pyObject!!.__tojava__(Any::class.java)
}

/**
* 获取作者信息
* @param file 文件地址
* @return Map<String,Object> 返回一个含有作者信息的map
*/
fun getAuthorInfo(file:String):Map<String,Any> {
loadFile(file)
return execFunc(loadPythonFunc(interpreter,"author_info")) as Map<String, Any>}
Expand Down
29 changes: 28 additions & 1 deletion src/org/ctfcracktools/json/PluginsJson.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,31 @@ import kotlin.collections.ArrayList

class PluginsJson {
private var jsonFile = File("ctfcracktools_plugins.json")

/**
* 初始化
*/
init{
if(!isJson()){
val initPlugins = arrayListOf<Map<String,Any>>()
jsonFile.createNewFile()
writeJson(initPlugins)
}
}

/**
* 解析json文件
* @return 返回一个Map<String,Object>的ArrayList插件列表
*/
fun parseJson(): ArrayList<Map<String, Any>> {
val pluginsReader = BufferedReader(FileReader(jsonFile))
return Gson().fromJson(pluginsReader, object : TypeToken<ArrayList<Map<String, Any>>>() {}.type)
}

/**
* 根据name去json文件中进行搜索,返回第一个
* @param name String 插件名称
*/
fun search(name:String):Map<String,Any>{
val plugins = parseJson()
var plugin:Map<String,Any> = HashMap()
Expand All @@ -29,17 +43,30 @@ class PluginsJson {
}
return plugin
}

/**
* 删除插件
* @param plugin Map<String,Object> 传入一个plugin的信息,进行删除
*/
fun removePlugin(plugin:Map<String,Any>){
val plugins = parseJson()
plugins.remove(plugin)
writeJson(plugins)
}

/**写入配置文件
* @param plugins ArrayList<Map<String,Object>> 插件别表
*/
fun writeJson(plugins:ArrayList<Map<String,Any>>){
val gson = GsonBuilder().setPrettyPrinting().create()
val writer = BufferedWriter(FileWriter(jsonFile))
writer.write(gson.toJson(plugins))
writer.flush()
}
// fun getDialog(dialog: Any?):ArrayList<*> = dialog as ArrayList<*>

/**
* 判断是否为配置文件
* @return Boolean
*/
fun isJson():Boolean = jsonFile.isFile && jsonFile.exists()
}
10 changes: 10 additions & 0 deletions src/org/ctfcracktools/json/SettingJson.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ class SettingJson {
writeJson(initSetting)
}
}

/**
* 返回一个储存配置信息的Map
* @return Map<String,String>
*/
fun parseJson():Map<String,String>{
val settingReader = BufferedReader(FileReader(settingFile))
return Gson().fromJson(settingReader, object : TypeToken<Map<String, String>>() {}.type)
}

/**
* 将配置信息写入json文件
* @param Setting String 配置信息
*/
fun writeJson(setting:Map<String,String>){
val gson = GsonBuilder().setPrettyPrinting().create()
val writer = BufferedWriter(FileWriter(settingFile))
Expand Down

0 comments on commit 9f6b24b

Please sign in to comment.