github.com/pkujhd/goloader@v0.0.0-20240411034752-1a28096bd7bd/obj/utils.go (about)

     1  package obj
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/pkujhd/goloader/constants"
     7  )
     8  
     9  func FindFileTab(filename string, namemap map[string]int, filetab []uint32) int32 {
    10  	tab := namemap[filename]
    11  	for index, value := range filetab {
    12  		if uint32(tab) == value {
    13  			return int32(index)
    14  		}
    15  	}
    16  	return -1
    17  }
    18  
    19  //go:inline
    20  func Grow(bytes *[]byte, size int) {
    21  	if len(*bytes) < size {
    22  		*bytes = append(*bytes, make([]byte, size-len(*bytes))...)
    23  	}
    24  }
    25  
    26  //go:inline
    27  func ReplacePkgPath(name, pkgpath string) string {
    28  	if !strings.HasPrefix(name, constants.TypeStringPrefix) {
    29  		name = strings.Replace(name, constants.EmptyPkgPath, pkgpath, -1)
    30  		//golang 1.13 - 1.19 go build -gcflags="-p xxx" xxx.go ineffective
    31  		name = strings.Replace(name, constants.CommandLinePkgPath, pkgpath, -1)
    32  	}
    33  	return name
    34  }