Guest User

Linda Cube Again Decompiler MVC++

a guest
Mar 26th, 2011
188
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Linda Decompiler.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <Windows.h>
  6. #include <direct.h>
  7. #include <iostream>
  8. #include <sstream>
  9. #include <fstream>
  10. #include <string>
  11. #include <iomanip>
  12. using namespace std;
  13.  
  14. void OpenPAC(char* FileName){
  15. ifstream Data (FileName, ios::in | ios::binary);
  16. string OutputFileName = "";
  17. unsigned int FileSize;
  18. unsigned int FileOffset;
  19. unsigned int Byte;
  20. for(int a=0; a<512; a++){
  21. Data.seekg(a*24);
  22. OutputFileName = "";
  23. for(int i=0; i<14; i++){
  24. Byte = (int)Data.get();
  25. if(Byte!=0){
  26. OutputFileName += (char)Byte;
  27. }
  28. }
  29. // No file name means we're done here
  30. if(OutputFileName==""){break;}
  31. // Fetch file data
  32. FileOffset = Data.get();
  33. FileOffset += Data.get()*256;
  34. FileOffset *= 2048;
  35. FileSize = Data.get();
  36. FileSize += Data.get()*256;
  37. FileSize += Data.get()*65536;
  38. FileSize += Data.get()*16777216;
  39. //cout << "File Name: " << OutputFileName << "\nFile Offset: " << FileOffset << "\nFile Size: " << FileSize << "\nFile Offset + Size: " << FileOffset+FileSize << endl;
  40. ofstream Out (OutputFileName, ios::out | ios::binary);
  41. Data.seekg(FileOffset);
  42. //* New Method: Faster but can become RAM hog
  43. char *buffer = new char[FileSize];
  44. Data.read(buffer,FileSize);
  45. Out.write(buffer,FileSize);
  46. Out.close();
  47. delete[] buffer;
  48. //*/
  49. cout << OutputFileName << " " << FileSize << endl;
  50. /* Old Method: Slower but negligible RAM usage
  51. for(int i=FileSize;i>0;i--){
  52. Out << (char)Data.get();
  53. }
  54. //*/
  55. }
  56. Data.close();
  57. }
  58.  
  59. /* Table File
  60. void OpenMIC(char* FileName){
  61. ifstream Data (FileName, ios::in | ios::binary);
  62. string OutputFileName = "Info.txt";
  63. // Setup output file for writing
  64. ofstream Out (OutputFileName, ios::out | ios::app);
  65. Out.write("EO E FO FS\r\n",53);
  66. unsigned int Byte;
  67. unsigned int FileSize;
  68. unsigned int FileOffset;
  69. string SegmentEntry;
  70. string SegmentEntryFull;
  71. for(int a=0; a<768; a++){
  72. SegmentEntryFull = "";
  73. // Fetch entry
  74. Data.seekg(a*16);
  75. for(int j=0;j<16;j++){
  76. Byte = (int)Data.get();
  77. ostringstream oss;
  78. oss << setfill('0');
  79. oss << uppercase << setw(2) << hex << static_cast<int>(Byte);
  80. SegmentEntryFull += oss.str();
  81. oss.flush();
  82. oss.clear();
  83. }
  84. if(SegmentEntryFull == "00000000000000000000000000000000"){continue;}
  85. SegmentEntry = "";
  86. // Get Entry Pos
  87. if(0==0){
  88. ostringstream oss;
  89. oss << setfill('0');
  90. oss << uppercase << setw(4) << hex << static_cast<int>(a*16);
  91. SegmentEntry += oss.str();
  92. oss.flush();
  93. oss.clear();
  94. };
  95. SegmentEntry += " " + SegmentEntryFull + " ";
  96. Data.seekg(a*16);
  97. FileOffset = Data.get();
  98. FileOffset += Data.get()*256;
  99. FileOffset *= 2048;
  100. if(FileOffset > 0){
  101. ostringstream oss;
  102. oss << setfill('0');
  103. oss << uppercase << setw(7) << hex << FileOffset;
  104. SegmentEntry += oss.str();
  105. oss.clear();
  106. }
  107. SegmentEntry += " ";
  108. Data.seekg((a*16)+4);
  109. FileSize = Data.get();
  110. FileSize += Data.get()*256;
  111. FileSize *= 2048;
  112. if(FileSize > 0){
  113. ostringstream oss;
  114. oss << setfill('0');
  115. oss << uppercase << setw(5) << hex << FileSize;
  116. SegmentEntry += oss.str();
  117. oss.clear();
  118. }
  119. SegmentEntry += "\r\n";
  120. Out.write(SegmentEntry.c_str(),56);
  121. }
  122. Out.close();
  123. Data.close();
  124. }//*/
  125.  
  126. //* Extract
  127. void OpenMIC(char* FileName){
  128. ifstream Data (FileName, ios::in | ios::binary);
  129. string OutputFileName = "";
  130. unsigned int FileSize;
  131. unsigned int FileOffset;
  132. unsigned int Byte;
  133. for(int a=0; a<768; a++){
  134. // Get ID-FileOffset
  135. Data.seekg(a*16);
  136. FileOffset = Data.get();
  137. FileOffset += Data.get()*256;
  138. FileOffset *= 2048;
  139. OutputFileName = "";
  140. if(FileOffset == 0){continue;}
  141. /* File name by EntryOffset
  142. else{
  143. ostringstream oss;
  144. oss << setfill('0');
  145. oss << uppercase << setw(2) << hex << (a*16);
  146. OutputFileName += oss.str();
  147. oss.clear();
  148. }//*/
  149. //* File name by FileOffset
  150. Data.seekg(a*16);
  151. for(int j=0; j<2; j++){
  152. Byte = (int)Data.get();
  153. ostringstream oss;
  154. oss << setfill('0');
  155. oss << uppercase << setw(2) << hex << Byte;
  156. OutputFileName += oss.str();
  157. oss.clear();
  158. }//*/
  159. OutputFileName += ".DAT";
  160. // Calculate File Size
  161. Data.seekg((a*16)+4);
  162. FileSize = Data.get();
  163. FileSize += Data.get()*256;
  164. FileSize *= 2048;
  165. // Goto File Segment and Extract
  166. ofstream Out (OutputFileName, ios::out | ios::binary);
  167. Data.seekg(FileOffset);
  168. char *buffer = new char[FileSize];
  169. Data.read(buffer,FileSize);
  170. Out.write(buffer,FileSize);
  171. Out.close();
  172. delete[] buffer;
  173. cout << OutputFileName << " " << FileSize << endl;
  174. }
  175. Data.close();
  176. }//*/
  177.  
  178. void OpenSPK(char* FileName){
  179. unsigned int Length = strlen(FileName);
  180. ifstream Data (FileName, ios::in | ios::binary);
  181. string OutputFileName = "";
  182. unsigned int FileSize;
  183. unsigned int FileOffset;
  184. unsigned int Byte;
  185. for(int a=0; a<9; a++){
  186. // Fetch File Offset
  187. Data.seekg(a*2);
  188. FileOffset = Data.get() + 56;
  189. FileOffset += Data.get() * 256;
  190. // Fetch File Size
  191. Data.seekg((a*2)+18);
  192. FileSize = Data.get();
  193. FileSize += Data.get() * 256;
  194. // Create File Name
  195. char *OutputFileName = new char[Length+6];
  196. strcpy(OutputFileName,FileName);
  197. strncat(OutputFileName,"_0.SEQ",6);
  198. OutputFileName[Length-4] = 95;
  199. OutputFileName[Length+1] = 48+a;
  200. // Goto File Segment and Extract
  201. ofstream Out (OutputFileName, ios::out | ios::binary);
  202. Data.seekg(FileOffset);
  203. char *buffer = new char[FileSize];
  204. Data.read(buffer,FileSize);
  205. Out.write(buffer,FileSize);
  206. Out.close();
  207. delete[] buffer;
  208. // Print File Name and Size
  209. cout << "LINDA_SPK_" << a << ".SEQ " << FileSize << endl;
  210. }
  211. Data.close();
  212. }
  213.  
  214. void OpenDAT(char* FileName){
  215. ifstream Data (FileName, ios::in | ios::binary);
  216. // Get just the name of the file, minus path and extension
  217. FileName += strlen(FileName)-8;
  218. FileName[strlen(FileName)-4] = 47;
  219. FileName[strlen(FileName)-3] = 0;
  220. // Print name
  221. cout << FileName << " ----Extracting" << endl;
  222. // Make a folder for the files
  223. mkdir(FileName);
  224. // Setup variables for the loop
  225. string OutputFileName;
  226. unsigned int Byte;
  227. unsigned int Offset;
  228. unsigned int Size;
  229. ofstream Out;
  230. // 99 is an arbitrarily high number, I prefer this to a while(true) loop
  231. for(int i=0; i<99; i++){
  232. Data.seekg(i*16);
  233. // Reset the filename, we will be appending to it
  234. OutputFileName = "";
  235. for(int b=0; b<13; b++){
  236. Byte = (int)Data.get();
  237. if(Byte!=0){
  238. OutputFileName += (char)Byte;
  239. }
  240. }
  241. // If there is no filename, we're done extracting files
  242. if(OutputFileName == ""){break;}
  243. // Get offsets and calculate filesize
  244. Offset = Data.get();
  245. Offset += Data.get()*256;
  246. Offset += Data.get()*65536;
  247. Data.seekg(((i+1)*16)+13);
  248. Size = Data.get();
  249. Size += Data.get()*256;
  250. Size += Data.get()*65536;
  251. Size -= Offset;
  252. // Concatenate name and folder paths
  253. OutputFileName = FileName + OutputFileName;
  254. cout << OutputFileName << endl;
  255. //* Goto File Offset and Extract
  256. Data.seekg(Offset);
  257. Out.open(OutputFileName, ios::out | ios::binary);
  258. char *buffer = new char[Size];
  259. Data.read(buffer,Size);
  260. Out.write(buffer,Size);
  261. Out.close();
  262. delete[] buffer;
  263. //*/
  264. }
  265. Data.close();
  266. }
  267.  
  268. int _tmain(int argc, _TCHAR* argv[]){
  269. if(argc>1){
  270. for(int file=1;file<argc;file++){
  271. int Len = strlen(argv[file]);
  272. if(strcmp((argv[file]+(Len-9)),"LINDA.PAC")==0){
  273. OpenPAC(argv[file]);
  274. }else if(strcmp((argv[file]+(Len-9)),"LINDA.MIC")==0){
  275. OpenMIC(argv[file]);
  276. }else if(strcmp((argv[file]+(Len-9)),"LINDA.SPK")==0){
  277. OpenSPK(argv[file]);
  278. }else if(strcmp((argv[file]+(Len-4)),".DAT")==0){
  279. OpenDAT(argv[file]);
  280. }
  281. }
  282. system("PAUSE");
  283. }
  284. return 0;
  285. }
RAW Paste Data