🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.comp.security
Article #16

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

#16
From: nukq
Date: Fri, 21 Nov 2003 10:38
257 lines
11396 bytes
����������ʵ��:
o.c:
char *table[]={"0","1","2","3",NULL};
char **ptable=table;


t.c:

#include <stdio.h>

void main()
{
    extern char **table;
    extern char **ptable;

    printf("%p\n%p\n",table,ptable);
    return;
}

00401320
00402010

"nukq" <simenking@sohu.com> д���ʼ� news:bpkhhd$2bc$1@news.yaako.com...
> �ǰ�������϶�û��ġ�
> ����table�ĵ�ַ�����ˡ�
> "Qing, Quan" <skipme@nospam.263.net> д���ʼ�
> news:bpjubc$1f2f$1@mail.cn99.com...
> > �ҵ���˼�Ǵ�ӡ������ֵȷʵĪ�����Ȼ��������ַ�Ľ��û�д?���᲻
��
> ��
> > ����ط����ˡ�
> >
> > -- 
> > ------
> > Qing, Quan
> > Center for Nanoscale Science and Technology
> > Peking University
> > Beijing, P.R. China
> > http://www.chem.pku.edu.cn/nanochemistry
> >
> >
> > "nukq" <simenking@sohu.com> д���ʼ� news:bphude$p0f$1@news.yaako.com...
> > > ���岻ͬ�ˡ�*table[]��table�����飬��table������û�д洢�ռ�ģ���Ȼ��
��
> ʾ
> > ��
> > > ���׵�ַ��talbe[0] table[1] ..�Ÿ�����4byte�Ŀռ䡣
> > >
> > > ����Ҫ����
> > > o.c�����Ϊ
> > >
> > > void *__table[]={"0","1","2","3",NULL};
> > > void **table=__table;
> > >
> > >
> > > "Qing, Quan" <skipme@263.net> д���ʼ�
> news:bpfrjc$17uo$1@mail.cn99.com...
> > > > > 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: <bpkpvs$61e$1@news.yaako.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!panix!bloom-beacon.mit.edu!news.cn99.com!news.yaako.com!not-for-mail
References: <uad84zjij.fsf@yaako.com> <bpfrjc$17uo$1@mail.cn99.com> <bphude$p0f$1@news.yaako.com> <bpjubc$1f2f$1@mail.cn99.com> <bpkhhd$2bc$1@news.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: 11047e,a15f179b39aafe37
X-Google-Attributes: gid11047e,public
X-Google-Thread: f5fb9,a15f179b39aafe37
X-Google-Attributes: gidf5fb9,public
X-Google-Thread: 113009,a15f179b39aafe37
X-Google-Attributes: gid113009,public
X-Google-Thread: 10b277,a15f179b39aafe37
X-Google-Attributes: gid10b277,public
X-Google-ArrivalTime: 2003-11-21 02:41:40 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!panix!bloom-beacon.mit.edu!news.cn99.com!news.yaako.com!not-for-mail
From: "nukq" <simenking@sohu.com>
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: Fri, 21 Nov 2003 18:38:49 +0800
Organization: Bentium Ltd. (CN99)
Lines: 259
Message-ID: <bpkpvs$61e$1@news.yaako.com>
References: <uad84zjij.fsf@yaako.com> <bpfrjc$17uo$1@mail.cn99.com> <bphude$p0f$1@news.yaako.com> <bpjubc$1f2f$1@mail.cn99.com> <bpkhhd$2bc$1@news.yaako.com>
Reply-To: "nukq" <simenking@sohu.com>
NNTP-Posting-Host: 218.108.173.68
X-Trace: news.yaako.com 1069411133 6190 218.108.173.68 (21 Nov 2003 10:38:53 GMT)
X-Complaints-To: usenet@news.yaako.com
NNTP-Posting-Date: Fri, 21 Nov 2003 10:38:53 +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