Results 1 to 8 of 8

Thread: Unicode aware VB6 functions replacement

  1. #1

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Unicode aware VB6 functions replacement

    Hi,

    here is W replacement for several native VB6 functions / properties:

    - Dir -> DirW()
    - MkDir -> MkDirW()
    - Environ -> EnvironW()
    - App.Path -> AppPathW()
    - App.ExeName -> AppExeNameW()
    - App.Major, Minor, Revision -> AppVersionW()

    All functions packed on archive as separate projects, available under the post below.

    1) DirW

    Prototype is: Dir$(Path with mask or backslash at the end, opt_mask of allowed attributes, opt_return folders? )

    Difference to original VB6 Dir$():

    Fixed bug, when Dir cannot handle attribute: read only (vbReadOnly)
    Added attributes:
    - reparse points (symlinks / junctions) (vbReparse)
    - all file objects (vbAll)
    - vbFile (files only, without folders)

    Enum VbFileAttribute "overloaded" by own: I removed all superfluous attributes, which original VB6 dir() are still not used in any way; I leave meaningful attributes only.

    + 3-rd optional argument (FoldersOnly); if true, it will filter files and leave folders only in output.
    Function also automatically filter folders-aliases "." и ".."

    Code based on earlier VB6() Dir$ reversing by @The Trick.

    2) MkDirW()

    Prototype is: MkDirW(Path to folder to create, opt_LastComponentIsFile as boolean) as boolean

    LastComponentIsFile - true, if you plan to specify filename as a last part of path component
    Return value: true, if successfully created or if folder is already exist

    3) EnvironW()

    Prototype: EnvironW$( "%Environment variable(s)%" )

    Difference to original VB6 Environ():

    - support several env. var-s on one line, like EnvironW("%UserName% - %UserDomain%")
    - require %var%, i.e. each environment variable should be surrounded by % signs.
    - automatically correct and "right" (in the sense, like if we wanted to do so from a 64-bit application) to expand under WOW64 such env. variables as:
    - %PROGRAMFILES%
    - %COMMONPROGRAMFILES%
    and get on 64-bit OS, respectively:
    - C:\Program Files, but not C:\Program Files (x86)
    - C:\Program Files\Common Files, but not C:\Program Files (x86)\Common Files

    4,5) AppPathW(), AppExeNameW()

    Prototypes are:
    - AppPathW$(opt_bGetFullPath as boolean)
    - AppExeNameW$(opt_WithExtension As Boolean)

    Self-explained:
    Code:
        Debug.Print AppPathW()                          'Folder
        Debug.Print AppPathW(bGetFullPath:=True)        'Folder\FileName.extension
        Debug.Print AppExeNameW()                       'FileName
        Debug.Print AppExeNameW(WithExtension:=True)    'FileName.extension
    6) AppVersionW()

    Prototype is: AppVersionW$()

    # require AppPathW(), AppExeNameW()

    Just append unicode-char to your exe-name /and-or path (e.g. ALT + 3333) and you'll understand why you may need this function replacement.

    Returns: String, version of your program in format: Major.Minor.Build.Revision
    ___________________

    Best wishes,
    Alex.
    Attached Files Attached Files
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  2. #2
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,375

    Re: Unicode aware VB6 functions replacement

    Bug in the DirW function.

    Instead of
    Code:
    If hFind = INVALID_HANDLE_VALUE Then
        If (Err.LastDllError) > 12& Then hFind = 0&: Err.Raise 52&
        Exit Function
    End If
    it should be
    Code:
    If hFind = INVALID_HANDLE_VALUE Then
        hFind = 0&
        If (Err.LastDllError) > 12& Then Err.Raise 52&
        Exit Function
    End If
    Reason:
    You check always for "hFind <> 0&" and hFind of INVALID_HANDLE_VALUE would be also <> 0&. So the hFind must be reset to 0& regardless if an error shall be thrown out or not. (Err.LastDllError > 12&)

  3. #3
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: Unicode aware VB6 functions replacement

    Private Declare Function GetModuleFileNameW Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpFilename As Long, ByVal nSize As Long) As Long

    Function AppPathW() As String
    Const MAX_PATH = 560&

    AppPathW = Space$(MAX_PATH - 1&)
    AppPathW = Left$(AppPathW, GetModuleFileNameW(0&, StrPtr(AppPathW), MAX_PATH))
    AppPathW = Left(AppPathW, InStrRev(AppPathW, ""))
    End Function

  4. #4
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,323

    Question Re: Unicode aware VB6 functions replacement

    It looks like the API functions used for your "AppVersionW" could also be used to return values for App.Comments, App.CompanyName, App.FileDescription, App.LegalCopyright, App.LegalTrademarks and App.ProductName. All these properties fail when the executable lies on a path containing Unicode characters. Maybe you could make an updated version including these? It doesn't seem to be as trivial as retrieving the version numbers though...

  5. #5

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: Unicode aware VB6 functions replacement

    Well, I must give outdated thank to @Krool, that's correct remark. Sorry, for not answering. Were bad times.

    @xiaoyao, it's short but not reliable compared to mine. Always need to normalize, especially if you support various versions of Windows.

    @VanGoghGaming, I'll keep your proposal in mind until I'll have more time.
    Lot of things changed since. It's better to move source code on github, I think.
    For those properties, I already wrote 2 roots in the past: for exe & for ide (parsed from vbp). Just need to beautify it a bit.

    It's always a pain how to separate single samples from a large project.
    One time I thought about writing mini-framework with all functions embedded including -W, file/registry/window basic tasks. But I'm not the one who can write clear API (ahh, then I have to to write docs...)
    Actually I already have one in form of several mod/cls, ready to use. But I'd prefer to have it like OCX (or even both variants). So, you connect it once, and you have a full power much like mini .NET, aimed to interact with OS with most common actions developer may want.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  6. #6
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    678

    Re: Unicode aware VB6 functions replacement

    hi, reading files works, but I need to append data to a file using

    Open FN For Append As 1

    ( Where FN is the (unicode Aware) full path and file name string read with your functions)
    However, this does not work. Is there a solution?

  7. #7

    Thread Starter
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: Unicode aware VB6 functions replacement

    reexre, you can extract snippets from here:

    PutStringUnicode(hFile As Long, Optional pos As Long, Optional sStr As String) As Boolean
    PutString(hFile As Long, Optional pos As Long, Optional sStr As String, Optional bUnicode As Boolean = True) As Boolean
    PutW(hFile As Long, ByVal pos As Long, vInPtr As Long, cbToWrite As Long, Optional doAppend As Boolean) As Boolean
    PrintLineW(hFile As Long, sStr As String, Optional bUnicode As Boolean) As Boolean
    PrintBOM(hFile As Long) As Boolean
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  8. #8
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    678

    Re: Unicode aware VB6 functions replacement

    Quote Originally Posted by Dragokas View Post
    reexre, you can extract snippets from here:

    PutStringUnicode(hFile As Long, Optional pos As Long, Optional sStr As String) As Boolean
    PutString(hFile As Long, Optional pos As Long, Optional sStr As String, Optional bUnicode As Boolean = True) As Boolean
    PutW(hFile As Long, ByVal pos As Long, vInPtr As Long, cbToWrite As Long, Optional doAppend As Boolean) As Boolean
    PrintLineW(hFile As Long, sStr As String, Optional bUnicode As Boolean) As Boolean
    PrintBOM(hFile As Long) As Boolean
    Thank you! I (should) have resolved extracting from here

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width