Skip to content

Instantly share code, notes, and snippets.

@ubogdan
Forked from itaysk/Makefile
Created February 12, 2024 10:36
Show Gist options
  • Save ubogdan/bfd515e8c91d5ac89a2372cf1b7aeb26 to your computer and use it in GitHub Desktop.
Save ubogdan/bfd515e8c91d5ac89a2372cf1b7aeb26 to your computer and use it in GitHub Desktop.

Revisions

  1. @itaysk itaysk created this gist Apr 29, 2020.
    3 changes: 3 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    build:
    go build -o _main
    objcopy --add-section myfile=myfile _main main
    20 changes: 20 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    package main

    import (
    "debug/elf"
    "fmt"
    "os"
    )

    func main() {
    selfPath, _ := os.Executable()
    selfFile, _ := os.Open(selfPath)
    selfElf, _ := elf.NewFile(selfFile)
    var data []byte
    for _, s := range selfElf.Sections {
    if s.Name == "myfile" {
    data, _ = s.Data()
    }
    }
    fmt.Println(string(data))
    }