Beispiel #1
0
void HIDDEN GetAddressVtableByClassname(const char *szClassName, const int iOffset, bool bCreate)
{
	void *vtable;

	if (bCreate)
	{
		edict_t *pObject = CREATE_ENTITY();

		void *addr = GetFunctionEntity(szClassName);
	
		if (addr == NULL)
		{
			//can't create object. 
			printf2(__FUNCTION__ ":: Not found export function of binaries. Presumably looks '__declspec(dllexport) void %s(entvars_t *pev)'", szClassName);
			REMOVE_ENTITY(pObject);
			return;
		}

		// call link to class GetClassPtr<BaseClass>(pev);
		reinterpret_cast<void (*)(entvars_t *)>(addr)(&pObject->v);

		vtable = *(void **)pObject->pvPrivateData;
	}
	else
	{
		VirtualTableRef *refsVtbl = GetVirtualTableRefAddr(szClassName);
		vtable = (void *)refsVtbl->originalAddress;
	}

	printf2(__FUNCTION__ "* ADDRESS VTABLE: %p | ADDRESS VIRTUAL FUNC: %p",
		OffsetToRebase((size_t)vtable),
		OffsetToRebase(*(((size_t **)&vtable)[ iOffset ])));
}
Beispiel #2
0
void GenLabel(char* Label, int Static)
{
  {
    if (OutputFormat != FormatFlat && !Static && GenExterns)
      printf2("\t.globl\t%s\n", Label);
    printf2("%s:\n", Label);
  }
}
Beispiel #3
0
STATIC
void GenLabel(char* Label, int Static)
{
  {
    if (!Static && GenExterns)
      printf2("\t.global\t_%s\n", Label);
    printf2("_%s:\n", Label);
  }
}
Beispiel #4
0
void GenPrintLabel(char* Label)
{
  {
    if (isdigit(*Label))
      printf2("$L%s", Label);
    else
      printf2("%s", Label);
  }
}
Beispiel #5
0
STATIC
void GenPrintLabel(char* Label)
{
  {
    if (isdigit(*Label))
      printf2("L%s", Label);
    else
      printf2("_%s", Label);
  }
}
Beispiel #6
0
void GenAddrData(int Size, char* Label)
{
  if (Size == 1)
    printf2("\t.byte\t");
  else if (Size == 2)
    printf2("\t.half\t");
  else if (Size == 4)
    printf2("\t.word\t");
  GenPrintLabel(Label); puts2("");
}
Beispiel #7
0
void GenIntData(int Size, int Val)
{
  Val = truncInt(Val);
  if (Size == 1)
    printf2("\t.byte\t%d\n", Val);
  else if (Size == 2)
    printf2("\t.half\t%d\n", Val);
  else if (Size == 4)
    printf2("\t.word\t%d\n", Val);
}
Beispiel #8
0
STATIC
void GenIntData(int Size, int Val)
{
  Val = truncInt(Val);
  if (Size == 1)
    printf2("\t.db\t%d\n", Val);
  else if (Size == 2)
    printf2("\t.dw\t%d\n", Val);
  else if (Size == 4)
    printf2("\t.dd\t%d\n", Val);
}
Beispiel #9
0
__MSSHELL_WRAPPER_ __WINCALL static void _MS__private __system colFileLoader(const sel_typ argc, char ** argv)
{
    char path[MAX_PATH_LENGTH];
    #ifdef WINOS
		if(isnSett(BOOLS_ITEMSSELECTBYPATH))
		{
		    const bool wHandler = windowsFileHandler(path,  "Settings Configuration (*."DEFAULT_COLORS_FILE_EXTENSION")\0*."DEFAULT_COLORS_FILE_EXTENSION"\0Text Documents (*.txt)\0*.txt\0All Files (*.*)\0*.*\0",
		                            DEFAULT_COLORS_FILE_EXTENSION, true);
		    if(wHandler)
		    {
		        _colFileLoader(path);
		        sprint("%s\nFile has been correctly loaded.\n\n", path);
		    }
		    else
		        printErr(14, "Failed to select Colors Settings File");
		}
		else
	#endif
    {
        if(argc)
        {
            if(!file_exists(argv[0]))
            {
                printErr(2, "Inserted Path:\n%s\nrefers to non-existent File", argv[0]);
                return;
            }
            strcpy(path, argv[0]);
        }
        else
        {
            bool assert;

            printf2(COLOR_CREDITS, "Enter the Path of the "DEFAULT_LAYOUT_FILE_EXTENSION" File you wish to load.\n");
            printf2(COLOR_CREDITS, "or insert %c to exit SubProgram.\n\n", SCANFEXIT_CHAR);
            PRINTL();

            while(scanf("%s", path) != 1 || path[0] == SCANFEXIT_CHAR || (assert = !file_exists(path)))
            {
                CLEARBUFFER();
                if(path[0] == SCANFEXIT_CHAR) return;
                if(assert)
                {
                    printErr(2, "Inserted Path:\n%s\nrefers to non-existent File", argv[0]);
                    return;
                }
            // mustcreatefile = true;
            }
        }
        _colFileLoader(path);
        sprint("%s\nFile has been correctly loaded.\n\n", path);
    }
    return;
}
Beispiel #10
0
STATIC
void GenAddrData(int Size, char* Label, int ofs)
{
  ofs = truncInt(ofs);
  if (Size == 1)
    printf2("\t.db\t");
  else if (Size == 2)
    printf2("\t.dw\t");
  else if (Size == 4)
    printf2("\t.dd\t");
  GenPrintLabel(Label);
  if (ofs)
    printf2(" %+d", ofs);
  puts2("");
}
Beispiel #11
0
void handle_tcp(const unsigned char *bytes, uint16_t segment_len) {
    struct tcphdr *tcp_hdr = (struct tcphdr *) bytes;
    tcp_hdr->th_sport = ntohs(tcp_hdr->th_sport);
    tcp_hdr->th_dport = ntohs(tcp_hdr->th_dport);
    printf2("TCP     %u -> %u, [", tcp_hdr->th_sport, tcp_hdr->th_dport);
    print_flags(tcp_hdr->th_flags);
    print2("], ");
    printf2("seq %u, ack %u, win %u\n", ntohl(tcp_hdr->seq), ntohl(tcp_hdr->ack_seq), ntohs(tcp_hdr->window));

    int data_offset = 4 * tcp_hdr->th_off;
    const unsigned char *end = bytes + data_offset;
    bytes += sizeof(struct tcphdr);

    while(bytes < end) {
        uint8_t kind = *bytes++;

        uint8_t len = 0;
        if(kind != 0 && kind != 1)
            len = *bytes++;

        printf3("        option %u: ", kind);
        switch(kind) {
            case 0: print3("end of options"); break;
            case 1: print3("no operation (NOP)"); break;
            case 2: printf3("MSS %u", (*(uint32_t*) bytes)); break;
            case 3: print3("window scale"); break;
            case 4: print3("SACK permited"); break;
            case 5: print3("SACK"); break;
            case 8: print3("timestamps"); break;
            default: print3("unknown"); break;
        }
        print3("\n");

        // advance by the size of the option read
        if(kind != 0 && kind != 1)
            bytes += len - 2;
    }

    if(tcp_hdr->th_sport == 80 || tcp_hdr->th_dport == 80) {
        handle_http((const char *) bytes);
    }
    else if(tcp_hdr->th_sport == 23 || tcp_hdr->th_dport == 23) {
        handle_telnet(bytes, segment_len - data_offset);
    }
    else {
        printf1("???     Unknown TCP application with ports %u -> %u\n", tcp_hdr->th_sport, tcp_hdr->th_dport);
    }
}
Beispiel #12
0
STATIC
void GenSaveRestoreRegs(int save)
{
  int rstart, rstop, rinc, r;
  int mask = GenRegsUsed;
  mask &= ~(1 << Tr32OpReg0); // not preserved
//  mask &= ~(1 << Tr32OpRegY); // TBD??? Y is preserved, right???
  mask &= ~(1 << Tr32OpRegBp); // taken care of
  mask &= ~(1 << Tr32OpRegSp); // taken care of
  mask &= ~(1 << Tr32OpRegFlags); // TBD??? flags aren't preserved, right???

  if (save)
    rstart = Tr32OpReg0, rstop = Tr32OpRegFlags, rinc = 1;
  else
    rstart = Tr32OpRegFlags, rstop = Tr32OpReg0, rinc = -1;

  for (r = rstart; r != rstop; r += rinc)
  {
    int used = (mask & (1 << r)) != 0;
    if (save || used)
    {
      int pfx = used ? ' ' : ';';
      printf2(save ? "\t%cpush\t" : "\t%cpop\t", pfx);
      GenPrintOperand(r, 0);
      GenPrintNewLine();
    }
  }
  GenRegsUsed = mask; // undo changes in GenRegsUsed by GenPrintOperand()
}
Beispiel #13
0
STATIC
void GenPrintInstr(int instr, int val)
{
  char* p = "";

  (void)val;

  switch (instr)
  {
  case Tr32InstrNop  : p = "nop"; break;

  case Tr32InstrMov  : p = "mov"; break;

  case Tr32InstrLB   : p = "loadb"; break;
  case Tr32InstrLW   : p = "loadw"; break;
  case Tr32InstrL    : p = "load"; break;
  case Tr32InstrSB   : p = "storeb"; break;
  case Tr32InstrSW   : p = "storew"; break;
  case Tr32InstrS    : p = "store"; break;

  case Tr32InstrSigxB: p = "sigxb"; break;
  case Tr32InstrSigxW: p = "sigxw"; break;

  case Tr32InstrAdd  : p = "add"; break;
  case Tr32InstrSub  : p = "sub"; break;
  case Tr32InstrRSub : p = "rsb"; break;
  case Tr32InstrAnd  : p = "and"; break;
  case Tr32InstrOr   : p = "or"; break;
  case Tr32InstrXor  : p = "xor"; break;
  case Tr32InstrNot  : p = "not"; break;
  case Tr32InstrLLS  : p = "lls"; break;
  case Tr32InstrLRS  : p = "lrs"; break;
  case Tr32InstrARS  : p = "ars"; break;
  case Tr32InstrMul  : p = "mul"; break;
  case Tr32InstrSDiv : p = "sdiv"; break;
  case Tr32InstrDiv  : p = "div"; break;

  case Tr32InstrRJmp : p = "rjmp"; break;
  case Tr32InstrRCall: p = "rcall"; break;
  case Tr32InstrCall : p = "call"; break;
  case Tr32InstrRet  : p = "ret"; break;
  case Tr32InstrPush : p = "push"; break;
  case Tr32InstrPop  : p = "pop"; break;

  case Tr32InstrIfSL   : p = "ifsl"; break;
  case Tr32InstrIfSGE  : p = "ifsge"; break;
  case Tr32InstrIfSG   : p = "ifsg"; break;
  case Tr32InstrIfSLE  : p = "ifsle"; break;
  case Tr32InstrIfL    : p = "ifl"; break;
  case Tr32InstrIfGE   : p = "ifge"; break;
  case Tr32InstrIfG    : p = "ifg"; break;
  case Tr32InstrIfLE   : p = "ifle"; break;
  case Tr32InstrIfEq   : p = "ifeq"; break;
  case Tr32InstrIfNEq  : p = "ifneq"; break;
  case Tr32InstrIfBits : p = "ifbits"; break;
  case Tr32InstrIfClear: p = "ifclear"; break;
  }

  printf2("\t%s\t", p);
}
Beispiel #14
0
void GenPreIdentAccess(int label)
{
  if (UseGp)
    return;
  printf2("\t.set\tnoat\n\tlui\t$1, %%hi(");
  GenPrintLabel(IdentTable + label);
  puts2(")");
}
Beispiel #15
0
STATIC
void GenWriteFrameSize(void)
{
  unsigned size = -CurFxnMinLocalOfs;
  int pfx = size ? ' ' : ';';
  printf2("\t%csub\t%%sp, %%sp, %10u\n", pfx, size); // 10 chars are enough for 32-bit unsigned ints
  GenSaveRestoreRegs(1);
}
Beispiel #16
0
void print_flag(const char *name) {
    if(flag_count > 0) {
        printf2(", %s", name);
    }
    else {
        print2(name);
    }
    flag_count++;
}
void Regamedll_Game_Init(void)
{
#ifdef _WIN32
	if (g_ReGameDLLRuntimeConfig.disableAllHooks)
		return;
#endif // _WIN32

	printf2("[Hooker]: The total number hooks of functions is - %d", nCountHook);
}
Beispiel #18
0
void GenJumpIfNotZero(int label)
{
#ifndef NO_ANNOTATIONS
  printf2(" # JumpIfNotZero\n");
#endif
  GenPrintInstr3Operands(MipsInstrBNE, 0,
                         MipsOpRegV0, 0,
                         MipsOpRegZero, 0,
                         MipsOpNumLabel, label);
}
Beispiel #19
0
STATIC
void GenJumpIfNotZero(int label)
{
#ifndef NO_ANNOTATIONS
  printf2(" ; JumpIfNotZero\n");
#endif
  GenPrintInstr2Operands(Tr32InstrIfBits, 0,
                         GenWreg, 0,
                         GenWreg, 0);
  GenPrintInstr1Operand(Tr32InstrRJmp, 0,
                        Tr32OpNumLabel, label);
}
Beispiel #20
0
void GenPrintInstr(int instr, int val)
{
  char* p = "";

  (void)val;

  switch (instr)
  {
  case MipsInstrNop  : p = "nop"; break;
  case MipsInstrMov  : p = "move"; break;
  case MipsInstrMfLo : p = "mflo"; break;
  case MipsInstrMfHi : p = "mfhi"; break;
//  case MipsInstrMovZ : p = "movz"; break;
//  case MipsInstrMovN : p = "movn"; break;
  case MipsInstrLA   : p = "la"; break;
  case MipsInstrLI   : p = "li"; break;
//  case MipsInstrLUI  : p = "lui"; break;
  case MipsInstrLB   : p = "lb"; break;
  case MipsInstrLBU  : p = "lbu"; break;
  case MipsInstrLH   : p = "lh"; break;
  case MipsInstrLHU  : p = "lhu"; break;
  case MipsInstrLW   : p = "lw"; break;
  case MipsInstrSB   : p = "sb"; break;
  case MipsInstrSH   : p = "sh"; break;
  case MipsInstrSW   : p = "sw"; break;
  case MipsInstrAddU : p = "addu"; break;
  case MipsInstrSubU : p = "subu"; break;
  case MipsInstrAnd  : p = "and"; break;
  case MipsInstrOr   : p = "or"; break;
  case MipsInstrXor  : p = "xor"; break;
  case MipsInstrNor  : p = "nor"; break;
  case MipsInstrSLL  : p = "sll"; break;
  case MipsInstrSRL  : p = "srl"; break;
  case MipsInstrSRA  : p = "sra"; break;
  case MipsInstrMul  : p = "mul"; break;
  case MipsInstrDiv  : p = "div"; break;
  case MipsInstrDivU : p = "divu"; break;
  case MipsInstrSLT  : p = "slt"; break;
  case MipsInstrSLTU : p = "sltu"; break;
  case MipsInstrJ    : p = "j"; break;
  case MipsInstrJAL  : p = "jal"; break;
  case MipsInstrBEQ  : p = "beq"; break;
  case MipsInstrBNE  : p = "bne"; break;
//  case MipsInstrBLTZ : p = "bltz"; break;
//  case MipsInstrBGEZ : p = "bgez"; break;
//  case MipsInstrBLEZ : p = "blez"; break;
//  case MipsInstrBGTZ : p = "bgtz"; break;
//  case MipsInstrBreak: p = "break"; break;
  }

  printf2("\t%s\t", p);
}
Beispiel #21
0
__MSSHELL_WRAPPER_ __WINCALL static void _MS__private __system execScriptFiles(const sel_typ argc, char ** argv)
{
    char path[MAX_PATH_LENGTH];
    if(argc)
    {
        if(!file_exists(argv[0]))
        {
            printErr(2, "Inserted Path:\n%s\nrefers to non-existent Scriptfile", argv[0]);
            return;
        }
        strcpy(path, argv[0]);
    }
    else
    {
        bool assert;

        printf2("Enter Path of the "DEFAULT_SCRIPTFILES_EXTENSION" you wish to load.\n");
        printf2("or insert %c to exit SubProgram.\n\n", SCANFEXIT_CHAR);
        PRINTL();

        while(scanf("%s", path) != 1 || path[0] == SCANFEXIT_CHAR || (assert = !file_exists(path)))
        {
            CLEARBUFFER();
            if(path[0] == SCANFEXIT_CHAR) return;
            if(assert)
            {
                printErr(2, "Inserted Path:\n%s\nrefers to non-existent Scriptfile", path);
                return;
            }
            // mustcreatefile = true;
        }
    }
    if(_execScriptFiles(path))
        printf2("\nScriptfile:\n%s\nhas been correctly executed.\n\n", path);
    else
        printErr(2, "An error during:\n%s\nScriptfile opening process might have occured", path);
    return;
}
Beispiel #22
0
__MSSHELL_WRAPPER_ static void _MS__private __system handleCmdLine(const sel_typ argc, char ** argv)
{
    printf2("Enter one Programs Macro-List Command.\n\n");

    char str[INFO_STRING];

    (void) gets(str);

    if(!str[0])
        return;

    dim_typ i;
    char *cmdtab[MAX_ARGS];

    for(cmdtab[0]=strtok(str,BLANK_STRING),i=0; cmdtab[i] != NULL; cmdtab[++i] = strtok(NULL, BLANK_STRING));

    _handleCmdLine(i, cmdtab);

    return;
}
Beispiel #23
0
void handle_udp(const unsigned char *bytes) {
    struct udphdr *udp_hdr = (struct udphdr *)bytes;
    u_short source = ntohs(udp_hdr->source), dest = ntohs(udp_hdr->dest);
    printf2("UDP     %u -> %u, len %u, checksum %u\n",
           source, dest, ntohs(udp_hdr->len), ntohs(udp_hdr->check));

    bytes += sizeof(struct udphdr);

    if(source == 53 || dest == 53) {
        handle_dns(bytes);
    }
    else if(source == IPPORT_BOOTPS || dest == IPPORT_BOOTPS) {
        handle_bootp(bytes);
    }
    else if(source == 137 || dest == 137) {
        print1("NETBIOS \n");
    }
    else {
        print1("???     unsupported UDP protocol\n");
    }
}
Beispiel #24
0
void GenFin(void)
{
  if (StructCpyLabel)
  {
    char s[1 + 2 + (2 + CHAR_BIT * sizeof StructCpyLabel) / 3];
    char *p = s + sizeof s;
    int lbl = LabelCnt++;

    *--p = '\0';
    p = lab2str(p, StructCpyLabel);
    *--p = '_';
    *--p = '_';

    if (OutputFormat != FormatFlat)
      puts2(CodeHeader);

    GenLabel(p, 1);

    puts2("\tmove\t$2, $6\n"
          "\tmove\t$3, $6");
    GenNumLabel(lbl);
    puts2("\tlbu\t$6, 0($5)\n"
          "\taddiu\t$5, $5, 1\n"
          "\taddiu\t$4, $4, -1\n"
          "\tsb\t$6, 0($3)\n"
          "\taddiu\t$3, $3, 1");
    printf2("\tbne\t$4, $0, "); GenPrintNumLabel(lbl);
    puts2("");
#ifndef NO_REORDER_WORKAROUND
    GenNop();
#endif
    puts2("\tj\t$31");
#ifndef NO_REORDER_WORKAROUND
    GenNop();
#endif

    if (OutputFormat != FormatFlat)
      puts2(CodeFooter);
  }
}
Beispiel #25
0
__MSSHELL_WRAPPER_ static void _MS__private __system showUsage(const sel_typ argc, char ** argv)
{
    if(argc)
    {
        const sprog * const prog = searchProgram(argv[0]);
        if(prog)
            _showUsage(prog);
        else
            printErr(1, "SubProgram inserted CmdName hasn't been found into Programs Macro-List");
        return;
    }

    printf2("\n\n*** Program MACRO-LIST ***\n");
    SHOWPAUSEMESSAGE();
    PRINTL();

    dim_typ i;

    for(i=0; i<MAX_PROGRAMMI; ++i)
    {
        _showUsage(&main_menu[i]);
        if(catchPause()) return;
    }

    for(i=0; i<MAX_ADVCALC_PROGS; ++i)
    {
        _showUsage(&adv_calc[i]);
        if(catchPause()) return;
    }

    for(i=0; i<MAX_ALGEBRA_OPERATIONS; ++i)
    {
        _showUsage(&alg_operations[i]);
        if(catchPause()) return;
    }

    return;
}
Beispiel #26
0
void GenPrintOperand(int op, int val)
{
  if (op >= MipsOpRegZero && op <= MipsOpRegRa)
  {
    printf2("$%d", op);
  }
  else if (op >= MipsOpIndRegZero && op <= MipsOpIndRegRa)
  {
    printf2("%d($%d)", truncInt(val), op - MipsOpIndRegZero);
  }
  else
  {
    switch (op)
    {
    case MipsOpConst: printf2("%d", truncInt(val)); break;
    case MipsOpLabelGpOption:
      if (UseGp)
      {
        printf2("%%gp_rel(");
        GenPrintLabel(IdentTable + val);
        printf2(")($28)");
      }
      else
      {
        printf2("%%lo(");
        GenPrintLabel(IdentTable + val);
        printf2(")($1)");
      }
      break;
    case MipsOpLabel: GenPrintLabel(IdentTable + val); break;
    case MipsOpNumLabel: GenPrintNumLabel(val); break;

    default:
      //error("WTF!\n");
      errorInternal(100);
      break;
    }
  }
}
Beispiel #27
0
STATIC
void GenPrintOperand(int op, int val)
{
  if (op >= Tr32OpReg0 && op <= Tr32OpRegFlags)
  {
    GenRegsUsed |= 1 << op;
    switch (op)
    {
    case Tr32OpRegBp:    printf2("%%bp");    break;
    case Tr32OpRegSp:    printf2("%%sp");    break;
    case Tr32OpRegY:     printf2("%%y");     break;
    case Tr32OpRegFlags: printf2("%%flags"); break;
    default:             printf2("%%r%d", op);
    }
  }
  else if (op >= Tr32OpIndReg0 && op <= Tr32OpIndRegFlags)
  {
    GenPrintOperand(op - Tr32OpIndReg0, 0);
    val = truncInt(val);
    if (val)
      printf2(", %d", val);
  }
  else
  {
    switch (op)
    {
    case Tr32OpConst: printf2("%d", truncInt(val)); break;
    case Tr32OpLabel: GenPrintLabel(IdentTable + val); break;
    case Tr32OpNumLabel: GenPrintNumLabel(val); break;

    default:
      //error("WTF!\n");
      errorInternal(100);
      break;
    }
  }
}
Beispiel #28
0
int main (int argc, char **argv)
{
	volatile int opt, i,j;
	char *device = "/dev/pccl";
	char option_chars [BUFSIZ];
	char *filename = NULL;

	int rc, fd;

#if ENABLE_NLS
#if HAVE_SETLOCALE
   setlocale (LC_ALL, "");
#endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   bindtextdomain (program_invocation_short_name, LOCALEDIR);
   textdomain (PACKAGE);
#endif

	/*
	**	build the option-char string from the option struct.
	*/

	for (i=j=0; long_options[i].name; i++)
	{
		switch (long_options[i].has_arg)
		{
			case no_argument:
				option_chars[j++] = (char) long_options[i].val;
				break;
			case required_argument:
				option_chars[j++] = (char) long_options[i].val;
				option_chars[j++] = ':';
				break;
		}
	}
	option_chars[j] = 0;

	while ((opt = getopt_long(argc,argv,option_chars,long_options,NULL)) != EOF)
	{
		switch (opt)
		{
			case OPTION_HELP:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 (_("Usage: %s [options] <filename>\n"),program_invocation_short_name);
				for (i=0; long_options[i].name; i++)
				{
					switch (long_options[i].has_arg)
					{
						case no_argument:
							printf1 ("--%s,-%c \t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
						case required_argument:
							printf1 ("--%s=x,-%c\t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
					}
				}
				exit (EXIT_SUCCESS);

			case OPTION_VERSION:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 ("%s version %s\n",program_invocation_short_name,version_text);
				exit (EXIT_SUCCESS);

			case OPTION_QUIET:
				verbose_level = 0;
				break;

			case OPTION_VERBOSE:
				verbose_level = 2;
				break;

			case OPTION_DEVICE:
				device = optarg;
				break;

			default:
				exit(1);
		}
	}

	if (optind < argc) filename = argv[optind];

	if (getenv("PSXDEV_QUIET") && (verbose_level==1)) verbose_level = 0;

	if (filename == NULL) errorf (_("input filename missing"));

	psxdev_init();

	errno = 0;
	fd = open (filename,O_RDONLY);
	if (fd != -1)
	{
		int status;
		struct stat st;
	
		errno = 0;
		status = fstat (fd,&st);
		if (status != -1)
		{
			void *bytes;
			
			if (st.st_size == 0) errorf(_("input file has zero length"));

			errno = 0;
			bytes = mmap (NULL,st.st_size,PROT_READ,MAP_PRIVATE,fd,0);
			if (((int)bytes) != -1)
			{
				int pccl = open(device,O_RDWR);
				if (pccl != -1)
				{
					u_char byte;
				
					on_exit (on_exit_handler,(void*)pccl);

					rc = ioctl (pccl,CAEIOC_WRITE_XALIST);
					if (rc == -1) ioerrorf("ioctl(CAEIOC_WRITE_XALIST)");
					
					rc = write (pccl,bytes,st.st_size);
					if (rc < 0) ioerrorf("write()");
					
					rc = ioctl (pccl,CAEIOC_SWAP_8,&byte);
					if (rc == -1) ioerrorf("ioctl(CAEIOC_SWAP_8)");

					switch (byte)
					{
						case 0x00: printf2 (_("O.K.\n")); break;
						case 0xFF: errorf (_("invalid header")); break;
						case 0xFE: errorf (_("unsupported version")); break;
						case 0xFD: errorf (_("over size")); break;
						case 0xFC: errorf (_("inconsistency checksum")); break;
						default  : errorf (_("unknown error code")); break;
					}

					rc = ioctl (pccl,CAEIOC_RESUME);
					if (rc == -1) ioerrorf("ioctl(CAEIOC_RESUME)");

					close (pccl);
				}
				else ioerrorf ("open(%s)",device);

				munmap (bytes,st.st_size);
			}
				else ioerrorf ("mmap()");
		}
		else ioerrorf ("fstat()");
		close (fd);
	}
	else ioerrorf ("open(%s)",filename);

	return EXIT_SUCCESS;
}
Beispiel #29
0
__MSSHELL_WRAPPER_ static void _MS__private __system changeColors(const sel_typ argc, char ** argv)
{
    dim_typ i, j;
    dim_typ old_col = INIT_COLOR;

    if(argc)
    {
        if(argc > 1)
        {
            ityp tmp;
            if(PARSING_SYSTEM_ALLOWED)
            {
                if((!parse(argv[0], &tmp)) || tmp != (i = (dim_typ)tmp) || i < 0 || i > MAX_COLOR_TYPES)
                {
                    printErr(1, "Inserted Value refers to a bad Color ID");
                    printUsage(&cols_manager[COLORS_CHANGE]);
                    return;
                }

                old_col = access(colors)[i];

                if((!parse(argv[1], &tmp)) || tmp != (j = (dim_typ)tmp) || j < 0 || j > MAX_COLORS)
                {
                    printErr(1, "Inserted Value refers to a bad Color ID");
                    printUsage(&cols_manager[COLORS_CHANGE]);
                    return;
                }
            }
            else
            {
                if((tmp = strtod(argv[0], NULL)) != (i = (dim_typ)tmp) || (tmp = strtod(argv[1], NULL)) != (j = (dim_typ)tmp) || i < 0 || j < 0 || i > MAX_COLOR_TYPES || j > MAX_COLORS)
                {
                    printErr(1, "Inserted Value refers to a bad Color ID");
                    printUsage(&change_settings[COLORS_CHANGE]);
                    return;
                }
            }
        }
        else
        {
            printUsage(&change_settings[COLORS_CHANGE]);
            return;
        }
    }
    else
    {
        if((i = selectListItem(MAX_COLOR_TYPES, MAX_COLOR_TYPES > MAX_CASEINSENSITIVE_CHARS_ALPHABET,
            "Select the Color Type you wish to change", suite_c.colors_types_names)) == MAX_COLOR_TYPES) return;

        old_col = access(colors)[i];

        if((j = selectListItem(MAX_COLORS, MAX_COLORS > MAX_CASEINSENSITIVE_CHARS_ALPHABET,
            "Select the Color to set to the Color Type you've selected to change", suite_c.colors_names)) == MAX_COLORS) return;

    }

    access(colors)[i] = j;
    printf2(COLOR_USER, "%s has been correctly changed from: %s to: %s.\n\n", suite_c.colors_types_names[i], suite_c.colors_names[old_col], suite_c.colors_names[j]);
    return;

}
Beispiel #30
0
__MSSHELL_WRAPPER_ static void _MS__private __system backupColFile(const sel_typ argc, char ** argv)
{
    _backupColFile();
    printf2(COLOR_USER, "%s\nColors Settings File has been correctly saved.\n\n", access(colors_path));
    return;
}