feat(ReverseEngine):初始化工程
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* @Author : huangzj
|
||||
* @Time : 2020/4/17 14:04
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
package util
|
||||
|
||||
import "syscall"
|
||||
|
||||
var (
|
||||
kernel32 *syscall.LazyDLL = syscall.NewLazyDLL(`kernel32.dll`)
|
||||
proc *syscall.LazyProc = kernel32.NewProc(`SetConsoleTextAttribute`)
|
||||
CloseHandle *syscall.LazyProc = kernel32.NewProc(`CloseHandle`)
|
||||
|
||||
// 给字体颜色对象赋值
|
||||
FontColor Color = Color{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
|
||||
)
|
||||
|
||||
type Color struct {
|
||||
black int // 黑色
|
||||
blue int // 蓝色
|
||||
green int // 绿色
|
||||
cyan int // 青色
|
||||
Red int // 红色
|
||||
purple int // 紫色
|
||||
yellow int // 黄色
|
||||
light_gray int // 淡灰色(系统默认值)
|
||||
gray int // 灰色
|
||||
light_blue int // 亮蓝色
|
||||
light_green int // 亮绿色
|
||||
light_cyan int // 亮青色
|
||||
light_red int // 亮红色
|
||||
light_purple int // 亮紫色
|
||||
light_yellow int // 亮黄色
|
||||
white int // 白色
|
||||
}
|
||||
|
||||
// 输出有颜色的字体
|
||||
func ColorPrint(s string, i int) {
|
||||
handle, _, _ := proc.Call(uintptr(syscall.Stdout), uintptr(i))
|
||||
print(s)
|
||||
CloseHandle.Call(handle)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"ReverseEngine/entity"
|
||||
"database/sql"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DbUtil struct {
|
||||
}
|
||||
|
||||
func FindColumnMessage(dbName string, tableName string, db *sql.DB) []entity.ColumnMessage {
|
||||
var cms []entity.ColumnMessage
|
||||
|
||||
row, err := db.Query(strings.Join([]string{"show full columns from ", dbName, ".", tableName}, ""))
|
||||
if err != nil {
|
||||
panic("数据库查询出错:" + err.Error())
|
||||
}
|
||||
|
||||
for row.Next() {
|
||||
var cm entity.ColumnMessage
|
||||
err := row.Scan(&cm.Field, &cm.Type, &cm.Collation, &cm.Null, &cm.Key, &cm.Default, &cm.Extra, &cm.Privileges, &cm.Comment)
|
||||
if err != nil {
|
||||
panic("字段赋值错误了" + err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
cms = append(cms, cm)
|
||||
}
|
||||
|
||||
return cms
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
获取当前项目的路径
|
||||
*/
|
||||
func GetCurrentPath() string {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return strings.Replace(dir, "\\", "/", -1)
|
||||
}
|
||||
|
||||
/*
|
||||
判断路径是否存在并且为文件夹
|
||||
*/
|
||||
func IsDirExist(dirPath string) bool {
|
||||
fi, err := os.Stat(dirPath)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if fi.IsDir() {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
判断路径是否存在并且为文件
|
||||
*/
|
||||
func IsFileExist(filePath string) bool {
|
||||
fi, err := os.Stat(filePath)
|
||||
//文件不存在或者是文件夹的直接返回false
|
||||
if err != nil || fi.IsDir() {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/*
|
||||
判断是否有读权限
|
||||
*/
|
||||
func HasReadPermission(filePath string) bool {
|
||||
_, err := os.OpenFile(filePath, os.O_RDONLY, 0666)
|
||||
if err != nil {
|
||||
if os.IsPermission(err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
判断是否有写权限
|
||||
*/
|
||||
func HasWritePermission(filePath string) bool {
|
||||
_, err := os.OpenFile(filePath, os.O_WRONLY, 0666)
|
||||
if err != nil {
|
||||
if os.IsPermission(err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/*
|
||||
判断是否有读+写权限
|
||||
*/
|
||||
func HasReadWritePermission(filePath string) bool {
|
||||
return HasReadPermission(filePath) && HasWritePermission(filePath)
|
||||
}
|
||||
|
||||
/*
|
||||
创建文件
|
||||
*/
|
||||
func CreateFile(filePath string) (*os.File, bool) {
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
panic("创建文件失败" + err.Error())
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return file, true
|
||||
}
|
||||
|
||||
/*
|
||||
返回拼接的文件路径,这边类的首字母需要大写
|
||||
dirPath 文件夹路径
|
||||
filePath 文件路径
|
||||
splice 路径分隔符
|
||||
suffix 后缀
|
||||
*/
|
||||
func GenerateFilePath(dirPath string, filePath string, splice string, suffix string) string {
|
||||
return strings.Join([]string{dirPath, splice, strings.Title(filePath), suffix}, "")
|
||||
}
|
||||
|
||||
/*
|
||||
创建(如果需要)并已读写权限打开文件
|
||||
os.O_RDONLY // 只读
|
||||
os.O_WRONLY // 只写
|
||||
os.O_RDWR // 读写
|
||||
os.O_APPEND // 往文件中添建(Append)
|
||||
os.O_CREATE // 如果文件不存在则先创建
|
||||
os.O_TRUNC // 文件打开时裁剪文件
|
||||
os.O_EXCL // 和O_CREATE一起使用,文件不能存在
|
||||
os.O_SYNC // 以同步I/O的方式打开
|
||||
*/
|
||||
func CreateNeedOpenFile(filePath string) (*os.File, bool) {
|
||||
//先删除再创建
|
||||
if IsFileExist(filePath) {
|
||||
err := os.Remove(filePath)
|
||||
if err != nil {
|
||||
panic("文件删除失败:" + err.Error())
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(filePath, os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
panic("打开文件失败:" + err.Error())
|
||||
return nil, false
|
||||
}
|
||||
return file, true
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* @Author : huangzj
|
||||
* @Time : 2020/4/17 14:41
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"gopkg.in/ini.v1"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GenerateConfigBool(key string, real *bool, section *ini.Section) {
|
||||
if section.Key(key).String() != "false" {
|
||||
*real = true
|
||||
return
|
||||
}
|
||||
*real = false
|
||||
}
|
||||
|
||||
func GenerateConfig(key string, real string, section *ini.Section) {
|
||||
if section.Key(key).String() != "" {
|
||||
real = section.Key(key).String()
|
||||
}
|
||||
}
|
||||
|
||||
func GenerateConfigInt(key string, real int, section *ini.Section) {
|
||||
if section.Key(key).String() != "" {
|
||||
value, err := strconv.Atoi(section.Key(key).String())
|
||||
if err == nil {
|
||||
real = value
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user