int main()
{
  item * head = ll_sanity_check();
  item * reversed = reverse_ll(head);

  printf("This should print from 9 to 0\n");
  print_list(reversed);
  printf("-----------------------------\n");

  return test_reversed(reversed);
}
Exemplo n.º 2
0
int main()
{
    node_t *head = NULL;
    head = insert_node(head, 10);
    head = insert_node(head, 12);
    head = insert_node(head, 15);
    head = insert_node(head, 5);
    head = insert_node(head, 7);
    print_ll(head);
    head = reverse_ll(head);
    print_ll(head);
    return 0;
}
Exemplo n.º 3
0
Arquivo: proc.c Projeto: 0x36/BinTrace
int read_procfs_maps(struct procinfo *pi)
{
	char procfs_path[20];
	FILE *fp;
	char buf[512];
	char unwanted[256];
	char file_path[256];
	struct map_addr *ma_ptr, *head;
	u_long start, end;

	memset(procfs_path, 0, 20);
	memset(buf, 0, 512);
	memset(file_path, 512, 0);
	memset(unwanted, 0, 256);

	ma_ptr = NULL;
	head = NULL;
	sprintf(procfs_path, "/proc/%d/maps", (int)pi->pi_pid);

	fp = fopen(procfs_path, "r");
	if (!fp)
		return -1;
	printfd(2, DO "Fetch /procfs" NORM "\n");

	while (fgets(buf, 512, fp)) {
		//00400000-0040b000 r-xp 00000000 08:03 1572888                            /bin/cat
		
		sscanf(buf, "%lx-%lx %s %s %s %s %255s\n",
		       &start, &end, unwanted, unwanted, unwanted, unwanted,
		       file_path);

		if (!memcmp
		    (pi->pi_perm->p_full_path, file_path,
		     strlen((const char *)pi->pi_perm->p_full_path))) {
			ma_ptr =
			    (struct map_addr *)xmalloc(sizeof(struct map_addr));

			ma_ptr->ma_map[0] = start;
			ma_ptr->ma_map[1] = end;
			ma_ptr->ma_next = head;
			head = ma_ptr;

#if 0
			printfd(2, GREEN "%s " NORM "\n",
				pi->pi_perm->p_full_path);
			printfd(2, GREEN "line : %s" NORM "\n", buf);
			printfd(2, DEBUG " start : %lx\n", ma_ptr->ma_map[0]);
			printfd(2, DEBUG " end : %lx\n", ma_ptr->ma_map[1]);
			printfd(2, DEBUG " path : %s\n", file_path);
#endif

		}
		else if (!memcmp("[stack]", file_path,7)) {
			pi->pi_stack =
				(struct map_addr *)xmalloc(sizeof(struct map_addr));
			pi->pi_stack->ma_map[0] = start;
			pi->pi_stack->ma_map[1] = end;
			pi->pi_stack->ma_next = NULL;
		}
		/* It doesn't reach here  */
		else if (!memcmp("[heap]", file_path,6)) {
			//printfd(2,"FIXME\n");
		}
	}
#if 0
	for (ma_ptr = pi->pi_addr; ma_ptr; ma_ptr = ma_ptr->ma_next) {
		printf(BLUE "ADDR : 0x%lx" NORM "\n", ma_ptr->ma_map[0]);
	}
#endif

	pi->pi_addr = head;
	reverse_ll(&pi->pi_addr);

#if 0
	for (ma_ptr = pi->pi_addr; ma_ptr; ma_ptr = ma_ptr->ma_next) {
		printf(BLUE "ADDR : 0x%lx" NORM "\n", ma_ptr->ma_map[0]);
	}
#endif

#if 0
	addr2 = strtok(addr1, "-");
	addr2 = strtok(NULL, "-");
	pi->pi_address = pi->pi_map[0] = strtoul(addr1, NULL, 16);
	pi->pi_map[1] = strtoul(addr2, NULL, 16);

	pi->pi_offset = pi->pi_map[1] - pi->pi_map[0];

	printfd(2, DEBUG "%s", buf);
	printfd(2, DEBUG " Base address : 0x%08x\n", pi->pi_map[0]);
	printfd(2, DEBUG " End address :  0x%08x\n", pi->pi_map[1]);
	printfd(2, DEBUG " Offset :  0x%08x\n", pi->pi_offset);
#endif
	return 0;
}