Exemple #1
0
void party_created(int account_id,int char_id,int fail,int party_id,char *name)
{
	struct map_session_data *sd;
	sd = map_id2sd(account_id);

	if (!sd || sd->status.char_id != char_id || !sd->party_creating ) {
		//Character logged off before creation ack?
		if (!fail) //Break up party since player could not be added to it.
			intif_party_leave(party_id,account_id,char_id);
		return;
	}

	sd->party_creating = false;

	if (!fail) {
		sd->status.party_id = party_id;
		clif_party_created(sd,0); //Success message
		//We don't do any further work here because the char-server sends a party info packet right after creating the party
		if (party_create_byscript) {	//Returns party id in $@party_create_id if party is created by script
			mapreg_setreg(add_str("$@party_create_id"),party_id);
			party_create_byscript = 0;
		}
	} else
		clif_party_created(sd,1); // "Party name already exists"
}
Exemple #2
0
void search_message(unsigned char a[][250],int m)
{
    Clear();
    for(int i=0;i<m;i++)
    {
        add_str(a[i]);
    }
    add_pre();
    nans=0;
    for(struct person *p=longlong_to_PersonPoint(PersonList->NextPerson);p!=MemBasePerson;p=longlong_to_PersonPoint(p->NextPerson))
    {
        for(struct message *q=longlong_to_MessagePoint(p->HeadMessage);q!=MemBaseMessage;q=longlong_to_MessagePoint(q->NextMessage))
        {
            int tnum=Find(q->content);
            if(tnum>=1)
            {
                ans[nans].cont=q;
                ans[nans++].num=tnum;
            }
        }
    }
    qsort(ans,nans,sizeof(ans[0]),cmp);
    int index=0;
    for(int i=0;i<nans;i++)
    {
        mvaddstr(WELCOME_POS_X+9+index,WELCOME_POS_Y-3,ans[i].cont->content);
        //printf("匹配的关键字数:%d\n",ans[i].num);
        //move(WELCOME_POS_X+6+index,WELCOME_POS_Y-4);
        index++;
    }
}
Exemple #3
0
/*
 * Add iCalendar recur-rule-parts to a structured element.
 */
void icalrecurrencetype_add_as_xxx(struct icalrecurrencetype *recur, void *obj,
                                   void (*add_int)(void *, const char *, int),
                                   void (*add_str)(void *, const char *,
                                           const char *))
{
    char *rrule, *rpart;
    tok_t rparts;

    /* generate an iCal RRULE string */
    rrule = icalrecurrencetype_as_string_r(recur);

    /* split string into rparts & values */
    tok_initm(&rparts, rrule, "=;", TOK_TRIMLEFT|TOK_TRIMRIGHT);
    while ((rpart = tok_next(&rparts))) {
        if (!strcmp(rpart, "UNTIL")) {
            /* need to translate date format to ISO */
            struct icaltimetype until = icaltime_from_string(tok_next(&rparts));

            add_str(obj, "until", icaltime_as_iso_string(until));
        }
        else {
            /* assume the rpart has multiple values - split them */
            tok_t vlist;
            char *val, *p;

            tok_init(&vlist, tok_next(&rparts), ",",
                     TOK_TRIMLEFT|TOK_TRIMRIGHT);
            while ((val = tok_next(&vlist))) {
                if (add_int) {
                    /* try converting value to integer */
                    int n = strtol(val, &p, 10);

                    if (n && !*p) {
                        add_int(obj, lcase(rpart), n);
                        continue;
                    }
                }

                add_str(obj, lcase(rpart), val);
            }
            tok_fini(&vlist);
        }
    }
    tok_fini(&rparts);

    free(rrule);
}
Exemple #4
0
/**
 * Check here hacker for duplicate item in trade
 * normal client refuse to have 2 same types of item (except equipment) in same trade window
 * normal client authorise only no equipped item and only from inventory
 * This function could end player connection if too much hack is detected
 * @param sd : player to check
 * @return -1:zeny hack, 0:all fine, 1:item hack
 */
int impossible_trade_check(struct map_session_data *sd)
{
	struct item inventory[MAX_INVENTORY];
	char message_to_gm[200];
	int i, index;

	nullpo_retr(1, sd);

	if(sd->deal.zeny > sd->status.zeny) {
		pc_setglobalreg(sd, add_str("ZENY_HACKER"), 1);
		return -1;
	}

	// get inventory of player
	memcpy(&inventory, &sd->inventory.u.items_inventory, sizeof(struct item) * MAX_INVENTORY);

	// remove this part: arrows can be trade and equipped
	// re-added! [celest]
	// remove equipped items (they can not be trade)
	for (i = 0; i < MAX_INVENTORY; i++)
		if (inventory[i].nameid > 0 && inventory[i].equip && !(inventory[i].equip & EQP_AMMO))
			memset(&inventory[i], 0, sizeof(struct item));

	// check items in player inventory
	for(i = 0; i < 10; i++) {
		if (!sd->deal.item[i].amount)
			continue;

		index = sd->deal.item[i].index;

		if (inventory[index].amount < sd->deal.item[i].amount) { // if more than the player have -> hack
			sprintf(message_to_gm, msg_txt(sd,538), sd->status.name, sd->status.account_id); // Hack on trade: character '%s' (account: %d) try to trade more items that he has.
			intif_wis_message_to_gm(wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm);
			sprintf(message_to_gm, msg_txt(sd,539), inventory[index].amount, inventory[index].nameid, sd->deal.item[i].amount); // This player has %d of a kind of item (id: %d), and try to trade %d of them.
			intif_wis_message_to_gm(wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm);
			// if we block people
			if (battle_config.ban_hack_trade < 0) {
				chrif_req_login_operation(-1, sd->status.name, CHRIF_OP_LOGIN_BLOCK, 0, 0, 0); // type: 1 - block
				set_eof(sd->fd); // forced to disconnect because of the hack
				// message about the ban
				strcpy(message_to_gm, msg_txt(sd,540)); //  This player has been definitively blocked.
			// if we ban people
			} else if (battle_config.ban_hack_trade > 0) {
				chrif_req_login_operation(-1, sd->status.name, CHRIF_OP_LOGIN_BAN, battle_config.ban_hack_trade*60, 0, 0); // type: 2 - ban (year, month, day, hour, minute, second)
				set_eof(sd->fd); // forced to disconnect because of the hack
				// message about the ban
				sprintf(message_to_gm, msg_txt(sd,507), battle_config.ban_hack_trade); //  This player has been banned for %d minute(s).
			} else
				// message about the ban
				strcpy(message_to_gm, msg_txt(sd,508)); //  This player hasn't been banned (Ban option is disabled).

			intif_wis_message_to_gm(wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm);
			return 1;
		}

		inventory[index].amount -= sd->deal.item[i].amount; // remove item from inventory
	}
	return 0;
}
static void add_disp32(void) {
    uint32_t disp = get_code();
    disp |= (uint32_t)get_code() << 8;
    disp |= (uint32_t)get_code() << 16;
    disp |= (uint32_t)get_code() << 24;
    add_str("0x");
    add_hex_uint32(disp);
}
static void add_imm32(void) {
    uint32_t imm = get_code();
    imm |= (uint32_t)get_code() << 8;
    imm |= (uint32_t)get_code() << 16;
    imm |= (uint32_t)get_code() << 24;
    add_str("0x");
    add_hex_uint32(imm);
}
Exemple #7
0
void			flag_percent(t_str *out, t_opt *opt, va_list *ap)
{
	char			c;

	c = '%';
	add_str(out, &c, 1, opt);
	(void)ap;
}
Exemple #8
0
/*
 * Begin the string
 */
static void begin_str(LEX *lf, int ch)
{
   lf->str_len = 0;
   lf->str[0] = 0;
   if (ch != 0) {
      add_str(lf, ch);
   }
   lf->begin_line_no = lf->line_no;   /* save start string line no */
}
static void add_flt_uint64(uint64_t n) {
    char buf[32];
    union {
        uint64_t n;
        double d;
    } u;
    u.n = n;
    snprintf(buf, sizeof(buf), "%g", u.d);
    add_str(buf);
}
Exemple #10
0
/*
 * Save the current time of the duel in PC_LAST_DUEL_TIME
 */
void duel_savetime(struct map_session_data* sd)
{
	time_t timer;
	struct tm *t;

	time(&timer);
	t = localtime(&timer);

	pc_setglobalreg(sd, add_str("PC_LAST_DUEL_TIME"), t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min);
}
/*******************************************************************************
 * Copyright (c) 2015 Xilinx, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 * You may elect to redistribute this code under either of these licenses.
 *
 * Contributors:
 *     Xilinx - initial API and implementation
 *******************************************************************************/

#include <tcf/config.h>

#if SERVICE_Disassembly

#include <assert.h>
#include <stdio.h>
#include <tcf/framework/context.h>
#include <tcf/services/symbols.h>
#include <machine/x86_64/tcf/disassembler-x86_64.h>

#define PREFIX_LOCK         0x0001
#define PREFIX_REPNZ        0x0002
#define PREFIX_REPZ         0x0004
#define PREFIX_CS           0x0008
#define PREFIX_SS           0x0010
#define PREFIX_DS           0x0020
#define PREFIX_ES           0x0040
#define PREFIX_FS           0x0080
#define PREFIX_GS           0x0100
#define PREFIX_DATA_SIZE    0x0200
#define PREFIX_ADDR_SIZE    0x0400

#define REX_W               0x08
#define REX_R               0x04
#define REX_X               0x02
#define REX_B               0x01

static char buf[128];
static size_t buf_pos = 0;
static DisassemblerParams * params = NULL;
static uint64_t instr_addr = 0;
static uint8_t * code_buf = NULL;
static size_t code_pos = 0;
static size_t code_len = 0;
static uint32_t prefix = 0;
static uint32_t vex = 0;
static uint8_t rex = 0;
static unsigned data_size = 0;
static unsigned addr_size = 0;
static int x86_64 = 0;

static uint8_t get_code(void) {
    uint8_t c = 0;
    if (code_pos < code_len) c = code_buf[code_pos];
    code_pos++;
    return c;
}

static void add_char(char ch) {
    if (buf_pos >= sizeof(buf) - 1) return;
    buf[buf_pos++] = ch;
}

static void add_str(const char * s) {
    while (*s) add_char(*s++);
}

static void add_dec_uint32(uint32_t n) {
    char s[32];
    size_t i = 0;
    do {
        s[i++] = (char)('0' + n % 10);
        n = n / 10;
    }
    while (n != 0);
    while (i > 0) add_char(s[--i]);
}

#if 0 /* Not used yet */
static void add_dec_uint64(uint64_t n) {
    char s[64];
    size_t i = 0;
    do {
        s[i++] = (char)('0' + (int)(n % 10));
        n = n / 10;
    }
    while (n != 0);
    while (i > 0) add_char(s[--i]);
}
#endif

static void add_hex_uint32(uint32_t n) {
    char s[32];
    size_t i = 0;
    while (i < 8) {
        uint32_t d = n & 0xf;
        if (i > 0 && n == 0) break;
        s[i++] = (char)(d < 10 ? '0' + d : 'a' + d - 10);
        n = n >> 4;
    }
    while (i > 0) add_char(s[--i]);
}

static void add_hex_uint64(uint64_t n) {
    char s[64];
    size_t i = 0;
    while (i < 16) {
        uint32_t d = n & 0xf;
        if (i > 0 && n == 0) break;
        s[i++] = (char)(d < 10 ? '0' + d : 'a' + d - 10);
        n = n >> 4;
    }
    while (i > 0) add_char(s[--i]);
}

#if 0 /* Not used yet */
static void add_flt_uint32(uint32_t n) {
    char buf[32];
    union {
        uint32_t n;
        float f;
    } u;
    u.n = n;
    snprintf(buf, sizeof(buf), "%g", u.f);
    add_str(buf);
}
static void add_seg_reg(unsigned reg) {
    switch (reg) {
    case 0: add_str("es"); break;
    case 1: add_str("cs"); break;
    case 2: add_str("ss"); break;
    case 3: add_str("ds"); break;
    case 4: add_str("fs"); break;
    case 5: add_str("gs"); break;
    case 6: add_str("s6"); break;
    case 7: add_str("s7"); break;
    }
}
Exemple #13
0
/*! generic function which adds text derived from single octet map to text */
static unsigned int add_str_from_octet_map(ops_text_t *text,char *str,
					   unsigned char octet)
    {
    if (str && !add_str(&text->known,str)) 
	{
	/* value recognised, but there was a problem adding it to the list */
	/* XXX - should print out error msg here, Ben? - rachel */
	return 0;
	}
    else if (!str)
	{
	/* value not recognised and there was a problem adding it to the unknown list */
    unsigned len=2+2+1; /* 2 for "0x", 2 for single octet in hex format, 1 for NULL */
	str=malloc(len);
	snprintf(str,len,"0x%x",octet);
	if (!add_str(&text->unknown,str))
	    return 0;
	}
    return 1;
    }
Exemple #14
0
static int hist_entry__transaction_snprintf(struct hist_entry *he, char *bf,
					    size_t size, unsigned int width)
{
	u64 t = he->transaction;
	char buf[128];
	char *p = buf;
	int i;

	buf[0] = 0;
	for (i = 0; txbits[i].name; i++)
		if (txbits[i].flag & t)
			p = add_str(p, txbits[i].name);
	if (t && !(t & (PERF_TXN_SYNC|PERF_TXN_ASYNC)))
		p = add_str(p, "NEITHER ");
	if (t & PERF_TXN_ABORT_MASK) {
		sprintf(p, ":%" PRIx64,
			(t & PERF_TXN_ABORT_MASK) >>
			PERF_TXN_ABORT_SHIFT);
		p += strlen(p);
	}
static void add_addr(uint64_t addr) {
    add_hex_uint64(addr);
#if ENABLE_Symbols
    if (ctx != NULL) {
        Symbol * sym = NULL;
        char * name = NULL;
        ContextAddress sym_addr = 0;
        if (find_symbol_by_addr(ctx, STACK_NO_FRAME, (ContextAddress)addr, &sym) < 0) return;
        if (get_symbol_name(sym, &name) < 0 || name == NULL) return;
        if (get_symbol_address(sym, &sym_addr) < 0) return;
        if (sym_addr <= addr) {
            add_str(" ; ");
            add_str(name);
            if (sym_addr < addr) {
                add_str(" + 0x");
                add_hex_uint64(addr - sym_addr);
            }
        }
    }
#endif
}
/*******************************************************************************
 * Copyright (c) 2015 Xilinx, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 * You may elect to redistribute this code under either of these licenses.
 *
 * Contributors:
 *     Xilinx - initial API and implementation
 *******************************************************************************/

#include <tcf/config.h>

#if SERVICE_Disassembly

#include <assert.h>
#include <stdio.h>
#include <tcf/framework/context.h>
#include <tcf/services/symbols.h>
#include <machine/x86_64/tcf/disassembler-x86_64.h>

#define PREFIX_LOCK         0x0001
#define PREFIX_REPNZ        0x0002
#define PREFIX_REPZ         0x0004
#define PREFIX_CS           0x0008
#define PREFIX_SS           0x0010
#define PREFIX_DS           0x0020
#define PREFIX_ES           0x0040
#define PREFIX_FS           0x0080
#define PREFIX_GS           0x0100
#define PREFIX_DATA_SIZE    0x0200
#define PREFIX_ADDR_SIZE    0x0400

#define REX_W               0x08
#define REX_R               0x04
#define REX_X               0x02
#define REX_B               0x01

static char buf[128];
static size_t buf_pos = 0;
static DisassemblerParams * params = NULL;
static uint64_t instr_addr = 0;
static uint8_t * code_buf = NULL;
static size_t code_pos = 0;
static size_t code_len = 0;
static uint32_t prefix = 0;
static uint32_t vex = 0;
static uint8_t rex = 0;
static unsigned data_size = 0;
static unsigned addr_size = 0;
static int x86_64 = 0;

static uint8_t get_code(void) {
    uint8_t c = 0;
    if (code_pos < code_len) c = code_buf[code_pos];
    code_pos++;
    return c;
}

static void add_char(char ch) {
    if (buf_pos >= sizeof(buf) - 1) return;
    buf[buf_pos++] = ch;
}

static void add_str(const char * s) {
    while (*s) add_char(*s++);
}

static void add_dec_uint32(uint32_t n) {
    char s[32];
    size_t i = 0;
    do {
        s[i++] = (char)('0' + n % 10);
        n = n / 10;
    }
    while (n != 0);
    while (i > 0) add_char(s[--i]);
}

#if 0 /* Not used yet */
static void add_dec_uint64(uint64_t n) {
    char s[64];
    size_t i = 0;
    do {
        s[i++] = (char)('0' + (int)(n % 10));
        n = n / 10;
    }
    while (n != 0);
    while (i > 0) add_char(s[--i]);
}
#endif

static void add_hex_uint32(uint32_t n) {
    char s[32];
    size_t i = 0;
    while (i < 8) {
        uint32_t d = n & 0xf;
        if (i > 0 && n == 0) break;
        s[i++] = (char)(d < 10 ? '0' + d : 'a' + d - 10);
        n = n >> 4;
    }
    while (i > 0) add_char(s[--i]);
}

static void add_hex_uint64(uint64_t n) {
    char s[64];
    size_t i = 0;
    while (i < 16) {
        uint32_t d = n & 0xf;
        if (i > 0 && n == 0) break;
        s[i++] = (char)(d < 10 ? '0' + d : 'a' + d - 10);
        n = n >> 4;
    }
    while (i > 0) add_char(s[--i]);
}

#if 0 /* Not used yet */
static void add_flt_uint32(uint32_t n) {
    char buf[32];
    union {
        uint32_t n;
        float f;
    } u;
    u.n = n;
    snprintf(buf, sizeof(buf), "%g", u.f);
    add_str(buf);
}

static void add_flt_uint64(uint64_t n) {
    char buf[32];
    union {
        uint64_t n;
        double d;
    } u;
    u.n = n;
    snprintf(buf, sizeof(buf), "%g", u.d);
    add_str(buf);
}
#endif

static void add_addr(uint64_t addr) {
    while (buf_pos < 16) add_char(' ');
    add_str("; addr=0x");
    add_hex_uint64(addr);
#if ENABLE_Symbols
    if (params->ctx != NULL) {
        Symbol * sym = NULL;
        char * name = NULL;
        ContextAddress sym_addr = 0;
        if (find_symbol_by_addr(params->ctx, STACK_NO_FRAME, (ContextAddress)addr, &sym) < 0) return;
        if (get_symbol_name(sym, &name) < 0 || name == NULL) return;
        if (get_symbol_address(sym, &sym_addr) < 0) return;
        if (sym_addr <= addr) {
            add_str(": ");
            add_str(name);
            if (sym_addr < addr) {
                add_str(" + 0x");
                add_hex_uint64(addr - (uint64_t)sym_addr);
            }
        }
    }
#endif
}

static void add_reg(unsigned reg, unsigned size) {
    if (reg >= 8) {
        add_char('r');
        add_dec_uint32(reg);
        switch (size) {
        case 1: add_char('l'); break;
        case 2: add_char('w'); break;
        case 4: add_char('d'); break;
        }
        return;
    }
    if (x86_64 && size == 1 && reg >= 4 && reg <= 7) {
        switch (reg) {
        case 4: add_str("spl"); break;
        case 5: add_str("bpl"); break;
        case 6: add_str("sil"); break;
        case 7: add_str("dil"); break;
        }
        return;
    }
    if (size == 1) {
        switch (reg) {
        case 0: add_str("al"); break;
        case 1: add_str("cl"); break;
        case 2: add_str("dl"); break;
        case 3: add_str("bl"); break;
        case 4: add_str("ah"); break;
        case 5: add_str("ch"); break;
        case 6: add_str("dh"); break;
        case 7: add_str("bh"); break;
        }
    }
    else {
        switch (size) {
        case 4: add_char('e'); break;
        case 8: add_char('r'); break;
        }
        switch (reg) {
        case 0: add_str("ax"); break;
        case 1: add_str("cx"); break;
        case 2: add_str("dx"); break;
        case 3: add_str("bx"); break;
        case 4: add_str("sp"); break;
        case 5: add_str("bp"); break;
        case 6: add_str("si"); break;
        case 7: add_str("di"); break;
        }
    }
}

static void add_seg_reg(unsigned reg) {
    switch (reg) {
    case 0: add_str("es"); break;
    case 1: add_str("cs"); break;
    case 2: add_str("ss"); break;
    case 3: add_str("ds"); break;
    case 4: add_str("fs"); break;
    case 5: add_str("gs"); break;
    case 6: add_str("s6"); break;
    case 7: add_str("s7"); break;
    }
}

#if 0
static void add_ctrl_reg(unsigned reg) {
    add_str("cr");
    add_dec_uint32(reg);
}

static void add_dbg_reg(unsigned reg) {
    add_str("dr");
    add_dec_uint32(reg);
}
#endif

static void add_ttt(unsigned ttt) {
    switch (ttt) {
    case  0: add_str("o"); break;
    case  1: add_str("no"); break;
    case  2: add_str("b"); break;
    case  3: add_str("ae"); break;
    case  4: add_str("e"); break;
    case  5: add_str("ne"); break;
    case  6: add_str("be"); break;
    case  7: add_str("a"); break;
    case  8: add_str("s"); break;
    case  9: add_str("ns"); break;
    case 10: add_str("pe"); break;
    case 11: add_str("po"); break;
    case 12: add_str("l"); break;
    case 13: add_str("ge"); break;
    case 14: add_str("le"); break;
    case 15: add_str("g"); break;
    }
}

static void add_disp8(void) {
    uint32_t disp = get_code();
    if (disp < 0x80) {
        add_char('+');
    }
    else {
        add_char('-');
        disp = (disp ^ 0xff) + 1;
    }
    add_str("0x");
    add_hex_uint32(disp);
}

static void add_disp16(void) {
    uint32_t disp = get_code();
    disp |= (uint32_t)get_code() << 8;
    add_str("0x");
    add_hex_uint32(disp);
}

static void add_disp32(void) {
    uint32_t disp = get_code();
    disp |= (uint32_t)get_code() << 8;
    disp |= (uint32_t)get_code() << 16;
    disp |= (uint32_t)get_code() << 24;
    add_str("0x");
    add_hex_uint32(disp);
}

static void add_imm8(void) {
    uint32_t imm = get_code();
    add_str("0x");
    add_hex_uint32(imm);
}

static void add_imm16(void) {
    uint32_t imm = get_code();
    imm |= (uint32_t)get_code() << 8;
    add_str("0x");
    add_hex_uint32(imm);
}

static void add_imm32(void) {
    uint32_t imm = get_code();
    imm |= (uint32_t)get_code() << 8;
    imm |= (uint32_t)get_code() << 16;
    imm |= (uint32_t)get_code() << 24;
    add_str("0x");
    add_hex_uint32(imm);
}

#if 0 /* Not used yet */
static void add_imm64(void) {
    uint64_t imm = get_code();
    imm |= (uint64_t)get_code() << 8;
    imm |= (uint64_t)get_code() << 16;
    imm |= (uint64_t)get_code() << 24;
    imm |= (uint64_t)get_code() << 32;
    imm |= (uint64_t)get_code() << 40;
    imm |= (uint64_t)get_code() << 48;
    imm |= (uint64_t)get_code() << 56;
    add_str("0x");
    add_hex_uint64(imm);
}
static void add_disp8(void) {
    uint32_t disp = get_code();
    if (disp < 0x80) {
        add_char('+');
    }
    else {
        add_char('-');
        disp = (disp ^ 0xff) + 1;
    }
    add_str("0x");
    add_hex_uint32(disp);
}
static void add_moffs(int wide) {
    uint64_t addr = 0;
    unsigned i = 0;

    while (i < addr_size) {
        addr |= (uint64_t)get_code() << (i * 8);
        i++;
    }

    add_str("[0x");
    add_hex_uint64(addr);
    add_char(']');
}
Exemple #19
0
/*
 * Check if the time elapsed between last duel is enough to launch another.
 */
int duel_checktime(struct map_session_data* sd)
{
	int diff;
	time_t timer;
	struct tm *t;

	time(&timer);
	t = localtime(&timer);

	diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, add_str("PC_LAST_DUEL_TIME"));

	return !(diff >= 0 && diff < battle_config.duel_time_interval);
}
static void add_rel(unsigned size) {
    uint64_t offs = 0;
    uint64_t sign = (uint64_t)1 << (size * 8 - 1);
    uint64_t mask = sign - 1;
    unsigned i = 0;

    while (i < size) {
        offs |= (uint64_t)get_code() << (i * 8);
        i++;
    }

    if (offs & sign) {
        offs = (offs ^ (sign | mask)) + 1;
        add_str("-0x");
        add_hex_uint64(offs);
        add_addr(instr_addr + code_pos - offs);
    }
    else {
        add_str("+0x");
        add_hex_uint64(offs);
        add_addr(instr_addr + code_pos + offs);
    }
}
Exemple #21
0
char_buffer_st *lua_gsub(const char *src, size_t srcl, const char *p, size_t lp,const char *tr, size_t max_s, const char **error_ptr)
{
    int anchor;
    size_t n;
    LuaMatchState ms;
    char_buffer_st *b;
    if(max_s == 0) max_s = srcl+1;
    anchor = (*p == '^');
    n = NEW_SIZE(srcl);
    b = (char_buffer_st*)malloc(sizeof(char_buffer_st) + n);
    if(!b) return NULL;
    b->size = n;
    b->used = 0;
    
    n = 0;
    if (anchor)
        p++, lp--;  // skip anchor character
    
    ms.error = 0;
    ms.src_init = src;
    ms.src_end = src+srcl;
    ms.p_end = p + lp;
    while (n < max_s)
    {
        const char *e;
        ms.level = 0;
        e = match(&ms, src, p);
        if(ms.error) goto free_and_null;
        if (e) {
            n++;
            if(!add_value(&ms, &b, src, e, tr)) goto free_and_null;
        }
        if (e && e>src) // non empty match?
            src = e;  // skip it
        else if (src < ms.src_end){
            if(!add_char(&ms, &b, *src++)) goto free_and_null;
        }
        else break;
        if (anchor) break;
    }
    if(!add_str(&ms, &b, src, ms.src_end-src)) goto free_and_null;
    b->buf[b->used] = '\0';
    return b;
    
free_and_null:
    if(b) free(b);
    if(error_ptr) *error_ptr = ms.error;
    return NULL;
}
Exemple #22
0
static int add_num_time_t(char *string, int max, time_t num)
{
	/* This buffer is large enough to hold the character representation
	   (including the trailing NUL) of any unsigned decimal quantity
	   whose binary representation fits in 128 bits.  */
	char buf[40];
	int length;

	if (sizeof(num) > 16)
		abort();
	length = snprintf(buf, sizeof(buf), "%lu", (unsigned long)num);
	assert(length >= 0 && (size_t)length<sizeof(buf));
	length = add_str(string, buf, max);
	return length;
}
Exemple #23
0
char *get_detail_xcore(csh *handle, cs_mode mode, cs_insn *ins)
{
	cs_xcore *xcore;
	int i;
	char *result;

	result = (char *)malloc(sizeof(char));
	result[0] = '\0';

	if (ins->detail == NULL)
		return result;

	xcore = &(ins->detail->xcore);
	if (xcore->op_count)
		add_str(&result, " ; op_count: %u", xcore->op_count);

	for (i = 0; i < xcore->op_count; i++) {
		cs_xcore_op *op = &(xcore->operands[i]);
		switch((int)op->type) {
			default:
				break;
			case XCORE_OP_REG:
				add_str(&result, " ; operands[%u].type: REG = %s", i, cs_reg_name(*handle, op->reg));
				break;
			case XCORE_OP_IMM:
				add_str(&result, " ; operands[%u].type: IMM = 0x%x", i, op->imm);
				break;
			case XCORE_OP_MEM:
				add_str(&result, " ; operands[%u].type: MEM", i);
				if (op->mem.base != XCORE_REG_INVALID)
					add_str(&result, " ; operands[%u].mem.base: REG = %s", i, cs_reg_name(*handle, op->mem.base));
				if (op->mem.index != XCORE_REG_INVALID)
					add_str(&result, " ; operands[%u].mem.index: REG = %s", i, cs_reg_name(*handle, op->mem.index));
				if (op->mem.disp != 0)
					add_str(&result, " ; operands[%u].mem.disp: 0x%x", i, op->mem.disp);
				if (op->mem.direct != 1)
					add_str(&result, " ; operands[%u].mem.direct: -1", i);


				break;
		}
	}

	return result;
}
    string multiply(string num1, string num2) {
        string res = "";
        if(num1 == "0" || num2 == "0")
            return "0";
        if(num2.size() > num1.size())
            return multiply(num2, num1);
        int index_num1, index_num2 = num2.size() - 1;
        while(index_num2 >= 0) {
            string tmp_res = get_mid_str(num1, num2, index_num2);

            add_str(res, tmp_res, num2.size() - 1 - index_num2);

            index_num2--;
        }
        return res;
    }
Exemple #25
0
/*
 * format a string for the log, with suitable prefixes.
 * A format starting with ~ indicates that this is a reprocessing
 * of the message, so prefixing and quoting is suppressed.
 */
static void fmt_log(char *buf, size_t buf_len,
		const char *fmt, va_list ap)
{
	bool reproc = *fmt == '~';
	char *p = buf;

	buf[0] = '\0';
	if (reproc) {
		fmt++;	/* ~ at start of format suppresses this prefix */
	} else if (progname != NULL && (strlen(progname) + 1 + 1) < buf_len) {
		/* start with name of connection */
		p = add_str(buf, buf_len, jam_str(buf, buf_len, progname), " ");
	}
	vsnprintf(p, buf_len - (p - buf), fmt, ap);
	if (!reproc)
		sanitize_string(buf, buf_len);
}
Exemple #26
0
char *f_capture_text(void)
{
    t_str *text;
    char c;
    char *str;
    int width;

    text = NULL;
    while (_read(0, &c, 1))
        text = add_str(text, 0, c);
    str = export_str(text);
    width = cpt_index(text);
    if (width == 0)
        str = f_capture_text();
    text = free_list(text);
    return (str);
}
Exemple #27
0
/// Loads permanent variables from database
static void script_load_mapreg(void)
{
	/*
	        0        1       2
	   +-------------------------+
	   | varname | index | value |
	   +-------------------------+
	                                */
	SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
	char varname[32+1];
	int index;
	char value[255+1];
	uint32 length;

	if ( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapreg_table)
	  || SQL_ERROR == SqlStmt_Execute(stmt)
	  ) {
		SqlStmt_ShowDebug(stmt);
		SqlStmt_Free(stmt);
		return;
	}

	SqlStmt_BindColumn(stmt, 0, SQLDT_STRING, &varname[0], sizeof(varname), &length, NULL);
	SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &index, 0, NULL, NULL);
	SqlStmt_BindColumn(stmt, 2, SQLDT_STRING, &value[0], sizeof(value), NULL, NULL);
	
	while ( SQL_SUCCESS == SqlStmt_NextRow(stmt) )
	{
		int s = add_str(varname);
		int i = index;

		if( varname[length-1] == '$' )
			idb_put(mapregstr_db, (i<<24)|s, aStrdup(value));
		else
		{
			idb_put(mapreg_db, (i<<24)|s, (void *)atoi(value));
			if( !strcmp(varname, "$Region") && i > 0 && i < MAX_REGIONS )
				region[i].guild_id = atoi(value); // Regional Control
		}
	}
	
	SqlStmt_Free(stmt);

	mapreg_dirty = false;
}
static void add_m_form(uint32_t instr, const char * mnemonic) {
    add_str(mnemonic);
    if (bits_uint8(instr, 31, 1)) add_char('.');
    add_str(" r");
    add_dec_uint8(bits_uint8(instr, 11, 5));
    add_str(", r");
    add_dec_uint8(bits_uint8(instr, 6, 5));
    add_str(", ");
    add_dec_uint8(bits_uint8(instr, 16, 5));
    add_str(", ");
    add_dec_uint8(bits_uint8(instr, 21, 5));
    add_str(", ");
    add_dec_uint8(bits_uint8(instr, 26, 5));
}
Exemple #29
0
static int		init_with_rest(char **line, char **rest)
{
	char	*del;

	if (*rest && ft_strchr(*rest, '\n'))
	{
		add_str(line, *rest);
		del = *rest;
		*rest = set_rest(del);
		free(del);
		return (1);
	}
	else if (*rest && !ft_strchr(*rest, '\n'))
	{
		*line = ft_strdup(*rest);
		free(*rest);
		*rest = NULL;
	}
	return (0);
}
Exemple #30
0
char		*get_command(void)
{
	char	buff[BUFF_SIZE + 1];
	char	*line;
	int		ret;
	char	*ptr;

	line = NULL;
	ptr = NULL;
	while ((ret = read(0, buff, BUFF_SIZE)))
	{
		buff[ret] = '\0';
		line = add_str(buff, line);
		if ((ptr = ft_strchr(line, '\n')))
		{
			*ptr = '\0';
			return (line);
		}
	}
	return (NULL);
}