bugged
stringlengths 6
599k
| fixed
stringlengths 10
599k
| __index_level_0__
int64 0
1.13M
|
|---|---|---|
public static synchronized byte[] decompress(final byte[] bytes) throws IOException { final ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes); final Inflater inflater = new Inflater(); final InflaterInputStream inflaterInputStream = new InflaterInputStream( bytesIn, inflater, bytes.length); byte[] decompressedContent = new byte[0]; byte[] inflatedBytes = new byte[1024]; byte[] tempoararyBytes; int bytesRead = inflaterInputStream.read(inflatedBytes); int offset = 0; while (-1 != bytesRead) { /* Copy that which is already read to a temp location. */ tempoararyBytes = new byte[decompressedContent.length]; System.arraycopy(decompressedContent, 0, tempoararyBytes, 0, decompressedContent.length); /* Enlarge and copy that in the temp location back. */ decompressedContent = new byte[tempoararyBytes.length + bytesRead]; System.arraycopy(tempoararyBytes, 0, decompressedContent, 0, tempoararyBytes.length); /* Copy that which was just read. */ System.arraycopy(inflatedBytes, 0, decompressedContent, offset, bytesRead); bytesRead = inflaterInputStream.read(inflatedBytes); offset += bytesRead; } return decompressedContent; }
|
public static synchronized byte[] decompress(final byte[] bytes) throws IOException { final ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes); final Inflater inflater = new Inflater(); final InflaterInputStream inflaterInputStream = new InflaterInputStream( bytesIn, inflater, bytes.length); byte[] decompressedContent = new byte[0]; byte[] inflatedBytes = new byte[1024]; byte[] tempoararyBytes; int bytesRead = inflaterInputStream.read(inflatedBytes); int offset = 0; while (-1 != bytesRead) { /* Copy that which is already read to a temp location. */ tempoararyBytes = new byte[decompressedContent.length]; System.arraycopy(decompressedContent, 0, tempoararyBytes, 0, decompressedContent.length); /* Enlarge and copy that in the temp location back. */ decompressedContent = new byte[tempoararyBytes.length + bytesRead]; System.arraycopy(tempoararyBytes, 0, decompressedContent, 0, tempoararyBytes.length); /* Copy that which was just read. */ System.arraycopy(inflatedBytes, 0, decompressedContent, offset, bytesRead); bytesRead = inflaterInputStream.read(inflatedBytes); offset += bytesRead; } return decompressedContent; }
| 1,112,960
|
public static synchronized byte[] decompress(final byte[] bytes) throws IOException { final ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes); final Inflater inflater = new Inflater(); final InflaterInputStream inflaterInputStream = new InflaterInputStream( bytesIn, inflater, bytes.length); byte[] decompressedContent = new byte[0]; byte[] inflatedBytes = new byte[1024]; byte[] tempoararyBytes; int bytesRead = inflaterInputStream.read(inflatedBytes); int offset = 0; while (-1 != bytesRead) { /* Copy that which is already read to a temp location. */ tempoararyBytes = new byte[decompressedContent.length]; System.arraycopy(decompressedContent, 0, tempoararyBytes, 0, decompressedContent.length); /* Enlarge and copy that in the temp location back. */ decompressedContent = new byte[tempoararyBytes.length + bytesRead]; System.arraycopy(tempoararyBytes, 0, decompressedContent, 0, tempoararyBytes.length); /* Copy that which was just read. */ System.arraycopy(inflatedBytes, 0, decompressedContent, offset, bytesRead); bytesRead = inflaterInputStream.read(inflatedBytes); offset += bytesRead; } return decompressedContent; }
|
public static synchronized byte[] decompress(final byte[] bytes) throws IOException { final ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytes); final Inflater inflater = new Inflater(); final InflaterInputStream inflaterInputStream = new InflaterInputStream( bytesIn, inflater, bytes.length); byte[] decompressedContent = new byte[0]; byte[] inflatedBytes = new byte[1024]; byte[] tempoararyBytes; int bytesRead = inflaterInputStream.read(inflatedBytes); int offset = 0; while (-1 != bytesRead) { /* Copy that which is already read to a temp location. */ tempoararyBytes = new byte[decompressedContent.length]; System.arraycopy(decompressedContent, 0, tempoararyBytes, 0, decompressedContent.length); /* Enlarge and copy that in the temp location back. */ decompressedContent = new byte[tempoararyBytes.length + bytesRead]; System.arraycopy(tempoararyBytes, 0, decompressedContent, 0, tempoararyBytes.length); /* Copy that which was just read. */ System.arraycopy(inflatedBytes, 0, decompressedContent, offset, bytesRead); bytesRead = inflaterInputStream.read(inflatedBytes); offset += bytesRead; } return decompressedContent; }
| 1,112,961
|
public static synchronized byte[] compress(final byte[] bytes, final Level level) throws IOException { final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); final Deflater deflater = new Deflater(level.getLevel()); final DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream( bytesOut, deflater, bytes.length); deflaterOutputStream.write(bytes); deflaterOutputStream.finish(); return bytesOut.toByteArray(); }
|
public static synchronized byte[] compress(final byte[] bytes, final Level level) throws IOException { final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); final Deflater deflater = new Deflater(level.getLevel()); final DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream( bytesOut, deflater, bytes.length); deflaterOutputStream.write(bytes); deflaterOutputStream.finish(); return bytesOut.toByteArray(); }
| 1,112,962
|
private Avatar createBrowserMain() { if(null == browserMain) { browserMain = new BrowserMainAvatar(controller); browserMain.setContentProvider(ProviderFactory.getMainProvider()); } return browserMain; }
|
private Avatar createBrowserMain() { if(null == browserMain) { browserMain = new BrowserMainAvatar(); browserMain.setContentProvider(ProviderFactory.getMainProvider()); } return browserMain; }
| 1,112,963
|
BrowserMainAvatar(final Controller controller) { super("MainListAvatar", ScrollPolicy.VERTICAL, new Color(255, 255, 255, 0)); this.listItemMap = new Hashtable<JVMUniqueId, Component>(20, 0.75F); setLayout(new GridBagLayout()); }
|
BrowserMainAvatar(final Controller controller) { super("MainListAvatar", ScrollPolicy.VERTICAL, new Color(255, 255, 255, 0)); this.listItemMap = new Hashtable<JVMUniqueId, Component>(20, 0.75F); setLayout(new GridBagLayout()); }
| 1,112,964
|
private List<DocumentVersion> readBackupDocumentVersions(final JabberId userId, final UUID uniqueId, final Long versionId, final UUID documentUniqueId) { return getContainerModel().readBackupDocumentVersions(userId, uniqueId, versionId, documentUniqueId); }
|
private List<DocumentVersion> readBackupDocumentVersions(final JabberId userId, final UUID uniqueId, final Long versionId, final UUID documentUniqueId) { return getContainerModel().readBackupDocumentVersions(userId, uniqueId, versionId, documentUniqueId); }
| 1,112,966
|
private List<DocumentVersion> readBackupDocumentVersions(final JabberId userId, final UUID uniqueId, final Long versionId, final UUID documentUniqueId) { return getContainerModel().readBackupDocumentVersions(userId, uniqueId, versionId, documentUniqueId); }
|
private List<DocumentVersion> readBackupDocumentVersions(final JabberId userId, final UUID uniqueId, final Long versionId, final UUID documentUniqueId) { return getContainerModel().readBackupDocumentVersions(userId, uniqueId, versionId); }
| 1,112,967
|
public void service() { logApiId(); final List<DocumentVersion> versions = readBackupDocumentVersions( readJabberId("userId"), readUUID("uniqueId"), readLong("versionId"), readUUID("documentUniqueId")); writeDocumentVersions("documentVersions", "documentVersion", versions); }
|
public void service() { logApiId(); final List<DocumentVersion> versions = readBackupDocumentVersions( readJabberId("userId"), readUUID("uniqueId"), readLong("versionId")); writeDocumentVersions("documentVersions", "documentVersion", versions); }
| 1,112,968
|
public AbstractHandler(final String action) { super(action); this.logger = new Log4JWrapper(); }
|
public AbstractHandler(final String action) { super(action); this.logger = new Log4JWrapper(getClass()); }
| 1,112,969
|
public List<DocumentVersion> readBackupDocumentVersions(final JabberId userId, final UUID uniqueId, final Long versionId, final UUID documentUniqueId) { synchronized (getImplLock()) { return getImpl().readBackupDocumentVersions(userId, uniqueId, versionId, documentUniqueId); } }
|
public List<DocumentVersion> readBackupDocumentVersions(final JabberId userId, final UUID uniqueId, final Long versionId, final UUID documentUniqueId) { synchronized (getImplLock()) { return getImpl().readBackupDocumentVersions(userId, uniqueId, versionId, documentUniqueId); } }
| 1,112,970
|
public List<DocumentVersion> readBackupDocumentVersions(final JabberId userId, final UUID uniqueId, final Long versionId, final UUID documentUniqueId) { synchronized (getImplLock()) { return getImpl().readBackupDocumentVersions(userId, uniqueId, versionId, documentUniqueId); } }
|
public List<DocumentVersion> readBackupDocumentVersions(final JabberId userId, final UUID uniqueId, final Long versionId, final UUID documentUniqueId) { synchronized (getImplLock()) { return getImpl().readBackupDocumentVersions(userId, uniqueId, versionId, documentUniqueId); } }
| 1,112,971
|
public void close() { disconnect(); }
|
public void close() throws IOException { disconnect(); }
| 1,112,972
|
public void open() { connect(Type.UPSTREAM); }
|
public void open() throws IOException { connect(Type.UPSTREAM); }
| 1,112,973
|
public void write(final String streamId, final InputStream stream) { write(new StreamHeader(StreamHeader.Type.STREAM_BEGIN, streamId)); write(stream); }
|
public void write(final String streamId, final InputStream stream) { write(new StreamHeader(StreamHeader.Type.STREAM_BEGIN, streamId)); write(stream); }
| 1,112,974
|
public Boolean confirm(final String messageKey, final Object[] messageArguments) { final Data input = new Data(2); input.set(ConfirmDialog.DataKey.MESSAGE_KEY, messageKey); input.set(ConfirmDialog.DataKey.MESSAGE_ARGUMENTS, messageArguments); return confirm(input); }
|
public Boolean confirm(final String messageKey, final Object[] messageArguments) { final Data input = new Data(2); input.set(ConfirmDialog.DataKey.MESSAGE_KEY, messageKey); input.set(ConfirmDialog.DataKey.MESSAGE_ARGUMENTS, messageArguments); return confirm(input); }
| 1,112,975
|
public Boolean confirm(final String messageKey, final Object[] messageArguments) { final Data input = new Data(2); input.set(ConfirmDialog.DataKey.MESSAGE_KEY, messageKey); input.set(ConfirmDialog.DataKey.MESSAGE_ARGUMENTS, messageArguments); return confirm(input); }
|
public Boolean confirm(final String messageKey, final Object[] messageArguments) { final Data input = new Data(2); input.set(ConfirmDialog.DataKey.MESSAGE_KEY, messageKey); return confirm(input); }
| 1,112,976
|
public void runAddContainerDocuments(final Long containerId, final File[] files) { final Data data = new Data(2); data.set(AddDocument.DataKey.CONTAINER_ID, containerId); data.set(AddDocument.DataKey.FILES, files); invoke(ActionId.CONTAINER_ADD_DOCUMENT, data); }
|
public void runAddContainerDocuments(final Long containerId, final File[] files) { final Data data = new Data(2); data.set(AddDocument.DataKey.CONTAINER_ID, containerId); data.set(AddDocument.DataKey.FILES, files); invoke(ActionId.CONTAINER_ADD_DOCUMENT, data); }
| 1,112,977
|
public void runCreateContainer(final List<File> files) { runCreateContainer(null, files); }
|
public void runCreateContainer(final List<File> files) { runCreateContainer(null, files); }
| 1,112,978
|
public void runRenameDocument(final Long documentId, final String documentName) { final Data data = new Data(3); data.set(Rename.DataKey.DOCUMENT_ID, documentId); data.set(Rename.DataKey.DOCUMENT_NAME, documentName); invoke(ActionId.DOCUMENT_RENAME, data); }
|
public void runRenameDocument(final Long documentId, final String documentName) { final Data data = new Data(3); data.set(Rename.DataKey.DOCUMENT_ID, documentId); data.set(Rename.DataKey.DOCUMENT_NAME, documentName); invoke(ActionId.DOCUMENT_RENAME, data); }
| 1,112,979
|
public void runRenameDocument(final Long documentId, final String documentName) { final Data data = new Data(3); data.set(Rename.DataKey.DOCUMENT_ID, documentId); data.set(Rename.DataKey.DOCUMENT_NAME, documentName); invoke(ActionId.DOCUMENT_RENAME, data); }
|
public void runRenameDocument(final Long documentId, final String documentName) { final Data data = new Data(3); data.set(Rename.DataKey.DOCUMENT_ID, documentId); invoke(ActionId.DOCUMENT_RENAME, data); }
| 1,112,980
|
BrowserWindow(final Browser browser) throws HeadlessException { super("BrowserWindow"); this.browser = browser; this.logger = Logger.getLogger(getClass()); this.persistence = PersistenceFactory.getPersistence(getClass()); getRootPane().setBorder(new WindowBorder2()); addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { persist(); browser.hibernate(); }}); initMenu(); setIconImage(com.thinkparity.ophelia.browser.Constants.Images.WINDOW_ICON_IMAGE); setTitle(java.util.ResourceBundle.getBundle("localization/JFrame_Messages").getString("BrowserWindow.Title")); setUndecorated(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final Point location = persistence.get("location", new Point(100, 100)); location.x = (location.x < 0 ? 0 : location.x ); location.y = (location.y < 0 ? 0 : location.y ); setLocation(location.x, location.y); final Dimension size = persistence.get("size", getMainWindowSize()); mainWindowSize.setSize(size); setResizable(true); setMinimumSize(getMainWindowSize()); setSize(getMainWindowSize()); initComponents(); // Set up the semi-transparent JPanel semiTransparentJPanel = new SemiTransparentJPanel(Boolean.FALSE); getLayeredPane().add(semiTransparentJPanel, JLayeredPane.PALETTE_LAYER); // Set up the resizer resizer = new Resizer(browser, this, Boolean.FALSE, Resizer.ResizeEdges.ALL_EDGES); }
|
BrowserWindow(final Browser browser) throws HeadlessException { super("BrowserWindow"); this.browser = browser; this.logger = Logger.getLogger(getClass()); this.persistence = PersistenceFactory.getPersistence(getClass()); final Boolean maximized = persistence.get("maximized", Boolean.FALSE); getRootPane().setBorder(new WindowBorder2()); addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { persist(); browser.hibernate(); }}); initMenu(); setIconImage(com.thinkparity.ophelia.browser.Constants.Images.WINDOW_ICON_IMAGE); setTitle(java.util.ResourceBundle.getBundle("localization/JFrame_Messages").getString("BrowserWindow.Title")); setUndecorated(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final Point location = persistence.get("location", new Point(100, 100)); location.x = (location.x < 0 ? 0 : location.x ); location.y = (location.y < 0 ? 0 : location.y ); setLocation(location.x, location.y); final Dimension size = persistence.get("size", getMainWindowSize()); mainWindowSize.setSize(size); setResizable(true); setMinimumSize(getMainWindowSize()); setSize(getMainWindowSize()); initComponents(); // Set up the semi-transparent JPanel semiTransparentJPanel = new SemiTransparentJPanel(Boolean.FALSE); getLayeredPane().add(semiTransparentJPanel, JLayeredPane.PALETTE_LAYER); // Set up the resizer resizer = new Resizer(browser, this, Boolean.FALSE, Resizer.ResizeEdges.ALL_EDGES); }
| 1,112,982
|
BrowserWindow(final Browser browser) throws HeadlessException { super("BrowserWindow"); this.browser = browser; this.logger = Logger.getLogger(getClass()); this.persistence = PersistenceFactory.getPersistence(getClass()); getRootPane().setBorder(new WindowBorder2()); addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { persist(); browser.hibernate(); }}); initMenu(); setIconImage(com.thinkparity.ophelia.browser.Constants.Images.WINDOW_ICON_IMAGE); setTitle(java.util.ResourceBundle.getBundle("localization/JFrame_Messages").getString("BrowserWindow.Title")); setUndecorated(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final Point location = persistence.get("location", new Point(100, 100)); location.x = (location.x < 0 ? 0 : location.x ); location.y = (location.y < 0 ? 0 : location.y ); setLocation(location.x, location.y); final Dimension size = persistence.get("size", getMainWindowSize()); mainWindowSize.setSize(size); setResizable(true); setMinimumSize(getMainWindowSize()); setSize(getMainWindowSize()); initComponents(); // Set up the semi-transparent JPanel semiTransparentJPanel = new SemiTransparentJPanel(Boolean.FALSE); getLayeredPane().add(semiTransparentJPanel, JLayeredPane.PALETTE_LAYER); // Set up the resizer resizer = new Resizer(browser, this, Boolean.FALSE, Resizer.ResizeEdges.ALL_EDGES); }
|
BrowserWindow(final Browser browser) throws HeadlessException { super("BrowserWindow"); this.browser = browser; this.logger = Logger.getLogger(getClass()); this.persistence = PersistenceFactory.getPersistence(getClass()); getRootPane().setBorder(new WindowBorder2()); addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { persist(); browser.hibernate(); }}); initMenu(maximized); setIconImage(com.thinkparity.ophelia.browser.Constants.Images.WINDOW_ICON_IMAGE); setTitle(java.util.ResourceBundle.getBundle("localization/JFrame_Messages").getString("BrowserWindow.Title")); setUndecorated(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final Point location = persistence.get("location", new Point(100, 100)); location.x = (location.x < 0 ? 0 : location.x ); location.y = (location.y < 0 ? 0 : location.y ); setLocation(location.x, location.y); final Dimension size = persistence.get("size", getMainWindowSize()); mainWindowSize.setSize(size); setResizable(true); setMinimumSize(getMainWindowSize()); setSize(getMainWindowSize()); initComponents(); // Set up the semi-transparent JPanel semiTransparentJPanel = new SemiTransparentJPanel(Boolean.FALSE); getLayeredPane().add(semiTransparentJPanel, JLayeredPane.PALETTE_LAYER); // Set up the resizer resizer = new Resizer(browser, this, Boolean.FALSE, Resizer.ResizeEdges.ALL_EDGES); }
| 1,112,983
|
BrowserWindow(final Browser browser) throws HeadlessException { super("BrowserWindow"); this.browser = browser; this.logger = Logger.getLogger(getClass()); this.persistence = PersistenceFactory.getPersistence(getClass()); getRootPane().setBorder(new WindowBorder2()); addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { persist(); browser.hibernate(); }}); initMenu(); setIconImage(com.thinkparity.ophelia.browser.Constants.Images.WINDOW_ICON_IMAGE); setTitle(java.util.ResourceBundle.getBundle("localization/JFrame_Messages").getString("BrowserWindow.Title")); setUndecorated(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final Point location = persistence.get("location", new Point(100, 100)); location.x = (location.x < 0 ? 0 : location.x ); location.y = (location.y < 0 ? 0 : location.y ); setLocation(location.x, location.y); final Dimension size = persistence.get("size", getMainWindowSize()); mainWindowSize.setSize(size); setResizable(true); setMinimumSize(getMainWindowSize()); setSize(getMainWindowSize()); initComponents(); // Set up the semi-transparent JPanel semiTransparentJPanel = new SemiTransparentJPanel(Boolean.FALSE); getLayeredPane().add(semiTransparentJPanel, JLayeredPane.PALETTE_LAYER); // Set up the resizer resizer = new Resizer(browser, this, Boolean.FALSE, Resizer.ResizeEdges.ALL_EDGES); }
|
BrowserWindow(final Browser browser) throws HeadlessException { super("BrowserWindow"); this.browser = browser; this.logger = Logger.getLogger(getClass()); this.persistence = PersistenceFactory.getPersistence(getClass()); getRootPane().setBorder(new WindowBorder2()); addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { persist(); browser.hibernate(); }}); initMenu(); setIconImage(com.thinkparity.ophelia.browser.Constants.Images.WINDOW_ICON_IMAGE); setTitle(java.util.ResourceBundle.getBundle("localization/JFrame_Messages").getString("BrowserWindow.Title")); setUndecorated(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final Point location = persistence.get("location", getMainWindowLocation()); location.x = (location.x < 0 ? 0 : location.x ); location.y = (location.y < 0 ? 0 : location.y ); setLocation(location.x, location.y); final Dimension size = persistence.get("size", getMainWindowSize()); mainWindowSize.setSize(size); setResizable(true); setMinimumSize(getMainWindowSize()); setSize(getMainWindowSize()); initComponents(); // Set up the semi-transparent JPanel semiTransparentJPanel = new SemiTransparentJPanel(Boolean.FALSE); getLayeredPane().add(semiTransparentJPanel, JLayeredPane.PALETTE_LAYER); // Set up the resizer resizer = new Resizer(browser, this, Boolean.FALSE, Resizer.ResizeEdges.ALL_EDGES); }
| 1,112,984
|
BrowserWindow(final Browser browser) throws HeadlessException { super("BrowserWindow"); this.browser = browser; this.logger = Logger.getLogger(getClass()); this.persistence = PersistenceFactory.getPersistence(getClass()); getRootPane().setBorder(new WindowBorder2()); addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { persist(); browser.hibernate(); }}); initMenu(); setIconImage(com.thinkparity.ophelia.browser.Constants.Images.WINDOW_ICON_IMAGE); setTitle(java.util.ResourceBundle.getBundle("localization/JFrame_Messages").getString("BrowserWindow.Title")); setUndecorated(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final Point location = persistence.get("location", new Point(100, 100)); location.x = (location.x < 0 ? 0 : location.x ); location.y = (location.y < 0 ? 0 : location.y ); setLocation(location.x, location.y); final Dimension size = persistence.get("size", getMainWindowSize()); mainWindowSize.setSize(size); setResizable(true); setMinimumSize(getMainWindowSize()); setSize(getMainWindowSize()); initComponents(); // Set up the semi-transparent JPanel semiTransparentJPanel = new SemiTransparentJPanel(Boolean.FALSE); getLayeredPane().add(semiTransparentJPanel, JLayeredPane.PALETTE_LAYER); // Set up the resizer resizer = new Resizer(browser, this, Boolean.FALSE, Resizer.ResizeEdges.ALL_EDGES); }
|
BrowserWindow(final Browser browser) throws HeadlessException { super("BrowserWindow"); this.browser = browser; this.logger = Logger.getLogger(getClass()); this.persistence = PersistenceFactory.getPersistence(getClass()); getRootPane().setBorder(new WindowBorder2()); addWindowListener(new WindowAdapter() { public void windowClosing(final WindowEvent e) { persist(); browser.hibernate(); }}); initMenu(); setIconImage(com.thinkparity.ophelia.browser.Constants.Images.WINDOW_ICON_IMAGE); setTitle(java.util.ResourceBundle.getBundle("localization/JFrame_Messages").getString("BrowserWindow.Title")); setUndecorated(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final Point location = persistence.get("location", new Point(100, 100)); location.x = (location.x < 0 ? 0 : location.x ); location.y = (location.y < 0 ? 0 : location.y ); setLocation(location.x, location.y); final Dimension size = persistence.get("size", getMainWindowSize()); mainWindowSize.setSize(size); if (maximized) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); setMaximizedBounds(env.getMaximumWindowBounds()); setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); } setResizable(true); setMinimumSize(getMainWindowSize()); setSize(getMainWindowSize()); initComponents(); // Set up the semi-transparent JPanel semiTransparentJPanel = new SemiTransparentJPanel(Boolean.FALSE); getLayeredPane().add(semiTransparentJPanel, JLayeredPane.PALETTE_LAYER); // Set up the resizer resizer = new Resizer(browser, this, Boolean.FALSE, Resizer.ResizeEdges.ALL_EDGES); }
| 1,112,985
|
public MainProvider(final ArtifactModel artifactModel, final DocumentModel documentModel, final SystemMessageModel systemMessageModel) { super(); this.documentProvider = new SingleContentProvider() { public Object getElement(final Object input) { final Long documentId = assertNotNullLong( "The main provider's document provider requires " + "non-null java.lang.Long input.", input); try { final Document document = documentModel.get(documentId); return toDisplay(document, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.documentsProvider = new FlatContentProvider() { public Object[] getElements(final Object input) { try { // sort by: // +> remote update ? later b4 earlier // +> last update ? later b4 earlier final AbstractArtifactComparator sort = new RemoteUpdatedOnComparator(Boolean.FALSE); sort.add(new UpdatedOnComparator(Boolean.FALSE)); final Filter<Artifact> filter = (Filter<Artifact>) input; final Collection<Document> documents; if(null != filter) { documents = documentModel.list(sort, filter); } else { documents = documentModel.list(sort); } return toDisplay(documents, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.systemMessageProvider = new SingleContentProvider() { public Object getElement(final Object input) { final Long systemMessageId = assertNotNullLong( "The main provider's system message provider " + "requires non-null java.lang.Long input.", input); final SystemMessage systemMessage; try { systemMessage = systemMessageModel.read(systemMessageId); } catch(final ParityException px) { throw new RuntimeException(px); } switch(systemMessage.getType()) { case INFO: case CONTACT_INVITATION: case CONTACT_INVITATION_RESPONSE: return systemMessage; case KEY_REQUEST: case KEY_RESPONSE: return null; default: throw Assert.createUnreachable("Unknown message type: " + systemMessage.getType()); } } }; this.systemMessagesProvider = new FlatContentProvider() { public Object[] getElements(final Object input) { try { final Collection<SystemMessage> messages = systemMessageModel.readForNonArtifacts(); return messages.toArray(new SystemMessage[] {}); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.flatProviders = new FlatContentProvider[] {documentsProvider, systemMessagesProvider}; this.singleProviders = new SingleContentProvider[] {documentProvider, systemMessageProvider}; }
|
public MainProvider(final ArtifactModel artifactModel, final DocumentModel documentModel, final SystemMessageModel systemMessageModel) { super(); this.documentProvider = new SingleContentProvider() { public Object getElement(final Object input) { final Long documentId = assertNotNullLong( "The main provider's document provider requires " + "non-null java.lang.Long input.", input); try { final Document document = documentModel.get(documentId); return toDisplay(document, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.documentsProvider = new FlatContentProvider() { public Object[] getElements(final Object input) { try { // sort by: // +> remote update ? later b4 earlier // +> last update ? later b4 earlier final AbstractArtifactComparator sort = new RemoteUpdatedOnComparator(Boolean.FALSE); sort.add(new UpdatedOnComparator(Boolean.FALSE)); final Filter<Artifact> filter = (Filter<Artifact>) input; final Collection<Document> documents; if(null != filter) { documents = documentModel.list(sort, filter); } else { documents = documentModel.list(sort); } return toDisplay(documents, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.systemMessageProvider = new SingleContentProvider() { public Object getElement(final Object input) { final Long systemMessageId = assertNotNullLong( "The main provider's system message provider " + "requires non-null java.lang.Long input.", input); final SystemMessage systemMessage; try { systemMessage = systemMessageModel.read(systemMessageId); } catch(final ParityException px) { throw new RuntimeException(px); } switch(systemMessage.getType()) { case INFO: case CONTACT_INVITATION: case CONTACT_INVITATION_RESPONSE: return systemMessage; case KEY_REQUEST: case KEY_RESPONSE: return null; default: throw Assert.createUnreachable("Unknown message type: " + systemMessage.getType()); } } }; this.systemMessagesProvider = new FlatContentProvider() { public Object[] getElements(final Object input) { try { final Collection<SystemMessage> messages = systemMessageModel.readForNonArtifacts(); return messages.toArray(new SystemMessage[] {}); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.flatProviders = new FlatContentProvider[] {documentsProvider, systemMessagesProvider}; this.singleProviders = new SingleContentProvider[] {documentProvider, systemMessageProvider}; }
| 1,112,987
|
public MainProvider(final ArtifactModel artifactModel, final DocumentModel documentModel, final SystemMessageModel systemMessageModel) { super(); this.documentProvider = new SingleContentProvider() { public Object getElement(final Object input) { final Long documentId = assertNotNullLong( "The main provider's document provider requires " + "non-null java.lang.Long input.", input); try { final Document document = documentModel.get(documentId); return toDisplay(document, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.documentsProvider = new FlatContentProvider() { public Object[] getElements(final Object input) { try { // sort by: // +> remote update ? later b4 earlier // +> last update ? later b4 earlier final AbstractArtifactComparator sort = new RemoteUpdatedOnComparator(Boolean.FALSE); sort.add(new UpdatedOnComparator(Boolean.FALSE)); final Filter<Artifact> filter = (Filter<Artifact>) input; final Collection<Document> documents; if(null != filter) { documents = documentModel.list(sort, filter); } else { documents = documentModel.list(sort); } return toDisplay(documents, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.systemMessageProvider = new SingleContentProvider() { public Object getElement(final Object input) { final Long systemMessageId = assertNotNullLong( "The main provider's system message provider " + "requires non-null java.lang.Long input.", input); final SystemMessage systemMessage; try { systemMessage = systemMessageModel.read(systemMessageId); } catch(final ParityException px) { throw new RuntimeException(px); } switch(systemMessage.getType()) { case INFO: case CONTACT_INVITATION: case CONTACT_INVITATION_RESPONSE: return systemMessage; case KEY_REQUEST: case KEY_RESPONSE: return null; default: throw Assert.createUnreachable("Unknown message type: " + systemMessage.getType()); } } }; this.systemMessagesProvider = new FlatContentProvider() { public Object[] getElements(final Object input) { try { final Collection<SystemMessage> messages = systemMessageModel.readForNonArtifacts(); return messages.toArray(new SystemMessage[] {}); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.flatProviders = new FlatContentProvider[] {documentsProvider, systemMessagesProvider}; this.singleProviders = new SingleContentProvider[] {documentProvider, systemMessageProvider}; }
|
public MainProvider(final ArtifactModel artifactModel, final DocumentModel documentModel, final SystemMessageModel systemMessageModel) { super(); this.documentProvider = new SingleContentProvider() { public Object getElement(final Object input) { final Long documentId = assertNotNullLong( "The main provider's document provider requires " + "non-null java.lang.Long input.", input); try { final Document document = documentModel.get(documentId); if(filter.doFilter(document)) { return null; } else { return toDisplay(document, artifactModel); } } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.documentsProvider = new FlatContentProvider() { public Object[] getElements(final Object input) { try { // sort by: // +> remote update ? later b4 earlier // +> last update ? later b4 earlier final AbstractArtifactComparator sort = new RemoteUpdatedOnComparator(Boolean.FALSE); sort.add(new UpdatedOnComparator(Boolean.FALSE)); final Filter<Artifact> filter = (Filter<Artifact>) input; final Collection<Document> documents; if(null != filter) { documents = documentModel.list(sort, filter); } else { documents = documentModel.list(sort); } return toDisplay(documents, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.systemMessageProvider = new SingleContentProvider() { public Object getElement(final Object input) { final Long systemMessageId = assertNotNullLong( "The main provider's system message provider " + "requires non-null java.lang.Long input.", input); final SystemMessage systemMessage; try { systemMessage = systemMessageModel.read(systemMessageId); } catch(final ParityException px) { throw new RuntimeException(px); } switch(systemMessage.getType()) { case INFO: case CONTACT_INVITATION: case CONTACT_INVITATION_RESPONSE: return systemMessage; case KEY_REQUEST: case KEY_RESPONSE: return null; default: throw Assert.createUnreachable("Unknown message type: " + systemMessage.getType()); } } }; this.systemMessagesProvider = new FlatContentProvider() { public Object[] getElements(final Object input) { try { final Collection<SystemMessage> messages = systemMessageModel.readForNonArtifacts(); return messages.toArray(new SystemMessage[] {}); } catch(final ParityException px) { throw new RuntimeException(px); } } }; this.flatProviders = new FlatContentProvider[] {documentsProvider, systemMessagesProvider}; this.singleProviders = new SingleContentProvider[] {documentProvider, systemMessageProvider}; }
| 1,112,988
|
public Object getElement(final Object input) { final Long documentId = assertNotNullLong( "The main provider's document provider requires " + "non-null java.lang.Long input.", input); try { final Document document = documentModel.get(documentId); return toDisplay(document, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } }
|
public Object getElement(final Object input) { final Long documentId = assertNotNullLong( "The main provider's document provider requires " + "non-null java.lang.Long input.", input); try { final Document document = documentModel.get(documentId); return toDisplay(document, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } }
| 1,112,989
|
public Object getElement(final Object input) { final Long documentId = assertNotNullLong( "The main provider's document provider requires " + "non-null java.lang.Long input.", input); try { final Document document = documentModel.get(documentId); return toDisplay(document, artifactModel); } catch(final ParityException px) { throw new RuntimeException(px); } }
|
public Object getElement(final Object input) { final Long documentId = assertNotNullLong( "The main provider's document provider requires " + "non-null java.lang.Long input.", input); try { final Document document = documentModel.get(documentId); if(filter.doFilter(document)) { return null; } else { return toDisplay(document, artifactModel); } } catch(final ParityException px) { throw new RuntimeException(px); } }
| 1,112,990
|
private Boolean isDistributed(final Long containerId) { final ContainerVersion latestVersion = readLatestVersion(containerId); return null != latestVersion; }
|
private Boolean isDistributed(final Long containerId) { final ContainerVersion latestVersion = readLatestVersion(containerId); return null != latestVersion; }
| 1,112,991
|
ContainerDraft readDraft(final Long containerId) { logger.info(getApiId("[READ DRAFT]")); logger.debug(containerId); final InternalDocumentModel documentModel = getInternalDocumentModel(); final ContainerDraft draft = containerIO.readDraft(containerId); for (final Document document : draft.getDocuments()) { if (ContainerDraft.ArtifactState.NONE == draft.getState(document)) { if (documentModel.isDraftModified(document.getId())) { draft.putState(document, ContainerDraft.ArtifactState.MODIFIED); } } } return draft; }
|
ContainerDraft readDraft(final Long containerId) { logger.info(getApiId("[READ DRAFT]")); logger.debug(containerId); final InternalDocumentModel documentModel = getInternalDocumentModel(); final ContainerDraft draft = containerIO.readDraft(containerId); for (final Document document : draft.getDocuments()) { if (ContainerDraft.ArtifactState.NONE == draft.getState(document)) { if (documentModel.isDraftModified(document.getId())) { draft.putState(document, ContainerDraft.ArtifactState.MODIFIED); } } } return draft; }
| 1,112,992
|
void create(final Long containerId, final String containerName) throws ParityException { getInternalIndexModel().createContainer(containerId, containerName); }
|
void create(final Long containerId, final String containerName) throws ParityException { getInternalIndexModel().createContainer(containerId, containerName); }
| 1,112,993
|
protected void assertOnline(final StringBuffer api) { assertOnline(api.toString()); }
|
protected void assertOnline(final StringBuffer api) { assertOnline(api.toString()); }
| 1,112,994
|
void delete(final Long containerId) throws ParityException { getInternalIndexModel().deleteArtifact(containerId); }
|
void delete(final Long containerId) { getInternalIndexModel().deleteArtifact(containerId); }
| 1,112,995
|
public Container read(final Long containerId);
|
public List<Container> read();
| 1,112,996
|
public void createContainer(final Long containerId, final String containerName) throws ParityException { synchronized(getImplLock()) { getImpl().createContainer(containerId, containerName); } }
|
public void createContainer(final Long containerId, final String containerName) { synchronized(getImplLock()) { getImpl().createContainer(containerId, containerName); } }
| 1,112,997
|
void createContainer(final Long containerId, final String containerName) throws ParityException { logger.info(getApiId("[CREATE CONTAINER]")); logger.debug(containerId); logger.debug(containerName); final Set<User> team = getInternalArtifactModel().readTeam(containerId); final DocumentBuilder documentBuilder = new DocumentBuilder(6); documentBuilder.append(IDX_ARTIFACT_ID.setValue(containerId).toField()) .append(IDX_ARTIFACT_TYPE.setValue(ArtifactType.CONTAINER).toField()) .append(IDX_ARTIFACT_NAME.setValue(containerName).toField()) .append(IDX_ARTIFACT_CONTACTS.setValue(team).toField()); index(documentBuilder.toDocument()); }
|
void createContainer(final Long containerId, final String containerName) throws ParityException { logger.info(getApiId("[CREATE CONTAINER]")); logger.debug(containerId); logger.debug(containerName); final Set<User> team = getInternalArtifactModel().readTeam(containerId); final DocumentBuilder documentBuilder = new DocumentBuilder(6); documentBuilder.append(IDX_ARTIFACT_ID.setValue(containerId).toField()) .append(IDX_ARTIFACT_TYPE.setValue(ArtifactType.CONTAINER).toField()) .append(IDX_ARTIFACT_NAME.setValue(containerName).toField()) .append(IDX_ARTIFACT_CONTACTS.setValue(team).toField()); index(documentBuilder.toDocument()); }
| 1,112,998
|
void createContainer(final Long containerId, final String containerName) throws ParityException { logger.info(getApiId("[CREATE CONTAINER]")); logger.debug(containerId); logger.debug(containerName); final Set<User> team = getInternalArtifactModel().readTeam(containerId); final DocumentBuilder documentBuilder = new DocumentBuilder(6); documentBuilder.append(IDX_ARTIFACT_ID.setValue(containerId).toField()) .append(IDX_ARTIFACT_TYPE.setValue(ArtifactType.CONTAINER).toField()) .append(IDX_ARTIFACT_NAME.setValue(containerName).toField()) .append(IDX_ARTIFACT_CONTACTS.setValue(team).toField()); index(documentBuilder.toDocument()); }
|
void createContainer(final Long containerId, final String containerName) throws ParityException { logger.info(getApiId("[CREATE CONTAINER]")); logger.debug(containerId); logger.debug(containerName); final Set<User> team = getInternalArtifactModel().readTeam(containerId); final DocumentBuilder documentBuilder = new DocumentBuilder(6); documentBuilder.append(IDX_ARTIFACT_ID.setValue(containerId).toField()) .append(IDX_ARTIFACT_TYPE.setValue(ArtifactType.CONTAINER).toField()) .append(IDX_ARTIFACT_NAME.setValue(containerName).toField()) .append(IDX_ARTIFACT_CONTACTS.setValue(team).toField()); index(documentBuilder.toDocument()); }
| 1,112,999
|
private void processOfflineQueue() { assertIsReachable(environment); XMPPSession session = null; try { session = new XMPPSessionImpl(); session.login(environment, credentials); final JabberId userId = JabberIdBuilder.build( credentials.getUsername(), Constants.Jabber.DOMAIN, credentials.getResource()); session.processOfflineQueue(userId); } finally { Assert.assertNotNull(session, "User {0}'s session is null.", credentials.getUsername()); Assert.assertTrue(session.isLoggedIn(), "User {0} not logged in.", credentials.getUsername()); session.logout(); } }
|
private void processOfflineQueue() { assertIsReachable(environment); XMPPSession session = null; try { session = new XMPPSessionImpl(); session.login(environment, credentials); final JabberId userId = JabberIdBuilder.build( credentials.getUsername(), Constants.Jabber.DOMAIN, credentials.getResource()); session.processQueue(userId); } finally { Assert.assertNotNull(session, "User {0}'s session is null.", credentials.getUsername()); Assert.assertTrue(session.isLoggedIn(), "User {0} not logged in.", credentials.getUsername()); session.logout(); } }
| 1,113,000
|
public void login(final LoginMonitor monitor, final Credentials credentials) { synchronized(getImplLock()) { getImpl().login(monitor, credentials); } }
|
public void login(final LoginMonitor monitor, final Credentials credentials) { synchronized(getImplLock()) { getImpl().login(monitor, credentials); } }
| 1,113,001
|
public Group(Group group) { this(group.getFieldTag(), group.getDelimeter(), group.getFieldOrder()); setFields(group); setGroups(group); }
|
public Group(Group group) { this(group.getFieldTag(), group.getDelimeter(), group.getFieldOrder()); setFields(group); setGroups(group); }
| 1,113,002
|
public static void sortTeamMembers(final List<TeamMember> list, final Comparator<User> comparator) { Collections.sort(list, comparator); }
|
public static void sortTeamMembers(final List<TeamMember> list, final Comparator<? super User> comparator) { Collections.sort(list, comparator); }
| 1,113,003
|
public void openMainWindow() { Assert.assertIsNull("Cannot reopen main window.", mainWindow); // Schedule a job for the event-dispatching thread: creating and // showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { mainWindow = BrowserWindow.open(); displayTitleAvatar(); displayLogoAvatar(); displayMainBrowserAvatar(); displayDocumentHistoryListAvatar(); } }); }
|
public void openMainWindow() { Assert.assertIsNull("Cannot reopen main window.", mainWindow); // Schedule a job for the event-dispatching thread: creating and // showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { mainWindow = BrowserWindow.open(); displayTitleAvatar(); displayLogoAvatar(); displayMainBrowserAvatar(); displayDocumentHistoryAvatar(); } }); }
| 1,113,004
|
public void run() { mainWindow = BrowserWindow.open(); displayTitleAvatar(); displayLogoAvatar(); displayMainBrowserAvatar(); displayDocumentHistoryListAvatar(); }
|
public void run() { mainWindow = BrowserWindow.open(); displayTitleAvatar(); displayLogoAvatar(); displayMainBrowserAvatar(); displayDocumentHistoryAvatar(); }
| 1,113,005
|
public void reloadMainBrowserAvatar() { // NOTE Wierd AvatarFactory.create(AvatarId.BROWSER_MAIN).reload(); // NOTE Super wierd AvatarFactory.create(AvatarId.DOCUMENT_HISTORY_LIST).reload(); }
|
public void reloadMainBrowserAvatar() { // NOTE Wierd AvatarFactory.create(AvatarId.BROWSER_MAIN).reload(); // NOTE Super wierd AvatarFactory.create(AvatarId.DOCUMENT_HISTORY).reload(); }
| 1,113,006
|
public void selectDocument(final Long documentId) { setInput(AvatarId.DOCUMENT_HISTORY_LIST, documentId); setInput(AvatarId.SESSION_SEND_FORM, documentId); setInput(AvatarId.SESSION_SEND_KEY_FORM, documentId); }
|
public void selectDocument(final Long documentId) { setInput(AvatarId.DOCUMENT_HISTORY, documentId); setInput(AvatarId.SESSION_SEND_FORM, documentId); setInput(AvatarId.SESSION_SEND_KEY_FORM, documentId); }
| 1,113,007
|
private void reloadConnection() { connectionJLabel.setText(""); final Connection connection = getInputConnection(); if (null != connection) { final String connectionText; switch(getInputConnection()) { case ONLINE: connectionJLabel.setForeground(Colors.Browser.MainStatus.CONNECTION_FOREGROUND_ONLINE); if (null != profile) { connectionText = profile.getName(); } else { connectionText = getString(Connection.ONLINE); } break; case OFFLINE: connectionJLabel.setForeground(Colors.Browser.MainStatus.CONNECTION_FOREGROUND_OFFLINE); connectionText = getString(Connection.OFFLINE); break; default: throw Assert.createUnreachable("UNKNOWN CONNECTION"); } connectionJLabel.setText(connectionText); } }
|
private void reloadConnection() { connectionJLabel.setText(""); final Connection connection = getInputConnection(); if (null != connection) { final String connectionText; switch(getInputConnection()) { case ONLINE: connectionJLabel.setForeground(Colors.Browser.MainStatus.CONNECTION_FOREGROUND_ONLINE); if (null != profile) { connectionText = profile.getName(); } else { connectionText = getString(Connection.ONLINE); } break; case OFFLINE: connectionJLabel.setForeground(Colors.Browser.MainStatus.CONNECTION_FOREGROUND_OFFLINE); connectionText = getString(Connection.OFFLINE); break; default: throw Assert.createUnreachable("UNKNOWN CONNECTION"); } connectionJLabel.setText(connectionText); } }
| 1,113,008
|
protected void paintComponent(final Graphics g) { super.paintComponent(g); if (isRoundCorners()) { final Graphics g2 = g.create(); try { // These images help to make the rounded corners look good. g2.drawImage(Images.BrowserTitle.DIALOG_TOP_LEFT_INNER, 0, 0, Images.BrowserTitle.DIALOG_TOP_LEFT_INNER.getWidth(), Images.BrowserTitle.DIALOG_TOP_LEFT_INNER.getHeight(), this); g2.drawImage(Images.BrowserTitle.DIALOG_BOTTOM_LEFT_INNER, 0, getSize().height - Images.BrowserTitle.DIALOG_BOTTOM_LEFT_INNER.getHeight(), Images.BrowserTitle.DIALOG_BOTTOM_LEFT_INNER.getWidth(), Images.BrowserTitle.DIALOG_BOTTOM_LEFT_INNER.getHeight(), this); g2.drawImage(Images.BrowserTitle.DIALOG_TOP_RIGHT_INNER, getSize().width - Images.BrowserTitle.DIALOG_TOP_RIGHT_INNER.getWidth(), 0, Images.BrowserTitle.DIALOG_TOP_RIGHT_INNER.getWidth(), Images.BrowserTitle.DIALOG_TOP_RIGHT_INNER.getHeight(), this); g2.drawImage(Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER, getSize().width - Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER.getWidth(), getSize().height - Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER.getHeight(), Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER.getWidth(), Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER.getHeight(), this); } finally { g2.dispose(); } } }
|
protected void paintComponent(final Graphics g) { super.paintComponent(g); if (nativeSkin.isRounded()) { final Graphics g2 = g.create(); try { // These images help to make the rounded corners look good. g2.drawImage(Images.BrowserTitle.DIALOG_TOP_LEFT_INNER, 0, 0, Images.BrowserTitle.DIALOG_TOP_LEFT_INNER.getWidth(), Images.BrowserTitle.DIALOG_TOP_LEFT_INNER.getHeight(), this); g2.drawImage(Images.BrowserTitle.DIALOG_BOTTOM_LEFT_INNER, 0, getSize().height - Images.BrowserTitle.DIALOG_BOTTOM_LEFT_INNER.getHeight(), Images.BrowserTitle.DIALOG_BOTTOM_LEFT_INNER.getWidth(), Images.BrowserTitle.DIALOG_BOTTOM_LEFT_INNER.getHeight(), this); g2.drawImage(Images.BrowserTitle.DIALOG_TOP_RIGHT_INNER, getSize().width - Images.BrowserTitle.DIALOG_TOP_RIGHT_INNER.getWidth(), 0, Images.BrowserTitle.DIALOG_TOP_RIGHT_INNER.getWidth(), Images.BrowserTitle.DIALOG_TOP_RIGHT_INNER.getHeight(), this); g2.drawImage(Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER, getSize().width - Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER.getWidth(), getSize().height - Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER.getHeight(), Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER.getWidth(), Images.BrowserTitle.DIALOG_BOTTOM_RIGHT_INNER.getHeight(), this); } finally { g2.dispose(); } } }
| 1,113,010
|
public void setUtcTimeOnly(int field, Date value, boolean includeMillseconds) { String s = FieldValueConverter.UtcTimeOnlyConverter.convert(value, includeMillseconds); setField(new StringField(field, s)); }
|
public void setUtcTimeOnly(int field, Date value, boolean includeMillseconds) { String s = FieldValueConverter.UtcTimeOnlyConverter.convert(value, includeMillseconds); setField(new StringField(field, s)); }
| 1,113,011
|
public void service() { logApiId(); final User user = read(readJabberId("userId")); logVariable("user", user); if (null != user) { writeJabberId("id", user.getId()); writeString("name", user.getName()); if (user.isSetOrganization()) writeString("organization", user.getOrganization()); if (user.isSetTitle()) writeString("title", user.getTitle()); } }
|
public void service() { logApiId(); final User user = read(readJabberId("userId")); logger.logVariable("user", user); if (null != user) { writeJabberId("id", user.getId()); writeString("name", user.getName()); if (user.isSetOrganization()) writeString("organization", user.getOrganization()); if (user.isSetTitle()) writeString("title", user.getTitle()); } }
| 1,113,013
|
static void notifyArtifactClosed(final UUID artifactUniqueId) { try { DocumentModel.getInternalModel(sContext).close(artifactUniqueId); } catch(final ParityException px) { sLogger.fatal("Could not close artifact.", px); return; } }
|
static void notifyArtifactClosed(final UUID artifactUniqueId) { try { DocumentModel.getInternalModel(sContext).close(artifactUniqueId); } catch(final ParityException px) { sLogger.fatal("Could not close artifact.", px); return; } }
| 1,113,014
|
static void notifyKeyRequested(final UUID artifactUniqueId, final JabberId requestedBy) { try { final Document document = DocumentModel.getInternalModel(sContext).get(artifactUniqueId); SystemMessageModel.getInternalModel(sContext).createKeyRequest(document.getId(), requestedBy); } catch(final ParityException px) { sLogger.error("Could not create system message for key request.", px); return; } }
|
static void notifyKeyRequested(final UUID artifactUniqueId, final JabberId requestedBy) { try { final Document document = DocumentModel.getInternalModel(sContext).get(artifactUniqueId); SystemMessageModel.getInternalModel(sContext).createKeyRequest(document.getId(), requestedBy); } catch(final ParityException px) { sLogger.error("Could not process key request: " + artifactUniqueId, px); return; } }
| 1,113,015
|
public User(final JabberId id) { super(); this.id = id; }
|
public User(final JabberId id) { super(); this.id = id; }
| 1,113,018
|
public void createPublishedTo(final Long containerId, final Long versionId, final List<User> publishedTo) { final Session session = openSession(); try { session.prepareStatement(SQL_CREATE_PUBLISHED_TO); session.setLong(1, containerId); session.setLong(2, versionId); for (final User publishedToUser : publishedTo) { session.setLong(3, publishedToUser.getLocalId()); if (1 != session.executeUpdate()) throw new HypersonicException("Could not create published to entry."); } session.commit(); } catch (final HypersonicException hx) { session.rollback(); throw hx; } finally { session.close(); } }
|
public void createPublishedTo(final Long containerId, final Long versionId, final List<User> publishedTo) { final Session session = openSession(); try { session.prepareStatement(SQL_CREATE_PUBLISHED_TO); session.setLong(1, containerId); session.setLong(2, versionId); for (final User publishedToUser : publishedTo) { session.setLong(3, publishedToUser.getLocalId()); if (1 != session.executeUpdate()) throw new HypersonicException("Could not create published to entry."); } session.commit(); } catch (final HypersonicException hx) { session.rollback(); throw hx; } finally { session.close(); } }
| 1,113,019
|
public void createPublishedTo(final Long containerId, final Long versionId, final List<User> publishedTo) { final Session session = openSession(); try { session.prepareStatement(SQL_CREATE_PUBLISHED_TO); session.setLong(1, containerId); session.setLong(2, versionId); for (final User publishedToUser : publishedTo) { session.setLong(3, publishedToUser.getLocalId()); if (1 != session.executeUpdate()) throw new HypersonicException("Could not create published to entry."); } session.commit(); } catch (final HypersonicException hx) { session.rollback(); throw hx; } finally { session.close(); } }
|
public void createPublishedTo(final Long containerId, final Long versionId, final List<User> publishedTo) { final Session session = openSession(); try { session.prepareStatement(SQL_CREATE_PUBLISHED_TO); session.setLong(1, containerId); session.setLong(2, versionId); for (final User publishedToUser : publishedTo) { session.setLong(3, publishedToUser.getLocalId()); if (1 != session.executeUpdate()) throw new HypersonicException("Could not create published to entry."); } session.commit(); } catch (final HypersonicException hx) { session.rollback(); throw hx; } finally { session.close(); } }
| 1,113,020
|
public PreparedStatement prepareStatement(final String sql) { assertOpen("prepareStatement(String)"); logger.logVariable("sql", sql); try { preparedStatement = connection.prepareStatement(sql); return preparedStatement; } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public PreparedStatement prepareStatement(final String sql) { assertOpen("prepareStatement(String)"); logger.logVariable("sql", sql); try { preparedStatement = connection.prepareStatement(sql); return preparedStatement; } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,021
|
public PreparedStatement prepareStatement(final String sql) { assertOpen("prepareStatement(String)"); logger.logVariable("sql", sql); try { preparedStatement = connection.prepareStatement(sql); return preparedStatement; } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public PreparedStatement prepareStatement(final String sql) { assertOpen("prepareStatement(String)"); logger.logVariable("sql", sql); try { preparedStatement = connection.prepareStatement(sql); return preparedStatement; } }
| 1,113,022
|
public void setLong(final Integer index, final Long value) { assertOpen("setLong(Integer,Long)"); assertPreparedStatement("setLong(Integer,Long)"); logIndexAndValue(index, value); try { preparedStatement.setLong(index, value); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public void setLong(final Integer index, final Long value) { assertOpen("setLong(Integer,Long)"); assertPreparedStatement("setLong(Integer,Long)"); logIndexAndValue(index, value); try { preparedStatement.setLong(index, value); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,023
|
public void executeQuery() { assertOpen("Cannot execute query if the session is not open."); assertPreparedStatement("Cannot execute query if the statement is not prepared."); try { resultSet = preparedStatement.executeQuery(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public void executeQuery() { assertOpen("Cannot execute query if the session is not open."); assertPreparedStatement("Cannot execute query if the statement is not prepared."); try { resultSet = preparedStatement.executeQuery(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,024
|
public boolean nextResult() { assertOpen("nextResult()"); assertOpenResult("nextResult()"); try { return resultSet.next(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public boolean nextResult() { assertOpen("nextResult()"); assertOpenResult("nextResult()"); try { return resultSet.next(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,025
|
public ContainerDraft.ArtifactState getContainerStateFromString( final String columnName) { assertOpen("getStateFromString(String)"); assertOpenResult("getStateFromString(String)"); logger.logVariable("columnName", columnName); try { final String value = resultSet.getString(columnName); return resultSet.wasNull() ? null : ContainerDraft.ArtifactState.valueOf(value); } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public ContainerDraft.ArtifactState getContainerStateFromString( final String columnName) { assertOpen("getStateFromString(String)"); assertOpenResult("getStateFromString(String)"); logger.logVariable("columnName", columnName); try { final String value = resultSet.getString(columnName); return resultSet.wasNull() ? null : ContainerDraft.ArtifactState.valueOf(value); } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,026
|
public void close() { assertOpen("Cannot close a closed session."); try { close(preparedStatement, resultSet); connection.close(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } sessionManager.close(this); }
|
public void close() { assertOpen("Cannot close a closed session."); try { close(preparedStatement, resultSet); connection.close(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } sessionManager.close(this); }
| 1,113,028
|
public int executeUpdate() { assertOpen("executeUpdate()"); assertPreparedStatement("executeUpdate()"); try { return preparedStatement.executeUpdate(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public int executeUpdate() { assertOpen("executeUpdate()"); assertPreparedStatement("executeUpdate()"); try { return preparedStatement.executeUpdate(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,029
|
public void commit() { assertOpen("commit()"); try { connection.commit(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public void commit() { assertOpen("commit()"); try { connection.commit(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,030
|
public void rollback() { assertOpen("rollbackSession()"); try { connection.commit(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public void rollback() { assertConnectionIsOpen(); try { connection.commit(); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,031
|
public Long getIdentity() { ResultSet resultSet = null; try { resultSet = list("CALL IDENTITY()"); resultSet.next(); return resultSet.getLong(1); } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } finally { close(resultSet); } }
|
public Long getIdentity() { ResultSet resultSet = null; try { resultSet = list("CALL IDENTITY()"); resultSet.next(); return resultSet.getLong(1); } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } finally { close(resultSet); } }
| 1,113,032
|
public void setEnumTypeAsString(final Integer index, final Enum<?> value) { assertOpen("setEnumAsString(Integer,Enum<?>)"); assertPreparedStatement("setEnumAsString(Integer,Enum<?>)"); logIndexAndValue(index, value); try { preparedStatement.setString(index, value.toString()); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public void setEnumTypeAsString(final Integer index, final Enum<?> value) { assertOpen("setEnumAsString(Integer,Enum<?>)"); assertPreparedStatement("setEnumAsString(Integer,Enum<?>)"); logIndexAndValue(index, value); try { preparedStatement.setString(index, value.toString()); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,033
|
void createVersion(final Session session, final ArtifactVersion version) { session.prepareStatement(INSERT_ARTIFACT_VERSION); session.setLong(1, version.getArtifactId()); session.setLong(2, version.getVersionId()); session.setString(3, version.getName()); session.setTypeAsString(4, version.getArtifactType()); session.setUniqueId(5, version.getArtifactUniqueId()); session.setLong(6, readLocalId(version.getCreatedBy())); session.setCalendar(7, version.getCreatedOn()); session.setLong(8, readLocalId(version.getUpdatedBy())); session.setCalendar(9, version.getUpdatedOn()); if(1 != session.executeUpdate()) throw new HypersonicException("Could not create version."); setVersionMetaData(session, version.getArtifactId(), version .getVersionId(), version.getMetaData()); }
|
void createVersion(final Session session, final ArtifactVersion version) { session.prepareStatement(INSERT_ARTIFACT_VERSION); session.setLong(1, version.getArtifactId()); session.setLong(2, version.getVersionId()); session.setString(3, version.getName()); session.setTypeAsString(4, version.getArtifactType()); session.setUniqueId(5, version.getArtifactUniqueId()); session.setLong(6, readLocalId(version.getCreatedBy())); session.setCalendar(7, version.getCreatedOn()); session.setLong(8, readLocalId(version.getUpdatedBy())); session.setCalendar(9, version.getUpdatedOn()); if(1 != session.executeUpdate()) throw new HypersonicException("Could not create version."); setVersionMetaData(session, version.getArtifactId(), version .getVersionId(), version.getMetaData()); }
| 1,113,034
|
public Long getLong(final String columnName) { assertOpen("getLong(String)"); assertOpenResult("getLong(String)"); logger.logVariable("columnName", columnName); try { final Long value = resultSet.getLong(columnName); return resultSet.wasNull() ? null : value; } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public Long getLong(final String columnName) { assertOpen("getLong(String)"); assertOpenResult("getLong(String)"); logger.logVariable("columnName", columnName); try { final Long value = resultSet.getLong(columnName); return resultSet.wasNull() ? null : value; } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,035
|
public String getString(final String columnName) { assertOpen("getString(String)"); assertOpenResult("getString(String)"); logger.logVariable("columnName", columnName); try { final String value = resultSet.getString(columnName); return resultSet.wasNull() ? null : value; } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public String getString(final String columnName) { assertOpen("getString(String)"); assertOpenResult("getString(String)"); logger.logVariable("columnName", columnName); try { final String value = resultSet.getString(columnName); return resultSet.wasNull() ? null : value; } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,037
|
public JabberId getQualifiedUsername(final String columnName) { assertOpen("Cannot get values if the session is not open."); assertOpenResult("Cannot get values if the result is not open."); logger.logVariable("columnName", columnName); try { final String value = resultSet.getString(columnName); if (resultSet.wasNull()) { return null; } else { return JabberIdBuilder.parse(value); } } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } catch (final IllegalArgumentException iax) { throw new HypersonicException(iax); } }
|
public JabberId getQualifiedUsername(final String columnName) { assertOpen("Cannot get values if the session is not open."); assertOpenResult("Cannot get values if the result is not open."); logger.logVariable("columnName", columnName); try { final String value = resultSet.getString(columnName); if (resultSet.wasNull()) { return null; } else { return JabberIdBuilder.parse(value); } } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } catch (final IllegalArgumentException iax) { throw new HypersonicException(iax); } }
| 1,113,039
|
public Calendar getCalendar(final String columnName) { assertOpen("getCalendar(String)"); assertOpenResult("getCalendar(String)"); try { final Calendar calendar = DateUtil.getInstance(); final Timestamp timestamp = resultSet.getTimestamp(columnName, calendar); if (resultSet.wasNull()) { return null; } else { calendar.setTime(timestamp); return calendar; } } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public Calendar getCalendar(final String columnName) { assertOpen("getCalendar(String)"); assertOpenResult("getCalendar(String)"); try { final Calendar calendar = DateUtil.getInstance(); final Timestamp timestamp = resultSet.getTimestamp(columnName, calendar); if (resultSet.wasNull()) { return null; } else { calendar.setTime(timestamp); return calendar; } } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,041
|
public Calendar getCalendar(final String columnName) { assertOpen("getCalendar(String)"); assertOpenResult("getCalendar(String)"); try { final Calendar calendar = DateUtil.getInstance(); final Timestamp timestamp = resultSet.getTimestamp(columnName, calendar); if (resultSet.wasNull()) { return null; } else { calendar.setTime(timestamp); return calendar; } } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public Calendar getCalendar(final String columnName) { assertOpen("getCalendar(String)"); assertOpenResult("getCalendar(String)"); try { final Calendar calendar = DateUtil.getInstance(); final Timestamp timestamp = resultSet.getTimestamp(columnName, calendar); if (resultSet.wasNull()) { return null; } else { calendar.setTime(timestamp); return calendar; } } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,042
|
public Calendar getCalendar(final String columnName) { assertOpen("getCalendar(String)"); assertOpenResult("getCalendar(String)"); try { final Calendar calendar = DateUtil.getInstance(); final Timestamp timestamp = resultSet.getTimestamp(columnName, calendar); if (resultSet.wasNull()) { return null; } else { calendar.setTime(timestamp); return calendar; } } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public Calendar getCalendar(final String columnName) { assertOpen("getCalendar(String)"); assertOpenResult("getCalendar(String)"); try { final Calendar calendar = DateUtil.getInstance(); final Timestamp timestamp = resultSet.getTimestamp(columnName, calendar); if (resultSet.wasNull()) { return null; } else { calendar.setTime(timestamp); return calendar; } } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,043
|
public ArtifactState getStateFromInteger(final String columnName) { assertOpen("getStateFromInteger(String)"); assertOpenResult("getStateFromInteger(String)"); logger.logVariable("columnName", columnName); try { final Integer value = resultSet.getInt(columnName); return resultSet.wasNull() ? null : ArtifactState.fromId(value); } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public ArtifactState getStateFromInteger(final String columnName) { assertOpen("getStateFromInteger(String)"); assertOpenResult("getStateFromInteger(String)"); logger.logVariable("columnName", columnName); try { final Integer value = resultSet.getInt(columnName); return resultSet.wasNull() ? null : ArtifactState.fromId(value); } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,044
|
public ArtifactType getTypeFromInteger(final String columnName) { assertOpen("getTypeFromInteger(String)"); assertOpenResult("getTypeFromInteger(String)"); logger.logVariable("columnName", columnName); try { final Integer value = resultSet.getInt(columnName); return resultSet.wasNull() ? null : ArtifactType.fromId(value); } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public ArtifactType getTypeFromInteger(final String columnName) { assertOpen("getTypeFromInteger(String)"); assertOpenResult("getTypeFromInteger(String)"); logger.logVariable("columnName", columnName); try { final Integer value = resultSet.getInt(columnName); return resultSet.wasNull() ? null : ArtifactType.fromId(value); } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,046
|
public UUID getUniqueId(final String columnName) { assertOpen("getString(String)"); assertOpenResult("getString(String)"); final String value = getString(columnName); return null == value ? null : UUID.fromString(value); }
|
public UUID getUniqueId(final String columnName) { assertOpen("getString(String)"); assertOpenResult("getString(String)"); final String value = getString(columnName); return null == value ? null : UUID.fromString(value); }
| 1,113,048
|
public Integer getInteger(final String columnName) { assertOpen("[LMODEL] [IO] [HSQL] [GET INTEGER]"); assertOpenResult("[LMODEL] [IO] [HSQL] [GET INTEGER]"); logger.logVariable("columnName", columnName); try { final Integer value = resultSet.getInt(columnName); return resultSet.wasNull() ? null : value; } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public Integer getInteger(final String columnName) { assertOpen("[LMODEL] [IO] [HSQL] [GET INTEGER]"); assertOpenResult("[LMODEL] [IO] [HSQL] [GET INTEGER]"); logger.logVariable("columnName", columnName); try { final Integer value = resultSet.getInt(columnName); return resultSet.wasNull() ? null : value; } catch (final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,049
|
public void setString(final Integer index, final String value) { assertOpen("setString(Integer,String)"); assertPreparedStatement("setString(Integer,String)"); logIndexAndValue(index, value); try { preparedStatement.setString(index, value); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public void setString(final Integer index, final String value) { assertOpen("setString(Integer,String)"); assertPreparedStatement("setString(Integer,String)"); logIndexAndValue(index, value); try { preparedStatement.setString(index, value); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,051
|
public void setCalendar(final Integer index, final Calendar value) { assertOpen("setCalendar(Integer,Calendar)"); assertPreparedStatement("setCalendar(Integer,Calendar)"); logIndexAndValue(index, value); try { preparedStatement.setTimestamp(index, new Timestamp(value.getTimeInMillis()), value); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public void setCalendar(final Integer index, final Calendar value) { assertOpen("setCalendar(Integer,Calendar)"); assertPreparedStatement("setCalendar(Integer,Calendar)"); logIndexAndValue(index, value); try { preparedStatement.setTimestamp(index, new Timestamp(value.getTimeInMillis()), value); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
| 1,113,052
|
public void setCalendar(final Integer index, final Calendar value) { assertOpen("setCalendar(Integer,Calendar)"); assertPreparedStatement("setCalendar(Integer,Calendar)"); logIndexAndValue(index, value); try { preparedStatement.setTimestamp(index, new Timestamp(value.getTimeInMillis()), value); } catch(final SQLException sqlx) { throw new HypersonicException(sqlx); } }
|
public void setCalendar(final Integer index, final Calendar value) { assertOpen("setCalendar(Integer,Calendar)"); assertPreparedStatement("setCalendar(Integer,Calendar)"); logIndexAndValue(index, value); try { preparedStatement.setTimestamp(index, new Timestamp(value.getTimeInMillis()), value); } }
| 1,113,053
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,054
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,055
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,056
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long DMGBlock currentBlock = new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize); blocks.add(currentBlock); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,057
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,058
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,059
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,060
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(inBuffer, 0, Math.min((int)inSize, inBuffer.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,061
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,062
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(inBuffer, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,063
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(tmp, 0, Math.min((int)(inSize-totalBytesRead), tmp.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
|
public static void notmain(String[] args) throws Exception { System.setProperty("swing.aatext", "true"); //Antialiased text try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) {} if(DEBUG) verbose = true; parseArgs(args); printlnVerbose("Processing: " + dmgFile); RandomAccessFile dmgRaf = new RandomAccessFile(dmgFile, "r"); RandomAccessFile isoRaf = null; boolean testOnly = false; if(isoFile != null) { isoRaf = new RandomAccessFile(isoFile, "rw"); isoRaf.setLength(0); printlnVerbose("Extracting to: " + isoFile); } else { testOnly = true; printlnVerbose("Simulating extraction..."); } dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_1); long plistBegin1 = dmgRaf.readLong(); long plistEnd = dmgRaf.readLong(); dmgRaf.seek(dmgRaf.length()-PLIST_ADDRESS_2); long plistBegin2 = dmgRaf.readLong(); long plistSize = dmgRaf.readLong(); if(DEBUG) { println("Read addresses:", " " + plistBegin1, " " + plistBegin2); } if(plistBegin1 != plistBegin2) { println("Addresses not equal! Assumption broken... =/", plistBegin1 + " != " + plistBegin2); System.exit(0); } if(plistSize != (plistEnd-plistBegin1)) { println("plistSize field does not match plistEnd marker!", "plistSize=" + plistSize + " plistBegin1=" + plistBegin1 + " plistEnd=" + plistEnd + " plistEnd-plistBegin1=" + (plistEnd-plistBegin1)); } printlnVerbose("Jumping to address..."); dmgRaf.seek(plistBegin1); byte[] buffer = new byte[(int)plistSize]; dmgRaf.read(buffer); InputStream is = new ByteArrayInputStream(buffer); NodeBuilder handler = new NodeBuilder(); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); try {// System.out.println("validation: " + saxParser.getProperty("validation"));// System.out.println("external-general-entities: " + saxParser.getProperty("external-general-entities"));// System.out.println("external-parameter-entities: " + saxParser.getProperty("external-parameter-entities"));// System.out.println("is-standalone: " + saxParser.getProperty("is-standalone"));// System.out.println("lexical-handler: " + saxParser.getProperty("lexical-handler"));// System.out.println("parameter-entities: " + saxParser.getProperty("parameter-entities"));// System.out.println("namespaces: " + saxParser.getProperty("namespaces"));// System.out.println("namespace-prefixes: " + saxParser.getProperty("namespace-prefixes"));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println(": " + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty(""));// System.out.println("" + saxParser.getProperty("")); System.out.println("isValidating: " + saxParser.isValidating()); saxParser.parse(is, handler); } catch(SAXException se) { se.printStackTrace(); System.err.println("Could not read the partition list... exiting."); System.exit(1); } XMLNode[] rootNodes = handler.getRoots(); if(rootNodes.length != 1) { println("Could not parse DMG-file!"); System.exit(0); } /* Ok, now we have a tree built from the XML-document. Let's walk to the right place. */ /* cd plist cd dict cdkey resource-fork (type:dict) cdkey blkx (type:array) */ XMLNode current; XMLElement[] children; boolean keyFound; current = rootNodes[0]; //We are at plist... probably (there should be only one root node) current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); printlnVerbose("Found " + current.getChildren().length + " partitions:"); byte[] tmp = new byte[0x40000]; byte[] otmp = new byte[0x40000]; byte[] zeroblock = new byte[4096]; /* I think java always zeroes its arrays on creation... but let's play safe. */ for(int y = 0; y < zeroblock.length; ++y) zeroblock[y] = 0; LinkedList<DMGBlock> blocks = new LinkedList<DMGBlock>(); //long lastOffs = 0; long lastOutOffset = 0; long lastInOffset = 0; long totalSize = 0; boolean errorsFound = false; reportProgress(0); for(XMLElement xe : current.getChildren()) { if(progmon != null && progmon.isCanceled()) System.exit(0); if(xe instanceof XMLNode) { XMLNode xn = (XMLNode)xe; byte[] data = Base64.decode(xn.getKeyValue("Data")); long partitionSize = calculatePartitionSize(data); totalSize += partitionSize; printlnVerbose(" " + xn.getKeyValue("Name")); printlnVerbose(" ID: " + xn.getKeyValue("ID")); printlnVerbose(" Attributes: " + xn.getKeyValue("Attributes")); printlnVerbose(" Partition map data length: " + data.length + " bytes"); printlnVerbose(" Partition size: " + partitionSize + " bytes"); if(verbose) { printlnVerbose(" Dumping blkx..."); FileOutputStream fos = new FileOutputStream(xn.getKeyValue("ID") + ".blkx"); fos.write(data); fos.close(); } if(DEBUG) { File dumpFile = new File("data " + xn.getKeyValue("ID") + ".bin"); println(" Dumping partition map to file: " + dumpFile); FileOutputStream dump = new FileOutputStream(dumpFile); dump.write(data); dump.close(); } int offset = 0xCC; int blockType = 0; /* Offset of the input data for the current block in the input file */ long inOffset = 0; /* Size of the input data for the current block */ long inSize = 0; /* Offset of the output data for the current block in the output file */ long outOffset = 0; /* Size of the output data (possibly larger than inSize because of decompression, zero expansion...) */ long outSize = 0; long lastByteReadInBlock = -1; boolean addInOffset = false; //, lastInOffs = 0; int blockCount = 0; long previousPercentage = -1; while(blockType != BT_END) { if(progmon != null && progmon.isCanceled()) System.exit(0); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while(bytesSkipped < offset) bytesSkipped += dis.skipBytes(offset-bytesSkipped); blockType = dis.readInt(); int skipped = dis.readInt(); //Skip 4 bytes forward outOffset = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward outSize = dis.readLong()*0x200;//(dis.readInt() & 0xffffffffL)*0x200; //unsigned int -> long inOffset = dis.readLong();// & 0xffffffffL; //unsigned int -> long //dis.readInt(); //Skip 4 bytes forward inSize = dis.readLong();//dis.readInt() & 0xffffffffL; //unsigned int -> long blocks.add(new DMGBlock(blockType, skipped, outOffset, outSize, inOffset, inSize)); if(lastByteReadInBlock == -1) lastByteReadInBlock = inOffset; lastByteReadInBlock += inSize; /* The lines below are a "hack" that I had to do to make dmgx work with certain dmg-files. I don't understand the issue at all, which is why this hack is here, but sometimes inOffset == 0 means that it is 0 relative to the previous partition's last inOffset. And sometimes it doesn't (meaning the actual position 0 in the dmg file). */ if(addInOffset) inOffset += lastInOffset; else if(inOffset == 0) { addInOffset = true; inOffset += lastInOffset; } outOffset += lastOutOffset; if(DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset /*+ " lastInOffs=" + lastInOffs + " lastOffs=" + lastOffs*/); } if(blockType == BT_ADC) { println(" " + blockCount + ". BT_ADC not supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_ZLIB) { if(DEBUG) println(" " + blockCount + ". BT_ZLIB processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZLIB FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); if(tmp.length < inSize) tmp = new byte[(int)inSize]; long totalBytesRead = 0; while(totalBytesRead < inSize) { totalBytesRead += dmgRaf.read(tmp, (int)totalBytesRead, Math.min((int)(inSize-totalBytesRead), tmp.length)); } long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } Inflater inflater = new Inflater(); inflater.setInput(tmp, 0, (int)totalBytesRead); if(otmp.length < outSize) otmp = new byte[(int)outSize]; int bytesInflated = 0; while(true) { try { int counter = 0; while(bytesInflated < outSize && counter++ < 10) { int old = bytesInflated; bytesInflated += inflater.inflate(otmp, bytesInflated, (int)(outSize-bytesInflated)); if(old == bytesInflated) println("Nothing new! finished()=" + inflater.finished() + " needsInput()=" + inflater.needsInput() + " needsDictionary()=" + inflater.needsDictionary() + " getAdler()=" + inflater.getAdler() + " getBytesRead()=" + inflater.getBytesRead() + " getBytesWritten()=" + inflater.getBytesWritten() + " getRemaining()=" + inflater.getRemaining()); } //System.out.println(" Inflated " + bytesInflated + " bytes. Left in buffer: " + inflater.getRemaining() + " bytes inSize="+inSize+" outSize="+outSize); if(inflater.getRemaining() == 0) { //System.out.println(" done!"); break; } else { println(" " + blockCount + ". BT_ZLIB ERROR: otmp contents lost! (should not happen...)", " outSize=" + outSize + " inSize=" + inSize + " tmp.length=" + tmp.length + " otmp.length=" + otmp.length + " bytesInflated=" + bytesInflated + " inflater.getRemaining()=" + inflater.getRemaining());// if(bytesInflated == 0) throw new RuntimeException("WTF"); } } catch(DataFormatException dfe) { println(" " + blockCount + ". BT_ZLIB Could not decode..."); if(!DEBUG) { println("outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize + " lastOutOffset=" + lastOutOffset + " lastInOffset=" + lastInOffset); } dfe.printStackTrace(); if(!testOnly) System.exit(0); else { println(" Testing mode, so continuing..."); //System.exit(0); errorsFound = true; break; } } } inflater.end(); if(!testOnly) isoRaf.write(otmp, 0, (int)outSize); //lastInOffs = inOffset+inSize; } else if(blockType == BT_BZIP2) { println(" " + blockCount + ". BT_BZIP2 not currently supported."); if(!testOnly) System.exit(0); } else if(blockType == BT_COPY) { if(DEBUG) println(" " + blockCount + ". BT_COPY processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_COPY FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); dmgRaf.seek(/*lastOffs+*/inOffset); int bytesRead = dmgRaf.read(tmp, 0, Math.min((int)inSize, tmp.length)); long totalBytesRead = bytesRead; while(bytesRead != -1) { long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } if(!testOnly) isoRaf.write(tmp, 0, bytesRead); if(totalBytesRead >= inSize) break; bytesRead = dmgRaf.read(inBuffer, 0, Math.min((int)(inSize-totalBytesRead), inBuffer.length)); if(bytesRead > 0) totalBytesRead += bytesRead; } //lastInOffs = inOffset+inSize; } else if(blockType == BT_ZERO) { if(DEBUG) println(" " + blockCount + ". BT_ZERO processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_ZERO FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); long progressPercentage = dmgRaf.getFilePointer()*100/dmgRaf.length(); if(progressPercentage != previousPercentage) { reportProgress(progressPercentage); previousPercentage = progressPercentage; } long numberOfZeroBlocks = outSize/zeroblock.length; int numberOfRemainingBytes = (int)(outSize%zeroblock.length); for(int j = 0; j < numberOfZeroBlocks; ++j) { if(!testOnly) isoRaf.write(zeroblock); } if(!testOnly) isoRaf.write(zeroblock, 0, numberOfRemainingBytes); //lastInOffs = inOffset+inSize; } else if(blockType == BT_UNKNOWN) { /* I have no idea what this blocktype is... but it's common, and usually doesn't appear more than 2-3 times in a dmg. As long as its input and output sizes are 0, there's no reason to complain... is there? */ if(DEBUG) println(" " + blockCount + ". BT_UNKNOWN processing..."); if(!(inSize == 0 && outSize == 0)) { println(" " + blockCount + ". WARNING! Blocktype BT_UNKNOWN had non-zero sizes...", " inSize=" + inSize + ", outSize=" + outSize); //println(" The author of the program would be pleased if you contacted him about this."); // ...or would I? } } else if(blockType == BT_END) { if(DEBUG) println(" " + blockCount + ". BT_END processing..."); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". BT_END FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); //lastOffs += lastInOffs; lastOutOffset = outOffset; lastInOffset += lastByteReadInBlock; } else { println(" " + blockCount + ". WARNING: previously unseen blocktype " + blockType + " [0x" + Integer.toHexString(blockType) + "]", " " + blockCount + ". outOffset=" + outOffset + " outSize=" + outSize + " inOffset=" + inOffset + " inSize=" + inSize); if(!testOnly && isoRaf.getFilePointer() != outOffset) println(" " + blockCount + ". unknown blocktype FP != outOffset (" + isoRaf.getFilePointer() + " != " + outOffset + ")"); } offset += 0x28; ++blockCount; } } } //printlnVerbose("Progress: 100% Done!"); reportProgress(100); String errors = errorsFound?"There were errors...":"No errors reported."; if(!graphical) { newline(); println(errors); printlnVerbose("Total extracted bytes: " + totalSize + " B"); } else { progmon.close(); JOptionPane.showMessageDialog(null, "Extraction complete! " + errors + "\n" + "Total extracted bytes: " + totalSize + " B", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }// System.out.println("blocks.size()=" + blocks.size());// for(DMGBlock b : blocks)// System.out.println(" " + b.toString()); LinkedList<DMGBlock> merged = mergeBlocks(blocks);// System.out.println("merged.size()=" + merged.size());// for(DMGBlock b : merged)// System.out.println(" " + b.toString()); System.out.println("Extracting all the parts not containing block data from source file:"); int i = 1; DMGBlock previous = null; for(DMGBlock b : merged) { if(previous == null && b.inOffset > 0) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(0); byte[] data = new byte[(int)(b.inOffset)]; dmgRaf.read(data); curFos.write(data); curFos.close(); } else if(previous != null) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(b.inOffset-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } previous = b; } if(previous.inOffset+previous.inSize != dmgRaf.length()) { String filename = i++ + ".block"; System.out.print(" " + filename + "..."); FileOutputStream curFos = new FileOutputStream(new File(filename)); dmgRaf.seek(previous.inOffset+previous.inSize); byte[] data = new byte[(int)(dmgRaf.length()-(previous.inOffset+previous.inSize))]; dmgRaf.read(data); curFos.write(data); curFos.close(); } dmgRaf.close(); System.out.println("done!"); }
| 1,113,064
|
public static void reportProgress(long progressPercentage) { if(!graphical) { printCurrentLine("--->Progress: " + progressPercentage + "%"); } else { if(progmon == null) { progmon = new ProgressMonitor(null, "Extracting dmg to iso...", "0%", 0, 100); progmon.setProgress(0); progmon.setMillisToPopup(0); } progmon.setProgress((int)progressPercentage); progmon.setNote(progressPercentage + "%"); } }
|
public static void reportProgress(long progressPercentage) { if(!graphical) { printCurrentLine("--->Progress: " + progressPercentage + "%"); } else { if(progmon == null) { progmon = new ProgressMonitor(null, "Extracting dmg to iso...", "0%", 0, 100); progmon.setProgress(0); progmon.setMillisToPopup(0); } progmon.setProgress((int)progressPercentage); progmon.setNote(progressPercentage + "%"); } }
| 1,113,065
|
public static void reportProgress(long progressPercentage) { if(!graphical) { printCurrentLine("--->Progress: " + progressPercentage + "%"); } else { if(progmon == null) { progmon = new ProgressMonitor(null, "Extracting dmg to iso...", "0%", 0, 100); progmon.setProgress(0); progmon.setMillisToPopup(0); } progmon.setProgress((int)progressPercentage); progmon.setNote(progressPercentage + "%"); } }
|
public static void reportProgress(long progressPercentage) { if(!graphical) { printCurrentLine("--->Progress: " + progressPercentage + "%"); } else { if(progmon == null) { progmon = new ProgressMonitor(null, "Extracting dmg to iso...", "0%", 0, 100); progmon.setProgress(0); progmon.setMillisToPopup(0); } progmon.setProgress((int)progressPercentage); progmon.setNote(progressPercentage + "%"); } }
| 1,113,066
|
protected void setUp() throws Exception { super.setUp(); login(OpheliaTestUser.JUNIT); login(OpheliaTestUser.JUNIT_X); final ContainerModel containerModel = getContainerModel(OpheliaTestUser.JUNIT); final Container container = createContainer(OpheliaTestUser.JUNIT, NAME); addDocuments(OpheliaTestUser.JUNIT, container); final List<Contact> contacts = readContacts(OpheliaTestUser.JUNIT); datum = new Fixture(contacts, container, containerModel); containerModel.addListener(datum); }
|
protected void setUp() throws Exception { super.setUp(); login(OpheliaTestUser.JUNIT); final ContainerModel containerModel = getContainerModel(OpheliaTestUser.JUNIT); final Container container = createContainer(OpheliaTestUser.JUNIT, NAME); addDocuments(OpheliaTestUser.JUNIT, container); final List<Contact> contacts = readContacts(OpheliaTestUser.JUNIT); datum = new Fixture(contacts, container, containerModel); containerModel.addListener(datum); }
| 1,113,067
|
protected void tearDown() throws Exception { datum.containerModel.removeListener(datum); datum = null; logout(OpheliaTestUser.JUNIT); logout(OpheliaTestUser.JUNIT_X); super.tearDown(); }
|
protected void tearDown() throws Exception { datum.containerModel.removeListener(datum); datum = null; logout(OpheliaTestUser.JUNIT); logger.logTraceId(); super.tearDown(); }
| 1,113,068
|
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { setBackground(isSelected ? BG_SEL : BG); setText((HistoryItem) value); return this; }
|
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { setBackground(isSelected ? BG_SEL : BG); setText((DisplayHistoryItem) value); return this; }
| 1,113,074
|
protected void setText(final HistoryItem historyItem) { setDateText(historyItem); setEventText(historyItem); setVersionText(historyItem); }
|
protected void setText(final HistoryItem historyItem) { setDateText(historyItem); setEventText(historyItem); setVersionText(historyItem); }
| 1,113,075
|
DocumentListItem(final Document document, final Boolean isKeyHolder) { super("DocumentListItem"); this.isKeyHolder = isKeyHolder; setDocumentId(document.getId()); if(isClosed(document.getId())) { setMenuIcon(MENU_ICON_CLOSED); setNameForeground(NAME_FOREGROUND_CLOSED); } else { setMenuIcon(MENU_ICON); setNameForeground(NAME_FOREGROUND); } setName(new StringBuffer(document.getName()).append(" - ").append(document.getId()).toString()); if(isKeyHolder) { setInfoIcon(KEY_ICON); } }
|
DocumentListItem(final Document document, final Boolean isKeyHolder) { super("DocumentListItem"); this.isKeyHolder = isKeyHolder; setDocumentId(document.getId()); if(isClosed(document.getId())) { setMenuIcon(MENU_ICON_CLOSED); setNameForeground(NAME_FOREGROUND_CLOSED); } else { setMenuIcon(MENU_ICON); setNameForeground(NAME_FOREGROUND); } setName(document.getName()); if(isKeyHolder) { setInfoIcon(KEY_ICON); } }
| 1,113,076
|
private JMenuItem getCloseMenuItem() { if(null == closeMenuItem) { closeMenuItem = createJMenuItem(getString("Close"), getMnemonic("CloseMnemonic"), getCloseMenuItemActionListener()); } return closeMenuItem; }
|
private JMenuItem getCloseMenuItem() { if(null == closeMenuItem) { closeMenuItem = createJMenuItem(getString("Close"), getMnemonic("Close"), getCloseMenuItemActionListener()); } return closeMenuItem; }
| 1,113,077
|
private JMenuItem getDeleteMenuItem() { if(null == deleteMenuItem) { deleteMenuItem = createJMenuItem(getString("Delete"), getMnemonic("DeleteMnemonic"), getDeleteMenuItemActionListener()); } return deleteMenuItem; }
|
private JMenuItem getDeleteMenuItem() { if(null == deleteMenuItem) { deleteMenuItem = createJMenuItem(getString("Delete"), getMnemonic("Delete"), getDeleteMenuItemActionListener()); } return deleteMenuItem; }
| 1,113,078
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.