推荐两款工具 结合使用
1、Java Decompiler
这款反编译器叫 “Java Decompiler”, 由 Pavel Kouznetsov开发,目前最新版本为0.2.5. 它由 C++开发,并且官方可以下载 windows、linux和苹果Mac Os三个平台的可执行程序。
官方网站:http://jd.benow.ca/
2、Java 反编译器 JD-GUI
JD-GUI 是一个用 C++ 开发的 Java 反编译工具,由 Pavel Kouznetsov开发,支持Windows、Linux和苹果Mac Os三个平台。而且提供了Eclipse平台下的插件JD-Eclipse。JD-GUI不需要安装,直接点击运行,可以反编译jar,class文件。
官方网站:http://jd.benow.ca/
JD-GUI
主要使用 JD-gui, 因为他可以编译整个文件夹class文件非常方便
但是会偶尔地方报错,需要自己分析代码,比如创建一些
没有必要的局部变量
出错实例如下
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object h) throws Exception { String servletPath = req.getServletPath().toLowerCase(); boolean isContains = (servletPath.contains("add")) || (servletPath.contains("create")); boolean pass; if (isContains) { String name = this.userService.getStaffNameByStaffId((Long)req.getAttribute("sid")); boolean pass; if (StringUtils.isNotBlank(name)) { pass = true; } else { boolean pass = false; JSON.writeDataToStream(res.getOutputStream(), I18NResult.failure(ErrorType.USERNAM_NONE)); } } else { pass = true; } return pass; } }
pass 多处创建 调整后如下
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object h) /* */ throws Exception /* */ { /* 24 */ String servletPath = req.getServletPath().toLowerCase(); /* 25 */ boolean isContains = (servletPath.contains("add")) || (servletPath.contains("create")); /* */ boolean pass; /* 26 */ if (isContains) { /* 27 */ String name = this.userService.getStaffNameByStaffId((Long)req.getAttribute("sid")); /* 28 */ if (StringUtils.isNotBlank(name)) { /* 29 */ pass = true; /* */ } else { /* 31 */ pass = false; /* 32 */ JSON.writeDataToStream(res.getOutputStream(), I18NResult.failure(ErrorType.USERNAM_NONE)); /* */ } /* */ } else { /* 35 */ pass = true; /* */ } /* */ /* 38 */ return pass; /* */ } /* */ }
有时候JD-GUI编译出来的代码莫名其妙,这个时候可以结合
Java Decompiler 编译后的代码综合分析
下面给出一个class 文件的一个函数
由 jd-gui编译的函数 (有问题)
@RequestMapping({"/getMyProjectTaskList", "/getMeProjectTasks"}) /* */ @ResponseBody /* */ public Output getMetasks(@RequestParam("projectId") Long projectId, @Sid Long sid) { /* */ try { /* 141 */ metasks = this.taskService.getMetasks(projectId, sid); /* */ } /* */ catch (Exception e) /* */ { /* */ List metasks; /* 143 */ throw new RuntimeException(e); /* */ } /* 147 */ List metasks; /* 146 */ List metaskRess = new ArrayList(metasks.size()); /* 147 */ for (Iterator localIterator = metasks.iterator(); localIterator.hasNext(); ) { metask = (MetaskBo)localIterator.next(); /* 148 */ MetaskRes metaskVo = new MetaskRes(); /* */ /* 150 */ metaskVo.setTaskId(ObjectUtils.toString(metask.getTaskId())); /* 151 */ metaskVo.setIsLeafTask(ObjectUtils.toString(metask.getIsLeafTask())); /* 152 */ metaskVo.setTaskName(ObjectUtils.toString(metask.getTaskName())); /* 153 */ srt = metask.getStartDateTime(); /* 154 */ Date end = metask.getEndDateTime(); /* 155 */ metaskVo.setSrtDate(DateUtil.defaultDateToString(srt)); /* 156 */ metaskVo.setEndDate(DateUtil.defaultDateToString(end)); /* 157 */ metaskVo.setIsFinished(ObjectUtils.toString(metask.getIsFinished())); /* 158 */ metaskVo.setBetween((srt.getTime() <= metask.getCurrentDateTime().longValue()) && (metask.getCurrentDateTime().longValue() <= end.getTime()) ? "1" : "0"); /* 159 */ metaskVo.setTaskDesStatus(ObjectUtils.toString(metask.getTaskDesStatus())); /* 160 */ metaskVo.setTaskStatus(ObjectUtils.toString(metask.getTaskStatus())); /* 161 */ metaskVo.setRemindTime(ObjectUtils.toString(metask.getRemindTime())); /* 162 */ metaskVo.setWatcherSid(ObjectUtils.toString(metask.getWatcherSid())); /* 163 */ metaskVo.setAuditorSid(ObjectUtils.toString(metask.getAuditorSid())); /* */ /* 165 */ metaskRess.add(metaskVo); /* */ } /* 169 */ Date srt; /* 168 */ List taskInfos = this.taskProgressService.calcTaskProgress(projectId); /* 169 */ for (MetaskBo metask = taskInfos.iterator(); metask.hasNext(); ) { taskInfo = (TaskInfo)metask.next(); /* 170 */ for (MetaskRes metaskRes : metaskRess) /* 171 */ if (taskInfo.getTaskId().toString().equals(metaskRes.getTaskId())) { /* 172 */ metaskRes.setPlanProgress(ObjectUtils.toString(Float.valueOf(taskInfo.getPlanProgress()))); /* 173 */ float undoneProgress = taskInfo.getPlanProgress() - taskInfo.getProgress(); /* 174 */ metaskRes.setUndoneProgress(ObjectUtils.toString(Float.valueOf(undoneProgress < 0.0F ? 0.0F : undoneProgress))); /* 175 */ metaskRes.setActualProgress(ObjectUtils.toString(Float.valueOf(taskInfo.getProgress()))); /* 176 */ break; /* */ } /* */ } /* */ TaskInfo taskInfo; /* 181 */ return Result.success(metaskRess); /* */ }
由
dj java Decompiler工具分析出来的结果(也有问题)
@RequestMapping(value={"/getMyProjectTaskList", "/getMeProjectTasks"}) @ResponseBody public Output getMetasks(@RequestParam(value="projectId") Long projectId, @Sid Long sid) { List metasks; try { metasks = taskService.getMetasks(projectId, sid); } catch(Exception e) { throw new RuntimeException(e); } List metaskRess = new ArrayList(metasks.size()); MetaskRes metaskVo; for(Iterator iterator = metasks.iterator(); iterator.hasNext(); metaskRess.add(metaskVo)) { MetaskBo metask = (MetaskBo)iterator.next(); metaskVo = new MetaskRes(); metaskVo.setTaskId(ObjectUtils.toString(metask.getTaskId())); metaskVo.setIsLeafTask(ObjectUtils.toString(metask.getIsLeafTask())); metaskVo.setTaskName(ObjectUtils.toString(metask.getTaskName())); Date srt = metask.getStartDateTime(); Date end = metask.getEndDateTime(); metaskVo.setSrtDate(DateUtil.defaultDateToString(srt)); metaskVo.setEndDate(DateUtil.defaultDateToString(end)); metaskVo.setIsFinished(ObjectUtils.toString(metask.getIsFinished())); metaskVo.setBetween(srt.getTime() > metask.getCurrentDateTime().longValue() || metask.getCurrentDateTime().longValue() > end.getTime() ? "0" : "1"); metaskVo.setTaskDesStatus(ObjectUtils.toString(metask.getTaskDesStatus())); metaskVo.setTaskStatus(ObjectUtils.toString(metask.getTaskStatus())); metaskVo.setRemindTime(ObjectUtils.toString(metask.getRemindTime())); metaskVo.setWatcherSid(ObjectUtils.toString(metask.getWatcherSid())); metaskVo.setAuditorSid(ObjectUtils.toString(metask.getAuditorSid())); } List taskInfos = taskProgressService.calcTaskProgress(projectId); Iterator iterator1 = taskInfos.iterator(); label0: do { if(!iterator1.hasNext()) break; TaskInfo taskInfo = (TaskInfo)iterator1.next(); Iterator iterator2 = metaskRess.iterator(); MetaskRes metaskRes; do { if(!iterator2.hasNext()) continue label0; metaskRes = (MetaskRes)iterator2.next(); } while(!taskInfo.getTaskId().toString().equals(metaskRes.getTaskId())); metaskRes.setPlanProgress(ObjectUtils.toString(Float.valueOf(taskInfo.getPlanProgress()))); float undoneProgress = taskInfo.getPlanProgress() - taskInfo.getProgress(); metaskRes.setUndoneProgress(ObjectUtils.toString(Float.valueOf(undoneProgress >= 0.0F ? undoneProgress : 0.0F))); metaskRes.setActualProgress(ObjectUtils.toString(Float.valueOf(taskInfo.getProgress()))); } while(true); return Result.success(metaskRess); }
结合二者的优点 回避各自缺点
最终分析出来的结果
/* */ @RequestMapping({"/getMyProjectTaskList", "/getMeProjectTasks"}) /* */ @ResponseBody /* */ public Output getMetasks(@RequestParam("projectId") Long projectId, @Sid Long sid) { List<MetaskBo> metasks; /* */ try { /* 141 */ metasks = this.taskService.getMetasks(projectId, sid); /* */ } /* */ catch (Exception e) /* */ { /* 143 */ throw new RuntimeException(e); /* */ } /* 147 */ /* 146 */ List<MetaskRes> metaskRess = new ArrayList<MetaskRes>(metasks.size()); /* 147 */ for (Iterator localIterator = metasks.iterator(); localIterator.hasNext(); ) { MetaskBo metask = (MetaskBo)localIterator.next(); /* 148 */ MetaskRes metaskVo = new MetaskRes(); /* */ /* 150 */ metaskVo.setTaskId(ObjectUtils.toString(metask.getTaskId())); /* 151 */ metaskVo.setIsLeafTask(ObjectUtils.toString(metask.getIsLeafTask())); /* 152 */ metaskVo.setTaskName(ObjectUtils.toString(metask.getTaskName())); /* 153 */ Date srt = metask.getStartDateTime(); /* 154 */ Date end = metask.getEndDateTime(); /* 155 */ metaskVo.setSrtDate(DateUtil.defaultDateToString(srt)); /* 156 */ metaskVo.setEndDate(DateUtil.defaultDateToString(end)); /* 157 */ metaskVo.setIsFinished(ObjectUtils.toString(metask.getIsFinished())); /* 158 */ metaskVo.setBetween((srt.getTime() <= metask.getCurrentDateTime().longValue()) && (metask.getCurrentDateTime().longValue() <= end.getTime()) ? "1" : "0"); /* 159 */ metaskVo.setTaskDesStatus(ObjectUtils.toString(metask.getTaskDesStatus())); /* 160 */ metaskVo.setTaskStatus(ObjectUtils.toString(metask.getTaskStatus())); /* 161 */ metaskVo.setRemindTime(ObjectUtils.toString(metask.getRemindTime())); /* 162 */ metaskVo.setWatcherSid(ObjectUtils.toString(metask.getWatcherSid())); /* 163 */ metaskVo.setAuditorSid(ObjectUtils.toString(metask.getAuditorSid())); /* */ /* 165 */ metaskRess.add(metaskVo); /* */ } /* 168 */ List<TaskInfo> taskInfos = this.taskProgressService.calcTaskProgress(projectId); /* 169 */ for (Iterator iterator1= taskInfos.iterator(); iterator1.hasNext(); ) { TaskInfo taskInfo = (TaskInfo)iterator1.next(); /* 170 */ for (MetaskRes metaskRes : metaskRess) /* 171 */ if (taskInfo.getTaskId().toString().equals(metaskRes.getTaskId())) { /* 172 */ metaskRes.setPlanProgress(ObjectUtils.toString(Float.valueOf(taskInfo.getPlanProgress()))); /* 173 */ float undoneProgress = taskInfo.getPlanProgress() - taskInfo.getProgress(); /* 174 */ metaskRes.setUndoneProgress(ObjectUtils.toString(Float.valueOf(undoneProgress < 0.0F ? 0.0F : undoneProgress))); /* 175 */ metaskRes.setActualProgress(ObjectUtils.toString(Float.valueOf(taskInfo.getProgress()))); /* 176 */ break; /* */ } /* */ } /* 181 */ return Result.success(metaskRess); /* */ }