Skip to content

Added support for Write #x call#117

Open
lap1nou wants to merge 2 commits into
decalage2:masterfrom
lap1nou:vba-write
Open

Added support for Write #x call#117
lap1nou wants to merge 2 commits into
decalage2:masterfrom
lap1nou:vba-write

Conversation

@lap1nou
Copy link
Copy Markdown

@lap1nou lap1nou commented Mar 26, 2022

Hey,

I had a bug with a simple VBA macro like this one:

Sub Auto_Open()
    FileTest = "C:\Users\test\test.txt"
    
    Open FileTest For Output As #1
    Write #1, "Test"
    Close #1
End Sub

The actual ViperMonkey commit transformed the source code into this:

Sub Auto_Open()
    FileTest = "C:\Users\test\test.txt"
    
    Open FileTest For Output As #1
    Write 1, "Test"
    Close #1
End Sub

As you can see there is a missing # in the Write call, to fix this I've added these two lines:

vba_code = re.sub(r"[Ww]rite\s+#", "write__HASH", vba_code)
r = r.replace("write__HASH", "Write #")

I also had to modify the Write class defined in vba_library.py, the original file had this:

# Get the data.
        data = str(params[0])

But the data are actually stored in the second parameter like the Put call:

# Get the data.
        data = str(params[1])

I have tested with the code I've put above and it seems to work fine.

Like the Put call they may be more than on input so we might need to mimic Put class regarding this.

@decalage2 decalage2 self-requested a review March 27, 2022 15:32
@decalage2 decalage2 self-assigned this Mar 27, 2022
@decalage2 decalage2 added the bug label Mar 27, 2022
@decalage2 decalage2 added this to the ViperMonkey 1.0.3 milestone Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants