0

我最近开始开发一个开源防病毒软件,尽管哈希是使用 Aho-Corasick 算法生成的。

我很想知道如何从可执行文件中生成 Aho-Corasick 哈希,因为我在互联网上几乎找不到任何关于此的信息

4

1 回答 1

0

在 Java 中:

private static String readFile(String path) throws IOException {
  FileInputStream stream = new FileInputStream(new File(path));
  try {
    FileChannel fc = stream.getChannel();
    MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
    /* Instead of using default, pass in a decoder. */
    return Charset.defaultCharset().decode(bb).toString();
  }
  finally {
    stream.close();
  }
}

然后你可以使用,下面来获取 MD5 哈希

byte[] bytesOfMessage = readFile("filepath").getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
String thedigest = Arrays.toString[md.digest(bytesOfMessage)];
于 2011-04-08T23:08:27.823 回答