py-lua-parser icon indicating copy to clipboard operation
py-lua-parser copied to clipboard

Add AST tree replacement class

Open BackTrackCRoot opened this issue 1 month ago • 3 comments

Support for replacing the current node during Visitor traversal.


While using it, I wanted to edit the tree to deobfuscate Lua code, but it seems editing functionality is not supported—only traversal is allowed. Of course, it's also possible that I'm not using it correctly. If that's the case, please close this issue. Currently, the code runs well in my project, though I’m not sure if there are any unknown bugs.

class NumberVisitor(ast.ASTReplaceVisitor):
    def visit_Number(self, node):
        # Replace all Number types with a Number type of value 123. Of course, other types can be returned here, or conditional filtering can be applied.
        return ast.Number(123)
        # If it is not necessary to replace the current one
        # return None

BackTrackCRoot avatar Dec 09 '25 15:12 BackTrackCRoot

if key == 'values' or key == 'args':
    obj_list = getattr(parent, key, None)

The determination of types appears to be incomplete; let's wait until it's corrected before proceeding.

BackTrackCRoot avatar Dec 10 '25 01:12 BackTrackCRoot

Thanks I'm looking how I can integrate this feature in a more generic way into the existing visitor, I'll keep you updated. But for now you can use your implem directly in your code there is no blocker right?

boolangery avatar Dec 11 '25 08:12 boolangery

Thank you very much! The code is currently working fine in my project without any blocking issues. Looking forward to hearing good news. Additionally, I have resolved the issue regarding the incomplete type matching and have already updated it.

BackTrackCRoot avatar Dec 11 '25 15:12 BackTrackCRoot