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

return in Python 3.8 in try ... except #369

Open
Eleiber opened this issue Nov 30, 2021 · 11 comments
Open

return in Python 3.8 in try ... except #369

Eleiber opened this issue Nov 30, 2021 · 11 comments

Comments

@Eleiber
Copy link

Eleiber commented Nov 30, 2021

Description

Hi! I'm trying to decompile a cog from my Discord bot which I overwrote by error. When using uncompyle, all classes except one (the longest one) were recovered. In the last one, I get the following output (I also attached the full output, and the full .pyc):

             3708  POP_TOP          

Parse error at or near `LOAD_CONST' instruction at offset 220


    def setup(bot):
        bot.add_cog(BRCog(bot))

The script raises an error exactly on the last two lines of the code, so there isn't anything after that.

How to Reproduce

$ uncompyle6 battleroyale.cpython-38.pyc > output.txt
# file battleroyale.cpython-38.pyc
# Deparsing stopped due to parse error

Environment

  • OS: Ubuntu Server 20.04 LTS (focal)
  • Python: Python 3.8.10 (default, Sep 28 2021, 16:10:42)
  • Uncompyle6 version: version 3.8.1.dev0

Uncompyle6.zip

@rocky rocky added the Questionable Activity Possibly non-ethical or illegal activity label Nov 30, 2021
@rocky
Copy link
Owner

rocky commented Nov 30, 2021

According to Section 2 of https://www.epicgames.com/fortnite/en-US/eula:

You may not do or attempt to do any of the following with respect to the Software or any of its parts: (a) use it commercially or for a promotional purpose except as Epic expressly authorizes; (b) copy, reproduce, distribute (including via a network server), display, or use it in a way that is not expressly authorized in this Agreement; (c) sell, rent, lease, license, distribute, or otherwise transfer it; (d) reverse engineer, derive source code from, modify, adapt, translate, decompile, or disassemble it or make derivative works based on it

@Eleiber
Copy link
Author

Eleiber commented Nov 30, 2021

Hi! I know you may be confused by the name, but this have absolutely nothing to do with Fortnite, nor Epic Games. It's just a Discord text game which I made from scratch and it's an RNG game, and there are not even guns. I can provide older versions from a week ago as proof if you need them. It's in Spanish and there are no names, texts, images or anything related to Fortnite.
Also Battle Royales didn't come from Fortnite, if I remember correctly there was a book called like that before Fortnite.
Sorry if the name of the file caused any confusion.

@rocky rocky removed the Questionable Activity Possibly non-ethical or illegal activity label Nov 30, 2021
@rocky
Copy link
Owner

rocky commented Nov 30, 2021

Ok - I've deleted the label. Attach an old version. As for a bug report, this bytecode and source code is too large for a bug report here. Use the older source to see of you can create a small example that shows the bug.

@Eleiber
Copy link
Author

Eleiber commented Nov 30, 2021

Okay, already tested and the same error happens on the old source, the lines with problems seem to be the parts of the code where my async functions return None (lines 82, 107, 151), which raises the parse error. I manually deleted those 3 parts from the old source, recompiled the cache and tried with uncompyle, and now it works perfectly. Since those parts were also part of the lost version I am trying to recover, and the error is the same, I'm pretty sure the problems are those empty return.
Here it is the .pyc file of the old source:
battleroyale.cpython-38.zip

@rocky
Copy link
Owner

rocky commented Nov 30, 2021

Ok - cool. The last thing for you to do before it would be looked at in a here is to narrow the part that doesn't decompile into the smallest possible number of lines and resulting in a short program. Can you get it less than 30 lines? Less than 10? Less than 5?

(All of this is mentioned in Narrowing the problem. You should read the entire document if you haven't already.

@Eleiber
Copy link
Author

Eleiber commented Nov 30, 2021

Here it is:

import discord
from discord.ext import commands
import asyncio

class BRCog(commands.Cog):
    async def battle(self, ctx):
        try:
            await self.bot.wait_for('reaction_add')
        except asyncio.TimeoutError:
            await ctx.send("a")
            return

def setup(bot):
    bot.add_cog(BRCog(bot))

And here it is the .pyc, and the output (although the error is the same, LOAD_CONST)
output.zip
I also noticed that when you remove the await ctx.send("a"), or the return, the .py is exported succesfully.

@Eleiber
Copy link
Author

Eleiber commented Nov 30, 2021

I was able to narrow it even more:

import asyncio
def BRCog():
    try:
        1+1
    except asyncio.TimeoutError:
        asyncio.read()
        return

latest.zip

@rocky
Copy link
Owner

rocky commented Dec 1, 2021

I have some preliminary fixes, for some of the simpler code, But more work is needed for the more complex situations.

At any rate fixes will appear in the decompyle3 project - eventually.

@Eleiber
Copy link
Author

Eleiber commented Dec 1, 2021

Sounds good, I also follow the other repo so I'll be looking into that.

@Eleiber
Copy link
Author

Eleiber commented Dec 1, 2021

By now, is there a way to remove those lines from the .pyc or ignore the errors? Since all of the other parts of the code are being parsed correctly except that one.

@rocky
Copy link
Owner

rocky commented Dec 1, 2021

Seems like a useful feature for someone to add. Hey, how about you?

@rocky rocky changed the title "Parse error at or near `LOAD_CONST' instruction at offset 220" at the end of the file returns in Python 3.8 finally clause of try except Dec 2, 2021
@rocky rocky changed the title returns in Python 3.8 finally clause of try except return in Python 3.8 finally clause of try except Dec 2, 2021
@rocky rocky changed the title return in Python 3.8 finally clause of try except return in Python 3.8 finally clause of try ... except Dec 2, 2021
@rocky rocky changed the title return in Python 3.8 finally clause of try ... except return in Python 3.8 in try ... except Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants