mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-07-30 07:18:37 -09:00
Merge remote-tracking branch 'origin/GP-6868_James_improve_bsim_md5_validation' into patch
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -225,9 +225,6 @@ public class DescriptionManager {
|
||||
*/
|
||||
public ExecutableRecord newExecutableRecord(String md5, String enm, String cnm, String arc,
|
||||
Date dt, String repo, String path, RowKey id) throws LSHException {
|
||||
if (md5.length() != 32) {
|
||||
throw new LSHException("MD5 field must be exactly 32 hex characters");
|
||||
}
|
||||
ExecutableRecord newexe = new ExecutableRecord(md5, enm, cnm, arc, dt, id, repo, path);
|
||||
if (!exerec.add(newexe)) {
|
||||
ExecutableRecord oldexe = exerec.floor(newexe);
|
||||
|
||||
@@ -19,6 +19,8 @@ import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import generic.hash.SimpleCRC32;
|
||||
import ghidra.features.bsim.query.LSHException;
|
||||
@@ -53,6 +55,9 @@ public class ExecutableRecord implements Comparable<ExecutableRecord> {
|
||||
public static final int METADATA_PATH = 32;
|
||||
public static final int METADATA_LIBR = 64;
|
||||
|
||||
private static final String md5Regex = "[a-fA-F0-9]{32}";
|
||||
private static final Pattern md5Matcher = Pattern.compile(md5Regex);
|
||||
|
||||
private final String md5sum; // The MD5 hash of the executable
|
||||
private final String executableName; // The name of the executable
|
||||
private final String architecture; // The architecture on which the executable runs
|
||||
@@ -77,6 +82,13 @@ public class ExecutableRecord implements Comparable<ExecutableRecord> {
|
||||
public List<CategoryRecord> catinsert; // Non-null, if there are only insertions
|
||||
}
|
||||
|
||||
private static void checkValidMD5(String md5) {
|
||||
Matcher matcher = md5Matcher.matcher(md5);
|
||||
if (!matcher.matches()) {
|
||||
throw new IllegalArgumentException("Invalid MD5 hash string: " + md5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a 32-bit integer to hexadecimal ascii representation
|
||||
* @param val is the integer to encode
|
||||
@@ -125,8 +137,10 @@ public class ExecutableRecord implements Comparable<ExecutableRecord> {
|
||||
/**
|
||||
* Constructor for searching within a DescriptionManager
|
||||
* @param md5 is hash of executable being searched for
|
||||
* @throws IllegalArgumentException if {@code md5} is not a valid md5 hash string
|
||||
*/
|
||||
protected ExecutableRecord(String md5) {
|
||||
checkValidMD5(md5);
|
||||
md5sum = md5;
|
||||
executableName = "";
|
||||
architecture = "";
|
||||
@@ -151,9 +165,11 @@ public class ExecutableRecord implements Comparable<ExecutableRecord> {
|
||||
* @param id is the row id of the record
|
||||
* @param repo is the repository containing the executable (may be null)
|
||||
* @param path is the path to the executable (may be null)
|
||||
* @throws IllegalArgumentException if {@code md5} is not a valid MD5 hash string
|
||||
*/
|
||||
public ExecutableRecord(String md5, String execName, String compilerName, String architecture,
|
||||
Date date, RowKey id, String repo, String path) {
|
||||
checkValidMD5(md5);
|
||||
this.md5sum = md5;
|
||||
this.executableName = execName;
|
||||
this.architecture = architecture;
|
||||
@@ -177,9 +193,11 @@ public class ExecutableRecord implements Comparable<ExecutableRecord> {
|
||||
* @param id is the row id of the record
|
||||
* @param repo is the repository containing the executable (may be null)
|
||||
* @param pth is the path to the executable (may be null)
|
||||
* @throws IllegalArgumentException if {@code md5} is not a valid MD5 hash string.
|
||||
*/
|
||||
public ExecutableRecord(String md5, String enm, String cnm, String arc, Date dt,
|
||||
List<CategoryRecord> uc, RowKey id, String repo, String pth) {
|
||||
checkValidMD5(md5);
|
||||
md5sum = md5;
|
||||
executableName = enm;
|
||||
architecture = arc;
|
||||
|
||||
Reference in New Issue
Block a user