保護またはプライベートクラスのJavaからの起動:確認してそれをすることは不可能ですか?
正しい答えは: "が存在するか、セキュリティマネージャがないことにかかっている。 "
実際には、反射によって、実際に強制的にも非常に苦労なしには、 Java言語の制約、セキュリティマネージャammenochèは、唯一の俳優を管理するためにも本当に力のことではない、これらのタイプを停止することが可能です。
しかし、我々は議論する価値があるのは多くの例があります。 は、次のクラスを指定:
package net.nothing2hide.test; public class ClassWithMethodsToHack { private void sayHello(String name){ System.out.println("Hello " + name + "! You're calling a private method"); } }呼び出しているpackage net.nothing2hide.test; public class ClassWithMethodsToHack { private void sayHello(String name){ System.out.println("Hello " + name + "! You're calling a private method"); } }
として私はそれを使用するように予想を大きく反映方法について簡単にprivate sayHello "外に適用さを発揮したい:
package net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }方法をpackage net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }にpackage net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }* @package net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }公開package net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }/ /package net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }) )package net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }されているpackage net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }( )package net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }(package net.nothing2hide.test; public class PrivateMethodInvocationTest { /** * This sample class demonstrates how to * invoke a protected method on another class * * @param args */ public static void main(String[] args) { String myName = "Davide"; Method m; try { //Let'access the private method //by reflection. You could do the same //with a protected method m = ClassWithMethodsToHack.class.getDeclaredMethod( "sayHello", new Class[]{String.class}); if (m != null) { //Let's force the java language access //checks on the reflected method. Note //that if a security manager is defined //this workaround could not be permitted //and a SecurityException could be raised m.setAccessible(true); //And finally let's invoke the protected method m.invoke(new ClassWithMethodsToHack(), new Object[]{myName}); } } catch (Exception e) { e.printStackTrace(); } } }
閉じる
- 社会的な網
- メールを送る





