0x88开头的,其之前是三个00的东西全部都扫描 一遍。于是在之前的程序上修改了一下判断条件,得到下面代码:
opcode_analysis.cs:
C#代码
1.using System;
2.using System.Collections.Generic;
3.using System.IO;
4.using System.Text;
5.
6.namespace FFDSystemAnalysis
7.{
8. sealed class Analyzer
9. {
10. private static readonly byte[ ] SIGNATURE = {
11. ( byte )0x54, ( byte )0x4F, ( byte )0x4B, ( byte )0x45,
12. ( byte )0x4E, ( byte )0x53, ( byte )0x45, ( byte )0x54,
13. ( byte )0x64, ( byte )0x0, ( byte )0x0, ( byte )0x0
14. };
15.
16. static void Main( string[ ] args ) {
17. if ( !args[ 0 ].EndsWith( ".tkn" ) ) return;
18. if ( !File.Exists( args[ 0 ] ) ) return;
19.
20. string infile = args[ 0 ];
21. string outfile = infile + ".txt";
22.
23. Encoding utf16le = new UnicodeEncoding( false, true );
24. Encoding jis = Encoding.GetEncoding( 932 );
25.
26. using ( BinaryReader reader = new BinaryReader( File.OpenRead( infile ), jis ) ) {
27. using ( BinaryWriter writer = new BinaryWriter( File.Create( outfile ), utf16le ) ) {
28. byte[ ] sig = reader.ReadBytes( SIGNATURE.Length );
29. if ( !Equals( sig, SIGNATURE ) ) {
30. Console.WriteLine( "Wrong signature" );
31. return;
32. }
33.
34. // write UTF-16LE BOM
35. writer.Write( ( ushort ) 0xFEFF );
36.
37. Queue<byte> queue = new Queue<byte>( 3 );
38. queue.Enqueue( reader.ReadByte( ) );
39. queue.Enqueue( reader.ReadByte( ) );
40. queue.Enqueue( reader.ReadByte( ) );
41.
42. byte lastOpcode = 0;
43. while ( reader.BaseStream.Position < reader.BaseStream.Length ) {
44. byte currentByte = reader.ReadByte( );
45. if ( currentByte == 0x080
46. || currentByte == 0x081
47. || currentByte == 0x082
48. || currentByte == 0x083
49. || currentByte == 0x084
50. || currentByte == 0x085
51. || currentByte == 0x086
52. || currentByte == 0x087
53. || currentByte == 0x088 ) {
54. if ( MatchQueueData( queue ) ) {
55. long position = reader.BaseStream.Position;
56. string line = ReadCString( reader );
57. Entry e = new Entry( ) {
58. position = position,
59. opcode = currentByte,
60. lastOpcode = lastOpcode,
61. line = line
62. };
63. writer.Write(
64. utf16le.GetBytes(
65. string.Format( "{0}{1}",
66. e.ToString( ),
67. Environment.NewLine )
68. )
69. );
70. } // if
71. } // if
72.
73. // re-initialize
74. lastOpcode = queue.Dequeue( );
75. queue.Enqueue( currentByte );
76. } // while
77. } // using
78. } // using
79. } // Main
80.
81. static bool Equals( byte[ ] a, byte[ ] b ) {
82. int len = a.Length;
83. if ( len != b.Length ) return false;
84. for ( int i = 0; i < len; i++ ) {
85. if ( a[ i ] != b[ i ] ) return false;
86. }
87. return true;
88. }
89.
90. static bool MatchQueueData( Queue<byte> queue ) {
91. byte[ ] array = queue.ToArray( );
92. return Equals( zeros, array );
93. }
94.
95. static string ReadCString( BinaryReader reader ) {
96. StringBuilder builder = new StringBuilder( );
97. char c = ''\0'';
98.
99. while ( ( c = reader.ReadChar( ) ) != ''\0''
|