2010-11-28 2 views
0

나는 이것에 대한 답을 찾기 위해 노력했지만 지금은 1am이고 약간 피곤합니다.자바에서 16 진수 문자열 데이터베이스 파일을 검사하는 방법

누군가 올바른 방향으로 나를 가리켜 주시겠습니까, 내가하고 싶은 것은 16 진수 값의 패턴에 대해 Java (.wmdb 데이터베이스 파일)를 사용하여 파일을 스캔 한 다음이 패턴 이후의 16 진수 값을 추출하는 것입니다. 16 진수 값

예 1 스캔 "6B 4A 80 10 00 00 00 00 00" 2 스캐너는 "00 00 28" 를 반복

의 값에 도달하는 16 진수 값을 뽑아까지

이진 입출력을 사용하여 놓친 쉬운 방법이 있지만 확실하게 해결하지 못하는 것 같습니다. 대답 뒤에있는 것이 아니라 올바른 방향으로 걷어차는 것 또는 간단한 예가 나에게 큰 도움이 될 것입니다.

답변

0

맞습니다. 쉬운 방법이 있습니다. 시작 일치 및 최종 일치 표현을 byte의 시퀀스로 변환하면됩니다. 그런 다음 java.io.InputStream에서 시작 순서를 검색하고 최종 일치 항목이 일치 할 때까지 값을 꺼냅니다. 일치를 위해 well-known algorithms 중 하나를 사용할 수 있습니다.

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; 
} 
: 여기

순진한 구현 예가, 즉 beginMatch 및 endMatch 사이의 모든 바이트 시퀀스를 모아