T上西北

基础还是真重要的

一些知识太久不用,发现自己都快遗忘了。上周和某位同学一起聊天,谈到了一些最基本的知识,因为自己的生疏,或者不懂,搞得自己有些尴尬。为了改变这一现状,还是先熟悉一下例我远去的基础知识吧。

今年来自己状态也不是特别好,总被这样那样的事情分心,所以也没有时间去整理一下。事实上,与其说这样的理由,还不如说自己因为一些事情导致自己心都懒惰了,所以这些知识才离我远去,突然想起刚毕业那会和一年前那种干劲,真的很怀恋。

话不多说,是时候捡起来了。马上行动,先写一个计划吧。

给NetBean For Ruby安装Fast Debugger

心血来潮,发现自己的Netbean IDE for ruby已经很老了,于是想更新一下。

用就用最新的,到这里下载了一个最新的NB 6.5 beta版本:

http://bits.netbeans.org/download/trunk/nightly/latest/

下载2分钟,安装1分钟,导入工程1分钟。然后点击调试按钮0.1s,系统居然提示我安装fast debugger 0.3版本。直接在IDE上安装了,等了N久就是安装不上。

接着在命令行飞快输入:

gem install ruby-debug-ide -v '0.3.2' --include-dependencies

等了半天,居然出现如下结果:

INFO:  `gem install -y` is now default and will be removed
INFO:  use --ignore-dependencies to install only the gems you list
Bulk updating Gem source index for: http://gems.rubyforge.org/

于是在美国的服务器上试了一把,结果是没问题。看来是我们这边网络有问题呀。设置好socket代理,嘿,我也不知道怎么在gem下设置socket代理,只知道设置http代理。无果,只能下载gem文件安装了。

Google了一把,

ruby-debug-ide居然在Debug Commons里面。链接是:http://rubyforge.org/frs/?group_id=3085

因为ruby-debug-ide依赖ruby-debug-base,所以不得不找它。后来发现在ruby-debug这里,链接是http://rubyforge.org/frs/?group_id=1900

注意,如果你在windows安装,ruby-debug-base必须安装windows版本的。

一切搞定。要不是公司网络问题,我还不知道ruby-debug-ide的包究竟在哪里。

接下来想研究一下它是如何给ruby设置hook的。

7Zip的格式

我一直使用7Zip,今天下载了7Zip的代码,才知道7Zip的格式。所以将之Copy到这里。

7z Format description (2.30 Beta 25)
———————————–

This file contains description of 7z archive format.
7z archive can contain files compressed with any method.
See “Methods.txt” for description for defined compressing methods.

Format structure Overview
————————-

Some fields can be optional.

Archive structure
~~~~~~~~~~~~~~~~~ 
SignatureHeader
[PackedStreams]
[PackedStreamsForHeaders]
[
  Header
  or
  {
    Packed Header
    HeaderInfo
  }
]

Header structure
~~~~~~~~~~~~~~~~ 
{
  ArchiveProperties
  AdditionalStreams
  {
    PackInfo
    {
      PackPos
      NumPackStreams
      Sizes[NumPackStreams]
      CRCs[NumPackStreams]
    }
    CodersInfo
    {
      NumFolders
      Folders[NumFolders]
      {
        NumCoders
        CodersInfo[NumCoders]
        {
          ID
          NumInStreams;
          NumOutStreams;
          PropertiesSize
          Properties[PropertiesSize]
        }
        NumBindPairs
        BindPairsInfo[NumBindPairs]
        {
          InIndex;
          OutIndex;
        }
        PackedIndices
      }
      UnPackSize[Folders][Folders.NumOutstreams]
      CRCs[NumFolders]
    }
    SubStreamsInfo
    {
      NumUnPackStreamsInFolders[NumFolders];
      UnPackSizes[]
      CRCs[]
    }
  }

  MainStreamsInfo
  {
    (Same as in AdditionalStreams)
  }
  FilesInfo
  {
    NumFiles
    Properties[]
    {
      ID
      Size
      Data
    }
  }
}

 

HeaderInfo structure
~~~~~~~~~~~~~~~~~~~~
{
  (Same as in AdditionalStreams)
}

Notes about Notation and encoding
———————————

7z uses little endian encoding.

7z archive format has optional headers that are marked as
[]
Header
[]

REAL_UINT64 means real UINT64.

UINT64 means real UINT64 encoded with the following scheme:

  Size of encoding sequence depends from first byte:
  First_Byte  Extra_Bytes        Value
  (binary)  
  0xxxxxxx               : ( xxxxxxx           )
  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y
  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y
  …
  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y
  11111110    BYTE y[7]  :                         y
  11111111    BYTE y[8]  :                         y

Property IDs
————

0x00 = kEnd,

0x01 = kHeader,

0x02 = kArchiveProperties,
0x03 = kAdditionalStreamsInfo,
0x04 = kMainStreamsInfo,
0x05 = kFilesInfo,
0x06 = kPackInfo,
0x07 = kUnPackInfo,
0x08 = kSubStreamsInfo,

0x09 = kSize,
0x0A = kCRC,

0x0B = kFolder,

0x0C = kCodersUnPackSize,
0x0D = kNumUnPackStream,

0x0E = kEmptyStream,
0x0F = kEmptyFile,
0x10 = kAnti,

0x11 = kName,
0x12 = kCreationTime,
0x13 = kLastAccessTime,
0x14 = kLastWriteTime,
0x15 = kWinAttributes,
0x16 = kComment,

0x17 = kEncodedHeader,

7z format headers
—————–

SignatureHeader
~~~~~~~~~~~~~~~
  BYTE kSignature[6] = {‘7’, ‘z’, 0xBC, 0xAF, 0x27, 0x1C};

  ArchiveVersion
  {
    BYTE Major;   // now = 0
    BYTE Minor;   // now = 2
  };

  UINT32 StartHeaderCRC;

  StartHeader
  {
    REAL_UINT64 NextHeaderOffset
    REAL_UINT64 NextHeaderSize
    UINT32 NextHeaderCRC
  }

………………………

ArchiveProperties
~~~~~~~~~~~~~~~~~
BYTE NID::kArchiveProperties (0x02)
for (;;)
{
  BYTE PropertyType;
  if (aType == 0)
    break;
  UINT64 PropertySize;
  BYTE PropertyData[PropertySize];
}

Digests (NumStreams)
~~~~~~~~~~~~~~~~~~~~~
  BYTE AllAreDefined
  if (AllAreDefined == 0)
  {
    for(NumStreams)
      BIT Defined
  }
  UINT32 CRCs[NumDefined]

PackInfo
~~~~~~~~~~~~
  BYTE NID::kPackInfo  (0x06)
  UINT64 PackPos
  UINT64 NumPackStreams

  []
  BYTE NID::kSize    (0x09)
  UINT64 PackSizes[NumPackStreams]
  []

  []
  BYTE NID::kCRC      (0x0A)
  PackStreamDigests[NumPackStreams]
  []

  BYTE NID::kEnd

Folder
~~~~~~
  UINT64 NumCoders;
  for (NumCoders)
  {
    BYTE
    {
      0:3 DecompressionMethod.IDSize
      4:
        0 – IsSimple
        1 – Is not simple
      5:
        0 – No Attributes
        1 – There Are Attributes
      7:
        0 – Last Method in Alternative_Method_List
        1 – There are more alternative methods
    }
    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]
    if (!IsSimple)
    {
      UINT64 NumInStreams;
      UINT64 NumOutStreams;
    }
    if (DecompressionMethod[0] != 0)
    {
      UINT64 PropertiesSize
      BYTE Properties[PropertiesSize]
    }
  }
  NumBindPairs = NumOutStreamsTotal – 1;

  for (NumBindPairs)
  {
    UINT64 InIndex;
    UINT64 OutIndex;
  }

  NumPackedStreams = NumInStreamsTotal – NumBindPairs;
  if (NumPackedStreams > 1)
    for(NumPackedStreams)
    {
      UINT64 Index;
    };

Coders Info
~~~~~~~~~~~

  BYTE NID::kUnPackInfo  (0x07)

  BYTE NID::kFolder  (0x0B)
  UINT64 NumFolders
  BYTE External
  switch(External)
  {
    case 0:
      Folders[NumFolders]
    case 1:
      UINT64 DataStreamIndex
  }

  BYTE ID::kCodersUnPackSize  (0x0C)
  for(Folders)
    for(Folder.NumOutStreams)
     UINT64 UnPackSize;

  []
  BYTE NID::kCRC   (0x0A)
  UnPackDigests[NumFolders]
  []

  BYTE NID::kEnd

SubStreams Info
~~~~~~~~~~~~~~
  BYTE NID::kSubStreamsInfo; (0x08)

  []
  BYTE NID::kNumUnPackStream; (0x0D)
  UINT64 NumUnPackStreamsInFolders[NumFolders];
  []

  []
  BYTE NID::kSize  (0x09)
  UINT64 UnPackSizes[]
  []

  []
  BYTE NID::kCRC  (0x0A)
  Digests[Number of streams with unknown CRC]
  []

  BYTE NID::kEnd

Streams Info
~~~~~~~~~~~~

  []
  PackInfo
  []

  []
  CodersInfo
  []

  []
  SubStreamsInfo
  []

  BYTE NID::kEnd

FilesInfo
~~~~~~~~~
  BYTE NID::kFilesInfo;  (0x05)
  UINT64 NumFiles

  for (;;)
  {
    BYTE PropertyType;
    if (aType == 0)
      break;

    UINT64 Size;

    switch(PropertyType)
    {
      kEmptyStream:   (0x0E)
        for(NumFiles)
          BIT IsEmptyStream

      kEmptyFile:     (0x0F)
        for(EmptyStreams)
          BIT IsEmptyFile

      kAnti:          (0x10)
        for(EmptyStreams)
          BIT IsAntiFile
      case kCreationTime:   (0x12)
      case kLastAccessTime: (0x13)
      case kLastWriteTime:  (0x14)
        BYTE AllAreDefined
        if (AllAreDefined == 0)
        {
          for(NumFiles)
            BIT TimeDefined
        }
        BYTE External;
        if(External != 0)
          UINT64 DataIndex
        []
        for(Definded Items)
          UINT32 Time
        []
      kNames:     (0x11)
        BYTE External;
        if(External != 0)
          UINT64 DataIndex
        []
        for(Files)
        {
          wchar_t Names[NameSize];
          wchar_t 0;
        }
        []

      kAttributes:  (0x15)
        BYTE AllAreDefined
        if (AllAreDefined == 0)
        {
          for(NumFiles)
            BIT AttributesAreDefined
        }
        BYTE External;
        if(External != 0)
          UINT64 DataIndex
        []
        for(Definded Attributes)
          UINT32 Attributes
        []
    }
  }

Header
~~~~~~
  BYTE NID::kHeader (0x01)

  []
  ArchiveProperties
  []

  []
  BYTE NID::kAdditionalStreamsInfo; (0x03)
  StreamsInfo
  []

  []
  BYTE NID::kMainStreamsInfo;    (0x04)
  StreamsInfo
  []

  []
  FilesInfo
  []

  BYTE NID::kEnd

HeaderInfo
~~~~~~~~~~
  []
  BYTE NID::kEncodedHeader; (0x17)
  StreamsInfo for Encoded Header
  []


End of document