forked from iDroid-Project/openiBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
302 lines (266 loc) · 6.62 KB
/
util.h
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* util.h
*
* Copyright 2011 iDroid Project
*
* This file is part of iDroid. An android distribution for Apple products.
* For more information, please visit http://www.idroidproject.org/.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef UTIL_H
#define UTIL_H
#include "openiboot.h"
#include <stdarg.h>
#ifdef DEBUG
#define DebugPrintf bufferPrintf
#else
#define DebugPrintf(...)
#endif
typedef void (*printf_handler_t)(const char *_str);
/**
* panic
*
* OpeniBoot has just shit a brick, and now you are fucked - time for a reboot
*
*/
void panic();
/**
* system_panic
*
* The bottom wiping performed prior to a total and sudden panic
*
* @param format Format of what is being printed to the buffer
*
*/
void system_panic(const char* format, ...);
/**
* __assert
*
* Sucks to be you right now...
*
* @param file Need help with this? if you do, stop looking at this code right now
* @param line I'll give you a clue, this will be a number
* @param m Whatever it is you wish to shout about
*
*/
void __assert(const char* file, int line, const char* m);
/**
* memset
*
* Fills a block of memory
*
* @param x The bread
* @param fill The filling
* @param size The amount of filling required
*/
void* memset(void* x, int fill, uint32_t size);
/**
* memcpy
*
* Copies a block of memory
*
* @param dest Pointer to the destination
* @param src Pointer to the source
* @param size Well how many 'kin bytes do you need?
*/
void* memcpy(void* dest, const void* src, uint32_t size);
/**
* strcmp
*
* Compares strings an' shit yo'
*
* @param s1 First string
* @param s2 String to compare against s1
*/
int strcmp(const char* s1, const char* s2);
/**
* strncmp
*
* Compare characters of two strings
*
* @param s1 First string
* @param s2 String to compare against s1
* @param n Maximum number of characters to compare
*/
int strncmp(const char* s1, const char* s2, size_t n);
/**
* strchr
*
* Locate first occurrence of character in string
*
* @param s1 First string
* @param s2 String to compare against s1
*/
char* strchr(const char* s1, int s2);
/**
* strstr
* Find sharp shiny things in a heap of dead grass
*
* @param s1 Needle
* @param s2 Haystack
*/
char* strstr(const char* s1, const char* s2);
/**
* strdup
* Just like cloning, only different
*
* @param str String to duplicate
*/
char* strdup(const char* str);
/**
* strcpy
* I couldn't think of anything witty for this one, and tbh you should know what it does
*
* @param dst Destination
* @param src Source
*/
char* strcpy(char* dst, const char* src);
/**
* memcmp
* compare bytes in memory
*
* @param s1 What you want to compare
* @param s2 What you want to compare it against
* @param size mmmm, tasty bytes
*/
int memcmp(const void* s1, const void* s2, uint32_t size);
/**
* memmove
* Adapted from public domain memmove function from David MacKenzie <djm@gnu.ai.mit.edu>.
*
* @param dest Destination
* @param src Source
* @param length mmmm, tasty bytes
*/
void* memmove(void *dest, const void* src, size_t length);
/**
* strlen
* How long is my di.. I mean string
*
* @param str The string
*/
size_t strlen(const char* str);
/**
* tolower
* Makes it all proper little an' that
*
* @param c letter
*/
int tolower(int c);
/**
* putchar
* Prints a letter to the buffer
*
* @param c letter
*/
int putchar(int c);
/**
* puts
* Prints a string to the buffer
*
* @param str something stringy
*/
int puts(const char *str);
/**
* parseNumber
* Automagically makes numerical things from stringy things
*
* @param str something stringy
*/
unsigned long int parseNumber(const char* str);
/**
* strtoul
* Convert a string to an unsigned long
*
* @param str something stringy
* @param endptr the next char in str after the numerical value
* @param base The data encoding (int)
*/
unsigned long int strtoul(const char* str, char** endptr, int base);
/**
* tokenize
* ooh tokens
*
* @param commandline Teh commands
* @param argc Arguments, women love them
*/
char** tokenize(char* commandline, int* argc);
/**
* dump_memory
* Quick - get a bucket!
*
* @param start Where do we start?
* @param length Well, how much do you want exactly?
*/
void dump_memory(uint32_t start, int length);
/**
* buffer_dump_memory
* Cause OpeniBoot to have diahorea
*
* @param start Where do we start?
* @param length Well, how much do you want exactly?
*/
void buffer_dump_memory(uint32_t start, int length);
/**
* hexdump
* Cause OpeniBoot to have hexidecimal-diahorea
*
* @param start Where do we start?
* @param length Well, how much do you want exactly?
*/
void hexdump(void *start, int length);
/**
* buffer_dump_memory2
* Cause OpeniBoot to have diahorea2.0
*
* @param start Where do we start?
* @param length Well, how much do you want exactly?
*/
void buffer_dump_memory2(uint32_t start, int length, int width);
int addToBuffer(const char* toBuffer, int len);
printf_handler_t addPrintfHandler(printf_handler_t);
void bufferPrint(const char* toBuffer);
void bufferPrintf(const char* format, ...);
void uartPrint(const char* toBuffer);
void uartPrintf(const char* format, ...);
void bufferFlush(char* destination, size_t length);
char* getScrollback();
size_t getScrollbackLen();
/**
* hexToBytes
* This should need no explanation
*
* @param hex hexskidecskimal
* @param buffer no, not those things trains bump in to
* @param bytes well, how many?
*/
void hexToBytes(const char* hex, uint8_t** buffer, int* bytes);
/**
* bytesToHex
* The reverse of the above - This should also need no explanation
*
* @param buffer no, not those things trains bump in to
* @param bytes well, how many?
*/
void bytesToHex(const uint8_t* buffer, int bytes);
uint32_t crc32(uint32_t* ckSum, const void *buffer, size_t len);
uint32_t adler32(uint8_t *buf, int32_t len);
const char *strerr(error_t _e);
uint32_t next_power_of_two(uint32_t n);
inline void auto_store(void *_ptr, size_t _sz, uint32_t _val);
#include "printf.h"
#include "malloc-2.8.3.h"
#endif