Projects STRLCPY redress Commits 5163f8bd
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    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