1 // BinToTxt.cpp : Defines the entry point for the console application.
2 //
3
4 #include "stdafx.h"
5 #include "stdio.h"
6 #include "stdlib.h"
7
8 int GetFsize(char *path)
9 {
10 int num=0;
11 FILE*fp=fopen(path,"rb");
12 if (fp!=NULL)
13 {
14 fseek(fp,0,SEEK_END);
15 num=ftell(fp);
16 }
17
18 return num;
19 }
20
21
22
23 int main()
24 {
25 FILE *BIN;
26 FILE *TXT;
27 int ch,n;
28 char filename[20]="shellcode.txt";
29 int FileSize= GetFsize("admrty.bin");
30 printf("admrtySIZE=%d\n",FileSize);
31
32
33 if( !(BIN = fopen("admrty.bin","rb")))
34 {
35 printf ("Cannot opem the BIN file!\n");
36 fclose(BIN);
37 exit(0); //终止程序
38
39 }
40
41 if( (TXT = fopen(filename,"wb")))
42 {
43 while (1)
44 {
45 ch=fgetc(BIN);
46 if (EOF==ch) break;
47 n++;
48 fprintf(TXT,"0x%02X,",(unsigned char)ch);
49 }
50
51 }
52 else
53 {
54 printf ("Cannot opem the TXT file!\n");
55
56 fclose(TXT);
57 exit(0); //终止程序
58 }
59
60 printf("Number of data :%d \r\n");
61 fclose(BIN);
62 fclose(TXT);
63 system("pause"); //暂停窗口
64 return 0;
65 }