Skip to content

Commit

Permalink
v2.0.1 release!
Browse files Browse the repository at this point in the history
- Register preserving related bugs fixed
- Safe random register selection related bugs fixed
- Done major code refactoring
- New parameter parsing module added
- Command line parameters updated
- Example code updated
  • Loading branch information
EgeBalci committed Dec 18, 2023
1 parent 94a63c5 commit 8954414
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 243 deletions.
67 changes: 67 additions & 0 deletions config/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package config

import (
"errors"
"os"

"github.com/EgeBalci/sgn/utils"
"github.com/alecthomas/kong"
)

var (
Version = "?"
)

type Options struct {
Input string `help:"Input binary path" name:"input" short:"i"`
Output string `help:"Encoded output binary name" name:"out" short:"o"`
Arch int `help:"Binary architecture (32/64)" name:"arch" short:"a" default:"64"`
EncCount int `help:"Number of times to encode the binary (increases overall size)" name:"enc" short:"c" default:"1"`
ObsLevel int `help:"Maximum number of bytes for decoder obfuscation" name:"max" short:"M" default:"50"`
PlainDecoder bool `help:"Do not encode the decoder stub" name:"plain"`
AsciiPayload bool `help:"Generates a full ASCI printable payload (may take very long time to bruteforce)" name:"ascii"`
Safe bool `help:"Preserve all register values (a.k.a. no clobber)" name:"safe" short:"S"`
BadChars string `help:"Don't use specified bad characters given in hex format (\\x00\\x01\\x02...)" name:"badchars"`
Verbose bool `help:"Verbose mode" name:"verbose" short:"v"`
Version kong.VersionFlag
}

func HelpPrompt(options kong.HelpOptions, ctx *kong.Context) error {
err := kong.DefaultHelpPrinter(options, ctx)
if err != nil {
return err
}
return nil
}

func ConfigureOptions() (*Options, error) {
args := os.Args[1:]
// Parse arguments and check for errors
opts := &Options{}
parser, err := kong.New(
opts,
kong.Help(HelpPrompt),
kong.UsageOnError(),
kong.Vars{"version": Version},
kong.ConfigureHelp(kong.HelpOptions{
Summary: true,
}),
)
if err != nil {
return nil, err
}
_, err = parser.Parse(args)
if err != nil {
return nil, err
}

if opts.Input == "" {
return nil, errors.New("input file parameter is mandatory")
}

if opts.Verbose {
utils.Verbose = true
}

return opts, nil
}
14 changes: 8 additions & 6 deletions examples/encode_x64_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ package main
import (
"encoding/hex"
"fmt"
"io/ioutil"
"os"

sgn "github.com/egebalci/sgn/lib"
sgn "github.com/egebalci/sgn/pkg"
)

func main() {
// First open some file
file, err := ioutil.ReadFile("myfile.bin")
file, err := os.ReadFile("myfile.bin")
if err != nil { // check error
fmt.Println(err)
return
}
// Create a new SGN encoder
encoder := sgn.NewEncoder()
// Set the proper architecture
encoder.SetArchitecture(64)
encoder, err := sgn.NewEncoder(64)
if err != nil {
fmt.Println(err)
return
}
// Encode the binary
encodedBinary, err := encoder.Encode(file)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ go 1.15

require (
github.com/EgeBalci/keystone-go v0.0.0-20200525180613-e6c7cd32ceae
github.com/alecthomas/kong v0.8.1 // indirect
github.com/briandowns/spinner v1.11.1
github.com/fatih/color v1.10.0
github.com/fatih/color v1.16.0
github.com/olekukonko/tablewriter v0.0.4
github.com/rs/zerolog v1.31.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)
27 changes: 27 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
github.com/EgeBalci/keystone-go v0.0.0-20200525180613-e6c7cd32ceae h1:IMOEVXYMrzHg+1oWgTYBEwzMGsxFHUgoreu2Ic62K7Q=
github.com/EgeBalci/keystone-go v0.0.0-20200525180613-e6c7cd32ceae/go.mod h1:/HCfOmUN3INldcXC0YnFrOtOw3MuRFEQ9cKTT5fZuQ8=
github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA=
github.com/alecthomas/kong v0.8.1 h1:acZdn3m4lLRobeh3Zi2S2EpnXTd1mOL6U7xVml+vfkY=
github.com/alecthomas/kong v0.8.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/briandowns/spinner v1.11.1 h1:OixPqDEcX3juo5AjQZAnFPbeUA0jvkp2qzB5gOZJ/L0=
github.com/briandowns/spinner v1.11.1/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX3FScO+3/ZPQ=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Loading

0 comments on commit 8954414

Please sign in to comment.