Skip to content

Commit

Permalink
fix: allow IDA Pro cmds using diaphora to not require a DB path
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Apr 9, 2024
1 parent 5dfef8e commit d68424c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions cmd/ipsw/cmd/dyld/dyld_ida.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ var idaCmd = &cobra.Command{
log.Warnf("will only load dependancies for first dylib (%s)", args[1])
} else if viper.IsSet("dyld.ida.diaphora-db") && !viper.IsSet("dyld.ida.script") {
return fmt.Errorf("must supply '--script /path/to/diaphora.py' with '--diaphora-db /path/to/diaphora.db'")
} else if viper.IsSet("dyld.ida.diaphora-db") && viper.GetBool("dyld.ida.enable-gui") {
return fmt.Errorf("cannot use '--diaphora-db' with '--enable-gui'")
} else if (viper.IsSet("dyld.ida.diaphora-db") || strings.Contains(scriptFile, "diaphora.py")) && viper.GetBool("dyld.ida.enable-gui") {
return fmt.Errorf("diaphora analysis should be done headless and NOT with '--enable-gui'")
}

if viper.GetString("dyld.ida.slide") != "" {
Expand Down Expand Up @@ -264,9 +264,13 @@ var idaCmd = &cobra.Command{
dbFile = filepath.Join(folder, fmt.Sprintf("DSC_%s_%s_%s.i64", args[1], f.Headers[f.UUID].Platform, f.Headers[f.UUID].OsVersion))
}

if viper.IsSet("dyld.ida.diaphora-db") {
if viper.IsSet("dyld.ida.diaphora-db") || strings.Contains(scriptFile, "diaphora.py") {
env = append(env, "DIAPHORA_AUTO=1")
env = append(env, fmt.Sprintf("DIAPHORA_EXPORT_FILE=%s", viper.GetString("dyld.ida.diaphora-db")))
if viper.IsSet("dyld.ida.diaphora-db") {
env = append(env, fmt.Sprintf("DIAPHORA_EXPORT_FILE=%s", viper.GetString("dyld.ida.diaphora-db")))
} else {
env = append(env, fmt.Sprintf("DIAPHORA_EXPORT_FILE=%s", filepath.Join(folder, fmt.Sprintf("DSC_%s_%s_%s_diaphora.db", args[1], f.Headers[f.UUID].Platform, f.Headers[f.UUID].OsVersion))))
}
}

if len(logFile) > 0 {
Expand Down
12 changes: 8 additions & 4 deletions cmd/ipsw/cmd/kernel/kernel_ida.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ var kernelIdaCmd = &cobra.Command{
return fmt.Errorf("cannot use '--temp-db' and '--delete-db'")
} else if viper.IsSet("kernel.ida.diaphora-db") && !viper.IsSet("kernel.ida.script") {
return fmt.Errorf("must supply '--script /path/to/diaphora.py' with '--diaphora-db /path/to/diaphora.db'")
} else if viper.IsSet("kernel.ida.diaphora-db") && viper.GetBool("kernel.ida.enable-gui") {
return fmt.Errorf("cannot use '--diaphora-db' with '--enable-gui'")
} else if (viper.IsSet("kernel.ida.diaphora-db") || strings.Contains(scriptFile, "diaphora.py")) && viper.GetBool("kernel.ida.enable-gui") {
return fmt.Errorf("diaphora analysis should be done headless and NOT with '--enable-gui'")
}
// if viper.GetString("kernel.ida.slide") != "" { TODO: how to set kc slide?
// env = append(env, fmt.Sprintf("IDA_kernel_SHARED_CACHE_SLIDE=%s", viper.GetString("kernel.ida.slide")))
Expand Down Expand Up @@ -166,9 +166,13 @@ var kernelIdaCmd = &cobra.Command{
dbFile = filepath.Join(folder, fmt.Sprintf("KC_%s_%s_%s.i64", device, m.SubCPU.String(m.CPU), args[1]))
}

if viper.IsSet("kernel.ida.diaphora-db") {
if viper.IsSet("kernel.ida.diaphora-db") || strings.Contains(scriptFile, "diaphora.py") {
env = append(env, "DIAPHORA_AUTO=1")
env = append(env, fmt.Sprintf("DIAPHORA_EXPORT_FILE=%s", viper.GetString("kernel.ida.diaphora-db")))
if viper.IsSet("kernel.ida.diaphora-db") {
env = append(env, fmt.Sprintf("DIAPHORA_EXPORT_FILE=%s", viper.GetString("kernel.ida.diaphora-db")))
} else {
env = append(env, fmt.Sprintf("DIAPHORA_EXPORT_FILE=%s", filepath.Join(folder, fmt.Sprintf("KC_%s_%s_%s_diaphora.db", device, m.SubCPU.String(m.CPU), args[1]))))
}
}

if len(logFile) > 0 {
Expand Down

0 comments on commit d68424c

Please sign in to comment.