修改symbian工程uid3的脚本

来源:互联网 发布:字符串转json对象 编辑:程序博客网 时间:2024/06/05 03:31
脚本很简单。
运行时需要在工程根目录下,可修改脚本,以适应不同的uid
源码如下:

  1. #!/usr/bin/perl -w
  2. use File::Find;
  3. use strict;
  4. my $iterType;# "findUid" "replace"
  5. my $oldUid;
  6. my $newUid;
  7. &main();
  8. sub main()
  9. {
  10.     &findUid;
  11.     if(! $oldUid)
  12.     {
  13.         die 'cannot find uid';
  14.     }
  15.     else
  16.     {
  17.         print "ori uid3=$oldUid/n";
  18.     }
  19.     $newUid="0x12345678";
  20.     &ReplaceUid;
  21. }
  22. sub findUid
  23. {
  24.     my $groupDir='./group';
  25.     $iterType="findUid";
  26.     find({'wanted'=>/&HandleFile,'no_chdir'=>1},$groupDir);
  27. }
  28. sub ReplaceUid
  29. {
  30.     $iterType="findAll";
  31.     find({'wanted'=>/&HandleFile,'no_chdir'=>1},".");
  32. }
  33. sub HandleFile
  34. {
  35.     my $fullName=$File::Find::name;
  36.     if (! -T $fullName)
  37.     {
  38.         return;
  39.     }
  40.     if ($iterType eq 'findUid')
  41.     {
  42.         &DoFindUid($fullName);  
  43.     }
  44.     elsif ($iterType eq 'replace')
  45.     {
  46.         &DoReplaceUid($fullName);
  47.     }
  48.     else
  49.     {
  50.     }
  51. }
  52. sub DoFindUid
  53. {
  54.     my ($file)=@_;
  55.     if($file =~ /.mmp/)
  56.     {
  57.         print "found $file/n";
  58.         open (MMPFILE,"<$file") or die "cannot open $file/n";
  59.         my @content=<MMPFILE>;
  60.         chomp @content;
  61.         foreach (@content)
  62.         {
  63.             # UID 0xxxxxx  0x12345678
  64.             if (//s*uid/s*(/w*)/s*(/w*)/i)
  65.             {
  66.                 $oldUid=$2;
  67.                 $oldUid =~ s/0x//i;
  68.                 return;
  69.             }
  70.         }
  71.         close MMPFILE;
  72.     }
  73. }
  74. sub DoReplaceUid
  75. {
  76.     my ($file)=@_;
  77.     open FILEIN,"<$file" or die "cannot read $file/n";
  78.     my @data=<FILEIN>;
  79.     close FILEIN;
  80.     my $line=0;
  81.     foreach (@data)
  82.     {
  83.         if (/$oldUid/i)
  84.         {
  85.             print "in $file,line=$line,$_";
  86.             s/$oldUid/$newUid/g;
  87.         }
  88.         ++$line;
  89.     }
  90.     open FILEOUT,">$file";
  91.     print FILEOUT @data;
  92.     close FILEOUT;
  93. }

原创粉丝点击