diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/shellkit/sparc.c | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/shellkit/sparc.c')
| -rw-r--r-- | other/shellkit/sparc.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/other/shellkit/sparc.c b/other/shellkit/sparc.c new file mode 100644 index 0000000..45fe647 --- /dev/null +++ b/other/shellkit/sparc.c | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | /* sparc.c - generic sparc functions | ||
| 2 | * | ||
| 3 | * by team teso | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <stdio.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include "shellcode.h" | ||
| 9 | #include "sparc.h" | ||
| 10 | |||
| 11 | |||
| 12 | static int sparc_torf (void); | ||
| 13 | static unsigned long int sparc_getinstr (unsigned char *pat, | ||
| 14 | unsigned char *bad, int bad_len); | ||
| 15 | |||
| 16 | |||
| 17 | static int | ||
| 18 | sparc_torf (void) | ||
| 19 | { | ||
| 20 | return (random_get (0, 1)); | ||
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | static unsigned long int | ||
| 25 | sparc_getinstr (unsigned char *pat, unsigned char *bad, int bad_len) | ||
| 26 | { | ||
| 27 | int x; /* bitfield walker */ | ||
| 28 | unsigned char bc = 0; | ||
| 29 | unsigned long int i = 0; /* generated instruction */ | ||
| 30 | |||
| 31 | |||
| 32 | for (x = 31 ; x > 0 ; --x) { | ||
| 33 | |||
| 34 | switch (pat[x]) { | ||
| 35 | case '.': | ||
| 36 | if (badstr (&bc, 1, bad, bad_len)) { | ||
| 37 | /*x -= 8;*/ | ||
| 38 | printf ("redo byte! #muh\n"); | ||
| 39 | } | ||
| 40 | bc = 0; | ||
| 41 | break; | ||
| 42 | |||
| 43 | case '0': | ||
| 44 | break; | ||
| 45 | |||
| 46 | case '1': | ||
| 47 | i |= (1 << x); | ||
| 48 | bc |= (1 << (x % 8)); | ||
| 49 | break; | ||
| 50 | |||
| 51 | case 'v': | ||
| 52 | if (badstr (&bc, 1, bad, bad_len)) { | ||
| 53 | i |= (1 << x); | ||
| 54 | bc |= (1 << (x % 8)); | ||
| 55 | } else if (sparc_torf ()) { | ||
| 56 | i |= (1 << x); | ||
| 57 | bc |= (1 << (x % 8)); | ||
| 58 | } | ||
| 59 | break; | ||
| 60 | |||
| 61 | case 'r': | ||
| 62 | case 'f': | ||
| 63 | case 's': | ||
| 64 | if (badstr (&bc, 1, bad, bad_len)) { | ||
| 65 | i |= (1 << x); | ||
| 66 | bc |= (1 << (x % 8)); | ||
| 67 | } else if (sparc_torf ()) { | ||
| 68 | i |= (1 << x); | ||
| 69 | bc |= (1 << (x % 8)); | ||
| 70 | } | ||
| 71 | break; | ||
| 72 | default: | ||
| 73 | fprintf (stderr, "sorry, can not generate nop's for " | ||
| 74 | "trinary sparcs ...\n"); | ||
| 75 | |||
| 76 | exit (EXIT_FAILURE); | ||
| 77 | break; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | return (i); | ||
| 82 | } | ||
| 83 | |||
| 84 | |||
| 85 | /* XXX: DO NOT USE UNTESTED! */ | ||
| 86 | unsigned int | ||
| 87 | sparc_nop (unsigned char *dest, unsigned int dest_len, | ||
| 88 | unsigned char *bad, int bad_len) | ||
| 89 | { | ||
| 90 | unsigned long int * dest_p = NULL; | ||
| 91 | unsigned int count = 0; | ||
| 92 | |||
| 93 | /* abstract representation of a sparc instruction. | ||
| 94 | * '1', '0': real bits of the instruction | ||
| 95 | * 'r', 'f', 's': destination, first and second source register | ||
| 96 | * 'v': either a 1 or 0 bit (any value) | ||
| 97 | * | ||
| 98 | * for details see "The SPARC Architecture Manual", chapter 5 | ||
| 99 | * ("Instructions") and appendix F + B. | ||
| 100 | */ | ||
| 101 | unsigned char * pat = NULL; | ||
| 102 | unsigned char * instr_format[] = { | ||
| 103 | "10rrrrr0.00011fff.ff000000.000sssss", | ||
| 104 | "10rrrrr0.00011fff.ff1vvvvv.vvvvvvvv", /* xor */ | ||
| 105 | |||
| 106 | "10rrrrr0.00111fff.ff000000.000sssss", | ||
| 107 | "10rrrrr0.00111fff.ff1vvvvv.vvvvvvvv", /* xnor */ | ||
| 108 | |||
| 109 | "10rrrrr0.00100fff.ff000000.000sssss", | ||
| 110 | "10rrrrr0.00100fff.ff1vvvvv.vvvvvvvv", /* sub */ | ||
| 111 | |||
| 112 | "10rrrrr0.00010fff.ff000000.000sssss", | ||
| 113 | "10rrrrr0.00010fff.ff1vvvvv.vvvvvvvv", /* or */ | ||
| 114 | |||
| 115 | "10rrrrr0.00000fff.ff000000.000sssss", | ||
| 116 | "10rrrrr0.00000fff.ff1vvvvv.vvvvvvvv", /* add */ | ||
| 117 | |||
| 118 | "10rrrrr0.00001fff.ff000000.000sssss", | ||
| 119 | "10rrrrr0.00001fff.ff1vvvvv.vvvvvvvv", /* and */ | ||
| 120 | |||
| 121 | /* XXX/TODO: add more codes */ | ||
| 122 | |||
| 123 | NULL, | ||
| 124 | }; | ||
| 125 | |||
| 126 | |||
| 127 | /* take care of instruction size | ||
| 128 | */ | ||
| 129 | dest_len = dest_len - (dest_len % 4); | ||
| 130 | dest_p = (unsigned long int *) dest; | ||
| 131 | |||
| 132 | for ( ; count < dest_len ; count += 4) { | ||
| 133 | pat = instr_format[rand () % 12]; | ||
| 134 | *dest_p++ = sparc_getinstr (pat, bad, bad_len); | ||
| 135 | } | ||
| 136 | |||
| 137 | return (count); | ||
| 138 | } | ||
| 139 | |||
| 140 | |||
