Post by mchobo on Feb 16, 2014 20:31:20 GMT -5
Name of the program: BINdigo Repacker.
The following source code, when compiled, will display information about MML PC BIN files. At the moment it is at the alpha stage of development. It is supposed to repackage MML PC BIN files, however it needs further development.
MML PC BIN FILE ARCHITECTURE & INFORMATION:
MML PC utilizes various file types. One of such types is the BIN file format. This BIN format is different in architecture than conventional/other BIN formats.
The BIN file is structured the following way
*****************
4 BYTE array of size X Header
*****************
Data block Data
...
*****************
The example from above illustrates the BIN file structure in this way: The top section of the file (header?) is an array of a variable size - depending on the file. Each element in the array is 4 bytes long. After the array of 4 byte elements, there is a data block. The data block also has a variable size. However, unlike the previous section - it is not an array, nor is it the data separated exclusively by 4 bytes.
Each element in the Array block of the file contains offset data - offsets that correlate to a specific item in the data block from the beginning of the file. The first element in the array block is the offset to the first item in the data block - it also holds the size of the array block in bytes. The last element in the array block is the offset to the end of the file - it also holds the file size in bytes.
NOTE: You may need to change the codes file path to the correct path (The location where MML BIN files are stored - the DAT folder.)
The following source code, when compiled, will display information about MML PC BIN files. At the moment it is at the alpha stage of development. It is supposed to repackage MML PC BIN files, however it needs further development.
MML PC BIN FILE ARCHITECTURE & INFORMATION:
MML PC utilizes various file types. One of such types is the BIN file format. This BIN format is different in architecture than conventional/other BIN formats.
The BIN file is structured the following way
*****************
4 BYTE array of size X Header
*****************
Data block Data
...
*****************
The example from above illustrates the BIN file structure in this way: The top section of the file (header?) is an array of a variable size - depending on the file. Each element in the array is 4 bytes long. After the array of 4 byte elements, there is a data block. The data block also has a variable size. However, unlike the previous section - it is not an array, nor is it the data separated exclusively by 4 bytes.
Each element in the Array block of the file contains offset data - offsets that correlate to a specific item in the data block from the beginning of the file. The first element in the array block is the offset to the first item in the data block - it also holds the size of the array block in bytes. The last element in the array block is the offset to the end of the file - it also holds the file size in bytes.
NOTE: You may need to change the codes file path to the correct path (The location where MML BIN files are stored - the DAT folder.)
/************************************************************************************
* License :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/>*
************************************************************************************
* Title : BINdigo Repacker *
* copyright : Copyright (c) 2014 - mchobo/hobomchobo *
* Author : mchobo/hobomchobo *
* Email : hobomchobo@yahoo.com *
* Version : 0.01 (Alpha) *
* Date : 02/07/2014 *
* Description : Currently, all this application really does display information *
* about the internals of MML PC BIN files. Eventually I will write *
* more features to it such as unpacking/repacking BIN files. *
************************************************************************************
* NOTE I realize my code is in major need of optimization, I hope to clean *
* it up as time goes on - It is something I just put together. *
************************************************************************************
* Version -v0.01 (02/16/2014) - Inital release. *
* History -v0.02 (??/??/????) - Actually repack BIN files. *
************************************************************************************/
#include <iostream>
#include <string>
#include <fstream>
#include <Windows.h>
using namespace std;
string GET_FILE_NAME(){
string FileName;
cout << "Input file's name: ";
getline(cin, FileName);
return FileName;
}
fstream OPEN_FILE(string Path, string FileName){
fstream inFile;
inFile.open(Path + FileName, ios::in | ios::out | ios::binary);
return inFile;
}
bool CHECK_FILE_OPEN(fstream &FileObj, string FileName){
if(!FileObj){
cout << FileName << ": ERROR! - File did NOT open!" << endl << endl;
return false;
}else{
cout << FileName << ": SUCCESS! File is NOW open!" << endl << endl;
return true;
}
}
void CLOSE_FILE(fstream & File){
cout << "Closing File..." << endl;
File.close();
}
int main(){
//Strubg Object Declarations
string filePath = "C:\\Program Files (x86)\\Capcom\\Megaman\\DAT\\";
string fileName = GET_FILE_NAME();
unsigned char* pMainOffsetBuff = nullptr;; //Offset to begining of block of data
unsigned char* pOffsetArrayBuff = nullptr;; //Array of all Offsets to various items in main block of data.
unsigned int* pOffsetArraySize = nullptr;; //Size of Offset array in bytes
unsigned int* pOffsetArray = nullptr;
//File Objects Declarations
fstream binFile = OPEN_FILE(filePath, fileName); //Open file
CHECK_FILE_OPEN(binFile, fileName); //Check if file is open
//Allocate memory for pMainOffsetBuff
pMainOffsetBuff = new unsigned char[sizeof(unsigned int)];
//Read data from file into pMainOffsetBuff
binFile.read((char*) pMainOffsetBuff, sizeof(unsigned int));
pOffsetArraySize = (unsigned int*) pMainOffsetBuff;
//Reposition file to position 0;
binFile.seekg(0);
//
pOffsetArrayBuff = new unsigned char[*pOffsetArraySize];
binFile.read((char*) pOffsetArrayBuff, *pOffsetArraySize);
pOffsetArray = new unsigned int[*pOffsetArraySize / 4];
int x1, x2, x3, x4;
for(int countA = 0, countB = 0; countA < *pOffsetArraySize / 4; ++countA){ //preform bitwise distributions into OffsetArray
x1 = countB++, x2 = countB++, x3 = countB++, x4 = countB++;
pOffsetArray[countA] = pOffsetArrayBuff[x1] | (pOffsetArrayBuff[x2] << 8) | (pOffsetArrayBuff[x3] << 16) | (pOffsetArrayBuff[x4] << 24);
if(countA + 1 == *pOffsetArraySize / 4)
cout << "Byte offset to end of File: " << pOffsetArray[countA] << endl;
else
cout << "Byte offset to item No." << countA + 1 << ": " << pOffsetArray[countA] << endl;
}
cout << "Number of items in file: " << *pOffsetArraySize / 4 - 1 << endl << endl;
CLOSE_FILE(binFile); //Close file
delete [] pMainOffsetBuff; //Release memory for pMainOffsetBuff
delete [] pOffsetArrayBuff;
//delete pOffsetArraySize;
system("pause");
return 0;
}