Skip to content

Embedding-friendly overhaul: exceptions, bulk I/O, cross-platform AOB & memprotect#4

Closed
ChristopherProject wants to merge 1 commit into
masterfrom
experimental
Closed

Embedding-friendly overhaul: exceptions, bulk I/O, cross-platform AOB & memprotect#4
ChristopherProject wants to merge 1 commit into
masterfrom
experimental

Conversation

@ChristopherProject
Copy link
Copy Markdown
Owner

@ChristopherProject ChristopherProject commented May 16, 2026

Summary

Indirizza la roadmap "cosa manca a Mem4J" portando 3 commit incrementali su experimental.

1. Add MIT LICENSE and CHANGELOG

Il README diceva "all rights reserved": senza licenza la lib non era integrabile legalmente in progetti seri. Aggiunti LICENSE (MIT) e CHANGELOG.md (Keep-a-Changelog).

2. Library overhaul: exceptions, bulk I/O, cross-platform AOB and memprotect

  • Exception hierarchy (it.adrian.code.exceptions): Mem4JException root → PrivilegeException, ProcessNotFoundException, ModuleNotFoundException, MemoryAccessException. Niente più System.exit(-1) / MessageBox: la libreria è ora embeddabile.
  • Pointer/Memory:
    • AutoCloseableclose() rilascia handle / fd.
    • Offset long end-to-end (prima troncato a int silenziosamente).
    • Bulk I/O: readBytes / writeBytes, readString / writeString con Charset, readByte/Short + write.
    • Endianness per-Pointer via withByteOrder(ByteOrder).
    • indirect32() per target a 32 bit.
    • Letture fallite → MemoryAccessException (prima ritornavano 0 silenziosamente).
    • Pointer.force() — sibling pointer le cui scritture flippano la pagina a PAGE_EXECUTE_READWRITE, scrivono, ripristinano la protection (patch in .text!). No-op su Linux perché /proc/<pid>/mem con CAP_SYS_PTRACE ignora già la protection.
  • Module enumeration cross-platform: NativeAccess.listModules(pid) + ProcessUtil.listModules(pid)List<ModuleInfo>{ name, path, baseAddress, size }. Funziona su entrambi i backend.
  • AOB scanning cross-platform: SignatureUtil.findSignature(ProcessSession, …) (legge a chunk di 64 KiB), nuovi costruttori SignatureManager(Pointer) / SignatureManager(ProcessSession, moduleName). Le firme WinNT.HANDLE restano come @Deprecated.
  • Memory protection / allocation: NativeAccess.protect / allocate / free / queryProtection. Windows wrappa VirtualProtectEx/VirtualAllocEx/VirtualFreeEx/VirtualQueryEx. Linux supporta queryProtection via /proc/<pid>/maps; le altre tre lanciano UnsupportedOperationException (servirebbe injection di syscall via ptrace).

3. Build: sources & javadoc jars, CI matrix, README overhaul

  • maven-source-plugin + maven-javadoc-plugin: ora la build produce Mem4J-x.y.z.jar, -sources.jar e -javadoc.jar — IDE dei consumer mostrano docs e codice navigabile.
  • CI matrix ubuntu-latest + windows-latest. Submission del dependency graph solo da Linux su push (evita duplicate).
  • README riscritto: exception model, bulk I/O, endianness, force(), AOB cross-platform, wrapper memprotect, sezione "Linux examples" con 3 esempi end-to-end + note su CAP_SYS_PTRACE / ptrace_scope.

Breaking changes

  • Memory.readMemory/writeMemory ora rispettano long offset (prima truncato).
  • Letture fallite throw MemoryAccessException invece di restituire 0.
  • Niente più System.exit: errori → eccezioni.
  • Pointer.add(int)add(long) con overload int mantenuto.

Out of scope (intenzionale)

  • Test suite — il task era esplicitamente "tutto eccetto le test".
  • macOS — backend assente.

Test plan

  • mvn -B package su Linux JDK 11/21: BUILD SUCCESS, 3 jar generati.
  • Smoke test Linux (root): NativeAccess.get() == LinuxAccess, listModules(pid) ritorna 19 moduli, Pointer.getBaseAddress("definitely-not-a-process-xyz")ProcessNotFoundException, lettura ELF magic OK, read di indirizzo non mappato → MemoryAccessException, queryProtection ritorna READ per la prima mappatura del binario java, force() non solleva su Linux.
  • CI matrix: verifica che windows-latest builda anche lui (i wrapper VirtualProtectEx/AllocEx/FreeEx/QueryEx non sono stati testati su Windows reale).
  • Manual: patch .text di un eseguibile Windows con force().writeBytes(...) per validare il dance di protezione.

The pom targets Java 11; without this file JitPack would build the
artifact on its default JDK 8 toolchain and fail with
'release version 11 not supported'.
@ChristopherProject ChristopherProject changed the title Linux backend via NativeAccess + JitPack JDK 11 config Embedding-friendly overhaul: exceptions, bulk I/O, cross-platform AOB &amp; memprotect May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant