Re: argv



Howdy,

Andrew Robinson wrote:
This should be easy, but it is not. I am writing an assembly language program
involving GTK+. I want to parse the command line for options but am unable to
do so. The code to find argv and argc is simple:

main:
   push ebp
   mov ebp, esp
   lea eax, [ebp + 12]
   lea ecx, [ebp + 8]


Assuming your linker is producing a .exe file, what's the entry point
in the PE32 header?

Example:

$ dumpbin /headers stdcall_dll_user.exe
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file stdcall_dll_user.exe

PE signature found

File Type: EXECUTABLE IMAGE

FILE HEADER VALUES
             14C machine (x86)
               4 number of sections
        55CC0078 time date stamp Wed Aug 12 19:27:04 2015
               0 file pointer to symbol table
               0 number of symbols
              E0 size of optional header
             102 characteristics
                   Executable
                   32 bit word machine

OPTIONAL HEADER VALUES
             10B magic # (PE32)
           10.00 linker version
             A00 size of code
             E00 size of initialized data
               0 size of uninitialized data
            12F6 entry point (004012F6) _mainCRTStartup
[...]


$ dumpbin /disasm stdcall_dll_user.exe | grep -A 2 -E "_main|004010B3"
_main:
  00401000: 56                 push        esi
  00401001: 8B 35 9C 20 40 00  mov         esi,dword ptr [__imp____iob_func]
--
  004010B3: 6A 10              push        10h
  004010B5: 68 08 22 40 00     push        402208h
  004010BA: E8 01 05 00 00     call        __SEH_prolog4
--
  004011D0: E8 2B FE FF FF     call        _main
  004011D5: 83 C4 0C           add         esp,0Ch
  004011D8: A3 38 30 40 00     mov         dword ptr ds:[00403038h],eax
--
_mainCRTStartup:
  004012F6: E8 6E 03 00 00     call        ___security_init_cookie
  004012FB: E9 B3 FD FF FF     jmp         004010B3


Does the entry point change depending on whether you do or don't link with
GTK ?

Had you considered instructing the linker to use your own custom entry
point, so that you have full control over the startup?


Regards,

Bill

(yes, plenty of assembly in the 80's and 90's as a matter of necessity)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]