コード例 #1
0
      /// <summary>Writes a Backup file</summary>
      /// <param name="f">The file</param>
      /// <exception cref="Logic::ComException">COM Error</exception>
      /// <exception cref="Logic::IOException">An I/O error occurred</exception>
      void  BackupFileWriter::WriteFile(const BackupFile& f)
      {
         // Header
         WriteInstruction(L"version='1.0' encoding='UTF-8'");
         WriteComment(L"Written by X-Studio II");

         // Root: File type
         auto root = WriteRoot(L"backups");
         WriteAttribute(root, L"type", GetString(f.Type));

         // Write revision (newest -> oldest)
         for (auto& rev : f.Revisions)
            WriteRevision(rev, root);
      }
コード例 #2
0
// --------------------------------------------------------------------------------
//	Writes the code out for a given symbol.
// --------------------------------------------------------------------------------
void CodeGenerator::WriteSymbolCode(Symbol* symbol)
{
	if (symbol->GeneratedSymbolCode == false)
	{
		symbol->GeneratedSymbolCode = true;

		switch (symbol->GetSymbolType())
		{
			// Emit code for a function.
			case ST_FUNCTION:
			{
				if (((FunctionSymbol*)symbol)->IsExtern == false)
				{
					WriteLine(symbol->UniqueASMName + ":");

					for (int i = 0; i < (int)symbol->Instructions.size(); i++)
						WriteInstruction(symbol->Instructions.at(i));

					WriteLine("");
				}
				break;
			}

			// Emit the definition code for a class.
			case ST_CLASS:
			{
				// No code.
				break;
			}
		
			// Emit data for a string.
			case ST_STRING:
			{
				// No code.
				break;
			}
		
			// Emit code for a variable.
			case ST_VARIABLE:
			{
				// Variable symbols have no code.
				break;
			}
		}
	}

	// Emit all sub symbols.
	for (int i = 0; i < (int)symbol->Children.size(); i++)
		WriteSymbolCode(symbol->Children.at(i));
}
コード例 #3
0
ファイル: disasm3.cpp プロジェクト: godthem90/Mac_Security_S4
int CDisassembler::GetBlockAssembly( uint32_t blocki, vector<Instruction> *insns, uint64_t *start_addr, uint64_t *end_addr )
{
	int opnum = 0;

	Section = BlockList[blocki].Section;
	Buffer     = Sections[Section].Start;
	SectionEnd = Sections[Section].TotalSize;
	LabelInaccessible = Sections[Section].InitSize;
	WordSize   = Sections[Section].WordSize;
	SectionAddress = Sections[Section].SectionAddress;
	IBegin = IEnd = LabelEnd = BlockList[blocki].Start;

	//CodeMode = (SectionType & 1) ? 1 : 4;
	CodeMode = 1;

	*start_addr = SectionAddress + IBegin;
	while( IEnd < BlockList[blocki].End )
	{
		CTextFileBuffer temp_file;
		Instruction insn;
		uint32_t opcode = 0;

		s.Reset();
		ParseInstruction();
		s.AddressRelocation = 0;
		s.ImmediateRelocation = 0;
		WriteInstruction( &temp_file, 0 );

		for(int i = 0; i <= s.OpcodeStart2 - s.OpcodeStart1; i++)
		{
			opcode = opcode << 8;
			opcode += Buffer[s.OpcodeStart1 + i];
		}
		for(int i = 0; i < IEnd - IBegin; i++)
			insn.PushBinary(Buffer[IBegin + i]);
		insn.SetOpcode( opcode );
		insn.SetAddr( SectionAddress + IBegin );
		insn.SetInstruction( temp_file.Buf() );
		insns->push_back( insn );

		IBegin = IEnd;
		opnum++;
	}
	*end_addr = SectionAddress + IEnd;
	return opnum;
}
コード例 #4
0
ファイル: main.c プロジェクト: junstrix/car
void main(void)
{
	motor_fan_con(0);
	buzzer_led(0);
	init_sys();
	LcdInitiate();         //调用LCD初始化函数  
	Delay1ms(2);
	WriteInstruction(0x01);//清显示:清屏幕指令
	DisMenuInit();
	mo_forword_slow(); //调用慢速档
	while(!CarTurnLeft) { //AB段行驶
		if (DeviateLeftTrack) {
			mo_R_forword_slow();
		}
		if(DeviateRightTrack) {
			mo_L_forword_slow();
		}
		if (CHECK_COIN) { //检测硬币
			Delay1ms(5);
			if (CHECK_COIN) {
				mo_stop();
				buzzer_led(1);
				Delay1ms(500);
				mo_forword_slow();
				buzzer_led(0);
				Delay1ms(130);      //不能太小,不能太大,太小会冲出跑道,小了会多次检测!
				if (!CHECK_COIN) {
					count_coin++;
				}
			}
		}
		if (count_kk>=50&&count_kk<51) { //变量显示稳定控制
			ClearVarData();
			WriteVarData(0x05,mo_time);
			WriteVarData(0x0d,total_length);
			WriteVarData(0x45,count_coin);
			WriteVarData(0x4d,count_bottle);
		}
	}
	while(1){
		if (DeviateLeftTrack) {
			mo_R_forword();
		}
		if(DeviateRightTrack)	
		{
			mo_L_forword();
		}
		/*转角声控报警之奇淫巧技*/
		if((total_length >= 80 && total_length <= 110) ||\
				(total_length >= 190 && total_length <= 230) ||\
				(total_length >= 300 && total_length <= 360)){
			if(CarTurnLeft){
				mo_left();
				buzzer_led(1);
				Delay1ms(20);
				buzzer_led(0);
			}
			if (CarTurnRight) {
				mo_right();
				buzzer_led(1);
				Delay1ms(20);
				buzzer_led(0);
			}
		}
		else {
			if(CarTurnLeft){
				mo_left();
				Delay1ms(20);
				buzzer_led(0);
			}
			if (CarTurnRight) {
				mo_right();
				Delay1ms(20);
				buzzer_led(0);
			}
		}
		if (UpBottle) { //瓶子检测
			motor_fan_con(0);
			buzzer_led(1);
			Delay1ms(200);
			buzzer_led(0);
			if (NoBottle) {
				count_bottle++;
			}
		}
		if (DownBottle) {
			Delay1ms(2);
			if (DownBottle) {
				mo_stop();
				motor_fan_con(1);
				Delay1ms(250);
				mo_forword();
				motor_fan_con(0);
			}
			if (NoBottle) {
				count_bottle++;
				motor_fan_con(0);
			}
		}
		if (total_length>=430||mo_time>=90) { //终点
			mo_stop();
			Delay1ms(20);
			ClearVarData();
			WriteVarData(0x05,mo_time);
			WriteVarData(0x0d,total_length);
			WriteVarData(0x45,count_coin);
			WriteVarData(0x4d,count_bottle);
			EA = 0;
			while (1) {
				mo_stop();
			}
		}
		if (count_kk>=50&&count_kk<51) { //变量显示稳定控制
			ClearVarData();
			WriteVarData(0x05,mo_time);
			WriteVarData(0x0d,total_length);
			WriteVarData(0x45,count_coin);
			WriteVarData(0x4d,count_bottle);
		}
	}
}
コード例 #5
0
void CArmInstruction::Encode()
{
	unsigned int encoding = Vars.Opcode.UseNewEncoding == true ? Vars.Opcode.NewEncoding : Opcode.encoding;

	if ((Opcode.flags & ARM_UNCOND) == 0) encoding |= Vars.Opcode.c << 28;
	if (Vars.Opcode.s == true) encoding |= (1 << 20);

	if (Vars.Shift.UseFinal == true)
	{
		Vars.Shift.Type = Vars.Shift.FinalType;
		Vars.Shift.ShiftAmount = Vars.Shift.FinalShiftAmount;
	}


	switch (Vars.Opcode.UseNewType == true ? Vars.Opcode.NewType : Opcode.type)
	{
	case ARM_TYPE3:		// ARM.3: Branch and Exchange (BX, BLX)
		encoding |= (Vars.rn.Number << 0);
		break;
	case ARM_TYPE4:		// ARM.4: Branch and Branch with Link (B, BL, BLX)
		if ((Opcode.flags & ARM_HALFWORD) && (Vars.Immediate & 2)) encoding |= 1 << 24;
		encoding |= (Vars.Immediate >> 2) & 0xFFFFFF;
		break;
	case ARM_TYPE5:		// ARM.5: Data Processing
		if (Opcode.flags & ARM_N) encoding |= (Vars.rn.Number << 16);
		if (Opcode.flags & ARM_D) encoding |= (Vars.rd.Number << 12);

		if (Opcode.flags & ARM_IMMEDIATE)	// immediate als op2
		{
			encoding |= (Vars.Shift.ShiftAmount << 7);
			encoding |= Vars.Immediate;
		} else if (Opcode.flags & ARM_REGISTER) {	// shifted register als op2
			if (Vars.Shift.UseShift == true)
			{
				if (Vars.Shift.ShiftByRegister == true)
				{
					encoding |= (Vars.Shift.reg.Number << 8);
					encoding |= (1 << 4);
				} else {	// shiftbyimmediate
					encoding |= (Vars.Shift.ShiftAmount << 7);
				}
				encoding |= (Vars.Shift.Type << 5);
			}
			encoding |= (Vars.rm.Number << 0);
		}
		break;
	case ARM_TYPE6:		// ARM.6: PSR Transfer (MRS, MSR)
		if (Opcode.flags & ARM_MRS) //  MRS{cond} Rd,Psr          ;Rd = Psr
		{
			if (Vars.PsrData.spsr == true) encoding |= (1 << 22);
			encoding |= (Vars.rd.Number << 12);
		} else {					//  MSR{cond} Psr{_field},Op  ;Psr[field] = Op
			if (Vars.PsrData.spsr == true) encoding |= (1 << 22);
			encoding |= (Vars.PsrData.field << 16);

			if (Opcode.flags & ARM_REGISTER)
			{
				encoding |= (Vars.rm.Number << 0);
			} else if (Opcode.flags & ARM_IMMEDIATE)
			{
				encoding |= (Vars.Shift.ShiftAmount << 7);
				encoding |= Vars.Immediate;
			}
		}
		break;
	case ARM_TYPE7:		// ARM.7: Multiply and Multiply-Accumulate (MUL,MLA)
		encoding |= (Vars.rd.Number << 16);
		if (Opcode.flags & ARM_N) encoding |= (Vars.rn.Number << 12);
		encoding |= (Vars.rs.Number << 8);
		if ((Opcode.flags & ARM_Y) && Vars.Opcode.y == true) encoding |= (1 << 6);
		if ((Opcode.flags & ARM_X) && Vars.Opcode.x == true) encoding |= (1 << 5);
		encoding |= (Vars.rm.Number << 0);
		break;
	case ARM_TYPE9:		// ARM.9: Single Data Transfer (LDR, STR, PLD)
		if (Vars.writeback == true) encoding |= (1 << 21);
		if (Opcode.flags & ARM_N) encoding |= (Vars.rn.Number << 16);
		if (Opcode.flags & ARM_D) encoding |= (Vars.rd.Number << 12);
		if ((Opcode.flags & ARM_SIGN) && Vars.SignPlus == false) encoding &= ~(1 << 23);
		if ((Opcode.flags & ARM_ABS) && Vars.negative == true) encoding &= ~(1 << 23);
		if (Opcode.flags & ARM_IMMEDIATE)
		{
			if (Vars.Immediate < 0)
			{
				encoding &= ~(1 << 23);
				Vars.Immediate = abs(Vars.Immediate);
			}
			encoding |= (Vars.Immediate << 0);
		} else if (Opcode.flags & ARM_REGISTER)	// ... heißt der opcode nutzt shifts, mit immediates
		{
			if (Vars.Shift.UseShift == true)
			{
				encoding |= (Vars.Shift.ShiftAmount << 7);
				encoding |= (Vars.Shift.Type << 5);
			}
			encoding |= (Vars.rm.Number << 0);
		}
		break;
	case ARM_TYPE10:	// ARM.10: Halfword, Doubleword, and Signed Data Transfer
		if (Vars.writeback == true) encoding |= (1 << 21);
		encoding |= (Vars.rn.Number << 16);
		encoding |= (Vars.rd.Number << 12);
		if ((Opcode.flags & ARM_SIGN) && Vars.SignPlus == false) encoding &= ~(1 << 23);
		if ((Opcode.flags & ARM_ABS) && Vars.negative == true) encoding &= ~(1 << 23);
		if (Opcode.flags & ARM_IMMEDIATE)
		{
			if (Vars.Immediate < 0)
			{
				encoding &= ~(1 << 23);
				Vars.Immediate = abs(Vars.Immediate);
			}
			encoding |= ((Vars.Immediate & 0xF0) << 4);
			encoding |= (Vars.Immediate & 0xF);
		} else if (Opcode.flags & ARM_REGISTER)
		{
			encoding |= (Vars.rm.Number << 0);
		}
		break;
	case ARM_TYPE11:	// ARM.11: Block Data Transfer (LDM,STM)
		if (Opcode.flags & ARM_LOAD) encoding |= (LdmModes[Vars.Opcode.a] << 23);
		else if (Opcode.flags & ARM_STORE) encoding |= (StmModes[Vars.Opcode.a] << 23);
		if (Vars.psr == true) encoding |= (1 << 22);
		if (Vars.writeback == true) encoding |= (1 << 21);
		if (Opcode.flags & ARM_N) encoding |= (Vars.rn.Number << 16);
		encoding |= (Vars.rlist);
		break;
	case ARM_TYPE12:	// ARM.12: Single Data Swap (SWP)
	case ARM_MISC:		// ARM.X: Count Leading Zeros
		encoding |= (Vars.rm.Number << 0);
		encoding |= (Vars.rd.Number << 12);
		if (Opcode.flags & ARM_N) encoding |= (Vars.rn.Number << 16);
		break;
	case ARM_TYPE13:	// ARM.13: Software Interrupt (SWI,BKPT)
		if (Opcode.flags & ARM_SWI)
		{
			encoding |= Vars.Immediate;
		} else {
			encoding |= (Vars.Immediate & 0xF);
			encoding |= (Vars.Immediate >> 4) << 8;
		}
		break;
	case ARM_TYPE14:	// ARM.14: Coprocessor Data Operations (CDP)
		if (Opcode.flags & ARM_COPOP) encoding |= (Vars.CopData.Cpop << 20);
		encoding |= (Vars.CopData.cn.Number << 16);
		encoding |= (Vars.CopData.cd.Number << 12);
		encoding |= (Vars.CopData.pn.Number << 8);
		if (Opcode.flags & ARM_COPINF) encoding |= (Vars.CopData.Cpinf << 5);
		encoding |= (Vars.CopData.cm.Number << 0);
		break;
	case ARM_TYPE16:	// ARM.16: Coprocessor Register Transfers (MRC, MCR)
		if (Opcode.flags & ARM_COPOP) encoding |= (Vars.CopData.Cpop << 21);
		encoding |= (Vars.CopData.cn.Number << 16);
		encoding |= (Vars.rd.Number << 12);
		encoding |= (Vars.CopData.pn.Number << 8);
		if (Opcode.flags & ARM_COPINF) encoding |= (Vars.CopData.Cpinf << 5);
		encoding |= (Vars.CopData.cm.Number << 0);
		break;
	case ARM_TYPE17:	// ARM.X: Coprocessor Double-Register Transfer (MCRR,MRRC)
		encoding |= (Vars.rn.Number << 16);
		encoding |= (Vars.rd.Number << 12);
		encoding |= (Vars.CopData.pn.Number << 8);
		encoding |= (Vars.CopData.Cpop << 4);
		encoding |= (Vars.CopData.cm.Number << 0);
		break;
	default:
		printf("doh");
	}

	WriteInstruction(encoding);
}