A label is a name associated with an address. Labels are used to make code easier to read. For example, instead of "call 0x103f2d", the instruction might read "call printf". The name "printf" has been associated with the address "0x103f2d". In other words, the address "0x103f2d" has been labeled printf.
All labels have an assigned symbol name which has either explicitly been established or a default generated name. When assigning a label name (or any other namespace or symbol name) the following naming restrictions apply:
- Reserved Dynamic Name Pattern - certain dynamic name patterns are reserved for Ghidra use and may not be explicitly set. A dynamic pattern generally consists of a default prefix (SUB_, LAB_, DAT_, UNK_, EXT_, FUN_, OFF_) followed by an address (e.g., LAB_01234567).
- Space and Non-printable Characters Not Allowed - a blank space character or other non-printable ASCII character (e.g., backspace, linefeed, etc.) are not permitted within a name
- Length Limit of 2000 - the name length may not exceed 2000 characters/bytes
In addition to the above restrictions, the use of '::' within a label name may cause problems with certain name edit dialogs which may use this as a namespace separator.
Labels can be created or renamed by importing information, when auto-analysis is performed, or directly by the user. The label source indicates how the label was created or renamed.
- User Defined - Label name specified by the user.
- Imported - Label named during the import of the program or by some other imported information (for example, external libraries or C libraries.)
- Analysis - Label created by auto-analysis that do not have default names.
- Default - Label with a default name. (Ghidra generally creates default-named symbols at any address that is referenced by some other location.)
Some labels are automatically generated during disassembly. They use a standard naming convention to derive the symbolic name from the address. The current convention is to use a prefix that gives some information about what is at the address, followed by the address. For example, the automatic label generated for address "0x01234" would be "LAB_01234" if there is code at that address. If there was a data item at that address, the label would be "DAT_01234". Labels with auto-generated names are known as default labels. The importer, auto-analysis, or the user can also create labels (or rename default labels) using more meaningful names.
Default label prefixes can be any of the following:
The Add Label dialog and the Edit Label dialog are identical except for the title and the way the dialog's fields are initialized. The Add Label dialog will be filled in with suggested values for all fields. The Edit Label dialog, on the other hand will be filled in with the current values of the label being edited.
If you add a label where there is a function
with a default label name, the label you add will become the function's new name.
Enter Label
- Text field for entering the name of the label. A combo box is included which allows selecting recently used label names.
You may enter a namespace path in this text field that follows the format:
<namespace_name1>::<namespace_name2>::<...>::<label_text>For example, the following string denotes a full namespace path that starts at the Global namespace and ends at the label name myLabel:
Global::foo::bar::myLabelThe namespace in the Namespace combo box will be used as the parent namespace for the label name and any included namespaces. However, if the you provide a namespace path that starts with Global, then the value of the Namespace combo box will be ignored.Namespace
- The defining scope of the label. The available namespaces are based upon the current address. When editing a label, the available namespaces are not necessarily those in the namespace hierarchy in which the label is located, but rather are those based upon the address of that label. The Global namespace is always included by default, as well as the parent namespace of the current label, if one is being edited.
This field is disabled, if there is a function with a default name at this address. The namespace will stay set to the parent namespace of the function and the label name you enter will become the new function name.
Entry Point
- Sets the entry point property for address associated with this label. Setting this property on one symbol, changes it for all symbols at the same address.
Primary
- Sets the primary property for this symbol. If there is only one symbol at this address, the checkbox will be selected and disabled, since it must be primary. Whenever the checkbox is selected, it will be disabled because the only way to make a symbol become non-primary is to select another symbol at the same address and make it primary. This ensures that there will always be one label that is primary. If there is a function at this address and you add a new label, the checkbox will be enabled such that if you select the checkbox, the function is renamed to the new label that you entered. The function symbol must always be the primary symbol.
Pinned
- Sets the label to pinned. A pinned label will not move if the image base is changed or a memory block is moved. A label that is not pinned, will move with the code or data if a memory block is moved or the image base is changed. Also, a pinned label will not be removed if the memory block that contains it is removed. Only code, data, or function labels may be pinned.
Normally, the primary label is used to replace an address reference in the operand field of an instruction or data item. Ghidra allows users to change which symbol is used to replace the address using the Set Label dialog.
Label
The list in the combo box will show all symbols associated with the address shown in the dialog title. Choosing a label from the list will cause that symbol to be associated with the operand reference being modified. Typing in a new name will cause a new symbol to be created at the target address before associating it with the operand reference.
Adding a label will place a label at a particular address in a listing. Labels may be of any length but may not contain spaces. To add a label:
- Right-click and choose the Add Label menu option.
- Enter the name of the label in the text field (or accept the suggested default).
- Change any of the default options (see Label Dialog)
- Press the OK button.
Adding a label to an address where there is a function with a default name results in the function name becoming the new label name.
To change the name of a label or referenced label appearing in an operand:
- Right-click on the label, or referenced label appearing in an operand, then choose the Edit Label item from the popup menu.
- Enter the new name of the label in the text field in the Label dialog.
- Press the OK button.
If the label appearing in an operand corresponds to an external location the Edit Label action will be replaced by Edit External Location.
Similar to editing a label associated with the primary reference of an operand, an external location referenced by an operand may be renamed or modified. Right-click on the operand which references an external location and choose the Edit External Location menu option (see Symbol Tree - Edit External Location for more discussion on the use of the edit dialog).
Labels may or may not be eligible for removal depending on the following rules:
- Labels that have no references to them can always be removed.
- Labels at addresses that contain more than one label can always be removed.
- "Default" labels with at least one references and no other labels at that address can not be removed. (The menu option will be disabled.)
- "User-defined" labels with at least one reference and no other labels at that address can be removed, but will be replaced with a "default" label at that address.
- A "default" function label cannot be removed if there are no other labels at the address. To remove a "default" function label, you must remove the function itself.
- A "user-defined" function label can be removed. If there are no other labels at the address then the function label becomes a "default" label. If there are other labels at the address, one of these will become the new function label.
To remove a label:
- Right-click on the label to be removed and choose the Remove Label menu option.
Ghidra gives no confirmation on Remove Label. A status message is displayed if you try to remove a default function label.
A Namespace defines a scope, such that symbol names are unique within a namespace. The types of namespaces that Ghidra supports are Global, External, Function, Class, and Generic namespaces that reside in the global namespace.
To set the namespace:
- Right click on a symbol and choose the Edit Label menu option.
- Select a namespace from the namespace combo-box in the Label dialog. Or, you may enter a new namespace with the label using "::" as a name separator. If a specified namespace does not exist a simple-namespace will be created.
Any use of a class-namespace requires that it first be created prior to associating a label or other namespace with that class-namespace. This is most easily accomplished via the Symbol Tree
External Entry points can only be created at addresses that have at least one symbol. To set an external entry point:
- Right click on a symbol and choose the Edit Label menu option.
- Check the Entry Point checkbox in the Label dialog.
Making a label primary gives it priority over other labels that are associated with the same address. The primary label is displayed by other Ghidra features instead of the address. For example, in the subroutine view, the subroutine names are primary labels. If another label were added and made the primary label, then the subroutine view will display that label instead of the label bearing the subroutine name.
If a function exists at an address, its name is the primary label; if you set another label at this address to be primary, then the symbol for this label is removed, and the function is renamed to that label that you were editing. The function symbol must always be primary.To make a label primary:
- Right click on a symbol and choose the Edit Label menu option.
- Check the primary checkbox in the Label dialog.
Referenced labels appear in instruction operands. By default, the primary label associated with the primary reference from an operand will be displayed within the operand. To have the operand display a different label corresponding to the primary memory reference:
- Right click on the operand symbol and choose the Set Associated Label... menu option from the pop-up menu. This action only appears if the primary reference is a memory reference.
- Choose a label from the drop-down list on the Set Label dialog or type in a name for a new label that will appear at the referred-to address.
Provided by: the Edit Labels Plugin
You can show the history of changes on labels at a given address. You can also search the label history for all lables looking for old label names that no longer exist. Either way, a dialog is shown containing a table of lable changes. The "Action" column indicates whether the label was added, removed, or renamed. If the label was renamed, the "Label" column shows the old name renamed to the new name. The "User" is the user who made the change. The "Modification Date" is when the change was made. Labels that were added as a result of disassembly are not recorded in the history; however, if you rename a default label, you will see an entry in the table, as shown below.
A column for "Address" shows up in the table if you are viewing the history of changes on labels at all addresses.
To display the history of label changes at a specific address,
- Right mouse click on a label (either in the label field or the operand field).
- Choose the Show Label History option.
You can sort the label history by any of the columns and in ascending or descending order. By default, the history is sorted by ascending modification date (i.e., oldest date first). You can also reorder the columns by dragging the header to another column position.
To seach for label history for a past or present label name:
- Select SearchLabel History...
- A dialog is displayed so that you can enter a label name (or part of a label name)
- Enter a string you would like to see matches for.
- To display the label history for all the label changes, leave the field blank.
- Select the OK button or press the <Enter> key in the text field.
- If label history was found, a dialog similar to the one shown above is displayed with the addition of an "Address" column. The input dialog remains displayed if no label history was found.
- From the label history dialog, you can navigate to each address by clicking on the row in the table.
Provided by: the Edit Labels Plugin