2010-11-28 4 views
0

私はこれに対する答えを見つけようとしましたが、今は午前1時です。ちょっと疲れました。Javaの16進文字列のデータベースファイルをスキャンする方法

誰かが私に正しい方向を教えてください。私がしたいことは、Java(.wmdbデータベースファイル)を使って16進値のパターンをスキャンし、このパターンの後の16進値を引き出すことです。

例:1.進値アウト "(b)(a)80 10 00 00 00 00 00" 2プルのHEX値をスキャンスキャナが "00 00 28" の値に達するまで 3.繰り返し

私はバイナリIOを使用して逃した簡単な方法があると確信していますが、私はそれをうまくやってくれないようです。私は答えの後ではないが、正しい方向への蹴りや簡単な例が私に大きな助けになるだろう。

答えて

0

これは簡単な方法です。あなたのbegin matchとend match表現をbyteのシーケンスに変換するだけです。その後、java.io.InputStreamで開始シーケンスを検索し、最後に一致するまで値を引き出します。一致させるにはwell-known algorithmsのいずれかを使用してください。

ここbeginMatchとendMatch間のすべてのバイトシーケンスを収集することを、ナイーブな実装の例です:

public ArrayList<ArrayList<Integer>> pullOutBytes(InputStream stream, ArrayList<Integer> beginMatch, ArrayList<Integer> endMatch) 
     throws IOException { 
    ArrayList<ArrayList<Integer>> pulledOut = new ArrayList<ArrayList<Integer>>(); 
    int b; 
    BeginSearch: 
    while ((b = stream.read()) != -1) { 
     int beginMatchIndex = 0; 
     if (b != beginMatch.get(beginMatchIndex)) { 
      continue BeginSearch; 
     } 
     beginMatchIndex++; 
     while ((b = stream.read()) != -1 && beginMatchIndex < beginMatch.size()) { 
      if (b != beginMatch.get(beginMatchIndex)) { 
       continue BeginSearch; 
      } 
      beginMatchIndex++; 
     } 
     if (beginMatchIndex < beginMatch.size()) { 
      break; 
     } 
     int endMatchIndex = 0; 
     ArrayList<Integer> pull = new ArrayList<Integer>(); 
     pull.add(b); 
     while ((b = stream.read()) != -1) { 
      pull.add(b); 
      if (b == endMatch.get(endMatchIndex)) { 
       if (++endMatchIndex == (endMatch.size() - 1)) { 
        while (endMatchIndex > 0) { 
         pull.remove(pull.size() - 1); 
         endMatchIndex--; 
        } 
        pulledOut.add(pull); 
        continue BeginSearch; 
       } 
      } 
     } 
    } 
    return pulledOut; 
} 
関連する問題