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