- /* ObCrypter v1.2 for p0wnbox.com by OBLiQUE */
- /* WARNING!!!: compile it only with g++
- * use MinGW if you have Window$
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- #if defined(__unix__) || defined(__APPLE__)
- #define c '/'
- #else
- #define c '\\'
- #endif
- /* arguments */
- #define FLAG_V 0x01 // verbose mode
- #define FLAG_W 0x02 // write to path
- #define FLAG_F 0x04 // force to overwrite
- #define FLAG_E 0x08 // write the whole file
- // usage
- char usage[]="\n ObCrypter v1.2 for p0wnbox.com by OBLiQUE\n\n"
- " usage: obCrypter [options] file\n\n"
- "\t-w [file]\tchoose an output file\n"
- "\t-f\t\tforce to overwrite the output file\n"
- "\t-v\t\tverbose mode - this is slower than the quiet mode\n"
- "\t-e\t\twrite the whole file - EOF support\n\n"
- " example: obCrypter -v -w output_file.exe input_file.exe\n\n";
- unsigned int argflags=0;
- enum sort_t {byVirtualOffset, byRawOffset}; // sorting types
- class Section {
- public:
- Section();
- Section(Section *_section);
- char sname[9]; // section name
- unsigned int voffset; // VirtualOffset
- unsigned int vsize; // VirtualSize
- unsigned int roffset; // RawOffset
- unsigned int rsize; // RawSize
- unsigned int flags; // Characteristics
- unsigned int *psort; // this points to voffset or roffset
- Section *next; // next section
- };
- class Info {
- public:
- Info(sort_t _sort);
- ~Info();
- int insert(Section *_section); // add section to the linked-list
- int readinfo(); // read file info
- int writefile(); // write crypted file
- int crypt(char *_tocrypt,char *_crypted);
- int resort(sort_t _sort); // resort the linked-list
- private:
- unsigned int oep; // original EntryPoint
- unsigned int imagebase; // ImageBase
- unsigned int nos; // NumberOfSectios
- unsigned int size; // tocrypt size
- unsigned int pe_start; // PE-header starting point
- unsigned int import_rva; // ImportTable RVA
- unsigned int import_size; // ImportTable size
- sort_t sort; // sort type
- FILE *tocrypt; // file to crypt
- FILE *crypted; // crypted file
- Section *head; // top of my linked-list
- Section *tail; // tail of my linked-list
- };
- int main(int argc,char *argv[])
- {
- if (argc<2) {
- printf("%s", usage);
- return 1;
- }
- unsigned int i,j,n=0;
- char *path_tocrypt=NULL, *path_crypted=NULL;
- for (i=1;i<argc;i++)
- if (argv[i][0]=='-') {
- for (j=1;argv[i][j]!='\0';j++)
- switch (argv[i][j]) {
- case 'v':
- argflags|=FLAG_V;
- break;
- case 'w':
- argflags|=FLAG_W;
- if (argc-1==i+1) {
- printf("%s", usage);
- return 1;
- } else path_crypted=argv[i+1];
- break;
- case 'f':
- argflags|=FLAG_F;
- break;
- case 'e':
- argflags|=FLAG_E;
- break;
- default:
- fprintf(stderr,"Illegal argument: %c\n",argv[i][j]);
- printf("%s", usage);
- return 1;
- }
- } else if (argc-1==i)
- path_tocrypt=argv[i];
- else n++;
- if (argflags & FLAG_W) n--;
- if (!path_tocrypt || n) {
- printf("%s", usage);
- return 1;
- }
- Info fileinfo(byVirtualOffset);
- if (fileinfo.crypt(path_tocrypt,path_crypted)) {
- fprintf(stderr,"\nExiting ...\n");
- return 1;
- }
- return 0;
- }
- Section::Section()
- {
- sname[0]='\0';
- voffset=0;
- vsize=0;
- roffset=0;
- rsize=0;
- flags=0;
- psort=NULL;
- next=NULL;
- }
- Section::Section(Section *_section)
- {
- snprintf(sname,sizeof(sname),"%s",_section->sname);
- voffset=_section->voffset;
- vsize=_section->vsize;
- roffset=_section->roffset;
- rsize=_section->rsize;
- flags=_section->flags;
- psort=_section->psort;
- next=_section->next;
- }
- Info::Info(sort_t _sort)
- {
- size=0;
- oep=0;
- imagebase=0;
- nos=0;
- import_rva=0;
- import_size=0;
- sort=_sort;
- head=NULL;
- tail=NULL;
- tocrypt=NULL;
- crypted=NULL;
- }
- Info::~Info()
- {
- Section *tmp;
- while (head!=NULL) {
- tmp=head;
- head=head->next;
- delete tmp;
- }
- tail=head;
- if (tocrypt) fclose(tocrypt);
- if (crypted) fclose(crypted);
- }
- int Info::crypt(char *_tocrypt, char *_crypted)
- {
- struct stat flst;
- char path_tocrypt[FILENAME_MAX], path_crypted[FILENAME_MAX];
- if (argflags & FLAG_V) printf("ObCrypter v1.2 for p0wnbox.com by OBLiQUE\n");
- if (_crypted) {
- stat(_crypted,&flst);
- if (S_ISDIR(flst.st_mode)) {
- if (_crypted[strlen(_crypted)-1]==c)
- _crypted[strlen(_crypted)-1]='\0';
- snprintf(path_crypted,FILENAME_MAX,"%s%c%s",_crypted,c,"crypted.exe");
- } else snprintf(path_crypted,FILENAME_MAX,"%s",_crypted);
- } else snprintf(path_crypted,FILENAME_MAX,"crypted.exe");
- snprintf(path_tocrypt,FILENAME_MAX,"%s",_tocrypt);
- if (!strncmp(path_crypted,path_tocrypt,FILENAME_MAX)) {
- fprintf(stderr,"ERROR! The filename should be different\n");
- return 1;
- }
- if (!(tocrypt=fopen(path_tocrypt,"rb"))) {
- fprintf(stderr,"ERROR!: Can't open the file\n");
- return 1;
- }
- if (readinfo()) return 1;
- if (argflags & FLAG_V) printf("Output file: %s\n\n",path_crypted);
- if (!stat(path_crypted,&flst) && (!(argflags & FLAG_F))) {
- char input[3];
- do {
- printf("File exist! Do you want to overwrite? [Y/N]: ");
- scanf("%2s%*[^\n]",input);
- } while (input[1]!='\0' || (input[0]!='Y' && input[0]!='y' && input[0]!='n' && input[0]!='N'));
- if (input[0]=='N' || input[0]=='n') return 1;
- argflags|=FLAG_F;
- if (argflags & FLAG_V) printf("\n");
- }
- if (!(crypted=fopen(path_crypted,"wb"))) {
- fprintf(stderr,"ERROR!: Can't write the file\n");
- return 1;
- }
- writefile();
- return 0;
- }
- int Info::insert(Section *_section) // instert in sorted linked-listed
- {
- Section *new_section = new Section(_section);
- new_section->next=NULL;
- if (sort==byVirtualOffset) new_section->psort=&new_section->voffset;
- else if (sort==byRawOffset) new_section->psort=&new_section->roffset;
- if (head==NULL) tail=head=new_section;
- else if (*head->psort>*new_section->psort) {
- new_section->next=head;
- head=new_section;
- } else {
- Section *previous=head, *current=head->next;
- while (current!=NULL) {
- if (*current->psort>*new_section->psort)
- break;
- previous=current;
- current=current->next;
- }
- new_section->next=current;
- previous->next=new_section;
- if (new_section->next==NULL) tail=new_section;
- }
- return 0;
- }
- int Info::resort(sort_t _sort)
- {
- Info *new_info = new Info(_sort); // create new linked-list
- Section *tmp=head;
- while (tmp!=NULL) { // insert the sections to the new linked-list
- new_info->insert(tmp);
- tmp=tmp->next;
- }
- while (head!=NULL) { // delete the sections from the old linked-list
- tmp=head;
- head=head->next;
- delete tmp;
- }
- head=new_info->head; // change the pointer to the new head
- tail=new_info->tail; // change the pointer to the new tail
- new_info->tail=NULL; // i make it NULL to prevent deleting the new sorted list
- new_info->head=NULL;
- delete new_info; // delete the new linked-list
- return 0;
- }
- int Info::readinfo()
- {
- unsigned int tmp;
- Section *current;
- fseek(tocrypt,0,SEEK_END);
- size=ftell(tocrypt);
- fseek(tocrypt,0x3c,SEEK_SET);
- fread(&tmp,4,1,tocrypt);
- fseek(tocrypt,tmp,SEEK_SET);
- pe_start=ftell(tocrypt);
- fread(&tmp,4,1,tocrypt);
- if (tmp!=0x00004550) {
- fprintf(stderr,"ERROR!: Not a PE-Format file\n");
- return 1;
- }
- if (argflags & FLAG_V) printf("\nFile Info\n\n");
- fseek(tocrypt,2,SEEK_CUR);
- fread(&nos,2,1,tocrypt);
- if (argflags & FLAG_V) printf("NumberOfSections ... %#.4x\n",nos);
- fseek(tocrypt,0x20,SEEK_CUR);
- fread(&oep,4,1,tocrypt);
- if (argflags & FLAG_V) printf("Original EntryPoint ... %#.8x\n",oep);
- fseek(tocrypt,8,SEEK_CUR);
- fread(&imagebase,4,1,tocrypt);
- if (argflags & FLAG_V) printf("ImageBase ... %#.8x\n",imagebase);
- fseek(tocrypt,0x48,SEEK_CUR);
- fread(&import_rva,4,1,tocrypt);
- if (argflags & FLAG_V) printf("ImportTable RVA ... %#.8x\n",import_rva);
- fread(&import_size,4,1,tocrypt);
- if (argflags & FLAG_V) printf("ImportTable Size ... %#.8x\n",import_size);
- fseek(tocrypt,0x70,SEEK_CUR);
- if (argflags & FLAG_V) printf("\nSections Info\n\n");
- tmp=0;
- if (argflags & FLAG_V) {
- printf("+----------+-------------+------------+------------+------------+------------+\n");
- printf("| Name | VirtualSize | Vir.Offset | RawSize | RawOffset | Flags |\n");
- printf("+----------+-------------+------------+------------+------------+------------+\n");
- }
- while(tmp<nos) {
- int flag=0;
- Section *new_section = new Section();
- fread(new_section->sname,8,1,tocrypt);
- if (argflags & FLAG_V) printf("| %-8s |",new_section->sname);
- fread(&new_section->vsize,4,1,tocrypt);
- if (argflags & FLAG_V) printf(" %#-11.8x |",new_section->vsize);
- fread(&new_section->voffset,4,1,tocrypt);
- if (argflags & FLAG_V) printf(" %#-10.8x |",new_section->voffset);
- fread(&new_section->rsize,4,1,tocrypt);
- if (argflags & FLAG_V) printf(" %#-10.8x |",new_section->rsize);
- fread(&new_section->roffset,4,1,tocrypt);
- if (argflags & FLAG_V) printf(" %#-10.8x |",new_section->roffset);
- fseek(tocrypt,0xc,SEEK_CUR);
- fread(&new_section->flags,4,1,tocrypt);
- if (argflags & FLAG_V) printf(" %#-10.8x |\n",new_section->flags);
- if (!strcmp(new_section->sname,".idata")) // rename the .idata
- snprintf(new_section->sname,sizeof(new_section->sname),".import");
- insert(new_section);
- delete new_section;
- tmp++;
- }
- if (argflags & FLAG_V) printf("+----------+-------------+------------+------------+------------+------------+\n");
- tmp=0;
- current=head;
- while (current!=NULL) {
- if (current->roffset==0x0 || current->rsize==0x0) {
- current=current->next;
- continue;
- }
- if (current->roffset>pe_start) {
- if (!tmp) tmp=current->roffset;
- else if (current->roffset<tmp) tmp=current->roffset;
- }
- current=current->next;
- }
- if (((nos+2)*0x28+pe_start+0xf8)>=tmp) {
- fprintf(stderr,"ERROR!: No space for new sections\n");
- return 1;
- }
- for (tmp=0; tmp<2; tmp++) {
- Section *new_section = new Section();
- current=head;
- while (current!=NULL) {
- new_section->voffset=(new_section->voffset<current->voffset+current->vsize)?current->voffset+current->vsize:new_section->voffset;
- new_section->roffset=(new_section->roffset<current->roffset+current->rsize)?current->roffset+current->rsize:new_section->roffset;
- current=current->next;
- }
- new_section->voffset+=(0x1000-new_section->voffset%0x1000)%0x1000;
- if (tmp==0) { // add new .idata section
- snprintf(new_section->sname,sizeof(new_section->sname),".idata");
- new_section->vsize=0x200;
- new_section->rsize=0x200;
- new_section->flags=0xc0000040;
- } else if (tmp==1) { // add .Ob section
- snprintf(new_section->sname,sizeof(new_section->sname),".Ob");
- new_section->vsize=0x92+0x11*nos+0x88; // stub size
- new_section->vsize+=(0x200-new_section->vsize%0x200)%0x200;
- new_section->rsize=0x92+0x11*nos+0x88;
- new_section->rsize+=(0x200-new_section->rsize%0x200)%0x200;
- new_section->flags=0xe00000e0;
- }
- insert(new_section);
- delete new_section;
- nos++;
- }
- if (argflags & FLAG_V) printf("\n");
- return 0;
- }
- int Info::writefile()
- {
- char c_tmp;
- unsigned int i_tmp, i_tmp2;
- Section *current, *s_tmp;
- int xornum, flag;
- char msg[]="\rWriting the crypted file [%u/%u bytes]";
- fseek(tocrypt,0,SEEK_SET);
- if (argflags & FLAG_V) printf(msg,ftell(tocrypt),size);
- i_tmp=pe_start+0xf8;
- while (ftell(tocrypt)<i_tmp)
- if (ftell(tocrypt)==pe_start+0x6) {
- fwrite(&nos,2,1,crypted);
- fseek(tocrypt,2,SEEK_CUR);
- } else if (ftell(tocrypt)==pe_start+0x28) {
- fwrite(&tail->voffset,4,1,crypted);
- fseek(tocrypt,4,SEEK_CUR);
- } else if (ftell(tocrypt)==pe_start+0x50) {
- i_tmp2=tail->voffset+tail->vsize;
- fwrite(&i_tmp2,4,1,crypted);
- fseek(tocrypt,4,SEEK_CUR);
- } else if (ftell(tocrypt)==pe_start+0x80) {
- i_tmp2=tail->voffset-0x1000;
- fwrite(&i_tmp2,4,1,crypted);
- fwrite("\x63\x00\x00\x00",4,1,crypted);
- fseek(tocrypt,8,SEEK_CUR);
- } else {
- fread(&c_tmp,1,1,tocrypt);
- fwrite(&c_tmp,1,1,crypted);
- }
- current=head;
- while (current!=NULL) {
- fwrite(current->sname,8,1,crypted);
- fwrite(¤t->vsize,4,1,crypted);
- fwrite(¤t->voffset,4,1,crypted);
- fwrite(¤t->rsize,4,1,crypted);
- if ((argflags & FLAG_E) && (!strcmp(current->sname,".Ob") || !strcmp(current->sname,".idata"))) {
- i_tmp=size;
- i_tmp+=(0x1000-i_tmp%0x1000)%0x1000;
- if (!strcmp(current->sname,".Ob"))
- i_tmp+=0x200;
- fwrite(&i_tmp,4,1,crypted);
- } else fwrite(¤t->roffset,4,1,crypted);
- fseek(tocrypt,ftell(crypted),SEEK_SET);
- for (i_tmp=0;i_tmp<0xc;i_tmp++) {
- fread(&c_tmp,1,1,tocrypt);
- fwrite(&c_tmp,1,1,crypted);
- }
- i_tmp=current->flags | 0x80000000; // make the section writable
- fwrite(&i_tmp,4,1,crypted);
- current=current->next;
- }
- fseek(tocrypt,ftell(crypted),SEEK_SET);
- resort(byRawOffset);
- current=head;
- while (current->roffset==0x0 || current->rsize==0x0)
- current=current->next;
- while (ftell(tocrypt)<current->roffset) { // write to the file util the start of the first section
- fread(&c_tmp,1,1,tocrypt);
- fwrite(&c_tmp,1,1,crypted);
- }
- /* crypter */
- while (current!=NULL) {
- if (current->roffset==0x0 || current->rsize==0x0) {
- current=current->next;
- continue;
- }
- if (strncmp(current->sname,".idata",8)) {
- fseek(tocrypt,current->roffset,SEEK_SET);
- s_tmp=current->next;
- while (s_tmp!=NULL && (s_tmp->roffset==0x0 || s_tmp->rsize==0x0))
- s_tmp=s_tmp->next;
- if ((!strcmp(current->sname,".rsrc") ||
- !strcmp(current->sname,".rdata")) &&
- (import_rva>current->voffset &&
- import_rva<(current->voffset+current->vsize))) //if import table is in .rsrc or .rdata
- i_tmp=(import_rva-current->voffset)+current->roffset;
- else
- crypt: i_tmp=s_tmp->roffset;
- xornum=0xa0;
- while (ftell(tocrypt)<i_tmp) {
- fread(&c_tmp,1,1,tocrypt);
- if ((strcmp(current->sname,".rsrc") &&
- strcmp(current->sname,".rdata")) || flag) { // crypt all sections except
- xornum++;
- if (xornum==0xff) xornum=0xa1;
- if (c_tmp!='\x0' && c_tmp!=(char)xornum) c_tmp^=xornum;
- }
- fwrite(&c_tmp,1,1,crypted);
- if ((argflags & FLAG_V) && !(ftell(tocrypt)%0xffff)) {
- printf(msg,ftell(tocrypt),size);
- fflush(stdout);
- }
- }
- flag=0;
- if (i_tmp<s_tmp->roffset) {
- flag=1;
- goto crypt; // crypt the import table
- }
- } else {
- if (argflags & FLAG_E) { // write the whole file
- current->roffset=size;
- current->roffset+=(0x1000-current->roffset%0x1000)%0x1000;
- while (ftell(tocrypt)<size) {
- fread(&c_tmp,1,1,tocrypt);
- fwrite(&c_tmp,1,1,crypted);
- if ((argflags & FLAG_V) && !(ftell(tocrypt)%0xffff)) {
- printf(msg,ftell(tocrypt),size);
- fflush(stdout);
- }
- }
- while(ftell(crypted)<current->roffset)
- fwrite("\x0",1,1,crypted);
- }
- /* new Import Table section */
- fwrite("\x0\x0\x0\x0",4,1,crypted); // OriginalFirstThunk
- fwrite("\x0\x0\x0\x0",4,1,crypted); // TimeDateStamp
- fwrite("\x0\x0\x0\x0",4,1,crypted); // ForwarderChain
- i_tmp=current->voffset+0x28;
- fwrite(&i_tmp,4,1,crypted); // Name
- i_tmp=current->voffset+0x35;
- fwrite(&i_tmp,4,1,crypted); // FirstThunk
- for (i_tmp=0;i_tmp<5;i_tmp++)
- fwrite("\x0\x0\x0\x0",4,1,crypted); // add one null descriptor
- fwrite("KERNEL32.DLL\x0",13,1,crypted);
- i_tmp=current->voffset+0x41;
- fwrite(&i_tmp,4,1,crypted); // pointer to the LoadLibraryA
- i_tmp=current->voffset+0x4F;
- fwrite(&i_tmp,4,1,crypted); // pointer to the GetProcAddress
- fwrite("\x0\x0\x0\x0",4,1,crypted); // end of API pointers
- fwrite("\x0\x0",2,1,crypted); // Hint
- fwrite("LoadLibraryA",12,1,crypted);
- fwrite("\x0\x0",2,1,crypted); // Hint
- fwrite("GetProcAddress\x0\x0\x0\x0",18,1,crypted);
- while (ftell(crypted)<current->roffset+current->rsize)
- fwrite("\x0",1,1,crypted);
- current=current->next;
- /* stub section */
- /* ;stub in opcodes and assembly
- *
- * ;section information
- *
- * B9 xxxxxxxx MOV ECX, [start of section]
- * BB xxxxxxxx MOV EBX, [end of section]
- * BA xxxxxxxx MOV EDX, [address for the next section information ]
- *
- * ;decrypter
- *
- * B0 A0 MOV AL,0A0
- * FEC0 INC AL
- * 3C FF CMP AL,0FF ;to eax will be 0xA1 until 0xFE
- * 74 F8 JZ SHORT [address of the 4th mov]
- * 36:8039 00 CMP BYTE PTR SS:[ECX],0
- * 74 08 JZ SHORT [sto inc ecx]
- * 36:38 01 CMP BYTE PTR SS:[ECX],AL
- * 74 03 JZ SHORT [sto inc ecx]
- * 363001 XOR BYTE PTR SS:[ECX],AL
- * 41 INC ECX
- * 3BCB CMP ECX,EDX
- * 75 E7 JNZ SHORT [address of the 1st inc]
- * B8 xxxxxxxx MOV EAX, [address of the 4th mov]
- * FF E2 JMP EDX
- *
- * ;next section information...this will repeated for all the crypted sections
- *
- * B9 xxxxxxxx MOV ECX, [start of section]
- * BB xxxxxxxx MOV EBX, [end of section]
- * BA xxxxxxxx MOV EDX, [address for the next section information ]
- * FF E0 JMP EAX ;back to the decrypter
- *
- * ;old ImportTable loader
- *
- * 55 PUSH EBP
- * 8BEC MOV EBP,ESP
- * 83EC 14 SUB ESP,0C ;create memory for 3 dword variables
- * BB xxxxxxxx MOV EBX,[imagebase + import_rva]
- * 36:8B53 0C MOV EDX,DWORD PTR SS:[EBX+C] ;get the name of dll
- * 8955 FC MOV DWORD PTR SS:[EBP-4],EDX
- * 8145 FC xxxxxxxx ADD DWORD PTR SS:[EBP-4],[imagebase]
- * 36:8B53 10 MOV EDX,DWORD PTR SS:[EBX+10] ;get the FirstThunk
- * 8955 F8 MOV DWORD PTR SS:[EBP-8], EDX
- * 8145 F8 xxxxxxxx ADD DWORD PTR SS:[EBP-8], [imagebase]
- * FF75 FC PUSH DWORD PTR SS:[EBP-4] ;push the arg1 (dll name)
- * 36:FF15 xxxxxxxx CALL DWORD PTR SS:[imagebase+voffset+0x35] ;call LoadLibrayA
- * 8945 F4 MOV DWORD PTR SS:[EBP-C], EAX ;save the result
- * 8B4D F8 MOV ECX,DWORD PTR SS:[EBP-8]
- * 36:8B11 MOV EDX,DWORD PTR SS:[ECX] ;get the API name
- * F7C2 00000080 TEST EDX,80000000
- * 74 08 JZ SHORT
- * 81E2 FFFFFF7F AND EDX,7FFFFFFF
- * EB 06 JMP SHORT
- * 81C2 xxxxxxxx ADD EDX,[imagebase + 2]
- * 51 PUSH ECX ;save ecx in the stack
- * 52 PUSH EDX ;push arg2 (API name)
- * FF75 F4 PUSH DWORD PTR SS:[EBP-C] ;push arg1 (first result)
- * 36:FF15 xxxxxxxx CALL DWORD PTR SS:[imagebase+voffset+0x39] ;call GetProcAddress
- * 59 POP ECX; restore ecx
- * 36:8901 MOV DWORD PTR SS:[ECX],EAX ;save the IAT pointer
- * 83C1 04 ADD ECX,4
- * 36:8339 00 CMP DWORD PTR SS:[ECX],0
- * 75 CE JNZ SHORT ;loop back for the next API
- * 83C3 14 ADD EBX,14 ;next descriptor
- * 36:837B 10 00 CMP DWORD PTR SS:[EBX+10],0
- * 75 98 JNZ SHORT ;loop back for the next dll
- * 8BE5 MOV ESP,EBP ;clear the memory
- * 5D POP EBP
- *
- * B8 xxxxxxxx MOV EAX,[orignal entry point + imagebase]
- * FF E0 JMP EAX
- */
- if (argflags & FLAG_V) {
- printf(msg,ftell(tocrypt),size);
- if (ftell(tocrypt)<size)
- printf("\n%lu useless bytes have been cleaned ...",size-ftell(tocrypt));
- printf("\nWriting the stub ...\n");
- }
- /* stub */
- s_tmp=head;
- int i_edx;
- fwrite("\xB9",1,1,crypted);
- while (s_tmp!=NULL && (s_tmp->roffset==0x0 || s_tmp->rsize==0x0))
- s_tmp=s_tmp->next;
- i_tmp=s_tmp->voffset+imagebase;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\xBB",1,1,crypted);
- i_tmp=s_tmp->voffset+s_tmp->vsize+imagebase;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\xBA",1,1,crypted);
- i_edx=imagebase+current->voffset+0x31;
- fwrite(&i_edx,4,1,crypted);
- fwrite("\xB0\xA0",2,1,crypted);
- fwrite("\xFE\xC0",2,1,crypted);
- fwrite("\x3C\xFF",2,1,crypted);
- fwrite("\x74\xF8",2,1,crypted);
- fwrite("\x36\x80\x39\x00",4,1,crypted);
- fwrite("\x74\x08",2,1,crypted);
- fwrite("\x36\x38\x01",3,1,crypted);
- fwrite("\x74\x03",2,1,crypted);
- fwrite("\x36\x30\x01",3,1,crypted);
- fwrite("\x41",1,1,crypted);
- fwrite("\x3B\xCB",2,1,crypted);
- fwrite("\x75\xE7",2,1,crypted);
- fwrite("\xB8",1,1,crypted);
- i_tmp=imagebase+current->voffset+0xf;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\xFF\xE2",2,1,crypted);
- s_tmp=s_tmp->next;
- while (strncmp(s_tmp->sname,".idata",8)) {
- flag=0;
- if (s_tmp->roffset==0x0 || s_tmp->voffset==0x0) {
- s_tmp=s_tmp->next;
- continue;
- }
- if (!strcmp(s_tmp->sname,".rsrc") ||
- !strcmp(s_tmp->sname,".rdata")) {
- if (import_rva>s_tmp->voffset &&
- import_rva<(s_tmp->voffset+s_tmp->vsize))
- flag=1;
- else {
- s_tmp=s_tmp->next;
- continue;
- }
- }
- fwrite("\xB9",1,1,crypted);
- if (flag) i_tmp=imagebase+import_rva;
- else i_tmp=imagebase+s_tmp->voffset;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\xBB",1,1,crypted);
- i_tmp=imagebase+s_tmp->voffset+s_tmp->vsize;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\xBA",1,1,crypted);
- i_edx+=0x11;
- fwrite(&i_edx,4,1,crypted);
- fwrite("\xFF\xE0",2,1,crypted);
- s_tmp=s_tmp->next;
- }
- /* old ImportTable loader */
- fwrite("\x55",1,1,crypted);
- fwrite("\x8B\xEC",2,1,crypted);
- fwrite("\x83\xEC\x0C",3,1,crypted);
- fwrite("\xBB",1,1,crypted);
- i_tmp=imagebase+import_rva;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\x36\x8B\x53\x0C",4,1,crypted);
- fwrite("\x89\x55\xFC",3,1,crypted);
- fwrite("\x81\x45\xFC",3,1,crypted);
- fwrite(&imagebase,4,1,crypted);
- fwrite("\x36\x8B\x53\x10",4,1,crypted);
- fwrite("\x89\x55\xF8",3,1,crypted);
- fwrite("\x81\x45\xF8",3,1,crypted);
- fwrite(&imagebase,4,1,crypted);
- fwrite("\xFF\x75\xFC",3,1,crypted);
- fwrite("\x36\xFF\x15",3,1,crypted);
- i_tmp=imagebase+s_tmp->voffset+0x35;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\x89\x45\xF4",3,1,crypted);
- fwrite("\x8B\x4D\xF8",3,1,crypted);
- fwrite("\x36\x8B\x11",3,1,crypted);
- fwrite("\xF7\xC2\x00\x00\x00\x80",6,1,crypted);
- fwrite("\x74\x08",2,1,crypted);
- fwrite("\x81\xE2\xFF\xFF\xFF\x7F",6,1,crypted);
- fwrite("\xEB\x06",2,1,crypted);
- fwrite("\x81\xC2",2,1,crypted);
- i_tmp=imagebase+2;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\x51",1,1,crypted);
- fwrite("\x52",1,1,crypted);
- fwrite("\xFF\x75\xF4",3,1,crypted);
- fwrite("\x36\xFF\x15",3,1,crypted);
- i_tmp=imagebase+s_tmp->voffset+0x39;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\x59",1,1,crypted);
- fwrite("\x36\x89\x01",3,1,crypted);
- fwrite("\x83\xC1\x04",3,1,crypted);
- fwrite("\x36\x83\x39\x00",4,1,crypted);
- fwrite("\x75\xCE",2,1,crypted);
- fwrite("\x83\xC3\x14",3,1,crypted);
- fwrite("\x36\x83\x7B\x10\x00",5,1,crypted);
- fwrite("\x75\x98",2,1,crypted);
- fwrite("\x8B\xE5",2,1,crypted);
- fwrite("\x5D",1,1,crypted);
- /* jmp to OEP */
- fwrite("\xB8",1,1,crypted);
- i_tmp=imagebase+oep;
- fwrite(&i_tmp,4,1,crypted);
- fwrite("\xFF\xE0",2,1,crypted);
- }
- while (ftell(crypted)<current->roffset+current->rsize)
- fwrite("\x0",1,1,crypted);
- current=current->next;
- }
- if (argflags & FLAG_V) printf("Done!\n");
- return 0;
- }
