Java 中的逆向工程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4852649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:19:41  来源:igfitidea点击:

Reverse Engineering in Java

javareverse-engineering

提问by Umesh Awasthi

I know that the same question has been asked many times on SO and I have gone through most of the threads. However, I still dot not have a satisfactory answer, so I thought of asking from community.

我知道在 SO 上已经多次问过同样的问题,而且我已经浏览了大部分主题。但是,我仍然没有一个满意的答案,所以我想到了向社区询问。

I am being assigned the work to do reverse engineering to a module and have the following issues:

我被分配了对模块进行逆向工程的工作,并且存在以下问题:

  1. The team has no idea what exactly is in the underlying component (Module is a third party solution)
  2. Team was only working on testing part so they can only provide me information about the flow, but what is the starting point and which is where they have no idea.
  1. 团队不知道底层组件到底是什么(模块是第三方解决方案)
  2. 团队只在测试部分工作,所以他们只能向我提供有关流程的信息,但他们不知道起点是什么,在哪里。

Now they want me to dig through the code base and come up with class diagrams as well as sequence flow etc.

现在他们要我挖掘代码库并提出类图以及序列流等。

I have never worked in my professional life in this kind of situation where there is no idea where to start and how to do this work. The only thing I have is source code.

在我的职业生涯中,我从来没有在这种不知道从哪里开始以及如何做这项工作的情况下工作。我唯一拥有的是源代码。

I have two questions where I want the help:

我有两个问题需要帮助:

  1. Is there any plugin for Eclipse which can generate class diagrams automatically from the source code?
  2. What should the approach be when one is in this kind of situation?
  1. 是否有任何可以从源代码自动生成类图的 Eclipse 插件?
  2. 遇到这种情况,应该怎么做呢?

Update: I will have access to the source code. So I am more inclined towards the best approach to accomplish the task

更新:我将可以访问源代码。所以我更倾向于用最好的方法来完成任务

回答by Eric Giguere

There are several Java decompilers that will help you, such as JD-Core, and there's an Eclipse version of it.

有几个 Java 反编译器可以帮助您,例如JD-Core,并且有它的 Eclipse 版本。

回答by biziclop

I'd start with decompiling the module and making sure that the decompiled code can be reassembled into a working library. You can use JDfor example.I can see now that you've got the source code already.

我首先反编译模块并确保反编译的代码可以重新组装成一个工作库。例如,您可以使用JD我现在可以看到您已经获得了源代码。

Getting a compilable source code first is important, because you will have to add comments and javadoc as you explore it. You don't have to work with the original binary anymore, just treat the decompiled source code as a very badly documented normal code. It is also a good idea to rename local variables and method parameters to make the code easier to read.

首先获得可编译的源代码很重要,因为您在探索时必须添加注释和 javadoc。您不必再使用原始二进制文件,只需将反编译的源代码视为记录非常糟糕的普通代码。重命名局部变量和方法参数也是一个好主意,以使代码更易于阅读。

Generating class diagrams from .javafiles should be easy then.

.java那么从文件生成类图应该很容易。

Understanding the flow can be done in two ways, manually or using a profiler. For both methods you need to find the entry points first, but if you're already using the library, these should be fairly obvious. Then you just invoke the API method and step through the code. Always make notes of anything interesting you encounter. (In many ways, exploring unknown code is similar to exploring a dungeon in a good old adventure game.) Convert these notes into javadoc comments so you can generate more informative javadocs as you go along.

可以通过两种方式了解流程,手动或使用分析器。对于这两种方法,您首先需要找到入口点,但如果您已经在使用该库,那么这些应该是相当明显的。然后您只需调用 API 方法并逐步执行代码。总是记下你遇到的任何有趣的事情。(在许多方面,探索未知代码类似于在一个很好的老冒险游戏中探索地牢。)将这些笔记转换为 javadoc 注释,这样您就可以在进行过程中生成更多信息丰富的 javadoc。

The profiler method is more about discovering the general patterns of calls, but every profiler should have a call stack view you can use.

探查器方法更多地是关于发现调用的一般模式,但每个探查器都应该有一个可以使用的调用堆栈视图。

回答by Chris Thompson

The answer to question (2) will depend on your answer to my comment, but for question (1), check out this pagethat gives a tutorial on how to use eclipse to generate a UML class diagram from source.

问题 (2) 的答案将取决于您对我的评论的回答,但对于问题 (1),请查看此页面该页面提供了有关如何使用 eclipse 从源代码生成 UML 类图的教程。