Thread: scanf() works without parameters ?

  1. #1
    Registered User
    Join Date
    Apr 2013
    Location
    Still looking..
    Posts
    35

    scanf() works without parameters ?

    I used a decompiler to decompile a C program and this is the result :

    Code:
    // address: 0x8048504
    int main(int argc, char **argv, char **envp) {
        char local0[1024];         // m[r28 - 29]
        int local6;         // r24
    
        printf("What's the password? ");
        __isoc99_scanf();
        local6 = strcmp(local0, "gr8qw");
        if (local6 != 0) {
            local6 = puts("Sorry! Wrong password");
        } else {
            local6 = puts("Yes, you got the right password!");
        }
        return local6;
    }
    How does the scanf() even work in this piece of code ?

    I recalled that scanf needs to have a format string like %d etc..

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Perhaps your decompiler is broken.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    There is no scanf() call in that code. __isoc99_scanf() could be anything. It might be a simplified version of scanf() emitted by a smart compiler. It might mean the decompiler gives up when it encounters functions with variable argument lists, so can't handle things that originated as scanf() calls.

    Bear in mind that an executable program may be reordered or restructured relative to the original code (that's what compiler optimisation often does). Furthermore, decompilers are not guaranteed to be 100% accurate in mapping instructions to C statements.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Apr 2013
    Location
    Still looking..
    Posts
    35
    Thanks @grumpy for the detailed explanation.

    I used the Boomerang Decompiler for this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about how scanf works
    By kabaniz in forum C Programming
    Replies: 9
    Last Post: 01-07-2011, 12:26 PM
  2. Use c++ to do my works on web
    By mozee in forum C++ Programming
    Replies: 7
    Last Post: 09-18-2010, 09:09 PM
  3. How come this works?
    By caduardo21 in forum C Programming
    Replies: 1
    Last Post: 02-11-2006, 05:15 PM
  4. First scanf() skips next scanf() !
    By grahampatten in forum C Programming
    Replies: 5
    Last Post: 08-17-2004, 02:47 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 04:34 AM