Slashdot Mirror


Reverse Engineering Large Software Projects?

stalebread queries: "Me and a team of other students have been tasked with reverse engineering a massive C/C++ (mostly C) computer game of about half a million lines. We have most of the source, but no clue of how to approach a task of this magnitude. Anyone have suggestions of programs, or techniques we could use to understand the structure of the game?"

104 comments

  1. Legal? by TheCarlMau · · Score: 1, Interesting

    Just curious... is this something legal? For example, isn't it illegal to reverse engineer Windows?

    1. Re:Legal? by redelm · · Score: 2, Interesting
      I would presume that the code came from a liquidation/auction/takeover and the human capital the produced it is no longer available. First, I would try to hire one of the original sw architects to do some consulting. Who knows? They might have some email files that could be considered "part of the software".

    2. Re:Legal? by Fbelch · · Score: 1

      He said... reverse a 'computer game' not something 'that makes a computer lame' :)

    3. Re:Legal? by jericho4.0 · · Score: 2, Informative
      Why, yes! It is legal. In fact, the right to reverse engineer a piece of software or hardware for interoperbility is protected in the US, IIRC. Hence Intel clones, PC clones, Samba, etc.

      But the article poster has access to the source code, something not usually associated with 'reverse engineering'. Products are still protected by patents, copyright and trademarks, and writing Samba (for example) after seeing Microsofts code would open one up to legal woes.

      IANAL, or USian.

      --
      "A language that doesn't affect the way you think about programming, is not worth knowing" - Alan Perlis
    4. Re:Legal? by Macphisto · · Score: 3, Insightful

      "Human capital"? What are you, an alien overlord of some sort?

    5. Re:Legal? by redelm · · Score: 2, Informative
      Alien overlord? I love it!

      "Human capital" is a rather common economics term to refer to those skills and knowledge that enable an employee to produce the desired works. Use the wiki, Luke. In this case, it is the experience and serenity which makes the Tao Master of programming worth several novice salaries :)

  2. Flowcharting might help by eric2hill · · Score: 3, Informative

    Since you're probably proficient with C++, try a flowcharting solution to give you a high-level map of all the classes. Maybe that will help.

    --
    LOAD "SIG",8,1
    LOADING...
    READY.
    RUN
    1. Re:Flowcharting might help by computational+super · · Score: 1

      C-Scope is a cool, free, class browsing tool that can make vi feel like a full-featured IDE. If you're an OS kind of person, take a look at this before you jump into the commercial tools.

      --
      Proud neuron in the Slashdot hivemind since 2002.
    2. Re:Flowcharting might help by Hell+O'World · · Score: 0, Flamebait

      What, are you trying to imply that vi is not a full featured IDE?

    3. Re:Flowcharting might help by triso · · Score: 1

      Sorry, but those type of product are bloody useless. The output is too complex when broken down into thousands of functions.

      Perhaps the C++ products would be better since a diagram would be acceptable if broken down at the class level but the C portion of the program is useless if broken down at the function level.

      Also useless is output which is a simple listing on a printer. The output must be in UML. or something similar, to transmit useful information to the reader.

  3. oh boy by QuantumG · · Score: 3, Informative

    I presume you mean reverse engineering in the program understanding sense. In which case the way to go about it is to sit down and read the source code, taking notes as you go. You should then set yourself some maintenance tasks - modifying the source code is the best way to find out if you understand it or not.

    --
    How we know is more important than what we know.
    1. Re:oh boy by AvitarX · · Score: 1

      Don't know the exact quote, but Sun Tzu has some wisdom that applies.

      (paraphrased)"commanding many is the same as commanding few, it is generally a matter of organization".

      So I would read some general stuff on how to do this (Practical C Programming has a short chapter for example, but you probably want a book all about it). I would then do what they do with their few to few thousand line sample meticulously to the whole thing as the parent post suggests.

      You need to flow chart the whole thing with notes, then it can be subdivided much more easily as someone working on a block of code will know its context, but everyone will need a fairly good grasp of the flowchart to analize a segment properly.

      In the quote replace commanding with reconstructing meaning of code, I am not giving management advice. I think this would be obvious, but once I said Avril Lavigne was punk with a sarcasm tag and still people thought it was serious, so I take nothing for granted.

      --
      Wow, sent an e-mail as suggested when clicking on "use classic" banner, and got a fast response that addressed my msg
  4. Reverse Engineer or Refactor/Port? by linuxtelephony · · Score: 4, Interesting

    It sounds like you are wanting to refactor the code, or port it to another platform. If you are missing some of the code, then you'll have to reverse engineer that portion of it.

    As for how to approach it - I think it depends on the size of your team, and what goals you set for the effort. Are you just wanting to learn? Or do you want to improve performance? Or make it work on another platform? What are the goals for this project?

    Once you know those details, they might give you an idea where to begin.

    --
    . 62,400 repetitions make one truth -- Brave New World, Aldous Huxley
    1. Re:Reverse Engineer or Refactor/Port? by QuantumG · · Score: 5, Informative

      Yeah, the "most of the source code" part is a bit scary. If they really are talking about reverse engineering from executables they are in for a hell of a time. The state of the art is a project I work on now and then, Boomerang, and it isn't for the faint of heart. I've been hearing for years about people who are working on decompilation tools that are integrated into IDA Pro but I've yet to see it. The time where you can enter a binary, press a button and get back compilable, maintainable source code is still a long long way off. But that's good, friends of mine do commercial decompilation work.

      --
      How we know is more important than what we know.
    2. Re:Reverse Engineer or Refactor/Port? by undef24 · · Score: 1

      Pretty impressive IDA integration here: http://pedram.redhive.com/research/process_stalkin g/

    3. Re:Reverse Engineer or Refactor/Port? by QuantumG · · Score: 1

      There's lots of IDA Pro plugins.. there just aint any that do decompilation. Which is what I said.

      --
      How we know is more important than what we know.
    4. Re:Reverse Engineer or Refactor/Port? by Anonymous Coward · · Score: 0

      http://desquirr.sourceforge.net/desquirr/

      I've not tried it, so I don't know how sophisticated it is.

  5. It could help... by itistoday · · Score: 2, Insightful

    To understand how games are made in the first place. What kind of a game is it? Is it a single player game, or multiplayer game? If it's multiplayer you'll have to watch out for code designed to keep the game logic at a fixed rate; all other code will be built on top of that. Singly player games on the other hand don't have to worry about all the intricacies of keeping the various game clients in sync.

    So it really depends on the kind of game it is. Since I'm assuming you know this, I would suggest trying to first think how you would write the game yourself, and then see if you find any similarities between your ideas for the engine structure and the games.

    1. Re:It could help... by UsualDosage · · Score: 1

      Sounds like MUD/MUSH code to me. I can't think of many games with 500K lines of source code written exclusively in C/C++ that aren't MUDs. If that's the case, itistoday is right in that MUD code is built around a game timer (for fixed rate logic, MUDs use 'ticks', generally firing off around once every 30 seconds), and it's also built around clever use of sockets to allow multiple realtime connections, which is generally one of the harder things to accomplish (read, was). If I wanted to get to the nitty gritty of game code, I'd learn all about sockets first, game timing secondly, and then read into general game mechanics (balance, theme, style, story).

      --
      "A true friend stabs you in the front." -Oscar Wilde
  6. A UML reverse-engineering tool by Burz · · Score: 2, Informative

    One like Rational Rose. It can create iconographic models of programs from source code.

    Other UML tools exist, like Argo and Umbrello, but I'm not sure if they reverse engineer.

    1. Re:A UML reverse-engineering tool by superpulpsicle · · Score: 1

      Rational rose good suggestion, unfortunately it's just not something students will be able to afford.

      I feel bad for students nowadays to have to deal with these gigantic assignments in schools who never provide enough resources. But thats a different story altogether.

    2. Re:A UML reverse-engineering tool by Anonymous Coward · · Score: 0

      I'll second that - go for a UML reverse engineering tool that can turn your C++ into UML class diagrams.

      I've used IBM/Rational Rose and Enterprise Architect to do this and it works well. Rose is way too expensive for students unless your department has licenses.

      I would go for Enterprise Architect from Sparx Systems
      (http://www.sparxsystems.com.au/).

      Have a look at http://sparxsystems.com.au/products/academic_prici ng.html
      which lists the academic pricing. You will be after the Professional edition which does the reverse engineering.
      For what it can do, the academic edition is a bargain.

      So what will a tool like this give you. A list of all the packages/directories/sub-packages/modules in your system.
      A UML class diagram for each package showing all classes and relationships between classes, includinge aggregation and inheritance relationships. Each class will have the name, attributes/types and all operations/methods with their signatures.

      You can then use Enterprise Architect to further document every single class/relationship/atttribute/method.

      Finally, you can from the reverse engineered model automaticaly produce API documentation for the entire system either in an RTF document or HTML somewhat similar to doxygen.

      Your team can then use the class diagrams and the API documentation to help you understand the design of the system you are studying. Basically you can extract the detailed design document for the system using this technique. Having this information in addition to the source code is invaluable. Just having the source code, for a sufficiently large system is a nightmare.

    3. Re:A UML reverse-engineering tool by Iamthefallen · · Score: 1
      I feel bad for students nowadays to have to deal with these gigantic assignments in schools who never provide enough resources.

      Isn't that exactly what they'll do when they get out of school as well?

      --
      Wax-Museum Fire Results In Hundreds Of New Danny DeVito Statues
  7. Source navigator by Mr2cents · · Score: 3, Informative

    http://sourcenav.sourceforge.net/

    I like to use it when browsing through code, you can search and browse as much as you like. It will still take an effort though.

    --
    "It's too bad that stupidity isn't painful." - Anton LaVey
    1. Re:Source navigator by hughk · · Score: 1

      I used it quite nicely under Windows (Cygwin, I believe) to hack some AIX code (a big QT/Motif app). The AIX version was so old that Source Nav wouldn't compile there, but it ran on cygwin and I used to go to the file-shares where the AIX source code was and it ran quite nicely and got me out of a lot of trouble.

      --
      See my journal, I write things there
  8. Profiling! by redelm · · Score: 2, Informative
    First run the code under a profiler. This will give you some idea of where it spends it's time. Running under a first-class debugger (SoftICE?) will also help because you can haul off stack-traces and see what's been called from where.

    1. Re:Profiling! by Vladimir · · Score: 1

      I agree it's very useful. Callgrind && kcachegrind usually give a lot of insight into the code. I wonder if callgrind can be hacked to produce nice seq. UML diagrams (it knows when objects are created and what messages are sent -- should be a very nice addition to the analysis).

  9. lots of moutain dew.... by warpSpeed · · Score: 3, Funny
    Oh, yeah, and hohos! Never underestimate the power of the hoho.

  10. Re:If you already have the source... by Profane+Motherfucker · · Score: 0, Flamebait

    I don't agree with anything in the above comment except this: "If you have to ask slashdot, you are NOT QUALIFIED for the job."

    Ditto on that. And we wonder what the fuck happened to higher education? Small rocks have been know to have more ingenuity than this.

  11. I believe the instructor is assigning... by Burz · · Score: 2, Informative

    ...a maintenance task, not a coding task. S/he is probably looking for a UML model, as I implied elsewhere in the thread. IBM Rational, Gentleware, Borland and some FOSS projects have software just for this sort of thing: Modeling all of the classes, structs, member variables and functions along with displayable relationships (using arrows, lines, and nesting).

    Whats more, some of these tools can be used to modify programs within the model, and then update the source code (forward-engineering). They can also create tables/databases from your persistent entity classes, represented with their own DBMS variety of UML icons...and can even update the actual database (sometimes directly, other times with DDL scripts) and track/display relationships between tables, and with the classes that use them.

    UML tools will seldom be able to reverse-engineer information about procedural code (declarations, conditionals, etc.) also this can usually be modeled by hand when such detail is necessary.

    1. Re:I believe the instructor is assigning... by QuantumG · · Score: 2, Funny

      Yep, lots of luck finding a single one of these tools that works on C code. Although making pretty pictures can certainly be a good way to get an overview of the software, and maybe students need that kind of assistance. Personally I think something like C-Scope is more than enough.

      --
      How we know is more important than what we know.
    2. Re:I believe the instructor is assigning... by Burz · · Score: 1

      In theory, C should only be a problem if it was coded without regard for OOP. And even then, structs will likely abound... you can pull those into the model with the built-in reverse engineering and use that as the nucleous for modeling the rest of the program either by hand or with the help of scripts. For instance, in Rose you could write a script to represent .c files and functions as stereotyped components and classes...and maybe even show what sort of data gets passed between functions.

      UML assumes OOP, but the UML tools are not tied to that concept hard-and-fast: You can reappropriate the symbols as you see fit as long as you don't have to generate code from them (and even then its do-able).

    3. Re:I believe the instructor is assigning... by Doctor+Memory · · Score: 1

      In theory, C should only be a problem if it was coded without regard for OOP

      Yes, and we know that this practically never happens. Especially with performance-critical software like games.
      <eyeroll/>

      --
      Just junk food for thought...
  12. WTF? by jericho4.0 · · Score: 1, Insightful
    It looks like I get to be the first one to call you on this. WTF are you talking about!? You don't 'reverse engineer' something you have the code for. Maybe you mean 'port' or 'complile'.

    If you wish to start getting a handle on a chunk of code, start by reading main() along with a profilers output. Grep is your friend.

    --
    "A language that doesn't affect the way you think about programming, is not worth knowing" - Alan Perlis
    1. Re:WTF? by NextGaurd · · Score: 1

      Maybe they are trying to duplicate functionality but can't use the exact code.

    2. Re:WTF? by kisielk · · Score: 3, Insightful

      Just because you have the code doesn't mean you know how the system is assembled and how all the components work together. "Reverse Engineering" is a pretty loosely defined, but if you take it literally, it's just that.. reversing the engineering process. From the description of the question, the poster is looking to take the finished product (the source for this game..) and move back up the high level design phase. This means analyzing the module interconnections, class hierarchy, and that sort of stuff. It doesn't necessarily mean they want to "port" or "compile" it.

    3. Re:WTF? by Scorchio · · Score: 1

      Reminded me of a porting project I had a few years back. We had pretty much all the source code from the game, but only binaries for the proprietary libraries it relied heavily on. In fact, it was only when we started pulling the thing apart that we found out just how much stuff was hidden away in the libraries. For example, a lot of the code seemed very disjointed - most sections didn't seem to be called from anywhere. We found that all entities (player, enemies, effects, menus, sounds, and so on) were set up as tasks with common data structure headers containing function pointers and linkage, and the whole thing got build up as a tree. Re-implementing the task manager from the library code was a huge step towards getting the port to run.

      We had the game running on the original platform, with a debugger and disassembler, so disassembling the libraries wasn't too bad - actually it was quite fun. The libs were compiled c code, which made it easier to pull out a c implementation, especially as we knew from the library stub name roughly what it was supposed to do and what data was going in.

      I'm currently pulling apart an old 8-bit game to see how it worked; it's only 26kb, but it's all hand optimized and self-modifying 6502 code. Takes a little longer to figure out, but it's still fun.

    4. Re:WTF? by ifdef · · Score: 1

      That's right. Since the code is only half a million lines, it should be pretty straight forward simply to read it starting at main().

  13. Re:If you already have the source... by oopsdude · · Score: 1, Interesting

    If he already has the source, then this problem may be easy enough to make asking Slashdot unnecessary. However, there are instances in which asking Slashdot is necessary. If they didn't have most of the source, for example. Or, for example, in this article, where an IT guy was asked to make an infrastructure for over one million email accounts that must scale perfectly and have 99.9% uptime. Show me a university that trains students for that.

  14. IDA by segra · · Score: 1

    IDA pro, best dissasembler around ;) http://www.datarescue.com/

    1. Re:IDA by ifdef · · Score: 1

      Because it will be much easier to read disassembled binary that to try to figure out what half a million lines of C or C++ code does.

  15. Reverse engineering by Anonymous Coward · · Score: 1, Informative

    >We have most of the source, but no clue of how to approach a task of this magnitude.

    Reverse engineering is generally thought of as a "cleanroom" technique that involves having the binary and/or specification but not the source. If you have the source, then you're just reading/rewriting it (or perhaps just copying it and doing s/Old Name/Our Cool New Game That's Nothing Like Old Name/).

    >Anyone have suggestions of programs, or techniques we could use to understand the structure of the game?

    If it's mostly C, then you definitely need to get cscope, but that won't tell you where to start reading because it cannot resolve calls to function pointers. To get that information, you might also try running gprof.

    Another neat trick is to compile the program and use nm to help map out object file dependencies. You'll want to use perl or something to create a database of where the symbols are defined and where they're imported. This can help you establish which files are the meat and which ones are the potatoes.

    1. Re:Reverse engineering by ifdef · · Score: 1

      ... We have most of the source, but no clue of how to approach a task of this magnitude.

      Reverse engineering is generally thought of as a "cleanroom" technique that involves having the binary and/or specification but not the source. If you have the source, then you're just reading/rewriting it


      If you have the source but not the spec, and you're working on recreating the spec, then you're reverse engineering.

    2. Re:Reverse engineering by try_anything · · Score: 1

      You can't call it "reading" and "writing." Too many computer people think that "reading" and "writing" are fast, straightforward, linear techniques that result in a disorganized mess - which for them is probably the truth. They would never understand that putting serious mental effort into creating a coherent, useful work could be called "writing," or that a systematic, intelligent effort to understand something could be called "reading."

  16. Graphviz and GNU Global by nullspace · · Score: 1

    Graphviz and GNU GLOBAL used in combination give a graphical and web-accessible view of a large, unknown software system. This will give your team a high-level view of the modules and how they interact. This will make it easier to discern the system design.

  17. I know where I would start by heinousjay · · Score: 0, Flamebait

    I would start by trying to get someone on the internet to do my homework for me.

    Oh, wait, you've already come that far. Well, I'm stumped now. Good luck!

    --
    Slashdot - where whining about luck is the new way to make the world you want.
  18. Use our tool :) by mr_tenor · · Score: 2, Interesting

    www.cse.unsw.edu.au/~drt

    Not that I'm biased or anything. The idea is to monitor the program while it's running and use the call graph to generate sequence diagrams and such. Feedback and ideas for further reasearch welcome :)

  19. Whats your goal? by AuMatar · · Score: 1

    Whats the goal of your project? To figure out how they do one particular thing? To figure out how the code works in a general way? To understand 1 subsystem?

    For the first, I'd try and find the functions called around when it occurs, and use a debugger to step through what happens.

    For the second, I'd study the interface files and use cscope. Figure out what is calling what, and see how its interlinked.

    For the third, you need to do the same as above on a local level- between files of the module. Then dig into individual parts.

    Really, if you want better advice, you need to tell us what you want to do.

    --
    I still have more fans than freaks. WTF is wrong with you people?
  20. use the tools that are available by blackcoot · · Score: 1

    let's see:

    if you have access to (ir)rational rose, runing your code through that will probably speed up a lot of this process. otherwise, a combination of cccc and doxygen with the appropriate config files will give you about the best start you can hope for. hopefully, the code has reasonable documentation. if not, you're basically screwed --- you'll have to work out the use cases and reconstruct your software from there.

  21. here you go by pmike_bauer · · Score: 1

    reenigne

    --
    I read /. for the (Score:-1, Conservative) comments.
  22. Have most of the code? by mnmn · · Score: 2, Insightful

    It is not 'reverse engineering' if you already have the code. So you'll be reverse engineering the part that you dont have a code for, and making sense out of the code that you do have.

    Draw flow charts. Then assign a seperate person for each module to make sense out of it. Next you'll do what you plan to do....

    Make mods for it? Make a clone? Rewrite the code and sell the code? Recompile and port to Linux?

    --
    "Give orange me give eat orange me eat orange give me eat orange give me you." -Nim Chimpsky
  23. There are some automatic UML generators by rgbe · · Score: 2, Interesting

    There are some automatic UML generators that will give you an overview of the code, or parts of the code:
    http://droogs.org/autodia/

  24. What language is C/C++? by kupci · · Score: 0
    Check the C++ FAQ then post to comp.lang.c++. I thought this in particular was good:
    Do not refer to "C/C++." Some people get testy about that, and will (unfortunately!) ignore everything else you say just to correct you with something like, "There is no such language." It borders on pathetic, but you'll probably be okay if you say "C or C++" instead of "C/C++." Sigh.
    1. Re:What language is C/C++? by samjam · · Score: 0

      Excellent comment; but, those picky people would also be wrong.

      C/C++ more correctly but rarely known as C++/C is C++ written in the style of C, and is a wicked waste of Bjarne's time.

      The guy behind xapian.org/xapian.com, Olly Bets knows how to write C++ with proper and repeated use of the base classes, iterators and templates and to be frank, his C++ looks almost like perl, and it is a delight to read.

      C/C++ is just C with objects and falls so far short.

      Sam

    2. Re:What language is C/C++? by ACORN_USER · · Score: 1
      my $my;

      for ($you=('like');open(LY,read('ing',$_,('perl')));){ do{};you();}

    3. Re:What language is C/C++? by samjam · · Score: 1

      Nice one; ...but thats not real perl.

      Strictly speaking: Global symbol "$you" requires explicit package name

      Maybe the per parser doesn't throw up any errors but its no more perl that a lot of C/C++ is C++

      Sam

    4. Re:What language is C/C++? by ivan256 · · Score: 1

      When sombody says C/C++ it can easily be something less evil, like C++ that uses some libraries written in C, or C++ with a C API binding. You know, kindof like when somebody says their app is written in Java/C. Many projects do use multiple languages, and C and C++ are both very popular.

    5. Re:What language is C/C++? by ACORN_USER · · Score: 1
      Ok, so it doesn't run with strict. -w will give you a bollocking. But:

      $you == $::you == $main::foo

      So the package name is reall implicity implied.

      Agreed though. Most perl poetry is to perl and Larry what C/C++ is to C++ and Bjarne. The problem is that many write perl code like poetry - bad poetry.

    6. Re:What language is C/C++? by lznancy · · Score: 1

      If C++ was statically deterministic during initialization and the templated versions did not grow exponentionally, then it might still be a viable language even though it is an academic version of IBM's PL1.
      c was and still is a great generic universal (somewhat portable) assembler language which is why it is at the core of so many OSs.
      Why didn't they just generate c from Smalltalk instead of writing C++? Gee I bet that is/was already being done!
      And I don't even code in Smalltalk, but am stuck in the Java world for various reasons both good and bad, although I got there through Fortran, Cobol, BAL (IBM's version), PL1, c, 2 years of C++ OJT development, and now the WebSphere container environment.

  25. Cross-reference first: Doxygen is your friend by treerex · · Score: 4, Informative

    It sounds like you are unable to build the complete system and run it, since you're missing functionality. This removes the possibility of using runtime tracing tools.

    The first thing I would do is run something like Doxygen over it to generate a cross-referenced description of the structures. It won't give you a global view of things, but it will give you a decent browsable view of the code itself. Another response mentioned GNU GLOBAL which may work better for you. Yet another possibility is LXR, though it may not work as well in C++. Regardless, a nice thing about Doxygen is that, when used with GraphViz, you can get useful diagrams generated showing class containment and file inclusion graphs.

    After you have that, get out your paper and pencil, and start drawing and manually tracing things. That's how I go about coming up to speed on new code I can't execute and step through. Eventually transfer that knowledge into a text file (or, nowadays, a wiki) so that others can benefit from it.

    1. Re:Cross-reference first: Doxygen is your friend by maetenloch · · Score: 1

      Doxygen is a great help in understanding someone's code. If you have Graphviz installed, and all the options turned on, it will generate call graphs, header dependencies, and even UML diagrams of your classes and structures, along with an html-ized view of the code. And best of all it's free.

    2. Re:Cross-reference first: Doxygen is your friend by aero6dof · · Score: 1

      I would second this suggestion. I would also suggest you turn on the options the fully cross reference and include the source code, as well a generate the graphiz diagrams (as suggested by another reply th the parent post).

  26. Can you compile? by liquidsilver10 · · Score: 1
    From the description it sounds like you are trying to understand how the program works (as you have the source code), rather than 'reverse engineering' which the usual meaning assumes you don't.

    So my suggestion is start by getting it compiled, up and running ;) You can then use the debugger to breakpoint the code and follow it through. You say you have most of the source code. Is the rest available as libararies to link to? Otherwise you could create 'fake' libraries just to get it compiling and running.

    Probably best to start with a top down approach. Games invariably have a 'game loop', so locate it and start there. It'll be something along the lines of

    InitStuff();

    while(running)
    {
    DoStuff();
    }

    CloseStuffDown();

    Whilst games are many and varied in their complexity they more often than not follow the same kind of pattern. During DoStuff() they will update the user input, update the world state (objects in the world), and finally render stuff on the screen. Once you've got a basic handle on which bits, try changing or commenting out things to see what effect that has.

    You could try mapping out all the source code with various software tools and the like, but the best way I've found to understand the code is just to dive in and have a play around. You'll probably find there are one or two files that do most of the interesting stuff anyway. If you have the change information from source control (eg if it's including at the top of the file) then look for the ones with the most changes ;)

    Also - grep is your friend ;)

    HTH & Good luck

    1. Re:Can you compile? by liquidsilver10 · · Score: 1

      Another thing that might help is asking yourself what are the important events in the game and finding where they are handled (where is the score updated, where is damage worked out, spawn/death events handled). Sometimes games use global event handlers/listeners so different parts of the code can hook into the important stuff. Find where these events are handled or callbacks registered and it should give you a quick insight into the more interesting parts of the code ;)

  27. Resources For the Code Janitor by sohp · · Score: 4, Informative

    I applaud your professor or thesis advisor or whoever for this real-world task. Here's a few resources which I wouldn't do without:
    Code Reading: The Open Source Perspective
    Object-Oriented Reengineering Patterns
    Reading Computer Programs: Instructor's Guide and Exercise
    Tips for Reading Code

    1. Re:Resources For the Code Janitor by jdowland · · Score: 1

      I second the Spinellis book. Great stuff.

  28. Tarzan and Tanto School of Communication Arts by teknomage1 · · Score: 0, Offtopic

    You my friend obviously havn't attended the World Famous Tarzan and Tanto School of Communication Arts.

    • Tired of wasting time and money on articles such as "a" and "the" ?
    • Worried about confusing listeners by switching between personal pronouns?
    • Think noun-verb agreement is innefficient and redundant?

    Come on Down! TaT School of Comm. Arts am accepting applications now!

    --
    Stop intellectual property from infringing on me
    1. Re:Tarzan and Tanto School of Communication Arts by Anonymous Coward · · Score: 0
      Don't forget, TaT School of Comm. Arts offer graduation level course proctored by Professor Frankenstein.

      • Course 501 - "short good... conjunction bad!"
      • Course 502 - "verb tense... bad.
      • Course 503 - "fire bad!"
      • Course 504 - "fire BAD!"


      Your modern ways confused and frightened me... until I went to the TaT School of Communication Arts! - Unfrozen Caveman Laywer
  29. Re:Me by Anonymous Coward · · Score: 0
    Being more precise, for non-native english speakers:

    This isn't a plural versus singular problem, as you might initially think. "Jack and Jill have a dog named Spot," cannot be changed to "Jack have a dog named Spot", because it's plural versus singular. That's pretty obvious, but it doesn't apply here.

    The real problem is that 'me' is a direct object, and 'I' is a subject. You don't say "Me is going to the store" or "Me would like ice cream", unless you're trying to be funny. And you wouldn't say, "Give that ice cream to I!"

    Better phrasing for the original submission would have been "A team of students and I have been assigned....."



    -- Grammar Nazi

  30. A Couple of suggestions by jschmerge · · Score: 2, Informative

    I've been through this sort of exercise several times in my career so far. 500k LOC is too much for a small team to get a handle on in any reasonable amount of time, so don't feel too helpless... You're professor is throwing you guys to the wolves and seeing what you are able to accomplish.

    As for the actual suggestions, read on:

    First, you'll need a tool to generate some form of cross reference for the entire codebase... I'd recommend Doxygen (hack the config file to generate the inheritance and call graphs). This will speed up your ability read the code; being able to look up the interface to any class with a couple of clicks in a web browser will make life a lot less painful.

    Next, find a text editor/IDE that's good at navigating large projects. This is a must. I personally do this with vi and ctags (although many people will tell you that there are better alternatives). Being able to look at more than one source file at a time is a good thing (tm).

    These are the two primary tools that you'll need. There are some other pointers that I can give too:

    • Become intimately acquainted with the project's build system. The separation of components into separate directories/libraries/modules will give you a great deal of insight into the overall program's structure. You'll be able to accomplish a lot of this by watching a complete build of the project progress. The other place to look is in the project's Makefile(s). I'd bank on the fact that most code stuck in bottom level subdirectories is code that you'll be able to treat as black boxes.
    • As you become more familiar with the codebase, you'll find that you keep coming back to certain source files to look something up. Understand that these files are the ones that are probably the most important. It may help you to keep a web browser pointed to the crossreference material for these files, or memorize their content.
    • Don't get bogged down in understanding every bit of the source. Probably 90 percent of the code in the project is used to do things that you really don't have to ever care about. A good example of this is a project I recently inherited, comprised of about 20,000 LOC. Four thousand lines of code in this project was there just to read XML config files into very simple data structures.
    • If you are having a difficult time figuring out how a piece of the code works, you may want to try running it in a debugger and stepping through the execution. I'm not a huge fan of doing this, but I know people who swear by it.
    • Import the source for the project into some form of version control system. This will afford you the luxury of being able to modify the code without fear of breaking anything too badly.
    • If you have access to the developer's source code repository, sometimes commit histories can give you a lot of insight into why things in the code are the way they are.

    Anyway, good luck!

  31. Valve by Anonymous Coward · · Score: 0

    Hmmm ... from reading your post, I suddenly had to remember this email address "help_valve@valve.com". As the name implies, they offer help to folks trying to understand the unfinished engine they released a few years ago.

    Just in case this "massive" game has something to do with Half Life 2.

  32. Scripts and Configuration files by hayriye · · Score: 1
    Are there any other files containing scripts in some language? Maybe the original coders wrote the high level logic in some scripting language.

    Are there any configuration files? If no, there may be some code that's reading supposed to be found conf files.

  33. best solution? by RMH101 · · Score: 1

    if you're trying to rev engineer code from a company that's gone bust - go hire their lead programmer for 6 months, and task him with documenting it. seriously.

    1. Re:best solution? by Da+VinMan · · Score: 1

      Yeah, that'll work. Because talented leads love to write documentation for 6 months at a time. No, really they do...

      --
      Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
    2. Re:best solution? by RMH101 · · Score: 1

      "talented leads"? oh, you precious little prima donna. are they keeping you in lattes and nerf guns?
      pay big rates to skilled people if it's worth it to your business. pretty simple, really.

  34. I'm assuming that you have the source as a guide by ACORN_USER · · Score: 2, Informative
    My assumption is that you're to reverse engineer the software, but have been given fragments of the source as a guide, yet still have to show your methodologies so as to prove that you didn't just re-write the source.

    I'd start buy actually reading the source - building it if you can. Run profilers on it and try to get some kind of visual representation of the underlying code tree. If you have source, try using something like DOXYGEN to autogen some documentation (and structure) out of it. Someone mentioned Rational - you can get a trial license. Try to understand what the code does. For the most part games are straight forward, in that you have objects that have specific behaviours. You can try to establish the object hierarchies and see if you can redefine these to make more sense - or just be different.

    For the fragments of source you don't have - try using tools such as truss to track flow of what is going on. GDB is your friend and you probably want to try running it through the debugger - especially if the extracts you were given were compiled without stripping the symbols. nm is also another useful one at trying to get an idea of the symbols in your binary and establishing 'from meaningful names' what on earth goes on inside.

    Push your binaries through a disassembler like ldasm or datarescue - win. NASM also has a disassembler. Try and get a feel for what is going on.

    Now comes the hardpart - it's not called reverse 'engineering' for nothing. You've done the reverse bit. It's now time to engineer a solution which shows that you've gone through the 'reverse' bit. It can be y our view on how the code should work. Don't be affraid to reuse resource files/bitmaps, etc. That's allowed. It's the code which counts. You'll probably find that the assignment gave you something which was sub-optimal, in either design or processing - or both. It's your turn to write it the way which it should have been written. I'll leave the 'team dynamic' to you. Don't let one person have all the fun. Probably you - it's good to give others a chance. See what people are intersted in and allocate the work load. Just be prepared to fix everyone's bugs the night before submission - it's not so bad - it's 'fun.'

  35. Understand for C++ and Source-Navigator by Phatmanotoo · · Score: 1

    We are evaluating some tools along these lines. The ones we liked most are RedHat's Source-Navigator (GPL) and Scitool's Understand for C++ ($$$).

    Sorce-Navigator seems to be slow compared to Understand C++, I'm sure this has to do with the way they index the DB. On the other hand, the Linux version of Understand C++ needs some polishing IMHO (too many crashes on Debian/serge).

    As for report-generating tools that just index and cross-reference the whole project, Gonzui is a pretty good one.

    1. Re:Understand for C++ and Source-Navigator by ACORN_USER · · Score: 1

      Wow. Understand for C++ looks awesome. Then I looked at the pricing. Hmm. Do you really think that a team of students will be able to afford this?

  36. Prolog by ACORN_USER · · Score: 1

    If that's the task, you probably want to use DCG rules in Prolog. :)

  37. Ok - that should have been under the grammer flame by ACORN_USER · · Score: 1

    Hmm. I was sure I'd posted under the guy who joked that they had to improve their grammer..

  38. Not Rational Rose unless... by Doctor+Memory · · Score: 1

    ...it's improved mightily since I last used it. Granted, it was reverse-engineering some Java code, but it wouldn't do squat unless it could compile the whole thing (I assume it created a symbol table/parse tree and based its analysis on that). Which made it useless for documenting portions of a product, or one that was in flux and not in a cleanly-compilable state. Sure, you could stub out everything, but if you're talking an entire package that isn't available, then it's more work than it's worth.

    Personally, I'd try to break it down functionally first. Set off the graphics, the user interaction, the game core, any AI. Then break them down into their respective functions, and so on and so forth. Keep an eye out for "extern struct" declarations (esp. things like "extern struct _common" or "extern struct shared_vars", these will be communication vectors and be a general pain source).

    --
    Just junk food for thought...
  39. Headfuck by Anonymous Coward · · Score: 0

    OK, these should not be juxtaposed:

    "It can't be fully enjoyed if you're worried about your girlfriend walking in on you fucking a jar of spaghetti."

    immediately followed by:

    "Use our tool :)"

  40. Massive? by idries · · Score: 2, Interesting

    First of all this is not a massive code base for a commercial computer game, it's about average. Many games get into the 1-2 million lines of code. Having said that most games also have teams that are probably much larger than your group of students.

    I'm not exactly sure what you're trying to do here. As many ppl have said reverse engineering something that you already have the source for is not really reverse engineering at all. However if I make the (somewhat suspect) assumption that your objective is to examine the code and extract some kind of high-level understanding of the entire engine which you can then demonstrate in some way, I would advise you to think again. Most games (again, I am assuming that you have a commercially developed code base of some kind) are a giant mess with no overall design or direction in the code.

    Generally you'll find that a few sub-systems have been implemented with some kind of clean design (although not necessarily in a coordinated manner) and then the rest of the game is just a mass of glue code that holds these pieces together. During the original implementation no-one will have had the kind of general overview that you're looking for, each member of the team will know their specific area or areas, and how that part interfaces to the next, but no-one will know how all of them work together. Trying to summarize how all the systems work together will either give you something very high-level (and essentially meaningless) or something so complex that it's almost as hard to understand as the source (and not suitable to give to your professor as 'proof of understanding').

    My advice would be to choose one or more parts of the game and try to gain an understanding (in whatever manner you choose) of those areas. One of the best ways to choose these areas is to look at the USP (unique selling points) of the game itself. Some areas of the game will have been very important to the final product, while others will have been done just because they had to. For example, if the game is an RTS with a focus on the tactical aspect of the single player experience, then the scripting and ai systems will have been very important (and made as good as possible) while the sound engine will not have been very important (and made just good enough). The parts of code which are important to the actual gameplay will have had much more time and attention spent on them and will probably be far more interesting. Having said that the most important parts of the game will also have had more ppl working on them and they may well contain much less readable code.

    Perhaps you should give us some more info on what exactly you want to do, so that we can give you more relevant advice?

  41. One word by JamesP · · Score: 0

    Doxygen... Best thing I've to recommend to you

    (and yes, I am in a project involving understanding several lines of code)

    Doxygen beats the crap out of SourceNav and other stuff. It creates lots of graphics of major relationships thorout your code.

    --
    how long until /. fixes commenting on Chrome?
  42. Forward Engineer instead... by GiorgioG · · Score: 1

    How about forward-engineering it? Try and add a feature to the game that doesn't already exist (and doesn't make use of any built-in scripting system/tools, etc.) That's the only way you'll really learn what's going on in there. Reading code in and of itself doesn't mean you underestand what it does. But if you have to change the code, there's no doubt that you'll figure out how (at least a part of) it works!

  43. Reversing Std C by TheDracle · · Score: 3, Informative

    It's pretty simple, just time consuming. I've seen a few reverse engineering books floating around: "Reversing," "Exploiting Software." Since it's mostly stdC, it shouldn't be nearely as difficult to reverse engineer. Other languages can make things more complicated (Multiple calling mechanisms, more dynamic memory allocation, etc..).

    Tools:

    OllyDbg - Awesome usermode debugger, probably better suited than softice for this particular task. You can add assembly wherever you want, and it will create patches for the exe that can be automagically applied. It's also FREE.

    Numega Softice - Just in case you need to bring in the big guns.

    IDA Pro - Best reverse engineering tool available. Lots of extension scripts to do anything imaginable..

    TSearch - Can search memory at runtime, set breakpoints, disassemble code on the stack, and dynamically insert new assembly at runtime. Nice for understanding the flow of the software as it runs, and identifying interesting variables and structures.

    REC Decompiler - Awesome decompiler that produces a high level representation of the code. Not a replacement for your brain, but can save a lot of time tracing over assembly code to understand the purpose of a function.

    WinPCap & Ethereal - For reversing game protocols, and understanding client-server interaction. Sometimes it's nicer to just figure out where the host name/IP string is located in the binary and replace it with 127.0.0.1, then write a little proxy program to sit in between the client and the server.

    HVIEW: Hex editor with the ability to disassemble.

    (Use Cygwin or mingw for the following) strace: Traces signals, system calls, and spits them out to the screen.

    nm: Dump binary symbol table and names.

    I've definitely forgotten a plethora of other useful tools (especially the binutils ones), but the above consist of some of my favorites.

    For a game, you'll probably be dealing mostly with OllyDbg, HVIEW, REC, and winpcap/proxy. I'd recommend using nm to get a list of all of the symbols in the program, and then maybe split up and assign each student some number of symbols to understand and rewrite in C. Then they can use HVIEW or OllyDbg to navigate to those symbols, and try translating them. If they have a difficult time, have them use REC to get a higher level representation they can cheat off of.

    -Jason Thomas.

  44. Clarifications by stalebread · · Score: 1

    I submitted this question. Sorry about any confusion. I have all the code I care about, I can compile and run it, and I'm (unfortunately ) forced to use Visual Studio .Net.

    1. Re:Clarifications by idries · · Score: 1

      So what are you trying to do? Do you want to modify this source todo something new? Do you want to document it, or represent it in some other way? You're still not telling us what you mean by 'reverse engineer'. What is your goal here?

    2. Re:Clarifications by stalebread · · Score: 1

      So what are you trying to do? Do you want to modify this source todo something new? Do you want to document it, or represent it in some other way? You're still not telling us what you mean by 'reverse engineer'. What is your goal here?

      We want to do both. Right now we're at the point where we're trying to document and understand the code. Eventually our goal will be to modify the source to add some features.

    3. Re:Clarifications by idries · · Score: 1

      I see. Well my advice from the previous post still stands. Don't try to address the codebase as a whole, but confine yourselves to the functional (rather than architectural) areas that you're interested in.

      Presumably you have some specific types of modification in mind so start by creating a list of each functional area that you think each modification will impact. You probably don't even need to look at the code for this part. For example, if you want to add a 'boost' feature to a racing game, then you'll probably have to change the following areas:

        + physics/simulation - to actually do the boosting
        + control - to allow the player to trigger the boost
        + ai - to decide when to boost

      There may well be other areas (i.e. ui to indicate boost is available, fx to indicate to the player that a car is boosting, but let's ignore that for now).

      Once you have done this, then you'll have a list of modifications and corresponding functional areas:

        + boost - simulation, control, ai
        + position indicator - ui, simulation
        + car damage - simulation, (rendering?)
        + manual transmission - simulation, control, ai

      As you can see from my (rather contrived) example the areas you really need to look at are simulation, control and ai. You do not need to even look at the asset management system, memory manager (which is probably not a garbage collector;), front end, sound system, networking, user settings, ui or rendering until you actually start coding.

      That's not to say that you won't need to touch on these systems and understand them in some way (can't do much without allocating *some* memory) but you won't be *changing* them, and you don't need to understand how they work, just how to use them. In fact, the calls that you need to make can probably be figured out by looking at the code that you've already examined. For example, if you want to add a position indicator to the ui which is driven by the simulation, you'll probably be able to find another indicator (i.e. race progress) which is already driven by the simulation. You can just mimic it without ever looking at the ui code. Likewise, once you understand how the simulation uses the asset manager, memory manager, sound system and networking you can modify the simulation using those systems in the same manner without ever examining them in great detail.

      After a while you may find that you want to change the way that some of these other systems work. Although that may be necessary (depending on how good/bad the code is and how far your final requirements differ from the original functioning of that system) don't worry about this until it actually stops you from making a modification that you want to. There's probably alot of bad code in the engine, but just focus on what you need to in order to make your changes.

      Hope that helps.

    4. Re:Clarifications by SerpentMage · · Score: 1

      If you are still wondering please send me an email. I have reworked very large codebases in the same order as you are talking about. I can't name the packages in public.

      --

      "You can't make a race horse of a pig"
      "No," said Samuel, "but you can make very fast pig"
  45. an autodiagrammer? by mattr · · Score: 1

    I was thinking about that tool for Perl that uses Devel::DProf and a diagramming program (GraphViz I think) to draw flow charts of the program as it runs, showing which routines are called, that would be great.

    See graphviz.org's resources section for some links to profilers

    I wonder if something like that is avaiable for C++. Found ROCASE which looks like a CASE tool that can "reverse-engineer" (analyze) C++ files and automatically format diagrams for you to help understand the code structure. Post back here if you find it to work well!

  46. It's easy by CptPicard · · Score: 1

    Start with "main" and go from there :-)

    --
    I want to play Free Market with a drowning Libertarian.
  47. Use Data as the X-Ray by oldCoder · · Score: 1
    Usually you can find a tool that will dump out all the system calls with arguments. See what the program is doing, and maybe write some scripts to analyze the log files. It gives you a genuinely useful perspective that you'll never get from reading the code.

    For programs that primarily do file processing, you can get a similar understanding by analyzing the input files and the output files.

    For database programs you often can get the DBMS to log the transactions or the SQL.

    For embedded systems you would need a hardware device called a logic analyzer to get the data to make the analysis.

    For communications software you'd need to get something to dump the packets to log files. Lots of these for the popular protocols.

    From the above analysis you might be able to write a spec (that is, a doc that would tell somebody what the program is supposed to do, so they could code it from scratch just by reading the spec).

    Later on, modify the code and see what happens.

    --

    I18N == Intergalacticization
  48. Understand for C++ by skeptictank · · Score: 1
    You can get a free evaluation for 30 days. Google it to find their website. It's a generalized metrics collecting and reverse engineering tool.

    Just in case your still looking at this topic.

  49. Reverse Engineer or Refactor/Port? by lznancy · · Score: 1

    Primary Questions
    What is your target environment, language?
    What is your objective?
    What is your time line?
    What are your available resources and what is their available time to apply to this effort?
    Additional questions?
    Do you have a working version of the original installed Game?
    Can you get the missing source or if not possibly "Reverse Engineer" it?

  50. The people who read by int21hex · · Score: 1

    It becomes so very apperent the people who read about the scene, and the people who do it, and/or at least know enough to ask for more detials. After reading through various posts, it was somewhat easy to pick through the people who read about reverse engineering. Mostly the choice of tools, and attitudes they had reflected the general material about reverse engineering. Also I found the "I need mores" which I describe as people who don't wont to guess. "Tell me exactly what you are doing, and I will tell you exactly why I don't know that", is thier general war cry. However, reading through the posts; There where some really insitefull ones, (this not including the people who said, "If you have the souce, how can it be reverse engineering?".