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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2000 by Sun Microsystems, Inc.
# All rights reserved.
#
# ident "%Z%%M% %I% %E% SMI"
#
# check for perl5 -- we use things unavailable in perl4
#
$DBM_DIR_CHARACTERIZATION = "directory for the dbm databases";
$Usage =
"Usage: get_depend_info
-dbdir <$DBM_DIR_CHARACTERIZATION> [ -s ] [ -cons ] [ -root directory ]
[ -f ] [ -p ] [ -pkg SUNWxxx ] [ filename ]
[-h for help]\n";
$Help =
"This program statically analyzes executable files and their
can accept filename(s) or packages as the list of files to be
analyzed. By default, the program will report the file
dependencies and which packages those dependencies came from.
There is one required argument:
-dbdir <dir> the $DBM_DIR_CHARACTERIZATION
The optional argument -h produces this message instead of any processing.
The optional argument -cons tells the tool to be conservative and not to
The optional argument -root allows you to specify a new root (useful for
doing analysis on build trees).
The optional argument -pkg allows you to specify a package name.
The optional argument -f only outputs the filename of the dependencies
The optional argument -p only outputs the packanames of the dependencies
The optional argument -s ONLY outputs symbolic links for files or packages.
No ldd or strings analysis is done.
Some Examples:
get_depend_info -dbdir ./DBM -pkg SUNWnisu
get_depend_info -f -dbdir ./DBM -pkg SUNWnisu
get_depend_info -s -dbdir ./DBM -pkg SUNWnisu
NOTE: Run make_pkg_db to create the database directory for get_depend_info
";
#
# process arguments
#
@PkgList = "";
$PackageOnly = false;
$FileOnly = false;
$Verbose = true;
$Silent = false;
$SymLink = false;
$NoStrings = false;
$Root = "";
while (@ARGV) {
exit 0;
$SymLink = true;
$Silent = true;
$PackageOnly = true;
$Verbose = false;
$FileOnly = true;
$Verbose = false;
$NoStrings = true;
}else {
}
}
if (!$DBDir) {
exit 1;
}
if ($PKGName) {
# For a given pkg definition directory, this subroutine will
# go through the proto files and look for executable files.
# It will then put all the executable files into @filelist
$Silent = true;
}
}
&OpenDBs;
# make sure file exists
next;
}
next;
}
# destfile represents the actual file we are interested in!
}
}
else {
}
# if the -s flag is set, tell 'em about sym links and go to the next file
# Handle the case where the user resets $ROOT
# make sure we are dealing with an executable
if (($mode !~ /(.)(.*)7/) && ($mode !~ /(.)(.*)5/) && ($mode !~ /(.)(.*)3/) && ($mode !~ /(.)(.*)1/)){
print("Input file is not an executable\n");
next;
}
# Kernel modules are handled separately
next;
}
# take care of scripts
next;
}
# Its not a script, not a kernel module, so its get to be a binary
}
}
&CloseDBs;
#===========================END OF MAIN====================================
#
# use map file to see if this is a file that gives a known bad ldd return
#
# if ($Unsup{$FileID} == 1) {
# $outstring = "* unsupported or unknown file type, per map file";
# return ($outstring);
# }
# $err = "";
# if ($?) { # if some error (don't just get wait status here)
# $errnum = 0 + $!;
# $err = "==$?==$errnum==";
# if (($err eq "==256==29==") || ($err eq "==256==0==")) {
# $err = "*"; # these are normal ldd returns
# } else {
# die "Unexpected ldd return $? $!";
# }
# $string =~ s/\/usr\/bin\/ldd:[^\0]*://g; # trim up error line
# $err = "*";
# }
# on a non-zero ldd, return nothing
$line =~ s/^\s+//; # trim leading ws
}
}
sub CloseDBs {
# close the dbs
}
sub OpenDBs {
# open the databases for read-only
}
sub HandleKernelMod {
# search for the magic right, starting from the right (ie. end of path)
# rindex() returns where the "kernel" began, add 6 to get
# "{some path}/kernel"
$index += 6;
# OK, now pull out the absolute path
# There are two ways to figure out the dependencies.
$found = 0;
# first, check to see if there is a module relative to
# this file
$found++;
}
# Haven't found it yet, check /kernel
$found++;
}
$found++;
}
}
}
return;
}
# the ldd failed, so now let's look at the string output
}
}
$found = 0;
# first, check to see if there is a module relative to
# this file
$found++;
}
# Haven't found it yet, check /kernel
$found++;
}
$found++;
}
}
}
}
# use map file to see if this is a file that gives a known bad ldd return
}
}
}
}
}
}
sub HandleScripts {
s/^\s+//; # trim leading ws
s/=/ /g; # get rid of all =
s/\`/ /g; # get rid of all `
next if ($_ =~ /^#/); # strip out obvious comments
next unless $_; # skip if blank
$line = $_;
}
}
}
$count = 0;
# make sure we don't output dupes
}
}
$count++;
}
# remember to play nice
}
sub HandleBinaries {
# Parse the ldd output.
$found = 0;
$found++;
}
$found++;
}
}
}
# For the strings output, we parse it to see if we can match it to
# any files distributed in a package.
}
}
}
sub Output {
# If they want a package listing, a unique sorted list
# will be outputted later. Here we simply push elements onto
# this list.
}
return;
}
# If they want a package listing, a unique sorted list
# will be outputted later. Here we simply push elements onto
# this list.
return;
}
return;
}
}
sub HandlePackageName {
}
}
sub OutputPackageList {
# If the user specified a package list, here we sort
# the list and make sure we don't output dupes.
$pkg =~ s/\s*$//; # trim extra space off the end
# make sure this entry isn't a dupe before
# printing it
}
}
# reset the list for the next entry
}