# Diffing & Merging

## IDA's diff mode

The IDA diff mode lets the user compare two databases, in a traditional "diff" fashion: essentially a two-panel window, showing the unmodified file on the left and the version with your changes on the right.

After performing reverse-engineering work on an IDA database, you can review the resulting changes using a special diff mode. To access it, right-click within the database and select Diff against… from the context menu.

## Diff and Merge Differences

It is important to note the difference between the terms "diff" and "merge".

Through the docs, these terms sometimes are used interchangeably. This is because to IDA, a diff is just a specialized merge. Both diffing and merging are handled by IDA's "merge mode", which involves up to 3 databases, one of which *can* be modified to contain the result of the merge.

A diff is simply a merge operation that involves only 2 databases, neither of which are modified.

This is why often times you will see the term "merge" used in the context of a diff. In this case "merge" is referring to IDA's "merge mode", rather than the process of merging multiple databases together into a combined database.

## Using IDA as a diffing tool

Performing a merge between two IDA databases is substantially different from, for example, merging two text files. A change in a chunk of text file will not have an impact on another chunk.

IDA databases are not so simple. A change in one place in an idb will often have an impact on another place. For example, if a structure `mystruct` changed between two databases, it will have an impact not only on the name of the structure, but on cross-references to structure members, function prototypes, etc.

This is why IDA's merge mode is split into a strict series of "steps":

![Progress steps](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-0686812363c3dc022e578c52e995f4fd27a53f63%2Fmerge_progress_steps.png?alt=media)

Within a single step it is possible to go forward & backward between different chunks. But because of possible inter-dependencies between steps, it is not possible to move backwards between steps, you can only go forward:

![Apply changes button](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-87fbc4697a4050263b1bf5162894850cd67cc950%2Fapply_button.png?alt=media)

Since IDA's diff mode is just a variation of its merge mode, diffing databases is also subject to this sequential application of steps in order to view certain bits of information. That is why, in some steps (e.g., the "Disassembly/Items") IDA might not report some changes that were performed at another level.

For instance, if a user marked a function as `noret`, the listings that will be shown in "Disassembly/Items" step, will not advertise that there was a change at that place (even though the `"Attributes: noreturn"` is visible in the left-hand listing), only the changes to the instructions (and data, ...) are visible in the current step:

![noret attribute missing](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-cee9e01b4d7d7b11bea1c83baf37ab79b8e24206%2Flistings_noret_not_visible.png?alt=media)

The change will, however, be visible at a later step (i.e., "Functions/Registry"):

![noret attribute visible](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-735240b029d9b5c54b6b1fcaab9a6aafb732955b%2Ffunctions_noret_visible.png?alt=media)

{% hint style="info" %}
The changes applied during the "diff" process are only temporary. Exiting IDA (at any moment) will not alter the files being compared.
{% endhint %}

{% hint style="info" %}
Learn more about merging steps [here](https://docs.hex-rays.com/user-guide/teams/concepts/merge-steps).
{% endhint %}

### Merging concurrent modifications (conflicts)

As with any collaborative tool, it may happen that two coworkers work on the same dataset (e.g., IDA database), and make modifications to the same areas, resulting in "conflicts". Conflicts must be "resolved" prior to committing.

![File in worklist requiring resolve](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-b7929ee5ab978356eaa12091605068882df7279b%2Fworklists_pending_resolve.png?alt=media)

To do that, right-click and pick one of the "resolve" options:

![The different resolve options](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-662a03ea67b3f7b2a965b2962e9c270cdd29bb39%2Fresolve_pp.png?alt=media)

IDA Teams provides the following merge strategies.

### Interactive merging

If the option that was chosen (e.g., [Interactive merge mode](https://docs.hex-rays.com/user-guide/how-tos/resolving-conflicts#interactive-merge-mode)) requires user interaction due to conflicts, IDA will show in 3-pane "merge" mode.

![IDA in interactive merge mode](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-b42889907a89ec6522b2b60ce070fb89e4ac4aeb%2Fida_interactive_merge.png?alt=media)

When a conflict is encountered, you'll have the ability to pick, for all conflicts, which change should be kept (yours, or the other). Every time you pick a change (and thus resolve a conflict), IDA will proceed with the merging, applying all the non-conflicting changes it can, until the next conflict - if any. When all conflicts are resolved, you can leave IDA, and the new resulting file is ready to be submitted.

### The "Progress" widget

![Diff progress](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-57448ac81efda52a11d3f76dd489bb7e22dff5cb%2Fida_in_diff_mode_diff_progress.png?alt=media)

Represents the current [step](#using-ida-as-a-diffing-tool) in the diff process.

### The left panel

![The left panel](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-7e1d885a0aad4560a997f41d7e4f1571322369b0%2Fida_in_diff_mode_left_panel.png?alt=media)

Shows the "untouched" version of the database (i.e., the one without your changes)

### The right panel

![The right panel](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-279238626f3751b2e7aaf91c7df2d7e1636119d3%2Fida_in_diff_mode_right_panel.png?alt=media)

Shows your version of the database (i.e., featuring your changes)

### Diff region details

![The details area](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-5b5980da0074f63ee11277ed31017de1c1760c8e%2Fida_in_diff_mode_panel_details.png?alt=media)

Notice how both panels have a little area at the bottom, that is labeled "Details".

Details are available on certain steps of the diffing process, and provide additional information about the change that is currently displayed.

### The "diffing" toolbar

![The diff toolbar](https://3899235193-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd4yKxBBBv1qcoSuL2US4%2Fuploads%2Fgit-blob-47536af3de9c988f44a28c9fab5f7b811edb86f6%2Fida_in_diff_mode_toolbar.png?alt=media)

The actions in the toolbar are:

* **Previous chunk**: Move to the previous change
* **Center chunk**: Re-center the panels to show the current chunk (useful if you navigated around to get more context)
* **Next chunk**: Move to the next change
* **Proceed to the next step**: Move to the next step [step](#using-ida-as-a-diffing-tool) in the diffing process
* **Toggle 'Details'**: Toggle the visibility of the "Details" widgets in the various panels (note that some steps do not provide details, so even if the "Details" are requested, they might not be currently visible)

Using actions in the toolbar, you can iterate through the differences between the two databases, with each change shown in context as if viewed through a normal IDA window.

## What's next?

* Ready to [Get Started](https://docs.hex-rays.com/user-guide/teams/getting-started)?
