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

Python3 compatibility #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vipermonkey/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,10 @@ def procedures(self):
def entry_points(self):
"""Yields the entry points. (or None if not found)."""
# Since the module VBA_Object stores its elements with case intact we can't just hash.
for name, sub in self.obj.subs.iteritems():
for name, sub in self.obj.subs.items():
if name.lower() in self._ENTRY_POINTS:
yield sub
for name, function in self.obj.functions.iteritems():
for name, function in self.obj.functions.items():
if name.lower() in self._ENTRY_POINTS:
yield function

Expand Down
64 changes: 32 additions & 32 deletions vipermonkey/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@

import subprocess

from logger import log
from procedures import Function
from procedures import Sub
from function_call_visitor import *
from function_defn_visitor import *
from function_import_visitor import *
from var_defn_visitor import *
from .logger import log
from .procedures import Function
from .procedures import Sub
from .function_call_visitor import *
from .function_defn_visitor import *
from .function_import_visitor import *
from .var_defn_visitor import *

# === FUNCTIONS ==============================================================

Expand All @@ -130,11 +130,11 @@ def list_startswith(_list, lstart):

# === VBA GRAMMAR ============================================================

from vba_lines import *
from modules import *
from .vba_lines import *
from .modules import *

# Make sure we populate the VBA Library:
from vba_library import *
from .vba_library import *

# === ViperMonkey class ======================================================

Expand Down Expand Up @@ -406,7 +406,7 @@ def _get_external_funcs(self):
# Regular local function call.
r.append(f)

# Sort and return the fingerprint function list.
# Sort and return the fingerprint(function list.)
r.sort()
return r

Expand All @@ -431,35 +431,35 @@ def trace(self, entrypoint='*auto'):
context.dll_func_true_names[func.name] = func.alias_name

# Save the document text in the proper variable in the context.
context.globals["ActiveDocument.Content.Text".lower()] = "\n".join(self.doc_text)
context.globals["ActiveDocument.Range.Text".lower()] = "\n".join(self.doc_text)
context.globals["ActiveDocument.Range".lower()] = "\n".join(self.doc_text)
context.globals["ActiveDocument.Content.Text".lower()] = b"\n".join(self.doc_text)
context.globals["ActiveDocument.Range.Text".lower()] = b"\n".join(self.doc_text)
context.globals["ActiveDocument.Range".lower()] = b"\n".join(self.doc_text)
context.globals["ActiveDocument.Content.Start".lower()] = 0
context.globals["ActiveDocument.Content.End".lower()] = len("\n".join(self.doc_text))
context.globals["ActiveDocument.Content.End".lower()] = len(b"\n".join(self.doc_text))
context.globals["ActiveDocument.Paragraphs".lower()] = self.doc_text
context.globals["ThisDocument.Content.Text".lower()] = "\n".join(self.doc_text)
context.globals["ThisDocument.Range.Text".lower()] = "\n".join(self.doc_text)
context.globals["ThisDocument.Range".lower()] = "\n".join(self.doc_text)
context.globals["ThisDocument.Content.Text".lower()] = b"\n".join(self.doc_text)
context.globals["ThisDocument.Range.Text".lower()] = b"\n".join(self.doc_text)
context.globals["ThisDocument.Range".lower()] = b"\n".join(self.doc_text)
context.globals["ThisDocument.Content.Start".lower()] = 0
context.globals["ThisDocument.Content.End".lower()] = len("\n".join(self.doc_text))
context.globals["ThisDocument.Content.End".lower()] = len(b"\n".join(self.doc_text))
context.globals["ThisDocument.Paragraphs".lower()] = self.doc_text
context.globals["['ActiveDocument'].Content.Text".lower()] = "\n".join(self.doc_text)
context.globals["['ActiveDocument'].Range.Text".lower()] = "\n".join(self.doc_text)
context.globals["['ActiveDocument'].Range".lower()] = "\n".join(self.doc_text)
context.globals["['ActiveDocument'].Content.Text".lower()] = b"\n".join(self.doc_text)
context.globals["['ActiveDocument'].Range.Text".lower()] = b"\n".join(self.doc_text)
context.globals["['ActiveDocument'].Range".lower()] = b"\n".join(self.doc_text)
context.globals["['ActiveDocument'].Content.Start".lower()] = 0
context.globals["['ActiveDocument'].Content.End".lower()] = len("\n".join(self.doc_text))
context.globals["['ActiveDocument'].Content.End".lower()] = len(b"\n".join(self.doc_text))
context.globals["['ActiveDocument'].Paragraphs".lower()] = self.doc_text
context.globals["['ThisDocument'].Content.Text".lower()] = "\n".join(self.doc_text)
context.globals["['ThisDocument'].Range.Text".lower()] = "\n".join(self.doc_text)
context.globals["['ThisDocument'].Range".lower()] = "\n".join(self.doc_text)
context.globals["['ThisDocument'].Content.Text".lower()] = b"\n".join(self.doc_text)
context.globals["['ThisDocument'].Range.Text".lower()] = b"\n".join(self.doc_text)
context.globals["['ThisDocument'].Range".lower()] = b"\n".join(self.doc_text)
context.globals["['ThisDocument'].Content.Start".lower()] = 0
context.globals["['ThisDocument'].Content.End".lower()] = len("\n".join(self.doc_text))
context.globals["['ThisDocument'].Content.End".lower()] = len(b"\n".join(self.doc_text))
context.globals["['ThisDocument'].Paragraphs".lower()] = self.doc_text

# Fake up some comments.
# TODO: Figure out how to actually read the comments.
context.globals["ActiveDocument.Comments".lower()] = ["Comment 1", "Comment 2"]
context.globals["ThisDocument.Comments".lower()] = ["Comment 1", "Comment 2"]
context.globals["ActiveDocument.Comments".lower()] = [b"Comment 1", b"Comment 2"]
context.globals["ThisDocument.Comments".lower()] = [b"Comment 1", b"Comment 2"]

# reset the actions list, in case it is called several times
self.actions = []
Expand Down Expand Up @@ -550,19 +550,19 @@ def report_action(self, action, params=None, description=None):
# store the action for later use:
try:
if (isinstance(action, str)):
action = unidecode.unidecode(action.decode('unicode-escape'))
action = unidecode.unidecode(action)
except UnicodeDecodeError:
action = ''.join(filter(lambda x:x in string.printable, action))
if (isinstance(params, str)):
try:
decoded = params.replace("\\", "#ESCAPED_SLASH#").decode('unicode-escape').replace("#ESCAPED_SLASH#", "\\")
decoded = params.replace("\\", "#ESCAPED_SLASH#").replace("#ESCAPED_SLASH#", "\\")
params = unidecode.unidecode(decoded)
except Exception as e:
log.warn("Unicode decode of action params failed. " + str(e))
params = ''.join(filter(lambda x:x in string.printable, params))
try:
if (isinstance(description, str)):
description = unidecode.unidecode(description.decode('unicode-escape'))
description = unidecode.unidecode(description)
except UnicodeDecodeError as e:
log.warn("Unicode decode of action description failed. " + str(e))
description = ''.join(filter(lambda x:x in string.printable, description))
Expand Down
4 changes: 2 additions & 2 deletions vipermonkey/core/comments_eol.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@

from pyparsing import *

from vba_lines import line_terminator
from .vba_lines import line_terminator

from logger import log
from .logger import log
log.debug('importing comments_eol')


Expand Down
37 changes: 18 additions & 19 deletions vipermonkey/core/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@
import array
from hashlib import sha256

from identifiers import *
from reserved import *
from lib_functions import *
from literals import *
from operators import *
import procedures
from vba_object import eval_arg
from vba_object import coerce_to_int
from vba_object import strip_nonvb_chars
from vba_object import int_convert
from vba_object import VbaLibraryFunc
import vba_context

from logger import log
from .identifiers import *
from .reserved import *
from .lib_functions import *
from .literals import *
from .operators import *
from . import procedures
from .vba_object import eval_arg
from .vba_object import coerce_to_int
from .vba_object import strip_nonvb_chars
from .vba_object import int_convert
from .vba_object import VbaLibraryFunc
from . import vba_context

from .logger import log

# --- FILE POINTER -------------------------------------------------

Expand Down Expand Up @@ -482,7 +482,7 @@ def _handle_file_close(self, context, lhs, rhs):
rhs = rhs[0]
if (str(rhs) != "Close"):
return None
from vba_library import Close
from .vba_library import Close
file_close = Close()

# File closed.
Expand Down Expand Up @@ -1155,7 +1155,7 @@ def __init__(self, original_str, location, tokens, old_call=None):
# Making a new one.
self.name = str(tokens.name)
log.debug('Function_Call.name = %r' % self.name)
assert isinstance(self.name, basestring)
assert isinstance(self.name, str)
self.params = tokens.params
log.debug('Function_Call.params = %r' % self.params)
log.debug('parsed %r as Function_Call' % self)
Expand All @@ -1173,7 +1173,7 @@ def __repr__(self):
def eval(self, context, params=None):

# Save the unresolved argument values.
import vba_library
from . import vba_library
vba_library.var_names = self.params

log.debug("Function_Call: eval params: " + str(self.params))
Expand Down Expand Up @@ -1266,8 +1266,7 @@ def eval(self, context, params=None):
log.debug('Calling: %r' % f)
if (f is not None):
if (not(isinstance(f, str)) and
not(isinstance(f, list)) and
not(isinstance(f, unicode))):
not(isinstance(f, list))):
try:

# Call function.
Expand Down
8 changes: 4 additions & 4 deletions vipermonkey/core/function_call_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from visitor import *
from expressions import *
from lib_functions import *
from .visitor import *
from .expressions import *
from .lib_functions import *

class function_call_visitor(visitor):
"""
Expand All @@ -51,7 +51,7 @@ def __init__(self):

def visit(self, item):

import statements
from . import statements

if (item in self.visited):
return False
Expand Down
4 changes: 2 additions & 2 deletions vipermonkey/core/function_import_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from visitor import *
from procedures import *
from .visitor import *
from .procedures import *

class function_import_visitor(visitor):
"""
Expand Down
4 changes: 2 additions & 2 deletions vipermonkey/core/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
# --- IMPORTS ------------------------------------------------------------------

from pyparsing import *
from reserved import *
from logger import log
from .reserved import *
from .logger import log

# TODO: reduce this list when corresponding statements are implemented
# Handling whitespace in the RE version of reserved_keywords is a nightmare. Track this with a keyword list.
Expand Down
10 changes: 5 additions & 5 deletions vipermonkey/core/lib_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@

from pyparsing import *

from vba_object import *
from literals import *
import vb_str
from .vba_object import *
from .literals import *
from . import vb_str

from logger import log
from .logger import log

# --- VBA Expressions ---------------------------------------------------------

Expand Down Expand Up @@ -83,7 +83,7 @@ def eval(self, context, params=None):
param = eval_arg(self.arg, context)

# Get the ordinal value.
if isinstance(param, basestring):
if isinstance(param, str):
try:
param = integer.parseString(param.strip())[0]
except:
Expand Down
4 changes: 2 additions & 2 deletions vipermonkey/core/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@

from pyparsing import *

from logger import log
from vba_object import VBA_Object
from .logger import log
from .vba_object import VBA_Object

# --- BOOLEAN ------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion vipermonkey/core/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import subprocess

from logger import log
from .logger import log

class FakeMeta(object):
pass
Expand Down
12 changes: 6 additions & 6 deletions vipermonkey/core/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@

# --- IMPORTS ------------------------------------------------------------------

from comments_eol import *
from procedures import *
from statements import *
import vba_context
from function_defn_visitor import *
from .comments_eol import *
from .procedures import *
from .statements import *
from . import vba_context
from .function_defn_visitor import *

from logger import log
from .logger import log

# === VBA MODULE AND STATEMENTS ==============================================

Expand Down
4 changes: 2 additions & 2 deletions vipermonkey/core/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@

import sys

from vba_object import *
from .vba_object import *

from logger import log
from .logger import log

def debug_repr(op, args):
r = "("
Expand Down
10 changes: 5 additions & 5 deletions vipermonkey/core/procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@

# --- IMPORTS ------------------------------------------------------------------

from vba_context import *
from statements import *
from identifiers import *
from .vba_context import *
from .statements import *
from .identifiers import *

from logger import log
from tagged_block_finder_visitor import *
from .logger import log
from .tagged_block_finder_visitor import *

# --- SUB --------------------------------------------------------------------

Expand Down
Loading