il2cpp-dump-analyzer-mcp
Version:
Agentic RAG system for analyzing IL2CPP dump.cs files from Unity games
163 lines • 5.47 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.HashManager = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const crypto = __importStar(require("crypto"));
/**
* Manages file hashes to prevent duplicate processing of dump.cs files
*/
class HashManager {
constructor(hashFilePath) {
// Default to storing hashes in a .processed_dumps file in the current directory
this.hashFilePath = hashFilePath || path.join(process.cwd(), '.processed_dumps');
this.processedHashes = new Set();
this.loadHashes();
}
/**
* Calculate SHA-256 hash of a file
* @param filePath Path to the file
* @returns SHA-256 hash as hex string
*/
calculateFileHash(filePath) {
const fileBuffer = fs.readFileSync(filePath);
const hashSum = crypto.createHash('sha256');
hashSum.update(fileBuffer);
return hashSum.digest('hex');
}
/**
* Check if a file has already been processed
* @param filePath Path to the dump.cs file
* @returns true if file was already processed, false otherwise
*/
isFileProcessed(filePath) {
const hash = this.calculateFileHash(filePath);
return this.processedHashes.has(hash);
}
/**
* Mark a file as processed by storing its hash
* @param filePath Path to the dump.cs file
* @returns The hash that was stored
*/
markFileAsProcessed(filePath) {
const hash = this.calculateFileHash(filePath);
this.processedHashes.add(hash);
this.saveHashes();
return hash;
}
/**
* Get the hash of a file without marking it as processed
* @param filePath Path to the dump.cs file
* @returns The SHA-256 hash of the file
*/
getFileHash(filePath) {
return this.calculateFileHash(filePath);
}
/**
* Remove a hash from the processed list (useful for reprocessing)
* @param filePath Path to the dump.cs file
* @returns true if hash was removed, false if it wasn't found
*/
removeFileHash(filePath) {
const hash = this.calculateFileHash(filePath);
const wasRemoved = this.processedHashes.delete(hash);
if (wasRemoved) {
this.saveHashes();
}
return wasRemoved;
}
/**
* Clear all processed hashes
*/
clearAllHashes() {
this.processedHashes.clear();
this.saveHashes();
}
/**
* Get all processed hashes
* @returns Array of all stored hashes
*/
getAllHashes() {
return Array.from(this.processedHashes);
}
/**
* Get the number of processed files
* @returns Count of processed files
*/
getProcessedCount() {
return this.processedHashes.size;
}
/**
* Load hashes from the storage file
*/
loadHashes() {
try {
if (fs.existsSync(this.hashFilePath)) {
const content = fs.readFileSync(this.hashFilePath, 'utf8');
const hashes = content.split('\n').filter(line => line.trim() !== '');
this.processedHashes = new Set(hashes);
}
}
catch (error) {
console.warn(`Warning: Could not load hash file ${this.hashFilePath}:`, error);
this.processedHashes = new Set();
}
}
/**
* Save hashes to the storage file
*/
saveHashes() {
try {
const content = Array.from(this.processedHashes).join('\n');
fs.writeFileSync(this.hashFilePath, content, 'utf8');
}
catch (error) {
console.error(`Error: Could not save hash file ${this.hashFilePath}:`, error);
}
}
/**
* Get information about the hash storage
* @returns Object with hash file path and count
*/
getInfo() {
return {
hashFilePath: this.hashFilePath,
processedCount: this.getProcessedCount()
};
}
}
exports.HashManager = HashManager;
//# sourceMappingURL=hash-manager.js.map