summaryrefslogtreecommitdiff
path: root/other/shellkit/splocoder.c
blob: 96e36f8ef428730ea390fc136654ce64592e2c9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*

	A tool for the young exploit coder,  Copyright (c) acpizer, 2001.

*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>


char small_global[] = "acpizer";

int uninitialized_global;


int endianess() {
	union {
		long l;
		char c[sizeof (long)];
	} u;

	u.l = 1;

	return (u.c[sizeof (long) - 1] == 1);
}


static int iterate = 10;

int stack_growsdown(int *x) {
	auto int y;


	y = (x > &y);

	if (--iterate > 0)
		y = stack_growsdown(&y);

	if (y != (x > &y))
		exit(1);

	return y;
}

typedef struct {
	char *	sys_name;
	char *	sys_release;
	char *	sys_version;
	char *	sys_machine;

	unsigned long int	malloc_zero;
	unsigned long int	malloc_neg;
	unsigned long int	malloc_big;

	unsigned long int	malloc_small;
	unsigned long int	malloc_tiny;

	unsigned long int	bss;
	unsigned long int	data;

	int			sizeof_int;
	int			sizeof_voidptr;

	unsigned long int	env_start;

	unsigned long int	frame_addr;

	int			stack_down;
	int			endian_big;
} sys_def;

sys_def	this;


int
main (int argc, char *argv[], char *env[])
{
	struct utsname	uts;

	char		localstack[5];
	auto int	x;


	printf("splocoder, v1.0 by acpizer & sc -- team teso.\n\n");

	uname (&uts);

	this.sys_name = uts.sysname;
	this.sys_release = uts.release;
	this.sys_version = uts.version;
	this.sys_machine = uts.machine;

#ifdef VERBOSE
	printf("System: %s %s %s %s\n\n", uts.sysname, uts.release, uts.version,
		uts.machine);
#endif

	this.malloc_zero = (unsigned long int) malloc (0);
	this.malloc_neg = (unsigned long int) malloc (-4);
	this.malloc_big = (unsigned long int) malloc (1024 * 1024);

#ifdef VERBOSE
	printf("malloc(0) returns: 0x%08lx\n", this.malloc_zero);
	printf("malloc(-4) returns: 0x%08lx\n", this.malloc_neg);
	printf("Big heap: 0x%08lx\n", this.malloc_big);
#endif

	/* There might be a differece, depending on malloc implementation. */
	this.malloc_small = (unsigned long int) malloc (100);
	this.malloc_tiny = (unsigned long int) malloc (5);

#ifdef VERBOSE
	printf("Small heap: 0x%08lx\n", this.malloc_small);
	printf("Tiny heap: 0x%08lx\n\n", this.malloc_tiny);
#endif


	this.bss = (unsigned long int) &uninitialized_global;
	this.data = (unsigned long int) &small_global;

#ifdef VERBOSE
	printf("bss is at: 0x%08lx\n", this.bss);
	printf("Initialized global data is at: 0x%08lx\n\n", this.data);
#endif


	this.sizeof_int = sizeof (int);
	this.sizeof_voidptr = sizeof (void *);

#ifdef VERBOSE
	printf("sizeof(int): %d\n", this.sizeof_int);
	printf("sizeof(void *): %d\n\n", this.sizeof_voidptr);
#endif


	this.env_start = (unsigned long int) &env[0];
#ifdef VERBOSE
	printf("environ[0]: 0x%08lx\n\n", this.env_start);
#endif

	this.frame_addr = (unsigned long int) &localstack;
#ifdef VERBOSE
	printf("Local stack variable is at 0x%08lx\n", this.frame_addr);
#endif

	this.stack_down = stack_growsdown (&x) ? 1 : 0;
#ifdef VERBOSE
	printf("Stack growth direction: %s\n", this.stack_down ? "down" : "up");
#endif

	this.endian_big = endianess () ? 1 : 0;
#ifdef VERBOSE
	printf("Endianess: %s\n\n", this.endian_big ? "big" : "little");
#endif


	{
		char	sys[30];

		snprintf (sys, sizeof (sys), "%s-%s-%s", this.sys_name,
			this.sys_release, this.sys_machine);
		fprintf (stderr, "%-32s ", sys);
	}
	fprintf (stderr, "%s %-10s ", this.endian_big ? "be" : "le",
		this.stack_down ? "stackdown" : "stackup");
	fprintf (stderr, "%3d %3d\n",
		this.sizeof_int, this.sizeof_voidptr);

	fprintf (stderr, "%-33s%08lx %08lx %08lx %08lx",
		"      data bss stack env",
		this.data, this.bss,
		this.frame_addr, this.env_start);
	fprintf (stderr, "\n");

	fprintf (stderr, "%-33s%08lx %08lx %08lx %08lx %08lx ",
		"   M: zero neg big small tiny",
		this.malloc_zero, this.malloc_neg, this.malloc_big,
		this.malloc_small, this.malloc_tiny);
	fprintf (stderr, "\n");

	exit (EXIT_SUCCESS);
}