Ejemplo n.º 1
0
def decompile(conffile,
              force_jad,
              force_csv,
              no_recompile,
              no_comments,
              no_reformat,
              no_renamer,
              no_patch,
              only_patch,
              keep_lvt,
              keep_generics,
              only_client,
              only_server,
              force_rg,
              workdir,
              json,
              nocopy,
              only_joined=False):
    try:
        commands = Commands(conffile,
                            verify=True,
                            no_patch=no_patch,
                            workdir=workdir,
                            json=json)

        commands.checkupdates()

        if not commands.has_ss:
            force_rg = True

        use_ff = commands.has_ff and not force_jad
        use_srg = commands.has_srg and not force_csv

        if force_jad and not commands.has_jad:
            commands.logger.error('!! forcing jad when not available !!')
            sys.exit(1)

        if force_rg and not commands.has_rg:
            commands.logger.error(
                '!! forcing retroguard when not available !!')
            sys.exit(1)

        if force_csv and not commands.has_map_csv:
            commands.logger.error('!! forcing csvs when not available !!')
            sys.exit(1)

        # client or server
        process_client = True
        process_server = True
        if only_client and not only_server:
            process_server = False
        if only_server and not only_client:
            process_client = False
        if only_joined and not only_server and not only_client:
            process_server = False

        # always strip comments by default, turn off in update mode if required
        strip_comments = True

        # update only options
        rg_update = False
        exc_update = False

        if no_patch:
            # no_patch is basically update mode, disables everything
            # and reuses a few different options to do update stuff
            if only_patch:
                # with only_patch then we actually do the patches, but not the comment stripping, for use when updating
                # the fernflower patches
                no_patch = False
                strip_comments = False
            if no_reformat:
                # reuse -a no_reformat to switch rg to fullmap=1 startindex=RGIndex
                rg_update = True
            if no_renamer:
                # reuse -n to switch mcinjector to outputing exc file, and adding new parameters
                exc_update = True
            no_comments = True
            no_reformat = True
            no_renamer = True
            no_recompile = True
        elif only_patch:
            # if only_patch then disable everything but patching and comment stripping
            no_comments = True
            no_reformat = True
            no_renamer = True
            no_recompile = True

        # if we have generics enabled we need the lvt as well
        if keep_generics:
            keep_lvt = True

        if force_rg:
            commands.logger.info('> Creating Retroguard config files')
            commands.creatergcfg(reobf=False,
                                 keep_lvt=keep_lvt,
                                 keep_generics=keep_generics,
                                 rg_update=rg_update,
                                 joined_jar=only_joined)

        if not nocopy:
            clientCopy.copyClientAssets(commands, workdir)

        commands.setupjsr305()

        try:
            if process_client:
                cltdecomp = decompile_side(commands,
                                           CLIENT,
                                           use_ff=use_ff,
                                           use_srg=use_srg,
                                           no_comments=no_comments,
                                           no_reformat=no_reformat,
                                           no_renamer=no_renamer,
                                           no_patch=no_patch,
                                           strip_comments=strip_comments,
                                           exc_update=exc_update,
                                           keep_lvt=keep_lvt,
                                           keep_generics=keep_generics,
                                           force_rg=force_rg,
                                           rg_update=rg_update,
                                           joined=only_joined)
            else:
                cltdecomp = False
            if process_server:
                srvdecomp = decompile_side(commands,
                                           SERVER,
                                           use_ff=use_ff,
                                           use_srg=use_srg,
                                           no_comments=no_comments,
                                           no_reformat=no_reformat,
                                           no_renamer=no_renamer,
                                           no_patch=no_patch,
                                           strip_comments=strip_comments,
                                           exc_update=exc_update,
                                           keep_lvt=keep_lvt,
                                           keep_generics=keep_generics,
                                           force_rg=force_rg,
                                           rg_update=rg_update)
            else:
                srvdecomp = False
        except CalledProcessError:
            # retroguard or other called process error so bail
            commands.logger.error('Decompile failed')
            sys.exit(1)
        if not no_recompile:
            if cltdecomp:
                try:
                    updatemd5_side(commands, CLIENT)
                except CalledProcessError:
                    commands.logger.error(
                        'Initial client recompile failed, correct source then run updatemd5'
                    )
            if srvdecomp:
                try:
                    updatemd5_side(commands, SERVER)
                except CalledProcessError:
                    commands.logger.error(
                        'Initial server recompile failed, correct source then run updatemd5'
                    )
        else:
            commands.logger.info('!! recompile disabled !!')
    except Exception:  # pylint: disable-msg=W0703
        logging.exception('FATAL ERROR')
        sys.exit(1)
Ejemplo n.º 2
0
def decompile(conffile, force_jad, force_csv, no_recompile, no_comments, no_reformat, no_renamer, no_patch, only_patch,
              keep_lvt, keep_generics, only_client, only_server):
    try:
        commands = Commands(conffile, verify=True, no_patch=no_patch)

        commands.checkupdates()

        use_ff = commands.has_ff and not force_jad
        use_srg = commands.has_srg and not force_csv

        if force_jad and not commands.has_jad:
            commands.logger.error('!! forcing jad when not available !!')
            sys.exit(1)

        if force_csv and not commands.has_map_csv:
            commands.logger.error('!! forcing csvs when not available !!')
            sys.exit(1)

        # client or server
        process_client = True
        process_server = True
        if only_client and not only_server:
            process_server = False
        if only_server and not only_client:
            process_client = False

        # always strip comments by default, turn off in update mode if required
        strip_comments = True

        # update only options
        rg_update = False
        exc_update = False

        if no_patch:
            # no_patch is basically update mode, disables everything
            # and reuses a few different options to do update stuff
            if only_patch:
                # with only_patch then we actually do the patches, but not the comment stripping, for use when updating
                # the fernflower patches
                no_patch = False
                strip_comments = False
            if no_reformat:
                # reuse -a no_reformat to switch rg to fullmap=1 startindex=RGIndex
                rg_update = True
            if no_renamer:
                # reuse -n to switch mcinjector to outputing exc file, and adding new parameters
                exc_update = True
            no_comments = True
            no_reformat = True
            no_renamer = True
            no_recompile = True
        elif only_patch:
            # if only_patch then disable everything but patching and comment stripping
            no_comments = True
            no_reformat = True
            no_renamer = True
            no_recompile = True

        # if we have generics enabled we need the lvt as well
        if keep_generics:
            keep_lvt = True

        commands.logger.info('> Creating Retroguard config files')
        commands.creatergcfg(reobf=False, keep_lvt=keep_lvt, keep_generics=keep_generics, rg_update=rg_update)

        try:
            if process_client:
                cltdecomp = decompile_side(commands, CLIENT, use_ff=use_ff, use_srg=use_srg, no_comments=no_comments,
                                           no_reformat=no_reformat, no_renamer=no_renamer, no_patch=no_patch,
                                           strip_comments=strip_comments, exc_update=exc_update)
            else:
                cltdecomp = False
            if process_server:
                srvdecomp = decompile_side(commands, SERVER, use_ff=use_ff, use_srg=use_srg, no_comments=no_comments,
                                           no_reformat=no_reformat, no_renamer=no_renamer, no_patch=no_patch,
                                           strip_comments=strip_comments, exc_update=exc_update)
            else:
                srvdecomp = False
        except CalledProcessError:
            # retroguard or other called process error so bail
            commands.logger.error('Decompile failed')
            sys.exit(1)
        if not no_recompile:
            if cltdecomp:
                try:
                    updatemd5_side(commands, CLIENT)
                except CalledProcessError:
                    commands.logger.error('Initial client recompile failed, correct source then run updatemd5')
            if srvdecomp:
                try:
                    updatemd5_side(commands, SERVER)
                except CalledProcessError:
                    commands.logger.error('Initial server recompile failed, correct source then run updatemd5')
        else:
            commands.logger.info('!! recompile disabled !!')
    except Exception:  # pylint: disable-msg=W0703
        logging.exception('FATAL ERROR')
        sys.exit(1)