forked from MirrorHub/authlib-injector
Friendly log messages
This commit is contained in:
parent
d86d99c547
commit
6a25aaeffa
6 changed files with 40 additions and 40 deletions
|
@ -68,17 +68,17 @@ public final class AuthlibInjector {
|
||||||
|
|
||||||
public static void bootstrap(Consumer<ClassFileTransformer> transformerRegistry) {
|
public static void bootstrap(Consumer<ClassFileTransformer> transformerRegistry) {
|
||||||
if (!booted.compareAndSet(false, true)) {
|
if (!booted.compareAndSet(false, true)) {
|
||||||
Logging.LAUNCH.info("already booted, skipping");
|
Logging.LAUNCH.info("Already started, skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.LAUNCH.info("version: " + getVersion());
|
Logging.LAUNCH.info("Version: " + getVersion());
|
||||||
|
|
||||||
Optional<YggdrasilConfiguration> optionalConfig = configure();
|
Optional<YggdrasilConfiguration> optionalConfig = configure();
|
||||||
if (optionalConfig.isPresent()) {
|
if (optionalConfig.isPresent()) {
|
||||||
transformerRegistry.accept(createTransformer(optionalConfig.get()));
|
transformerRegistry.accept(createTransformer(optionalConfig.get()));
|
||||||
} else {
|
} else {
|
||||||
Logging.LAUNCH.warning("no config available");
|
Logging.LAUNCH.warning("No config available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public final class AuthlibInjector {
|
||||||
if (prefetched == null) {
|
if (prefetched == null) {
|
||||||
prefetched = System.getProperty(PROP_PREFETCHED_DATA_OLD);
|
prefetched = System.getProperty(PROP_PREFETCHED_DATA_OLD);
|
||||||
if (prefetched != null) {
|
if (prefetched != null) {
|
||||||
Logging.LAUNCH.warning("org.to2mbn.authlibinjector.config.prefetched option is deprecated and will be removed in a future release.");
|
Logging.LAUNCH.warning(PROP_PREFETCHED_DATA_OLD + " option is deprecated, please use " + PROP_PREFETCHED_DATA + " instead");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Optional.ofNullable(prefetched);
|
return Optional.ofNullable(prefetched);
|
||||||
|
@ -96,44 +96,44 @@ public final class AuthlibInjector {
|
||||||
private static Optional<YggdrasilConfiguration> configure() {
|
private static Optional<YggdrasilConfiguration> configure() {
|
||||||
String apiRoot = System.getProperty(PROP_API_ROOT);
|
String apiRoot = System.getProperty(PROP_API_ROOT);
|
||||||
if (apiRoot == null) return empty();
|
if (apiRoot == null) return empty();
|
||||||
Logging.CONFIG.info("api root: " + apiRoot);
|
Logging.CONFIG.info("API root: " + apiRoot);
|
||||||
|
|
||||||
String metadataResponse;
|
String metadataResponse;
|
||||||
|
|
||||||
Optional<String> prefetched = getPrefetchedResponse();
|
Optional<String> prefetched = getPrefetchedResponse();
|
||||||
if (!prefetched.isPresent()) {
|
if (!prefetched.isPresent()) {
|
||||||
Logging.CONFIG.info("fetching metadata");
|
Logging.CONFIG.info("Fetching metadata");
|
||||||
try {
|
try {
|
||||||
metadataResponse = asString(getURL(apiRoot));
|
metadataResponse = asString(getURL(apiRoot));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Logging.CONFIG.severe("unable to fetch metadata: " + e);
|
Logging.CONFIG.severe("Failed to fetch metadata: " + e);
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Logging.CONFIG.info("prefetched metadata detected");
|
Logging.CONFIG.info("Prefetched metadata detected");
|
||||||
try {
|
try {
|
||||||
metadataResponse = new String(Base64.getDecoder().decode(removeNewLines(prefetched.get())), UTF_8);
|
metadataResponse = new String(Base64.getDecoder().decode(removeNewLines(prefetched.get())), UTF_8);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Logging.CONFIG.severe("unable to decode metadata: " + e + "\n"
|
Logging.CONFIG.severe("Unable to decode metadata: " + e + "\n"
|
||||||
+ "metadata to decode:\n"
|
+ "Encoded metadata:\n"
|
||||||
+ prefetched.get());
|
+ prefetched.get());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.CONFIG.fine("metadata: " + metadataResponse);
|
Logging.CONFIG.fine("Metadata: " + metadataResponse);
|
||||||
|
|
||||||
YggdrasilConfiguration configuration;
|
YggdrasilConfiguration configuration;
|
||||||
try {
|
try {
|
||||||
configuration = YggdrasilConfiguration.parse(apiRoot, metadataResponse);
|
configuration = YggdrasilConfiguration.parse(apiRoot, metadataResponse);
|
||||||
} catch (UncheckedIOException e) {
|
} catch (UncheckedIOException e) {
|
||||||
Logging.CONFIG.severe("unable to parse metadata: " + e + "\n"
|
Logging.CONFIG.severe("Unable to parse metadata: " + e + "\n"
|
||||||
+ "metadata to parse:\n"
|
+ "Raw metadata:\n"
|
||||||
+ metadataResponse);
|
+ metadataResponse);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
Logging.CONFIG.fine("parsed metadata: " + configuration);
|
Logging.CONFIG.fine("Parsed metadata: " + configuration);
|
||||||
return of(configuration);
|
return of(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,14 @@ public class LocalYggdrasilHandle {
|
||||||
if (started)
|
if (started)
|
||||||
return;
|
return;
|
||||||
if (configuration == null)
|
if (configuration == null)
|
||||||
throw new IllegalStateException("configuration hasn't been set yet");
|
throw new IllegalStateException("Configuration hasn't been set yet");
|
||||||
httpd = new LocalYggdrasilHttpd(0, configuration);
|
httpd = new LocalYggdrasilHttpd(0, configuration);
|
||||||
try {
|
try {
|
||||||
httpd.start();
|
httpd.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalStateException("httpd failed to start");
|
throw new IllegalStateException("Httpd failed to start");
|
||||||
}
|
}
|
||||||
Logging.HTTPD.info("httpd is running on port " + getLocalApiPort());
|
Logging.HTTPD.info("Httpd is running on port " + getLocalApiPort());
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,25 +61,25 @@ public class LocalYggdrasilHttpd extends NanoHTTPD {
|
||||||
.map(encoded -> asString(Base64.getDecoder().decode(encoded)))
|
.map(encoded -> asString(Base64.getDecoder().decode(encoded)))
|
||||||
.flatMap(texturesPayload -> obtainTextureUrl(texturesPayload, "SKIN"));
|
.flatMap(texturesPayload -> obtainTextureUrl(texturesPayload, "SKIN"));
|
||||||
} catch (UncheckedIOException e) {
|
} catch (UncheckedIOException e) {
|
||||||
Logging.HTTPD.log(Level.WARNING, "unable to fetch skin for " + username, e);
|
Logging.HTTPD.log(Level.WARNING, "Failed to fetch skin for " + username, e);
|
||||||
return of(newFixedLengthResponse(Status.INTERNAL_ERROR, null, null));
|
return of(newFixedLengthResponse(Status.INTERNAL_ERROR, null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skinUrl.isPresent()) {
|
if (skinUrl.isPresent()) {
|
||||||
String url = skinUrl.get();
|
String url = skinUrl.get();
|
||||||
Logging.HTTPD.fine("retrieving skin for " + username + " from " + url);
|
Logging.HTTPD.fine("Retrieving skin for " + username + " from " + url);
|
||||||
byte[] data;
|
byte[] data;
|
||||||
try {
|
try {
|
||||||
data = getURL(url);
|
data = getURL(url);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Logging.HTTPD.log(Level.WARNING, "unable to retrieve skin from " + url, e);
|
Logging.HTTPD.log(Level.WARNING, "Failed to retrieve skin from " + url, e);
|
||||||
return of(newFixedLengthResponse(Status.INTERNAL_ERROR, null, null));
|
return of(newFixedLengthResponse(Status.INTERNAL_ERROR, null, null));
|
||||||
}
|
}
|
||||||
Logging.HTTPD.info("retrieved skin for " + username + " from " + url + ", " + data.length + " bytes");
|
Logging.HTTPD.info("Retrieved skin for " + username + " from " + url + ", " + data.length + " bytes");
|
||||||
return of(newFixedLengthResponse(Status.OK, "image/png", new ByteArrayInputStream(data), data.length));
|
return of(newFixedLengthResponse(Status.OK, "image/png", new ByteArrayInputStream(data), data.length));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Logging.HTTPD.info("no skin found for " + username);
|
Logging.HTTPD.info("No skin is found for " + username);
|
||||||
return of(newFixedLengthResponse(Status.NOT_FOUND, null, null));
|
return of(newFixedLengthResponse(Status.NOT_FOUND, null, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ public class LocalYggdrasilHttpd extends NanoHTTPD {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
Logging.HTTPD.fine("query uuid of username " + username + ", response: " + responseText);
|
Logging.HTTPD.fine("Query UUID of username " + username + ", response: " + responseText);
|
||||||
|
|
||||||
JSONArray response = asJsonArray(parseJson(responseText));
|
JSONArray response = asJsonArray(parseJson(responseText));
|
||||||
if (response.size() == 0) {
|
if (response.size() == 0) {
|
||||||
|
@ -116,10 +116,10 @@ public class LocalYggdrasilHttpd extends NanoHTTPD {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
if (responseText.isEmpty()) {
|
if (responseText.isEmpty()) {
|
||||||
Logging.HTTPD.fine("query profile of " + uuid + ", not found");
|
Logging.HTTPD.fine("Query profile of " + uuid + ", not found");
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
Logging.HTTPD.fine("query profile of " + uuid + ", response: " + responseText);
|
Logging.HTTPD.fine("Query profile of " + uuid + ", response: " + responseText);
|
||||||
|
|
||||||
JSONObject response = asJsonObject(parseJson(responseText));
|
JSONObject response = asJsonObject(parseJson(responseText));
|
||||||
return asJsonArray(response.get("properties")).stream()
|
return asJsonArray(response.get("properties")).stream()
|
||||||
|
@ -137,7 +137,7 @@ public class LocalYggdrasilHttpd extends NanoHTTPD {
|
||||||
.map(JsonUtils::asJsonObject)
|
.map(JsonUtils::asJsonObject)
|
||||||
.map(it -> ofNullable(it.get("url"))
|
.map(it -> ofNullable(it.get("url"))
|
||||||
.map(JsonUtils::asJsonString)
|
.map(JsonUtils::asJsonString)
|
||||||
.orElseThrow(() -> newUncheckedIOException("Invalid JSON: missing texture url")));
|
.orElseThrow(() -> newUncheckedIOException("Invalid JSON: Missing texture url")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,20 +16,20 @@ public class AuthlibInjectorPremain {
|
||||||
|
|
||||||
public static void premain(String arg, Instrumentation instrumentation) {
|
public static void premain(String arg, Instrumentation instrumentation) {
|
||||||
try {
|
try {
|
||||||
Logging.LAUNCH.info("launched from premain");
|
Logging.LAUNCH.info("Launched from premain");
|
||||||
initInjector(arg, instrumentation, false);
|
initInjector(arg, instrumentation, false);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Logging.LAUNCH.log(Level.SEVERE, "an exception has been caught, exiting", e);
|
Logging.LAUNCH.log(Level.SEVERE, "An exception has occurred, exiting", e);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void agentmain(String arg, Instrumentation instrumentation) {
|
public static void agentmain(String arg, Instrumentation instrumentation) {
|
||||||
try {
|
try {
|
||||||
Logging.LAUNCH.info("launched from agentmain");
|
Logging.LAUNCH.info("Launched from agentmain");
|
||||||
initInjector(arg, instrumentation, true);
|
initInjector(arg, instrumentation, true);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Logging.LAUNCH.log(Level.SEVERE, "an exception has been caught", e);
|
Logging.LAUNCH.log(Level.SEVERE, "An exception has occurred", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +42,10 @@ public class AuthlibInjectorPremain {
|
||||||
|
|
||||||
if (needsRetransform) {
|
if (needsRetransform) {
|
||||||
if (retransformSupported) {
|
if (retransformSupported) {
|
||||||
Logging.TRANSFORM.info("start retransforming");
|
Logging.TRANSFORM.info("Start retransforming");
|
||||||
doRetransform(instrumentation);
|
doRetransform(instrumentation);
|
||||||
} else {
|
} else {
|
||||||
Logging.TRANSFORM.warning("retransforming is not supported");
|
Logging.TRANSFORM.warning("Retransform is not supported");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,9 @@ public class AuthlibInjectorPremain {
|
||||||
instrumentation.retransformClasses(classToRetransform);
|
instrumentation.retransformClasses(classToRetransform);
|
||||||
}
|
}
|
||||||
long t1 = System.currentTimeMillis();
|
long t1 = System.currentTimeMillis();
|
||||||
Logging.TRANSFORM.info("retransforming finished in " + (t1 - t0) + "ms");
|
Logging.TRANSFORM.info("Retransform finished in " + (t1 - t0) + "ms");
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Logging.TRANSFORM.log(Level.SEVERE, "unable to retransform", e);
|
Logging.TRANSFORM.log(Level.SEVERE, "Failed to retransform", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public class AuthlibInjectorPremain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logging.TRANSFORM.fine("loaded " + loadedClasses.length + " classes, " + idx + " to retransform");
|
Logging.TRANSFORM.fine("Loaded " + loadedClasses.length + " classes, " + idx + " to retransform");
|
||||||
return Arrays.copyOf(dest, idx);
|
return Arrays.copyOf(dest, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class ClassTransformer implements ClassFileTransformer {
|
||||||
ClassReader reader = new ClassReader(classBuffer);
|
ClassReader reader = new ClassReader(classBuffer);
|
||||||
reader.accept(optionalVisitor.get(), 0);
|
reader.accept(optionalVisitor.get(), 0);
|
||||||
if (currentModified) {
|
if (currentModified) {
|
||||||
Logging.TRANSFORM.info("transform " + className + " using " + unit);
|
Logging.TRANSFORM.info("Transformed " + className + " with " + unit);
|
||||||
modified = true;
|
modified = true;
|
||||||
classBuffer = writer.toByteArray();
|
classBuffer = writer.toByteArray();
|
||||||
}
|
}
|
||||||
|
@ -88,11 +88,11 @@ public class ClassTransformer implements ClassFileTransformer {
|
||||||
}
|
}
|
||||||
return classBuffer;
|
return classBuffer;
|
||||||
} else {
|
} else {
|
||||||
Logging.TRANSFORM.fine("no transform performed on " + className);
|
Logging.TRANSFORM.fine("No transformation is applied to " + className);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Logging.TRANSFORM.log(Level.WARNING, "unable to transform: " + internalClassName, e);
|
Logging.TRANSFORM.log(Level.WARNING, "Failed to transform " + internalClassName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -102,7 +102,7 @@ public class ClassTransformer implements ClassFileTransformer {
|
||||||
try {
|
try {
|
||||||
Files.write(Paths.get(className + "_dump.class"), classBuffer, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
Files.write(Paths.get(className + "_dump.class"), classBuffer, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Logging.TRANSFORM.log(Level.WARNING, "unable to dump class " + className, e);
|
Logging.TRANSFORM.log(Level.WARNING, "Failed to dump class " + className, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class LdcTransformUnit implements TransformUnit {
|
||||||
Optional<String> transformed = ldcMapper.apply((String) cst);
|
Optional<String> transformed = ldcMapper.apply((String) cst);
|
||||||
if (transformed.isPresent() && !transformed.get().equals(cst)) {
|
if (transformed.isPresent() && !transformed.get().equals(cst)) {
|
||||||
modifiedCallback.run();
|
modifiedCallback.run();
|
||||||
Logging.TRANSFORM.info("transform [" + cst + "] to [" + transformed.get() + "]");
|
Logging.TRANSFORM.info("Transformed string [" + cst + "] to [" + transformed.get() + "]");
|
||||||
super.visitLdcInsn(transformed.get());
|
super.visitLdcInsn(transformed.get());
|
||||||
} else {
|
} else {
|
||||||
super.visitLdcInsn(cst);
|
super.visitLdcInsn(cst);
|
||||||
|
|
Loading…
Reference in a new issue