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

  • Home
  • SEARCH
  • 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

Related Questions

my test code is below: main1.c: #include <stdio.h> extern struct tt ; int main()
I have this code below #include <stdio.h> int main(){ int i=0; for(i=0; i<1000; i++)
#include<stdio.h> #include<iostream> #include<fstream> #include<string.h> using namespace std; class base { public: int lookup(char c);
I create a file using the code below: #include <stdio.h> #include <stdlib.h> #include <sys/stat.h>
Consider the code below. What is going on there? #include <iostream> #include <stdio.h> using
I have the code below in my test code in many places: // //
I found this orientation test code below looking for JQTouch reference material. This works
I am using the below code in my test class , to load all
In the below code onclick edit how can the value of tag test be
the code below gives compilation error when I try to create test t[2]; because

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.