golang 獲取exe dll apk 版本號

2021-07-10 20:13:11 字數 2704 閱讀 3652

通過go獲取exe、dll、apk版本號,支援誇平台,可交叉編譯。
換了個賬號,審核下。我把另乙個賬號的文章都會刪掉。
// golang 實現讀取exe dll apk 版本號

}// 獲取exe dll版本

func (f *fileinfo) getexeversion() (err error)

peoffset := f.unpack(byte)

if peoffset < peoffset

// 讀取從檔案開頭移位到 peoffset,第二次讀取 24 byte

_, err = file.seek(int64(peoffset), 0)

buffer = make(byte, 24)

_, err = file.read(buffer)

f.checkerror(err)

str = string(buffer[0]) + string(buffer[1])

if str != pe

machine := f.unpack(byte)

if machine != machine

nosections := f.unpack(byte)

opthdrsize := f.unpack(byte)

// 讀取從當前位置移位到 opthdrsize,第三次讀取 40 byte

file.seek(int64(opthdrsize), 1)

resfound := false

for i := 0; i < int(nosections); i++

}if !resfound

infovirt := f.unpack(byte)

infosize := f.unpack(byte)

infooff := f.unpack(byte)

// 讀取從檔案開頭位置移位到 infooff,第四次讀取 infosize byte

file.seek(int64(infooff), 0)

buffer = make(byte, infosize)

_, err = file.read(buffer)

f.checkerror(err)

nameentries := f.unpack(byte)

identries := f.unpack(byte)

var infofound bool

var suboff, i int64

for i = 0; i < (nameentries + identries); i++ )

if typet == typet ))

break}}

if !infofound

suboff = suboff & 0x7fffffff

infooff = f.unpack(byte) //offset of first fileinfo

infooff = infooff & 0x7fffffff

infooff = f.unpack(byte) //offset to data

dataoff := f.unpack(byte)

dataoff = dataoff - infovirt

version1 := f.unpack(byte)

version2 := f.unpack(byte)

version3 := f.unpack(byte)

version4 := f.unpack(byte)

version := fmt.sprintf("%d.%d.%d.%d", version2, version1, version4, version3)

f.version = version

return nil

}func (f *fileinfo) unpack(b byte) (num int64)

return

}// 獲取 apk 版本

func (f *fileinfo) getapkversion() (err error)

func init()

func main()

switch

fmt.printf("%s", file.version)

}

golang學習 獲取URL

執行命令 go run main.go 這個程式從兩個package中匯入了函式,net http和io ioutil包,http.get函式是建立http請求 的函式,如果獲取過程沒有出錯,那麼會在resp這個結構體中得到訪問的請求結果。resp的 body欄位包括乙個可讀的伺服器響應流。iout...

golang 獲取檔案大小

目錄 read位元組方式 ioutil方式 stat方法 終極方案 os.stat 在專案中,我們可能會需要獲取乙個檔案的大小,在go語言中,有很多方法來獲取乙個檔案的大小 func main fmt.println file size is sum 這種方式需要開啟檔案,通過for迴圈讀取檔案的位...

golang獲取命令列引數

package main import fmt os func main os可以通過變數args來獲取命令引數,os.args返回乙個字串陣列。其中第乙個引數就是執行檔案的名字。package main import flag fmt func main 執行go run test.go,會得到 ...