-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Goodbye Access Checks if unsafeMode is enabled
- Loading branch information
Showing
7 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/minecraft/com/vbitz/MinecraftScript/MinecraftScriptJavaObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.vbitz.MinecraftScript; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
|
||
import org.mozilla.javascript.NativeJavaObject; | ||
import org.mozilla.javascript.Scriptable; | ||
|
||
public class MinecraftScriptJavaObject extends NativeJavaObject { | ||
|
||
private static Object recuriveGetItem(Class<?> cls, String name) { | ||
for (Method item : cls.getDeclaredMethods()) { | ||
if (item.getName().equals(name)) { | ||
return item; | ||
} | ||
} | ||
for (Field item : cls.getDeclaredFields()) { | ||
if (item.getName().equals(name)) { | ||
return item; | ||
} | ||
} | ||
if (cls.getSuperclass() != null) { | ||
return recuriveGetItem(cls.getSuperclass(), name); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public MinecraftScriptJavaObject(Scriptable scope, Object javaObject, | ||
Class<?> staticType) { | ||
super(scope, javaObject, staticType); | ||
} | ||
|
||
@Override | ||
public Object get(String name, Scriptable thisObject) { | ||
if (name.equals("getClass") && !MinecraftScriptMod.getUnsafeEnabled()) { | ||
return NOT_FOUND; | ||
} | ||
|
||
if (!MinecraftScriptMod.getUnsafeEnabled()) { | ||
return super.get(name, thisObject); | ||
} | ||
|
||
Object reflectItem = recuriveGetItem(unwrap().getClass(), name); | ||
|
||
if (reflectItem == null) { | ||
return NOT_FOUND; | ||
} | ||
|
||
if (reflectItem instanceof Method) { | ||
if (!((Method) reflectItem).isAccessible()) { | ||
System.out.println("private call"); | ||
((Method) reflectItem).setAccessible(true); | ||
} | ||
} else if (reflectItem instanceof Field) { | ||
if (!((Field) reflectItem).isAccessible()) { | ||
System.out.println("private call"); | ||
((Field) reflectItem).setAccessible(true); | ||
} | ||
} | ||
|
||
return super.get(name, thisObject); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/minecraft/com/vbitz/MinecraftScript/MinecraftScriptWrapFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.vbitz.MinecraftScript; | ||
|
||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.Scriptable; | ||
import org.mozilla.javascript.WrapFactory; | ||
|
||
public class MinecraftScriptWrapFactory extends WrapFactory { | ||
@Override | ||
public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, | ||
Object javaObject, Class<?> staticType) { | ||
return new MinecraftScriptJavaObject(scope, javaObject, staticType); | ||
} | ||
} |