Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHovious committed Jun 9, 2017
1 parent b655d36 commit 476ccbb
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# bin2hex
# bin2hex

A very simple utility to read an input file and output a hexfile in the format of `\x00`.
46 changes: 46 additions & 0 deletions bin2hex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"bytes"
"encoding/hex"
"fmt"
"io/ioutil"
"os"
)

func insertNth(s string, n int) string {
var buffer bytes.Buffer
buffer.WriteRune('\\')
buffer.WriteRune('x')
var n1 = n - 1
var l1 = len(s) - 1
for i, rune := range s {
buffer.WriteRune(rune)
if i%n == n1 && i != l1 {
buffer.WriteRune('\\')
buffer.WriteRune('x')
}
}
return buffer.String()
}

func main() {
argsWithoutProg := os.Args[1:]
if len(argsWithoutProg) != 2 {
fmt.Println("[!] Should only have two arguments!")
os.Exit(0)
}
bytes, err := ioutil.ReadFile(argsWithoutProg[0])
if err != nil {
fmt.Println("[!] Error reading file")
os.Exit(0)
}
binStr := hex.EncodeToString(bytes)
hexBytes := []byte(insertNth(binStr, 2))

err = ioutil.WriteFile(argsWithoutProg[1], hexBytes, 0644)
if err != nil {
fmt.Println("[+] Successfully wrote out file")
}

}
52 changes: 52 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Replace demo with your desired executable name
appname := bin2hex

sources := $(wildcard *.go)

build = GOOS=$(1) GOARCH=$(2) go build -o build/$(appname)$(3)
tar = cd build && tar -cvzf $(1)_$(2).tar.gz $(appname)$(3) && rm $(appname)$(3)
zip = cd build && zip $(1)_$(2).zip $(appname)$(3) && rm $(appname)$(3)

.PHONY: all windows darwin linux clean

all: windows darwin linux

clean:
rm -rf build/

##### LINUX BUILDS #####
linux: build/linux_arm.tar.gz build/linux_arm64.tar.gz build/linux_386.tar.gz build/linux_amd64.tar.gz

build/linux_386.tar.gz: $(sources)
$(call build,linux,386,)
$(call tar,linux,386)

build/linux_amd64.tar.gz: $(sources)
$(call build,linux,amd64,)
$(call tar,linux,amd64)

build/linux_arm.tar.gz: $(sources)
$(call build,linux,arm,)
$(call tar,linux,arm)

build/linux_arm64.tar.gz: $(sources)
$(call build,linux,arm64,)
$(call tar,linux,arm64)

##### DARWIN (MAC) BUILDS #####
darwin: build/darwin_amd64.tar.gz

build/darwin_amd64.tar.gz: $(sources)
$(call build,darwin,amd64,)
$(call tar,darwin,amd64)

##### WINDOWS BUILDS #####
windows: build/windows_386.zip build/windows_amd64.zip

build/windows_386.zip: $(sources)
$(call build,windows,386,.exe)
$(call zip,windows,386,.exe)

build/windows_amd64.zip: $(sources)
$(call build,windows,amd64,.exe)
$(call zip,windows,amd64,.exe)

0 comments on commit 476ccbb

Please sign in to comment.