Disassemble C/C++ Code

Hello People,

is it possible to Dissasemble C or C++ code with the Express edition

What I have to Download

Thanks Leo




Answer this question

Disassemble C/C++ Code

  • Thea Burger

    BIG BIG THANKS

    thx for helping me. =)

    It works now, and i'am able to debug :)!

    I wish you a nice evening ;)!

    and THANKS!!!



  • dongjunming

    JaLeo wrote:

    [ ... program written in Standard C ... ]

    But i'm not able to debug this, because maybe its in C

    I've downloaded the Symbols for Win XP.

    There's no problem using the debugger with a Win32 Console Application that is written in Standard C.

    I'm going to duplicate your program, build it, and perform a debug run with it so we can compare experiences.

    I'm not sure having the Win XP symbols will help you. Is it your intention to follow the calls into the standard libraries and down into Windows itself We'll see ...



  • Dan Ward

    JaLeo wrote:
    but how can I debug a source When I tried to debug a programm, there writes out in the output .../kernel32.dll => Symbol not found ... and a other *.dll too.

    Without knowing more about your actual situation and the sequence of events, it is difficult to suggest appropriate action.

    Let me confirm some things:

    1. Assumption: You have a VC++ Project and you have the source program that you want to use as part of the project. You have the Platform SDK Installed.

    2. With the project open, when you use the Build | Rebuild Solution menu item (or Alt+F7 keys), do you get a successful Build Do you get a final output from Build like

    Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped

    3. If not, then you don't have a program that you can debug yet, and looking at assembly code won't help you. You must get a clean build first. This means you must check your source code and perhaps your VC++ 2005 Express Edition configuration for what is wrong.

    If you are getting successful builds, then we can look at debugging. But you need to get this far first. If you're not getting this far, we can look at the messages and see how to track down what needs to be repaired.



  • barbarian

    Thanks for your fast replay,

    but how can I debug a source When I tried to debug a programm, there writes out in the output .../kernel32.dll => Symbol not found ... and a other *.dll too.

    What should i do

    Leo



  • Jeremy Grand

     orcmid wrote:
    I'm going to duplicate your program, build it, and perform a debug run with it so we can compare experiences.

    OK, now I understand why you want to use the debugger. 

    First, the messages about "No Symbols Loaded" are not important.  The debugger is just reporting that it doesn't have access to symbolic definitions for some of the library files your program uses.  You can debug anyhow. 

    You need to know about setting breakpoints.  I describe that in comments in my copy of your program.

    I have edited your program (and I made a bug).  Some of the comments and changes to the code are simply how I explain things to myself along with housekeeping I always practice (and that's when I added a bug of my own).  I also provide comments that should let you compile my version (or yours), set breakpoints, and confirm the bug. 

    I put a long comment at the front so that you can duplicate exactly what I did to make a project for the program. 

    I also added an explanation at the end that describes the problem I introduced and one way to get around it.  There are other ways that I left as possible exercises.

    Thanks, this was fun. 


    /* JaLeoTest1.c Debugging Test Program from Leo.
       This program is being used to confirm how to test and see
       code in the VC++ 2005 Express Edition environment.
      
        Project Setup:
            Use File | New | Project ... to start a new project.
            Name the project (e.g., "JaLeoTest1"),
            Use the default Location chosen by VC++ EE
            For the Solution, allow "Create new Solution"
                and do not check "Create new directory for Solution"
            For the Project types, choose Win32
            For the Templates choose "Win32 Console Application."
         
            On the Win32 Application Wizard Overview (Welcome) dialog,
                click "Next."
         
            On the Win32 Application Wizard Application Settings
                dialog select Application Type "Console application"
                and check "Additional options: Empty Project"
                then click "Finish"
           
            Copy this file (or your version) into the Project Directory
                made by the VC++ Express Edition.  (E.g., move it into
                "My Documents\Visual Studio 2005\Projects\JaLeoTest1"
           
            In the solution Explorer, right click on the project name
                (in bold beneath the Solution name, which is the same).
                Select Add | Existing Item ... and select the file you just
                moved to the project directory.  This will have VC++
                recognize it as part of the project.
               
        Building the Solution:
            Perform Build | Solution (or click F7).
                You should see the program compile, link, and report
                Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped
                in the Build Output.
               
        Testing the Solution:
            Confirm the program works using Debug | Start Without Debugging
            (or Ctrl-F5).  Do it for several inputs of names.  Even if you
            enter "Peter" the program does not provide a different response.
           
        Finding the Bug:
            Put a breakpoint in your code.  Because it appears that the
            function ask_user() never returns 1, I suggest placing a break-
            point on the line "if (ret == 0)" in the definition of function
            ask_user().
           
            You set the breakpoint by clicking to the left of the statement
            in the grey left margin of the editor.  A red ball symbol appears
            when the breakpoint is set.
           
            Run the program with Debug | Start Debugging (F5).  When you are
            prompted for your name, enter "Peter" and click Enter.
           
            When the debugger stops on the breakpoint, look at the values in
            the lower-left corner in the Autos pane.  Notice that variable ret
            has value "1" and that the array name[] has something odd after "Peter". 
            Click the "+" next to "name" in the Autos Name column of the debugger
            window.
           
            Do you see the decimal value 10 in name[5] before the ending '\0'
            in name[ 6 ]   That is why the string compare does not match "Peter".
           
            Look in the Output from Debug in the Output window net to the Autos
            window.  There are many messages about files that are used in
            running your program and for which "No symbols loaded."  This is
            not a problem.  It simply means that there are libraries used in
            running your program for which no symbolic information (such as source
            code and other information) is available.  You don't need that to
            debug your own program, because you can see where you are in your
            program anyhow if you need to look at the code more closely. 
           
            Click F5 to end the debugging execution.
           
            You now have enough information to find out what the problem is.
           
            I have placed the solution in comments at the end of this program.
            (I didn't know that either, until I saw it here.)       
       
        */
           
      

    #include <stdio.h>
        /* For console text input-output */

    #include <string.h>
        /* For string comparison */

     

    int ask_user(void)
    {   /* Obtain the user's name as input
           return 1 if it is "Peter",
                  0 for anything else.
                  */
                 
        int ret;

        char name[10];
            /* Allow up to 9 characters in the name
               plus a trailing null, '\0'. */

        fputs("Dein Name: ", stdout);
            /* Use text input-output with file names to
               have all input-output at the same level. */

        fflush(stdout);
            /* Ensure that the prompt is output before
               waiting on input.
               */

        fgets(name, sizeof name, stdin);
            /* Take no chances with buffer over-run and
               unterminated string buffers.  fgets
               always returns a final '\0' and does not
               exceed the buffer that is provided.
               */

        ret = strcmp(name, "Peter");
            /* BUG WARNING.  There is a bug here.  I am
               leaving it in to to demonstrate how to find it.
               See the comments at the top of this file for
               how to test the program, confirm that it doesn't
               work, and then reveal the problem using the
               VC++ 2005 Express Edition debugger.
               */

        if (ret == 0)
            return 1;

        return 0;

        } /* ask_user */
       

    int main(int argc, char *argv[])
    {   /* Program to see if the user is Peter. */

        int is_peter;
       
        fputs("JaLeoTest1> 1.01 Demonstration of an easy bug to make\n", stdout);
        fputs("            when performing console input in C Language\n\n", stdout);

        fputs("            Dieses Programm findet dem Peter!\n\n", stdout);

        is_peter = ask_user();

        if(is_peter == 1)
             fputs("\nJawoll, Du bist ein echter Peter!\n\n", stdout);
        else fputs("\nOh, leider bist kein echter Peter!\n\n", stdout);

        return 0;
       
        } /* main */
       
    /* What's the Bug, and How Can You Fix It
       ---------------------------------------
      
       When you enter "Peter" there is an additional value, 10,
       returned by fgets in name[5].  This is the newline code from
       pressing the enter key.  fgets() will return input characters
       up until a newline character (which is returned), until an
       end-of-file (which is not returned), or the input buffer is
       filled when an ending null ('\0') character is also added
       to the buffer.
      
       You can confirm that this is the problem by using
      
            ret = strcmp(name, "Peter\n");
           
       in ask_user().  This covers all cases (so long as the buffer size
       is at least 7 bytes).  It is possible to have an end-of-file
       in the input without any end-of-line, but that is hard to do.
      
       Figuring out how to deal with an OPTIONAL end-of-line occurence
       so that all cases work is an useful exercise.  The challenge is to
       do it without introducing any new bugs.
      
       Finding Out How fgets() Really Works
       ------------------------------------
      
       Little pocket references don't include all of the information
       about edge cases for fgets() so I reached onto my bookshelf.
      
       I have P. J. Plauger's "The Standard C Library" from 1992, and
       I missed it the first time.  It is this statement from the ANSI
       C Standard:
      
            "No additional characters are read after a new-line
            character (which is retained) or after end-of-file."
           
       In my copy of Harbison & Steele's "C: A Reference Manual" 4th
       edition (1995), they are more explicit about the new-line case.
      
       Best of all, if you use VC++ Help | Index and Look for: fgets
       you'll see that this standard behavior is confirmed in the
       VC++ Runtime Library Reference.
      
       This must be a problem that every newcomer to C Language stumbles
       on, don't you think
      
      */

     
    /*  1.01 2006-02-04-18:15 correct function-key error in the comment on
             running with debugger; space out name[ 6 ] to keep the Forum
             from making an emoticon from it.
        1.00 2006-02-04-17:41 Oops, put it under source-code control.
        0.95 2006-02-04-17:33 Document the bug and the rules about fgets() in
             comments and add a title line to the output.
        0.90 2006-02-04-17:00 Confirm that the problem can be cured by including
             a new-line code in the comparison.
        0.85 2006-02-04-16:41 Execute the program, notice that it doesn't
             recognize input of "Peter" and document what the debugging
             session reveals.
        0.75 2006-02-04-15:58 Get clean compile and tidy up use of fgets.
        0.50 2006-02-04-15:48 Tidy up the source code a little just to
             use the same level of input-output throughout and also
             avoid buffer over-run and unterminated strings.
        0.00 2006-02-04-14:40 save JaLeo source code from the Forum.   
        */
       
    /* $Header: /MyProjects/JaLeoTest1/JaLeoTest1.c 2     06-02-04 18:09 Orcmid $    */
       
    /*                          end of JaLeoTest1.c                            */   

     



  • Werner de Jong

    This Programm works perfect:

    #include <stdio.h>

    #include <stdlib.h>

    #include <string.h>

    int ask_user(void)

    {

    int ret;

    char name[10];

    printf("Dein Name: ");

    fflush(stdout);

    gets(name);

    ret = strcmp(name, "Peter");

    if (ret == 0)

    return 1;

    return 0;

    }

    int main(int argc, char *argv[])

    {

    int is_peter;

    printf("Dieses Programm findet dem Peter!\n");

    is_peter = ask_user();

    if(is_peter == 1)

    {

    printf("Jawoll, Du bist ein echter Peter!\n");

    return 0;

    }

    printf("Oh, leider bist kein echter Peter!\n");

    return 0;

    }

    But i'm not able to debug this, because maybe its in C

    I've downloaded the Symbols for Win XP.

    Thx



  • David Bachy

    JaLeo wrote:

    is it possible to Dissasemble C or C++ code with the Express edition

    The dumpbin utility is included in the Visual C++ 2005 Express Edition. You can use it to show a disassembly of native Windows code from a .EXE or .DLL. Use Tools | Visual Studio 2005 Command Prompt, switch to the directory having the binary file in it, and then do a command like

    C> dumpbin /DISASM yourfile.exe | more

    and you can see what it produces. Jumps and calls won't be to labels, but I assume that you just want to see the machine-language code in assembly format.

    If you have the C or C++ source code, you can see the assembly code that is produced using the debugger and you can also have the compiler produce a file of assembly code. The nice part in this case is the C/C++ source code will be merged into the assembly listing as comments, giving a clue how the code matches up to the C/C++ Language statements that are being implemented.

    If you have a C/C++ program that was compiled for the CLR, you can also see the MSIL code using ILDASM, also supplied.



  • Disassemble C/C++ Code