[自己]有關於OE的研究(續)

我知道總共有兩個地方
16進位的0A
變成0D0A

但是0A的地方很多啊
為什麼只有兩個地方出問題

我找不出規律…

把程式碼貼在後面…
=======================================

#!/usr/bin/perl -w
use strict;

my $DBX_PREFIX = "old_";
my $FOLDER_NAME_OFFSET = 9665; # 我不知道怎麼定constant!; 0x25c1 = 9665
my $MAX_DBX_FILESIZE = 2000000000; # Max size = 2G

my $buf;
my $len;
my $realname;
my $temp;
my $string_format;
my $file_remaining;
my $offset;

while (<*.dbx>) {
# 我們會修改二進位檔中, folder name的字串
# 但是檔名不會改
# print chr(65); #print A
# print ord(A); #print 65

# $_ 檔名,如 older.水友信件.dbx
# $realname 如 水友信件, 從檔名去頭去尾而來
# $buf, 從0x25c1讀來的,必須與$realname做比較
$realname = $_;
$realname =~ s/^$DBX_PREFIX//;
$realname =~ s/\.dbx$//;
$len = length $realname;
print "$len $realname\n";



open(FROM, "$_") or die("can't open file: $!");
open(TO, ">temp") or die("can't open file: $!");

read(FROM, $buf, $FOLDER_NAME_OFFSET);
print TO $buf;


read(FROM, $buf, $len);

# for debug.
$string_format = "%.".$len."s";
print "***";
print sprintf $string_format, $buf;
print "\n";
if( $buf eq $realname){
print "字串相同";
}else{
print "字串不同";
}
print "\n";
print "$DBX_PREFIX$realname\n";


print TO $DBX_PREFIX.$realname;

$len = length $DBX_PREFIX;
seek( FROM, $len, 1); # 將FROM 的檔案指標移到跟TO的檔案指標一樣的位置

print tell TO;
print "\n";
print tell FROM;
print "\n";

# 複製檔案剩餘的部分
my $readchr;
while( $readchr = read(FROM, $buf, 16384)){
print TO $buf;
print "# $readchr\n";

}

close TO;
close FROM;
unlink $_;
rename "temp", $_;

}

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: