对于包含switch语句的class文件进行反编译发现的问题

 

对于有switch语句 反编译的java 文件 需要注意 如果 有switch语句 则重点观察 break 使用情况,检查 case 后 break是否丢失。
经过比较DJ Java Decompiler 和Java Decompiler 两个工具 发现Java Decompiler 对于switch语句处理丢失break 语句。
所以涉及switch语句的方法综合两个工具得到最后结果,以Java Decompiler为主,DJ Java Decompiler为辅,因为DJ Java Decompiler中数字变成了16进制,而且DJ Java Decompiler 中 简单if语句会被简化掉花括号。

案例:

源码如下:

    protected Long doSubmit(ActionForm form) throws GenericException {
        OUserForm oForm = (OUserForm) form;
        int operType = oForm.getOperType();
        Long userId = null;
        UserTransaction ut = Trans.getUserTransaction();
        try {
            ut.begin();
            switch (operType) {
            case 1001:
                try {
                    userId = new Long(oForm.getUserId());
                    UserVO oUser = SysMgmtDSLocator.getUserDS()
                            .getUserByUserID(userId);
                    updateProcess(oForm);
                    Audit.doAudit(22, userId.intValue(), 99003,
                            "Save basic information of the user");
                    String stat = oForm.getUserStat();
                    if ((stat != null)
                            && (stat.equals(CodeConstant.YES_NO__YES))
                            && (!oUser.getDisable().booleanValue())) {
                        Audit.doAudit(49, userId.intValue(), 99003,
                                "User Account Lock");
                    }
                    if ((stat != null)
                            && (stat.equals(CodeConstant.YES_NO__NO))
                            && (oUser.getDisable().booleanValue())) {
                        Audit.doAudit(50, userId.intValue(), 99003,
                                "User Account Unlock");
                    }
                    break;
                } catch (GenericException ex) {
                    logger.error("Encounter Exception when update a user! Exception Massage:"
                            + ex.getMessage());
                    throw ex;
                }
            case 1002:
                try {
                    userId = createProcess(oForm);
                    Audit.doAudit(24, userId.intValue(), 99003, "create a user");
                    break;
                } catch (GenericException ex) {
                    logger.error("Encounter Exception when create a user! Exception Massage:"
                            + ex.getMessage());
                    throw ex;
                }
            case 1003:
                break;
            }
            ut.commit();
        } catch (GenericException ex) {
            try {
                ut.rollback();
            } catch (SystemException se) {
                logger.error("Encounter Exception when transaction rollback ! Exception Massage:"
                        + se.getMessage());
                throw ExceptionFactory.parse(se);
            }
            throw ex;
        } catch (Exception e) {
            try {
                ut.rollback();
            } catch (SystemException se) {
                logger.error("Encounter Exception when transaction rollback ! Exception Massage:"
                        + se.getMessage());

                throw ExceptionFactory.parse(se);
            }
            throw ExceptionFactory.parse(e);
        }
        return userId;
    }

使用

Java Decompiler 反编译结果如下:

  protected Long doSubmit(ActionForm form)
    throws GenericException
  {
    OUserForm oForm = (OUserForm)form;
    int operType = oForm.getOperType();
    Long userId = null;
    UserTransaction ut = Trans.getUserTransaction();
    try
    {
      ut.begin();
      switch (operType)
      {
      case 1001: 
        try
        {
          userId = new Long(oForm.getUserId());
          UserVO oUser = SysMgmtDSLocator.getUserDS()
            .getUserByUserID(userId);
          updateProcess(oForm);
          Audit.doAudit(22, userId.intValue(), 99003, 
            "Save basic information of the user");
          String stat = oForm.getUserStat();
          if ((stat != null) && 
            (stat.equals(CodeConstant.YES_NO__YES)) && 
            (!oUser.getDisable().booleanValue())) {
            Audit.doAudit(49, userId.intValue(), 99003, 
              "User Account Lock");
          }
          if ((stat != null) && 
            (stat.equals(CodeConstant.YES_NO__NO)) && 
            (oUser.getDisable().booleanValue())) {
            Audit.doAudit(50, userId.intValue(), 99003, 
              "User Account Unlock");
          }
        }
        catch (GenericException ex)
        {
          logger.error("Encounter Exception when update a user! Exception Massage:" + 
            ex.getMessage());
          throw ex;
        }
      case 1002: 
        try
        {
          userId = createProcess(oForm);
          Audit.doAudit(24, userId.intValue(), 99003, "create a user");
        }
        catch (GenericException ex)
        {
          logger.error("Encounter Exception when create a user! Exception Massage:" + 
            ex.getMessage());
          throw ex;
        }
      }
      ut.commit();
    }
    catch (GenericException ex)
    {
      try
      {
        ut.rollback();
      }
      catch (SystemException se)
      {
        logger.error("Encounter Exception when transaction rollback ! Exception Massage:" + 
          se.getMessage());
        throw ExceptionFactory.parse(se);
      }
      throw ex;
    }
    catch (Exception e)
    {
      try
      {
        ut.rollback();
      }
      catch (SystemException se)
      {
        logger.error("Encounter Exception when transaction rollback ! Exception Massage:" + 
          se.getMessage());
        
        throw ExceptionFactory.parse(se);
      }
      throw ExceptionFactory.parse(e);
    }
    return userId;
  }

使用

DJ Java Decompiler 反编译结果如下:

    protected Long doSubmit(ActionForm form)
        throws GenericException
    {
        OUserForm oForm = (OUserForm)form;
        int operType = oForm.getOperType();
        Long userId = null;
        UserTransaction ut = Trans.getUserTransaction();
        try
        {
            ut.begin();
            switch(operType)
            {
            case 1003: 
            default:
                break;
            case 1001: 
                try
                {
                    userId = new Long(oForm.getUserId());
                    UserVO oUser = SysMgmtDSLocator.getUserDS().getUserByUserID(userId);
                    updateProcess(oForm);
                    Audit.doAudit(22, userId.intValue(), 0x182bb, "Save basic information of the user");
                    String stat = oForm.getUserStat();
                    if(stat != null && stat.equals(CodeConstant.YES_NO__YES) && !oUser.getDisable().booleanValue())
                        Audit.doAudit(49, userId.intValue(), 0x182bb, "User Account Lock");
                    if(stat != null && stat.equals(CodeConstant.YES_NO__NO) && oUser.getDisable().booleanValue())
                        Audit.doAudit(50, userId.intValue(), 0x182bb, "User Account Unlock");
                    break;
                }
                catch(GenericException ex)
                {
                    logger.error((new StringBuilder("Encounter Exception when update a user! Exception Massage:")).append(ex.getMessage()).toString());
                    throw ex;
                }
            case 1002: 
                try
                {
                    userId = createProcess(oForm);
                    Audit.doAudit(24, userId.intValue(), 0x182bb, "create a user");
                    break;
                }
                catch(GenericException ex)
                {
                    logger.error((new StringBuilder("Encounter Exception when create a user! Exception Massage:")).append(ex.getMessage()).toString());
                    throw ex;
                }
            }
            ut.commit();
        }
        catch(GenericException ex)
        {
            try
            {
                ut.rollback();
            }
            catch(SystemException se)
            {
                logger.error((new StringBuilder("Encounter Exception when transaction rollback ! Exception Massage:")).append(se.getMessage()).toString());
                throw ExceptionFactory.parse(se);
            }
            throw ex;
        }
        catch(Exception e)
        {
            try
            {
                ut.rollback();
            }
            catch(SystemException se)
            {
                logger.error((new StringBuilder("Encounter Exception when transaction rollback ! Exception Massage:")).append(se.getMessage()).toString());
                throw ExceptionFactory.parse(se);
            }
            throw ExceptionFactory.parse(e);
        }
        return userId;
    }

 

posted @ 2017-05-16 15:11  亚北  阅读(1030)  评论(0编辑  收藏  举报