A guide that contains all general tricks and rules that apply to all
classes.
This section is a shortened version of Christoper Nahr's HOMM3 Manual Addendum, rewritten and published with author's permission. The originalis recommended for most players as required reading...
General rules on building are these:
A Town Hall built on day one will result in extra 1000 gold on first day of next week (and then extra 3500 every first day of week). The build schedules shown in other articles build it, but there may be cases where you could build some highlevel dwelling at the cost of not building the Town Hall. So, before you build your first structure, try to guess whether you will be able (gold and resource-wise) to go for some high-end dwelling that quickly, and alter the building schedule accordingly. Always try to build most of dwellings before day one of next week. All miscellaneous buildings like Mage Guild, MarketPlace or Blacksmith can wait. The second week should be usually aimed at building money generators including Capitol, if possible. Ideal case: You start with two towns. One goes for the creatures and Citadel/Castle, the other goes for money in the first week. In the second week, the first town goes for capitol, while the second stays idle. Further on, all the cash that is left after troops are purchased should go to upgrades and also lower level dwellings in the second town. If you really don't know what to do with cash, build other structures. Short notes on all common structures: Get used to computer heroes attacking every now and then your castles. There are three main ways to chose: |
十一月二十五日等待变化等待机会
这个是一个很小的问题,公司又要断电关机,我就需要把我的服务器虚拟机都关机,但是一个简单的循环总是不能正常工作:
cat serverList.txt | while read line; do /usr/bin/ssh -X -i /Users/nihuang/.ssh/id_rsa -o ConnectTimeout=3 -o BatchMode=yes root@${line} "nohup id >&- 2>&- <&- &" | echo $? ; done
后来稍微修改了一个循环方式就可以了,不知道为什么?nihuang@C02Y714BJGH5:~$ for host in $(cat serverList.txt); do /usr/bin/ssh -X -i /Users/nihuang/.ssh/id_rsa -o ConnectTimeout=3 -o BatchMode=yes root@${host} "nohup ip addr | grep ${host} &" ; done
inet 172.25.11.112/24 brd 172.25.11.255 scope global bond0
inet 172.25.11.114/24 brd 172.25.11.255 scope global noprefixroute enp59s0f0
inet 172.25.239.101/24 brd 172.25.239.255 scope global ens160
inet 172.25.239.128/24 brd 172.25.239.255 scope global eth0
inet 172.25.57.119/24 brd 172.25.57.255 scope global eth0
inet 172.25.57.75/24 brd 172.25.57.255 scope global eth0
inet 172.25.59.243/24 brd 172.25.59.255 scope global noprefixroute ens160
inet 172.25.59.244/24 brd 172.25.59.255 scope global ens160
inet 172.25.58.110/24 brd 172.25.58.255 scope global eth0
nihuang@C02Y714BJGH5:~$
nihuang@C02Y714BJGH5:~$ for host in $(cat serverList.txt); do /usr/bin/ssh -X -i /Users/nihuang/.ssh/id_rsa -o ConnectTimeout=3 -o BatchMode=yes root@${host} "nohup poweroff &" ; done
ssh: connect to host 172.25.11.112 port 22: Operation timed out
ssh: connect to host 172.25.11.114 port 22: Operation timed out
ssh: connect to host 172.25.239.101 port 22: Operation timed out
ssh: connect to host 172.25.57.75 port 22: Operation timed out
ssh: connect to host 172.25.59.243 port 22: Operation timed out
ssh: connect to host 172.25.59.244 port 22: Operation timed out
nihuang@C02Y714BJGH5:~$
另一件是我再次证明了regex里的lazy和选择什么matching flag无关,这一点我还是不很理解,因为似乎哪里看到了Posix和perl还是什么的match是最长的,我的理解就是和lazy是一样的。
By default, search will try to get longest match. i.e. the result is "abc"x"
string str="\"abc\"x\"";
regex ex("\".+\"");
cmatch what;
if (regex_search(str.c_str(), what, ex))
{
cout >> what[0] >> endl;
}
If lazy, the result is "abc"
string str="\"abc\"x\"";
regex ex("\".+?\"");
cmatch what;
if (regex_search(str.c_str(), what, ex))
{
cout >> what[0] >> endl;
}
我在论文的一个链接看到这个帖子果断决定收藏。
Heroes' Stats and Skills Chances
Here are the chances for different hero classes to gain a point in a certain primary skill on level up:
Hero Class__ Level_ Attack____ Defense___ Spell Power Knowledge
--------------------------------------------------------
Alchemist___ 2-9____30%________30%________20%________20%
Alchemist___ 10+____30%________30%________20%________20%
Barbarian___ 2-9____55%________35%________5%_________5%
Barbarian___ 10+____30%________30%________20%________20%
Battle Mage_ 2-9____30%________20%________25%________25%
Battle Mage_ 10+____25%________25%________25%________25%
Beastmaster_ 2-9____30%________60%________5%_________5%
Beastmaster_ 10+____30%________30%________20%________20%
Cleric______ 2-9____20%________15%________30%________35%
Cleric______ 10+____20%________20%________30%________30%
Death Knight 2-9____30%________25%________20%________25%
Death Knight 10+____25%________25%________25%________25%
Demoniac____ 2-9____30%________30%________20%________20%
Demoniac____ 10+____20%________20%________30%________30%
Druid_______ 2-9____10%________20%________35%________35%
Druid_______ 10+____20%________20%________30%________30%
Elementalist 2-9____10%________10%________50%________30%
Elementalist 10+____20%________20%________30%________30%
Heretic_____ 2-9____20%________10%________35%________35%
Heretic_____ 10+____25%________25%________25%________25%
Knight______ 2-9____40%________40%________10%________10%
Knight______ 10+____30%________30%________20%________20%
Necromancer_ 2-9____15%________15%________35%________35%
Necromancer_ 10+____25%________25%________25%________25%
Overlord____ 2-9____40%________35%________15%________10%
Overlord____ 10+____30%________30%________20%________20%
Planeswalker 2-9____50%________30%________10%________10%
Planeswalker 10+____30%________30%________20%________20%
Ranger______ 2-9____35%________45%________10%________10%
Ranger______ 10+____30%________30%________20%________20%
Warlock_____ 2-9____10%________10%________50%________30%
Warlock_____ 10+____20%________20%________30%________30%
Witch_______ 2-9____5%_________15%________40%________40%
Witch_______ 10+____20%________20%________30%________30%
Wizard______ 2-9____10%________10%________40%________40%
Wizard______ 10+____30%________30%________20%________20%
Here are the chances for different hero classes to have a certain secondary skill offered on level up:
Skill_______ Cleric__ Warlock_ Witch___ Heretic_ Necro___ Druid___ B. Mage_ Wizard___Elementalist
Air Magic___ 4________2________2________3________3________2________3________6________6
Archery_____ 3________2________3________4________2________5________4________2________2
Armorer_____ 3________1________4________4________2________3________4________1________1
Artillery___ 2________1________1________4________3________1________4________1________1
Ballistics__ 4________6________8________6________5________4________6________4________4
Diplomacy___ 7________4________2________3________4________4________3________4________4
Eagle Eye___ 6________8________10_______4________7________7________5________8________8
Earth Magic_ 3________5________3________4________8________4________3________3________6
Estates_____ 3________5________1________2________3________3________1________5________3
Fire Magic__ 2________3________3________5________2________1________3________2________6
First Aid___ 10_______6________8________5________0________7________4________7________4
Intelligence 6________8________7________6________6________7________5________10_______8
Leadership__ 2________3________1________2________0________2________4________4________3
Learning____ 4________4________4________4________4________4________4________4________4
Logistics___ 4________2________3________3________4________5________9________2________2
Luck________ 5________2________4________2________1________9________2________4________2
Mysticism___ 4________8________8________10_______6________6________4________8________8
Navigation__ 5________4________6________2________5________2________0________1________4
Necromancy__ 0________0________0________0________10_______0________0________0________0
Offense_____ 4________1________2________4________3________1________8________1________1
Pathfinding_ 2________2________2________4________6________5________4________2________2
Resistance__ 2________0________0________3________1________1________4________0________0
Scholar_____ 6________8________7________5________6________8________4________9________8
Scouting____ 3________2________2________3________2________2________4________2________2
Sorcery_____ 5________10_______8________6________6________6________6________8________8
Tactics_____ 2________1________1________4________2________1________5________1________1
Water Magic_ 4________2________3________2________3________4________3________3________6
Wisdom______ 7________10_______8________8________8________8________6________10_______8
Skill_______ Knight__ Overlord Beast___ Demon___ Death __ Ranger__ Barbarian Alchem. Planeswalker
Air Magic___ 3________1________1________2________2________1________3________4________2
Archery_____ 5________6________7________6________5________8________7________5________8
Armorer_____ 5________6________10_______7________5________8________6________8________5
Artillery___ 5________8________8________5________5________6________8________4________8
Ballistics__ 8________7________7________7________7________4________8________6________8
Diplomacy___ 4________3________1________4________2________4________1________3________2
Eagle Eye___ 2________2________1________3________4________2________2________3________2
Earth Magic_ 2________3________3________3________4________3________3________3________3
Estates_____ 6________4________1________3________0________2________2________4________3
Fire Magic__ 1________2________0________4________1________0________2________1________3
First Aid___ 2________1________6________2________0________3________1________2________1
Intelligence 1________1________1________2________5________2________1________4________1
Leadership__ 10_______8________5________3________0________6________5________3________3
Learning____ 4________4________4________4________4________4________4________10_______8
Logistics___ 5________8________8________10_______5________5________7________6________8
Luck________ 3________1________2________2________1________6________3________2________2
Mysticism___ 2________3________2________2________4________3________3________4________3
Navigation__ 8________4________8________4________8________3________2________3________5
Necromancy__ 0________0________0________0________10_______0________0________0________0
Offense_____ 7________8________5________8________7________5________10_______6________9
Pathfinding_ 4________5________8________4________4________7________8________4________6
Resistance__ 5________6________5________6________5________9________6________5________2
Scholar_____ 1________1________1________2________2________1________1________3________1
Scouting____ 4________5________7________5________4________7________8________4________6
Sorcery_____ 1________2________1________3________4________2________1________3________1
Tactics_____ 7________10_______6________6________5________5________8________4________8
Water Magic_ 4________0________2________1________3________3________0________2________2
Wisdom______ 3________3________2________4________6________3________2________6________2
Now... how does this thing work? Well, every time you level up the computer offers you to choose between a skill you already have and a new skill (or 2 new skills). The chance to get an existing skill is approximately (existing skill value)/(total of values of non-expert existing skills). The chance to get the new skill can be approximated by this formula: (value from the skill table)/(112 - total of values of the skills you already have).
for example, Ivor starts with archery and offense. The values for those skills add up to 13. The value of log skill for Ivor is 5.
So, the chance of Ivor getting logistics when he reaches level 2 is:
5/(112-13)=5.05%
*Note: Magic school skills and wisdom have some exceptions for might heroes. There may also be exceptions for the other skills.
If a might hero hasn't been offered a magic school yet, he will be offered one at level 4. If he turns it down a magic school will be offered again at level 8, if he keeps turning it down, he will also have one offered at levels 12, 16 and 20 (i.e. every 4-th level). If he gets offered a magic school on one of the other levels (see the chances in the random table above), the counter will be reset. Say, he is offered magic school at level 3. If he keeps turning it down and the counter doesn't get reset again, he will be offered it again on levels 7, 11, 15 and 19. The wisdom gets offered in a similar way. If you keep declining it and if the counter doesn't get reset, it will be offered on levels 6, 12 and 18.
Say, you want to know the chance of a certain hero getting earth magic before level 5. Instead of looking at earth magic skill values from the table, you need to look at the ratio of earth/total magic school values to get the chance of getting earth before level 5.
Using this info, here are the % chances to get earth for different might hero classes before they reach level 5:
Knights: 2/10 = 20%
Overlords: 3/6 = 50%
Beastmasters: 3/6 = 50%
Demoniacs: 3/10 = 30%
Death Knights: 4/10 = 40%
Rangers: 3/7 = 43%
Barbarians: 3/8 = 37.5%
Alchemists: 3/10 = 30%
Planeswalkers: 3/10 = 30%
Edit: edited some points based on posts by maretti and Binabik - thanks for your feedback, guys.
Edit by angelito
这里是我找到的类似的数据。
When a hero advances a level by means of battling or picking up a treasure chest, you are given the choice of two secondary skill advancements. Believe it or not, you will be offered skill choices (not only new ones, but to advance and expertise in a skill) 112 times before you cannot learn skills any further! These tables indicate how many times a given skill will be offered to that hero type, out of the 112 times.
MAGIC HERO SECONDARY SKILL ADVANCEMENT
SKILL NAME | CLER | WARL | WITC | HERE | NECR | DRUI | BATT | WIZA |
---|---|---|---|---|---|---|---|---|
Air Magic | 4 | 2 | 2 | 3 | 3 | 2 | 4 | 5 |
Archery | 3 | 2 | 3 | 4 | 2 | 5 | 4 | 2 |
Armorer | 3 | 1 | 4 | 4 | 2 | 3 | 4 | 1 |
Artillery | 2 | 1 | 2 | 4 | 3 | 1 | 4 | 1 |
Ballistics | 4 | 6 | 4 | 6 | 5 | 4 | 6 | 4 |
Diplomacy | 7 | 4 | 2 | 3 | 4 | 4 | 3 | 4 |
Eagle Eye | 6 | 8 | 10 | 4 | 7 | 7 | 5 | 8 |
Earth Magic | 3 | 4 | 4 | 4 | 5 | 4 | 3 | 4 |
Estates | 3 | 5 | 1 | 1 | 3 | 3 | 1 | 5 |
Fire Magic | 2 | 3 | 1 | 5 | 2 | 1 | 2 | 2 |
First Aid | 10 | 3 | 1 | 5 | 0 | 7 | 4 | 7 |
Intelligence | 6 | 8 | 7 | 6 | 7 | 7 | 5 | 10 |
Leadership | 2 | 3 | 1 | 1 | 0 | 2 | 4 | 4 |
Learning | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 |
Logistics | 4 | 2 | 3 | 3 | 4 | 5 | 10 | 2 |
Luck | 5 | 2 | 4 | 2 | 1 | 10 | 2 | 4 |
Mysticism | 4 | 8 | 8 | 10 | 6 | 6 | 4 | 8 |
Navigation | 5 | 4 | 6 | 2 | 5 | 2 | 0 | 1 |
Necromancy | 0 | 4 | 4 | 4 | 10 | 0 | 2 | 0 |
Offense | 4 | 1 | 2 | 4 | 3 | 1 | 7 | 1 |
Pathfinding | 2 | 2 | 2 | 3 | 6 | 5 | 4 | 2 |
Resistance | 2 | 0 | 0 | 3 | 1 | 1 | 4 | 0 |
Scholar | 6 | 8 | 7 | 5 | 6 | 8 | 4 | 9 |
Scouting | 3 | 2 | 2 | 3 | 2 | 2 | 4 | 2 |
Sorcery | 5 | 10 | 8 | 6 | 7 | 6 | 6 | 8 |
Tactics | 2 | 1 | 2 | 4 | 2 | 1 | 5 | 1 |
Water Magic | 4 | 1 | 3 | 2 | 4 | 3 | 1 | 3 |
Wisdom | 7 | 10 | 8 | 7 | 8 | 8 | 6 | 10 |
Total | 112 | 112 | 112 | 112 | 112 | 112 | 112 | 112 |
As you can see we have some restrictions on skills for many heroes. Let's summarize this:
Battle Mage - Restriction on Navigation.We can see that Necromancy is not a favorite among the ranks of magic heroes nor is resistance. Also notice that the Heretic hero class has absolutely no restrictions on any skill.
Cleric - Cannot learn Necromancy.
Necromancer - Cannot learn First Aid or Leadership.
Druid - Cannot learn Necromancy.
Witch - Restricted from Learning Resistance.
Warlock - Also cannot learn Resistance.
Wizard - Cannot learn Necromancy or Resistance.
MIGHT HERO SECONDARY SKILL ADVANCEMENT
SKILL NAME | KNIG | OVER | BEAS | DEMO | DEAT | RANG | BARB | ALCH |
---|---|---|---|---|---|---|---|---|
Air Magic | 3 | 1 | 1 | 2 | 2 | 1 | 3 | 4 |
Archery | 5 | 6 | 7 | 6 | 5 | 8 | 7 | 5 |
Armorer | 5 | 6 | 10 | 7 | 5 | 8 | 6 | 6 |
Artillery | 5 | 8 | 8 | 5 | 5 | 6 | 8 | 4 |
Ballistics | 8 | 7 | 6 | 6 | 7 | 4 | 8 | 6 |
Diplomacy | 4 | 3 | 1 | 4 | 2 | 4 | 1 | 3 |
Eagle Eye | 2 | 1 | 1 | 2 | 4 | 2 | 2 | 3 |
Earth Magic | 2 | 3 | 3 | 3 | 4 | 3 | 3 | 3 |
Estates | 6 | 4 | 1 | 3 | 0 | 2 | 2 | 4 |
Fire Magic | 1 | 2 | 0 | 4 | 1 | 0 | 2 | 1 |
First Aid | 2 | 1 | 6 | 1 | 0 | 3 | 1 | 2 |
Intelligence | 1 | 1 | 1 | 2 | 5 | 2 | 1 | 4 |
Leadership | 10 | 8 | 5 | 3 | 0 | 6 | 5 | 3 |
Learning | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 10 |
Logistics | 5 | 8 | 8 | 10 | 5 | 5 | 7 | 6 |
Luck | 3 | 1 | 2 | 2 | 1 | 6 | 3 | 1 |
Mysticism | 2 | 3 | 2 | 3 | 4 | 3 | 3 | 4 |
Navigation | 8 | 4 | 8 | 3 | 8 | 3 | 2 | 3 |
Necromancy | 0 | 1 | 1 | 0 | 10 | 0 | 1 | 4 |
Offense | 7 | 8 | 5 | 5 | 7 | 5 | 10 | 6 |
Pathfinding | 4 | 5 | 8 | 4 | 4 | 7 | 8 | 4 |
Resistance | 5 | 6 | 5 | 6 | 5 | 10 | 6 | 5 |
Scholar | 1 | 1 | 1 | 2 | 2 | 1 | 1 | 3 |
Scouting | 4 | 5 | 7 | 5 | 4 | 7 | 8 | 4 |
Sorcery | 1 | 2 | 1 | 3 | 4 | 2 | 1 | 3 |
Tactics | 7 | 10 | 6 | 6 | 5 | 5 | 7 | 4 |
Water Magic | 4 | 0 | 2 | 1 | 3 | 2 | 0 | 2 |
Wisdom | 3 | 3 | 2 | 4 | 6 | 3 | 2 | 5 |
Total | 112 | 112 | 112 | 112 | 112 | 112 | 112 | 112 |
Hero classes |
---|
Castle |
Knight |
Cleric |
Rampart |
Ranger |
Druid |
Tower |
Alchemist |
Wizard |
Inferno |
Demoniac |
Heretic |
Necropolis |
Death Knight |
Necromancer |
Dungeon |
Overlord |
Warlock |
Stronghold |
Barbarian |
Battle Mage |
Fortress |
Beastmaster |
Witch |
Conflux |
Planeswalker |
Elementalist |
十一月二十六日等待变化等待机会
关于micro-httpd的配置本来是一个很正常的问题,不知道为什么我办公室的电脑不正常。
service micro-httpd
{
disable = no
flags = REUSE
id = micro-httpd
type = UNLISTED
socket_type = stream
protocol = tcp
user = nick
wait = no
server = /usr/sbin/micro-httpd
server_args = /BigDisk/diabloforum/public_html/
port = 8080
}
十一月二十八日等待变化等待机会
昨天最后发现我配置microhttpd的方法并没有什么问题,而也许是公司防火墙的问题,同样类似的问题都出现在某些旧系统的webservice不能穿越防火墙的问题,也许吧。实际上这一切都来源于我的microhttpd不能正确的传送pdf等文件,我一开始以为是firefox的pdf插件的问题,很快就明白这个是microhttpd的mime设定问题,查看源代码可不是吗?号称一百行代码的webservice当然没有给你一个完全的mime list了。那么我自己添加这些mime如何呢?我做了一个列表:
struct MimeExt { std::string strExt; std::string strMime;};
struct MimeExt mimeExt[]={
{".3dm","x-world/x-3dmf"},
{".3dmf","x-world/x-3dmf"},
{".a","application/octet-stream"},
{".aab","application/x-authorware-bin"},
{".aam","application/x-authorware-map"},
{".aas","application/x-authorware-seg"},
{".abc","text/vnd.abc"},
{".acgi","text/html"},
{".afl","video/animaflex"},
{".ai","application/postscript"},
{".aif","audio/aiff"},
{".aif","audio/x-aiff"},
{".aifc","audio/aiff"},
{".aifc","audio/x-aiff"},
{".aiff","audio/aiff"},
{".aiff","audio/x-aiff"},
{".aim","application/x-aim"},
{".aip","text/x-audiosoft-intra"},
{".ani","application/x-navi-animation"},
{".aos","application/x-nokia-9000-communicator-add-on-software"},
{".aps","application/mime"},
{".arc","application/octet-stream"},
{".arj","application/arj"},
{".arj","application/octet-stream"},
{".art","image/x-jg"},
{".asf","video/x-ms-asf"},
{".asm","text/x-asm"},
{".asp","text/asp"},
{".asx","application/x-mplayer2"},
{".asx","video/x-ms-asf"},
{".asx","video/x-ms-asf-plugin"},
{".au","audio/basic"},
{".au","audio/x-au"},
{".avi","application/x-troff-msvideo"},
{".avi","video/avi"},
{".avi","video/msvideo"},
{".avi","video/x-msvideo"},
{".avs","video/avs-video"},
{".bcpio","application/x-bcpio"},
{".bin","application/mac-binary"},
{".bin","application/macbinary"},
{".bin","application/octet-stream"},
{".bin","application/x-binary"},
{".bin","application/x-macbinary"},
{".bm","image/bmp"},
{".bmp","image/bmp"},
{".bmp","image/x-windows-bmp"},
{".boo","application/book"},
{".book","application/book"},
{".boz","application/x-bzip2"},
{".bsh","application/x-bsh"},
{".bz","application/x-bzip"},
{".bz2","application/x-bzip2"},
{".c","text/plain"},
{".c","text/x-c"},
{".c++","text/plain"},
{".cat","application/vnd.ms-pki.seccat"},
{".cc","text/plain"},
{".cc","text/x-c"},
{".ccad","application/clariscad"},
{".cco","application/x-cocoa"},
{".cdf","application/cdf"},
{".cdf","application/x-cdf"},
{".cdf","application/x-netcdf"},
{".cer","application/pkix-cert"},
{".cer","application/x-x509-ca-cert"},
{".cha","application/x-chat"},
{".chat","application/x-chat"},
{".class","application/java"},
{".class","application/java-byte-code"},
{".class","application/x-java-class"},
{".com","application/octet-stream"},
{".com","text/plain"},
{".conf","text/plain"},
{".cpio","application/x-cpio"},
{".cpp","text/x-c"},
{".cpt","application/mac-compactpro"},
{".cpt","application/x-compactpro"},
{".cpt","application/x-cpt"},
{".crl","application/pkcs-crl"},
{".crl","application/pkix-crl"},
{".crt","application/pkix-cert"},
{".crt","application/x-x509-ca-cert"},
{".crt","application/x-x509-user-cert"},
{".csh","application/x-csh"},
{".csh","text/x-script.csh"},
{".css","application/x-pointplus"},
{".css","text/css"},
{".cxx","text/plain"},
{".dcr","application/x-director"},
{".deepv","application/x-deepv"},
{".def","text/plain"},
{".der","application/x-x509-ca-cert"},
{".dif","video/x-dv"},
{".dir","application/x-director"},
{".dl","video/dl"},
{".dl","video/x-dl"},
{".doc","application/msword"},
{".dot","application/msword"},
{".dp","application/commonground"},
{".drw","application/drafting"},
{".dump","application/octet-stream"},
{".dv","video/x-dv"},
{".dvi","application/x-dvi"},
{".dwf","drawing/x-dwf"},
{".dwf","model/vnd.dwf"},
{".dwg","application/acad"},
{".dwg","image/vnd.dwg"},
{".dwg","image/x-dwg"},
{".dxf","application/dxf"},
{".dxf","image/vnd.dwg"},
{".dxf","image/x-dwg"},
{".dxr","application/x-director"},
{".el","text/x-script.elisp"},
{".elc","application/x-bytecode.elisp"},
{".elc","application/x-elc"},
{".env","application/x-envoy"},
{".eps","application/postscript"},
{".es","application/x-esrehber"},
{".etx","text/x-setext"},
{".evy","application/envoy"},
{".evy","application/x-envoy"},
{".exe","application/octet-stream"},
{".f","text/plain"},
{".f","text/x-fortran"},
{".f77","text/x-fortran"},
{".f90","text/plain"},
{".f90","text/x-fortran"},
{".fdf","application/vnd.fdf"},
{".fif","application/fractals"},
{".fif","image/fif"},
{".fli","video/fli"},
{".fli","video/x-fli"},
{".flo","image/florian"},
{".flx","text/vnd.fmi.flexstor"},
{".fmf","video/x-atomic3d-feature"},
{".for","text/plain"},
{".for","text/x-fortran"},
{".fpx","image/vnd.fpx"},
{".fpx","image/vnd.net-fpx"},
{".frl","application/freeloader"},
{".funk","audio/make"},
{".g","text/plain"},
{".g3","image/g3fax"},
{".gif","image/gif"},
{".gl","video/gl"},
{".gl","video/x-gl"},
{".gsd","audio/x-gsm"},
{".gsm","audio/x-gsm"},
{".gsp","application/x-gsp"},
{".gss","application/x-gss"},
{".gtar","application/x-gtar"},
{".gz","application/x-compressed"},
{".gz","application/x-gzip"},
{".gzip","application/x-gzip"},
{".gzip","multipart/x-gzip"},
{".h","text/plain"},
{".h","text/x-h"},
{".hdf","application/x-hdf"},
{".help","application/x-helpfile"},
{".hgl","application/vnd.hp-hpgl"},
{".hh","text/plain"},
{".hh","text/x-h"},
{".hlb","text/x-script"},
{".hlp","application/hlp"},
{".hlp","application/x-helpfile"},
{".hlp","application/x-winhelp"},
{".hpg","application/vnd.hp-hpgl"},
{".hpgl","application/vnd.hp-hpgl"},
{".hqx","application/binhex"},
{".hqx","application/binhex4"},
{".hqx","application/mac-binhex"},
{".hqx","application/mac-binhex40"},
{".hqx","application/x-binhex40"},
{".hqx","application/x-mac-binhex40"},
{".hta","application/hta"},
{".htc","text/x-component"},
{".htm","text/html"},
{".html","text/html"},
{".htmls","text/html"},
{".htt","text/webviewhtml"},
{".htx","text/html"},
{".ice","x-conference/x-cooltalk"},
{".ico","image/x-icon"},
{".idc","text/plain"},
{".ief","image/ief"},
{".iefs","image/ief"},
{".iges","application/iges"},
{".iges","model/iges"},
{".igs","application/iges"},
{".igs","model/iges"},
{".ima","application/x-ima"},
{".imap","application/x-httpd-imap"},
{".inf","application/inf"},
{".ins","application/x-internett-signup"},
{".ip","application/x-ip2"},
{".isu","video/x-isvideo"},
{".it","audio/it"},
{".iv","application/x-inventor"},
{".ivr","i-world/i-vrml"},
{".ivy","application/x-livescreen"},
{".jam","audio/x-jam"},
{".jav","text/plain"},
{".jav","text/x-java-source"},
{".java","text/plain"},
{".java","text/x-java-source"},
{".jcm","application/x-java-commerce"},
{".jfif","image/jpeg"},
{".jfif","image/pjpeg"},
{".jfif-tbnl","image/jpeg"},
{".jpe","image/jpeg"},
{".jpe","image/pjpeg"},
{".jpeg","image/jpeg"},
{".jpeg","image/pjpeg"},
{".jpg","image/jpeg"},
{".jpg","image/pjpeg"},
{".jps","image/x-jps"},
{".js","application/x-javascript"},
{".js","application/javascript"},
{".js","application/ecmascript"},
{".js","text/javascript"},
{".js","text/ecmascript"},
{".jut","image/jutvision"},
{".kar","audio/midi"},
{".kar","music/x-karaoke"},
{".ksh","application/x-ksh"},
{".ksh","text/x-script.ksh"},
{".la","audio/nspaudio"},
{".la","audio/x-nspaudio"},
{".lam","audio/x-liveaudio"},
{".latex","application/x-latex"},
{".lha","application/lha"},
{".lha","application/octet-stream"},
{".lha","application/x-lha"},
{".lhx","application/octet-stream"},
{".list","text/plain"},
{".lma","audio/nspaudio"},
{".lma","audio/x-nspaudio"},
{".log","text/plain"},
{".lsp","application/x-lisp"},
{".lsp","text/x-script.lisp"},
{".lst","text/plain"},
{".lsx","text/x-la-asf"},
{".ltx","application/x-latex"},
{".lzh","application/octet-stream"},
{".lzh","application/x-lzh"},
{".lzx","application/lzx"},
{".lzx","application/octet-stream"},
{".lzx","application/x-lzx"},
{".m","text/plain"},
{".m","text/x-m"},
{".m1v","video/mpeg"},
{".m2a","audio/mpeg"},
{".m2v","video/mpeg"},
{".m3u","audio/x-mpequrl"},
{".man","application/x-troff-man"},
{".map","application/x-navimap"},
{".mar","text/plain"},
{".mbd","application/mbedlet"},
{".mc$","application/x-magic-cap-package-1.0"},
{".mcd","application/mcad"},
{".mcd","application/x-mathcad"},
{".mcf","image/vasa"},
{".mcf","text/mcf"},
{".mcp","application/netmc"},
{".me","application/x-troff-me"},
{".mht","message/rfc822"},
{".mhtml","message/rfc822"},
{".mid","application/x-midi"},
{".mid","audio/midi"},
{".mid","audio/x-mid"},
{".mid","audio/x-midi"},
{".mid","music/crescendo"},
{".mid","x-music/x-midi"},
{".midi","application/x-midi"},
{".midi","audio/midi"},
{".midi","audio/x-mid"},
{".midi","audio/x-midi"},
{".midi","music/crescendo"},
{".midi","x-music/x-midi"},
{".mif","application/x-frame"},
{".mif","application/x-mif"},
{".mime","message/rfc822"},
{".mime","www/mime"},
{".mjf","audio/x-vnd.audioexplosion.mjuicemediafile"},
{".mjpg","video/x-motion-jpeg"},
{".mm","application/base64"},
{".mm","application/x-meme"},
{".mme","application/base64"},
{".mod","audio/mod"},
{".mod","audio/x-mod"},
{".moov","video/quicktime"},
{".mov","video/quicktime"},
{".movie","video/x-sgi-movie"},
{".mp2","audio/mpeg"},
{".mp2","audio/x-mpeg"},
{".mp2","video/mpeg"},
{".mp2","video/x-mpeg"},
{".mp2","video/x-mpeq2a"},
{".mp3","audio/mpeg3"},
{".mp3","audio/x-mpeg-3"},
{".mp3","video/mpeg"},
{".mp3","video/x-mpeg"},
{".mpa","audio/mpeg"},
{".mpa","video/mpeg"},
{".mpc","application/x-project"},
{".mpe","video/mpeg"},
{".mpeg","video/mpeg"},
{".mpg","audio/mpeg"},
{".mpg","video/mpeg"},
{".mpga","audio/mpeg"},
{".mpp","application/vnd.ms-project"},
{".mpt","application/x-project"},
{".mpv","application/x-project"},
{".mpx","application/x-project"},
{".mrc","application/marc"},
{".ms","application/x-troff-ms"},
{".mv","video/x-sgi-movie"},
{".my","audio/make"},
{".mzz","application/x-vnd.audioexplosion.mzz"},
{".nap","image/naplps"},
{".naplps","image/naplps"},
{".nc","application/x-netcdf"},
{".ncm","application/vnd.nokia.configuration-message"},
{".nif","image/x-niff"},
{".niff","image/x-niff"},
{".nix","application/x-mix-transfer"},
{".nsc","application/x-conference"},
{".nvd","application/x-navidoc"},
{".o","application/octet-stream"},
{".oda","application/oda"},
{".omc","application/x-omc"},
{".omcd","application/x-omcdatamaker"},
{".omcr","application/x-omcregerator"},
{".p","text/x-pascal"},
{".p10","application/pkcs10"},
{".p10","application/x-pkcs10"},
{".p12","application/pkcs-12"},
{".p12","application/x-pkcs12"},
{".p7a","application/x-pkcs7-signature"},
{".p7c","application/pkcs7-mime"},
{".p7c","application/x-pkcs7-mime"},
{".p7m","application/pkcs7-mime"},
{".p7m","application/x-pkcs7-mime"},
{".p7r","application/x-pkcs7-certreqresp"},
{".p7s","application/pkcs7-signature"},
{".part","application/pro_eng"},
{".pas","text/pascal"},
{".pbm","image/x-portable-bitmap"},
{".pcl","application/vnd.hp-pcl"},
{".pcl","application/x-pcl"},
{".pct","image/x-pict"},
{".pcx","image/x-pcx"},
{".pdb","chemical/x-pdb"},
{".pdf","application/pdf"},
{".pfunk","audio/make"},
{".pfunk","audio/make.my.funk"},
{".pgm","image/x-portable-graymap"},
{".pgm","image/x-portable-greymap"},
{".pic","image/pict"},
{".pict","image/pict"},
{".pkg","application/x-newton-compatible-pkg"},
{".pko","application/vnd.ms-pki.pko"},
{".pl","text/plain"},
{".pl","text/x-script.perl"},
{".plx","application/x-pixclscript"},
{".pm","image/x-xpixmap"},
{".pm","text/x-script.perl-module"},
{".pm4","application/x-pagemaker"},
{".pm5","application/x-pagemaker"},
{".png","image/png"},
{".pnm","application/x-portable-anymap"},
{".pnm","image/x-portable-anymap"},
{".pot","application/mspowerpoint"},
{".pot","application/vnd.ms-powerpoint"},
{".pov","model/x-pov"},
{".ppa","application/vnd.ms-powerpoint"},
{".ppm","image/x-portable-pixmap"},
{".pps","application/mspowerpoint"},
{".pps","application/vnd.ms-powerpoint"},
{".ppt","application/mspowerpoint"},
{".ppt","application/powerpoint"},
{".ppt","application/vnd.ms-powerpoint"},
{".ppt","application/x-mspowerpoint"},
{".ppz","application/mspowerpoint"},
{".pre","application/x-freelance"},
{".prt","application/pro_eng"},
{".ps","application/postscript"},
{".psd","application/octet-stream"},
{".pvu","paleovu/x-pv"},
{".pwz","application/vnd.ms-powerpoint"},
{".py","text/x-script.phyton"},
{".pyc","application/x-bytecode.python"},
{".qcp","audio/vnd.qcelp"},
{".qd3","x-world/x-3dmf"},
{".qd3d","x-world/x-3dmf"},
{".qif","image/x-quicktime"},
{".qt","video/quicktime"},
{".qtc","video/x-qtc"},
{".qti","image/x-quicktime"},
{".qtif","image/x-quicktime"},
{".ra","audio/x-pn-realaudio"},
{".ra","audio/x-pn-realaudio-plugin"},
{".ra","audio/x-realaudio"},
{".ram","audio/x-pn-realaudio"},
{".ras","application/x-cmu-raster"},
{".ras","image/cmu-raster"},
{".ras","image/x-cmu-raster"},
{".rast","image/cmu-raster"},
{".rexx","text/x-script.rexx"},
{".rf","image/vnd.rn-realflash"},
{".rgb","image/x-rgb"},
{".rm","application/vnd.rn-realmedia"},
{".rm","audio/x-pn-realaudio"},
{".rmi","audio/mid"},
{".rmm","audio/x-pn-realaudio"},
{".rmp","audio/x-pn-realaudio"},
{".rmp","audio/x-pn-realaudio-plugin"},
{".rng","application/ringing-tones"},
{".rng","application/vnd.nokia.ringing-tone"},
{".rnx","application/vnd.rn-realplayer"},
{".roff","application/x-troff"},
{".rp","image/vnd.rn-realpix"},
{".rpm","audio/x-pn-realaudio-plugin"},
{".rt","text/richtext"},
{".rt","text/vnd.rn-realtext"},
{".rtf","application/rtf"},
{".rtf","application/x-rtf"},
{".rtf","text/richtext"},
{".rtx","application/rtf"},
{".rtx","text/richtext"},
{".rv","video/vnd.rn-realvideo"},
{".s","text/x-asm"},
{".s3m","audio/s3m"},
{".saveme","application/octet-stream"},
{".sbk","application/x-tbook"},
{".scm","application/x-lotusscreencam"},
{".scm","text/x-script.guile"},
{".scm","text/x-script.scheme"},
{".scm","video/x-scm"},
{".sdml","text/plain"},
{".sdp","application/sdp"},
{".sdp","application/x-sdp"},
{".sdr","application/sounder"},
{".sea","application/sea"},
{".sea","application/x-sea"},
{".set","application/set"},
{".sgm","text/sgml"},
{".sgm","text/x-sgml"},
{".sgml","text/sgml"},
{".sgml","text/x-sgml"},
{".sh","application/x-bsh"},
{".sh","application/x-sh"},
{".sh","application/x-shar"},
{".sh","text/x-script.sh"},
{".shar","application/x-bsh"},
{".shar","application/x-shar"},
{".shtml","text/html"},
{".shtml","text/x-server-parsed-html"},
{".sid","audio/x-psid"},
{".sit","application/x-sit"},
{".sit","application/x-stuffit"},
{".skd","application/x-koan"},
{".skm","application/x-koan"},
{".skp","application/x-koan"},
{".skt","application/x-koan"},
{".sl","application/x-seelogo"},
{".smi","application/smil"},
{".smil","application/smil"},
{".snd","audio/basic"},
{".snd","audio/x-adpcm"},
{".sol","application/solids"},
{".spc","application/x-pkcs7-certificates"},
{".spc","text/x-speech"},
{".spl","application/futuresplash"},
{".spr","application/x-sprite"},
{".sprite","application/x-sprite"},
{".src","application/x-wais-source"},
{".ssi","text/x-server-parsed-html"},
{".ssm","application/streamingmedia"},
{".sst","application/vnd.ms-pki.certstore"},
{".step","application/step"},
{".stl","application/sla"},
{".stl","application/vnd.ms-pki.stl"},
{".stl","application/x-navistyle"},
{".stp","application/step"},
{".sv4cpio","application/x-sv4cpio"},
{".sv4crc","application/x-sv4crc"},
{".svf","image/vnd.dwg"},
{".svf","image/x-dwg"},
{".svr","application/x-world"},
{".svr","x-world/x-svr"},
{".swf","application/x-shockwave-flash"},
{".t","application/x-troff"},
{".talk","text/x-speech"},
{".tar","application/x-tar"},
{".tbk","application/toolbook"},
{".tbk","application/x-tbook"},
{".tcl","application/x-tcl"},
{".tcl","text/x-script.tcl"},
{".tcsh","text/x-script.tcsh"},
{".tex","application/x-tex"},
{".texi","application/x-texinfo"},
{".texinfo","application/x-texinfo"},
{".text","application/plain"},
{".text","text/plain"},
{".tgz","application/gnutar"},
{".tgz","application/x-compressed"},
{".tif","image/tiff"},
{".tif","image/x-tiff"},
{".tiff","image/tiff"},
{".tiff","image/x-tiff"},
{".tr","application/x-troff"},
{".tsi","audio/tsp-audio"},
{".tsp","application/dsptype"},
{".tsp","audio/tsplayer"},
{".tsv","text/tab-separated-values"},
{".turbot","image/florian"},
{".txt","text/plain"},
{".uil","text/x-uil"},
{".uni","text/uri-list"},
{".unis","text/uri-list"},
{".unv","application/i-deas"},
{".uri","text/uri-list"},
{".uris","text/uri-list"},
{".ustar","application/x-ustar"},
{".ustar","multipart/x-ustar"},
{".uu","application/octet-stream"},
{".uu","text/x-uuencode"},
{".uue","text/x-uuencode"},
{".vcd","application/x-cdlink"},
{".vcs","text/x-vcalendar"},
{".vda","application/vda"},
{".vdo","video/vdo"},
{".vew","application/groupwise"},
{".viv","video/vivo"},
{".viv","video/vnd.vivo"},
{".vivo","video/vivo"},
{".vivo","video/vnd.vivo"},
{".vmd","application/vocaltec-media-desc"},
{".vmf","application/vocaltec-media-file"},
{".voc","audio/voc"},
{".voc","audio/x-voc"},
{".vos","video/vosaic"},
{".vox","audio/voxware"},
{".vqe","audio/x-twinvq-plugin"},
{".vqf","audio/x-twinvq"},
{".vql","audio/x-twinvq-plugin"},
{".vrml","application/x-vrml"},
{".vrml","model/vrml"},
{".vrml","x-world/x-vrml"},
{".vrt","x-world/x-vrt"},
{".vsd","application/x-visio"},
{".vst","application/x-visio"},
{".vsw","application/x-visio"},
{".w60","application/wordperfect6.0"},
{".w61","application/wordperfect6.1"},
{".w6w","application/msword"},
{".wav","audio/wav"},
{".wav","audio/x-wav"},
{".wb1","application/x-qpro"},
{".wbmp","image/vnd.wap.wbmp"},
{".web","application/vnd.xara"},
{".wiz","application/msword"},
{".wk1","application/x-123"},
{".wmf","windows/metafile"},
{".wml","text/vnd.wap.wml"},
{".wmlc","application/vnd.wap.wmlc"},
{".wmls","text/vnd.wap.wmlscript"},
{".wmlsc","application/vnd.wap.wmlscriptc"},
{".word","application/msword"},
{".wp","application/wordperfect"},
{".wp5","application/wordperfect"},
{".wp5","application/wordperfect6.0"},
{".wp6","application/wordperfect"},
{".wpd","application/wordperfect"},
{".wpd","application/x-wpwin"},
{".wq1","application/x-lotus"},
{".wri","application/mswrite"},
{".wri","application/x-wri"},
{".wrl","application/x-world"},
{".wrl","model/vrml"},
{".wrl","x-world/x-vrml"},
{".wrz","model/vrml"},
{".wrz","x-world/x-vrml"},
{".wsc","text/scriplet"},
{".wsrc","application/x-wais-source"},
{".wtk","application/x-wintalk"},
{".xbm","image/x-xbitmap"},
{".xbm","image/x-xbm"},
{".xbm","image/xbm"},
{".xdr","video/x-amt-demorun"},
{".xgz","xgl/drawing"},
{".xif","image/vnd.xiff"},
{".xl","application/excel"},
{".xla","application/excel"},
{".xla","application/x-excel"},
{".xla","application/x-msexcel"},
{".xlb","application/excel"},
{".xlb","application/vnd.ms-excel"},
{".xlb","application/x-excel"},
{".xlc","application/excel"},
{".xlc","application/vnd.ms-excel"},
{".xlc","application/x-excel"},
{".xld","application/excel"},
{".xld","application/x-excel"},
{".xlk","application/excel"},
{".xlk","application/x-excel"},
{".xll","application/excel"},
{".xll","application/vnd.ms-excel"},
{".xll","application/x-excel"},
{".xlm","application/excel"},
{".xlm","application/vnd.ms-excel"},
{".xlm","application/x-excel"},
{".xls","application/excel"},
{".xls","application/vnd.ms-excel"},
{".xls","application/x-excel"},
{".xls","application/x-msexcel"},
{".xlt","application/excel"},
{".xlt","application/x-excel"},
{".xlv","application/excel"},
{".xlv","application/x-excel"},
{".xlw","application/excel"},
{".xlw","application/vnd.ms-excel"},
{".xlw","application/x-excel"},
{".xlw","application/x-msexcel"},
{".xm","audio/xm"},
{".xml","application/xml"},
{".xml","text/xml"},
{".xmz","xgl/movie"},
{".xpix","application/x-vnd.ls-xpix"},
{".xpm","image/x-xpixmap"},
{".xpm","image/xpm"},
{".x-png","image/png"},
{".xsr","video/x-amt-showrun"},
{".xwd","image/x-xwd"},
{".xwd","image/x-xwindowdump"},
{".xyz","chemical/x-pdb"},
{".z","application/x-compress"},
{".z","application/x-compressed"},
{".zip","application/x-compressed"},
{".zip","application/x-zip-compressed"},
{".zip","application/zip"},
{".zip","multipart/x-zip"},
{".zoo","application/octet-stream"},
{".zsh","text/x-script.zsh"},
};
可是我傻傻的在感恩节当天去上班后改主意了,我觉得还是我之前想法使用file/magic来的好。另一个大笑话是我前田晚上犯迷糊居然一晚上没有意识到我在使用bigendian的方式,问题是我在拷贝粘贴homm3的地图读法的代码时候不小心选择了bigendian的,就是把integer都要reverse一下的方式,结果一晚上都不明白为什么读取的结果都不对,其中还包含了我对于stringstream的使用方法的存疑,我不明白为什么使用read方法指针是正确移动的,而使用get方法似乎第一次正确移动了,后来都错误了。今天我开始再次研究怎么转化中文字串的问题,首先面临的是究竟那些中文使用的是什么编码的问题,这个其实就是考验基本概念的时候了,魔鬼在细节,基本上没有程序员敢说自己不明白unicode的,可是真的吗?我对于utf8和utf16都不甚了了,何况是中文的各种编码,究竟gb2312和utf8是什么关系呢?我至今没有一个明确的概念,这个说出来真的很令人沮丧。这里先摘录utf8和utf16的部分。一个很重要的utf8的优势是endian-neutral
because Unicode text encoded in UTF-8 is just a sequence of 8-bit byte units, there's no endianness complication. The UTF-8 encoding (unlike UTF-16) is endian-neutral by design. This is an important feature when exchanging text across different computing systems that can have different hardware architectures with different endianness.微软之所以在这里提到utf16只不过是微软api使用的基本形式,这个应用已经不是主流了,所以没必要去使用,既生瑜何生亮?utf8有这么一个巨大的优势就足够了。
十二月一日等待变化等待机会
今天做了一个高难度的动作,太多的不知从何说起。我把这个存在这里。
先说一个小部分。就是makefile不显示执行的命令,这个帖子说的太好了。By default, make does print every command before executing it. This printing can be suppressed by one of the following mechanisms:我在file的Makefile里看到AM_DEFAULT_VERBOSITY=0导致不打印命令,于是我改成了1就好了。有一个时期我修改Makefile.am导致configure引发了libtool的重新编译抱怨我的版本不存在,为了压制这个问题,当然是因为file这个package制作的时候使用比较老的版本的autotool之类的,于是touch -d "2 days ago" Makefile.am。我之所以在经历这一切是因为我想做一个非常小的改进,就是libmagic把默认的magic.mgc作为资源文件嵌入到binary文件中这样就不至于因为不同系统路径设置不同二找不到了。这个完全是反智的行为,因为之所以使用文件就是增加了灵活性,而我在作这样一个无理而无礼的愚蠢的动作,但是其中的过程却是超乎我的预期的复杂。首先我要修改makefile.am/makefile.in来把汇编文件加入。其实,我作弊直接把*.Plo直接加在了.deps目录下,因为我不清楚怎么产生这个。现在看来我只要把我的汇编文件blob.S加入到source里再重新configure产生。
- on a case-by-case basis, by adding @ at the beginning of the command
- globally, by adding the .SILENT built-in target.
- somewhere along the make process, by invoking sub-make(s) with one of the flags -s, --silent or --quiet, as in $(MAKE) --silent -C someDir, for example. From that moment on, command echoing is suppressed in the sub-make.
- 在Makefile.am里我把blob.S加入到source文件名组里。并且加了这么一行:@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/blob.Plo@am__quote@
nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32$ cat src/.deps/blob.Plo blob.lo: blob.S /usr/include/stdc-predef.h /usr/include/stdc-predef.h: nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32$
- 在makefile.in里我拷贝了.c.lo:的规则:
.S.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
- 我只好硬性在configure里设置AM_DEFAULT_VERBOSITY=1强迫命令打印,也许环境变量是更好的办法?同时我意识到我应该编译静态库libmagic,同时我为了debug方便需要编译debug 版本:
./configure --enable-shared=false --enable-static=true make CFLAGS="-g -O0" CXXFLAGS="-g -O0" LDFLAGS="-g -O0"
- 我加入了一个汇编文件
nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32/src$ cat blob.S .global in_memory_blob .global in_memory_blob_size .section .rodata in_memory_blob: .incbin "/usr/lib/file/.magic.mgc" 1: in_memory_blob_size: .int 1b - in_memory_blob nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32/src$
- 在apprentice.c里需要修改load_1函数,通常在打开magic.mgc文件失败时候直接返回错误,我试图使用内存自带的资源文件同时模仿getline文件返回一行一行的文件内容:
extern char* in_memory_blob; extern int in_memory_blob_size; private int mygetline(char **buf, size_t *bufsiz, size_t*pos) { if (*pos >= in_memory_blob_size) { return -1; } size_t newsize=0; while (*pos + newsize < in_memory_blob_size) { if (in_memory_blob[*pos + newsize++] == '\n') { if (*buf == NULL) { *buf = malloc(newsize); } else { if (newsize > *bufsiz) { *buf = realloc(*buf, newsize); } } if (*buf == NULL) { return -1; } memcpy(*buf, in_memory_blob+*pos, newsize); *pos += newsize; *bufsiz = newsize; break; } } return newsize; } private void load_1(struct magic_set *ms, int action, const char *fn, int *errs, struct magic_entry_set *mset) { size_t lineno = 0, llen = 0; char *line = NULL; ssize_t len; struct magic_entry me; FILE *f = fopen(ms->file = fn, "r"); // if (f == NULL) { // if (errno != ENOENT) // file_error(ms, errno, "cannot read magic file `%s'", // fn); // (*errs)++; // return; // } // else // { // // use built-in in-memory one // } size_t pos = 0; memset(&me, 0, sizeof(me)); /* read and parse this file */ for (ms->line = 1; (len = (f==NULL)? mygetline(&line, &llen, &pos): getline(&line, &llen,f)) != -1; ms->line++) { if (len == 0) /* null line, garbage, etc */ continue; if (line[len - 1] == '\n') { lineno++; line[len - 1] = '\0'; /* delete newline */ } switch (line[0]) { case '\0': /* empty, do not parse */ case '#': /* comment, do not parse */ continue; case '!': if (line[1] == ':') { size_t i; for (i = 0; bang[i].name != NULL; i++) { if ((size_t)(len - 2) > bang[i].len && memcmp(bang[i].name, line + 2, bang[i].len) == 0) break; } if (bang[i].name == NULL) { file_error(ms, 0, "Unknown !: entry `%s'", line); (*errs)++; continue; } if (me.mp == NULL) { file_error(ms, 0, "No current entry for :!%s type", bang[i].name); (*errs)++; continue; } if ((*bang[i].fun)(ms, &me, line + bang[i].len + 2) != 0) { (*errs)++; continue; } continue; } /*FALLTHROUGH*/ default: again: switch (parse(ms, &me, line, lineno, action)) { case 0: continue; case 1: (void)addentry(ms, &me, mset); goto again; default: (*errs)++; break; } } } if (me.mp) (void)addentry(ms, &me, mset); free(line); if (f) { (void)fclose(f); } }
- 然而我在做了以上居然始终遇到无法访问in_memory_blob内存的问题,之前我没有使用malloc/remalloc而直接使用in_memory_blob的内存部分出现segment fault之类错误是可以预期的因为section是rodata就是只读的section,但是现在为什么出现了内存地址不能访问的问题呢?我把我之前的例子修改了一下检验使用静态库链接是没有问题的。
十二月二日等待变化等待机会
在终于找到问题的源头后,我把我的发现过程夸赞为“一个变量地址的研究”以便作为对伟大的福尔摩斯探案方法的再一次致敬:在你排除一切的不可能之后,那么唯一的你认为的不可能就成为可能。
我仔细的检查编译的过程,看起来没有问题,排除了编译错误我开始怀疑代码的问题,可是看汇编的symbol似乎也没有头绪,我的看汇编的能力太差,需要再学习分析。libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -DMAGIC=\"/etc/magic:/usr/local/share/misc/magic\" -fvisibility=hidden -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wsign-compare -Wreturn-type -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2 -g -O0 -MT blob.lo -MD -MP -MF .deps/blob.Tpo -c blob.S -o blob.o
libtool: link: ar cru .libs/libmagic.a magic.o apprentice.o blob.o softmagic.o ascmagic.o encoding.o compress.o is_tar.o readelf.o print.o fsmagic.o funcs.o apptype.o der.o cdf.o cdf_time.o readcdf.o strlcpy.o strlcat.o fmtcheck.o
libtool: link: ranlib .libs/libmagic.a
libtool: link: gcc -fvisibility=hidden -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wsign-compare -Wreturn-type -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2 -g -O0 -g -O0 -o file file.o ./.libs/libmagic.a -lz
查看汇编是这样子的:其中我怎么也想不明白.rodata里的偏移量00000000000273a8怎么也无法和代码中的地址0x1f9e0联系起来?
00000000000273a8 g .rodata 0000000000000000 in_memory_blob
00000000000273a8 g .rodata 0000000000000000 in_memory_blob
extern char* in_memory_blob;
extern int in_memory_blob_size;
private int mygetline(char **buf, size_t *bufsiz, size_t*pos)
{
7982: 55 push %rbp
7983: 48 89 e5 mov %rsp,%rbp
7986: 48 83 ec 30 sub $0x30,%rsp
798a: 48 89 7d e8 mov %rdi,-0x18(%rbp)
798e: 48 89 75 e0 mov %rsi,-0x20(%rbp)
7992: 48 89 55 d8 mov %rdx,-0x28(%rbp)
if (*pos >= in_memory_blob_size)
7996: 48 8b 45 d8 mov -0x28(%rbp),%rax
799a: 48 8b 10 mov (%rax),%rdx
799d: 8b 05 45 b0 4d 00 mov 0x4db045(%rip),%eax # 4e29e8 <n_memory_blob_size>
79a3: 48 98 cltq
79a5: 48 39 c2 cmp %rax,%rdx
79a8: 72 0a jb 79b4 <mygetline+0x32>
{
return -1;
79aa: b8 ff ff ff ff mov $0xffffffff,%eax
79af: e9 09 01 00 00 jmpq 7abd <mygetline+0x13b>
}
size_t newsize=0;
79b4: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
79bb: 00
while (*pos + newsize < in_memory_blob_size)
79bc: e9 d9 00 00 00 jmpq 7a9a <mygetline+0x118>
{
if (in_memory_blob[*pos + newsize++] == '\n')
79c1: 48 8b 0d e0 f9 01 00 mov 0x1f9e0(%rip),%rcx # 273a8 <in_memory_blob>
79c8: 48 8b 45 d8 mov -0x28(%rbp),%rax
经过一个上午的瞎捣鼓终于明白了。- 编译器当然没有错,也没有什么section绝对地址相对地址的问题,比如mov 0x1f9e0 (%rip),%rcx # 273a8 <in_memory_blob>里地址是完全没有问题的,这里的0x1f9e0加上当前代码执行地址,也就是下一行的地址0x79c8就是.rodata里的偏移量0x273a8。
- 在gdb里我看到了真实的问题,就是这个全局变量in_memory_blob我把它定义为指针char*可是只有当我使用它的地址的时候我才能访问,或者说我只有使用&才能真正获得她所指向的偏移0x273a8(当然这个是不真实的因为在gdb里这些都要加上一个真正的基地址,不过我说的的确是事实因为可以从另一个变量in_memory_blob_size与之相比较看出来那个是实际的地址因为这个长度变量我始终访问没有问题。所以,结论是我对于汇编代码的指针类型的理解有误!
- 这个实在是embarassing,我用了这么多年的指针居然会犯这么个低级错误?回忆当年唯一写过汇编的大学作业里,的确声明一个字符串你只能说它变量类型是char,而没有什么char*这个概念,也就是说我声明的这个全局变量in_memory_blob类型必须是char。然后我在使用中必须使用他的地址来获得数组:
真的是老糊涂了啊!似乎我在我的测试例子里就没有这个问题,难道我这么多年代码都白写了?extern char in_memory_blob; ... char* ptr = &in_memory_blob; if (ptr[*pos + newsize++] == '\n')
extern char blob[]; extern int blob_size; int main(int argc, char** argv) { char* buf = NULL; buf = (char*)malloc(blob_size+1); if (buf) { memcpy(buf, blob, blob_size); buf[blob_size] = '\0'; printf("%s\n", buf); free(buf); } return 0; }
- 随着这个问题的解决我才真正的遇到了核心问题就是我的算法有问题,这个代码有问题在于这里输入的文件似乎不对,也就是说期待的是未处理的文件?这个才是真正的核心,而我花了整整一天半时间在细枝末节上。这才遇到了核心的算法问题,需要回去看代码才行。
十二月二日等待变化等待机会
经过一整天的迷惑,我终于意识到我是bark the wrong tree!完全瞄准了错误的目标,但是前两天的工作并不是毫无作用,没有对于汇编字符串的研究结果我肯定会陷入更多的迷潭之中。
- 我陷入了一种迷惑之地,因为我编译的版本正常加载magic.mgc的时候抱怨格式有问题,我一开始以为是我改动代码的缘故,后来我下载原来代码同样遇到这个问题,我又以为是magic.mgc的问题,可是Ubuntu原装的file没有这个问题,我于是编译了源代码的动态库,依然有同样的问题,除非链接官方的动态库,所以,看起来是编译libmagic.so的问题,可是问题能出在哪里呢?libmagic是一个很简单的东西,怎么会有什么大学问呢?我有源代码,编译方法有什么问题呢?
- 我完全没有头绪,只是注意到了一个小细节就是默认的libmagic.so是存在于/usr/lib/x86_64-linux-gnu/libmagic.so,这个是一个很长的multiarch的话题,我看的头疼,模模糊糊印象以前这个类似的东西都是交叉编译才需要。我依然毫无头绪,32位与64位始终是一个模糊地带,代码需要支持可是magic.mgc有什么关系呢?难道文件偏移量和32/64位有关?
我找到了magic.mgc应该的格式,这个也正是我在gdb里跟踪所迷惑的。 - 什么叫做山穷水复疑无路柳暗花明又一村。终于我领悟到我看到的magic.mgc是已经编译好的文件而不是man magic里讲的source的格式。所以,我使用了错误的模式,实际上我在使用bcompile模式,而我应该作的工作是加载模式,所以,我之前的代码都是错误的,我需要修改的是这个函数:(注意原来这个函数使用mmap实际上还是挺复杂的因为使用mmap之前要打开文件句柄,而mmap等等环节都需要作错误检查,而现在我使用内嵌的资源文件就只有两行代码)
现在变得多么的简洁啊,extern char in_memory_blob; extern int in_memory_blob_size; private struct magic_map * apprentice_map(struct magic_set *ms, const char *fn) { struct magic_map *map; struct magic_map *rv = NULL; if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) { file_oomem(ms, sizeof(*map)); goto error; } map->type = MAP_TYPE_USER; /* unspecified */ map->len = (size_t)in_memory_blob_size; map->p = &in_memory_blob; if (check_buffer(ms, map, fn) != 0) { rv = (struct magic_map *)-1; goto error; } return map; error: return rv; }
而使用方法是你需要使用file的加载模式(注意我这里故意在-m后使用一个虚假的参数1,这里我仅仅要进入加载模式而已。现在我只需要直接使用我自己编译的file命令,即便默认的magic.mgc被我删除了也照样工作,当然官方的file是不能工作了如果我删除了默认的magic.mgc的话:nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32/src$ ./file -m 1 ~/Pictures/mercy.gif /home/nick/Pictures/mercy.gif: GIF image data, version 89a, 688 x 288 nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32/src$
nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32/src$ ./file ./file ./file: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=bf07c31f00cf7d2937cbcfabd3160a30a82dfceb, with debug_info, not stripped nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32/src$ nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32/src$ ldd ./file linux-vdso.so.1 (0x00007fffc4cc5000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff8c734d000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff8c6f5c000) /lib64/ld-linux-x86-64.so.2 (0x00007ff8c7c54000) nick@nick-HP-Laptop-AMD:~/Downloads/file-5.32/src$