Git Product home page Git Product logo

ljd's People

Contributors

ammer avatar aussiemon avatar iroot avatar manuelblanc avatar zaoqi avatar znixian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ljd's Issues

Fix the decompiler crashing if the results of a massive refs function or varargs are used more than once

Problematic place in the code:

assert len(info.references) == 2

Test code:

        _remove_invalid_references()
        if (len(info.references) != 2):
            for ref in info.references:
                print("ID:", ref.identifier.id)
        assert len(info.references) == 2

Output:

ID: 861
ID: 861
ID: 883
ID: 883
  File "\ljd\ast\slotworks.py", line 252, in _fill_massive_refs
    assert len(info.references) == 2
AssertionError

Solution: in array info.references all duplicates should be removed.

Minimize diffs of tables by using trailing comma

Lua tables can have an empty trailing comma. Consider "without" vs "with" trailing comma:

mytable = {
    1,
    2
}
mytable = {
    1,
    2,
}

Now if the next version added the element "3" and you compared the diff, then the "without" version will have 2 changed lines (remove & add) whereas the "with" version will only have one line diff (add three).

Even in my own code I usually add the trailing comma to not forget it later on when extending a table. Since the decompiler output is used mostly in a read-only fashion, I suggest it to be added at all times.

Insert instruction fails

Following code fails for some files (state.debuginfo.addr_to_line_map is empty, so index our of bounds exception is thrown):

line_mapping = state.debuginfo.addr_to_line_map[preceding_index]

My workaround was

    line_mapping = -1
    if preceding_index >= 0 and preceding_index < len(state.debuginfo.addr_to_line_map):
        line_mapping = state.debuginfo.addr_to_line_map[preceding_index]

Not sure if it's a good or bad fix, but it does work.

String constant with special characters failure

Original Lua string constants may contain "unusual" characters, and when such a string is encountered, ljd stops writing more Lua. I am not very familiar with the differences between string encodings, so I can't be more specific about what characters cause this. This is what I did to work around the issue:

I changed value to value.encode('ascii', 'replace').decode() in the following two lines:

https://github.com/Aussiemon/ljd/blob/2ed0381b2e563531b0fe8de0a574cea8e6a04478/ljd/ast/builder.py#LL928C27-L928C27
https://github.com/Aussiemon/ljd/blob/2ed0381b2e563531b0fe8de0a574cea8e6a04478/ljd/ast/builder.py#LL1030C12-L1030C12

This replaces any problematic characters with ? so information is lost. I am not sure what the real fix would look like that does not lose this information.

AST mutation in depth

To put it simply, is there a way to replace an AST node by an unrelated one (possibly constructed on the fly during traversal)? For example, flattening loadstring("...")("...")

luajit-2.1.0-beta3 error

Traceback (most recent call last):
  File "main.py", line 476, in <module>
    retval = main_obj.main()
  File "main.py", line 301, in main
    ast = self.decompile(self.options.file_name)
  File "main.py", line 411, in decompile
    ljd.ast.unwarper.unwarp(ast, False)
  File "/tools/ljd/ljd/ast/unwarper.py", line 94, in unwarp
    _run_step(_unwarp_ifs, node)
  File "/tools/ljd/ljd/ast/unwarper.py", line 137, in _run_step
    statements.contents = step(statements.contents, **kargs)
  File "/tools/ljd/ljd/ast/unwarper.py", line 392, in _unwarp_ifs
    _unwarp_if_statement(start, body, end, end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 1704, in _unwarp_if_statement
    else_blocks = _unwarp_ifs(else_body, else_body[-1], topmost_end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 392, in _unwarp_ifs
    _unwarp_if_statement(start, body, end, end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 1704, in _unwarp_if_statement
    else_blocks = _unwarp_ifs(else_body, else_body[-1], topmost_end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 392, in _unwarp_ifs
    _unwarp_if_statement(start, body, end, end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 1704, in _unwarp_if_statement
    else_blocks = _unwarp_ifs(else_body, else_body[-1], topmost_end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 392, in _unwarp_ifs
    _unwarp_if_statement(start, body, end, end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 1700, in _unwarp_if_statement
    then_blocks = _unwarp_ifs(then_body, then_body[-1], topmost_end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 392, in _unwarp_ifs
    _unwarp_if_statement(start, body, end, end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 1728, in _unwarp_if_statement
    then_blocks = _unwarp_ifs(body, body[-1], topmost_end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 392, in _unwarp_ifs
    _unwarp_if_statement(start, body, end, end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 1669, in _unwarp_if_statement
    topmost_end)
  File "/tools/ljd/ljd/ast/unwarper.py", line 1766, in _extract_if_expression
    assert false is not None
AssertionError

this is file zip
1 (2).zip

issuse2

There is one more question. It's during decompilation. There will be many uv0 that cannot obtain its actual function

image

too many arguments

hello i tried to convert luajt languages to lua but show this error in cmd with administator mode why?

python "C:\luajit\main.py" "C:\luajit\AISowingCultivatorFix.lua" "C:\luajit\lua\AISowingCultivatorFix.lua"
Usage: main.py [options]

main.py: error: Too many arguments.

TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'

Hello,I tried to decompile luajit, but the following error occurred:
Traceback (most recent call last):
File "main.py", line 468, in
retval = main_obj.main()
File "main.py", line 299, in main
ast = self.decompile(self.options.file_name)
File "main.py", line 403, in decompile
ljd.ast.unwarper.unwarp(ast, False)
File "C:\Users\xxx\Desktop\ljd-2021_revision\ljd\ast\unwarper.py", line 51, in unwarp
_run_step(_fix_loops, node, repeat_until=False)
File "C:\Users\xxx\Desktop\ljd-2021_revision\ljd\ast\unwarper.py", line 137, in _run_step
statements.contents = step(statements.contents, **kargs)
File "C:\Users\xxx\Desktop\ljd-2021_revision\ljd\ast\unwarper.py", line 1794, in _fix_loops
blocks = _handle_single_loop(start, end, blocks, repeat_until)
File "C:\Users\xxx\Desktop\ljd-2021_revision\ljd\ast\unwarper.py", line 1870, in _handle_single_loop
loop = _unwarp_loop(start, end, body)
File "C:\Users\xxx\Desktop\ljd-2021_revision\ljd\ast\unwarper.py", line 2070, in _unwarp_loop
expression = expr_body + body[:i]
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.