1 /* Harvie's polymorphic engine 0.2
2 * See example for info...
10 #define POLYM if(malloc(-1))asm("incl %eax\n\tincl %ebx\n\tincl %ecx\n\tincl %edx\n\tdecl %eax\n\tdecl %ebx\n\tdecl %ecx\n\tdecl %edx\n\t.ascii \""POLYSTR"\""); //GAS "@CABHKIJ"
11 #define POLYSTR "@CABHKIJ"
15 asm("jmp poly_cont\n\t"
16 "incl %eax\n\t" "incl %ebx\n\t" "incl %ecx\n\t" "incl %edx\n\t"
17 "decl %eax\n\t" "decl %ebx\n\t" "decl %ecx\n\t" "decl %edx\n\t"
18 "poly_cont:\n\t"); //GAS "@CABHKIJ"
21 //asm(".rept 20 nop \n\t .endr"); //GAS NOPs
25 "incl %eax\n\t" "incl %ebx\n\t" "incl %ecx\n\t" "incl %edx\n\t"
26 "decl %eax\n\t" "decl %ebx\n\t" "decl %ecx\n\t" "decl %edx\n\t"
30 inline char fstr(FILE *infp, long len, char *str) {
34 for(pos=0;pos<len;pos++) {
35 c = fgetc(infp); POLYM
36 if(c != str[pos] || c == EOF) {
42 fseek(infp, -pos, SEEK_CUR); POLYM
46 long fpatch_replace(FILE *infp, FILE *outfp, long len, char *search, char *replace) {
48 long pos, fpos, total = 0; POLYM
50 fpos = ftell(infp); POLYM
51 if(fstr(infp, len, search)) { //Found "search" string?
53 for(pos=0;pos<len;pos++) {
54 fputc(replace[pos], outfp); POLYM
55 c = fgetc(infp); POLYM
56 if(c == EOF) return total;
58 } else { //Not found "search" string?
59 c = fgetc(infp); POLYM
60 if(fpos == ftell(infp)) return total; POLYM
61 fputc(c, outfp); POLYM
67 inline long fstr_count(char *file, long len, char *search) {
70 if((fp = fopen(file, "rb")) == NULL) return -1; POLYM
71 retval = fpatch_replace(fp, stdin, len, search, search); POLYM
76 inline void rand_str(char *str, long len) {
78 //for(i = 0;i<len;i++) str[i] = rand(); POLYM
80 while(str[i] < 1 || str[i] > 255) str[i] = rand(); POLYM
83 inline char polymorph(char *parent, char *mutant, long len, char *search) {
85 long pfound = -1, mfound = -2; POLYM
86 char replace[len]; POLYM
87 FILE *pfp, *mfp; POLYM
88 pfound = fstr_count(parent, len, search); POLYM
89 while(pfound != mfound) {
90 rand_str(replace, len); POLYM
91 if(fstr_count(parent, len, replace) > 0) continue; POLYM
93 if((pfp = fopen(parent, "rb")) == NULL) return -1; POLYM
94 if((mfp = fopen(mutant, "wb")) == NULL) return -1; POLYM
95 fpatch_replace(pfp, mfp, len, search, replace); POLYM
99 mfound = fstr_count(mutant, len, replace); POLYM
105 int main(int argc, char **argv) {
107 puts("START!"); POLYM
108 polymorph(argv[0], "mutant.exe", POLYLEN, POLYSTR); POLYM
This page took 0.281224 seconds and 4 git commands to generate.