airbus-seclab / bincat

Binary code static analyser, with IDA integration. Performs value and taint analysis, type reconstruction, use-after-free and double-free detection
1.66k stars 159 forks source link

[IDA Plugin] UnicodeEncodeError + edited config should be validated #109

Open DarkaMaul opened 4 years ago

DarkaMaul commented 4 years ago

Hello,

When launching an analysis/saving a config on a file which path contains non-ascii characters, the plugin crash with the following stacktrace:

Traceback (most recent call last):
  File "[...]/idabincat/gui.py", line 798, in launch_analysis
    self._save_config("(last used)")
  File "[...]/idabincat/gui.py", line 937, in _save_config
    self.s.configurations[config_name] = self.s.edit_config
  File "[...]/idabincat/analyzer_conf.py", line 882, in wrap
    f(self, *args, **kwargs)
  File "[...]/idabincat/analyzer_conf.py", line 929, in __setitem__
    self._configs[name] = str(config)
  File "[...]/idabincat/analyzer_conf.py", line 691, in __str__
    self._config.write(sio)
  File "/usr/lib/python2.7/ConfigParser.py", line 412, in write
    key = " = ".join((key, str(value).replace('\n', '\n\t')))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 15: ordinal not in range(128)

Steps to reproduce

  1. Launch IDA with a file in a directory with non ascii characters (e.g ~/Téléchargements/prog)
  2. Launch BinCat plugin
  3. Go to configuration panel and try to save the config

Using last stable version of the plugin (1.1)

trou commented 4 years ago

Hello, thanks for the report. Which version of IDA are you using ? on which OS ?

DarkaMaul commented 4 years ago

I'm using IDA 7.2 on Linux. However, after more research I think the bug comes from ConfigParser in itself ( Python #11597 )

There is also another problem when the configuration is edited using the "Edit button" in the GUI. The result string is saved "as-if" in the AnalyzerConfig object, without passing any validations sets by the different setters for the fields.

I guess the following snippet explains it better:

    def validate_config(self, config):
        # A mapping of config fields => setter names
        translator = {'cut': 'stop_address', 
                      'analysis': 'analysis_method', 
                      'filepath': 'binary_filepath',
                      'headers': 'headers_files',
                      'analysis_ep': 'analysis_ep',
                      'in_marshalled_cfa_file': 'in_marshalled_cfa_file',
                      'format': 'format'}

        for section in config.sections():
            self._config.add_section(section)
            for item, value in config.items(section):
                if item in translator:
                    setattr(self, translator.get(item), value)
                else:
                    self._config.set(section, item, value)

Note : this does not solve this issue but would solve others (e.g if you change the start address in the config edit-panel to a non hex-represented value)

trou commented 4 years ago

Regarding the encoding problem, it seems I cannot trigger it with the current master.

i'll check the other issue later.