File: osegs.pl

package info (click to toggle)
openscenegraph 2.8.3-5
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 33,968 kB
  • ctags: 30,935
  • sloc: cpp: 287,169; ansic: 9,050; sh: 654; yacc: 548; objc: 374; makefile: 264; lex: 151; perl: 119
file content (51 lines) | stat: -rw-r--r-- 928 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

die "Usage: $0 file\n" unless @ARGV;
open(OTOOL, "otool -l $ARGV[0]|") || die "Can't run otool\n";

$cmd      = 0;
$name     = "";
$segstart = 0;
$segend   = 0;
$ostart   = 0xffffffff;
$oend     = 0;

while(<OTOOL>) {
	chop;
	if(/^Load *command /) {
		$cmd = 1;
		next;
	}
	next unless $cmd != 0;
	if(/^ *cmd  *(.*)/ && $cmd == 1) {
		if($1 eq "LC_SEGMENT") {
			$cmd = 2;
		} else {
			$cmd = 0;
		}
		next;
	}
	if(/^ *segname  *(.*)/ && $cmd == 2) {
		$name = $1;
		next;
	}
	if(/^ *vmaddr  *(.*)/ && $cmd == 2) {
		$segstart = hex $1;
		next;
	}
	if(/^ *vmsize  *(.*)/ && $cmd == 2) {
		$len    = hex $1;
		$segend = $segstart + $len;
		printf("Segment $name, %x - %x\n", $segstart, $segend);
		$ostart = $segstart if $segstart < $ostart;
		$oend = $segend if $segend > $oend;
		$cmd = 0;
	}
}

close OTOOL;
$len = $oend - $ostart;
printf("Image from %x to %x (length %x)\n", $ostart, $oend, $len);

exit 0