سؤال

I am trying to do a simple task in FASM that I have literally been struggling with for about two hours now.

I have commented the code with the goal and the issue, but I will explain.

I am trying to store the path to a specific file into a variable. The file is located in the Temp Directory. So I must first get the temp path, then append the file name to the end of the temp path.

I am trying to do this two times sequentially. But for some reason, my resulting strings end up "screwy".

My current code is as follows:

include "win32ax.inc"

entry start

section ".data" data readable writeable

TmpDir          rb 256d
aSTR            dd ?
bSTR            dd ?
cSTR            db "aFILE.txt",0
dSTR            db "bFILE.txt",0

section ".code" code readable executable

start:

        ;The goal is to get two seperate strings like so:
        ;1 - C:\PATH-TO-TEMP-DIR\aFILE.txt in "aSTR"
        ;2 - C:\PATH-TO-TEMP-DIR\bFILE.txt in "bSTR"

        ;Get temp directory
        invoke  GetTempPath,TmpDir,TmpDir

        ;Copy tempdir into aSTR
        invoke  lstrcpy,aSTR,TmpDir
        ;Add "aFILE.txt" to the end of aSTR
        invoke  lstrcat,aSTR,cSTR

        ;Copy tempdir into bSTR
        invoke  lstrcpy,bSTR,TmpDir
        ;Add "bFILE.txt" to the end of bSTR
        invoke  lstrcat,bSTR,dSTR

        ;Results in "C:\UC:\Users\user\AppData\Local\Temp\AppData\Local\Temp\A\\
        ;Instead of "C:\Users\user\AppData\Local\Temp\aFILE.txt"
        invoke  MessageBox,0,aSTR,"Test",0
        ;Results in "C:\Users\user\AppData\Local\Temp\AppData\Local\Temp\A\\"
        ;Instead of "C:\Users\user\AppData\Local\Temp\bFILE.txt"
        invoke  MessageBox,0,bSTR,"Test",0

        invoke  ExitProcess,0

section ".idata" import readable writeable

        library kernel32,               "KERNEL32.DLL",\
                user32,                 "USER32.DLL"

        import  kernel32,\
                lstrcpy,                "lstrcpy",\
                lstrcat,                "lstrcat",\
                GetTempPath,            "GetTempPathA",\
                ExitProcess,            "ExitProcess"

        import  user32,\
                MessageBox,             "MessageBoxA"

Any help resolving this would be greatly appreciated. Thanks!

هل كانت مفيدة؟

المحلول

Hmm. one of your strings is:

C:\UC:\Users\u...
^^^^

almost as if there's only four bytes for storing it before the next item in memory.

I wonder if that could be anything to do with the fact that you're using dd to define the space for it. Nudge, nudge, wink, wink.


Enough humour, time for a more serious response. Why do you think that:

aSTR            dd ?

will give you enough space to store a path name? Surely it should be something more like:

aSTR            rb 512d

which should give you heaps of space (and similarly for bSTR).


In fact, you're first cpy/cat operation also overwrites cSTR and dSTR, making it even harder to figure out what happens with the second operation.

Try reserving enough space (as per above) then giving it another shot.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top