Quartett!的二进制脚本分析 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-14
NATURE.Length ); 65. if ( !Equals( sig, SIGNATURE ) ) { 66. Console.WriteLine( "Wrong signature" ); 67. return; 68. } 69. 70. // write UTF-16LE BOM 71. writer.Write( ( ushort ) 0xFEFF ); 72. 73. // process each token 74. int lineNum = 1; 75. int lastLineNum = 1; 76. TokenType tokenType = TokenType.Operator; 77. TokenType lastTokenType = TokenType.Operator; 78. int tabCount = 0; 79. int tokenCount = reader.ReadInt32( ); 80. for ( int tokenNum = 0; tokenNum < tokenCount; ++tokenNum ) { 81. // deal with line numbers, insert empty new lines if needed 82. lineNum = reader.ReadInt32( ); 83. if ( lastLineNum < lineNum ) { // should write on a newline 84. // write empty lines 85. for ( int i = lastLineNum; i < lineNum; ++i ) { 86. writer.Write( utf16le.GetBytes( Environment.NewLine ) ); 87. } 88. // write tabs as indent 89. for ( int tabs = 0; tabs < tabCount; ++tabs ) { 90. writer.Write( utf16le.GetBytes( "\t" ) ); 91. } 92. // put a dummy value into tokenType 93. lastTokenType = TokenType.Operator; 94. } 95. 96. // get token tokenType 97. tokenType = ( TokenType ) ( reader.ReadByte( ) & 0x0FF ); 98. 99. // get token value 100. string tokenString = ReadCString( reader ); 101. 102. // deal with different token types 103. if ( !( lastTokenType == TokenType.Operator 104. || lastTokenType == TokenType.String 105. || lastTokenType == TokenType.Decimal 106. || lastTokenType == TokenType.Hexadecimal ) ) { 107. writer.Write( utf16le.GetBytes( " " ) ); 108. } 109. switch ( tokenType ) { 110. case TokenType.Decimal: 111. case TokenType.Identifier: 112. case TokenType.Hexadecimal: 113. writer.Write( utf16le.GetBytes( tokenString ) ); 114. break; 115. 116. case TokenType.String: 117. writer.Write( 118. utf16le.GetBytes( string.Format( "\"{0}\"", tokenString ) ) ); 119. break; 120. 121. case TokenType.Operator: 122. switch ( tokenString ) { 123. case "#": 124. case "%": 125. case "-": 126. case "@": 127. writer.Write( utf16le.GetBytes( tokenString ) ); 128. break; 129. case "{": 130. ++tabCount; 131. writer.Write( utf16le.GetBytes( tokenString ) ); 132. break; 133. case "}": 134. --tabCount; 135. writer.BaseStream.Position -= 2; // delete the last tab 136. writer.Write( utf16le.GetBytes( tokenString ) ); 137. break; 138. case "(": 139. case ",": 140. case ";": 141. case "=": 142. writer.Write( 143. utf16le.GetBytes( string.Format( "{0} ", tokenString ) ) ); 144. break; 145. case ")": 146. writer.Write( 147. utf16le.GetBytes( string.Format( " {0}", tokenString ) ) ); 148. break; 149. } // switch tokenString 150. break; 151. 152. default: 153. Console.WriteLine( "Unexpected token type {0} at 0x{1}.", 154. tokenType.ToString( "X" ), 155. reader.BaseStream.Position.ToString( "X" ) ); 156. return; 157. } // switch tokenType 158. 159. // re-initiali |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于Quartett!的二进制脚本分析 - 编程入门网的所有评论