Projects STRLCPY redress Commits e2e2c8c8
🤬
  • ■ ■ ■ ■ ■ ■
    go.mod
    skipped 3 lines
    4 4   
    5 5  require (
    6 6   github.com/TcM1911/r2g2 v0.1.0
    7  - github.com/goretk/gore v0.7.3
    8  - github.com/stretchr/objx v0.2.0 // indirect
    9  - github.com/stretchr/testify v1.4.0 // indirect
     7 + github.com/davecgh/go-spew v1.1.1 // indirect
     8 + github.com/goretk/gore v0.8.0
     9 + github.com/kr/pretty v0.1.0 // indirect
    10 10   gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
    11 11  )
    12 12   
  • ■ ■ ■ ■ ■ ■
    go.sum
    skipped 1 lines
    2 2  github.com/TcM1911/r2g2 v0.1.0/go.mod h1:bIlbmX15G7n81ptKeK12fCzghH1BH4jgJbl6RUc7t48=
    3 3  github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
    4 4  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
     5 +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
    5 6  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
    6  -github.com/goretk/gore v0.7.0 h1:5JVRBD69+TYcpU1FMsMlQb46FJaJJZq3HzX9n3CJKdM=
    7  -github.com/goretk/gore v0.7.0/go.mod h1:55S4yLVw56AnIltHwGa19ee7loewKG+a/+iVqfuoAlw=
    8  -github.com/goretk/gore v0.7.1 h1:Zy+ZkcZBqPByvbxFkTqSge5aDgsYKmnby75CzN7k80I=
    9  -github.com/goretk/gore v0.7.1/go.mod h1:55S4yLVw56AnIltHwGa19ee7loewKG+a/+iVqfuoAlw=
    10  -github.com/goretk/gore v0.7.2 h1:UPlM9nEPtRVu26qicO0Cl/Xvq3ehcewydA6KOEFZ0pk=
    11  -github.com/goretk/gore v0.7.2/go.mod h1:55S4yLVw56AnIltHwGa19ee7loewKG+a/+iVqfuoAlw=
    12  -github.com/goretk/gore v0.7.3 h1:wxsAGMtNO0DC/g6hFjS7aJKwLtqFnq93aeoMPaEfOoQ=
    13  -github.com/goretk/gore v0.7.3/go.mod h1:55S4yLVw56AnIltHwGa19ee7loewKG+a/+iVqfuoAlw=
     7 +github.com/goretk/gore v0.8.0 h1:VmIQbe9vl3MmhZt1Hcu+NoqK6obVNZ/S9imdOiGHJ3w=
     8 +github.com/goretk/gore v0.8.0/go.mod h1:feYF9BIRgr3SsMoGBRia9UaifmCTvlYXqM3DmjFLpRo=
     9 +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
     10 +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
     11 +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
     12 +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
     13 +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
    14 14  github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
    15 15  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
    16 16  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
    17  -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
    18  -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
    19 17  github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
    20 18  github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
    21 19  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
    22 20  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
     21 +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
    23 22  gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
    24 23  gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
    25 24  gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
    skipped 1 lines
  • ■ ■ ■ ■ ■ ■
    main.go
    skipped 28 lines
    29 29   lookupType *int
    30 30   printCompiler *bool
    31 31   printVersion *bool
     32 + resolveStrSlice *bool
    32 33  }
    33 34   
    34 35  // This is set at compile time.
    skipped 4 lines
    39 40  func init() {
    40 41   if r2g2.CheckForR2Pipe() {
    41 42   options.lookupType = flag.Int("type", 0, "Lookup the Go definition for a type")
     43 + options.resolveStrSlice = flag.Bool("str", false, "Print slice of strings at offset")
    42 44   } else {
    43 45   options.printPackages = flag.Bool("pkg", false, "List packages")
    44 46   options.printStdLibPackages = flag.Bool("std", false, "Include standard library packages")
    skipped 26 lines
  • ■ ■ ■ ■ ■ ■
    r2.go
    skipped 4 lines
    5 5  package main
    6 6   
    7 7  import (
     8 + "bytes"
     9 + "encoding/binary"
     10 + "flag"
    8 11   "fmt"
     12 + "io"
    9 13   "reflect"
     14 + "strconv"
    10 15   "strings"
    11 16   
    12 17   "github.com/TcM1911/r2g2"
    skipped 30 lines
    43 48   // Lookup type?
    44 49   if *options.lookupType != 0 {
    45 50   lookupType(file, uint64(*options.lookupType))
     51 + return
     52 + }
     53 + 
     54 + // Print a string slice
     55 + if *options.resolveStrSlice {
     56 + args := flag.Args()
     57 + if len(args) != 2 {
     58 + fmt.Println("2 arguments are required. Address and slice length")
     59 + return
     60 + }
     61 + address, err := strconv.ParseUint(args[0], 0, 32)
     62 + if err != nil {
     63 + fmt.Println("Failed to parse address argument:", err)
     64 + return
     65 + }
     66 + length, err := strconv.ParseUint(args[1], 0, 32)
     67 + if err != nil {
     68 + fmt.Println("Failed to parse length argument:", err)
     69 + return
     70 + }
     71 + printStringSlice(file, address, length)
    46 72   return
    47 73   }
    48 74   
    skipped 97 lines
    146 172   }
    147 173  }
    148 174   
     175 +func printStringSlice(f *gore.GoFile, offset uint64, length uint64) {
     176 + // Number of bytes needed for each string is one word for pointer to data and
     177 + // one word for the length of the data. This needs to be multiplied by the length
     178 + // of the array.
     179 + arrayData, err := f.Bytes(offset, 2*length*uint64(f.FileInfo.WordSize))
     180 + if err != nil {
     181 + fmt.Println("Failed to get string slice:", err)
     182 + return
     183 + }
     184 + r := bytes.NewReader(arrayData)
     185 + for i := 0; i < int(length); i++ {
     186 + strPtr, err := readUintToUint64(r, f.FileInfo)
     187 + if err != nil {
     188 + fmt.Println("Error when reading pointer to string data:", err)
     189 + return
     190 + }
     191 + strLen, err := readUintToUint64(r, f.FileInfo)
     192 + if err != nil {
     193 + fmt.Println("Error when reading string data length:", err)
     194 + return
     195 + }
     196 + strData, err := f.Bytes(strPtr, strLen)
     197 + if err != nil {
     198 + fmt.Println("Error when reading string data:", err)
     199 + return
     200 + }
     201 + fmt.Println(string(strData))
     202 + }
     203 +}
     204 + 
     205 +func readUintToUint64(r io.Reader, fi *gore.FileInfo) (uint64, error) {
     206 + if fi.WordSize == 4 {
     207 + var a uint32
     208 + err := binary.Read(r, fi.ByteOrder, &a)
     209 + return uint64(a), err
     210 + }
     211 + var a uint64
     212 + err := binary.Read(r, fi.ByteOrder, &a)
     213 + return a, err
     214 +}
     215 + 
Please wait...
Page is in error, reload to recover