Upgrade to Pro — share decks privately, control downloads, hide ads and more …

go:embedでExplainable Binaryを作る/fukoukago17_go_c...

go:embedでExplainable Binaryを作る/fukoukago17_go_code_embedding

monochromegane

June 10, 2021
Tweet

More Decks by monochromegane

Other Decks in Programming

Transcript

  1. • ॴఆͷ௥ՃϏϧυϓϩηεΛεΩοϓͯ͠΋ιʔείʔυͱဃ཭͠ͳ͍ • → go build (without ldflag) ͚ͩͰඞ࣮ͣߦ͞ΕΔϓϩηε •

    ϦϙδτϦ΍ಛఆϦϏδϣϯ͕ফࣦͯ͠΋ιʔείʔυΛࢀরͰ͖Δ • → 11 ݒ೦఺Λղফͨ͠όΠφϦ
  2. • ॴఆͷ௥ՃϏϧυϓϩηεΛεΩοϓͯ͠΋ιʔείʔυͱဃ཭͠ͳ͍ • → go build (without ldflag) ͚ͩͰඞ࣮ͣߦ͞ΕΔϓϩηε •

    ϦϙδτϦ΍ಛఆϦϏδϣϯ͕ফࣦͯ͠΋ιʔείʔυΛࢀরͰ͖Δ • → ιʔείʔυࣗମΛόΠφϦʹ಺แ͢Δ 12 ݒ೦఺Λղফͨ͠όΠφϦ
  3. • ॴఆͷ௥ՃϏϧυϓϩηεΛεΩοϓͯ͠΋ιʔείʔυͱဃ཭͠ͳ͍ • → go build (without ldflag) ͚ͩͰඞ࣮ͣߦ͞ΕΔϓϩηε •

    ϦϙδτϦ΍ಛఆϦϏδϣϯ͕ফࣦͯ͠΋ιʔείʔυΛࢀরͰ͖Δ • → ιʔείʔυࣗମΛόΠφϦʹ಺แ͢Δ 13 ݒ೦఺Λղফͨ͠όΠφϦ • go:embedͰόΠφϦʹιʔείʔυΛࠝแ͢Δͱ͍͏ఏҊ
  4. • ιʔείʔυΛόΠφϦʹ૊ΈࠐΈɺӾཡ͢ΔͨΊͷδΣωϨʔλ • ίϚϯυҰൃͰࣗ࡞ͷϓϩμΫτʹҎԼͷΞΫηαΦϓγϣϯΛ௥Ճ • ιʔείʔυදࣔͷΦϓγϣϯ • ιʔείʔυҰཡͷΦϓγϣϯ • ιʔείʔυ෮ݩͷΦϓγϣϯ

    15 ػೳ # myapp --help Usage of myapp: -list-code list code -restore-code restore code -restore-path string restore code to specified path (default ".") -show-code string show specified code Usage of myapp: -output-dir string Output directory (default ".") -pkg string Package name to use in the generated code. (default "main")
  5. 22 ࢓૊Έ Source code Generated code $ go build -o

    myapp Explainable binary -list-code list code -restore-code restore code -restore-path string restore code to specified path (default ".") -show-code string show specified code Source code
  6. • ιʔείʔυΛόΠφϦʹಉࠝ͢ΔΞΠσΟΞ͸ࣗ਎Ͱઌߦ࣮૷͍ͯͨ͠ • ʰ໺ྑόΠφϦʹͳͬͯ΋େৎ෉ɻGoͷόΠφϦʹιʔείʔυΛఴ෇͢ ΔπʔϧΛͭͬͨ͘ɻʱ(2015.8) (*1) • monochromegane/go-bincode (*2) •

    ઌߦ࣮૷͸go-bindataʹґଘ͍͕ͯͨ͠ɺඪ४ͷembedػೳʹஔ͖׵͑Δ͜ ͱ͕Ͱ͖ɺ࣮૷΋γϯϓϧʹͳͬͨɻ • go:embedͷීٴ͕ݟࠐ·ΕΔ͜ͱ͔ΒɺվΊͯఏҊʢωλ੾ΕͰ͸ͳ͍ʣ 27 ࣗ਎Ͱͷઌߦ࣮૷  IUUQTCMPHNPOPDISPNFHBOFDPNCMPHHPCJODPEF  IUUQTHJUIVCDPNNPOPDISPNFHBOFHPCJODPEF