Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.94 KB | None | 0 0
  1. include <windows.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include "zlib123-dll/include/zlib.h"
  5. #include "blowfish.h"
  6. #pragma comment(lib, "./zlib123-dll/lib/zdll")
  7.  
  8.  
  9. #pragma warning( disable : 4099 )
  10.  
  11. #include "acvarchive.h"
  12.  
  13. using namespace std;
  14.  
  15. const int MAYORVERSION = 1;
  16. const int MINORVERSION = 3;
  17.  
  18. enum Acvmode { ACVLIST, ACVCOMPRESS1, ACVCOMPRESSALL,
  19. ACVDECOMPRESS1, ACVDECOMPRESSALL, ACVCOMPRESSINDEX,
  20. ACVCOMPRESSNEW } ;
  21.  
  22. Acvmode acvmode = ACVLIST;
  23. char * acvfilename = 0;
  24. char * outputdirectory = 0;
  25. char * inputdirectory = 0;
  26. char * inputfilename = 0;
  27. int acvindex = 0;
  28.  
  29. vector<string> pathlist;
  30.  
  31. void usage();
  32. bool parseargs( int argc, char * argv[] );
  33. bool acvprintlist(AcvArchive& acv);
  34. bool acvcompress1(AcvArchive& acv);
  35. bool acvcompressall(AcvArchive& acv);
  36. bool acvdecompress1(AcvArchive& acv);
  37. bool acvdecompressall(AcvArchive& acv);
  38. bool acvcompressindex(AcvArchive& acv);
  39. bool acvcompressnew(AcvArchive& acv);
  40.  
  41. extern unsigned char acvkeyheader[];
  42.  
  43. int main(int argc, char * argv[] )
  44. {
  45. /*BlowFish::CBlowFish crypt( &acvkeyheader[0], 56);
  46. FILE * in = fopen("052.acv","rb");
  47. int filecount=0;
  48. unsigned short csize;
  49. unsigned char * bufin = new unsigned char[1024*1024];
  50. unsigned char * bufout = new unsigned char[1024*1024];
  51. fread( bufin, 4, 1, in);
  52. fread( &filecount, 4, 1, in );
  53. fread( &csize, 2, 1, in );
  54.  
  55. fread( bufin, csize, csize, in );
  56. crypt.Decrypt( bufin, bufout, csize );
  57. uncompress(bufin, (uLongf *)&filecount, bufout, 1024*1024 );
  58.  
  59. fclose(in);
  60. */
  61.  
  62. //////////////////////////////
  63. int err;
  64. bool result;
  65. AcvArchive acv;
  66.  
  67. if ( parseargs( argc, argv ) == false )
  68. {
  69. usage();
  70. return 1;
  71. }
  72. bool openmode = ( acvmode == ACVCOMPRESSALL || acvmode == ACVCOMPRESS1 || ACVCOMPRESSINDEX );
  73. result = acv.Open( acvfilename, openmode );
  74. pathlist = acv.Getpathlist();
  75. if ( result == false )
  76. {
  77. printf("Error opening file ...%s\n", acvfilename );
  78. return 1;
  79. }
  80.  
  81. switch( acvmode )
  82. {
  83. case ACVLIST:
  84. err = acvprintlist( acv ) == true;
  85. break;
  86.  
  87. case ACVCOMPRESS1:
  88. err = acvcompress1( acv ) == true;
  89. acv.Rebuild();
  90. break;
  91.  
  92. case ACVCOMPRESSALL:
  93. err = acvcompressall( acv ) == true;
  94. acv.Rebuild();
  95. break;
  96. case ACVCOMPRESSINDEX:
  97. err = acvcompressindex( acv ) == true;
  98. acv.Rebuild();
  99. break;
  100. case ACVCOMPRESSNEW:
  101. err = acvcompressnew( acv ) == true;
  102. acv.Rebuild();
  103. break;
  104. case ACVDECOMPRESS1:
  105. err = acvdecompress1( acv ) == true;
  106. break;
  107.  
  108. case ACVDECOMPRESSALL:
  109. err = acvdecompressall( acv ) == true;
  110. break;
  111.  
  112. default:
  113. printf("Should not get here \"switch(acvmode)\"....\n");
  114. }
  115.  
  116. return !(err==1);
  117. }
  118.  
  119. bool acvprintlist(AcvArchive& acv)
  120. {
  121. Acvfilelist& acvlist = acv.Getfilelist();
  122. Acvfilelist::iterator it;
  123. it = acvlist.begin();
  124. while( it != acvlist.end() )
  125. {
  126. printf( "[%03i] %s\n", it->index, it->fullname.c_str() );
  127. it++;
  128. }
  129. printf("Total files = %i\n", acv.Getfilecount() );
  130.  
  131. int i=1;
  132. vector<string>::iterator sit;
  133. sit = pathlist.begin();
  134. while( sit != pathlist.end() )
  135. {
  136. printf( "<<< %02i >>> %s\n", i, sit->c_str() );
  137. sit++;
  138. i++;
  139. }
  140. return true;
  141. }
  142.  
  143. bool acvcompressindex(AcvArchive& acv)
  144. {
  145. Acvfilelist& acvlist = acv.Getfilelist();
  146. Acvfilelist::iterator it;
  147. string argsinput;
  148. int matchindex=-1;
  149.  
  150. argsinput = inputfilename;
  151. it = acvlist.begin();
  152. while( it != acvlist.end() )
  153. {
  154. if ( it->index == acvindex )
  155. matchindex = it->index;
  156. it++;
  157. }
  158. if ( matchindex == -1 )
  159. {
  160. printf( "File not found : %s\n", inputfilename );
  161. return false;
  162. }
  163. if ( acv.Insert( acvlist[matchindex], argsinput ) == false )
  164. {
  165. printf( "Insert failed...\n" );
  166. return false;
  167. }
  168. return true;
  169.  
  170. }
  171.  
  172. bool acvcompressnew(AcvArchive& acv)
  173. {
  174. int size = pathlist.size();
  175. if ( acvindex > size )
  176. {
  177. printf( "Directory not found\n");
  178. return false;
  179. }
  180.  
  181. vector<string>& pathlist = acv.Getpathlist();
  182. string argsinput = inputfilename;
  183. if ( acv.InsertNew( pathlist[acvindex-1], argsinput ) == false )
  184. {
  185. printf( "Insert failed...\n" );
  186. return false;
  187. }
  188. return true;
  189.  
  190.  
  191. }
  192.  
  193. bool acvcompress1(AcvArchive& acv)
  194. {
  195. Acvfilelist& acvlist = acv.Getfilelist();
  196. Acvfilelist::iterator it;
  197. string argsinput;
  198. int matchindex=-1;
  199.  
  200. argsinput = inputfilename;
  201. it = acvlist.begin();
  202. while( it != acvlist.end() )
  203. {
  204. if ( it->name == argsinput )
  205. matchindex = it->index;
  206. it++;
  207. }
  208. if ( matchindex == -1 )
  209. {
  210. printf( "File not found : %s\n", inputfilename );
  211. return false;
  212. }
  213. if ( acv.Insert( acvlist[matchindex], argsinput ) == false )
  214. {
  215. printf( "Insert failed...\n" );
  216. return false;
  217. }
  218. return true;
  219. }
  220.  
  221. bool acvcompressall(AcvArchive& acv)
  222. {
  223. // NOT IMPLEMENTED
  224. return true;
  225. }
  226. bool acvdecompress1(AcvArchive& acv)
  227. {
  228. Acvfilelist& acvlist = acv.Getfilelist();
  229. Acvfilelist::iterator it;
  230.  
  231. if ( !(acvindex && acvindex <= acv.Getfilecount()) )
  232. {
  233. printf("Index out of range, valid range are 0 to %03i\n", acv.Getfilecount() );
  234. return false;
  235. }
  236. printf("Extract...%s\n", acvlist[acvindex].name.c_str() );
  237. return acv.Extract( acvlist[acvindex], acvlist[acvindex].name );
  238. }
  239.  
  240. bool acvdecompressall(AcvArchive& acv)
  241. {
  242. Acvfilelist& acvlist = acv.Getfilelist();
  243. Acvfilelist::iterator it;
  244. vector<string>::iterator sit;
  245. vector<string>& pathlist = acv.Getpathlist();
  246.  
  247. CreateDirectory( outputdirectory, 0 );
  248. sit = pathlist.begin();
  249. while( sit != pathlist.end() )
  250. {
  251. string path = outputdirectory;
  252. path += "\\";
  253. path += *sit;
  254. CreateDirectory( path.c_str(), 0 );
  255. sit++;
  256. }
  257. it = acvlist.begin();
  258. int i=0;
  259. while ( it != acvlist.end() )
  260. {
  261. i++;
  262. if ( i==0xb2 )
  263. i=i;
  264. string path = outputdirectory;
  265. path += "\\";
  266. path += it->fullname;
  267. printf(" writing : %s\n", path.c_str() );
  268. acv.Extract( *it, path );
  269. it++;
  270. }
  271. return true;
  272. }
  273.  
  274. void usage()
  275. {
  276. printf( "ACV Archive Tool v%i.%i\n", MAYORVERSION, MINORVERSION );
  277. printf( " Copyright (C) 2009 mnemonix\n\n" );
  278. printf( "Usage : acv <switch> <acvfile> <filename>\n\n");
  279. printf( "Examples :\n");
  280. printf( " acv -l <acvfile> list archive contents\n" );
  281. printf( " acv -da <acvfile> <outdir> decompress all files to directory <outdir>\n" );
  282. printf( " acv -d <acvfile> <index> decompress 1 file specified by <index>\n" );
  283. printf( " use -l switch to get the index\n" );
  284.  
  285. // NOT IMPLEMENTED
  286. //printf( " acv -ca <acvfile> <inputdir> compress <inputdir> directory into\n");
  287. //printf( " a single <acvfile>\n" );
  288.  
  289. printf( " acv -c <acvfile> <input> compress <input> to <acvfile>\n" );
  290. printf( " acv -c1 <acvfile> <input> <index> compress <input> to <index> into <acvfile>\n" );
  291. printf( " acv -cn <acvfile> <input> <dindex> compress <input> to directory <index>\n");
  292. printf( "Have a nice mod....\n\n" );
  293. }
  294.  
  295. bool parseargs( int argc, char * argv[] )
  296. {
  297. if ( argc < 3 ) return false;
  298.  
  299. char * sw = argv[1];
  300.  
  301. if ( sw[0] != '-' ) return false;
  302.  
  303. bool bret = false;
  304.  
  305. switch ( sw[1] )
  306. {
  307. case 'l' :
  308. acvmode = ACVLIST;
  309. acvfilename = argv[2];
  310. bret = true;
  311. break;
  312.  
  313. case 'd' :
  314. if ( sw[2] == 'a' && argc == 4)
  315. {
  316. acvfilename = argv[2];
  317. outputdirectory = argv[3];
  318. acvmode = ACVDECOMPRESSALL;
  319. bret = true;
  320. }
  321. else if ( sw[2] == 0 && argc != 4 )
  322. {
  323. acvfilename = argv[2];
  324. acvmode = ACVDECOMPRESS1;
  325. if ( sscanf(argv[3], "%i", &acvindex ) == 0 )
  326. {
  327. bret = true;
  328. }
  329. }
  330. break;
  331.  
  332. case 'c' :
  333. if ( sw[2] == 'a' && argc == 4 )
  334. {
  335. acvfilename = argv[2];
  336. inputdirectory = argv[3];
  337. acvmode = ACVCOMPRESSALL;
  338. bret = true;
  339. }
  340. else if ( sw[2] == 0 && argc == 4)
  341. {
  342. acvfilename = argv[2];
  343. inputfilename = argv[3];
  344. acvmode = ACVCOMPRESS1;
  345. //if ( sscanf(argv[4], "%i", &acvindex ) == 1 )
  346. //{
  347. bret = true;
  348. //}
  349. }
  350. else if ( sw[2] == '1' && argc == 5 )
  351. {
  352. acvfilename = argv[2];
  353. inputfilename = argv[3];
  354. acvmode = ACVCOMPRESSINDEX;
  355. if ( sscanf(argv[4], "%i", &acvindex ) == 1 )
  356. {
  357. bret = true;
  358. }
  359. }
  360. else if ( sw[2] == 'n' && argc == 5 )
  361. {
  362. acvfilename = argv[2];
  363. inputfilename = argv[3];
  364. acvmode = ACVCOMPRESSNEW;
  365. if ( sscanf( argv[4], "%i", &acvindex ) == 1 )
  366. {
  367. bret = true;
  368. }
  369. }
  370. break;
  371. }
  372.  
  373. return bret;
  374. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement