fork(6) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. #define BUFFER_SIZE (1024 * 1024 * 256)
  5. /**
  6. * BIG-SIZE buffer
  7. **/
  8. unsigned char *buff1;
  9. unsigned char *buff2;
  10. /**
  11. * SONNORI Lz77 Xor Key
  12. **/
  13. unsigned short lz77_customkey[] = {
  14. 0xFF21, 0x834F, 0x675F, 0x0034, 0xF237, 0x815F, 0x4765, 0x0233
  15. }; //65313 33615 26463 52 62007 33119 18277 563
  16. //
  17. // NOP file unpack~~~ *^^*
  18. //
  19. void nop_unpack(const char *nopFile)
  20. {
  21. enum e_noptype {
  22. NOP_DATA_RAW = 0x00,
  23. NOP_DATA_LZ77 = 0x01,
  24. NOP_DATA_DIRECTORY = 0x02,
  25. NOP_DATA_SONNORI_LZ77 = 0x03
  26. };
  27. FILE *fp, *out_fp;
  28. int off, num, i, j;
  29. unsigned char key;
  30. fopen_s(&fp, nopFile, "rb");
  31. if (!fp)
  32. return;
  33. /* the last byte value of NOP file must be 0x12 */
  34. fseek(fp, -1, SEEK_END);
  35. if (fgetc(fp) != 0x12) {
  36. printf_s("* %-15s : 손상된 NOP 파일입니다.\n", nopFile);
  37. fclose(fp);
  38. return;
  39. }
  40. /* NOP file header */
  41. fseek(fp, -9, SEEK_END);
  42. fread(&off, 4, 1, fp);
  43. fread(&num, 4, 1, fp);
  44. printf_s("* %-15s : 총 %d개의 데이터를 포함하고 있습니다.\n", nopFile, num);
  45. for (i = 0; i < num; ++i) {
  46. unsigned char ? name[256];
  47. unsigned char ? name_size;
  48. unsigned char ? type;
  49. int ? ? ? ? ? ? offset;
  50. int ? ? ? ? ? ? encode_size;
  51. int ? ? ? ? ? ? decode_size;
  52. /* File infomation */
  53. fseek(fp, off, SEEK_SET);
  54. fread(&name_size, 1, 1, fp);
  55. fread(&type, 1, 1, fp);
  56. fread(&offset, 4, 1, fp);
  57. fread(&encode_size, 4, 1, fp);
  58. fread(&decode_size, 4, 1, fp);
  59. fread(name, 1, name_size + 1, fp);
  60. off += name_size + 15;
  61. /**
  62. * [ Data Type ]
  63. * 0x00 : Raw
  64. * 0x01 : Lz77 Compressed
  65. * 0x02 : Directory
  66. * 0x03 : SONNORI Lz77 Compressed
  67. **/
  68. /* In directory, this value used as file path decrypt key */
  69. if (type == NOP_DATA_DIRECTORY) {
  70. key = (char)decode_size;
  71. }
  72. else {
  73. decode_size ^= key;
  74. }
  75. /* File path decrypt */
  76. for (j = 0; j < name_size; ++j)
  77. name[j] ^= key;
  78. /* we doesn't have enough buffer size. so we skip this file. */
  79. if (decode_size > BUFFER_SIZE) {
  80. printf_s(" -> 실패 : %s ? ? ?\n", name);
  81. continue;
  82. }
  83. /* show current status with percent^^ */
  84. printf_s("* %0.1f%% : %-68s\r", ((float)i / (float)num * (float)100.0), name);
  85. switch (type) {
  86. case NOP_DATA_RAW:
  87. {
  88. fseek(fp, offset, SEEK_SET);
  89. fread(buff1, 1, encode_size, fp);
  90. fopen_s(&out_fp, name, "wb");
  91. if (!out_fp) {
  92. printf_s(" -> 실패 : %s ? ? ?\n", name);
  93. break;
  94. }
  95. fwrite(buff1, 1, decode_size, out_fp);
  96. fclose(out_fp);
  97. break;
  98. }
  99. case NOP_DATA_LZ77:
  100. {
  101. ?int bmask, bcnt = 0, size = 0, off, len;
  102. ?unsigned short Lz77Info;
  103. ?fseek(fp, offset, SEEK_SET);
  104. ?fread(buff1, 1, encode_size, fp);
  105. ?/* Lz77 uncompress */
  106. ?for (j = 0; j < encode_size; bcnt = (bcnt + 1) & 0x07)
  107. ?{
  108. ?if (!bcnt) {
  109. ?bmask = buff1[j++];
  110. ?}
  111. ?else {
  112. ?bmask >>= 1;
  113. ?}
  114. ?if (bmask & 0x01) {
  115. ?Lz77Info = *(unsigned short *)&buff1[j], j += 2;
  116. ?off = Lz77Info & 0x0FFF;
  117. ?len = (Lz77Info >> 12) + 2;
  118. ?memcpy(&buff2[size], &buff2[size - off], len);
  119. ?size += len;
  120. ?}
  121. ?else {
  122. ?buff2[size++] = buff1[j++];
  123. ?}
  124. ?}
  125. ?if (size != decode_size) {
  126. ?printf_s(" -> 실패 : %s ? ? ?%d != %d\n", name, size, decode_size);
  127. ?break;
  128. ?}
  129. ?fopen_s(&out_fp, name, "wb");
  130. ?if (!out_fp) {
  131. ?printf_s(" -> 실패 : %s ? ? ?\n", name);
  132. ?break;
  133. ?}
  134. ?fwrite(buff2, 1, decode_size, out_fp);
  135. ?fclose(out_fp);
  136. ?break;
  137. }
  138. case NOP_DATA_DIRECTORY:
  139. {
  140. ? _mkdir(name);
  141. ? break;
  142. }
  143. case NOP_DATA_SONNORI_LZ77:
  144. {
  145. ?int bmask, bsrcmask, bcnt = 0, size = 0, off, len;
  146. ?unsigned short Lz77Info;
  147. ?fseek(fp, offset, SEEK_SET);
  148. ?fread(buff1, 1, encode_size, fp);
  149. ?/* SONNORI Lz77 uncompress */
  150. ?for (j = 0; j < encode_size; bcnt = (bcnt + 1) & 0x07)
  151. ?{
  152. ?if (!bcnt) {
  153. ?bmask = bsrcmask = buff1[j++];
  154. ?bmask ^= 0xC8;
  155. ?}
  156. ?else {
  157. ?bmask >>= 1;
  158. ?}
  159. ?if (bmask & 0x01) {
  160. ?Lz77Info = *(unsigned short *)&buff1[j], j += 2;
  161. ?Lz77Info ^= lz77_customkey[(bsrcmask >> 3) & 0x07];
  162. ?off = Lz77Info & 0x0FFF;
  163. ?len = (Lz77Info >> 12) + 2;
  164. ?memcpy(&buff2[size], &buff2[size - off], len);
  165. ?size += len;
  166. ?}
  167. ?else {
  168. ?buff2[size++] = buff1[j++];
  169. ?}
  170. ?}
  171. ?if (size != decode_size) {
  172. ?printf_s(" -> 실패 : %s ? ? ?%d != %d\n", name, size, decode_size);
  173. ?break;
  174. ?}
  175. ?fopen_s(&out_fp, name, "wb");
  176. ?if (!out_fp) {
  177. ?printf_s(" -> 실패 : %s ? ? ?\n", name);
  178. ?break;
  179. ?}
  180. ?fwrite(buff2, 1, decode_size, out_fp);
  181. ?fclose(out_fp);
  182. ?break;
  183. }
  184. default: // unknown type
  185. printf_s(" -> 실패 : %s ? ? ?\n", name);
  186. break;
  187. }
  188. }
  189. fclose(fp);
  190. return;
  191. }
  192. int main(int argc, char *argv[])
  193. {
  194. /* 콘솔 속성 변경 */
  195. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
  196. /* 인트로 표시 */
  197. SetConsoleTitle("NOPUnpack - http://c...content-available-to-author-only...r.com/wdlabyrinth");
  198. printf_s("o------------------------------------------------------------------------------o");
  199. printf_s("| W h i t e D a y :: A Labyrinth named school ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|");
  200. printf_s("o------------------------------------------------------------------------------o");
  201. printf_s(" 네이버 카페 [화이트데이 게임 - 미궁의 열쇠] http://c...content-available-to-author-only...r.com/wdlabyrinth\n");
  202. printf_s(" 제작자: 다솜(Naver ID - love947345, MSN - eunju...@hotmail.com)\n");
  203. printf_s("o------------------------------------------------------------------------------o");
  204. printf_s(" NOP파일을 풀어줍니다..^^\n");
  205. printf_s(" 화이트데이가 설치된 폴더에서 실행하시면, 게임실행에 문제가 생길 수 있습니다.\n");
  206. printf_s(" 계속 하실려면 아무키나 누르세요.\n");
  207. printf_s("o------------------------------------------------------------------------------o");
  208. _getch();
  209. /* 버퍼 메모리 할당 */
  210. if (!(buff1 = (unsigned char *)malloc(BUFFER_SIZE)) || !(buff2 = (unsigned char *)malloc(BUFFER_SIZE))) {
  211. printf_s("* 메모리 할당에 실패하였습니다.\n");
  212. return 0;
  213. }
  214. {
  215. char path[256];
  216. int i;
  217. /* 데모버전 NOP 파일 */
  218. nop_unpack("whiteday.nop");
  219. /* 데모버전 NOP 패치 파일 */
  220. for (i = 100; i < 999; ++i) {
  221. sprintf_s(path, sizeof(path), "patch%02d.nop", i);
  222. nop_unpack(path);
  223. }
  224. /* 정식버전 NOP 패치 파일 */
  225. for (i = 100; i < 999; ++i) {
  226. sprintf_s(path, sizeof(path), "whiteday%03d.nop", i);
  227. nop_unpack(path);
  228. }
  229. /* 오!재미 NOP 파일*/
  230. for (i = 99; i < 999; ++i) {
  231. sprintf_s(path, sizeof(path), "mod_beanbag%03d.nop", i);
  232. nop_unpack(path);
  233. }
  234. }
  235. /* 메모리 해제 */
  236. free(buff2);
  237. free(buff1);
  238. printf_s("o------------------------------------------------------------------------------o");
  239. printf_s(" 모든 작업이 끝났습니다. 종료하실려면 엔터키를 누르세요.\n");
  240. return 0;
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:19: fatal error: conio.h: No such file or directory
 #include <conio.h>
                   ^
compilation terminated.
stdout
Standard output is empty