// Copyright 2011-2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package security.bindiff;

option java_package = "com.google.security.zynamics.bindiff";
option java_outer_classname = "BinDiffProtos";

message Config {
  // Next id: 14

  // Configuration version. Should be at least "7" for proto based configuration
  // files.
  int32 version = 1;

  // The BinDiff installation directory.
  // Directory layout on Linux and Windows:
  //   <directory>/bin      (BinDiff binaries, bindiff.jar)
  //   <directory>/jre      (Bundled JRE)
  //   <directory>/libexec  (Linux: location of bindiff_config_setup)
  //
  // On macOS, BinDiff uses an application bundle with a different directory
  // layout rooted in "bundle_dir", with "directory" below it:
  //   <bundle_dir>/Contents/app                    (bindiff.jar)
  //   <bundle_dir>/Contents/MacOS                  <directory>
  //   <bundle_dir>/Contents/MacOS/bin              (BinDiff binaries)
  //   <bundle_dir>/Contents/MacOS/BinDiff          (Launcher)
  //   <bundle_dir>/Contents/runtime/Contents/Home  (Bundled JRE)
  string directory = 2;

  message UiLaunchOptions {
    // The java executable used to start the UI. If empty, BinDiff will try to
    // auto-detect a suitable JVM.
    string java_binary = 1;

    // Additional Java VM arguments
    repeated string java_vm_option = 2;

    // Maximum heap size for the Java VM. If set to zero, 75% of physical RAM
    // will be set.
    int32 max_heap_size_mb = 3;

    // Local IP address and port where the UI should listen on to serve visual
    // diff requests. If empty (or zero in case of port), "localhost" and port
    // 2000 will be used.
    string server = 4;
    int32 port = 5;

    // Number of times BinDiff should try to launch the UI.
    int32 retries = 6;
  }
  UiLaunchOptions ui = 3;

  message IdaProOptions {
    // The IDA Pro installation directory. If empty, the BinDiff plugin will
    // populate this field with the result of calling idadir(). The BinDiff
    // UI will simply ask the user.
    string directory = 1;

    // Whether to export IDA Pro databases using an x86/x86-64 specific
    // heuristic to determine whether a function returns. If unset, defaults
    // to "false".
    bool binexport_x86_noreturn_heuristic = 2;
  }
  IdaProOptions ida = 4;

  reserved 5, 6;  // Binary Ninja, Ghidra

  // How many BinDiff threads to use when batch-diffing. Use 0 or -1 for the
  // number of hardware threads present in the system.
  int32 num_threads = 7;

  message LogOptions {
    enum LogLevel {
      LOG_LEVEL_UNSPECIFIED = 0;
      DEBUG = 1;
      INFO = 2;
      WARNING = 3;
      ERROR = 4;
      OFF = 5;
    }

    // Minimum log level
    LogLevel level = 1;

    // Whether to write a log file
    bool to_file = 2;

    // Log into this directory. If empty, uses a path under the per-user
    // BinDiff directory (i.e. "~/.bindiff/logs").
    string directory = 3;

    // Whether to also log to standard error
    bool to_stderr = 4;
  }
  LogOptions log = 8;

  message BinaryFormatOptions {
    // Whether to include demangled function names in the binary database
    // format. The default is to include them.
    bool exclude_function_names = 1;
  }
  BinaryFormatOptions binary_format = 9;

  message MatchingStep {
    string name = 1;
    double confidence = 2;
  }
  // For documentation on the various algorithms, see the BinDiff manual
  // at https://zynamics.com/bindiff/manual/index.html#N2038E.
  // If empty, built-in settings will be used. Note that order matters and
  // duplicates will be ignored, keeping steps that were added first.
  repeated MatchingStep function_matching = 10;
  // See https://zynamics.com/bindiff/manual/index.html#N20496.
  // The comments for function_matching also apply here.
  repeated MatchingStep basic_block_matching = 11;

  message UiTheme {
    message ThemeFont {
      string family = 1;
      int32 size = 2;
    }

    // A color gradient for visualizing similarity. Should contain 256 colors.
    // All colors should be specified in the form of standard hex triplets:
    // #RRGGBB.
    repeated string similarity_ramp = 1;

    // Color for manually assigned matches. Not used by all disassembler
    // plugins/UIs.
    string manual_match = 2;

    // Colors for graph nodes
    string text = 3;
    string address = 4;
    string mnemonic = 5;
    string symbol = 6;
    string immediate = 7;
    string operator = 8;
    string register = 9;
    string size_prefix = 10;
    string dereference = 11;
    string operator_separator = 12;
    string stack_variable = 13;
    string global_variable = 14;
    string jump_label = 15;
    string function = 16;
    string comment = 17;

    // Color gradient for single graph windows
    repeated string background = 18;
    // Color gradient for the primary side of a graph match
    repeated string background_primary = 19;
    // Color gradient for the secondary side of a graph match
    repeated string background_secondary = 20;

    ThemeFont ui = 21;
    ThemeFont code = 22;
  }

  // Maps names to themes
  map<string, UiTheme> themes = 12;

  message UiPreferences {
    // Filename of the default workspace that BinDiff loads automatically.
    string default_workspace = 1;

    message HistoryOptions {
      string new_diff_primary_dir = 1;
      string new_diff_secondary_dir = 2;
      string directory_diff_primary_dir = 3;
      string directory_diff_secondary_dir = 4;
      string add_existing_diff_dir = 5;
      repeated string recent_workspace = 6;
    }
    HistoryOptions history = 2;

    message LayoutOptions {
      int32 x = 1;
      int32 y = 2;
      int32 width = 3;
      int32 height = 4;

      // Used to check for changes in screen resolution to avoid placing windows
      // of screen.
      int32 screen_width = 5;
      int32 screen_height = 6;

      bool maximized = 7;
      int32 divider_position = 8;
    }
    LayoutOptions layout = 3;

    string use_theme = 4;

    message GraphLayoutOptions {
      enum GraphLayout {
        GRAPH_LAYOUT_UNSPECIFIED = 0;
        HIERARCHICAL = 1;
        ORTHOGONAL = 2;
        CIRCULAR = 3;
      }
      GraphLayout layout = 1;
      bool auto_layout = 2;
      bool draw_bends = 3;

      // A value of 0 disables animations, 1-10 set the speed.
      int32 animation_speed = 4;

      enum LayoutOrientation {
        LAYOUT_ORIENTATION_UNSPECIFIED = 0;
        HORIZONTAL = 1;
        VERTICAL = 2;
      }

      message HierarchicalLayoutOptions {
        enum HierarchicalLayoutStyle {
          HIERARCHICAL_LAYOUT_STYLE_UNSPECIFIED = 0;
          DEFAULT = 1;
          ORTHOGONAL_EDGE_ROUTING = 2;
        }
        HierarchicalLayoutStyle style = 1;

        LayoutOrientation orientation = 2;
        int32 min_layer_distance = 4;
        int32 min_node_distance = 5;
      }
      HierarchicalLayoutOptions hierarchical_options = 5;

      message OrthogonalLayoutOptions {
        enum OrthogonalLayoutStyle {
          ORTHOGONAL_LAYOUT_STYLE_UNSPECIFIED = 0;
          DEFAULT = 1;
          TREE = 2;
        }
        OrthogonalLayoutStyle style = 1;

        LayoutOrientation orientation = 2;
        int32 min_node_distance = 3;
      }
      OrthogonalLayoutOptions orthogonal_options = 6;

      message CircularLayoutOptions {
        enum CircularLayoutStyle {
          CIRCULAR_LAYOUT_STYLE_UNSPECIFIED = 0;
          COMPACT = 1;
          ISOLATED = 2;
          SINGLE_CIRCLE = 3;
        }
        CircularLayoutStyle style = 1;

        int32 min_node_distance = 2;
      }
      CircularLayoutOptions circular_options = 7;

      message ProximityBrowsingOptions {
        bool enabled = 1;
        int32 auto_enable_threshold = 2;
        int32 child_depth = 3;
        int32 parent_depth = 4;
        int32 visibility_warn_threshold = 5;
      }
      ProximityBrowsingOptions proximity_browsing = 8;

      // Sensitivity steps range from 0 to 9
      int32 scroll_sensitivity = 9;
      bool show_scrollbars = 10;
      int32 zoom_sensitivity = 11;

      enum MouseWheelAction {
        MOUSE_WHEEL_ACTION_UNSPECIFIED = 0;
        ZOOM = 1;
        SCROLL = 2;
      }
      MouseWheelAction wheel_action = 12;

      bool view_synchronization = 13;
    }

    GraphLayoutOptions call_graph_options = 5;
    GraphLayoutOptions flow_graph_options = 6;

    message DebugOptions {
      bool show_debug_menu = 1;
      bool show_super_graph = 2;
    }

    // Debug settings. These are loaded by the UI, but modifications are not
    // written back.
    DebugOptions debug = 7;
  }
  UiPreferences preferences = 13;
}
