Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.97 KB | None | 0 0
  1. import com.sun.star.beans.PropertyValue;
  2. import com.sun.star.bridge.XBridge;
  3. import com.sun.star.bridge.XBridgeFactory;
  4. import com.sun.star.connection.XConnection;
  5. import com.sun.star.connection.XConnector;
  6. import com.sun.star.frame.XComponentLoader;
  7. import com.sun.star.lang.EventObject;
  8. import com.sun.star.lang.XComponent;
  9. import com.sun.star.lang.XEventListener;
  10. import com.sun.star.lang.XMultiComponentFactory;
  11. import com.sun.star.uno.UnoRuntime;
  12. import com.sun.star.uno.XComponentContext;
  13.  
  14. public class Main implements XEventListener {
  15.  
  16.     public static void main(String[] args) throws Exception
  17.     {
  18.         com.sun.star.uno.XComponentContext xContext =
  19.                 com.sun.star.comp.helper.Bootstrap
  20.                         .createInitialComponentContext(null);
  21.  
  22.         Object x =
  23.                 xContext.getServiceManager()
  24.                         .createInstanceWithContext("com.sun.star.connection.Connector",
  25.                                                    xContext);
  26.  
  27.         XConnector xConnector =
  28.                 (XConnector) UnoRuntime.queryInterface(XConnector.class, x);
  29.         // UnoUrl.parseUnoUrl("uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager");
  30.         XConnection connection =
  31.                 xConnector.connect("socket,host=localhost,port=2002");
  32.         try {
  33.             x =
  34.                     xContext.getServiceManager()
  35.                             .createInstanceWithContext("com.sun.star.bridge.BridgeFactory",
  36.                                                        xContext);
  37.             XBridgeFactory xBridgeFactory =
  38.                     (XBridgeFactory) UnoRuntime
  39.                             .queryInterface(XBridgeFactory.class, x);
  40.             XBridge bridge =
  41.                     xBridgeFactory.createBridge("", "urp", connection, null);
  42.  
  43.             XComponent xComponent =
  44.                     (XComponent) UnoRuntime.queryInterface(XComponent.class,
  45.                                                            bridge);
  46.             xComponent.addEventListener(new Main());
  47.  
  48.             x = bridge.getInstance("StarOffice.ServiceManager");
  49.  
  50.             if (x == null) {
  51.                 System.out.println("failed");
  52.                 System.exit(0);
  53.             } else {
  54.                 System.out.println("ok");
  55.             }
  56.  
  57.             XMultiComponentFactory xOfficeMultiComponentFactory =
  58.                     (XMultiComponentFactory) UnoRuntime
  59.                             .queryInterface(XMultiComponentFactory.class, x);
  60.  
  61.             doStuff(xContext, xOfficeMultiComponentFactory);
  62.         } finally {
  63.             connection.close();
  64.         }
  65.     }
  66.  
  67.     private static void
  68.             doStuff(XComponentContext xContext,
  69.                     XMultiComponentFactory multiComponent) throws Exception
  70.     {
  71.         Object desktop =
  72.                 multiComponent
  73.                         .createInstanceWithContext("com.sun.star.frame.Desktop",
  74.                                                    xContext);
  75.         XComponentLoader xComponentLoader =
  76.                 (XComponentLoader) UnoRuntime
  77.                         .queryInterface(XComponentLoader.class, desktop);
  78.         PropertyValue[] loadProps = new PropertyValue[2];
  79.         loadProps[0] = new PropertyValue();
  80.         loadProps[0].Name = "Password";
  81.         loadProps[0].Value = "";
  82.         loadProps[1] = new PropertyValue();
  83.         loadProps[1].Name = "Hidden";
  84.         loadProps[1].Value = Boolean.TRUE;
  85.  
  86.         tryPasswords(xComponentLoader, loadProps);
  87.  
  88.         XComponent document =
  89.                 xComponentLoader.loadComponentFromURL("file:///E:/test.odt",
  90.                                                       "_blank", 0, loadProps);
  91.         if (document == null) {
  92.             System.out.println("Document failed");
  93.         } else {
  94.             System.out.println("Document ok");
  95.         }
  96.     }
  97.  
  98.     private static void tryPasswords(XComponentLoader xComponentLoader,
  99.                                      PropertyValue[] loadProps)
  100.                                                                throws Exception
  101.     {
  102.         // This test for tota, totb, totc... toto ... hopefully toto will work
  103.         // :)
  104.         char[] pass = { 't', 'o', 't', 'a' };
  105.         int iter = 20;
  106.         while (iter-- > 0) {
  107.             loadProps[0].Value = new String(pass);
  108.             XComponent document =
  109.                     xComponentLoader
  110.                             .loadComponentFromURL("file:///E:/test.odt",
  111.                                                   "_blank", 0, loadProps);
  112.             if (document != null) {
  113.                 System.out.println(String.format("Password \"%s\" worked",
  114.                                                  loadProps[0].Value));
  115.                 return;
  116.             }
  117.             pass[3] += 1;
  118.         }
  119.         System.out.println("Brute-force failed");
  120.     }
  121.  
  122.     @Override
  123.     public void disposing(EventObject arg0)
  124.     {
  125.         // TODO Auto-generated method stub
  126.  
  127.     }
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement