本文整理汇总了C++中R_MIN函数的典型用法代码示例。如果您正苦于以下问题:C++ R_MIN函数的具体用法?C++ R_MIN怎么用?C++ R_MIN使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了R_MIN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __write
static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) {
if (fd->flags & R_IO_WRITE) {
int left, perm;
if (self_in_section (io->off, &left, &perm)) {
int newlen = R_MIN (len, left);
ut8 *ptr = (ut8*)(size_t)io->off;
if (newlen>0)
memcpy (ptr, buf, newlen);
return newlen;
}
}
return -1;
}
示例2: check_bytes
static int check_bytes(const ut8 *buf, ut64 length) {
bool rc = false;
if (buf && length >= 32) {
char arch[9] = {0};
strncpy (arch, (const char *)buf+9, R_MIN (length, sizeof (arch)-1));
rc = !memcmp (buf, "\x64\x79\x6c\x64", 4);
if (rc) {
dyld64 = strstr (arch, "64") != NULL;
eprintf ("Arch: %s\n", arch);
}
}
return rc;
}
示例3: __read
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) {
int left;
int perm;
if (self_in_section (io->off, &left, &perm)) {
if (perm & R_IO_READ) {
int newlen = R_MIN (len, left);
ut8 *ptr = (ut8*)(size_t)io->off;
memcpy (buf, ptr, newlen);
return newlen;
}
}
return 0;
}
示例4: r_diff_buffers_static
R_API int r_diff_buffers_static(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb) {
int i, len;
int hit = 0;
la = R_ABS (la);
lb = R_ABS (lb);
if (la != lb) {
len = R_MIN (la, lb);
eprintf ("Buffer truncated to %d byte(s) (%d not compared)\n", len, R_ABS(lb-la));
} else {
len = la;
}
for (i = 0; i < len; i++) {
if (a[i] != b[i]) {
hit++;
} else {
if (hit > 0) {
int ra = la - (i - hit);
int rb = lb - (i - hit);
struct r_diff_op_t o = {
.a_off = d->off_a+i-hit, .a_buf = a+i-hit, .a_len = R_MIN (hit, ra),
.b_off = d->off_b+i-hit, .b_buf = b+i-hit, .b_len = R_MIN (hit, rb)
};
d->callback (d, d->user, &o);
hit = 0;
}
}
}
if (hit > 0) {
int ra = la - (i - hit);
int rb = lb - (i - hit);
struct r_diff_op_t o = {
.a_off = d->off_a+i-hit, .a_buf = a+i-hit, .a_len = R_MIN (hit, ra),
.b_off = d->off_b+i-hit, .b_buf = b+i-hit, .b_len = R_MIN (hit, rb)
};
d->callback (d, d->user, &o);
hit = 0;
}
return 0;
}
示例5: disassemble
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
cs_insn* insn = NULL;
cs_mode mode = 0;
int ret, n = 0;
csh cd;
mode = (a->bits==16)? CS_MODE_THUMB: CS_MODE_ARM;
if (a->big_endian)
mode |= CS_MODE_BIG_ENDIAN;
else
mode |= CS_MODE_LITTLE_ENDIAN;
if (a->cpu && strstr (a->cpu, "m"))
mode |= CS_MODE_MCLASS;
if (a->cpu && strstr (a->cpu, "v8"))
mode |= CS_MODE_V8;
op->size = 4;
op->buf_asm[0] = 0;
ret = (a->bits==64)?
cs_open (CS_ARCH_ARM64, mode, &cd):
cs_open (CS_ARCH_ARM, mode, &cd);
if (ret) {
ret = -1;
goto beach;
}
if (a->syntax == R_ASM_SYNTAX_REGNUM) {
cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME);
} else cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT);
cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF);
n = cs_disasm (cd, buf, R_MIN (4, len),
a->pc, 1, &insn);
if (n<1) {
ret = -1;
goto beach;
}
if (insn->size<1) {
ret = -1;
goto beach;
}
op->size = insn->size;
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
insn->mnemonic,
insn->op_str[0]?" ":"",
insn->op_str);
r_str_rmch (op->buf_asm, '#');
cs_free (insn, n);
beach:
cs_close (&cd);
if (!op->buf_asm[0])
strcpy (op->buf_asm, "invalid");
return op->size;
}
示例6: r_io_def_mmap_seek
static ut64 r_io_def_mmap_seek(RIO *io, RIOMMapFileObj *mmo, ut64 offset, int whence) {
ut64 seek_val = UT64_MAX;
if (!mmo) return UT64_MAX;
if (mmo->rawio)
return lseek (mmo->fd, offset, whence);
if (!mmo->buf) return UT64_MAX;
seek_val = mmo->buf->cur;
switch (whence) {
case SEEK_SET:
seek_val = R_MIN (mmo->buf->length, offset);
break;
case SEEK_CUR:
seek_val = R_MIN (mmo->buf->length, (offset + mmo->buf->cur));
break;
case SEEK_END:
seek_val = mmo->buf->length;
break;
}
mmo->buf->cur = io->off = seek_val;
return seek_val;
}
示例7: SetCursorPosConcrete
bool SetCursorPosConcrete(
struct Tracker_Windows *window,
struct WBlocks *wblock,
NInt tracknum,
int subtrack
){
struct WTracks *wtrack;
int ret=0,tempret;
if(tracknum>=wblock->block->num_tracks || tracknum<TEMPOTRACK) return false;
if(tracknum<0){
if(tracknum==window->curr_track) return true;
if(tracknum>window->curr_track){
while(window->curr_track!=tracknum){
tempret=CursorRight(window,wblock);
ret=R_MAX(tempret,ret);
}
}else{
while(window->curr_track!=tracknum){
tempret=CursorLeft(window,wblock);
ret=R_MAX(tempret,ret);
}
}
}else{
wtrack=ListFindElement1(&wblock->wtracks->l,tracknum);
int num_subtracks = GetNumSubtracks(wtrack);
subtrack=R_MIN(num_subtracks-1,subtrack);
if(tracknum==window->curr_track && subtrack==window->curr_track_sub)
return 0;
if(tracknum>window->curr_track || (tracknum==window->curr_track && subtrack>window->curr_track_sub)){
while(window->curr_track!=tracknum || window->curr_track_sub!=subtrack){
tempret=CursorRight(window,wblock);
//printf("wtrack->num: %d, curr_track: %d, num_tracks: %d\n",wtrack->l.num, window->curr_track,wblock->block->num_tracks);
ret=R_MAX(tempret,ret);
}
}else{
while(window->curr_track!=tracknum || window->curr_track_sub!=subtrack){
tempret=CursorLeft(window,wblock);
ret=R_MAX(tempret,ret);
}
}
}
return true;
}
示例8: r_debug_reg_sync
R_API int r_debug_reg_sync(RDebug *dbg, int type, int write) {
int i, size;
if (!dbg || !dbg->reg || !dbg->h)
return R_FALSE;
// Theres no point in syncing a dead target
if (r_debug_is_dead (dbg))
return R_FALSE;
// Check if the functions needed are available
if (write && !dbg->h->reg_write)
return R_FALSE;
if (!write && !dbg->h->reg_read)
return R_FALSE;
// Sync all the types sequentially if asked
i = (type == R_REG_TYPE_ALL) ? R_REG_TYPE_GPR : type;
do {
if (write) {
ut8 *buf = r_reg_get_bytes (dbg->reg, i, &size);
if (!buf || !dbg->h->reg_write (dbg, i, buf, size)) {
if (i==0)
eprintf ("r_debug_reg: error writing registers %d to %d\n", i, dbg->pid);
return R_FALSE;
}
} else {
//int bufsize = R_MAX (1024, dbg->reg->size*2); // i know. its hacky
int bufsize = dbg->reg->size;
ut8 *buf = malloc (bufsize);
if (!buf) return R_FALSE;
//we have already checked dbg->h and dbg->h->reg_read above
size = dbg->h->reg_read (dbg, i, buf, bufsize);
// we need to check against zero because reg_read can return R_FALSE
if (!size) {
eprintf ("r_debug_reg: error reading registers\n");
free (buf);
return R_FALSE;
} else
r_reg_set_bytes (dbg->reg, i, buf, R_MIN(size, bufsize));
free (buf);
}
// DO NOT BREAK R_REG_TYPE_ALL PLEASE
// break;
// Continue the syncronization or just stop if it was asked only for a single type of regs
} while ((type==R_REG_TYPE_ALL) && (i++ < R_REG_TYPE_LAST));
return R_TRUE;
}
示例9: onIterMap
// Precondition: len > 0
// Non-stop IO
// Returns true iff all reads/writes on overlapped maps are complete.
static bool onIterMap(SdbListIter *iter, RIO *io, ut64 vaddr, ut8 *buf,
int len, int match_flg, cbOnIterMap op, void *user) {
// vendaddr may be 0 to denote 2**64
ut64 vendaddr = vaddr + len, len1;
int t;
bool ret = true;
for (; iter; iter = iter->p) {
RIOMap *map = (RIOMap *)iter->data;
ut64 to = r_itv_end (map->itv);
if (r_itv_overlap2 (map->itv, vaddr, len)) {
if ((map->flags & match_flg) == match_flg || io->p_cache) {
t = vaddr < map->itv.addr
? op (io, map->fd, map->delta, buf + map->itv.addr - vaddr,
len1 = R_MIN (vendaddr - map->itv.addr, map->itv.size), map, user)
: op (io, map->fd, map->delta + vaddr - map->itv.addr, buf,
len1 = R_MIN (to - vaddr, len), map, user);
if (t != len1) {
ret = false;
}
}
if (vaddr < map->itv.addr) {
t = onIterMap (iter->p, io, vaddr, buf, map->itv.addr - vaddr, match_flg, op, user);
if (!t) {
ret = false;
}
}
if (to - 1 < vendaddr - 1) {
t = onIterMap (iter->p, io, to, buf + to - vaddr, vendaddr - to, match_flg, op, user);
if (!t) {
ret = false;
}
}
}
}
return ret;
}
示例10: disassemble
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
struct disassemble_info disasm_obj;
int mode = 2;
op->buf_asm[0]='\0';
if (len<4)
return -1;
buf_global = op->buf_asm;
Offset = a->pc;
memcpy (bytes, buf, R_MIN (len, 8)); // TODO handle thumb
/* prepare disassembler */
memset (&disasm_obj, '\0', sizeof (struct disassemble_info));
disasm_obj.disassembler_options=(a->bits==64)?"64":"";
disasm_obj.buffer = bytes;
disasm_obj.read_memory_func = &cris_buffer_read_memory;
disasm_obj.symbol_at_address_func = &symbol_at_address;
disasm_obj.memory_error_func = &memory_error_func;
disasm_obj.print_address_func = &print_address;
disasm_obj.endian = !a->big_endian;
disasm_obj.fprintf_func = &buf_fprintf;
disasm_obj.stream = stdout;
if (a->cpu && *a->cpu) {
if (!strcmp (a->cpu, "v10+v32")) {
mode = 1;
} else
if (!strcmp (a->cpu, "v10")) {
mode = 0;
} else
if (!strcmp (a->cpu, "v32")) {
mode = 2;
} else mode = 2;
} else mode = 2;
(void)cris_parse_disassembler_options (&disasm_obj, mode);
if (a->syntax == R_ASM_SYNTAX_ATT) {
op->size = print_insn_crisv10_v32_with_register_prefix (
(bfd_vma)Offset, &disasm_obj);
} else {
op->size = print_insn_crisv10_v32_without_register_prefix (
(bfd_vma)Offset, &disasm_obj);
}
if (op->size == -1)
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
return op->size;
}
示例11: readstr
static void readstr (char *s, int sz, const ut8 *buf, int len) {
int die = 0;
int last = R_MIN (len, sz);
strncpy (s, (char *)buf, last + die);
s[last] = 0;
while (*s && *s == '\n') {
s++;
}
#if 1
char *nl = strchr (s, '\n');
if (nl) {
*nl = 0;
}
#endif
virgin = false;
}
示例12: __read
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) {
vm_size_t size = 0;
int blen, err, copied = 0;
int blocksize = 32;
if (RIOMACH_PID (fd->data) == 0) {
if (io->off<4096)
return len;
}
memset (buf, 0xff, len);
while (copied<len) {
blen = R_MIN ((len-copied), blocksize);
//blen = len;
err = vm_read_overwrite (RIOMACH_TASK (fd->data),
(ut64)io->off+copied, blen, (pointer_t)buf+copied, &size);
switch (err) {
case KERN_PROTECTION_FAILURE:
//eprintf ("r_io_mach_read: kern protection failure.\n");
break;
case KERN_INVALID_ADDRESS:
if (blocksize == 1) {
memset (buf+copied, 0xff, len-copied);
return size+copied;
}
blocksize = 1;
blen = 1;
buf[copied] = 0xff;
//eprintf("invaddr %d\n",len);
break;
}
if (err == -1) {
//eprintf ("Cannot read\n");
return -1;
}
if (size==0) {
if (blocksize == 1) {
memset (buf+copied, 0xff, len-copied);
return len; //size+copied;
}
blocksize = 1;
blen = 1;
buf[copied] = 0xff;
}
//if (size != blen) { return size+copied; }
copied += blen;
}
return len; //(int)size;
}
示例13: r_debug_gdb_reg_read
static int r_debug_gdb_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
int copy_size;
int buflen = 0;
gdbr_read_registers (desc);
if (!desc) {
return -1;
}
// read the len of the current area
free (r_reg_get_bytes (dbg->reg, type, &buflen));
if (size < desc->data_len) {
eprintf ("r_debug_gdb_reg_read: small buffer %d vs %d\n",
(int)size, (int)desc->data_len);
// return -1;
}
copy_size = R_MIN (desc->data_len, size);
buflen = R_MAX (desc->data_len, buflen);
if (reg_buf) {
if (buf_size < copy_size) { //desc->data_len) {
ut8* new_buf = realloc (reg_buf, copy_size);
if (!new_buf)
return -1;
reg_buf = new_buf;
buflen = copy_size;
buf_size = desc->data_len;
}
} else {
reg_buf = calloc (buflen, 1);
if (!reg_buf)
return -1;
buf_size = buflen;
}
memset ((void*)(volatile void*)buf, 0, size);
memcpy ((void*)(volatile void*)buf, desc->data, copy_size);
memset ((void*)(volatile void*)reg_buf, 0, buflen);
memcpy ((void*)(volatile void*)reg_buf, desc->data, copy_size);
#if 0
int i;
//for(i=0;i<168;i++) {
for(i=0;i<copy_size;i++) {
if (!(i%16)) printf ("\n0x%08x ", i);
printf ("%02x ", buf[i]); //(ut8)desc->data[i]);
}
printf("\n");
#endif
return desc->data_len;
}
示例14: r_cons_canvas_box
R_API void r_cons_canvas_box(RConsCanvas *c, int x, int y, int w, int h, const char *color) {
int i, x_mod;
int roundcorners = 0;
char *row = NULL, *row_ptr;
char corner = '=';
if (w < 1 || h<1) return;
//if (x > c->w*2) return;
//if (y > c->h*2) return;
if (color)
c->attr = color;
row = malloc (w+1);
if (!row)
return;
row[0] = roundcorners?'.':corner;
if (w>2)
memset (row+1, '-', w-2);
if (w>1)
row[w-1] = roundcorners?'.':corner;
row[w] = 0;
row_ptr = row;
x_mod = x;
if (x < -c->sx) {
x_mod = R_MIN(-c->sx, x_mod + w);
row_ptr += x_mod - x;
}
if (G(x_mod, y)) {
W(row_ptr);
}
if (G(x_mod, y+h-1)) {
row[0] = roundcorners?'\'':corner;
row[w-1] = roundcorners?'\'':corner;
W(row_ptr);
}
for (i=1; i<h-1; i++) {
if (G(x, y+i)) W("|");
if (G(x+w-1, y+i)) W("|");
}
free (row);
if (color)
c->attr = Color_RESET;
}
示例15: rdisplay_ratio_compute
/*========================================================================
* rdisplay_ratio_compute
*
*
*========================================================================*/
void rdisplay_ratio_compute(void)
{
double lratio, lratio_width, lratio_height;
if ( (( rval_get( window_mode ) ) == RDISPLAY_FULLSCREEN) ) {
lratio_width = (double)( rval_get( desktop_width ) ) / (double)( rattr( design_width ) );
lratio_height = (double)( rval_get( desktop_height ) ) / (double)( rattr( design_height ) );
} else {
lratio_width = (double)( rval_get( window_width ) ) / (double)( rattr( design_width ) );
lratio_height = (double)( rval_get( window_height ) ) / (double)( rattr( design_height ) );
}
lratio = R_MIN( lratio_width, lratio_height);
rval_set( rdh_double, ratio_width, lratio_width);
rval_set( rdh_double, ratio_height, lratio_height);
rval_set( rdh_double, ratio, lratio);
/* styles refresh */
{
rlsstyle_iterator iter;
rlsstyle* ls = &( rattr( styles ) );
rstyle* style = rlsstyle_first( &iter, ls );
while (style) {
rstyle_refresh( style, lratio, lratio_width, lratio_height);
style = rlsstyle_next( &iter );
}
}
/* wid ratio/blit */
{
rlswid_iterator iter;
rlswid* ls = &( rattr( wids ) );
rwid* wid = rlswid_first( &iter, ls );
while (wid) {
/* [!] wid list shall sorted with parents first */
rwid_bb_compute( wid );
wid = rlswid_next( &iter );
}
}
}