Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse engineer a program which has no documentation [closed]

I have a source of python program which doesn't have any documentation or comments. I did tried twice to understand it but most of the times I am losing my track, because there are many files. What should be the steps to understand that program fully and quickly.

like image 575
Xinus Avatar asked Sep 09 '09 04:09

Xinus


2 Answers

Michael Feathers' "Working Effectively with Legacy Code" is a superb starting point for such endeavors -- not particularly language-dependent (his examples are in several non-python languages, but the techniques and mindset DO extend pretty well to Python and just about any other language).

The key focus is, that you want to understand the code for a reason -- modifying it and/or porting it. So, instrumenting the legacy code -- with batteries and scaffolding of tests and tracing/logging -- is the crucial path on the long, hard slog to understanding and modifying safely and responsibly.

Feathers suggests heuristics and techniques for where to focus your efforts and how to get started when the code is a total mess (hence "legacy") - no docs, or misleading docs (describing something quite different, maybe in subtle ways, from what the code actually DOES), no tests, an untestable-without-refactoring tangle of spaghetti dependencies. This may seem an extreme case but anybody who's spent a long-ish career in programming knows it's actually more common than anyone would like;-).

like image 197
Alex Martelli Avatar answered Oct 21 '22 04:10

Alex Martelli


  • In past I have used 'Python call graph' to understand the source structure
  • Use a debugger e.g. pdb to wak thru the code.
  • Try to read code again after one day break, that also helps
like image 20
Anurag Uniyal Avatar answered Oct 21 '22 02:10

Anurag Uniyal