-
Notifications
You must be signed in to change notification settings - Fork 1
/
READELF.PAS
129 lines (125 loc) · 3.76 KB
/
READELF.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2023
@website(https://www.gladir.com/linux-0)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program READELF;
{$A-}
Var
I:Integer;
FileELF:File;
ByteReaded:Word;
Header:Record
Sign:Array[0..3]of Char;
Format,MemCellFormat:Byte;
Version:Byte;
OSABI:Byte;
Inused1:Array[8..15]of Byte;
FileType:Word;
InstructionUsed:Word;
End;
ShowHeader:Boolean;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-H')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('READELF: Cette commande permet d''afficher des ',
'informations sur un ELF.');
WriteLn;
WriteLn('Syntaxe: READELF -h|--file-header programme[.ELF]');
WriteLn;
WriteLn('programme Ce paramŠtre permet d''indiquer le nom du programme.');
WriteLn('-h Ce paramŠtre permet d''indiquer qu''il faut ',
'afficher les informations d''entˆte.');
WriteLn('--file-header Ce paramŠtre permet d''indiquer qu''il faut ',
'afficher les informations d''entˆte.');
End
Else
If ParamCount>0Then Begin
ShowHeader:=False;
For I:=1 to ParamCount do Begin
If ParamStr(I)='-h'Then ShowHeader:=True;
If ParamStr(I)='--file-header'Then ShowHeader:=True;
End;
If(ShowHeader)Then Begin
For I:=1 to ParamCount do
If Not((ParamStr(I)='-h')or(ParamStr(I)='--file-header'))Then Begin
{$I+}Assign(FileELF,ParamStr(I));
Reset(FileELF,1);{$I-}
If IOResult<>0 Then Begin
WriteLn('Erreur de lecture du fichier ',ParamStr(I),' !');
Halt;
End;
Seek(FileELF,0);
BlockRead(FileELF,Header,SizeOf(Header),ByteReaded);
If ByteReaded=0 Then Begin
WriteLn('Erreur de lecture de l''entˆte ELF');
Halt;
End
Else
If(Header.Sign[0]=#$7F)and(Header.Sign[1]='E')and
(Header.Sign[2]='L')and(Header.Sign[3]='F')Then Begin
WriteLn('Entˆte ELF:');
WriteLn(' Type de fichier : ','ELF');
Write (' Format : ');
Case Header.Format of
1:WriteLn('32 bits');
2:WriteLn('64 bits');
Else WriteLn('Inconnu : ',Header.Format);
End;
Write (' Format des cellules: ');
Case Header.MemCellFormat of
1:WriteLn('Petite-Boutiste - Little Endian (LSB)');
2:WriteLn('Gros-Boutiste - Big Endian (MSB)');
Else WriteLn('Inconnu : ',Header.Format);
End;
WriteLn(' Version ELF : ',Header.Version);
Write (' Interface binaire (ABI) :');
Case Header.OSABI of
0:WriteLn('UNIX System V');
1:WriteLn('HP-UX');
2:WriteLn('NetBSD');
3:WriteLn('Linux');
6:WriteLn('Sun Solaris');
7:WriteLn('IBM AIX');
8:WriteLn('SGI Irix');
9:WriteLn('FreeBSD');
10:WriteLn('Compaq TRU64');
11:WriteLn('Novell Modesto');
12:WriteLn('OpenBSD');
64:WriteLn('ARM EABI');
97:WriteLn('ARM');
255:WriteLn('Standalone');
Else WriteLn('Inconnu')
End;
Write (' Type de fichier : ');
Case Header.FileType of
1:WriteLn('Repositionable');
2:WriteLn('Ex‚cutable');
3:WriteLn('Partag‚');
4:WriteLn('Coeur du systŠme d''exploitation');
Else WriteLn('Inconnu')
End;
Write (' Ensemble d''instructions :');
Case Header.InstructionUsed of
$00:WriteLn('Architecture non sp‚cifi‚.');
$02:WriteLn('Sparc');
$03:WriteLn('80x86');
$08:WriteLn('MIPS');
$14:WriteLn('PowerPC');
$28:WriteLn('ARM');
$2A:WriteLn('SuperH');
$32:WriteLn('IA-64');
$3E:WriteLn('x86-64');
$B7:WriteLn('AArch64');
Else WriteLn('Inconnu')
End;
End
Else
WriteLn('Signature ELF invalide');
Close(FileELF);
End;
End
Else
WriteLn('ParamŠtre attendue !');
End;
END.