Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.star.beans.PropertyValue;
- import com.sun.star.bridge.XBridge;
- import com.sun.star.bridge.XBridgeFactory;
- import com.sun.star.connection.XConnection;
- import com.sun.star.connection.XConnector;
- import com.sun.star.frame.XComponentLoader;
- import com.sun.star.lang.EventObject;
- import com.sun.star.lang.XComponent;
- import com.sun.star.lang.XEventListener;
- import com.sun.star.lang.XMultiComponentFactory;
- import com.sun.star.uno.UnoRuntime;
- import com.sun.star.uno.XComponentContext;
- public class Main implements XEventListener {
- public static void main(String[] args) throws Exception
- {
- com.sun.star.uno.XComponentContext xContext =
- com.sun.star.comp.helper.Bootstrap
- .createInitialComponentContext(null);
- Object x =
- xContext.getServiceManager()
- .createInstanceWithContext("com.sun.star.connection.Connector",
- xContext);
- XConnector xConnector =
- (XConnector) UnoRuntime.queryInterface(XConnector.class, x);
- // UnoUrl.parseUnoUrl("uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager");
- XConnection connection =
- xConnector.connect("socket,host=localhost,port=2002");
- try {
- x =
- xContext.getServiceManager()
- .createInstanceWithContext("com.sun.star.bridge.BridgeFactory",
- xContext);
- XBridgeFactory xBridgeFactory =
- (XBridgeFactory) UnoRuntime
- .queryInterface(XBridgeFactory.class, x);
- XBridge bridge =
- xBridgeFactory.createBridge("", "urp", connection, null);
- XComponent xComponent =
- (XComponent) UnoRuntime.queryInterface(XComponent.class,
- bridge);
- xComponent.addEventListener(new Main());
- x = bridge.getInstance("StarOffice.ServiceManager");
- if (x == null) {
- System.out.println("failed");
- System.exit(0);
- } else {
- System.out.println("ok");
- }
- XMultiComponentFactory xOfficeMultiComponentFactory =
- (XMultiComponentFactory) UnoRuntime
- .queryInterface(XMultiComponentFactory.class, x);
- doStuff(xContext, xOfficeMultiComponentFactory);
- } finally {
- connection.close();
- }
- }
- private static void
- doStuff(XComponentContext xContext,
- XMultiComponentFactory multiComponent) throws Exception
- {
- Object desktop =
- multiComponent
- .createInstanceWithContext("com.sun.star.frame.Desktop",
- xContext);
- XComponentLoader xComponentLoader =
- (XComponentLoader) UnoRuntime
- .queryInterface(XComponentLoader.class, desktop);
- PropertyValue[] loadProps = new PropertyValue[2];
- loadProps[0] = new PropertyValue();
- loadProps[0].Name = "Password";
- loadProps[0].Value = "";
- loadProps[1] = new PropertyValue();
- loadProps[1].Name = "Hidden";
- loadProps[1].Value = Boolean.TRUE;
- tryPasswords(xComponentLoader, loadProps);
- XComponent document =
- xComponentLoader.loadComponentFromURL("file:///E:/test.odt",
- "_blank", 0, loadProps);
- if (document == null) {
- System.out.println("Document failed");
- } else {
- System.out.println("Document ok");
- }
- }
- private static void tryPasswords(XComponentLoader xComponentLoader,
- PropertyValue[] loadProps)
- throws Exception
- {
- // This test for tota, totb, totc... toto ... hopefully toto will work
- // :)
- char[] pass = { 't', 'o', 't', 'a' };
- int iter = 20;
- while (iter-- > 0) {
- loadProps[0].Value = new String(pass);
- XComponent document =
- xComponentLoader
- .loadComponentFromURL("file:///E:/test.odt",
- "_blank", 0, loadProps);
- if (document != null) {
- System.out.println(String.format("Password \"%s\" worked",
- loadProps[0].Value));
- return;
- }
- pass[3] += 1;
- }
- System.out.println("Brute-force failed");
- }
- @Override
- public void disposing(EventObject arg0)
- {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement