s2s is a command line tool for database reverse engineering.

Overview

s2s

什么是s2s

s2s (sql to structure)是一款命令行数据库逆向工程工具,它可以通过数据库表生成对应的JavaGoRust结构体(class),后面将陆续支持更多的语言。

配置数据库源

s2s依赖于你的数据库,所以需要你配置好你的数据库连接信息,以便s2s会正常的运行。配置信息方法很简单你只需要在你的环境变量中加入以下信息即可。

#s2s 命令的数据库信息
export s2s_host="127.0.0.1:3306"
export s2s_user="root"
export s2s_pwd="you db password"
export s2s_charset="utf8"

windows的配置此电脑->属性->高级系统设置->环境变量MacLinux则在~/.profile或者~/.zshrc中添加以上配置信息即可。

使用方法

  1. 你可以克隆下载本代码库,然后如果你的电脑上已经安装好了go的编译器那么就进入主目录即可使用go build命令编译生成二进制程序文件。

  2. 如果你觉得麻烦即可在下面列表中找到你对应的平台架构下载对应的二进制可执行文件到电脑上,如果你想在系统上随意调用你则只需要把s2s的安装目录放入你的环境变量中。

  3. 目前对Rust部分数据类型支持不够友好,不过不耽误使用,目前被生成的数据库表名格式必须为user_info这样的snake case这种格式!!后面会考虑修复这个bug

平台 地址
windows-64 单元格
Mac-64 单元格

内置命令

PS: 在命令行模式下按下tab键会有命令补全提示!

命令 使用方法
databases 显示所有数据库名
use 指定使用哪个数据库
tables 显示当前数据库所有表
gen 生成指定的表,gen 表名
info 显示数据库所有信息
exit 退出命令行模式
clear 清理屏幕内容

使用案例

exit 🤖‍: Bye👋 :) ">
$:> s2s java

	        ______
	.-----.|__    |.-----.
	|__ --||    __||__ --|
	|_____||______||_____|



🥳: You have entered the command line mode!

🥳: Press the 'tab' key to get a prompt!

🥳: Enter `exit` to exit the program!

😃:s2s>databases
+---+--------------------+
| * | Database           |
+---+--------------------+
| 1 | information_schema |
| 2 | emp_db             |
| 3 | mysql              |
| 4 | performance_schema |
| 5 | sys                |
| 6 | test_db            |
+---+--------------------+


😃:s2s>use emp_db

🤖‍: Selected as database 👉 `emp_db`!

😃:s2s>tables
+---+-----------+
| * | Tables    |
+---+-----------+
| 1 | user_info |
+---+-----------+


😃:s2s>gen user_info

	package model


	import java.sql.Timestamp;

	import java.math.BigDecimal;

	import java.math.BigInteger;


	public class UserInfo {


		// 用户账号
		private String Account;

		// 用户创建时间
		private Timestamp CreateTime;

		// 用户更新时间
		private Timestamp UpdatedDate;

		// 用户年龄
		private short Age;

		// 用户余额
		private BigDecimal Money;

		// 用户ID
		private BigInteger Uid;



		public String getAccount() {
			return Account;
		}

		public void setAccount(String Account) {
			this.Account = Account;
		}

		public Timestamp getCreateTime() {
			return CreateTime;
		}

		public void setCreateTime(Timestamp CreateTime) {
			this.CreateTime = CreateTime;
		}

		public Timestamp getUpdatedDate() {
			return UpdatedDate;
		}

		public void setUpdatedDate(Timestamp UpdatedDate) {
			this.UpdatedDate = UpdatedDate;
		}

		public short getAge() {
			return Age;
		}

		public void setAge(short Age) {
			this.Age = Age;
		}

		public BigDecimal getMoney() {
			return Money;
		}

		public void setMoney(BigDecimal Money) {
			this.Money = Money;
		}

		public BigInteger getUid() {
			return Uid;
		}

		public void setUid(BigInteger Uid) {
			this.Uid = Uid;
		}


		@Override
		public String toString() {
			return "user_info{" +

					"Account=" + Account + ","+

					"CreateTime=" + CreateTime + ","+

					"UpdatedData=" + UpdatedDate + ","+

					"Age=" + Age + ","+

					"Money=" + Money + ","+

					"Uid=" + Uid + ","+

					"}";
		}
	}

😃:s2s>exit

🤖‍: Bye👋 :)

导入包

本库支持你二次开发使用,你只需要导入本包即可在你的代码中进行扩充开发,但是目前仅支持go语言!

  1. 下载
go get -u github.com/higker/s2s
  1. 导入并且使用
package main

import (
	"github.com/higker/s2s/core/lang/java"
	"github.com/higker/s2s/core/db"
)


func main() {

    // 创建一个Java的代码生成器
    structure := java.New()
    
    // 数据库连接信息
    if err := structure.OpenDB(
        &db.Info{
            HostIPAndPort: os.Getenv("s2s_host"), // 数据库IP
            UserName:      os.Getenv("s2s_user"), // 数据库用户名
            Password:      os.Getenv("s2s_pwd"),  // 数据库密码
            Type:          db.MySQL,              // 数据库类型 PostgreSQL Oracle
            Charset:       os.Getenv("s2s_charset"),
        },
    ); err != nil {
        // Failed to establish a connection to the database!
        // .... logic code
    }
		
    defer structure.Close()
    
    structure.SetSchema("选择数据库名")
    
    // 生成结果输出到标准输出
    structure.Parse(os.Stdout,"表名")

}

其他

目前仅支持mysql数据库,如果有想贡献代码提issues!跟多需求: 1. 支持linux管道命令这样就可以可编程操作了,前面一个输出就是后面一个程序的输入。

Issues
Owner
Jaco Ding
Jokes are truth.
Jaco Ding
ReverseSSH - a statically-linked ssh server with reverse shell functionality for CTFs and such

ReverseSSH A statically-linked ssh server with a reverse connection feature for simple yet powerful remote access. Most useful during HackTheBox chall

null 357 Sep 20, 2021
:cherry_blossom: A command-line fuzzy finder

fzf is a general-purpose command-line fuzzy finder. It's an interactive Unix filter for command-line that can be used with any list; files, command hi

Junegunn Choi 39.3k Sep 24, 2021
A versatile library for building CLI applications in Go

mow.cli Package cli provides a framework to build command line applications in Go with most of the burden of arguments parsing and validation placed o

Jawher Moussa 748 Sep 5, 2021
A modern UNIX ed (line editor) clone written in Go

ed (the awesome UNIX line editor) ed is a clone of the UNIX command-line tool by the same name ed a line editor that was nortorious for being and most

James Mills 45 May 29, 2021
Simplistic interactive filtering tool

peco Simplistic interactive filtering tool NOTE: If you are viewing this on GitHub, this document refers to the state of peco in whatever current bran

null 6.5k Sep 18, 2021
A Commander for modern Go CLI interactions

Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files. Cobra is used i

Steve Francia 23.2k Sep 17, 2021
Kong is a command-line parser for Go

Kong is a command-line parser for Go Introduction Help Help as a user of a Kong application Defining help in Kong Command handling Switch on the comma

Alec Thomas 663 Sep 25, 2021
Secure, private and feature-rich CLI password manager

Kure Kure is a free and open-source password manager for the command-line. This project aims to offer the most secure and private way of operating wit

Gastón Palomeque 110 Sep 15, 2021
A command-line tool and library for generating regular expressions from user-provided test cases

Table of Contents What does this tool do? Do I still need to learn to write regexes then? Current features How to install? 4.1 The command-line tool 4

Peter M. Stahl 4.5k Sep 25, 2021
Handy little CLI for interacting with OCI data

oci-tool Handy little CLI for interacting with OCI data Installation go get github.com/csweichel/oci-tool I use Gitpod for developing this tool; you s

Christian Weichel 7 Sep 9, 2021
CONTRIBUTIONS ONLY: A Go (golang) command line and flag parser

CONTRIBUTIONS ONLY What does this mean? I do not have time to fix issues myself. The only way fixes or new features will be added is by people submitt

Alec Thomas 3.1k Sep 15, 2021
wrench - Schema management tool for Cloud Spanner -

wrench wrench is a schema management tool for Cloud Spanner. Please feel free to report issues and send pull requests, but note that this application

Cloud Spanner Ecosystem 132 Aug 13, 2021
Fully featured Go (golang) command line option parser with built-in auto-completion support.

go-getoptions Go option parser inspired on the flexibility of Perl’s GetOpt::Long. Table of Contents Quick overview Examples Simple script Program wit

David Gamba 37 Sep 16, 2021
sg is the CLI tool that Sourcegraph developers can use to develop Sourcegraph.

sg is the CLI tool that Sourcegraph developers can use to develop Sourcegraph.

Sourcegraph 25 Sep 14, 2021
Go (golang) package with 70+ configurable terminal spinner/progress indicators.

Spinner spinner is a simple package to add a spinner / progress indicator to any terminal application. Examples can be found below as well as full exa

Brian Downs 1.6k Sep 21, 2021
Reads from existing Cloud Providers (reverse Terraform) and generates your infrastructure as code on Terraform configuration

TerraCognita Imports your current Cloud infrastructure to an Infrastructure As Code Terraform configuration (HCL) or/and to a Terraform State. At Cycl

Cycloid 706 Sep 19, 2021
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Table of contents Introduction Reference Contributing Introduction Overview git-xargs is a command-line tool (CLI) for making updates across multiple

Gruntwork 489 Sep 24, 2021
🔥 [WIP] Interactive Jira Command Line

JiraCLI Interactive Jira CLI ?? This project is still a work in progress ?? This tool mostly focuses on issue search and navigation at the moment. How

Ankit Pokhrel 175 Sep 16, 2021
Pure Go line editor with history, inspired by linenoise

Liner Liner is a command line editor with history. It was inspired by linenoise; everything Unix-like is a VT100 (or is trying very hard to be). If yo

Peter Harris 814 Sep 13, 2021