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
}

View file

@ -1,6 +0,0 @@
#ifndef SYSTEM_STD_BOOL_H
#define SYSTEM_STD_BOOL_H
typedef char bool;
#endif

View file

@ -1,17 +0,0 @@
#ifndef SYSTEM_STD_INT_H
#define SYSTEM_STD_INT_H
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef int32_t ptrdiff_t;
typedef uint32_t uintptr_t;
typedef int32_t intptr_t;
#endif

View file

@ -79,6 +79,7 @@ loop:
arrsize *= int32(t.Len())
case cc.Function:
s = "void*" + s
break loop
default:
s = t.Kind().String() + s
break loop
@ -114,6 +115,10 @@ func (profile *Profile) generate_x64dbg_types() (err error) {
}
cc_sources := []cc.Source{
cc.Source{
Name: "pch.h",
Value: `#define BINANA_GENERATOR 1\n`,
},
cc.Source{
Name: filepath.Join(profile.Directory, "include", "main.h"),
},
@ -155,10 +160,10 @@ func (profile *Profile) generate_x64dbg_types() (err error) {
for _, node := range scope {
if declarator, ok := node.(*cc.Declarator); ok {
if declarator.IsTypedefName {
if declarator.Type().Kind() != cc.Struct {
var x64_type x64dbg.AliasType = cc_type_to_typedef(declarator.Type())
x64_type.Name = scope_id.String()
if !slices.Contains(ignore_types, x64_type.Name) {
var x64_type x64dbg.AliasType = cc_type_to_typedef(declarator.Type())
x64_type.Name = scope_id.String()
if !slices.Contains(ignore_types, x64_type.Name) {
if x64_type.Name != x64_type.Type {
x64_types.Types = append(x64_types.Types, x64_type)
}
}