CensoredUsername / unrpyc

A ren'py script decompiler
Other
861 stars 157 forks source link

Failed Decompilation - 29 Jul 2019 - Renpy 7.3.2 #81

Closed SergioLopezJAAS closed 5 years ago

SergioLopezJAAS commented 5 years ago

Microsoft Windows [Versión 10.0.18362.239] (c) 2019 Microsoft Corporation. Todos los derechos reservados.

C:\Users\Sergio Lopez>cd c:/prbrpa

c:\PrbRpa>c:\python27\python.exe C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py -c C:\PrbRpa\rpyc-game\displayables.rpyc Decompiling C:\PrbRpa\rpyc-game\displayables.rpyc to C:\PrbRpa\rpyc-game\displayables.rpy... Error while decompiling C:\PrbRpa\rpyc-game\displayables.rpyc: Traceback (most recent call last): File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py", line 146, in worker no_pyexpr=args.no_pyexpr, comparable=args.comparable, translator=translator, init_offset=args.init_offset) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py", line 111, in decompile_rpyc ast = read_ast_from_file(in_file) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py", line 89, in read_ast_from_file data, stmts = magic.safe_loads(raw_contents, class_factory, {"_ast", "collections"}) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\decompiler\magic.py", line 599, in safe_loads encoding=encoding, errors=errors).load() File "c:\python27\lib\pickle.py", line 864, in load dispatchkey File "c:\python27\lib\pickle.py", line 1223, in load_build setstate(state) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\decompiler\magic.py", line 127, in setstate raise FakeUnpicklingError("{0}.setstate() got unexpected arguments {1}".format(self.class, state)) FakeUnpicklingError: <class 'renpy.python.RevertableSet'>.setstate() got unexpected arguments ({u'default': True, u'without': True},)

Decompilation of 1 file failed

CensoredUsername commented 5 years ago

I pushed some fixes to the dev branch, could you try them out?

SergioLopezJAAS commented 5 years ago

Thank CensoredUsername, I try that, I say you

SergioLopezJAAS commented 5 years ago

The error continue, I don't what happend , I Don't speak english but I want to help you

Microsoft Windows [Versión 10.0.18362.239] (c) 2019 Microsoft Corporation. Todos los derechos reservados.

C:\Users\Sergio Lopez>cd c:/prbrpa

c:\PrbRpa>c:\python27\python.exe C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py -c C:\PrbRpa\rpyc-game\displayables.rpyc Decompiling C:\PrbRpa\rpyc-game\displayables.rpyc to C:\PrbRpa\rpyc-game\displayables.rpy... Error while decompiling C:\PrbRpa\rpyc-game\displayables.rpyc: Traceback (most recent call last): File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py", line 151, in worker no_pyexpr=args.no_pyexpr, comparable=args.comparable, translator=translator, init_offset=args.init_offset) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py", line 116, in decompile_rpyc ast = read_ast_from_file(in_file) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py", line 94, in read_ast_from_file data, stmts = magic.safe_loads(raw_contents, class_factory, {"_ast", "collections"}) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\decompiler\magic.py", line 599, in safe_loads encoding=encoding, errors=errors).load() File "c:\python27\lib\pickle.py", line 864, in load dispatchkey File "c:\python27\lib\pickle.py", line 1223, in load_build setstate(state) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\decompiler\magic.py", line 127, in setstate raise FakeUnpicklingError("{0}.setstate() got unexpected arguments {1}".format(self.class, state)) FakeUnpicklingError: <class 'renpy.python.RevertableSet'>.setstate() got unexpected arguments ({u'default': True, u'without': True},)

Decompilation of 1 file failed

c:\PrbRpa>

CensoredUsername commented 5 years ago

Ah, looks like RevertableSet has a custom setstate impl. I've pushed another fix for it to the dev branch, hopefully it works now! Thanks for the testing.

SergioLopezJAAS commented 5 years ago

okay. Try the last change and the problem continues, You tell me what I can do to help more. I run The unrpyc today (01/Ago/2019), with your last archive

My python 2.7 version is 2.7.16

c:\PrbRpa>c:\python27\python.exe C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py -c C:\PrbRpa\rpyc-game\script.rpyc Decompiling C:\PrbRpa\rpyc-game\script.rpyc to C:\PrbRpa\rpyc-game\script.rpy... Error while decompiling C:\PrbRpa\rpyc-game\script.rpyc: Traceback (most recent call last): File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py", line 157, in worker no_pyexpr=args.no_pyexpr, comparable=args.comparable, translator=translator, init_offset=args.init_offset) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py", line 122, in decompile_rpyc ast = read_ast_from_file(in_file) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py", line 100, in read_ast_from_file data, stmts = magic.safe_loads(raw_contents, class_factory, {"_ast", "collections"}) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\decompiler\magic.py", line 599, in safe_loads encoding=encoding, errors=errors).load() File "c:\python27\lib\pickle.py", line 864, in load dispatchkey File "c:\python27\lib\pickle.py", line 1139, in load_reduce value = func(*args) File "C:\PrbRpa\UnrpyC\unrpyc-1.0.15\decompiler\magic.py", line 113, in new raise FakeUnpicklingError("{0} was instantiated with unexpected arguments {1}, {2}".format(cls, args, kwargs)) FakeUnpicklingError: <class 'renpy.object.Sentinel'> was instantiated with unexpected arguments (u'NotSet',), {}

Decompilation of 1 file failed

c:\PrbRpa>

harikattar commented 5 years ago

Commenting out the test on line 112,113 produces a human-readable file, but obviously it doesn't compile back to the input.

E: To clarify

diff --git a/decompiler/magic.py b/decompiler/magic.py
index f7163de..27717c5 100644
--- a/decompiler/magic.py
+++ b/decompiler/magic.py
@@ -110,7 +110,8 @@ class FakeStrict(FakeClass, object):
     def __new__(cls, *args, **kwargs):
         self = FakeClass.__new__(cls)
         if args or kwargs:
-            raise FakeUnpicklingError("{0} was instantiated with unexpected arguments {1}, {2}".format(cls, args, kwargs))
+            pass
+            # raise FakeUnpicklingError("{0} was instantiated with unexpected arguments {1}, {2}".format(cls, args, kwargs))
         return self

     def __setstate__(self, state):
SergioLopezJAAS commented 5 years ago

Hi, sorry if I bother you, but I am still learning to understand Github, the problem with unrpyc.py continues, I have updated the last branch, but it still does not work. I am learning python, I work adjusting office solutions with Visual Basic and VBA for applications, I would appreciate the recommendation of a book or manual for python, Thank you and excuse me for mixing 2 topics.

CensoredUsername commented 5 years ago

Hey @SergioLopezJAAS , don't worry about it, I just wasn't online the last days. Unfortunately the issues are mostly stemming from some special class definitions in Ren'Py that need to be coded into unrpyc to allow deserialization of the compiled script files. The whole deserialization system is pretty complex python. It might be easier if you could just send me a failing .rpyc file and I can add all the missing definitions (and figure out what's causing them to actually end up in the file as I don't recall anything that would pull these definitions in).

As for books on python, I don't know anything in particular. I can recommend starting out with the tutorial: https://docs.python.org/3/tutorial/index.html , but I can't recommend any specific book.

SergioLopezJAAS commented 5 years ago

Thank you.

I sent you this file.

script.zip

This archive not work.

00modules.zip

And this archive work

CensoredUsername commented 5 years ago

Hey, I've added the relevant definitions and it should just work now. Feel free to check with the dev branch, and if it works I'll push it to master.

SergioLopezJAAS commented 5 years ago

Thanks very much, Work, work very good.

I thanks you and I want to help you. You tell me how I help, please.

Thanks you

SergioLopezJAAS commented 5 years ago

Hi, I don't know this message ,

C:\PrbRpa>c:\python27\python.exe C:\PrbRpa\UnrpyC\unrpyc-1.0.15\unrpyc.py -c C:\PrbRpa\rpyc-game\screens.rpyc Decompiling C:\PrbRpa\rpyc-game\screens.rpyc to C:\PrbRpa\rpyc-game\screens.rpy... Warning: Encountered a user-defined displayable of type '<class 'store.ImageTextButton'>'. Unfortunately, the name of user-defined displayables is not recorded in the compiled file. For now the style name 'imagetext_fixed' will be substituted. To check if this is correct, find the corresponding renpy.register_sl_displayable call. Warning: Encountered a user-defined displayable of type '<class 'store.ImageTextButton'>'. Unfortunately, the name of user-defined displayables is not recorded in the compiled file. For now the style name 'imagetext_fixed' will be substituted. To check if this is correct, find the corresponding renpy.register_sl_displayable call. Warning: Encountered a user-defined displayable of type '<class 'store.ImageTextButton'>'. Unfortunately, the name of user-defined displayables is not recorded in the compiled file. For now the style name 'imagetext_fixed' will be substituted. To check if this is correct, find the corresponding renpy.register_sl_displayable call. Warning: Encountered a user-defined displayable of type '<class 'store.ImageTextButton'>'. Unfortunately, the name of user-defined displayables is not recorded in the compiled file. For now the style name 'imagetext_fixed' will be substituted. To check if this is correct, find the corresponding renpy.register_sl_displayable call. Warning: Encountered a user-defined displayable of type '<class 'store.ImageTextButton'>'. Unfortunately, the name of user-defined displayables is not recorded in the compiled file. For now the style name 'imagetext_fixed' will be substituted. To check if this is correct, find the corresponding renpy.register_sl_displayable call. Warning: Encountered a user-defined displayable of type '<class 'store.ImageTextButton'>'. Unfortunately, the name of user-defined displayables is not recorded in the compiled file. For now the style name 'imagetext_fixed' will be substituted. To check if this is correct, find the corresponding renpy.register_sl_displayable call. Warning: Encountered a user-defined displayable of type '<class 'store.ImageTextButton'>'. Unfortunately, the name of user-defined displayables is not recorded in the compiled file. For now the style name 'imagetext_fixed' will be substituted. To check if this is correct, find the corresponding renpy.register_sl_displayable call. Warning: Encountered a user-defined displayable of type '<class 'store.ImageTextButton'>'. Unfortunately, the name of user-defined displayables is not recorded in the compiled file. For now the style name 'imagetext_fixed' will be substituted. To check if this is correct, find the corresponding renpy.register_sl_displayable call. Decompilation of 1 script file successful

when I decompiled that file:

screens.zip

CensoredUsername commented 5 years ago

The message indicates that ren'py encountered a piece of code which it couldn't decompile completely, due to usage of custom screen displayables. Unfortunately ren'py doesn't record the actual name of said displayables into the compiled datastructures.

If you find a call to renpy.register_sl_displayable in any other file of the game it will show what the actually used name was.

This is unfortunately a limitation of the .rpyc format and not a bug.

SergioLopezJAAS commented 5 years ago

Thanks you, I found that in a archive ( CDSL.rpym) :

python early: def ImageTextButton( text, idle, hover=None, insensitive=None, selected_idle=None, selected_hover=None, selected_insensitive=None, style="imagetext_fixed", text_style="imagetext_text", button_style="imagetext_button", scope=None, **properties ): text_props = {} button_props = {} fixedprops = {} for key, value in properties.items(): if key.startswith("text"): textprops[key[5:]] = value elif key.startswith("button"): button_props[key[7:]] = value elif key in renpy.sl2.slproperties.position_property_names: fixed_props[key] = value elif key in renpy.sl2.slproperties.box_property_names: fixed_props[key] = value else: button_props[key] = value

    t_transform = text_props.pop("at", [])
    text_d = Text(text, style=text_style, scope=scope, **text_props)
    text = _invoke_transform(text_d, t_transform)

    b_transform = button_props.pop("at", [])
    image_d = ImageButton(idle, hover, insensitive, selected_idle, selected_hover, selected_insensitive, style=button_style, **button_props)
    image = _invoke_transform(image_d, b_transform)

    rv = Fixed(image, text, style=style, **fixed_props)
    rv._main = text_d
    rv._composite_parts = [image_d, text_d]
    return rv

(**renpy.register_sl_displayable("imagetextbutton", ImageTextButton, "imagetext_fixed", scope=True**)
    .add_positional("text")
    .add_property("idle")
    .add_property("hover")
    .add_property("insensitive")
    .add_property("selected_idle")
    .add_property("selected_hover")
    .add_property("selected_insensitive")
    .add_property_group("button")
    .add_property_group("window")
    .add_property_group("box")
    .add_property_group("position", "button_")
    .add_property_group("ui", "button_")
    .add_property_group("ui", "text_")
    .add_property_group("position", "text_")
    .add_property_group("text", "text_")
    .add(renpy.sl2.slparser.if_statement)
)

def ColoredTextButton(
    text,
    idle_color,
    hover_color=None,
    insensitive_color=None,
    selected_idle_color=None,
    selected_hover_color=None,
    selected_insensitive_color=None,
    style="commonbutton_fixed",
    text_style="commonbutton_text",
    button_style="commonbutton_button",
    scope=None,
    **properties
):
    def colorize(color):
        if color is None:
            return None
        return im.Color("gui/button/common_button.png", color)

    if idle_color is None:
        raise Exception("ColoredTextButton does not have a idle_color.")
    idle = colorize(idle_color)

    hover = colorize(hover_color) or idle
    insensitive = colorize(insensitive_color) or idle
    selected_idle = colorize(selected_idle_color) or idle
    selected_hover = colorize(selected_hover_color) or hover
    selected_insensitive = colorize(selected_insensitive_color) or insensitive

    return ImageTextButton(text, idle, hover, insensitive, selected_idle, selected_hover, selected_insensitive, style, text_style, button_style, scope, **properties)

**(renpy.register_sl_displayable("coloredtextbutton", ColoredTextButton, "commonbutton_fixed", scope=True)**
    .add_positional("text")
    .add_property("idle_color")
    .add_property("hover_color")
    .add_property("insensitive_color")
    .add_property("selected_idle_color")
    .add_property("selected_hover_color")
    .add_property("selected_insensitive_color")
    .add_property_group("button")
    .add_property_group("window")
    .add_property_group("box")
    .add_property_group("position", "button_")
    .add_property_group("ui", "button_")
    .add_property_group("ui", "text_")
    .add_property_group("position", "text_")
    .add_property_group("text", "text_")
    .add(renpy.sl2.slparser.if_statement)
)
SergioLopezJAAS commented 5 years ago

`python early: def ImageTextButton( text, idle, hover=None, insensitive=None, selected_idle=None, selected_hover=None, selected_insensitive=None, style="imagetext_fixed", text_style="imagetext_text", button_style="imagetext_button", scope=None, **properties ): text_props = {} button_props = {} fixedprops = {} for key, value in properties.items(): if key.startswith("text"): textprops[key[5:]] = value elif key.startswith("button"): button_props[key[7:]] = value elif key in renpy.sl2.slproperties.position_property_names: fixed_props[key] = value elif key in renpy.sl2.slproperties.box_property_names: fixed_props[key] = value else: button_props[key] = value

    t_transform = text_props.pop("at", [])
    text_d = Text(text, style=text_style, scope=scope, **text_props)
    text = _invoke_transform(text_d, t_transform)

    b_transform = button_props.pop("at", [])
    image_d = ImageButton(idle, hover, insensitive, selected_idle, selected_hover, selected_insensitive, style=button_style, **button_props)
    image = _invoke_transform(image_d, b_transform)

    rv = Fixed(image, text, style=style, **fixed_props)
    rv._main = text_d
    rv._composite_parts = [image_d, text_d]
    return rv

(renpy.register_sl_displayable("imagetextbutton", ImageTextButton, "imagetext_fixed", scope=True)
    .add_positional("text")
    .add_property("idle")
    .add_property("hover")
    .add_property("insensitive")
    .add_property("selected_idle")
    .add_property("selected_hover")
    .add_property("selected_insensitive")
    .add_property_group("button")
    .add_property_group("window")
    .add_property_group("box")
    .add_property_group("position", "button_")
    .add_property_group("ui", "button_")
    .add_property_group("ui", "text_")
    .add_property_group("position", "text_")
    .add_property_group("text", "text_")
    .add(renpy.sl2.slparser.if_statement)
)

def ColoredTextButton(
    text,
    idle_color,
    hover_color=None,
    insensitive_color=None,
    selected_idle_color=None,
    selected_hover_color=None,
    selected_insensitive_color=None,
    style="commonbutton_fixed",
    text_style="commonbutton_text",
    button_style="commonbutton_button",
    scope=None,
    **properties
):
    def colorize(color):
        if color is None:
            return None
        return im.Color("gui/button/common_button.png", color)

    if idle_color is None:
        raise Exception("ColoredTextButton does not have a idle_color.")
    idle = colorize(idle_color)

    hover = colorize(hover_color) or idle
    insensitive = colorize(insensitive_color) or idle
    selected_idle = colorize(selected_idle_color) or idle
    selected_hover = colorize(selected_hover_color) or hover
    selected_insensitive = colorize(selected_insensitive_color) or insensitive

    return ImageTextButton(text, idle, hover, insensitive, selected_idle, selected_hover, selected_insensitive, style, text_style, button_style, scope, **properties)

(renpy.register_sl_displayable("coloredtextbutton", ColoredTextButton, "commonbutton_fixed", scope=True)
    .add_positional("text")
    .add_property("idle_color")
    .add_property("hover_color")
    .add_property("insensitive_color")
    .add_property("selected_idle_color")
    .add_property("selected_hover_color")
    .add_property("selected_insensitive_color")
    .add_property_group("button")
    .add_property_group("window")
    .add_property_group("box")
    .add_property_group("position", "button_")
    .add_property_group("ui", "button_")
    .add_property_group("ui", "text_")
    .add_property_group("position", "text_")
    .add_property_group("text", "text_")
    .add(renpy.sl2.slparser.if_statement)
)

`

SergioLopezJAAS commented 5 years ago

I really excuse me for answer but Where I look up... this? renpy.register_sl_displayable("imagetextbutton", ImageTextButton, "imagetext_fixed", scope=True

I look in directory renpy of game : "XXXGAME"/renpy/

and I look in sub-categories:

XXXGAME/renpy/SL2 ... and .... XXXGAME/renpy/display

Am I doing good? I don't know

CensoredUsername commented 5 years ago

You've found the offending renpy.register_sl_displayable calls, which defined custom displayables "imagetextbutton" and "coloredtextbutton". Looks like the decompiler guessed then to be called "imagetext_fixed" and "commonbutton_fixed" instead. So if you fix those in the decompiled files everything should work.

CensoredUsername commented 5 years ago

Marking this as closed as it seems to have been resolved.