Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file Extractor.java
- * @brief Class implementing a .win resource extractor.
- *
- * @section License
- *
- * Copyright (C) 2013-2014 Robert B. Colton
- * This file is a part of the GameMaker: Studio decompiler.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.nio.ByteBuffer;
- import java.nio.ByteOrder;
- import javax.swing.JFileChooser;
- import javax.swing.JOptionPane;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- public class Extractor {
- public static int scanFiles(String directory, String ext, byte[] buffer, byte[] start, byte[] end) throws IOException {
- int num = 0;
- int length = buffer.length;
- for (int i = 0; i < length - 3; i++) {
- if (buffer[i] == start[0]
- && buffer[i + 1] == start[1]
- && buffer[i + 2] == start[2]
- && buffer[i + 3] == start[3]) {
- for (int ii = i + 4; ii < length - 3; ii++) {
- if (buffer[ii] == end[0] && buffer[ii + 1] == end[1]
- && buffer[ii + 2] == end[2]
- && buffer[ii + 3] == end[3]) {
- File file = new File(directory + num + ext);
- file.getParentFile().mkdirs();
- num += 1;
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(buffer, i, ii - i + 9);
- fos.close();
- i = ii + 8;
- break;
- }
- }
- }
- }
- return num;
- }
- public static int scanFileChunks(String directory, String ext, byte[] buffer, byte[] start, byte[] format) throws IOException {
- int num = 0;
- int length = buffer.length;
- for (int i = 0; i < length - 3; i++) {
- if (buffer[i] == start[0]
- && buffer[i + 1] == start[1]
- && buffer[i + 2] == start[2]
- && buffer[i + 3] == start[3]) {
- File file = new File(directory + num + ext);
- file.getParentFile().mkdirs();
- num += 1;
- FileOutputStream fos = new FileOutputStream(file);
- ByteBuffer bb = ByteBuffer.wrap(buffer, i + 4, 4);
- bb.order(ByteOrder.LITTLE_ENDIAN);
- int filelength = bb.getInt();
- JOptionPane.showMessageDialog(null, filelength);
- fos.write(buffer, i, filelength);
- fos.close();
- i += filelength;
- break;
- }
- }
- return num;
- }
- public static void main(String args[]) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
- // Set native Java L&F, otherwise file chooser looks like shit
- UIManager.setLookAndFeel(
- UIManager.getSystemLookAndFeelClassName());
- JFileChooser fileChooser = new JFileChooser();
- if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
- File file = fileChooser.getSelectedFile();
- FileInputStream fis = new FileInputStream(file);
- int length = (int)file.length();
- byte buffer[] = new byte [length];
- fis.read(buffer);
- fis.close();
- int textures = 0;
- textures += scanFiles(file.getParent() + "/textures/texture", ".png", buffer, new byte[]{ -119, 'P', 'N', 'G' }, new byte[]{ (byte) -82, 66, 96, -126 });
- //textures += scanFiles(file.getParent() + "/textures/texture", ".bmp", buffer, new byte[]{ -119, 'P', 'N', 'G' }, new byte[]{ (byte) -82, 66, 96, -126 });
- JOptionPane.showMessageDialog(null, textures + " Textures Extracted");
- int sounds = 0;
- sounds += scanFileChunks(file.getParent() + "/audio/sound", ".wav", buffer, new byte[]{ 'R', 'I', 'F', 'F' }, new byte[]{ 'W', 'A', 'V', 'E' });
- JOptionPane.showMessageDialog(null, sounds + " Sounds Extracted");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement