Golang : A program that contain another program and executes it during run-time
For this tutorial, what we are trying to achieve here is to write a program that contains another mini program inside it. The mini program is embedded inside the main program as []byte
slice and the mini program will only appear during run-time with the output captured by the main program.
NOTE: For some this is also known as shell code.
Now, why would anyone deploys a program that will create another program during run-time? A few reasons. Some are malicious and some are purely for defensive programming - i.e to prevent reverse engineering.
One good reason to have a mini program inside a main program is to perform checksum integrity on the main executable or other modules during run-time. If any of the checksum verification goes wrong, then send out alert or inform the main program to abort further execution.
Another popular usage is for the main program to deploy a .DLL
or .so
file during run-time and delete the file after the main program about to terminates.
As for the malicious part, I will leave it to your own imagination, but please remember that this world has "karma" and whatever malicious things your program does .....somehow and somewhere later it will come back to haunt you.
Alright, here you go!
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
)
func handleError(err error) {
if err != nil {
panic(err)
}
}
func main() {
// this is a 8.6kb Hello World program written in C - from https://socketloop.com/tutorials/golang-convert-an-executable-file-into-byte-example
miniProgram := []byte{127,69,76,70,2,1,1,0,0,0,0,0,0,0,0,0,2,0,62,0,1,0,0,0,48,4,64,0,0,0,0,0,64,0,0,0,0,0,0,0,224,25,0,0,0,0,0,0,0,0,0,0,64,0,56,0,9,0,64,0,31,0,28,0,6,0,0,0,5,0,0,0,64,0,0,0,0,0,0,0,64,0,64,0,0,0,0,0,64,0,64,0,0,0,0,0,248,1,0,0,0,0,0,0,248,1,0,0,0,0,0,0,8,0,0,0,0,0,0,0,3,0,0,0,4,0,0,0,56,2,0,0,0,0,0,0,56,2,64,0,0,0,0,0,56,2,64,0,0,0,0,0,28,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,64,0,0,0,0,0,252,6,0,0,0,0,0,0,252,6,0,0,0,0,0,0,0,0,32,0,0,0,0,0,1,0,0,0,6,0,0,0,16,14,0,0,0,0,0,0,16,14,96,0,0,0,0,0,16,14,96,0,0,0,0,0,40,2,0,0,0,0,0,0,48,2,0,0,0,0,0,0,0,0,32,0,0,0,0,0,2,0,0,0,6,0,0,0,40,14,0,0,0,0,0,0,40,14,96,0,0,0,0,0,40,14,96,0,0,0,0,0,208,1,0,0,0,0,0,0,208,1,0,0,0,0,0,0,8,0,0,0,0,0,0,0,4,0,0,0,4,0,0,0,84,2,0,0,0,0,0,0,84,2,64,0,0,0,0,0,84,2,64,0,0,0,0,0,68,0,0,0,0,0,0,0,68,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,80,229,116,100,4,0,0,0,212,5,0,0,0,0,0,0,212,5,64,0,0,0,0,0,212,5,64,0,0,0,0,0,52,0,0,0,0,0,0,0,52,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,81,229,116,100,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,82,229,116,100,4,0,0,0,16,14,0,0,0,0,0,0,16,14,96,0,0,0,0,0,16,14,96,0,0,0,0,0,240,1,0,0,0,0,0,0,240,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,47,108,105,98,54,52,47,108,100,45,108,105,110,117,120,45,120,56,54,45,54,52,46,115,111,46,50,0,4,0,0,0,16,0,0,0,1,0,0,0,71,78,85,0,0,0,0,0,2,0,0,0,6,0,0,0,32,0,0,0,4,0,0,0,20,0,0,0,3,0,0,0,71,78,85,0,112,186,147,42,25,199,158,118,176,227,83,101,169,166,168,185,59,13,162,154,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,0,0,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,36,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,105,98,99,46,115,111,46,54,0,112,114,105,110,116,102,0,95,95,108,105,98,99,95,115,116,97,114,116,95,109,97,105,110,0,95,95,103,109,111,110,95,115,116,97,114,116,95,95,0,71,76,73,66,67,95,50,46,50,46,53,0,0,0,0,2,0,2,0,0,0,1,0,1,0,1,0,0,0,16,0,0,0,0,0,0,0,117,26,105,9,0,0,2,0,51,0,0,0,0,0,0,0,248,15,96,0,0,0,0,0,6,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,24,16,96,0,0,0,0,0,7,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,32,16,96,0,0,0,0,0,7,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,72,131,236,8,72,139,5,37,12,32,0,72,133,192,116,5,232,67,0,0,0,72,131,196,8,195,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,53,18,12,32,0,255,37,20,12,32,0,15,31,64,0,255,37,18,12,32,0,104,0,0,0,0,233,224,255,255,255,255,37,10,12,32,0,104,1,0,0,0,233,208,255,255,255,255,37,210,11,32,0,102,144,0,0,0,0,0,0,0,0,49,237,73,137,209,94,72,137,226,72,131,228,240,80,84,73,199,192,176,5,64,0,72,199,193,64,5,64,0,72,199,199,38,5,64,0,232,183,255,255,255,244,102,15,31,68,0,0,184,63,16,96,0,85,72,45,56,16,96,0,72,131,248,14,72,137,229,118,27,184,0,0,0,0,72,133,192,116,17,93,191,56,16,96,0,255,224,102,15,31,132,0,0,0,0,0,93,195,15,31,64,0,102,46,15,31,132,0,0,0,0,0,190,56,16,96,0,85,72,129,238,56,16,96,0,72,193,254,3,72,137,229,72,137,240,72,193,232,63,72,1,198,72,209,254,116,21,184,0,0,0,0,72,133,192,116,11,93,191,56,16,96,0,255,224,15,31,0,93,195,102,15,31,68,0,0,128,61,81,11,32,0,0,117,17,85,72,137,229,232,110,255,255,255,93,198,5,62,11,32,0,1,243,195,15,31,64,0,191,32,14,96,0,72,131,63,0,117,5,235,147,15,31,0,184,0,0,0,0,72,133,192,116,241,85,72,137,229,255,208,93,233,122,255,255,255,85,72,137,229,191,196,5,64,0,184,0,0,0,0,232,199,254,255,255,184,0,0,0,0,93,195,65,87,65,86,65,137,255,65,85,65,84,76,141,37,190,8,32,0,85,72,141,45,190,8,32,0,83,73,137,246,73,137,213,76,41,229,72,131,236,8,72,193,253,3,232,87,254,255,255,72,133,237,116,32,49,219,15,31,132,0,0,0,0,0,76,137,234,76,137,246,68,137,255,65,255,20,220,72,131,195,1,72,57,235,117,234,72,131,196,8,91,93,65,92,65,93,65,94,65,95,195,144,102,46,15,31,132,0,0,0,0,0,243,195,0,0,72,131,236,8,72,131,196,8,195,0,0,0,1,0,2,0,72,101,108,108,111,44,32,87,111,114,108,100,33,0,0,0,1,27,3,59,48,0,0,0,5,0,0,0,28,254,255,255,124,0,0,0,92,254,255,255,76,0,0,0,82,255,255,255,164,0,0,0,108,255,255,255,196,0,0,0,220,255,255,255,12,1,0,0,20,0,0,0,0,0,0,0,1,122,82,0,1,120,16,1,27,12,7,8,144,1,7,16,20,0,0,0,28,0,0,0,8,254,255,255,42,0,0,0,0,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,1,122,82,0,1,120,16,1,27,12,7,8,144,1,0,0,36,0,0,0,28,0,0,0,152,253,255,255,48,0,0,0,0,14,16,70,14,24,74,15,11,119,8,128,0,63,26,59,42,51,36,34,0,0,0,0,28,0,0,0,68,0,0,0,166,254,255,255,26,0,0,0,0,65,14,16,134,2,67,13,6,85,12,7,8,0,0,0,68,0,0,0,100,0,0,0,160,254,255,255,101,0,0,0,0,66,14,16,143,2,66,14,24,142,3,69,14,32,141,4,66,14,40,140,5,72,14,48,134,6,72,14,56,131,7,77,14,64,114,14,56,65,14,48,65,14,40,66,14,32,66,14,24,66,14,16,66,14,8,0,20,0,0,0,172,0,0,0,200,254,255,255,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,2,0,0,0,0,0,0,0,48,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,23,0,0,0,0,0,0,0,152,3,64,0,0,0,0,0,7,0,0,0,0,0,0,0,128,3,64,0,0,0,0,0,8,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,9,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,254,255,255,111,0,0,0,0,96,3,64,0,0,0,0,0,255,255,255,111,0,0,0,0,1,0,0,0,0,0,0,0,240,255,255,111,0,0,0,0,88,3,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,14,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,4,64,0,0,0,0,0,22,4,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,67,67,58,32,40,85,98,117,110,116,117,32,53,46,52,46,48,45,54,117,98,117,110,116,117,49,126,49,54,46,48,52,46,49,49,41,32,53,46,52,46,48,32,50,48,49,54,48,54,48,57,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,1,0,56,2,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,2,0,84,2,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,3,0,116,2,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,4,0,152,2,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,5,0,184,2,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,6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,0,0,0,0,0,0,0,0,0,1,0,0,0,4,0,241,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,1,0,21,0,32,14,96,0,0,0,0,0,0,0,0,0,0,0,0,0,25,0,0,0,2,0,14,0,96,4,64,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,2,0,14,0,160,4,64,0,0,0,0,0,0,0,0,0,0,0,0,0,46,0,0,0,2,0,14,0,224,4,64,0,0,0,0,0,0,0,0,0,0,0,0,0,68,0,0,0,1,0,26,0,56,16,96,0,0,0,0,0,1,0,0,0,0,0,0,0,83,0,0,0,1,0,20,0,24,14,96,0,0,0,0,0,0,0,0,0,0,0,0,0,122,0,0,0,2,0,14,0,0,5,64,0,0,0,0,0,0,0,0,0,0,0,0,0,134,0,0,0,1,0,19,0,16,14,96,0,0,0,0,0,0,0,0,0,0,0,0,0,165,0,0,0,4,0,241,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,4,0,241,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,178,0,0,0,1,0,18,0,248,6,64,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,1,0,21,0,32,14,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,241,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,204,0,0,0,0,0,19,0,24,14,96,0,0,0,0,0,0,0,0,0,0,0,0,0,221,0,0,0,1,0,22,0,40,14,96,0,0,0,0,0,0,0,0,0,0,0,0,0,230,0,0,0,0,0,19,0,16,14,96,0,0,0,0,0,0,0,0,0,0,0,0,0,249,0,0,0,0,0,17,0,212,5,64,0,0,0,0,0,0,0,0,0,0,0,0,0,12,1,0,0,1,0,24,0,0,16,96,0,0,0,0,0,0,0,0,0,0,0,0,0,34,1,0,0,18,0,14,0,176,5,64,0,0,0,0,0,2,0,0,0,0,0,0,0,50,1,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,138,1,0,0,32,0,25,0,40,16,96,0,0,0,0,0,0,0,0,0,0,0,0,0,78,1,0,0,16,0,25,0,56,16,96,0,0,0,0,0,0,0,0,0,0,0,0,0,44,1,0,0,18,0,15,0,180,5,64,0,0,0,0,0,0,0,0,0,0,0,0,0,85,1,0,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,105,1,0,0,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,136,1,0,0,16,0,25,0,40,16,96,0,0,0,0,0,0,0,0,0,0,0,0,0,149,1,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,164,1,0,0,17,2,25,0,48,16,96,0,0,0,0,0,0,0,0,0,0,0,0,0,177,1,0,0,17,0,16,0,192,5,64,0,0,0,0,0,4,0,0,0,0,0,0,0,192,1,0,0,18,0,14,0,64,5,64,0,0,0,0,0,101,0,0,0,0,0,0,0,216,0,0,0,16,0,26,0,64,16,96,0,0,0,0,0,0,0,0,0,0,0,0,0,142,1,0,0,18,0,14,0,48,4,64,0,0,0,0,0,42,0,0,0,0,0,0,0,208,1,0,0,16,0,26,0,56,16,96,0,0,0,0,0,0,0,0,0,0,0,0,0,220,1,0,0,18,0,14,0,38,5,64,0,0,0,0,0,26,0,0,0,0,0,0,0,225,1,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,245,1,0,0,17,2,25,0,56,16,96,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,202,1,0,0,18,0,11,0,200,3,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,99,114,116,115,116,117,102,102,46,99,0,95,95,74,67,82,95,76,73,83,84,95,95,0,100,101,114,101,103,105,115,116,101,114,95,116,109,95,99,108,111,110,101,115,0,95,95,100,111,95,103,108,111,98,97,108,95,100,116,111,114,115,95,97,117,120,0,99,111,109,112,108,101,116,101,100,46,55,53,57,52,0,95,95,100,111,95,103,108,111,98,97,108,95,100,116,111,114,115,95,97,117,120,95,102,105,110,105,95,97,114,114,97,121,95,101,110,116,114,121,0,102,114,97,109,101,95,100,117,109,109,121,0,95,95,102,114,97,109,101,95,100,117,109,109,121,95,105,110,105,116,95,97,114,114,97,121,95,101,110,116,114,121,0,72,101,108,108,111,87,111,114,108,100,46,99,0,95,95,70,82,65,77,69,95,69,78,68,95,95,0,95,95,74,67,82,95,69,78,68,95,95,0,95,95,105,110,105,116,95,97,114,114,97,121,95,101,110,100,0,95,68,89,78,65,77,73,67,0,95,95,105,110,105,116,95,97,114,114,97,121,95,115,116,97,114,116,0,95,95,71,78,85,95,69,72,95,70,82,65,77,69,95,72,68,82,0,95,71,76,79,66,65,76,95,79,70,70,83,69,84,95,84,65,66,76,69,95,0,95,95,108,105,98,99,95,99,115,117,95,102,105,110,105,0,95,73,84,77,95,100,101,114,101,103,105,115,116,101,114,84,77,67,108,111,110,101,84,97,98,108,101,0,95,101,100,97,116,97,0,112,114,105,110,116,102,64,64,71,76,73,66,67,95,50,46,50,46,53,0,95,95,108,105,98,99,95,115,116,97,114,116,95,109,97,105,110,64,64,71,76,73,66,67,95,50,46,50,46,53,0,95,95,100,97,116,97,95,115,116,97,114,116,0,95,95,103,109,111,110,95,115,116,97,114,116,95,95,0,95,95,100,115,111,95,104,97,110,100,108,101,0,95,73,79,95,115,116,100,105,110,95,117,115,101,100,0,95,95,108,105,98,99,95,99,115,117,95,105,110,105,116,0,95,95,98,115,115,95,115,116,97,114,116,0,109,97,105,110,0,95,74,118,95,82,101,103,105,115,116,101,114,67,108,97,115,115,101,115,0,95,95,84,77,67,95,69,78,68,95,95,0,95,73,84,77,95,114,101,103,105,115,116,101,114,84,77,67,108,111,110,101,84,97,98,108,101,0,0,46,115,121,109,116,97,98,0,46,115,116,114,116,97,98,0,46,115,104,115,116,114,116,97,98,0,46,105,110,116,101,114,112,0,46,110,111,116,101,46,65,66,73,45,116,97,103,0,46,110,111,116,101,46,103,110,117,46,98,117,105,108,100,45,105,100,0,46,103,110,117,46,104,97,115,104,0,46,100,121,110,115,121,109,0,46,100,121,110,115,116,114,0,46,103,110,117,46,118,101,114,115,105,111,110,0,46,103,110,117,46,118,101,114,115,105,111,110,95,114,0,46,114,101,108,97,46,100,121,110,0,46,114,101,108,97,46,112,108,116,0,46,105,110,105,116,0,46,112,108,116,46,103,111,116,0,46,116,101,120,116,0,46,102,105,110,105,0,46,114,111,100,97,116,97,0,46,101,104,95,102,114,97,109,101,95,104,100,114,0,46,101,104,95,102,114,97,109,101,0,46,105,110,105,116,95,97,114,114,97,121,0,46,102,105,110,105,95,97,114,114,97,121,0,46,106,99,114,0,46,100,121,110,97,109,105,99,0,46,103,111,116,46,112,108,116,0,46,100,97,116,97,0,46,98,115,115,0,46,99,111,109,109,101,110,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0,56,2,64,0,0,0,0,0,56,2,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,35,0,0,0,7,0,0,0,2,0,0,0,0,0,0,0,84,2,64,0,0,0,0,0,84,2,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,49,0,0,0,7,0,0,0,2,0,0,0,0,0,0,0,116,2,64,0,0,0,0,0,116,2,0,0,0,0,0,0,36,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,0,0,0,246,255,255,111,2,0,0,0,0,0,0,0,152,2,64,0,0,0,0,0,152,2,0,0,0,0,0,0,28,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112,16,0,0,0,0,0,0,72,6,0,0,0,0,0,0,30,0,0,0,47,0,0,0,8,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,9,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,184,22,0,0,0,0,0,0,27,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
// if running on Windows, then add .exe extension at the back
babyProgramFileName := "helloworld"
file, err := os.Create(babyProgramFileName)
handleError(err)
fmt.Println("Giving birth to " + babyProgramFileName + " now!!")
ioutil.WriteFile(babyProgramFileName, miniProgram, os.ModeAppend)
// remember to close the new file
// otherwise, you will get this error message during runtime
// panic: fork/exec ./helloworld: text file busy
file.Close()
fmt.Println("Changing the permission to executable")
err = os.Chmod(babyProgramFileName, 0777)
handleError(err)
fmt.Println("Executing the baby program and capture the output")
cmd := exec.Command("./"+babyProgramFileName)
out, err := cmd.Output()
handleError(err)
fmt.Println(string(out))
}
Output:
Giving birth to helloworld now!!
Changing the permission to executable
Executing the baby program and capture the output
Hello, World!
References :
https://en.wikipedia.org/wiki/Shellcode
https://www.socketloop.com/tutorials/golang-embed-secret-text-string-into-binary-executable-file
https://socketloop.com/tutorials/convert-file-content-into-array-of-bytes-in-go
https://www.socketloop.com/tutorials/golang-capture-text-return-from-exec-function-example
See also : Golang : Convert an executable file into []byte example
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+15.2k Golang : invalid character ',' looking for beginning of value
+40.7k Golang : How to check if a string contains another sub-string?
+4.9k Golang : Display packages names during compilation
+7.6k Golang : Lock executable to a specific machine with unique hash of the machine
+7.1k Golang : File system scanning
+7.7k Golang : Gomobile init produce "iphoneos" cannot be located error
+9.5k Golang : Load ASN1 encoded DSA public key PEM file example
+5.2k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+26.1k Golang : Calculate future date with time.Add() function
+17.6k Golang : Qt image viewer example
+13.3k Facebook PHP getUser() returns 0
+5.8k Golang : Compound interest over time example