-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b655d36
commit 476ccbb
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |