Add initial AccessWidener

This commit is contained in:
2026-06-11 12:22:44 +02:00
parent e176b3bca8
commit 786257ad0e
15 changed files with 979 additions and 6 deletions
@@ -0,0 +1,67 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar;
import java.lang.instrument.Instrumentation;
import java.util.logging.Logger;
/**
* Java agent entry point.
*
* Can be used two ways:
* 1. At JVM startup: java -javaagent:paper-access-widener-agent.jar -jar server.jar
* 2. Late attach: from inside a Paper plugin via the Attach API
*
* On attach the agent:
* 1. Scans all existing plugin ClassLoaders for "plugin.accesswidener" resources
* 2. Registers a ClassFileTransformer that:
* a. Applies widening to every class as it loads
* b. Detects new plugin ClassLoaders and scans them automatically
* 3. Retransforms any Minecraft/server classes that are already loaded
*/
public class Agent {
private Agent() {
/* This utility class should not be instantiated */
}
private static final Logger LOG = Logger.getLogger("AccessWidenerAgent");
// Exposed so tests or other code can inspect the live transformer
static volatile WideningTransformer transformer;
// -javaagent: startup
public static void premain(String args, Instrumentation inst) {
init(inst);
}
private static void init(Instrumentation inst) {
LOG.info("[AccessWidener] Agent initialising.");
WideningTransformer t = new WideningTransformer(inst);
transformer = t;
// --- Phase 2: register transformer for future class loads ---
// canRetransform=true so we can call retransformClasses() later
inst.addTransformer(t, true);
LOG.info("[AccessWidener] Agent ready.");
}
}