🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.comp.security
Article #11

Re: extern��ָ���ָ�����

#11
From: Qing, Quan
Date: Wed, 19 Nov 2003 13:35
153 lines
8191 bytes
> 804841e:       a1 18 95 04 08          mov    0x8049518,%eax <-----��
0x8049518��ַ�е�ֵ�ŵ�eax��
> 8048423:       83 c0 04                add    $0x4,%eax      <-----�ٰ���
��ֵ��4������Ȼ�����ǵı����г���

> table 8049518
> &table[1] 8048507 <-----������Ȼ����������Ҫ��
> table[1] (null)   <-----������dz�����

0x8049518+0x04=0x804951c����ʹ�ӡ������զ��ϵ�ϵ��أ�:(
��ô����û�д?��

-- 
------
Qing, Quan
Center for Nanoscale Science and Technology
Peking University
Beijing, P.R. China
http://www.chem.pku.edu.cn/nanochemistry
"NewBlue" <NewBlue@yaako.com> д���ʼ� news:uad84zjij.fsf@yaako.com...
> [tips] extern��ָ���ָ�����
>
> alert7  �����ڣ�2003-09-08 13:02
>
>  extern��ָ���ָ�����
>
> by alert7
>
>   gcc��һ��С����,�������Ѿ�֪�����ȽϷ�dz�����Dz�֪���Ŀ��ܻ����ƺü���С
ʱ��
>
>   һֱ���������Ƕ���Ϊchar *argv[]��char **argv�ǵȼ۵ġ���������
> Ҳһֱû�г��?���Խ��ҵ���Ϊchar *argv[]��char **argv�ǵȼ۵ģ�ԭ��
> ��һ��������ͨ�õġ�
>   ���ǣ������һ��BUG������һ�죬���ƾ���֮�������Ƕ���ָ���ָ�����
> �ǵĻ�������ԭ�ͣ�Ӧ�ö����ָ�����顣���������ְѾ���д�ɱ��ģ���ʹ����
��
> ��һЩ��·��
>
>   ���µ��������ҳ�������ģ�table�������ָ�����飬��ʵ����ʵ��o.c�����ǵ�
��
> ���ṩ�������û��Դ���룬����ܲݲݵİ�table����Ϊextern void ** ;
>
> [root@redhat73 root]# cat o.c
> #include <stdio.h>
> void * table[]={"0","1","2","3",NULL};
>
> int test(void )
> {
>
>         return 0;
> }
>
> [root@redhat73 root]# cat t.c
> #include <stdio.h>
> int main(int argc, char *argv[])
> {
>         extern void **table;
>         int t;
>
>         printf("table %x\n",&table);
>         printf("&table[1] %x\n",&table[1]);
>         printf("table[1] %s\n",table[1]);
>
>         return 0;
> }
> [root@redhat73 root]# gcc -c t.c
> [root@redhat73 root]# gcc -o t t.o o.o
> [root@redhat73 root]# ./t
> table 8049518
> &table[1] 8048507 <-----������Ȼ����������Ҫ��
> table[1] (null)   <-----������dz�����
>
> ���������»�����
> 08048400 <main>:
> 8048400:       55                      push   %ebp
> 8048401:       89 e5                   mov    %esp,%ebp
> 8048403:       83 ec 08                sub    $0x8,%esp
> 8048406:       83 ec 08                sub    $0x8,%esp
> 8048409:       68 18 95 04 08          push   $0x8049518  <------table��ַ
> 804840e:       68 d8 84 04 08          push   $0x80484d8
> 8048413:       e8 d8 fe ff ff          call   80482f0 <_init+0x58>
> 8048418:       83 c4 10                add    $0x10,%esp
> 804841b:       83 ec 08                sub    $0x8,%esp
> 804841e:       a1 18 95 04 08          mov    0x8049518,%eax <-----��
0x8049518��ַ�е�ֵ�ŵ�eax��
> 8048423:       83 c0 04                add    $0x4,%eax      <-----�ٰ���
��ֵ��4������Ȼ�����ǵı����г���
> 8048426:       50                      push   %eax
> 8048427:       68 e2 84 04 08          push   $0x80484e2
> 804842c:       e8 bf fe ff ff          call   80482f0 <_init+0x58>
> 8048431:       83 c4 10                add    $0x10,%esp
> 8048434:       83 ec 08                sub    $0x8,%esp
> 8048437:       a1 18 95 04 08          mov    0x8049518,%eax
> 804843c:       83 c0 04                add    $0x4,%eax
> 804843f:       ff 30                   pushl  (%eax)
> 8048441:       68 f0 84 04 08          push   $0x80484f0
> 8048446:       e8 a5 fe ff ff          call   80482f0 <_init+0x58>
> 804844b:       83 c4 10                add    $0x10,%esp
> 804844e:       b8 00 00 00 00          mov    $0x0,%eax
> 8048453:       c9                      leave
> 8048454:       c3                      ret
>
> �������°���ԭ�Ͷ����extern void *table[];
> #include <stdio.h>
> int main(int argc, char *argv[])
> {
>         extern void *table[];
>         int t;
>
>         printf("table %x\n",&table);
>         printf("&table[1] %x\n",&table[1]);
>         printf("table[1] %s\n",table[1]);
>
>         return 0;
> }
> [root@redhat73 root]# gcc -c t.c
> [root@redhat73 root]# gcc -o t t.o o.o
> [root@redhat73 root]# ./t
> table 8049508
> &table[1] 804950c
> table[1] 1
> 08048400 <main>:
> 8048400:       55                      push   %ebp
> 8048401:       89 e5                   mov    %esp,%ebp
> 8048403:       83 ec 08                sub    $0x8,%esp
> 8048406:       83 ec 08                sub    $0x8,%esp
> 8048409:       68 08 95 04 08          push   $0x8049508
> 804840e:       68 c8 84 04 08          push   $0x80484c8
> 8048413:       e8 d8 fe ff ff          call   80482f0 <_init+0x58>
> 8048418:       83 c4 10                add    $0x10,%esp
> 804841b:       83 ec 08                sub    $0x8,%esp
> 804841e:       68 0c 95 04 08          push   $0x804950c  <--------�����
����
> 8048423:       68 d2 84 04 08          push   $0x80484d2
> 8048428:       e8 c3 fe ff ff          call   80482f0 <_init+0x58>
> 804842d:       83 c4 10                add    $0x10,%esp
> 8048430:       83 ec 08                sub    $0x8,%esp
> 8048433:       ff 35 0c 95 04 08       pushl  0x804950c
> 8048439:       68 e0 84 04 08          push   $0x80484e0
> 804843e:       e8 ad fe ff ff          call   80482f0 <_init+0x58>
> 8048443:       83 c4 10                add    $0x10,%esp
> 8048446:       b8 00 00 00 00          mov    $0x0,%eax
> 804844b:       c9                      leave
> 804844c:       c3                      ret
>
> ���ԣ����ǻ���Ҫ�ϸ��պ����ԭ�������塣
>
> ����һЩʵ�飬ָ���ָ���������extern����������Ҫע���ˣ�
> ��ʱ��ָ���ָ�������ָ������Ͳ���ͨ���ˡ�
> -- 
> NewBlue
> �Դ����뿪���Ժ���һֱ�ȴ��������
Technical Details
Message-ID: <bpfrjc$17uo$1@mail.cn99.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!news.cn99.com!not-for-mail
References: <uad84zjij.fsf@yaako.com>

Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB
X-Google-Thread: 1009e6,a15f179b39aafe37
X-Google-Attributes: gid1009e6,public
X-Google-Thread: 1098a9,a15f179b39aafe37
X-Google-Attributes: gid1098a9,public
X-Google-Thread: f5fb9,a15f179b39aafe37
X-Google-Attributes: gidf5fb9,public
X-Google-Thread: 113009,a15f179b39aafe37
X-Google-Attributes: gid113009,public
X-Google-Thread: 11047e,a15f179b39aafe37
X-Google-Attributes: gid11047e,public
X-Google-Thread: 10b277,a15f179b39aafe37
X-Google-Attributes: gid10b277,public
X-Google-ArrivalTime: 2003-11-19 05:37:07 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!news.cn99.com!not-for-mail
From: "Qing, Quan" <skipme@263.net>
Newsgroups: cn.comp.security,cn.comp.programm,cn.comp.lang.c,cn.comp.os.linux,cn.comp.os.freebsd,cn.comp.hacker
Subject: Re: extern��ָ���ָ�����
Date: Wed, 19 Nov 2003 21:35:18 +0800
Organization: Bentium Ltd. (CN99)
Lines: 155
Message-ID: <bpfrjc$17uo$1@mail.cn99.com>
References: <uad84zjij.fsf@yaako.com>
NNTP-Posting-Host: 162.105.153.31
X-Trace: mail.cn99.com 1069248942 40920 162.105.153.31 (19 Nov 2003 13:35:42 GMT)
X-Complaints-To: usenet@news.cn99.com
NNTP-Posting-Date: Wed, 19 Nov 2003 13:35:42 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165