question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

createLabel doesn't set a new label as the primary label on a function

See original GitHub issue

Describe the bug When using the default createLabel method exposed to the python api, it will not correctly set the new label as the primary label even if True is passed for makePrimary on a function. It does seem to work at any other point in the listing.

To Reproduce Steps to reproduce the issue:

  1. use the cursor to select a the beginning of a function at a “FUN_***”

  2. open the python console

  3. type createLabel(currentAddress, "test", True)

  4. In listing, see the new label for the function name and that it is primary

  5. go back to console and type createLabel(currentAddress, "next", True)

  6. In listing, see the old label is still the primary label

  7. go to any other point in the function, repeat 3-5

  8. see that “next” is now the primary label (expected behavior I think)

Expected behavior Make the new label the primary label

Environment (please complete the following information):

  • OS: Windows 10 x64
  • Java Version: openjdk 11.0.2
  • Ghidra Version: 9.0 and 9.0.1

Additional context I can edit the new label I’ve created and manually change it to be the primary label by clicking the box. Maybe I’m just doing something wrong. Thanks for any help.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
GhidraKnightcommented, Apr 1, 2019

There’s several ways to accomplish it via the Ghidra API. Try invoking the SetLabelPrimaryCmd. This command will handle setting a label to primary, and it handles the case where you want to change the function name.

Command command= new SetLabelPrimaryCmd( address, name, namespace ) command.applyTo( currentProgram );

The “name” parameter needs to already exist as a label/symbol.

1reaction
GhidraKnightcommented, Apr 1, 2019

Sorry for the confusion. This behavior is as-designed; functions are special case labels(symbols). In order to change the name of a function, you must get the function object at the current address and call setName(). Will try to update the javadoc to reflect this case.

Function fun = getFunctionAt(currentAddress) if ( fun == null ) createLabel(…) else fun.setName(…)

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create labels to organize Gmail - Computer - Google Support
Create a label · On your computer, go to Gmail. · On the left, scroll down, then click More. · Click Create new...
Read more >
How to Use Labels (The Java™ Tutorials > Creating a GUI ...
How to Use Labels. With the JLabel class, you can display unselectable text and images. If you need to create a component that...
Read more >
Labels - GitLab Docs
On the top bar, select Main menu > Projects and find your project. ... You can also create a new project label from...
Read more >
Create a label using jQuery on the fly - Stack Overflow
Something like this would work: //Create the label element var $label = $("<label>").text('Date:'); //Create the input element var $input ...
Read more >
How to Create Labels in Gmail (Gmail Tips & Tricks) - YouTube
How to Create Labels in Gmail (Gmail Tips & Tricks)Track your emails for free, with MailTag ➜ https://www.MailTag.ioIn today's video, Blake ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found