<commit_before>#pragma once
#include <vector>
#include <hash_set>
#include <list>

#include "Common.h"
#include "OneIDAClientManager.h"
#include "DataStructure.h"
#include "LogOperation.h"

const enum {DiffMachineFileBinaryFormat, DiffMachineFileSQLiteFormat};

#define MATCH_MAP_TABLE "MatchMap"
#define CREATE_MATCH_MAP_TABLE_STATEMENT "CREATE TABLE " MATCH_MAP_TABLE" ( \n\
			id INTEGER PRIMARY KEY AUTOINCREMENT, \n\
			TheSourceFileID INTEGER, \n\
			TheTargetFileID INTEGER, \n\
			TheSourceAddress INTEGER, \n\
			TheTargetAddress INTEGER, \n\
			MatchType INTEGER, \n\
			Type INTEGER, \n\
			SubType INTEGER, \n\
			Status INTEGER, \n\
			MatchRate INTEGER, \n\
			UnpatchedParentAddress INTEGER, \n\
			PatchedParentAddress INTEGER\n\
		 );"
#define INSERT_MATCH_MAP_TABLE_STATEMENT "INSERT INTO  "MATCH_MAP_TABLE" ( TheSourceFileID, TheTargetFileID, TheSourceAddress, TheTargetAddress, MatchType, Type, SubType, Status, MatchRate, UnpatchedParentAddress, PatchedParentAddress ) values ( '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u' );"
#define DELETE_MATCH_MAP_TABLE_STATEMENT "DELETE FROM "MATCH_MAP_TABLE" WHERE TheSourceFileID=%u and TheTargetFileID=%u"
#define CREATE_MATCH_MAP_TABLE_INDEX_STATEMENT "CREATE INDEX "MATCH_MAP_TABLE"Index ON "MATCH_MAP_TABLE" ( TheSourceFileID, TheTargetFileID, TheSourceAddress, TheTargetAddress )"

#define UNIDENTIFIED_BLOCKS_TABLE "UnidentifiedBlocks"
#define CREATE_UNIDENTIFIED_BLOCKS_TABLE_STATEMENT "CREATE TABLE "UNIDENTIFIED_BLOCKS_TABLE" ( \n\
			id INTEGER PRIMARY KEY AUTOINCREMENT, \n\
			OldFileID INTEGER, \n\
			NewFileID INTEGER, \n\
			Type INTEGER, \n\
			Address INTEGER\n\
		 );"
#define INSERT_UNIDENTIFIED_BLOCKS_TABLE_STATEMENT "INSERT INTO  "UNIDENTIFIED_BLOCKS_TABLE" ( Type, Address ) values ( '%u', '%u' );"

#define FUNCTION_MATCH_INFO_TABLE "FunctionMatchInfo"
#define CREATE_FUNCTION_MATCH_INFO_TABLE_STATEMENT "CREATE TABLE " FUNCTION_MATCH_INFO_TABLE" ( \n\
			id INTEGER PRIMARY KEY AUTOINCREMENT, \n\
			TheSourceFileID INTEGER, \n\
			TheTargetFileID INTEGER, \n\
			TheSourceAddress INTEGER, \n\
			EndAddress INTEGER, \n\
			TheTargetAddress INTEGER, \n\
			BlockType INTEGER, \n\
			MatchRate INTEGER, \n\
			TheSourceFunctionName TEXT, \n\
			Type INTEGER, \n\
			TheTargetFunctionName TEXT, \n\
			MatchCountForTheSource INTEGER, \n\
			NoneMatchCountForTheSource INTEGER, \n\
			MatchCountWithModificationForTheSource INTEGER, \n\
			MatchCountForTheTarget INTEGER, \n\
			NoneMatchCountForTheTarget INTEGER, \n\
			MatchCountWithModificationForTheTarget INTEGER\n\
		 );"
#define INSERT_FUNCTION_MATCH_INFO_TABLE_STATEMENT "INSERT INTO  " FUNCTION_MATCH_INFO_TABLE" ( TheSourceFileID, TheTargetFileID, TheSourceAddress, EndAddress, TheTargetAddress, BlockType, MatchRate, TheSourceFunctionName, Type, TheTargetFunctionName, MatchCountForTheSource, NoneMatchCountForTheSource, MatchCountWithModificationForTheSource, MatchCountForTheTarget, NoneMatchCountForTheTarget, MatchCountWithModificationForTheTarget ) values ( '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%s', '%u', '%s', '%u', '%u', '%u', '%u', '%u', '%u' );"
#define DELETE_FUNCTION_MATCH_INFO_TABLE_STATEMENT "DELETE FROM "FUNCTION_MATCH_INFO_TABLE" WHERE TheSourceFileID=%u and TheTargetFileID=%u"
#define CREATE_FUNCTION_MATCH_INFO_TABLE_INDEX_STATEMENT "CREATE INDEX "FUNCTION_MATCH_INFO_TABLE"Index ON "FUNCTION_MATCH_INFO_TABLE" ( TheSourceFileID, TheTargetFileID, TheSourceAddress, TheTargetAddress )"

enum {TYPE_MATCH, TYPE_REVERSE_MATCH, TYPE_BEFORE_UNIDENTIFIED_BLOCK, TYPE_AFTER_UNIDENTIFIED_BLOCK};

typedef struct _AnalysisResult_ {
	multimap <DWORD, MatchData> MatchMap;
	hash_map <DWORD, DWORD> ReverseAddressMap;
} AnalysisResult;

#define DEBUG_FUNCTION_LEVEL_MATCH_OPTIMIZING 1

class DiffMachine
{
private:
	int DebugFlag;
	DBWrapper *m_InputDB;
	int m_TheSourceFileID;
	int m_TheTargetFileID;

	DWORD SourceFunctionAddress;
	DWORD TargetFunctionAddress;

	multimap <DWORD, DWORD> *FunctionMembersMapForTheSource;
	multimap <DWORD, DWORD> *FunctionMembersMapForTheTarget;
	multimap <DWORD, DWORD> *AddressToFunctionMapForTheSource;<commit_msg>Added SecurityImplicationsScore field to FunctionMatchInfo table<commit_after>#pragma once
#include <vector>
#include <hash_set>
#include <list>

#include "Common.h"
#include "OneIDAClientManager.h"
#include "DataStructure.h"
#include "LogOperation.h"

const enum {DiffMachineFileBinaryFormat, DiffMachineFileSQLiteFormat};

#define MATCH_MAP_TABLE "MatchMap"
#define CREATE_MATCH_MAP_TABLE_STATEMENT "CREATE TABLE " MATCH_MAP_TABLE" ( \n\
			id INTEGER PRIMARY KEY AUTOINCREMENT, \n\
			TheSourceFileID INTEGER, \n\
			TheTargetFileID INTEGER, \n\
			TheSourceAddress INTEGER, \n\
			TheTargetAddress INTEGER, \n\
			MatchType INTEGER, \n\
			Type INTEGER, \n\
			SubType INTEGER, \n\
			Status INTEGER, \n\
			MatchRate INTEGER, \n\
			UnpatchedParentAddress INTEGER, \n\
			PatchedParentAddress INTEGER\n\
		 );"
#define INSERT_MATCH_MAP_TABLE_STATEMENT "INSERT INTO  "MATCH_MAP_TABLE" ( TheSourceFileID, TheTargetFileID, TheSourceAddress, TheTargetAddress, MatchType, Type, SubType, Status, MatchRate, UnpatchedParentAddress, PatchedParentAddress ) values ( '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u' );"
#define DELETE_MATCH_MAP_TABLE_STATEMENT "DELETE FROM "MATCH_MAP_TABLE" WHERE TheSourceFileID=%u and TheTargetFileID=%u"
#define CREATE_MATCH_MAP_TABLE_INDEX_STATEMENT "CREATE INDEX "MATCH_MAP_TABLE"Index ON "MATCH_MAP_TABLE" ( TheSourceFileID, TheTargetFileID, TheSourceAddress, TheTargetAddress )"

#define UNIDENTIFIED_BLOCKS_TABLE "UnidentifiedBlocks"
#define CREATE_UNIDENTIFIED_BLOCKS_TABLE_STATEMENT "CREATE TABLE "UNIDENTIFIED_BLOCKS_TABLE" ( \n\
			id INTEGER PRIMARY KEY AUTOINCREMENT, \n\
			OldFileID INTEGER, \n\
			NewFileID INTEGER, \n\
			Type INTEGER, \n\
			Address INTEGER\n\
		 );"
#define INSERT_UNIDENTIFIED_BLOCKS_TABLE_STATEMENT "INSERT INTO  "UNIDENTIFIED_BLOCKS_TABLE" ( Type, Address ) values ( '%u', '%u' );"

#define FUNCTION_MATCH_INFO_TABLE "FunctionMatchInfo"
#define CREATE_FUNCTION_MATCH_INFO_TABLE_STATEMENT "CREATE TABLE " FUNCTION_MATCH_INFO_TABLE" ( \n\
			id INTEGER PRIMARY KEY AUTOINCREMENT, \n\
			TheSourceFileID INTEGER, \n\
			TheTargetFileID INTEGER, \n\
			TheSourceAddress INTEGER, \n\
			EndAddress INTEGER, \n\
			TheTargetAddress INTEGER, \n\
			BlockType INTEGER, \n\
			MatchRate INTEGER, \n\
			TheSourceFunctionName TEXT, \n\
			Type INTEGER, \n\
			TheTargetFunctionName TEXT, \n\
			MatchCountForTheSource INTEGER, \n\
			NoneMatchCountForTheSource INTEGER, \n\
			MatchCountWithModificationForTheSource INTEGER, \n\
			MatchCountForTheTarget INTEGER, \n\
			NoneMatchCountForTheTarget INTEGER, \n\
			MatchCountWithModificationForTheTarget INTEGER, \n\
			SecurityImplicationsScore INTEGER \n\
		 );"
#define INSERT_FUNCTION_MATCH_INFO_TABLE_STATEMENT "INSERT INTO  " FUNCTION_MATCH_INFO_TABLE" ( TheSourceFileID, TheTargetFileID, TheSourceAddress, EndAddress, TheTargetAddress, BlockType, MatchRate, TheSourceFunctionName, Type, TheTargetFunctionName, MatchCountForTheSource, NoneMatchCountForTheSource, MatchCountWithModificationForTheSource, MatchCountForTheTarget, NoneMatchCountForTheTarget, MatchCountWithModificationForTheTarget ) values ( '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%s', '%u', '%s', '%u', '%u', '%u', '%u', '%u', '%u' );"
#define DELETE_FUNCTION_MATCH_INFO_TABLE_STATEMENT "DELETE FROM "FUNCTION_MATCH_INFO_TABLE" WHERE TheSourceFileID=%u and TheTargetFileID=%u"
#define CREATE_FUNCTION_MATCH_INFO_TABLE_INDEX_STATEMENT "CREATE INDEX "FUNCTION_MATCH_INFO_TABLE"Index ON "FUNCTION_MATCH_INFO_TABLE" ( TheSourceFileID, TheTargetFileID, TheSourceAddress, TheTargetAddress )"

enum {TYPE_MATCH, TYPE_REVERSE_MATCH, TYPE_BEFORE_UNIDENTIFIED_BLOCK, TYPE_AFTER_UNIDENTIFIED_BLOCK};

typedef struct _AnalysisResult_ {
	multimap <DWORD, MatchData> MatchMap;
	hash_map <DWORD, DWORD> ReverseAddressMap;
} AnalysisResult;

#define DEBUG_FUNCTION_LEVEL_MATCH_OPTIMIZING 1

class DiffMachine
{
private:
	int DebugFlag;
	DBWrapper *m_InputDB;
	int m_TheSourceFileID;
	int m_TheTargetFileID;

	DWORD SourceFunctionAddress;
	DWORD TargetFunctionAddress;

	multimap <DWORD, DWORD> *FunctionMembersMapForTheSource;
	multimap <DWORD, DWORD> *FunctionMembersMapForTheTarget;
	multimap <DWORD, DWORD> *AddressToFunctionMapForTheSource;
{'fraction_non_alphanumeric': 0.10179425837320574, 'fraction_numerical': 0.00023923444976076556, 'mean_word_length': 6.379523389232127, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5189537', 'n_tokens_mistral': 3100, 'n_tokens_neox': 2716, 'n_words': 644}