Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Write #x call #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lap1nou
Copy link

@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.

None yet

2 participants