当前位置: 首页>>代码示例>>C++>>正文


C++ r_cons_singleton函数代码示例

本文整理汇总了C++中r_cons_singleton函数的典型用法代码示例。如果您正苦于以下问题:C++ r_cons_singleton函数的具体用法?C++ r_cons_singleton怎么用?C++ r_cons_singleton使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了r_cons_singleton函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: r_core_project_save

R_API int r_core_project_save(RCore *core, const char *file) {
	int fd, tmp, ret = R_TRUE;
	char *prj;

	if (file == NULL || *file == '\0')
		return R_FALSE;

	prj = r_core_project_file (file);
	r_core_project_init ();
	fd = r_sandbox_open (prj, O_BINARY|O_RDWR|O_CREAT, 0644);
	if (fd != -1) {
		int fdold = r_cons_singleton ()->fdout;
		r_cons_singleton ()->fdout = fd;
		r_cons_singleton ()->is_interactive = R_FALSE;
		r_str_write (fd, "# r2 rdb project file\n");
		//--
		r_str_write (fd, "# flags\n");
		tmp = core->flags->space_idx;
		core->flags->space_idx = -1;
		r_flag_list (core->flags, R_TRUE);
		core->flags->space_idx = tmp;
		r_cons_flush ();
		//--
		r_str_write (fd, "# eval\n");
		// TODO: r_str_writef (fd, "e asm.arch=%s", r_config_get ("asm.arch"));
		r_config_list (core->config, NULL, R_TRUE);
		r_cons_flush ();
		r_str_write (fd, "# sections\n");
		r_io_section_list (core->io, core->offset, 1);
		r_cons_flush ();
		r_str_write (fd, "# meta\n");
		r_meta_list (core->anal->meta, R_META_TYPE_ANY, 1);
		r_cons_flush ();
		r_core_cmd (core, "ar*", 0);
		r_cons_flush ();
		r_core_cmd (core, "af*", 0);
		r_cons_flush ();
		r_core_cmd (core, "ah*", 0);
		r_cons_flush ();
		r_str_write (fd, "# seek\n");
		r_str_writef (fd, "s 0x%08"PFMT64x, core->offset);
		r_cons_flush ();
		close (fd);
		r_cons_singleton ()->fdout = fdold;
		r_cons_singleton ()->is_interactive = R_TRUE;
	} else {
		eprintf ("Cannot open '%s' for writing\n", prj);
		ret = R_FALSE;
	}
	free (prj);
	return ret;
}
开发者ID:0xroot,项目名称:radare2,代码行数:52,代码来源:project.c

示例2: gs

R_API char *r_cons_rgb_str (char *outstr, ut8 r, ut8 g, ut8 b, int is_bg) {
	int k, fgbg = is_bg? 48: 38;
	k = (r == g && g == b)?  gs (r): rgb (r, g, b);
	//k = rgb (r, g, b);
	if (!outstr) outstr = malloc (32);

	switch (r_cons_singleton()->truecolor) {
	case 1: // 256 color palette
		sprintf (outstr, "\x1b[%d;5;%dm", fgbg, k);
		break;
	case 2: // 16M - xterm only
		sprintf (outstr, "\x1b[%d;2;%d;%d;%dm", fgbg, 
			r&0xff, g&0xff, b&0xff);
		break;
	case 0: // ansi 16 colors
	default:
		{
		int k = (r+g+b)/3;
		r = (r>k)?1:0;
		g = (g>k)?1:0;
		b = (b>k)?1:0;
		k = (r?1:0) + (g? (b?6:2): (b?4:0));
		sprintf (outstr, "\x1b[%dm", 30+k);
		}
		break;
	}
	return outstr;
}
开发者ID:DePierre,项目名称:radare2,代码行数:28,代码来源:rgb.c

示例3: r_cons_pal_init

R_API void r_cons_pal_init(const char *foo) {
	RCons *cons = r_cons_singleton ();
	memset (&cons->pal, 0, sizeof (cons->pal));
	cons->pal.prompt = Color_YELLOW;
	cons->pal.offset = Color_GREEN;
	cons->pal.input = Color_WHITE;
	cons->pal.comment = Color_CYAN;
	cons->pal.fname = Color_CYAN;
	cons->pal.fline = Color_CYAN;
	cons->pal.flag = Color_CYAN;
	cons->pal.label = Color_CYAN;
	cons->pal.flow = Color_CYAN;
	cons->pal.b0x00 = Color_GREEN;
	cons->pal.b0x7f = Color_CYAN;
	cons->pal.b0xff = Color_RED;
	cons->pal.other = Color_YELLOW;
	cons->pal.btext = Color_YELLOW;
	cons->pal.push = Color_MAGENTA;
	cons->pal.pop = Color_BMAGENTA;
	cons->pal.nop = Color_BLUE;
	cons->pal.jmp = Color_GREEN;
	cons->pal.cjmp = Color_GREEN;
	cons->pal.call = Color_BGREEN;
	cons->pal.cmp = Color_CYAN;
	cons->pal.swi = Color_MAGENTA;
	cons->pal.trap = Color_BRED;
	cons->pal.ret = Color_RED;
	cons->pal.num = Color_YELLOW;
	cons->pal.reg = Color_CYAN;
	cons->pal.reset = "\x1b[0m";
}
开发者ID:eddyb,项目名称:radare2,代码行数:31,代码来源:pal.c

示例4: r_cons_pal_random

R_API void r_cons_pal_random () {
	RCons *cons = r_cons_singleton ();
	ut8 r, g, b;
	char val[32];
	const char *k;
	int i;
	for (i = 0; ; i++) {
		k = r_cons_pal_get_i (i);
		if (!k) break;
		if (cons->truecolor > 0) {
			r = r_num_rand (0xff);
			g = r_num_rand (0xff);
			b = r_num_rand (0xff);
			sprintf (val, "rgb:%02x%02x%02x", r, g, b);
			r_cons_pal_set (k, val);
		} else {
			char *s = r_cons_color_random_string (0);
			if (s) {
				r_cons_pal_set (k, s);
				free (s);
			} else {
				r_cons_pal_set (k, "red");
			}
		}
	}
	for (i = 0; i < R_CONS_PALETTE_LIST_SIZE; i++) {
		if (cons->pal.list[i]) R_FREE (cons->pal.list[i]);
		cons->pal.list[i] = r_cons_color_random (0);
	}
}
开发者ID:AmesianX,项目名称:radare2,代码行数:30,代码来源:pal.c

示例5: r_core_dump

R_API int r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size) {
	ut64 i;
	ut8 *buf;
	int bs = core->blocksize;
	FILE *fd;
	r_sys_truncate (file, 0);
	fd = r_sandbox_fopen (file, "wb");
	if (!fd) {
		eprintf ("Cannot open '%s' for writing\n", file);
		return R_FALSE;
	}
	buf = malloc (bs);
	r_cons_break (NULL, NULL);
	for (i=0; i<size; i+=bs) {
		if (r_cons_singleton ()->breaked)
			break;
		if ((i+bs)>size)
			bs = size-i;
		r_io_read_at (core->io, addr+i, buf, bs);
		if (fwrite (buf, bs, 1, fd) <1) {
			eprintf ("write error\n");
			break;
		}
	}
	eprintf ("dumped 0x%"PFMT64x" bytes\n", i);
	r_cons_break_end ();
	fclose (fd);
	free (buf);
	return R_TRUE;
}
开发者ID:adamharder,项目名称:radare2,代码行数:30,代码来源:io.c

示例6: r_cons_pal_free

R_API void r_cons_pal_free () {
	int i;
	RCons *cons = r_cons_singleton ();
	for (i = 0; i < R_CONS_PALETTE_LIST_SIZE; i++) {
		if (cons->pal.list[i]) R_FREE (cons->pal.list[i]);
	}
}
开发者ID:AmesianX,项目名称:radare2,代码行数:7,代码来源:pal.c

示例7: apply_line_style

static void apply_line_style(RConsCanvas *c, int x, int y, int x2, int y2, int style){
	RCons *cons = r_cons_singleton ();
	switch (style) {
	case 0: // Unconditional jump
		//c->attr=Color_BLUE;
		c->attr = cons->pal.graph_trufae; //Color_GREEN;
		if (G (x, y))
			W ("v");
		if (G (x2, y2))
			W ("V");
		break;
	case 1: // Conditional jump, True branch
		c->attr = cons->pal.graph_true; //Color_GREEN;
		if (G (x, y))
			W ("t"); //\\");
		if (G (x2, y2))
			W ("\\");
		break;
	case 2: // Conditional jump, False branch
		c->attr = cons->pal.graph_false; //Color_RED;
		if (G (x, y))
			W ("f");
		if (G (x2, y2))
			W ("/");
		break;
	default:
		c->attr = cons->pal.graph_trufae; //Color_BLUE;
		break;
	}
}
开发者ID:four0four,项目名称:radare2,代码行数:30,代码来源:canvas_line.c

示例8: r_cons_pal_init

R_API void r_cons_pal_init(const char *foo) {
	RCons *cons = r_cons_singleton ();
	memset (&cons->pal, 0, sizeof (cons->pal));
	cons->pal.b0x00 = Color_GREEN;
	cons->pal.b0x7f = Color_CYAN;
	cons->pal.b0xff = Color_RED;
	cons->pal.args = Color_YELLOW;
	cons->pal.bin = Color_YELLOW;
	cons->pal.btext = Color_WHITE;
	cons->pal.call = Color_BGREEN;
	cons->pal.cjmp = Color_GREEN;
	cons->pal.cmp = Color_CYAN;
	cons->pal.comment = Color_CYAN; // blue
	cons->pal.creg = Color_CYAN;
	cons->pal.flag = Color_CYAN;
	cons->pal.fline = Color_CYAN;
	cons->pal.floc = Color_CYAN;
	cons->pal.flow = Color_CYAN;
	cons->pal.fname = Color_RED;
	cons->pal.help = Color_GREEN;
	cons->pal.input = Color_WHITE;
	cons->pal.invalid = Color_BRED;
	cons->pal.jmp = Color_GREEN;
	cons->pal.label = Color_CYAN;
	cons->pal.math = Color_YELLOW;
	cons->pal.mov = Color_WHITE;
	cons->pal.nop = Color_BLUE;
	cons->pal.num = Color_YELLOW;
	cons->pal.offset = Color_GREEN;
	cons->pal.other = Color_WHITE;
	cons->pal.pop = Color_BMAGENTA;
	cons->pal.prompt = Color_YELLOW;
	cons->pal.push = Color_MAGENTA;
	cons->pal.reg = Color_CYAN;
	cons->pal.reset = Color_RESET;
	cons->pal.ret = Color_RED;
	cons->pal.swi = Color_MAGENTA;
	cons->pal.trap = Color_BRED;

	cons->pal.ai_read = Color_GREEN;
	cons->pal.ai_write = Color_BLUE;
	cons->pal.ai_exec = Color_RED;
	cons->pal.ai_seq = Color_MAGENTA;
	cons->pal.ai_ascii = Color_YELLOW;

	cons->pal.gui_cflow = Color_YELLOW;
	cons->pal.gui_dataoffset = Color_YELLOW;
	cons->pal.gui_background = Color_BLACK;
	cons->pal.gui_alt_background = Color_GRAY;
	cons->pal.gui_border = Color_BGGRAY;

	cons->pal.list[0] = strdup (Color_RED);
	cons->pal.list[1] = strdup (Color_YELLOW);
	cons->pal.list[2] = strdup (Color_BGREEN);
	cons->pal.list[3] = strdup (Color_CYAN);
	cons->pal.list[4] = strdup (Color_MAGENTA);
	cons->pal.list[5] = strdup (Color_GRAY);
	cons->pal.list[6] = strdup (Color_BLUE);
	cons->pal.list[7] = strdup (Color_GREEN);
}
开发者ID:commiebstrd,项目名称:radare2,代码行数:60,代码来源:pal.c

示例9: r_cons_pal_null

static void r_cons_pal_null (){
	int i;
	RCons *cons = r_cons_singleton ();
	for (i = 0; i< R_CONS_PALETTE_LIST_SIZE; i++){
		cons->pal.list[i] = NULL;	
	}
}
开发者ID:NightOfTwelve,项目名称:radare2,代码行数:7,代码来源:cons.c

示例10: r_core_asm_hit_list_new

R_API RList *r_core_asm_bwdisassemble (RCore *core, ut64 addr, int n, int len) {
	RList *hits = r_core_asm_hit_list_new();
	RAsmOp op;
	// len = n * 32;
	// if (n > core->blocksize) n = core->blocksize;
	ut8 *buf;
	ut64 instrlen = 0, at = 0;
	ut32 idx = 0, hit_count = 0;
	int numinstr, asmlen, ii;
	RAsmCode *c;

	if (len<1) return NULL;
	buf = (ut8 *)malloc (len);
	if (hits == NULL || buf == NULL ){
		if (hits) {
			r_list_free (hits);
		}
		free (buf);
		return NULL;
	}

	if (r_io_read_at (core->io, addr-len, buf, len) != len) {
		if (hits) {
			r_list_free (hits);
		}
		free (buf);
		return NULL;
	}

	for (idx = 1; idx < len; ++idx) {
		if (r_cons_singleton ()->breaked) break;
		at = addr - idx; hit_count = 0;
		c = r_asm_mdisassemble (core->assembler, buf+(len-idx), idx);
		if (strstr(c->buf_asm, "invalid") || strstr(c->buf_asm, ".byte")) {
			r_asm_code_free(c);
			continue;
		}
		numinstr = 0;
		asmlen = strlen(c->buf_asm);
		for(ii = 0; ii < asmlen; ++ii) {
			if (c->buf_asm[ii] == '\n') ++numinstr;
		}
		r_asm_code_free(c);
		if (numinstr >= n || idx > 32 * n) {
			break;
		}
	}
	at = addr - idx;
	hit_count = 0;
	r_asm_set_pc (core->assembler, at);
	at = addr-idx;
	for ( hit_count = 0; hit_count < n; hit_count++) {
		instrlen = r_asm_disassemble (core->assembler, &op, buf+(len-(addr-at)), addr-at);
		add_hit_to_hits(hits, at, instrlen, true);
		at += instrlen;
	}
	free (buf);
	return hits;
}
开发者ID:AitorATuin,项目名称:radare2,代码行数:59,代码来源:asm.c

示例11: r_core_asm_hit_list_new

R_API RList *r_core_asm_bwdisassemble (RCore *core, ut64 addr, int n, int len) {
	RList *hits = r_core_asm_hit_list_new();
	RCoreAsmHit dummy_value;
	RAsmOp op;
	ut8 *buf = (ut8 *)malloc (len);
	ut64 instrlen = 0, 
		 at = 0;

	ut32 
	 	 idx = 0,
	 	 hit_count = 0;

	memset (&dummy_value, 0, sizeof (RCoreAsmHit));

	if (hits == NULL || buf == NULL ){
		if (hits) r_list_destroy (hits);
		if (buf) free (buf); 
		return NULL;
	}

	if (r_io_read_at (core->io, addr-len, buf, len) != len) {
		if (hits) r_list_destroy (hits);
		if (buf) free (buf); 
		return NULL;
	}

	for (idx = 1; idx < len; idx++) {
		ut32 current_buf_pos;
		if (r_cons_singleton ()->breaked) break;
		at = addr - idx; hit_count = 0;
		// XXX - buf here. at may be greater than addr if near boundary.

		for (current_buf_pos = len - idx, hit_count = 0; 
			current_buf_pos < len && hit_count <= n; 
			current_buf_pos += instrlen, at += instrlen, hit_count++) {
			r_asm_set_pc (core->assembler, at);
			//XXX HACK We need another way to detect invalid disasm!!
			if (!(instrlen = r_asm_disassemble (core->assembler, &op, buf+(len-(addr-at)), addr-at)) || strstr (op.buf_asm, "invalid")) {
				break;
			} 
		}
		if (hit_count >= n) break;
	}

	if (hit_count == n) {
		at = addr - idx;
		hit_count = 0;
		r_asm_set_pc (core->assembler, at);
		for ( hit_count = 0; hit_count < n; hit_count++) {
			instrlen = r_asm_disassemble (core->assembler, &op, buf+(len-(addr-at)), addr-at);
			add_hit_to_hits(hits, at, instrlen, R_TRUE);
			at += instrlen;
		}
	}

	r_asm_set_pc (core->assembler, addr);
	free (buf);
	return hits;
}
开发者ID:17twenty,项目名称:radare2,代码行数:59,代码来源:asm.c

示例12: ThreadFunction

DWORD WINAPI ThreadFunction(LPVOID lpParam) {
	RLang * lang = lpParam;
	CHAR buf[PIPE_BUF_SIZE];
	BOOL bSuccess = FALSE;
	int i, res = 0;
	DWORD dwRead, dwWritten;
	r_cons_break (NULL, NULL);
	res = ConnectNamedPipe (hPipeInOut, NULL);
	if (!res) {
		eprintf ("ConnectNamedPipe failed\n");
		return FALSE;
	}
	do {
		if (r_cons_singleton ()->breaked) {
			TerminateProcess(hproc,0);
			break;
		}
		memset (buf, 0, PIPE_BUF_SIZE);
		bSuccess = ReadFile (hPipeInOut, buf, PIPE_BUF_SIZE, &dwRead, NULL);
                if (bStopThread)
			break;
		if (bSuccess && dwRead>0) {
			buf[sizeof (buf)-1] = 0;
			char *res = lang->cmd_str ((RCore*)lang->user, buf);
			if (res) {
				int res_len = strlen (res) + 1;
				for (i = 0; i < res_len; i++) {
					memset (buf, 0, PIPE_BUF_SIZE);
					dwWritten = 0;
					int writelen=res_len - i;
					int rc = WriteFile (hPipeInOut, res + i, writelen>PIPE_BUF_SIZE?PIPE_BUF_SIZE:writelen, &dwWritten, 0);
					if (bStopThread) {
						free (res);
						break;
					}
					if (!rc) {
						eprintf ("WriteFile: failed 0x%x\n", (int)GetLastError());
					}
					if (dwWritten > 0) {
						i += dwWritten - 1;
					} else {
						/* send null termination // chop */
						eprintf ("w32-lang-pipe: 0x%x\n", (ut32)GetLastError ());
						//WriteFile (hPipeInOut, "", 1, &dwWritten, NULL);
						//break;
					}
				}
				free (res);
			} else {
				WriteFile (hPipeInOut, "", 1, &dwWritten, NULL);
			}
		}
	} while(!bStopThread);
	r_cons_break_end ();
	return TRUE;
}
开发者ID:13572293130,项目名称:radare2,代码行数:56,代码来源:pipe.c

示例13: apply_line_style

static void apply_line_style(RConsCanvas *c, int x, int y, int x2, int y2,
		RCanvasLineStyle *style, int isvert) {
	RCons *cons = r_cons_singleton ();
	switch (style->color) {
	case LINE_UNCJMP:
		c->attr = cons->pal.graph_trufae;
		break;
	case LINE_TRUE:
		c->attr = cons->pal.graph_true;
		break;
	case LINE_FALSE:
		c->attr = cons->pal.graph_false;
		break;
	case LINE_NONE:
	default:
		c->attr = cons->pal.graph_trufae;
		break;
	}
	if (!c->color) {
		c->attr = Color_RESET;
	}
	switch (style->symbol) {
	case LINE_UNCJMP:
		if (G (x, y)) {
			if (isvert) {
				W ("v");
			} else {
				W (">");
			}
		}
		break;
	case LINE_TRUE:
		if (G (x, y)) {
			W ("t"); //\\");
		}
		break;
	case LINE_FALSE:
		if (G (x, y)) {
			W ("f");
		}
		break;
	case LINE_NOSYM_VERT:
		if (G (x, y)) {
			W (useUtf8 ? RUNECODESTR_LINE_VERT : "|");
		}
		break;
	case LINE_NOSYM_HORIZ:
		if (G (x, y)) {
			W (useUtf8 ? RUNECODESTR_LINE_HORIZ : "-");
		}
		break;
	case LINE_NONE:
	default:
		break;
	}
}
开发者ID:PankajKataria,项目名称:radare2,代码行数:56,代码来源:canvas_line.c

示例14: r_core_asm_back_disassemble_all

static RList * r_core_asm_back_disassemble_all(RCore *core, ut64 addr, ut64 len, ut64 max_hit_count, ut32 extra_padding){
	RList *hits = r_core_asm_hit_list_new ();
	RCoreAsmHit dummy_value;
	RCoreAsmHit *hit = NULL;
	RAsmOp op;
	ut8 *buf = (ut8 *)malloc (len + extra_padding);
	int current_instr_len = 0;
	ut64 current_instr_addr = addr,
		 current_buf_pos = len - 1,
		 hit_count = 0;

	memset (&dummy_value, 0, sizeof (RCoreAsmHit));

	if (hits == NULL || buf == NULL ){
		if (hits) {
			r_list_purge (hits);
			free (hits);
		}
		free (buf);
		return NULL;
	}

	if (r_io_read_at (core->io, addr-(len+extra_padding), buf, len+extra_padding) != len+extra_padding) {
		r_list_purge (hits);
		free (hits);
		free (buf);
		return NULL;
	}

	if (len == 0){
		return hits;
	}

	current_buf_pos = len - 1;

	do {
		if (r_cons_singleton ()->breaked) break;
		// reset assembler
		r_asm_set_pc (core->assembler, current_instr_addr);
		current_instr_len = len - current_buf_pos + extra_padding;
		IFDBG eprintf("current_buf_pos: 0x%"PFMT64x", current_instr_len: %d\n", current_buf_pos, current_instr_len);
		current_instr_len = r_asm_disassemble (core->assembler, &op, buf+current_buf_pos, current_instr_len);
		hit = r_core_asm_hit_new ();
		hit->addr = current_instr_addr;
		hit->len = current_instr_len;
		hit->code = NULL;
		r_list_add_sorted (hits, hit, ((RListComparator)rcoreasm_address_comparator));

		current_buf_pos--;
		current_instr_addr--;
		hit_count++;
	} while ( ((int) current_buf_pos  >= 0) && (int)(len - current_buf_pos) >= 0 && hit_count <= max_hit_count);

	free(buf);
	return hits;
}
开发者ID:DePierre,项目名称:radare2,代码行数:56,代码来源:asm.c

示例15:

R_API const char *r_cons_pal_get (const char *key) {
	int i;
	for (i = 0; keys[i].name; i++) {
		if (!strcmp (key, keys[i].name)) {
			char **p = (char **) ((char *)& (r_cons_singleton ()->pal) + keys[i].off);
			return p? *p: "";
		}
	}
	return "";
}
开发者ID:AmesianX,项目名称:radare2,代码行数:10,代码来源:pal.c


注:本文中的r_cons_singleton函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。