Hex-Rays' blog

When choosers invade forms – Hex Rays

Written by   Daniel Pistelli | Feb 17, 2011

With the upcoming IDA 6.1 it will be possible to create forms which host chooser controls. This feature will be available in the Qt and text version (not so in the VCL one).



While this may not be important news, it is part of our effort to make the components of IDA Pro communicate even more among each other.
The plugin sample which demonstrates this new feature is called formchooser.
static void idaapi run(int)
{
  static const char form[] =
    "STARTITEM 0\n"
    "Form with choosers\n\n"
    "%/"
    "Select an item in the main chooser:\n"
    "\n"
    "
 
  
   \n\n" "
   
    \n" "\n"; chooser_info_t main_chi = { sizeof(chooser_info_t), CH_NOIDB, // flags (doesn't need an open database) 0, 0, // width, height NULL, //title NULL, // obj qnumber(header), // columns widths, icon_id, // icon 0, // deflt NULL, // popup_names main_choose_sizer, main_choose_getl, NULL, // del NULL, // ins NULL, // update NULL, // edit NULL, // enter NULL, // destroyer NULL // get_icon }; chooser_info_t aux_chi = main_chi; aux_chi.flags |= CH_MULTI; aux_chi.sizer = aux_choose_sizer; aux_chi.getl = aux_choose_getl; intvec_t main_sel, aux_sel; char str[MAXSTR] = {0}; // default selection for the main chooser main_sel.push_back(main_current_index); if ( AskUsingForm_c(form, modcb, &main_chi, &main_sel, &aux_chi, &aux_sel, str) > 0 ) { msg("Selection: %s\n", str); } }
   
  
 

The new tag introduced in the forms syntax is the letter E. As you can see, it is mostly a matter of filling the chooser_info_t structure with the same fields which you would pass to the choose2 function. Other than this structure, a intvec_t class has to be passed for every chooser. The intvec_t will specify the initial selection and return the final one.
For those of you who noticed the smiley icon and wonder what that is all about: it is now possible to load custom icons in idaq and to display them in the chooser. Three new APIs have been introduced for this task:

int load_custom_icon(const char *file_name);
int load_custom_icon(const void *ptr, unsigned int len, const char *format);
void free_custom_icon(int icon_id);

The icon can be loaded from file or memory. In the latter case, it is necessary to specify the format (say “png” or “jpg”). The “load” functions return an icon id which can be used in the chooser. If the icon is not freed with free_custom_icon, it will be automatically released when IDA terminates.