feat(binana): no special include directories now, you must pass GHIDRA or IDA as a definition into your preprocessor

This commit is contained in:
phaneron 2024-08-09 07:15:03 -04:00
parent de5bdadc78
commit 1042d9fa22
60 changed files with 3132 additions and 589 deletions

View file

@ -12,49 +12,62 @@ import (
func (profile *Profile) generate_symbols_idc() (err error) {
var (
output_file *os.File
f *os.File
)
output_file, err = os.Create(filepath.Join(profile.Directory, "ida", "import.idc"))
f, err = os.Create(filepath.Join(profile.Directory, "ida", "import_symbols.idc"))
if err != nil {
return
}
fmt.Fprintf(output_file, "#include <idc.idc>\n")
fmt.Fprintf(output_file, "\n")
fmt.Fprintf(output_file, "static main() {\n")
fmt.Fprintf(output_file, " // Make names\n")
fmt.Fprintf(f, "#include <idc.idc>\n")
fmt.Fprintf(f, "\n")
fmt.Fprintf(f, "#include \"import_data_types.idc\"\n")
fmt.Fprintf(f, "static main() {\n")
fmt.Fprintf(f, " // Make names\n")
for _, symbol := range profile.SymbolTable.Entries {
quoted_name := strconv.Quote(symbol.Name)
address := fmt.Sprintf("0x%08X", symbol.StartAddress)
fmt.Fprintf(output_file, " set_name(%s, %s);\n", address, quoted_name)
fmt.Fprintf(f, " set_name(%s, %s);\n", address, quoted_name)
}
fmt.Fprintf(output_file, " // Make functions\n")
fmt.Fprintf(f, " // Make functions\n")
for _, function_symbol := range profile.SymbolTable.Entries {
if function_symbol.Kind == symfile.Function {
address := fmt.Sprintf("0x%08X", function_symbol.StartAddress)
fmt.Fprintf(output_file, " set_func_start(%s, %s);\n", address, address)
fmt.Fprintf(f, " set_func_start(%s, %s);\n", address, address)
if function_symbol.EndAddress != 0 {
end_address := fmt.Sprintf("0x%08X", function_symbol.EndAddress)
fmt.Fprintf(output_file, " set_func_end(%s, %s);\n", address, end_address)
fmt.Fprintf(f, " set_func_end(%s, %s);\n", address, end_address)
}
}
}
fmt.Fprintf(output_file, " // Apply data types\n")
fmt.Fprintf(f, " // Apply data types\n")
fmt.Fprintf(f, " import_data_types();\n")
fmt.Fprintf(f, "}\n")
f.Close()
f, err = os.Create(filepath.Join(profile.Directory, "ida", "import_data_types.idc"))
if err != nil {
return
}
fmt.Fprintf(f, "#include <idc.idc>\n")
fmt.Fprintf(f, "\n")
fmt.Fprintf(f, "static import_data_types() {\n")
for _, symbol := range profile.SymbolTable.Entries {
if symbol.DataType != "" {
quoted_data_type := strconv.Quote(symbol.DataType)
address := fmt.Sprintf("0x%08X", symbol.StartAddress)
fmt.Fprintf(output_file, " apply_type(%s, %s);\n", address, quoted_data_type)
fmt.Fprintf(f, " apply_type(%s, %s);\n", address, quoted_data_type)
}
}
fmt.Fprintf(output_file, "}\n")
fmt.Fprintf(f, "}\n")
output_file.Close()
return
}