sbsv1/abld/platform/findimp.pl
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 599 fa7a3cc6effd
permissions -rw-r--r--
Specify extenal tool with path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
my $argc=scalar(@ARGV);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
$argc==2 or die "findimp <map file> <output file>\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
my $infile=@ARGV[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
my $outfile=@ARGV[1];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
my @imp_dll_names;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
my @imp_dll_ordinal_lists;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
my $i=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
open INFILE, $infile or die "Can't open input file $infile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
while (<INFILE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
	if (/^\s*(\d+)\:(([0-9|a-f|A-F])+)\s+__imp_(\S+)\s+(([0-9|a-f|A-F])+)\s+(\S+?)\:(.*?)\s*$/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
		my $section_num=$1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
		my $section_offset=hex $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
		my $import_name="__imp_$4";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
		my $addr=$5;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
		my $dllname=$8;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
		my $implist;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
		for ($i=0; $i<scalar(@imp_dll_names); ++$i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
			if ($imp_dll_names[$i] eq $dllname) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
				$implist=$imp_dll_ordinal_lists[$i];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
				push @$implist, $section_offset;				
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
				last;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
		if ($i==scalar(@imp_dll_names)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
			my @new_list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
			push @new_list, $section_offset;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
			push @imp_dll_names, $dllname;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
			push @imp_dll_ordinal_lists, \@new_list;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
close INFILE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
my $noffset=4;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
my $n_imp_dlls=scalar(@imp_dll_names);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
for ($i=0; $i<$n_imp_dlls; ++$i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
	$noffset+=8;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
	my $implist=$imp_dll_ordinal_lists[$i];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
	foreach (@$implist) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
		$noffset+=4;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
open OUTFILE, ">$outfile" or die "Can't open output file $outfile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
binmode OUTFILE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
printf OUTFILE "%c%c%c%c",$n_imp_dlls&0xff,($n_imp_dlls>>8)&0xff,($n_imp_dlls>>16)&0xff,$n_imp_dlls>>24;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
$i=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
for ($i=0; $i<$n_imp_dlls; ++$i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
	my $nlen=length $imp_dll_names[$i];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
	printf OUTFILE "%c%c%c%c",$noffset&0xff,($noffset>>8)&0xff,($noffset>>16)&0xff,$noffset>>24;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
	$noffset+=$nlen + 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
	my $implist=$imp_dll_ordinal_lists[$i];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
	my $nimp=scalar(@$implist);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
	printf OUTFILE "%c%c%c%c",$nimp&0xff,($nimp>>8)&0xff,($nimp>>16)&0xff,$nimp>>24;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
	foreach (@$implist) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
		printf OUTFILE "%c%c%c%c",$_&0xff,($_>>8)&0xff,($_>>16)&0xff,$_>>24;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
for ($i=0; $i<$n_imp_dlls; ++$i) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
	print OUTFILE $imp_dll_names[$i];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
	printf OUTFILE "%c",0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
close OUTFILE;