flat assembler
Message board for the users of flat assembler.

Index > Windows > import undefined function from shell32

Author
Thread Post new topic Reply to topic
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
How do I import CommandLineToArgvW from shell32.dll? It is not in the shipped shell32.inc, and it complains that shell32 is already defined if I try this:


Code:
include 'win32wxp.inc'  
...
import shell32,CommandLineToArgvW,'CommandLineToArgvW'     


Error: symbol already defined

_________________
This is a block of text that can be added to posts you make.
Post 07 Apr 2010, 17:35
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17248
Location: In your JS exploiting you and your system
revolution
Two options:

1. Edit include\api\shell32.inc

2. Create your own import table (add other commands as necessary):
Code:
section '.idata' import data readable

   dd      0,0,0,RVA shell_name,RVA shell_table
        dd      0,0,0,0,0

       shell_table:
            CommandLineToArgvW      dd      RVA _CommandLineToArgvW
                                     dd      0

       shell_name                      db      'SHELL32.DLL',0

       _CommandLineToArgvW             db      0,0,'CommandLineToArgvW',0    
Post 07 Apr 2010, 17:42
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
3. Create your own import table (add other commands as necessary), but easier Razz:
Code:
section '.idata' import data readable 
  library kernel32, 'KERNEL32.dll',\ ; Add other libraries here
          shell32,'SHELL32.DLL'

; Include the headers of the libraries you are not adding new functions
  include 'api/kernel32.inc' 

  import shell32,\
         CommandLineToArgvW, 'CommandLineToArgvW'
    


BTW, in both, revolution's version and mine, don't use ".end start", use "entry start" instead, because otherwise the import table will be attempted to be build twice.
Post 07 Apr 2010, 19:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17248
Location: In your JS exploiting you and your system
revolution
I imagine the reason that CommandLineToArgvW is not listed is because it is not present in Win95. Although, surprisingly, is was part of Win32s.

Anyhow, by using CommandLineToArgvW you also limit the number Windows systems that can run your code. Maybe this is not an issue for you, maybe it is, but it is something to consider.
Post 08 Apr 2010, 02:50
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
This was kind of a downer; do the first one and you contaminate the "standard library", do the other you lose the functionality of the "standard library" altogether.

I don't care about win9x that much, but it seems like an awful lot of hassle to add the entry, more than writing my own function.

Oh well.
Post 08 Apr 2010, 10:16
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Before I run off making an ascii/utf-16 command line slicer, perhaps I should ask how you are doing it. Is there any other WINAPI call that I can use? If not, any hints on making a macro that takes either one- or two-byte strings depending on the header you're using?
Post 08 Apr 2010, 10:38
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2900
Location: [RSP+8*5]
bitRAKE
Just patch the includes and make note of the dependency within your project. Only a single line needs to be added to .\FASM\INCLUDE\API\SHELL32.INC -- there are even programs on the board to generate the API include file for any DLL. The structure of the "standard library" facilitates augmentation, imho. There are also many examples of other Windows API support macros in the macro section of the board.
Post 11 Apr 2010, 22:40
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
I realised I only needed one parameter, while it would have been nice to have, it would have been overkill.

I came up with this, works on a pointer from GetCommandLineW:

Code:
GetParameter:   ;eax
        cmp     word [eax],'"'
        je      .quote
        cmp     word [eax],0
        je      .out
 .nqloop:
        cmp     word [eax],' '
        je      .lastspace
        inc     eax
        inc     eax
        jmp     .nqloop

 .quote:
        inc     eax
        inc     eax
        cmp     word [eax],'"'
        jne     .quote

 .lastspace:
        inc     eax
        inc     eax
        cmp     word [eax],' '
        jne     .out
        inc     eax
        inc     eax
 .out:
        ret      


Any magic way to make this work when sizeof.TCHAR = 1?

_________________
This is a block of text that can be added to posts you make.
Post 12 Apr 2010, 18:57
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
mindcooler,

I've posted kind of solution to the importing problem here.

TCHAR equ word, cmp TCHAR [eax], ' ' and add eax, sizeof.TCHAR probably can fit the bill.
Post 13 Apr 2010, 10:40
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
That's some voodoo alright, but I hope TG catches on the idea of being able to easily extend the import tables.

That looks that something I thought of, but I didn't get it to work. I gave up the idea of one-byters as I found more w2k+ calls that I want to use, such as VirtualAlloc.
Post 13 Apr 2010, 11:30
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.