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/splocoder.c | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/shellkit/splocoder.c')
| -rw-r--r-- | other/shellkit/splocoder.c | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/other/shellkit/splocoder.c b/other/shellkit/splocoder.c new file mode 100644 index 0000000..96e36f8 --- /dev/null +++ b/other/shellkit/splocoder.c | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | /* | ||
| 2 | |||
| 3 | A tool for the young exploit coder, Copyright (c) acpizer, 2001. | ||
| 4 | |||
| 5 | */ | ||
| 6 | |||
| 7 | #include <stdio.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <sys/utsname.h> | ||
| 10 | |||
| 11 | |||
| 12 | char small_global[] = "acpizer"; | ||
| 13 | |||
| 14 | int uninitialized_global; | ||
| 15 | |||
| 16 | |||
| 17 | int endianess() { | ||
| 18 | union { | ||
| 19 | long l; | ||
| 20 | char c[sizeof (long)]; | ||
| 21 | } u; | ||
| 22 | |||
| 23 | u.l = 1; | ||
| 24 | |||
| 25 | return (u.c[sizeof (long) - 1] == 1); | ||
| 26 | } | ||
| 27 | |||
| 28 | |||
| 29 | static int iterate = 10; | ||
| 30 | |||
| 31 | int stack_growsdown(int *x) { | ||
| 32 | auto int y; | ||
| 33 | |||
| 34 | |||
| 35 | y = (x > &y); | ||
| 36 | |||
| 37 | if (--iterate > 0) | ||
| 38 | y = stack_growsdown(&y); | ||
| 39 | |||
| 40 | if (y != (x > &y)) | ||
| 41 | exit(1); | ||
| 42 | |||
| 43 | return y; | ||
| 44 | } | ||
| 45 | |||
| 46 | typedef struct { | ||
| 47 | char * sys_name; | ||
| 48 | char * sys_release; | ||
| 49 | char * sys_version; | ||
| 50 | char * sys_machine; | ||
| 51 | |||
| 52 | unsigned long int malloc_zero; | ||
| 53 | unsigned long int malloc_neg; | ||
| 54 | unsigned long int malloc_big; | ||
| 55 | |||
| 56 | unsigned long int malloc_small; | ||
| 57 | unsigned long int malloc_tiny; | ||
| 58 | |||
| 59 | unsigned long int bss; | ||
| 60 | unsigned long int data; | ||
| 61 | |||
| 62 | int sizeof_int; | ||
| 63 | int sizeof_voidptr; | ||
| 64 | |||
| 65 | unsigned long int env_start; | ||
| 66 | |||
| 67 | unsigned long int frame_addr; | ||
| 68 | |||
| 69 | int stack_down; | ||
| 70 | int endian_big; | ||
| 71 | } sys_def; | ||
| 72 | |||
| 73 | sys_def this; | ||
| 74 | |||
| 75 | |||
| 76 | int | ||
| 77 | main (int argc, char *argv[], char *env[]) | ||
| 78 | { | ||
| 79 | struct utsname uts; | ||
| 80 | |||
| 81 | char localstack[5]; | ||
| 82 | auto int x; | ||
| 83 | |||
| 84 | |||
| 85 | printf("splocoder, v1.0 by acpizer & sc -- team teso.\n\n"); | ||
| 86 | |||
| 87 | uname (&uts); | ||
| 88 | |||
| 89 | this.sys_name = uts.sysname; | ||
| 90 | this.sys_release = uts.release; | ||
| 91 | this.sys_version = uts.version; | ||
| 92 | this.sys_machine = uts.machine; | ||
| 93 | |||
| 94 | #ifdef VERBOSE | ||
| 95 | printf("System: %s %s %s %s\n\n", uts.sysname, uts.release, uts.version, | ||
| 96 | uts.machine); | ||
| 97 | #endif | ||
| 98 | |||
| 99 | this.malloc_zero = (unsigned long int) malloc (0); | ||
| 100 | this.malloc_neg = (unsigned long int) malloc (-4); | ||
| 101 | this.malloc_big = (unsigned long int) malloc (1024 * 1024); | ||
| 102 | |||
| 103 | #ifdef VERBOSE | ||
| 104 | printf("malloc(0) returns: 0x%08lx\n", this.malloc_zero); | ||
| 105 | printf("malloc(-4) returns: 0x%08lx\n", this.malloc_neg); | ||
| 106 | printf("Big heap: 0x%08lx\n", this.malloc_big); | ||
| 107 | #endif | ||
| 108 | |||
| 109 | /* There might be a differece, depending on malloc implementation. */ | ||
| 110 | this.malloc_small = (unsigned long int) malloc (100); | ||
| 111 | this.malloc_tiny = (unsigned long int) malloc (5); | ||
| 112 | |||
| 113 | #ifdef VERBOSE | ||
| 114 | printf("Small heap: 0x%08lx\n", this.malloc_small); | ||
| 115 | printf("Tiny heap: 0x%08lx\n\n", this.malloc_tiny); | ||
| 116 | #endif | ||
| 117 | |||
| 118 | |||
| 119 | this.bss = (unsigned long int) &uninitialized_global; | ||
| 120 | this.data = (unsigned long int) &small_global; | ||
| 121 | |||
| 122 | #ifdef VERBOSE | ||
| 123 | printf("bss is at: 0x%08lx\n", this.bss); | ||
| 124 | printf("Initialized global data is at: 0x%08lx\n\n", this.data); | ||
| 125 | #endif | ||
| 126 | |||
| 127 | |||
| 128 | this.sizeof_int = sizeof (int); | ||
| 129 | this.sizeof_voidptr = sizeof (void *); | ||
| 130 | |||
| 131 | #ifdef VERBOSE | ||
| 132 | printf("sizeof(int): %d\n", this.sizeof_int); | ||
| 133 | printf("sizeof(void *): %d\n\n", this.sizeof_voidptr); | ||
| 134 | #endif | ||
| 135 | |||
| 136 | |||
| 137 | this.env_start = (unsigned long int) &env[0]; | ||
| 138 | #ifdef VERBOSE | ||
| 139 | printf("environ[0]: 0x%08lx\n\n", this.env_start); | ||
| 140 | #endif | ||
| 141 | |||
| 142 | this.frame_addr = (unsigned long int) &localstack; | ||
| 143 | #ifdef VERBOSE | ||
| 144 | printf("Local stack variable is at 0x%08lx\n", this.frame_addr); | ||
| 145 | #endif | ||
| 146 | |||
| 147 | this.stack_down = stack_growsdown (&x) ? 1 : 0; | ||
| 148 | #ifdef VERBOSE | ||
| 149 | printf("Stack growth direction: %s\n", this.stack_down ? "down" : "up"); | ||
| 150 | #endif | ||
| 151 | |||
| 152 | this.endian_big = endianess () ? 1 : 0; | ||
| 153 | #ifdef VERBOSE | ||
| 154 | printf("Endianess: %s\n\n", this.endian_big ? "big" : "little"); | ||
| 155 | #endif | ||
| 156 | |||
| 157 | |||
| 158 | { | ||
| 159 | char sys[30]; | ||
| 160 | |||
| 161 | snprintf (sys, sizeof (sys), "%s-%s-%s", this.sys_name, | ||
| 162 | this.sys_release, this.sys_machine); | ||
| 163 | fprintf (stderr, "%-32s ", sys); | ||
| 164 | } | ||
| 165 | fprintf (stderr, "%s %-10s ", this.endian_big ? "be" : "le", | ||
| 166 | this.stack_down ? "stackdown" : "stackup"); | ||
| 167 | fprintf (stderr, "%3d %3d\n", | ||
| 168 | this.sizeof_int, this.sizeof_voidptr); | ||
| 169 | |||
| 170 | fprintf (stderr, "%-33s%08lx %08lx %08lx %08lx", | ||
| 171 | " data bss stack env", | ||
| 172 | this.data, this.bss, | ||
| 173 | this.frame_addr, this.env_start); | ||
| 174 | fprintf (stderr, "\n"); | ||
| 175 | |||
| 176 | fprintf (stderr, "%-33s%08lx %08lx %08lx %08lx %08lx ", | ||
| 177 | " M: zero neg big small tiny", | ||
| 178 | this.malloc_zero, this.malloc_neg, this.malloc_big, | ||
| 179 | this.malloc_small, this.malloc_tiny); | ||
| 180 | fprintf (stderr, "\n"); | ||
| 181 | |||
| 182 | exit (EXIT_SUCCESS); | ||
| 183 | } | ||
| 184 | |||
