Thread: Reverse Engineering a C Program

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    New York City
    Posts
    3

    Reverse Engineering a C Program

    Hi !

    I'm new to computer programming, but lately I have been bitten by the bug. I'm interesting in learning how to program, but I can't quite "see" what exactly is the purpose of this language. I understand everything I hear, but I don't see it. Yes. I've done the hello world samples. But so what ? I want to see something larger, and more complex so that I can reserver engineer it and then actually figure out what does what, and why ?

    Can somebody help ?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why don't you just learn assembly if you want to know what it's really doing?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    sign up for an account on github.com ( or not) and clone the linux kernel. Proceed to have tons of fun.

    Edit: save you the trouble: https://github.com/torvalds/linux
    "All that we see or seem
    Is but a dream within a dream." - Poe

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Out of morbid curiousity, did you take about your bicycle before you learned to ride it?

    Soma

  5. #5
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Sorry to say this, but those responses are about right.

    What you've said is that you want to be an airline pilot, so why can't you just take apart a Boeing 747, or fly transatlantic flights to see how it goes?

    You want to learn - then you have to put in the graft. That means either churning through sample code and slowing building up or taking a mid-size project (e.g. an open-source game that interests you) and looking at the code. If you understand more than 1% of it by the time you get bored, I'll be quite impressed. And I don't mean "understand" as it "this command does this" but as in understanding why it was done a certain way, why it's more efficient with this loop structure, how they've compressed that data and why, why the OpenGL pipeline is that way etc.

    What you've done with your post is walk into an operating theatre and said to a bunch of surgeons "I've got GCSE Biology. Shove over, I want to do what you're doing."

    Learn. Through samples, creating your own project or finding a project to read through. I'll give you a hint: If you haven't already found a project on Google that you can find open-source C code for and you have an interest in the program, then you haven't even bothered to try and probably won't have the dedication to actually learn C anyway. To get to the point where you can pull down even, say, OpenTTD (a clone of a DOS game from 20 years ago) and understand even the majority of the code will take YEARS - not just of studying C but studying that projects particular quirks too.

    I've programmed since I was 8, or even earlier, I'm not sure. I took my own A-Level computing classes in programming (i.e. teaching all my classmates) because the teacher saw I taught it better than him. But I wouldn't have the arrogance to think I can just pull down the code for any project with any sort of significance (even just a sillly game) and actually make sense of it. Hell, I spent a month this year trying to make a simple OpenSSL-using library to get some copy-protection code written and I still don't understand 1% of OpenSSL's library (despite having a degree in Maths and Computer Science and a specialist interest in encryption and cryptography). Even a small linked list or balanced tree code can be difficult to understand even with the best, cleanest, well-documented code in the world.

    You want to learn? Get off the hello world samples. Think of a game you want to write and do it. If you get it finished in under a year, I'll be impressed. If you *ever*, in your entire life, get it to a commercial standard where you could sell it on an app store, for example, I'll be extremely impressed. Pull down something like OpenTTD (which is C++, but never mind) or Simon Tatham's Portable Puzzles (simple C games with complex game theory behind their solvers) and try to port it, convert it, enhance it, get a patch to the author that adds something new.

    But, honestly, just from your tone, I would hazard a guess that you'll never really understand and, in the privacy of your head, think you could "do it all" when actually you've never written a worthwhile line of code in your life.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Another "I want to be an engineer, I don't care if it takes all day" post.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by ledow View Post
    ..., I would hazard a guess that you'll never really understand and, in the privacy of your head, think you could "do it all" when actually you've never written a worthwhile line of code in your life.
    A good summary of a past supervisor that I had about 6 years ago.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by stahta01 View Post
    A good summary of a past supervisor that I had about 6 years ago.

    Tim S.
    Tell me about it. I interviewed a grad student once, who had been teaching C++ to the year 1 undergraduates (i.e. Programming 101). After the interview was over I felt compelled to write to the head of department, saying that really we shouldn't be taking anyone from the undergrad classes this guy had been teaching. Based on his understanding of programming there was no way that batch was any good.
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. StarUML reverse engineering
    By VirtualAce in forum General Discussions
    Replies: 1
    Last Post: 11-11-2010, 04:44 PM
  2. Reverse Engineering
    By fcommisso in forum C Programming
    Replies: 8
    Last Post: 12-14-2009, 12:58 AM
  3. Reverse Engineering Tools
    By Goldie in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-26-2004, 11:36 PM
  4. reverse-engineering...
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 02-17-2002, 12:48 AM
  5. Reverse Engineering and Disasembling
    By jinx in forum Windows Programming
    Replies: 0
    Last Post: 12-08-2001, 06:16 PM

Tags for this Thread