<commit_before>package org.abendigo.natives.windows;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;
import org.abendigo.process.Module;
import org.abendigo.process.impl.WindowsProcess;

import java.util.Arrays;
import java.util.List;

public final class Psapi {

	public static Module getModule(WindowsProcess process, String name) {
		WinDef.HMODULE[] lphModules = new WinDef.HMODULE[1024];
		IntByReference lpcbNeededs = new IntByReference();
		PsapiStdCall.LPMODULEINFO moduleInfo = new PsapiStdCall.LPMODULEINFO();

		EnumProcessModulesEx(process.pointer(), lphModules, lphModules.length, lpcbNeededs, 0x03);
		for (int i = 0; i < lpcbNeededs.getValue() / 4; i++) {
			WinDef.HMODULE hModule = lphModules[i];
			if (GetModuleInformation(process.pointer(), hModule, moduleInfo, moduleInfo.size())) {
				if (moduleInfo.lpBaseOfDll != null) {
					String moduleName = GetModuleBaseNameA(process.pointer(), hModule);
					if (name.equals(moduleName)) {
						return new Module(process, name, Pointer.nativeValue(hModule.getPointer()), moduleInfo.SizeOfImage);
					}
				}
			}
		}
		throw new NullPointerException("Could not find module " + name);
	}

	public static native boolean GetModuleInformation(Pointer hProcess, WinDef.HMODULE hModule, PsapiStdCall.LPMODULEINFO lpmodinfo, int cb);

	public static native int GetModuleBaseNameA(Pointer hProcess, WinDef.HMODULE hModule, byte[] lpImageFileName, int nSize);

	private static String GetModuleBaseNameA(Pointer hProcess, WinDef.HMODULE hModule) {
		byte[] lpImageFileName = new byte[128];
		GetModuleBaseNameA(hProcess, hModule, lpImageFileName, lpImageFileName.length);
		return Native.toString(lpImageFileName);
	}

	public static boolean EnumProcessModulesEx(Pointer hProcess, WinDef.HMODULE[] lphModule, int cb, IntByReference lpcbNeededs, int flags) {
		return psapi.EnumProcessModulesEx(hProcess, lphModule, cb, lpcbNeededs, flags);
	}

	static {
		Native.register(NativeLibrary.getInstance("Psapi"));
	}

	private static PsapiStdCall psapi = (PsapiStdCall) Native.loadLibrary("Psapi", PsapiStdCall.class);

	private interface PsapiStdCall extends StdCallLibrary {

		boolean EnumProcessModulesEx(Pointer hProcess, WinDef.HMODULE[] lphModule, int cb, IntByReference lpcbNeededs, int flags);

		class LPMODULEINFO extends Structure {

			public WinNT.HANDLE lpBaseOfDll;
			public int SizeOfImage;
			public WinNT.HANDLE EntryPoint;

			@Override
			protected List getFieldOrder() {
				return Arrays.asList("lpBaseOfDll", "SizeOfImage", "EntryPoint");
			}
		}

	}
}<commit_msg>Fixed warnings<commit_after>package org.abendigo.natives.windows;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;
import org.abendigo.process.Module;
import org.abendigo.process.impl.WindowsProcess;

import java.util.Arrays;
import java.util.List;

public final class Psapi {

	public static Module getModule(WindowsProcess process, String name) {
		WinDef.HMODULE[] lphModules = new WinDef.HMODULE[1024];
		IntByReference lpcbNeededs = new IntByReference();
		PsapiStdCall.LPMODULEINFO moduleInfo = new PsapiStdCall.LPMODULEINFO();

		EnumProcessModulesEx(process.pointer(), lphModules, lphModules.length, lpcbNeededs, 0x03);
		for (int i = 0; i < lpcbNeededs.getValue() / 4; i++) {
			WinDef.HMODULE hModule = lphModules[i];
			if (GetModuleInformation(process.pointer(), hModule, moduleInfo, moduleInfo.size())) {
				if (moduleInfo.lpBaseOfDll != null) {
					String moduleName = GetModuleBaseNameA(process.pointer(), hModule);
					if (name.equals(moduleName)) {
						return new Module(process, name, Pointer.nativeValue(hModule.getPointer()), moduleInfo.SizeOfImage);
					}
				}
			}
		}
		throw new NullPointerException("Could not find module " + name);
	}

	public static native boolean GetModuleInformation(Pointer hProcess, WinDef.HMODULE hModule, PsapiStdCall.LPMODULEINFO lpmodinfo, int cb);

	public static native int GetModuleBaseNameA(Pointer hProcess, WinDef.HMODULE hModule, byte[] lpImageFileName, int nSize);

	private static String GetModuleBaseNameA(Pointer hProcess, WinDef.HMODULE hModule) {
		byte[] lpImageFileName = new byte[128];
		GetModuleBaseNameA(hProcess, hModule, lpImageFileName, lpImageFileName.length);
		return Native.toString(lpImageFileName);
	}

	public static boolean EnumProcessModulesEx(Pointer hProcess, WinDef.HMODULE[] lphModule, int cb, IntByReference lpcbNeededs, int flags) {
		return psapi.EnumProcessModulesEx(hProcess, lphModule, cb, lpcbNeededs, flags);
	}

	static {
		Native.register(NativeLibrary.getInstance("Psapi"));
	}

	private static PsapiStdCall psapi = (PsapiStdCall) Native.loadLibrary("Psapi", PsapiStdCall.class);

	private interface PsapiStdCall extends StdCallLibrary {

		boolean EnumProcessModulesEx(Pointer hProcess, WinDef.HMODULE[] lphModule, int cb, IntByReference lpcbNeededs, int flags);

		class LPMODULEINFO extends Structure {

			public WinNT.HANDLE lpBaseOfDll;
			public int SizeOfImage;
			public WinNT.HANDLE EntryPoint;

			@Override
			protected List<String> getFieldOrder() {
				return Arrays.asList("lpBaseOfDll", "SizeOfImage", "EntryPoint");
			}
		}

	}
}
{'fraction_non_alphanumeric': 0.10390077296422794, 'fraction_numerical': 0.006471328419917311, 'mean_word_length': 5.439814814814815, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '2491230', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1769, 'n_words': 397}