Example #1
0
File: v7.c Project: di3online/v7
// variable = identifier { '.' identifier | '[' expression ']' }
static enum v7_err parse_variable(struct v7 *v7) {
  struct v7_val **v = NULL, key = str_to_val(v7->tok, v7->tok_len);
  struct v7_val *ns = find(v7, &key), ro_prop;

  if (!v7->no_exec) {
    TRY(v7_make_and_push(v7, V7_UNDEF));
    v = v7_top(v7);
  }

  while (*v7->cursor == '.' || *v7->cursor == '[') {
    int ch = *v7->cursor;

    TRY(match(v7, ch));
    CHECK(v7->no_exec || ns != NULL, V7_SYNTAX_ERROR);
    v7->cur_obj = ns;

    if (ch == '.') {
      TRY(parse_identifier(v7));
      if (!v7->no_exec) {
        key = str_to_val(v7->tok, v7->tok_len);
        ns = get2(ns, &key);
        if (ns != NULL && ns->type == V7_RO_PROP) {
          ns->v.prop_func(v7->cur_obj, &ro_prop);
          ns = &ro_prop;
        }
      }
    } else {
      TRY(parse_expression(v7));
      TRY(match(v7, ']'));
      if (!v7->no_exec) {
        ns = get2(ns, v7_top(v7)[-1]);
        if (ns != NULL && ns->type == V7_RO_PROP) {
          ns->v.prop_func(v7->cur_obj, &ro_prop);
          ns = &ro_prop;
        }
        TRY(inc_stack(v7, -1));
      }
    }
  }

  if (v != NULL && ns != NULL) {
    free_val(v7, v[-1]);
    v[-1] = ns;
    v[-1]->ref_count++;
  }

  return V7_OK;
}
Example #2
0
File: v7.c Project: di3online/v7
static enum v7_err parse_delete(struct v7 *v7) {
  struct v7_val key;
  TRY(parse_expression(v7));
  key = str_to_val(v7->tok, v7->tok_len);  // Must go after parse_expression
  TRY(del_key(v7, v7->cur_obj, &key));
  return V7_OK;
}
Example #3
0
static void
dissect_hpfeeds_publish_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                            guint offset)
{
    guint8 len = 0;
    guint8 *strptr = NULL;
    gint8 channel = CH_EINVAL;
    tvbuff_t *json_tvb = NULL;

    len = tvb_get_guint8(tvb, offset);
    proto_tree_add_item(tree, hf_hpfeeds_ident_len, tvb, offset, 1,
                        ENC_BIG_ENDIAN);
    offset += 1;
    proto_tree_add_item(tree, hf_hpfeeds_ident, tvb, offset, len,
                        ENC_BIG_ENDIAN);
    offset += len;
    len = tvb_get_guint8(tvb, offset);
    proto_tree_add_item(tree, hf_hpfeeds_chan_len, tvb, offset, 1,
                        ENC_BIG_ENDIAN);
    offset += 1;

    /* get the channel name as ephemeral string just to make an attempt
    *  in order to decode more payload if channel is "well known"
    */
    strptr = tvb_get_string(wmem_packet_scope(), tvb, offset, len);
    proto_tree_add_item(tree, hf_hpfeeds_channel, tvb, offset, len,
                        ENC_BIG_ENDIAN);
    offset += len;
    channel = str_to_val(strptr, chan_vals, CH_EINVAL);
    pinfo->private_data = strptr;
    switch (channel) {
    case CH_DIONAEA_CAPTURE:
    case CH_DIONAEA_DCE:
    case CH_DIONAEA_SHELLCODE:
    case CH_DIONAEA_UINQUE:
    case CH_DIONAEA_CONNECTIONS:
    case CH_KIPPO_SESSIONS:
    case CH_GLASTOPF_EVENTS:
    case CH_GEOLOC_EVENTS:
        json_tvb = tvb_new_subset(tvb, offset, -1, -1);
        call_dissector(json_hdl, json_tvb, pinfo, tree);
        break;
    default:
        proto_tree_add_item(tree, hf_hpfeeds_payload, tvb, offset, -1,
                            ENC_NA);
        break;
    }


}
Example #4
0
V7_PRIVATE enum v7_err v7_del2(struct v7 *v7, struct v7_val *obj,
  const char *key, unsigned long n) {
  struct v7_val k = str_to_val(key, n);
  struct v7_prop **p;
  CHECK(obj->type == V7_TYPE_OBJ, V7_TYPE_ERROR);
  for (p = &obj->props; *p != NULL; p = &p[0]->next) {
    if (cmp(&k, p[0]->key) == 0) {
      struct v7_prop *next = p[0]->next;
      free_prop(v7, p[0]);
      p[0] = next;
      break;
    }
  }
  return V7_OK;
}
Example #5
0
static int uart_test(int argc ,char *argv[])
{
	int opt;
	int het;
	int ret = 0;
	struct loader_opt ld_opt;

	memset(&ld_opt, 0x0, sizeof(ld_opt));
	while ((opt = getopt(argc, argv, "m::p:f:i:vh")) != -1) {
		switch (opt) {
		case 'm':
			if (optarg != NULL) {
				het = str_to_val(optarg, (__u32 *)&ld_opt.load_addr);
				if (het < 0) {
					printf("Input a invalied address!\n");

					return -EINVAL;
				}
			}

			break;

		case 'p':
		case 'v':
		case 'i':
		case 'f':

			// fixme

			break;

		default:
			ret = -EINVAL;

		case 'h':
			usage();
			return ret;
		}
	}

	// fixme

	return 0;
}
Example #6
0
static int flash_str_to_val(char * str, __u32 * val, char *unit)
{
	int len;
	char *p = str;

	len = strlen(str);

	if (len > 5 && 0 == strncmp(p + len - 5, "block", 5)) {
		*unit = 'b'; // block
		p[len - 5] = '\0';
	} else if (len > 4 && 0 == strncmp(p + len - 4, "page", 4)) {
		*unit = 'p'; // page
		p[len - 4] = '\0';
	} else if (len > 1 && strchr("kKmMgG", str[len - 1])) {
		return hr_str_to_val(str, (unsigned long *)val);
	}

	return str_to_val(str, (unsigned long *)val);
}
Example #7
0
static int uart_load(int argc, char *argv[])
{
	int size, ret;
	struct loader_opt ld_opt;
	struct block_device *bdev;
	char *pro = NULL;
	int opt;

	size = 0;

	memset(&ld_opt, 0x0, sizeof(ld_opt));

	bdev = get_bdev_by_volume(get_curr_volume());
	ld_opt.file = bdev->file;
	// fixme
	bdev->file->open(bdev->file, 0);

	while ((opt = getopt(argc, argv, "m::p:f:i:vh")) != -1) {
		switch (opt) {
		case 'm':
			if (optarg != NULL) {
				ret = str_to_val(optarg, (__u32 *)&ld_opt.load_addr);
				if (ret < 0) {
					printf("Input a invalied address!\n");

					return -EINVAL;
				}
			}

			ld_opt.file = NULL;

			break;

		case 'v':
		case 'i':
		case 'f':

			// fixme

			break;

		case 'h':
			usage();

			return 0;

		case 'p':
			pro = optarg;

			break;

		default:
			usage();

			return -EINVAL;
		}
	}

	if (0 == strcmp(pro, "k")) {
		printf("load kermit....:");
		size = kermit_load(&ld_opt);
	} else if (0 == strcmp(pro, "y")) {
		printf("load ymode....:");
		size = ymodem_load(&ld_opt);
	} else {
		usage();
		return -EINVAL;
	}

	if (ld_opt.file && size > 0) {
		strncpy(ld_opt.file->name, ld_opt.file_name, FILE_NAME_SIZE);
		ld_opt.file->size = size;

		set_bdev_file_attr(ld_opt.file);
	}

	return size;
}
Example #8
0
V7_PRIVATE struct v7_val v7_str_to_val(const char *buf) {
  return str_to_val((char *) buf, strlen(buf));
}
Example #9
0
int main(int argc, char *argv[])
{
	int opt, ret = 0;
	extern char *optarg;
	__u32 id;
	struct display *disp;
	const struct lcd_vmode *vm;

	if (argc == 1) {
		usage();
		return -EINVAL;
	}

	while ((opt = getopt(argc, argv, "l::s:h")) != -1) {
		switch (opt) {
		case 'l':
			disp = get_system_display();
			if (!disp) {
				printf("Fail to open display!\n");
				return -ENODEV;
			}

			if (NULL == optarg) {
				vm = disp->video_mode;
				vmode_print(vm, disp);

				break;
			}

			if (strcmp("all", optarg) != 0) {
				usage();
				return -EINVAL;
			}

			for (id = 0; (vm = lcd_get_vmode_by_id(id)); id++) {
				printf("\n[%d] ", id);
				vmode_print(vm, disp);
			}

			break;

		case 's':
			if (NULL == optarg) {
				usage();
				return -EINVAL;
			}

			if (str_to_val(optarg, &id) < 0) {
				vm = lcd_get_vmode_by_name(optarg);
			} else {
				vm = lcd_get_vmode_by_id(id);
			}
			if (vm == NULL) {
				printf("Fail to get display mode!\n");
				return -EINVAL;
			}

			disp = get_system_display();
			if (!disp) {
				printf("Fail to open display!\n");
				return -ENODEV;
			}

			ret = disp->set_vmode(disp, vm);
			if (ret < 0) {
				printf("Fail to set video mode \"%s\"!\n", vm->model);
			} else {
				printf("Success to set video mode \"%s\"!\n", vm->model);
			}
			break;

		default:
			ret = -EINVAL;
		case 'h':
			usage();
			return ret;
		}
	}

	return ret;
}
Example #10
0
static int read_write(int argc, char *argv[])
{
	int ch, ret = 0, flag = 0;
	__u32 start = 0, size = 1024;
	char start_unit = 0, size_unit = 0;
	void *buff = NULL;
	int fd;
	struct flash_info flash_val;
	char bdev_name[BLOCK_DEV_NAME_LEN];

	while ((ch = getopt(argc, argv, "a:l:m:h")) != -1) {
		switch (ch) {
		case 'a':
			if (flag || flash_str_to_val(optarg, &start, &start_unit) < 0) {
				printf("Invalid argument: \"%s\"\n", optarg);
				usage();

				return -EINVAL;
			}

			flag++;

			break;

		case 'l':
			if (flash_str_to_val(optarg, &size, &size_unit) < 0) {
				printf("Invalid argument: \"%s\"\n", optarg);
				return -EINVAL;
			}

			flag++;

			break;

		case 'm':
			if (str_to_val(optarg, (unsigned long *)&buff) < 0) {
				printf("Invalid argument: \"%s\"\n", optarg);
				usage();
				return -EINVAL;
			}

			flag++;

			break;

		default:
			ret = -EINVAL;
		case 'h':
			usage();
			return ret;
		}
	}

	// must set -a flash_addr -l size -m mem_addr
	if (flag != 3) {
		printf("Please set the option -a addr -l size -m address>\n");
		usage();
		return -EINVAL;
	}

	// fixme
	getcwd(bdev_name, sizeof(bdev_name));
	fd = open(bdev_name, O_RDWR);
	if (fd < 0) {
		goto L1;
	}

	ret = ioctl(fd, FLASH_IOCG_INFO, &flash_val);
	if (ret < 0) {
		goto L2;
	}

	// -a xxxblock or -a xxxpage
	if (start_unit == 'b') {
		start *= flash_val.block_size;
	} else if (start_unit == 'p') {
		start *= flash_val.page_size;
	}

	// -l xxxblock or -l xxxpage
	if (size_unit == 'b') {
		size *= flash_val.block_size;
	} else if (size_unit == 'p') {
		size *= flash_val.page_size;
	}

	if (start + size >= flash_val.bdev_size) {
		printf("Address 0x%08x overflow!\n", start + size);
		ret = -EINVAL;
		goto L1;
	}

	lseek(fd, start, SEEK_SET);
	if (0 == strcmp(argv[0], "read")) {
		ret = read(fd, buff, size);
		if (ret < 0) {
			printf("please check argument!\n");
			usage();

			ret = -EINVAL;
			goto L2;
		}
		printf("Read 0x%08x bytes data to mem 0x%08x from flash 0x%08x\n", size, (__u32)buff, start);
	} else {
		ret = write(fd, buff, size);
		if (ret < 0) {
			printf("please check argument!\n");
			usage();

			ret = -EINVAL;
			goto L2;
		}
		printf("write 0x%08x bytes data to flash 0x%08x from mem 0x%08x\n", size, start, (__u32)buff);
	}

L2:
	close(fd);
L1:
	return ret;
}
Example #11
0
static int dump(int argc, char *argv[])
{
	int opt;
	int flag = 0;
	__u8 buf[BLK_LEN];
	int ret = 0;
	__u32 addr = 0;
	__u32 unit_size;
	struct block_device *bdev;
	struct disk_drive *disk;
	char vol;
	int i, j;

	while ((opt = getopt(argc, argv, "a::hw:")) != -1) {
		switch (opt) {
		case 'a':
			if (optarg != NULL) {
				ret = str_to_val(optarg, &addr);
				if (ret < 0) {
					printf("Error: Address error!\n");

					return -EINVAL;
				}
			}

			printf("Dump from the address: 0x%x\n", addr);
			break;

		case 'w':
			if (optarg != NULL) {
				ret = str_to_val(optarg, &unit_size);
				if (ret < 0){
					printf("Error: Unit_size error!\n");
					return -EINVAL;
				}
			}

			if (!(unit_size == 1 || unit_size == 2 || unit_size == 4 || unit_size == 8)) {
				printf("Error: invalid unit_size!\n");
				return -EINVAL;
			}

			flag = 1;
			printf("Unit_size: 0x%x\n", unit_size);
			break;

		case 'h':
		default:
			usage();
			return 0;
		}
	}

	if (flag == 0){
		unit_size = DEFAULT_UNIT_SIZE;
	}

	vol = get_home_volume();

	bdev = get_bdev_by_volume(vol);
	if (!bdev) {
		printf("fail to change to \"%c\", no such block device!\n", vol);
		return -ENODEV;
	}

	disk = container_of(bdev, struct disk_drive, bdev);

	memset(buf, 0xbb, BLK_LEN);
	printf("get_block: %p\n", disk->get_block);

	ret = disk->get_block(disk, addr, buf);
	if (ret < 0) {
		printf("Error: Fail to Read!\n");
		return ret;
	}

	for (i = 0; i < BLK_LEN / unit_size; i++) {
		for (j = 0; j < unit_size; j++) {
			printf("%0x", ((__u8*)buf)[i * unit_size + i]);
		}

		if ((i + 1)% 8) {
			printf(" ");
		} else {
			printf("\n");
		}
	}

	return 0;
}
Example #12
0
static int read(int argc, char *argv[])
{
	int i;
	int opt;
	int ret = 0;
	char volume;
	__u8 buf[BLK_LEN];
	__u32 mem_addr = 0, disk_addr = 0;
	struct block_device *bdev;
	struct disk_drive *drive;

	while ((opt = getopt(argc, argv, "a::m:h")) != -1) {
		switch (opt) {
		case 'a':
			if (optarg != NULL) {
				ret = str_to_val(optarg, &disk_addr);
				if (ret < 0) {
					printf("Error: Start disk address error!\n");

					return -EINVAL;
				}
			}

			printf("Disk address: 0x%x\n", disk_addr);
			break;

		case 'm':
			if (optarg != NULL) {
				ret = str_to_val(optarg, &mem_addr);
				if (ret < 0) {
					printf("Error: Start memory address error!\n");

					return -EINVAL;
				}
			}

			printf("Memory address: 0x%x\n", mem_addr);
			break;

		case 'h':
		default:
			usage();

			return 0;
		}
	}

	volume = get_home_volume();

	printf("volume: %c\n", volume);

	bdev = get_bdev_by_volume(volume);
	if (!bdev) {
		printf("fail to get bdev \"%c\", no such block device!\n", volume);

		return -ENODEV;
	}

	drive = container_of(bdev, struct disk_drive, bdev);

	printf("drive->get_block address: %p\n", drive->get_block);

	ret = drive->get_block(drive, disk_addr, buf);
	if (ret < 0) {
		printf("Read failed!\n");
	}

	for (i = 0; i < BLK_LEN; i++) {
		*(unsigned char *)mem_addr = buf[i];
		mem_addr++;
	}

	printf("Read disk sucess!\n");

	return 0;
}