golang程序在编译时去掉了符号信息,怎么逆向

Python07

golang程序在编译时去掉了符号信息,怎么逆向,第1张

使用原始build编译的大小

6,107KB

通过去除部分连接和调试,build部分参数查看结果。

-a 强制编译所有依赖包。

-s 去掉符号信息

-w 去掉DWARF调试信息,得到的程序就不能用gdb调试了

不建议s和w同时使用。

go build -ldflags -w test.go

但是体积还是有点大

4,633KB

1、解压压缩包到go工作目录,如解压到E:\opensource\go\go,解压后的目录结构如下:

E:\opensource\go\go

├─api

├─bin

│ ├─go.exe

│ ├─godoc.exe

│ └─gofmt.exe

├─doc

├─include

├─lib

├─misc

├─pkg

├─src

└─test

2、增加环境变量GOROOT,取值为上面的go工作目录

3、Path环境变量中添加"%GOROOT%\bin",以便能够直接调用go命令来编译go代码,至此go编译环境就配置好了

注:如果不想手动设置系统环境变量,也可下载go启动环境批处理附件,

修改goenv.bat文件中的GOROOT值为上面的go工作目录后直接双击该bat文件,go编译环境变量即设置完成。

4、测试go编译环境,启动一个cmd窗口,直接输入go,看到下面的提示就是搭建成功了

E:\opensource\go\go>go

Go is a tool for managing Go source code.

Usage:

go command [arguments]

The commands are:

build compile packages and dependencies

clean remove object files

doc run godoc on package sources

env print Go environment information

fix run go tool fix on packages

fmt run gofmt on package sources

get download and install packages and dependencies

install compile and install packages and dependencies

listlist packages

run compile and run Go program

testtest packages

toolrun specified go tool

version print Go version

vet run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

gopath GOPATH environment variable

packagesdescription of package lists

remote remote import path syntax

testflagdescription of testing flags

testfuncdescription of testing functions

Use "go help [topic]" for more information about that topic.

5、编译helloworld测试程序,go语言包中test目录带有helloworld.go测试程序,源码见"附一 helloworld.go",

直接调用"go build helloworld.go"就生成了"helloworld.exe"可执行程序,运行一下这个程序看到了我们期望的hello,wolrd。

E:\opensource\go\go\test>go build helloworld.go

E:\opensource\go\go\test>helloworld.exe

hello, world

E:\opensource\go\go\test>

附一 helloworld.go

// cmpout

// Copyright 2009 The Go Authors. All rights reserved.

// Use of this source code is governed by a BSD-style

// license that can be found in the LICENSE file.

// Test that we can do page 1 of the C book.

package main

func main() {

print("hello, world\n")

}

现代应用支持多平台运行是一件稀松平常的事情,在 Go 语言里面,为了支持应用的多平台部署,给用户提供了方便的配置方式来轻松构建针对不同操作系统和平台的运行文件。

Go 的构建约束,即构建标签,是以 // go:build 为开始的行注释,如果是 1.16 或之前的版本,格式是 // +build 。跟此变更相关的 issue 可以参考 25348 。

构建标签必须出现在 package 子句之前。为了区分构建标签和包文档的描述注释,构建标签后面应该有一个空行。

构建标签由||, &&, !运算符以及括号来组合表达。运算符与 Go 中的含义相同。

例如,以下构建标签在满足 linux 和 386 约束,或者满足 darwin 而 cgo 不满足时构建文件:

//go:build (linux &&386) || (darwin &&!cgo)

又如:仅在使用 cgo 时,且仅在 Linux 和 OS X 上构建文件: //go:build cgo &&(linux || darwin)

注意:1.17 及以后的表达格式里,一个文件有多个 //go:build 行是错误的。

在 1.16 及以前的版本,多行构建标签是允许的,并且组合方式是通过空格和逗号等来区分,空格符表示 OR,逗号表示 AND,感叹号表示 NOT。而多行之间则表示 OR。gofmt 命令将在遇到旧语法时添加等效的 //go:build 约束。如下是示例:

如果文件名在去除扩展名和可能的 _test 后缀后匹配以下任何模式, (例如:source_windows_amd64.go)其中 GOOS 和 GOARCH 分别代表任何已知的操作系统和体系结构值,那么认为该文件除了文件中的任何显式约束之外,具有这些术语的所表达的隐式构建标签。

除了官方提供的针对不同平台的内置标签,用户也可以使用自定义标签,例如 //go:build prod , 只需要在执行 go build 时显式带上标签名 go build --tags=prod 。

想要使文件构建时被忽略,可以使用: //go:build ignore ,其他任何没有被用来定义为标签的词也可以,但"ignore"是约定俗成的。)。Go 语言目前支持的系统和架构可以参考 官方文档 。