Skip to content

Instantly share code, notes, and snippets.

@Tustin
Created June 15, 2017 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tustin/cd3dd1bd9ef90f229503d9a2288e1728 to your computer and use it in GitHub Desktop.
Save Tustin/cd3dd1bd9ef90f229503d9a2288e1728 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
"time"
)
type NativeJSON struct {
Name string `json:"name"`
Params []struct {
Type string `json:"type"`
Name string `json:"name"`
} `json:"params"`
Results string `json:"results"`
Jhash string `json:"jhash"`
Hash string `json:"hash"`
Namespace string `json:"namespace"`
}
var NativeJsonMap map[string]NativeJSON
var NativeAddresses map[string]string
var output []string
func main() {
start := time.Now()
//Make maps
NativeAddresses = make(map[string]string)
NativeJsonMap = make(map[string]NativeJSON)
//Parse json into map
file, _ := ioutil.ReadFile("./new.json")
json.Unmarshal(file, &NativeJsonMap)
output = append(output, "#include <idc.idc>\nstatic main()\n{\n")
file, _ = ioutil.ReadFile("./natives_dump.txt")
for _, line := range strings.Split(string(file), "\n") {
pieces := strings.Split(line, " : ")
hash, err := strconv.ParseUint(pieces[0], 0, 64)
if err != nil {
panic(err)
}
NativeAddresses[pieces[0]] = pieces[1]
original_hash := "0x" + strings.ToUpper(strconv.FormatUint(HASH_MAP[hash], 16))
original_native_data := NativeJsonMap[original_hash]
if original_native_data.Name == "" {
continue
}
output = append(output, fmt.Sprintf("\tMakeName(%s, \"%s\");\n", pieces[1], original_native_data.Name))
}
fmt.Printf("found %d natives\r\n", len(NativeAddresses))
new_file, _ := os.Create("output.idc")
defer new_file.Close()
w := bufio.NewWriter(new_file)
for _, line := range output {
fmt.Fprint(w, line)
}
elapsed := time.Since(start)
log.Printf("completed in %s\r\n", elapsed)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment