Recent

Author Topic: How can I add Assembly Code, that can be used, to import a win32api Function ?  (Read 682 times)

paule32

  • Sr. Member
  • ****
  • Posts: 280
Hello,
I would know, how the Code for the win32api Kernel32 Function ExitProcess shows in Assembly.
For this, I have extract a object File that is in a libimp archive, created by FPC 3.2.0.
Before, I did:
Code: Bash  [Select][+][-]
  1. nm libimp.a | grep ExitProcess
and get:
Code: Bash  [Select][+][-]
  1. 0000000000000000 T _$dll$kernel32$ExitProcess
then, I did:
Code: Bash  [Select][+][-]
  1. nm libimp.a > 1.txt
and searched for the Text above in 1.txt.
then, I did extract the .o bject File which contains the T flagged function/procedure:
Code: Bash  [Select][+][-]
  1. ar x libimp impsystem2s17.o
then, I did:
Code: Bash  [Select][+][-]
  1. objdump.exe -D impsystem2s17.o
and get the following content:
Code: Text  [Select][+][-]
  1. impsystem2s17.o:     file format pe-x86-64
  2.  
  3.  
  4. Disassembly of section .text:
  5.  
  6. 0000000000000000 <_$dll$kernel32$ExitProcess>:
  7.    0:   ff 25 00 00 00 00       jmp    *0x0(%rip)        # 6 <_$dll$kernel32$ExitProcess+0x6>
  8.  
  9. Disassembly of section .idata$4:
  10.  
  11. 0000000000000000 <.idata$4>:
  12.         ...
  13.  
  14. Disassembly of section .idata$5:
  15.  
  16. 0000000000000000 <.idata$5>:
  17.         ...
  18.  
  19. Disassembly of section .idata$6:
  20.  
  21. 0000000000000000 <.idata$6>:
  22.    0:   00 00                   add    %al,(%rax)
  23.    2:   45 78 69                rex.RB js 6e <.idata$6+0x6e>
  24.    5:   74 50                   je     57 <.idata$6+0x57>
  25.    7:   72 6f                   jb     78 <.idata$6+0x78>
  26.    9:   63 65 73                movsxd 0x73(%rbp),%esp
  27.    c:   73 00                   jae    e <.idata$6+0xe>
  28.  
  29. Disassembly of section .idata$7:
  30.  
  31. 0000000000000000 <.idata$7>:
  32.    0:   00 00                   add    %al,(%rax)
  33.         ...
  34.  

But I can not find anyplace where kernel32.dll is directly pointed.
So, my Question Request there:
How can I add Assembly Code, that can be used, to import a win32api Function ?

The Assembly Code should be able to compile with nasm64.exe

Thanks for reading, and helping
paule32

paule32

  • Sr. Member
  • ****
  • Posts: 280
ok, I get the Solution:

I open/write a new Pascal file: foo.pas with this content:
Code: Pascal  [Select][+][-]
  1. procedure ExitProcess(AValue: Integer); external 'kernel32.dll';

After compiling, I get the Code:
...
call _$dll$kernel32$ExitProcess
...

When Linking, FPC seems to form some Code internal by using the Symbol in the archive objects
and a mystic procedure by the Compiler.

When I would import code, that call the win32api Function ExitProcess, I have to write only
the call _$dll$kernel32$ExitProcess, and refer/link against the archive files, produced by FPC Compiler.

But, hoiw can I compile a FPC Pascal Script File, so the Compiler does not use the common ini File ?
Ok, I can use the Option -n but my current Problem is, that FPC tries then to compile the System Files
that come with the Compiler.

But I expected, that only the Units are compiled by FPC, and not the System Files again, and again ...
This can result in multiple referenced Symbols so far I know...

PascalDragon

  • Hero Member
  • *****
  • Posts: 5752
  • Compiler Developer
But I can not find anyplace where kernel32.dll is directly pointed.
So, my Question Request there:
How can I add Assembly Code, that can be used, to import a win32api Function ?

Aside from a CALL of that import symbol there is no other magic involved. That's simply how compile time imports from libaries work on Windows.

But, hoiw can I compile a FPC Pascal Script File, so the Compiler does not use the common ini File ?
Ok, I can use the Option -n but my current Problem is, that FPC tries then to compile the System Files
that come with the Compiler.

First of there is no ini-file that FPC consumes. An ini-file has a specific structure, but FPC's configuration file is simply a listing of command line options paired with preprocessor directives.

And if you pass -n then the compiler needs to get the System unit from somewhere.

But I expected, that only the Units are compiled by FPC, and not the System Files again, and again ...

That's the point of the unit system which is the key to speed up compilation as the precompiled units can be parsed more easily than an unprocessed source.

 

TinyPortal © 2005-2018