here is my disas code:
这是我的disas代码:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and
here is my disas code:
这是我的disas代码:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and $0xfffffff0,%esp
0x08048453 <+6>: sub $0x20,%esp
0x08048456 <+9>: movl $0x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl $0x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp $0x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl $0x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl $0x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov $0x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
what i'm tring to examine is $0x208c. When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c. When i type Info registers and look at eax it says the value which i provided. So basically this program compares two values and depending on that prints something out.The problem is that this is homework from university and I have not got code. Hope you can help. Thank you.
我要检查的是$ 0x208c。当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存。当我输入Info寄存器并查看eax时,它会显示我提供的值。所以基本上这个程序比较两个值,并根据打印出来的东西。问题是这是大学的家庭作业,我没有代码。希望你能帮忙。谢谢。
3 个解决方案
#1
14
When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c
当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存
The disassembly for your program says that it does something like this:
你的程序的反汇编说它做了这样的事情:
puts("some string");
int i;
scanf("%d", &i); // I don't know what the actual format string is.
// You can find out with x/s 0x8048555
if (i == 0x208c) { ... } else { ... }
In other words, the 0x208c is a value (8332) that your program has hard-coded in it, and is not a pointer. Therefore, GDB is entirely correct in telling you that if you interpret 0x208c as a pointer, that pointer does not point to readable memory.
换句话说,0x208c是您的程序在其中硬编码的值(8332),而不是指针。因此,GDB完全正确地告诉您如果将0x208c解释为指针,则该指针不指向可读内存。
i finally figured out to use print statement instead of x/xw
我终于想通了使用print语句而不是x / xw
You appear to not understand the difference between print and examine commands. Consider this example:
您似乎不理解print和examine命令之间的区别。考虑这个例子:
int foo = 42;
int *pfoo = &foo;
With above, print pfoo will give you the address of foo, and x pfoo will give you the value stored at that address (i.e. the value of foo).
如上所述,print pfoo将为您提供foo的地址,x pfoo将为您提供存储在该地址的值(即foo的值)。
#2
3
I found out that it is impossible to examine mmaped memory that does not have PROT_READ flag. This is not the OPs problem, but it was mine, and the error message is the same.
我发现无法检查没有PROT_READ标志的mmaped内存。这不是OP问题,但它是我的,错误信息是相同的。
Instead of
mmap(0, size, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
do
mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
and voila, the memory can be examined.
瞧,可以检查记忆。
#3
0
Uninitialized pointers
It is kind of obvious in retrospective, but this is what was causing GDB to show that error message to me. Along:
这在回顾展中是显而易见的,但这是导致GDB向我显示错误消息的原因。沿:
#include <stdio.h>
int main(void) {
int *p;
printf("*p = %d\n", *p);
}
And then:
gdb -q -nh -ex run ./tmp.out
Reading symbols from ./tmp.out...done.
Starting program: /home/ciro/bak/git/cpp-cheat/gdb/tmp.out
Program received signal SIGSEGV, Segmentation fault.
0x0000555555554656 in main () at tmp.c:5
5 printf("*p = %d\n", *p);
(gdb) print *p
Cannot access memory at address 0x0
But in a complex program of course, and where the address was something random different from zero.
但在一个复杂的程序当然,地址是零随机的不同之处。
xfffffff0,%esp
0x08048453 <+6>: sub
here is my disas code:
这是我的disas代码:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and $0xfffffff0,%esp
0x08048453 <+6>: sub $0x20,%esp
0x08048456 <+9>: movl $0x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl $0x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp $0x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl $0x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl $0x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov $0x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
what i'm tring to examine is $0x208c. When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c. When i type Info registers and look at eax it says the value which i provided. So basically this program compares two values and depending on that prints something out.The problem is that this is homework from university and I have not got code. Hope you can help. Thank you.
我要检查的是$ 0x208c。当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存。当我输入Info寄存器并查看eax时,它会显示我提供的值。所以基本上这个程序比较两个值,并根据打印出来的东西。问题是这是大学的家庭作业,我没有代码。希望你能帮忙。谢谢。
3 个解决方案
#1
14
When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c
当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存
The disassembly for your program says that it does something like this:
你的程序的反汇编说它做了这样的事情:
puts("some string");
int i;
scanf("%d", &i); // I don't know what the actual format string is.
// You can find out with x/s 0x8048555
if (i == 0x208c) { ... } else { ... }
In other words, the 0x208c is a value (8332) that your program has hard-coded in it, and is not a pointer. Therefore, GDB is entirely correct in telling you that if you interpret 0x208c as a pointer, that pointer does not point to readable memory.
换句话说,0x208c是您的程序在其中硬编码的值(8332),而不是指针。因此,GDB完全正确地告诉您如果将0x208c解释为指针,则该指针不指向可读内存。
i finally figured out to use print statement instead of x/xw
我终于想通了使用print语句而不是x / xw
You appear to not understand the difference between print and examine commands. Consider this example:
您似乎不理解print和examine命令之间的区别。考虑这个例子:
int foo = 42;
int *pfoo = &foo;
With above, print pfoo will give you the address of foo, and x pfoo will give you the value stored at that address (i.e. the value of foo).
如上所述,print pfoo将为您提供foo的地址,x pfoo将为您提供存储在该地址的值(即foo的值)。
#2
3
I found out that it is impossible to examine mmaped memory that does not have PROT_READ flag. This is not the OPs problem, but it was mine, and the error message is the same.
我发现无法检查没有PROT_READ标志的mmaped内存。这不是OP问题,但它是我的,错误信息是相同的。
Instead of
mmap(0, size, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
do
mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
and voila, the memory can be examined.
瞧,可以检查记忆。
#3
0
Uninitialized pointers
It is kind of obvious in retrospective, but this is what was causing GDB to show that error message to me. Along:
这在回顾展中是显而易见的,但这是导致GDB向我显示错误消息的原因。沿:
#include <stdio.h>
int main(void) {
int *p;
printf("*p = %d\n", *p);
}
And then:
gdb -q -nh -ex run ./tmp.out
Reading symbols from ./tmp.out...done.
Starting program: /home/ciro/bak/git/cpp-cheat/gdb/tmp.out
Program received signal SIGSEGV, Segmentation fault.
0x0000555555554656 in main () at tmp.c:5
5 printf("*p = %d\n", *p);
(gdb) print *p
Cannot access memory at address 0x0
But in a complex program of course, and where the address was something random different from zero.
但在一个复杂的程序当然,地址是零随机的不同之处。
x20,%esp
0x08048456 <+9>: movl
here is my disas code:
这是我的disas代码:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and $0xfffffff0,%esp
0x08048453 <+6>: sub $0x20,%esp
0x08048456 <+9>: movl $0x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl $0x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp $0x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl $0x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl $0x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov $0x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
what i'm tring to examine is $0x208c. When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c. When i type Info registers and look at eax it says the value which i provided. So basically this program compares two values and depending on that prints something out.The problem is that this is homework from university and I have not got code. Hope you can help. Thank you.
我要检查的是$ 0x208c。当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存。当我输入Info寄存器并查看eax时,它会显示我提供的值。所以基本上这个程序比较两个值,并根据打印出来的东西。问题是这是大学的家庭作业,我没有代码。希望你能帮忙。谢谢。
3 个解决方案
#1
14
When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c
当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存
The disassembly for your program says that it does something like this:
你的程序的反汇编说它做了这样的事情:
puts("some string");
int i;
scanf("%d", &i); // I don't know what the actual format string is.
// You can find out with x/s 0x8048555
if (i == 0x208c) { ... } else { ... }
In other words, the 0x208c is a value (8332) that your program has hard-coded in it, and is not a pointer. Therefore, GDB is entirely correct in telling you that if you interpret 0x208c as a pointer, that pointer does not point to readable memory.
换句话说,0x208c是您的程序在其中硬编码的值(8332),而不是指针。因此,GDB完全正确地告诉您如果将0x208c解释为指针,则该指针不指向可读内存。
i finally figured out to use print statement instead of x/xw
我终于想通了使用print语句而不是x / xw
You appear to not understand the difference between print and examine commands. Consider this example:
您似乎不理解print和examine命令之间的区别。考虑这个例子:
int foo = 42;
int *pfoo = &foo;
With above, print pfoo will give you the address of foo, and x pfoo will give you the value stored at that address (i.e. the value of foo).
如上所述,print pfoo将为您提供foo的地址,x pfoo将为您提供存储在该地址的值(即foo的值)。
#2
3
I found out that it is impossible to examine mmaped memory that does not have PROT_READ flag. This is not the OPs problem, but it was mine, and the error message is the same.
我发现无法检查没有PROT_READ标志的mmaped内存。这不是OP问题,但它是我的,错误信息是相同的。
Instead of
mmap(0, size, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
do
mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
and voila, the memory can be examined.
瞧,可以检查记忆。
#3
0
Uninitialized pointers
It is kind of obvious in retrospective, but this is what was causing GDB to show that error message to me. Along:
这在回顾展中是显而易见的,但这是导致GDB向我显示错误消息的原因。沿:
#include <stdio.h>
int main(void) {
int *p;
printf("*p = %d\n", *p);
}
And then:
gdb -q -nh -ex run ./tmp.out
Reading symbols from ./tmp.out...done.
Starting program: /home/ciro/bak/git/cpp-cheat/gdb/tmp.out
Program received signal SIGSEGV, Segmentation fault.
0x0000555555554656 in main () at tmp.c:5
5 printf("*p = %d\n", *p);
(gdb) print *p
Cannot access memory at address 0x0
But in a complex program of course, and where the address was something random different from zero.
但在一个复杂的程序当然,地址是零随机的不同之处。
x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl
here is my disas code:
这是我的disas代码:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and $0xfffffff0,%esp
0x08048453 <+6>: sub $0x20,%esp
0x08048456 <+9>: movl $0x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl $0x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp $0x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl $0x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl $0x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov $0x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
what i'm tring to examine is $0x208c. When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c. When i type Info registers and look at eax it says the value which i provided. So basically this program compares two values and depending on that prints something out.The problem is that this is homework from university and I have not got code. Hope you can help. Thank you.
我要检查的是$ 0x208c。当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存。当我输入Info寄存器并查看eax时,它会显示我提供的值。所以基本上这个程序比较两个值,并根据打印出来的东西。问题是这是大学的家庭作业,我没有代码。希望你能帮忙。谢谢。
3 个解决方案
#1
14
When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c
当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存
The disassembly for your program says that it does something like this:
你的程序的反汇编说它做了这样的事情:
puts("some string");
int i;
scanf("%d", &i); // I don't know what the actual format string is.
// You can find out with x/s 0x8048555
if (i == 0x208c) { ... } else { ... }
In other words, the 0x208c is a value (8332) that your program has hard-coded in it, and is not a pointer. Therefore, GDB is entirely correct in telling you that if you interpret 0x208c as a pointer, that pointer does not point to readable memory.
换句话说,0x208c是您的程序在其中硬编码的值(8332),而不是指针。因此,GDB完全正确地告诉您如果将0x208c解释为指针,则该指针不指向可读内存。
i finally figured out to use print statement instead of x/xw
我终于想通了使用print语句而不是x / xw
You appear to not understand the difference between print and examine commands. Consider this example:
您似乎不理解print和examine命令之间的区别。考虑这个例子:
int foo = 42;
int *pfoo = &foo;
With above, print pfoo will give you the address of foo, and x pfoo will give you the value stored at that address (i.e. the value of foo).
如上所述,print pfoo将为您提供foo的地址,x pfoo将为您提供存储在该地址的值(即foo的值)。
#2
3
I found out that it is impossible to examine mmaped memory that does not have PROT_READ flag. This is not the OPs problem, but it was mine, and the error message is the same.
我发现无法检查没有PROT_READ标志的mmaped内存。这不是OP问题,但它是我的,错误信息是相同的。
Instead of
mmap(0, size, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
do
mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
and voila, the memory can be examined.
瞧,可以检查记忆。
#3
0
Uninitialized pointers
It is kind of obvious in retrospective, but this is what was causing GDB to show that error message to me. Along:
这在回顾展中是显而易见的,但这是导致GDB向我显示错误消息的原因。沿:
#include <stdio.h>
int main(void) {
int *p;
printf("*p = %d\n", *p);
}
And then:
gdb -q -nh -ex run ./tmp.out
Reading symbols from ./tmp.out...done.
Starting program: /home/ciro/bak/git/cpp-cheat/gdb/tmp.out
Program received signal SIGSEGV, Segmentation fault.
0x0000555555554656 in main () at tmp.c:5
5 printf("*p = %d\n", *p);
(gdb) print *p
Cannot access memory at address 0x0
But in a complex program of course, and where the address was something random different from zero.
但在一个复杂的程序当然,地址是零随机的不同之处。
x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp
here is my disas code:
这是我的disas代码:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and $0xfffffff0,%esp
0x08048453 <+6>: sub $0x20,%esp
0x08048456 <+9>: movl $0x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl $0x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp $0x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl $0x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl $0x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov $0x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
what i'm tring to examine is $0x208c. When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c. When i type Info registers and look at eax it says the value which i provided. So basically this program compares two values and depending on that prints something out.The problem is that this is homework from university and I have not got code. Hope you can help. Thank you.
我要检查的是$ 0x208c。当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存。当我输入Info寄存器并查看eax时,它会显示我提供的值。所以基本上这个程序比较两个值,并根据打印出来的东西。问题是这是大学的家庭作业,我没有代码。希望你能帮忙。谢谢。
3 个解决方案
#1
14
When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c
当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存
The disassembly for your program says that it does something like this:
你的程序的反汇编说它做了这样的事情:
puts("some string");
int i;
scanf("%d", &i); // I don't know what the actual format string is.
// You can find out with x/s 0x8048555
if (i == 0x208c) { ... } else { ... }
In other words, the 0x208c is a value (8332) that your program has hard-coded in it, and is not a pointer. Therefore, GDB is entirely correct in telling you that if you interpret 0x208c as a pointer, that pointer does not point to readable memory.
换句话说,0x208c是您的程序在其中硬编码的值(8332),而不是指针。因此,GDB完全正确地告诉您如果将0x208c解释为指针,则该指针不指向可读内存。
i finally figured out to use print statement instead of x/xw
我终于想通了使用print语句而不是x / xw
You appear to not understand the difference between print and examine commands. Consider this example:
您似乎不理解print和examine命令之间的区别。考虑这个例子:
int foo = 42;
int *pfoo = &foo;
With above, print pfoo will give you the address of foo, and x pfoo will give you the value stored at that address (i.e. the value of foo).
如上所述,print pfoo将为您提供foo的地址,x pfoo将为您提供存储在该地址的值(即foo的值)。
#2
3
I found out that it is impossible to examine mmaped memory that does not have PROT_READ flag. This is not the OPs problem, but it was mine, and the error message is the same.
我发现无法检查没有PROT_READ标志的mmaped内存。这不是OP问题,但它是我的,错误信息是相同的。
Instead of
mmap(0, size, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
do
mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
and voila, the memory can be examined.
瞧,可以检查记忆。
#3
0
Uninitialized pointers
It is kind of obvious in retrospective, but this is what was causing GDB to show that error message to me. Along:
这在回顾展中是显而易见的,但这是导致GDB向我显示错误消息的原因。沿:
#include <stdio.h>
int main(void) {
int *p;
printf("*p = %d\n", *p);
}
And then:
gdb -q -nh -ex run ./tmp.out
Reading symbols from ./tmp.out...done.
Starting program: /home/ciro/bak/git/cpp-cheat/gdb/tmp.out
Program received signal SIGSEGV, Segmentation fault.
0x0000555555554656 in main () at tmp.c:5
5 printf("*p = %d\n", *p);
(gdb) print *p
Cannot access memory at address 0x0
But in a complex program of course, and where the address was something random different from zero.
但在一个复杂的程序当然,地址是零随机的不同之处。
x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl
here is my disas code:
这是我的disas代码:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and $0xfffffff0,%esp
0x08048453 <+6>: sub $0x20,%esp
0x08048456 <+9>: movl $0x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl $0x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp $0x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl $0x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl $0x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov $0x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
what i'm tring to examine is $0x208c. When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c. When i type Info registers and look at eax it says the value which i provided. So basically this program compares two values and depending on that prints something out.The problem is that this is homework from university and I have not got code. Hope you can help. Thank you.
我要检查的是$ 0x208c。当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存。当我输入Info寄存器并查看eax时,它会显示我提供的值。所以基本上这个程序比较两个值,并根据打印出来的东西。问题是这是大学的家庭作业,我没有代码。希望你能帮忙。谢谢。
3 个解决方案
#1
14
When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c
当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存
The disassembly for your program says that it does something like this:
你的程序的反汇编说它做了这样的事情:
puts("some string");
int i;
scanf("%d", &i); // I don't know what the actual format string is.
// You can find out with x/s 0x8048555
if (i == 0x208c) { ... } else { ... }
In other words, the 0x208c is a value (8332) that your program has hard-coded in it, and is not a pointer. Therefore, GDB is entirely correct in telling you that if you interpret 0x208c as a pointer, that pointer does not point to readable memory.
换句话说,0x208c是您的程序在其中硬编码的值(8332),而不是指针。因此,GDB完全正确地告诉您如果将0x208c解释为指针,则该指针不指向可读内存。
i finally figured out to use print statement instead of x/xw
我终于想通了使用print语句而不是x / xw
You appear to not understand the difference between print and examine commands. Consider this example:
您似乎不理解print和examine命令之间的区别。考虑这个例子:
int foo = 42;
int *pfoo = &foo;
With above, print pfoo will give you the address of foo, and x pfoo will give you the value stored at that address (i.e. the value of foo).
如上所述,print pfoo将为您提供foo的地址,x pfoo将为您提供存储在该地址的值(即foo的值)。
#2
3
I found out that it is impossible to examine mmaped memory that does not have PROT_READ flag. This is not the OPs problem, but it was mine, and the error message is the same.
我发现无法检查没有PROT_READ标志的mmaped内存。这不是OP问题,但它是我的,错误信息是相同的。
Instead of
mmap(0, size, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
do
mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
and voila, the memory can be examined.
瞧,可以检查记忆。
#3
0
Uninitialized pointers
It is kind of obvious in retrospective, but this is what was causing GDB to show that error message to me. Along:
这在回顾展中是显而易见的,但这是导致GDB向我显示错误消息的原因。沿:
#include <stdio.h>
int main(void) {
int *p;
printf("*p = %d\n", *p);
}
And then:
gdb -q -nh -ex run ./tmp.out
Reading symbols from ./tmp.out...done.
Starting program: /home/ciro/bak/git/cpp-cheat/gdb/tmp.out
Program received signal SIGSEGV, Segmentation fault.
0x0000555555554656 in main () at tmp.c:5
5 printf("*p = %d\n", *p);
(gdb) print *p
Cannot access memory at address 0x0
But in a complex program of course, and where the address was something random different from zero.
但在一个复杂的程序当然,地址是零随机的不同之处。
x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl
here is my disas code:
这是我的disas代码:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and $0xfffffff0,%esp
0x08048453 <+6>: sub $0x20,%esp
0x08048456 <+9>: movl $0x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl $0x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp $0x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl $0x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl $0x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov $0x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
what i'm tring to examine is $0x208c. When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c. When i type Info registers and look at eax it says the value which i provided. So basically this program compares two values and depending on that prints something out.The problem is that this is homework from university and I have not got code. Hope you can help. Thank you.
我要检查的是$ 0x208c。当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存。当我输入Info寄存器并查看eax时,它会显示我提供的值。所以基本上这个程序比较两个值,并根据打印出来的东西。问题是这是大学的家庭作业,我没有代码。希望你能帮忙。谢谢。
3 个解决方案
#1
14
When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c
当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存
The disassembly for your program says that it does something like this:
你的程序的反汇编说它做了这样的事情:
puts("some string");
int i;
scanf("%d", &i); // I don't know what the actual format string is.
// You can find out with x/s 0x8048555
if (i == 0x208c) { ... } else { ... }
In other words, the 0x208c is a value (8332) that your program has hard-coded in it, and is not a pointer. Therefore, GDB is entirely correct in telling you that if you interpret 0x208c as a pointer, that pointer does not point to readable memory.
换句话说,0x208c是您的程序在其中硬编码的值(8332),而不是指针。因此,GDB完全正确地告诉您如果将0x208c解释为指针,则该指针不指向可读内存。
i finally figured out to use print statement instead of x/xw
我终于想通了使用print语句而不是x / xw
You appear to not understand the difference between print and examine commands. Consider this example:
您似乎不理解print和examine命令之间的区别。考虑这个例子:
int foo = 42;
int *pfoo = &foo;
With above, print pfoo will give you the address of foo, and x pfoo will give you the value stored at that address (i.e. the value of foo).
如上所述,print pfoo将为您提供foo的地址,x pfoo将为您提供存储在该地址的值(即foo的值)。
#2
3
I found out that it is impossible to examine mmaped memory that does not have PROT_READ flag. This is not the OPs problem, but it was mine, and the error message is the same.
我发现无法检查没有PROT_READ标志的mmaped内存。这不是OP问题,但它是我的,错误信息是相同的。
Instead of
mmap(0, size, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
do
mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
and voila, the memory can be examined.
瞧,可以检查记忆。
#3
0
Uninitialized pointers
It is kind of obvious in retrospective, but this is what was causing GDB to show that error message to me. Along:
这在回顾展中是显而易见的,但这是导致GDB向我显示错误消息的原因。沿:
#include <stdio.h>
int main(void) {
int *p;
printf("*p = %d\n", *p);
}
And then:
gdb -q -nh -ex run ./tmp.out
Reading symbols from ./tmp.out...done.
Starting program: /home/ciro/bak/git/cpp-cheat/gdb/tmp.out
Program received signal SIGSEGV, Segmentation fault.
0x0000555555554656 in main () at tmp.c:5
5 printf("*p = %d\n", *p);
(gdb) print *p
Cannot access memory at address 0x0
But in a complex program of course, and where the address was something random different from zero.
但在一个复杂的程序当然,地址是零随机的不同之处。
x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov
here is my disas code:
这是我的disas代码:
0x0804844d <+0>: push %ebp
0x0804844e <+1>: mov %esp,%ebp
0x08048450 <+3>: and $0xfffffff0,%esp
0x08048453 <+6>: sub $0x20,%esp
0x08048456 <+9>: movl $0x8048540,(%esp)
0x0804845d <+16>: call 0x8048310 <puts@plt>
0x08048462 <+21>: lea 0x1c(%esp),%eax
0x08048466 <+25>: mov %eax,0x4(%esp)
0x0804846a <+29>: movl $0x8048555,(%esp)
0x08048471 <+36>: call 0x8048320 <scanf@plt>
0x08048476 <+41>: mov 0x1c(%esp),%eax
0x0804847a <+45>: cmp $0x208c,%eax
0x0804847f <+50>: jne 0x804848f <main+66>
0x08048481 <+52>: movl $0x8048558,(%esp)
0x08048488 <+59>: call 0x8048310 <puts@plt>
0x0804848d <+64>: jmp 0x804849b <main+78>
=> 0x0804848f <+66>: movl $0x8048569,(%esp)
0x08048496 <+73>: call 0x8048310 <puts@plt>
0x0804849b <+78>: mov $0x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
what i'm tring to examine is $0x208c. When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c. When i type Info registers and look at eax it says the value which i provided. So basically this program compares two values and depending on that prints something out.The problem is that this is homework from university and I have not got code. Hope you can help. Thank you.
我要检查的是$ 0x208c。当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存。当我输入Info寄存器并查看eax时,它会显示我提供的值。所以基本上这个程序比较两个值,并根据打印出来的东西。问题是这是大学的家庭作业,我没有代码。希望你能帮忙。谢谢。
3 个解决方案
#1
14
When I type x/xw 0x208c it gives me back error which says Cannot access memory at address 0x208c
当我输入x / xw 0x208c时,它会返回错误,表示无法访问地址0x208c处的内存
The disassembly for your program says that it does something like this:
你的程序的反汇编说它做了这样的事情:
puts("some string");
int i;
scanf("%d", &i); // I don't know what the actual format string is.
// You can find out with x/s 0x8048555
if (i == 0x208c) { ... } else { ... }
In other words, the 0x208c is a value (8332) that your program has hard-coded in it, and is not a pointer. Therefore, GDB is entirely correct in telling you that if you interpret 0x208c as a pointer, that pointer does not point to readable memory.
换句话说,0x208c是您的程序在其中硬编码的值(8332),而不是指针。因此,GDB完全正确地告诉您如果将0x208c解释为指针,则该指针不指向可读内存。
i finally figured out to use print statement instead of x/xw
我终于想通了使用print语句而不是x / xw
You appear to not understand the difference between print and examine commands. Consider this example:
您似乎不理解print和examine命令之间的区别。考虑这个例子:
int foo = 42;
int *pfoo = &foo;
With above, print pfoo will give you the address of foo, and x pfoo will give you the value stored at that address (i.e. the value of foo).
如上所述,print pfoo将为您提供foo的地址,x pfoo将为您提供存储在该地址的值(即foo的值)。
#2
3
I found out that it is impossible to examine mmaped memory that does not have PROT_READ flag. This is not the OPs problem, but it was mine, and the error message is the same.
我发现无法检查没有PROT_READ标志的mmaped内存。这不是OP问题,但它是我的,错误信息是相同的。
Instead of
mmap(0, size, PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
do
mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
and voila, the memory can be examined.
瞧,可以检查记忆。
#3
0
Uninitialized pointers
It is kind of obvious in retrospective, but this is what was causing GDB to show that error message to me. Along:
这在回顾展中是显而易见的,但这是导致GDB向我显示错误消息的原因。沿:
#include <stdio.h>
int main(void) {
int *p;
printf("*p = %d\n", *p);
}
And then:
gdb -q -nh -ex run ./tmp.out
Reading symbols from ./tmp.out...done.
Starting program: /home/ciro/bak/git/cpp-cheat/gdb/tmp.out
Program received signal SIGSEGV, Segmentation fault.
0x0000555555554656 in main () at tmp.c:5
5 printf("*p = %d\n", *p);
(gdb) print *p
Cannot access memory at address 0x0
But in a complex program of course, and where the address was something random different from zero.
但在一个复杂的程序当然,地址是零随机的不同之处。
x0,%eax
0x080484a0 <+83>: leave
0x080484a1 <+84>: ret
0x08