<commit_before>// Scans for patterns in specific modules code section.
function scan(name, sig) {
    if (sig == undefined) {
        sig = name;
        name = 'client.exe';
    }

    var ranges = Module.enumerateRangesSync(name, 'r-x');
    
    var address = NULL;

    for (var i = 0; i < ranges.length; ++i) {
        var range = ranges[i];
        var results = Memory.scanSync(range.base, range.size, sig);

        if (results.length > 0) {
            address = results[0].address;
            break;
        }
    }

    if (debug)
        send(address);

    return address;
}

// Just adds an offset to the base address of a module.
function moduleOffset(moduleName, offset) {
    var baseAddress = Module.findBaseAddress(moduleName);

    if (baseAddress.isNull()) {
        return NULL;
    }

    return baseAddress.add(offset);
}

// Patches a byte.
function patch(addr, c) {
    if (!testing) {
        Memory.protect(addr, 4096, 'rwx');
        Memory.writeU8(addr, c);
        Memory.protect(addr, 4096, 'r-x');
    }
}

// Writes a string to allocated memory.  Make sure theres enough room at the 
// address for str.length + 1 (for the trailing zero).
function writeStr(address, str) {
    for (var i = 0; i < str.length; ++i) {
        Memory.writeS8(address.add(i), str.charCodeAt(i)); 
    }

    Memory.writeU8(address.add(str.length), 0);
}

// Gets the address of an exported function.
function getProcAddress(moduleName, funcName) {
    return Module.findExportByName(moduleName, funcName);
}

// Allocates some memory.
var VirtualAlloc = new NativeFunction(getProcAddress('Kernel32.dll', 'VirtualAlloc'), 
        'pointer', ['pointer', 'ulong', 'uint32', 'uint32'], 'stdcall');

function allocateMemory(len) {
    // 0x3000 = MEM_COMMIT | MEM_RESERVE
    // 0x40 = PAGE_EXECUTE_READWRITE
    return VirtualAlloc(NULL, len, 0x3000, 0x40);
}

// Frees memory allocated with allocateMemory.
var VirtualFree = new NativeFunction(getProcAddress('Kernel32.dll', 'VirtualFree'),<commit_msg>Allow patching an array of bytes<commit_after>// Scans for patterns in specific modules code section.
function scan(name, sig) {
    if (sig == undefined) {
        sig = name;
        name = 'client.exe';
    }

    var ranges = Module.enumerateRangesSync(name, 'r-x');
    
    var address = NULL;

    for (var i = 0; i < ranges.length; ++i) {
        var range = ranges[i];
        var results = Memory.scanSync(range.base, range.size, sig);

        if (results.length > 0) {
            address = results[0].address;
            break;
        }
    }

    if (debug)
        send(address);

    return address;
}

// Just adds an offset to the base address of a module.
function moduleOffset(moduleName, offset) {
    var baseAddress = Module.findBaseAddress(moduleName);

    if (baseAddress.isNull()) {
        return NULL;
    }

    return baseAddress.add(offset);
}

// Patches an array of bytes.
function patch(addr, c) {
    if (!testing) {
		if (!Array.isArray(c))
			c = [c];
		
		Memory.protect(addr, c.length, 'rwx');
		for (var i = 0; i < c.length; ++i)
			if (c[i] >= 0 && c[i] <= 0xFF)
				Memory.writeU8(addr.add(i), c[i]);
        Memory.protect(addr, c.length, 'r-x');
    }
}

// Writes a string to allocated memory.  Make sure theres enough room at the 
// address for str.length + 1 (for the trailing zero).
function writeStr(address, str) {
    for (var i = 0; i < str.length; ++i) {
        Memory.writeS8(address.add(i), str.charCodeAt(i)); 
    }

    Memory.writeU8(address.add(str.length), 0);
}

// Gets the address of an exported function.
function getProcAddress(moduleName, funcName) {
    return Module.findExportByName(moduleName, funcName);
}

// Allocates some memory.
var VirtualAlloc = new NativeFunction(getProcAddress('Kernel32.dll', 'VirtualAlloc'), 
        'pointer', ['pointer', 'ulong', 'uint32', 'uint32'], 'stdcall');

function allocateMemory(len) {
    // 0x3000 = MEM_COMMIT | MEM_RESERVE
    // 0x40 = PAGE_EXECUTE_READWRITE
    return VirtualAlloc(NULL, len, 0x3000, 0x40);
}

// Frees memory allocated with allocateMemory.
var VirtualFree = new NativeFunction(getProcAddress('Kernel32.dll', 'VirtualFree'),
{'fraction_non_alphanumeric': 0.13454632511371797, 'fraction_numerical': 0.01843428297821403, 'mean_word_length': 2.8901303538175047, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, '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': '3263567', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1323, 'n_words': 372}