Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Linda Decompiler.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <Windows.h>
- #include <direct.h>
- #include <iostream>
- #include <sstream>
- #include <fstream>
- #include <string>
- #include <iomanip>
- using namespace std;
- void OpenPAC(char* FileName){
- ifstream Data (FileName, ios::in | ios::binary);
- string OutputFileName = "";
- unsigned int FileSize;
- unsigned int FileOffset;
- unsigned int Byte;
- for(int a=0; a<512; a++){
- Data.seekg(a*24);
- OutputFileName = "";
- for(int i=0; i<14; i++){
- Byte = (int)Data.get();
- if(Byte!=0){
- OutputFileName += (char)Byte;
- }
- }
- // No file name means we're done here
- if(OutputFileName==""){break;}
- // Fetch file data
- FileOffset = Data.get();
- FileOffset += Data.get()*256;
- FileOffset *= 2048;
- FileSize = Data.get();
- FileSize += Data.get()*256;
- FileSize += Data.get()*65536;
- FileSize += Data.get()*16777216;
- //cout << "File Name: " << OutputFileName << "\nFile Offset: " << FileOffset << "\nFile Size: " << FileSize << "\nFile Offset + Size: " << FileOffset+FileSize << endl;
- ofstream Out (OutputFileName, ios::out | ios::binary);
- Data.seekg(FileOffset);
- //* New Method: Faster but can become RAM hog
- char *buffer = new char[FileSize];
- Data.read(buffer,FileSize);
- Out.write(buffer,FileSize);
- Out.close();
- delete[] buffer;
- //*/
- cout << OutputFileName << " " << FileSize << endl;
- /* Old Method: Slower but negligible RAM usage
- for(int i=FileSize;i>0;i--){
- Out << (char)Data.get();
- }
- //*/
- }
- Data.close();
- }
- /* Table File
- void OpenMIC(char* FileName){
- ifstream Data (FileName, ios::in | ios::binary);
- string OutputFileName = "Info.txt";
- // Setup output file for writing
- ofstream Out (OutputFileName, ios::out | ios::app);
- Out.write("EO E FO FS\r\n",53);
- unsigned int Byte;
- unsigned int FileSize;
- unsigned int FileOffset;
- string SegmentEntry;
- string SegmentEntryFull;
- for(int a=0; a<768; a++){
- SegmentEntryFull = "";
- // Fetch entry
- Data.seekg(a*16);
- for(int j=0;j<16;j++){
- Byte = (int)Data.get();
- ostringstream oss;
- oss << setfill('0');
- oss << uppercase << setw(2) << hex << static_cast<int>(Byte);
- SegmentEntryFull += oss.str();
- oss.flush();
- oss.clear();
- }
- if(SegmentEntryFull == "00000000000000000000000000000000"){continue;}
- SegmentEntry = "";
- // Get Entry Pos
- if(0==0){
- ostringstream oss;
- oss << setfill('0');
- oss << uppercase << setw(4) << hex << static_cast<int>(a*16);
- SegmentEntry += oss.str();
- oss.flush();
- oss.clear();
- };
- SegmentEntry += " " + SegmentEntryFull + " ";
- Data.seekg(a*16);
- FileOffset = Data.get();
- FileOffset += Data.get()*256;
- FileOffset *= 2048;
- if(FileOffset > 0){
- ostringstream oss;
- oss << setfill('0');
- oss << uppercase << setw(7) << hex << FileOffset;
- SegmentEntry += oss.str();
- oss.clear();
- }
- SegmentEntry += " ";
- Data.seekg((a*16)+4);
- FileSize = Data.get();
- FileSize += Data.get()*256;
- FileSize *= 2048;
- if(FileSize > 0){
- ostringstream oss;
- oss << setfill('0');
- oss << uppercase << setw(5) << hex << FileSize;
- SegmentEntry += oss.str();
- oss.clear();
- }
- SegmentEntry += "\r\n";
- Out.write(SegmentEntry.c_str(),56);
- }
- Out.close();
- Data.close();
- }//*/
- //* Extract
- void OpenMIC(char* FileName){
- ifstream Data (FileName, ios::in | ios::binary);
- string OutputFileName = "";
- unsigned int FileSize;
- unsigned int FileOffset;
- unsigned int Byte;
- for(int a=0; a<768; a++){
- // Get ID-FileOffset
- Data.seekg(a*16);
- FileOffset = Data.get();
- FileOffset += Data.get()*256;
- FileOffset *= 2048;
- OutputFileName = "";
- if(FileOffset == 0){continue;}
- /* File name by EntryOffset
- else{
- ostringstream oss;
- oss << setfill('0');
- oss << uppercase << setw(2) << hex << (a*16);
- OutputFileName += oss.str();
- oss.clear();
- }//*/
- //* File name by FileOffset
- Data.seekg(a*16);
- for(int j=0; j<2; j++){
- Byte = (int)Data.get();
- ostringstream oss;
- oss << setfill('0');
- oss << uppercase << setw(2) << hex << Byte;
- OutputFileName += oss.str();
- oss.clear();
- }//*/
- OutputFileName += ".DAT";
- // Calculate File Size
- Data.seekg((a*16)+4);
- FileSize = Data.get();
- FileSize += Data.get()*256;
- FileSize *= 2048;
- // Goto File Segment and Extract
- ofstream Out (OutputFileName, ios::out | ios::binary);
- Data.seekg(FileOffset);
- char *buffer = new char[FileSize];
- Data.read(buffer,FileSize);
- Out.write(buffer,FileSize);
- Out.close();
- delete[] buffer;
- cout << OutputFileName << " " << FileSize << endl;
- }
- Data.close();
- }//*/
- void OpenSPK(char* FileName){
- unsigned int Length = strlen(FileName);
- ifstream Data (FileName, ios::in | ios::binary);
- string OutputFileName = "";
- unsigned int FileSize;
- unsigned int FileOffset;
- unsigned int Byte;
- for(int a=0; a<9; a++){
- // Fetch File Offset
- Data.seekg(a*2);
- FileOffset = Data.get() + 56;
- FileOffset += Data.get() * 256;
- // Fetch File Size
- Data.seekg((a*2)+18);
- FileSize = Data.get();
- FileSize += Data.get() * 256;
- // Create File Name
- char *OutputFileName = new char[Length+6];
- strcpy(OutputFileName,FileName);
- strncat(OutputFileName,"_0.SEQ",6);
- OutputFileName[Length-4] = 95;
- OutputFileName[Length+1] = 48+a;
- // Goto File Segment and Extract
- ofstream Out (OutputFileName, ios::out | ios::binary);
- Data.seekg(FileOffset);
- char *buffer = new char[FileSize];
- Data.read(buffer,FileSize);
- Out.write(buffer,FileSize);
- Out.close();
- delete[] buffer;
- // Print File Name and Size
- cout << "LINDA_SPK_" << a << ".SEQ " << FileSize << endl;
- }
- Data.close();
- }
- void OpenDAT(char* FileName){
- ifstream Data (FileName, ios::in | ios::binary);
- // Get just the name of the file, minus path and extension
- FileName += strlen(FileName)-8;
- FileName[strlen(FileName)-4] = 47;
- FileName[strlen(FileName)-3] = 0;
- // Print name
- cout << FileName << " ----Extracting" << endl;
- // Make a folder for the files
- mkdir(FileName);
- // Setup variables for the loop
- string OutputFileName;
- unsigned int Byte;
- unsigned int Offset;
- unsigned int Size;
- ofstream Out;
- // 99 is an arbitrarily high number, I prefer this to a while(true) loop
- for(int i=0; i<99; i++){
- Data.seekg(i*16);
- // Reset the filename, we will be appending to it
- OutputFileName = "";
- for(int b=0; b<13; b++){
- Byte = (int)Data.get();
- if(Byte!=0){
- OutputFileName += (char)Byte;
- }
- }
- // If there is no filename, we're done extracting files
- if(OutputFileName == ""){break;}
- // Get offsets and calculate filesize
- Offset = Data.get();
- Offset += Data.get()*256;
- Offset += Data.get()*65536;
- Data.seekg(((i+1)*16)+13);
- Size = Data.get();
- Size += Data.get()*256;
- Size += Data.get()*65536;
- Size -= Offset;
- // Concatenate name and folder paths
- OutputFileName = FileName + OutputFileName;
- cout << OutputFileName << endl;
- //* Goto File Offset and Extract
- Data.seekg(Offset);
- Out.open(OutputFileName, ios::out | ios::binary);
- char *buffer = new char[Size];
- Data.read(buffer,Size);
- Out.write(buffer,Size);
- Out.close();
- delete[] buffer;
- //*/
- }
- Data.close();
- }
- int _tmain(int argc, _TCHAR* argv[]){
- if(argc>1){
- for(int file=1;file<argc;file++){
- int Len = strlen(argv[file]);
- if(strcmp((argv[file]+(Len-9)),"LINDA.PAC")==0){
- OpenPAC(argv[file]);
- }else if(strcmp((argv[file]+(Len-9)),"LINDA.MIC")==0){
- OpenMIC(argv[file]);
- }else if(strcmp((argv[file]+(Len-9)),"LINDA.SPK")==0){
- OpenSPK(argv[file]);
- }else if(strcmp((argv[file]+(Len-4)),".DAT")==0){
- OpenDAT(argv[file]);
- }
- }
- system("PAUSE");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement