Recent

Author Topic: Calling Pure C functions (external DLL) from Lazarus  (Read 6898 times)

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Calling Pure C functions (external DLL) from Lazarus
« Reply #15 on: March 25, 2020, 02:17:04 pm »
I need a good PE Viewer as well.  ::)
Mine isn't graphical and doesn't resolve dependencies but, there is no PE viewer around that gives more detail both, in raw and "cooked" form.

For what you do, it does lack one feature that is probably important to you, it doesn't dump the DWARF debug sections, only the COFF symbol table.  The other thing that could be a problem is that, I don't provide the source and, it considers any .NET PE a third class citizen (it dumps the directory if present but barely and I included it only for completeness.)

I have another version, which I haven't shared because it's a quick and dirty hack of the one I shared that, outputs the PE as it will be laid out in memory by the loader.  I did that one because some PE files multiplex some areas of the PE format and there is no viewer around that shows the multiplexing (not even disassemblers do it.)    That's occasionally exploited by malware.  Another reason I wrote that PE viewer is that, there is no PE viewer that formats the LOAD_CONFIG_DIRECTORY correctly.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: Calling Pure C functions (external DLL) from Lazarus
« Reply #16 on: March 26, 2020, 09:34:36 am »
I need a good PE Viewer as well.  ::)
Mine isn't graphical and doesn't resolve dependencies but, there is no PE viewer around that gives more detail both, in raw and "cooked" form.

For what you do, it does lack one feature that is probably important to you, it doesn't dump the DWARF debug sections, only the COFF symbol table.  The other thing that could be a problem is that, I don't provide the source and, it considers any .NET PE a third class citizen (it dumps the directory if present but barely and I included it only for completeness.)

I have another version, which I haven't shared because it's a quick and dirty hack of the one I shared that, outputs the PE as it will be laid out in memory by the loader.  I did that one because some PE files multiplex some areas of the PE format and there is no viewer around that shows the multiplexing (not even disassemblers do it.)    That's occasionally exploited by malware.  Another reason I wrote that PE viewer is that, there is no PE viewer that formats the LOAD_CONFIG_DIRECTORY correctly.

The DWARF sections aren't a problem. Those I mainly handle with the assembly output if I need to deal with them at all. No, I'm mainly talking about various header fields (file flags and DLL characteristics for example) or things like the import/export tables. And the exception tables (.pdata, .xdata) for non-i386 platforms.

Do you have a link to your viewer?

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Calling Pure C functions (external DLL) from Lazarus
« Reply #17 on: March 26, 2020, 10:23:28 am »
No, I'm mainly talking about various header fields (file flags and DLL characteristics for example) or things like the import/export tables. And the exception tables (.pdata, .xdata) for non-i386 platforms.
In that case, my viewer will meet some of your needs.  Some, because it only handles the i386 platform but, on that platform, with the exception of .net stuff, it is _complete_, it doesn't miss a byte.

Do you have a link to your viewer?
Sure do.  Right here in the forums https://forum.lazarus.freepascal.org/index.php?topic=46617.0

Of course, if you find a bug, I will promptly fix it.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: Calling Pure C functions (external DLL) from Lazarus
« Reply #18 on: March 27, 2020, 09:26:57 am »
No, I'm mainly talking about various header fields (file flags and DLL characteristics for example) or things like the import/export tables. And the exception tables (.pdata, .xdata) for non-i386 platforms.
In that case, my viewer will meet some of your needs.  Some, because it only handles the i386 platform but, on that platform, with the exception of .net stuff, it is _complete_, it doesn't miss a byte.

So you don't handle the 64-bit optional header yet? Pity, cause that's something I'd really need...  :'( (and it isn't that different from the 32-bit one)

Do you have a link to your viewer?
Sure do.  Right here in the forums https://forum.lazarus.freepascal.org/index.php?topic=46617.0

Thanks, I'll give it a try. :) (And will report bugs in that other thread)

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Calling Pure C functions (external DLL) from Lazarus
« Reply #19 on: March 27, 2020, 09:55:18 am »
So you don't handle the 64-bit optional header yet? Pity, cause that's something I'd really need...  :'( (and it isn't that different from the 32-bit one)
64bit optional header ? ... no problem!.

It handles any 32 and 64 bit structure but only on Intel/AMD and Windows.  It  doesn't try to analyze a PE file targeted to other architectures.

Thanks, I'll give it a try. :) (And will report bugs in that other thread)
Hopefully there aren't very many.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: Calling Pure C functions (external DLL) from Lazarus
« Reply #20 on: March 28, 2020, 11:16:11 am »
So you don't handle the 64-bit optional header yet? Pity, cause that's something I'd really need...  :'( (and it isn't that different from the 32-bit one)
64bit optional header ? ... no problem!.

It handles any 32 and 64 bit structure but only on Intel/AMD and Windows.  It  doesn't try to analyze a PE file targeted to other architectures.

What about at least import and export sections? I know that e.g. relocations are highly platform specific, so those are out for now, but the former two follow a standardized format (as well as resource sections by the way).

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Calling Pure C functions (external DLL) from Lazarus
« Reply #21 on: March 28, 2020, 02:23:10 pm »
What about at least import and export sections? I know that e.g. relocations are highly platform specific, so those are out for now, but the former two follow a standardized format (as well as resource sections by the way).
I'm open to creating a version that "relaxes" some of its requirements.  I normally limit my programs to handle what I can ensure they can process correctly.  See my reply to your post in the other thread.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018