Cisco-Talos / Nim-IDA-FLIRT-Generator

Nim-IDA-FLIRT-Generator
Apache License 2.0
11 stars 1 forks source link

Currently supports only building object files for nim 1.6.x? #4

Open danielplohmann opened 10 months ago

danielplohmann commented 10 months ago

Hi!

First off, thanks a lot for the effort in building this toolchain!
I spent some time this morning replicating your results and wanted to share my observations.
In short: It appears that it currently only works with nim 1.6.x, as pyparsing is failing on older versions of nim source code and for 2.0.0, a critical file seems missing.
More details below.


System:

Observations:

nim 1.2.10

(Line: 0419): -----------------------------------------------------
---
(Line: 0602): Fn num      : 43
(Line: 0603): Fn def      : proc <#alignLeft,string,Natural,char>`_.
  ##
  ## See also:
  ## * `alignLeft proc<#alignLeft,string,Natural,char>`_
  ## * `spaces proc<#spaces,Natural>`_
  ## * `indent proc<#indent,string,Natural,string>`_
  ## * `center proc<#center,string,int,char>`_
  runnableExamples:
    assert align("abc", 4) =
Traceback (most recent call last):
  File "C:\Users\User\Downloads\nim_rtl_builder.py", line 682, in <module>
    parse_file(RTLfile + '.nim')
  File "C:\Users\User\Downloads\nim_rtl_builder.py", line 604, in parse_file
    fn_call = gen_function(f)
              ^^^^^^^^^^^^^^^
  File "C:\Users\User\Downloads\nim_rtl_builder.py", line 335, in gen_function
    parsed_fn = fn.parseString(f, parseAll=False)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyparsing\util.py", line 256, in _inner
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyparsing\core.py", line 1197, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected W:(0-9A-Z^-z), found '<'  (at char 5), (line:1, col:6)
nim 1.4.8

(Line: 0419): -----------------------------------------------------
---
(Line: 0602): Fn num      : 44
(Line: 0603): Fn def      : proc <#alignLeft,string,Natural,char>`_.
  ##
  ## See also:
  ## * `alignLeft proc<#alignLeft,string,Natural,char>`_
  ## * `spaces proc<#spaces,Natural>`_
  ## * `indent proc<#indent,string,Natural,string>`_
  ## * `center proc<#center,string,int,char>`_
  runnableExamples:
    assert align("abc", 4) =
Traceback (most recent call last):
  File "C:\Users\User\Downloads\nim_rtl_builder.py", line 682, in <module>
    parse_file(RTLfile + '.nim')
  File "C:\Users\User\Downloads\nim_rtl_builder.py", line 604, in parse_file
    fn_call = gen_function(f)
              ^^^^^^^^^^^^^^^
  File "C:\Users\User\Downloads\nim_rtl_builder.py", line 335, in gen_function
    parsed_fn = fn.parseString(f, parseAll=False)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyparsing\util.py", line 256, in _inner
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyparsing\core.py", line 1197, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected W:(0-9A-Z^-z), found '<'  (at char 5), (line:1, col:6)
nim 2.0.0

C:\Users\User\.choosenim\toolchains\nim-2.0.0\lib\pure>python C:\Users\User\Downloads\nim_rtl_builder.py

[ERROR] File not found: ..\system\io.nim
[ERROR] Are you running this script in '<Nim_install_dir>\lib\pure' directory ?
nim 1.6.14 x86

collect2.exe: error: ld returned 1 exit status
Error: execution of an external program failed: 'gcc.exe   -o C:\Users\User\.choosenim\toolchains\nim-1.6.14\lib\pure\parseutils_hu.exe  C:\Users\User\.choosenim\toolchains\nim-1.6.14\lib\pure\HU_nim_cache\@m..@sstd@sprivate@sdigitsutils.nim.c.o C:\Users\User\.choosenim\toolchains\nim-1.6.14\lib\pure\HU_nim_cache\@m..@ssystem@sassertions.nim.c.o C:\Users\User\.choosenim\toolchains\nim-1.6.14\lib\pure\HU_nim_cache\@m..@ssystem@sdollars.nim.c.o C:\Users\User\.choosenim\toolchains\nim-1.6.14\lib\pure\HU_nim_cache\@m..@ssystem@sio.nim.c.o C:\Users\User\.choosenim\toolchains\nim-1.6.14\lib\pure\HU_nim_cache\@m..@ssystem.nim.c.o C:\Users\User\.choosenim\toolchains\nim-1.6.14\lib\pure\HU_nim_cache\@mparseutils_hu.nim.c.o   -m32  '
(Line: 0434): Command failed with return code: 1

edit: I used nim 1.6.14, 1.6.18 does not exist.

hunterbr72 commented 10 months ago

thx Daniel, I ll look into this we only focused on 1.6.x , parsing Nim is a nightmare so no surprise other versions crash the parser. I ll have some other work to do the next two weeks so pls expect some delay.

hunterbr72 commented 10 months ago

I haven't looked into it yet, but rg. "[ERROR] File not found: ..\system\io.nim" just exclude it from the list of libraries in the script (the list which lists all the RTL libs), my guess would be that it just doesn't exists in 2.0. or was renamed.

hunterbr72 commented 10 months ago

Hi Daniel, I have created a development branch, you can find a quick'n dirty update there for Nim 1.2.10. There is now a nim_rtl_builder script per Nim version.

danielplohmann commented 10 months ago

That's awesome, thank you so much! I was indeed able to build symbols for 1.2.10, both x86+x64. For 1.4.8 this same adjusted script "almost" works as well, with some error messages being thrown and there's less files generated, which suggests that its incomplete. For 2.0.0 I tried to remove ../system/io.nim as suggested by you but then there's some other errors of missing declarations despite methods being present in the glued together source code, so no idea what's up with that.

hunterbr72 commented 10 months ago

cool. Yeah, there could be dependencies, when I find time I ll release a 2.0.x version and a simplified version of manually adding excluded functions. I ll ping you once it is done.