c_cpp dr4基本测试用于新的二进制行格​​式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp dr4基本测试用于新的二进制行格​​式相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

/**
 * @file Prototype for the dr4 file format
 * stands for Data Row format (4 == f)
 */

#define DR4_MAGIC_SIZE 3

/* Magic sequence of bytes at the beginning of
 * every *.dr4 file.
 */
static unsigned char DR4_MAGIC_SIG[3] = {83, 94, 121};

#define DR4_MAGIC_WRITE(ptr) \
                  ptr[0] = DR4_MAGIC_SIG[0]; \
                  ptr[1] = DR4_MAGIC_SIG[1]; \
                  ptr[2] = DR4_MAGIC_SIG[2]


enum dr4_type_t {
	dr4_stop_t,
	dr4_none_t
};

struct dr4_doc_t 
{
	unsigned char* data;
	void* begin;
};

struct dr4_row_t
{
	unsigned char* data;
	uint32_t* size;
	uint32_t* length;
	uint32_t* indexes;
};

#define DR4_TEST_SIZE 100

static unsigned char TEST_DATA[DR4_TEST_SIZE];

void setup_test(void)
{
	uint32_t test_len = 2;
	DR4_MAGIC_WRITE(TEST_DATA);
	unsigned char* access = TEST_DATA;
	uint32_t* writer = (uint32_t*)(access + 3);
	// set a size
	*writer++ = (sizeof(uint32_t) * 4) + 2 + 1 /*last is stop t*/ ;
	*writer++ = test_len;
	*writer++ = 0;
	*writer++ = 1;
	access = (unsigned char*)writer;
	*access++ = dr4_none_t;
	*access++ = dr4_none_t;
	*access++ = dr4_stop_t;



}

// prints binary rep
void print_test(void) {
	unsigned char* reader = TEST_DATA;
	for(;reader != TEST_DATA + DR4_TEST_SIZE;reader++) {
		printf("(%p)-> %u\n", reader, *reader);
	}
}

void print_csv(void) {
	struct dr4_row_t samp;
	samp.data = TEST_DATA + DR4_MAGIC_SIZE;
	samp.size = (uint32_t*)(samp.data);
	samp.length = (uint32_t*)(samp.data + sizeof(uint32_t));
	samp.indexes = samp.length + sizeof(uint32_t);
	samp.data += sizeof(uint32_t) * 4;
	unsigned char chosen;
	for(uint32_t i = 0; i < *(samp.length); i++) {
		chosen = *(samp.data + samp.indexes[i]);
		switch(chosen) {
			case dr4_none_t:
			      printf("None");
			      break;
			case dr4_stop_t:
			      putc('\n', stdout);
			      break;
		}
		if(i % 2 == 0) putc(',', stdout);
	}
	putc('\n', stdout);
}

int main(int argc, char const *argv[])
{
	setup_test();
	struct dr4_row_t samp;
	samp.data = TEST_DATA + DR4_MAGIC_SIZE;
	samp.size = (uint32_t*)(samp.data);
	samp.length = (uint32_t*)(samp.data + sizeof(uint32_t));
	samp.indexes = samp.length + sizeof(uint32_t);
	samp.data += sizeof(uint32_t) * 4;
	print_test();
	print_csv();
	return 0;
}

以上是关于c_cpp dr4基本测试用于新的二进制行格​​式的主要内容,如果未能解决你的问题,请参考以下文章

Vulnhub渗透测试 DR4G0N B4LL: 1

响应式应用新协议RSocket

c_cpp 用于生成十六进制字符串表示的NSData类别

八个提高效率的VSCode必备扩展插件

八个提高效率的VSCode必备扩展插件

c_cpp 伪随机生成的假数据用于测试内部工具