All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.bloodshura.ignitium.ntv.process.Module Maven / Gradle / Ivy

The newest version!
package com.github.bloodshura.ignitium.ntv.process;

import com.github.bloodshura.ignitium.ntv.NativeException;
import com.github.bloodshura.ignitium.ntv.source.SizedDataSource;
import com.github.bloodshura.ignitium.ntv.util.Buffer;
import com.github.bloodshura.ignitium.ntv.util.RangeUtils;

import javax.annotation.Nonnull;

public final class Module implements SizedDataSource {
	private final long address;
	private final String name;
	private final NativeProcess process;
	private final int size;

	public Module(@Nonnull NativeProcess process, @Nonnull String name, long address, int size) {
		this.address = address;
		this.name = name;
		this.process = process;
		this.size = size;
	}

	public long getAddress() {
		return address;
	}

	@Nonnull
	public String getName() {
		return name;
	}

	@Nonnull
	public NativeProcess getProcess() {
		return process;
	}

	@Override
	public int getSize() {
		return size;
	}

	@Override
	public boolean isReadable(long address, int size) throws NativeException {
		return RangeUtils.validateRange(address, size, getSize()) && getProcess().isReadable(getAddress() + address, size);
	}

	@Override
	public boolean isWritable(long address, int size) throws NativeException {
		return RangeUtils.validateRange(address, size, getSize()) && getProcess().isWritable(getAddress() + address, size);
	}

	@Override
	public void read(long address, @Nonnull Buffer buffer, int size) throws NativeException {
		RangeUtils.checkRange(address, size, (int) buffer.size());
		RangeUtils.checkRange(address, size, getSize());
		getProcess().read(getAddress() + address, buffer, size);
	}

	@Override
	public void write(long address, @Nonnull Buffer buffer) throws NativeException {
		RangeUtils.checkRange(address, (int) buffer.size(), getSize());
		getProcess().write(getAddress() + address, buffer);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy