Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1033805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:17:17+00:00 2026-05-16T14:17:17+00:00

Below is my code (test.c): #include <stdio.h> #include <string.h> int main(int argc, char **argv)

  • 0

Below is my code (test.c):

#include <stdio.h>
#include <string.h>

int main(int argc, char **argv) {

 char passwd[] = "pass";

 if (argc < 2) {
        printf("usage: %s <given-password>\n", argv[0]);
        return 0;
 }

 if (!strncmp(passwd, argv[1],4)) {
        printf("Green light!\n");
        return 1;
 }

 printf("Red light!\n");
 return 0;
}

I compiled using :

  gcc -o test test.c

    And I started debugger: `gdb ./test`
    (gdb) disassemble main
    Dump of assembler code for function main:
    0x08048404 <main+0>:    lea    0x4(%esp),%ecx
    ......
    0x08048456 <main+82>:   mov    0x4(%edx),%eax
    0x08048459 <main+85>:   add    $0x4,%eax
    0x0804845c <main+88>:   mov    (%eax),%eax
    0x0804845e <main+90>:   movl   $0x4,0x8(%esp)
    0x08048466 <main+98>:   mov    %eax,0x4(%esp)
    0x0804846a <main+102>:  lea    -0x9(%ebp),%eax
    0x0804846d <main+105>:  mov    %eax,(%esp)
    0x08048470 <main+108>:  call   0x8048318 <strncmp@plt>
    0x08048475 <main+113>:  test   %eax,%eax
    0x08048477 <main+115>:  jne    0x804848e <main+138>
    0x08048479 <main+117>:  movl   $0x804859c,(%esp)
    0x08048480 <main+124>:  call   0x8048308 <puts@plt>
    0x08048485 <main+129>:  movl   $0x1,-0x18(%ebp)
 ...........
    0x080484a8 <main+164>:  pop    %ebp
    0x080484a9 <main+165>:  lea    -0x4(%ecx),%esp
    0x080484ac <main+168>:  ret
    End of assembler dump.

I set breakpoint at main+108 and run prog!

    (gdb) break *main+108
    Breakpoint 1 at 0x8048470
    (gdb) run p@ss
    Starting program: /etc/hien/test p@ss

    Breakpoint 1, 0x08048470 in main ()
    eax            0xbfffe9ff       -1073747457
    ecx            0xbfffea20       -1073747424
    edx            0xbfffea20       -1073747424
    ebx            0xaebff4 11452404
    esp            0xbfffe9e0       0xbfffe9e0
    ebp            0xbfffea08       0xbfffea08
    esi            0x994ca0 10046624
    edi            0x0      0
    eip            0x8048470        0x8048470 <main+108>
    eflags         0x282    [ SF IF ]
    cs             0x73     115
    ss             0x7b     123
    ds             0x7b     123
    es             0x7b     123
    fs             0x0      0
    gs             0x33     51
    (gdb) x/s $eax
    0xbfffe9ff:      "pass"
    (gdb) x/s $ecx
    0xbfffea20:      "\002"
    (gdb)

Which register can show value of “argv[1]”?
Please help me!Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:17:18+00:00Added an answer on May 16, 2026 at 2:17 pm

    The calling convention should be that all parameters are pushed to the stack. So try

    (gdb) x/s *(0 + (void**)$esp)
    # should show "pass"
    (gdb) x/s *(1 + (void**)$esp)
    # should show argv[1]
    (gdb) x/d *(2 + (void**)$esp)
    # should show 4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From Xtream How do I specify that a field should… May 16, 2026 at 5:07 pm
  • Editorial Team
    Editorial Team added an answer Best is to use some appropriate combination of these window… May 16, 2026 at 5:07 pm
  • Editorial Team
    Editorial Team added an answer You need to type-cast your parameter marker so DB2 knows… May 16, 2026 at 5:07 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

The test code below leads to a null pointer deference bug on a String
Here's my code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <wait.h> #include <readline/readline.h> #define
I've discovered that std::string s are very slow compared to old-fashioned null-terminated strings, so
I have some code that I want to build. The code uses boost::ptr_map class
I've been trying to get this code to work for hours! All I need
This might not appear like a programming question, but inherently deals with code. I
When I run this code the page repeats its self. I also need it
[Updated]: Answer inline below question I have an inspecting program and one objective is
My initial suspicion was that there was a circular dependency in my code and
I have been working for a couple of days on a problem with my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.