コード例 #1
0
ファイル: Jcc.cpp プロジェクト: rdnelson/Libra
Instruction* Jcc::CreateInstruction(unsigned char* memLoc, Processor* proc) {
	unsigned char* opLoc = memLoc;
	char buf[65];
	std::string inst;

	Prefix* pre = Prefix::GetPrefix(memLoc);
	unsigned int preSize = 0;
	unsigned int opcodeOffset = 0;

	Instruction* newJcc = 0;

	if(pre) {
		opLoc += preSize = pre->GetLength();
	}

	unsigned int val = (int)*(opLoc + 1);
	if(*opLoc == TWO_BYTE_OPCODE) {
		preSize++;
		opLoc++;
		opcodeOffset = TWO_BYTE_OFFSET;
		val = (int)*(opLoc + 1) + ((int)*(opLoc + 2) << 8);
	}

	Operand* src = 0;

	switch(*opLoc - opcodeOffset) {

		case JA:
		case JAE:
		case JB:
		case JBE:
		case JCXZ:
		case JE:
		case JG:
		case JGE:
		case JL:
		case JLE:
		case JNE:
		case JNO:
		case JNP:
		case JNS:
		case JO:
		case JP:
		case JS:

			GETINST(preSize + 1 + (opcodeOffset == TWO_BYTE_OFFSET ? 2 : 1));
			src = new ImmediateOperand(val, opcodeOffset == TWO_BYTE_OFFSET ? 2 : 1);
			snprintf(buf, 65, "%s %s", _GetStr(*opLoc - opcodeOffset), src->GetDisasm().c_str());
			newJcc = new Jcc(pre, buf, inst, (unsigned char)*opLoc - opcodeOffset);
			newJcc->SetOperand(Operand::SRC, src);
			break;

		default:
			break;

	}

	return newJcc;
}
コード例 #2
0
ファイル: Main.cpp プロジェクト: vvolis/MarkovWriter
void AddEntry(Prefix& prefix, const string& suffix)
{
	if (prefix.size() == PREFIX_LENGTH) {
		dictionary[prefix].push_back(suffix);
		prefix.pop_front();
	}
	prefix.push_back(suffix);
}
コード例 #3
0
// add: add word to suffix list, update prefix
void add(Prefix& prefix, const string& s)
{
	if (prefix.size() == NPREF) {
		statetab[prefix].push_back(s);
		prefix.pop_front();
	}
	prefix.push_back(s);
}
コード例 #4
0
ファイル: component.hpp プロジェクト: ebott/boneyard
 void add(Prefix& prefix, string& new_word)
 {
      if(prefix.size() == prefix_len_)
      {
          state_list[prefix].push_back(new_word);
          prefix.pop_front();
      } 
      prefix.push_back(new_word);
 }
コード例 #5
0
ファイル: In.cpp プロジェクト: DarrenStahl/Libra
Instruction* In::CreateInstruction(Memory::MemoryOffset& memLoc, Processor* proc) {
	Memory::MemoryOffset opLoc = memLoc;
	char buf[65];
	std::string inst;

	Prefix* pre = Prefix::GetPrefix(memLoc);
	unsigned int preSize = 0;
	Instruction* newIn = 0;

	if(pre) {
		opLoc += preSize = pre->GetLength();
	}

	switch(*opLoc) {
		case IN_AL_IMM8:
		case IN_AX_IMM8:
		{
			eRegisters reg = *opLoc == IN_AL_IMM8 ? REG_AL : REG_AX;
			Operand* src = new ImmediateOperand(*(opLoc + 1), 1, (opLoc + 1).getOffset());
			Operand* dst = new RegisterOperand(reg, proc);
			GETINST(preSize + 2);
			snprintf(buf, 65, "IN %s, %s",reg == REG_AX ? "AX" : "AL", src->GetDisasm().c_str());

			newIn = new In(pre, buf, inst, (int)*opLoc);
			newIn->SetOperand(Operand::SRC, src);
			newIn->SetOperand(Operand::DST, dst);
			break;
		}
		case IN_AL_DX:
		case IN_AX_DX:
		{
			eRegisters reg = *opLoc == IN_AL_DX ? REG_AL : REG_AX;
			Operand* src = new RegisterOperand(REG_DX, proc);
			Operand* dst = new RegisterOperand(reg, proc);
			GETINST(preSize + 1);
			snprintf(buf, 65, "IN %s, DX", reg == REG_AX ? "AX" : "AL");
			newIn = new In(pre, buf, inst, (int)*opLoc);
			newIn->SetOperand(Operand::SRC, src);
			newIn->SetOperand(Operand::DST, dst);
			break;
		}
	}

	return newIn;

}
コード例 #6
0
ファイル: Out.cpp プロジェクト: rdnelson/Libra
Instruction* Out::CreateInstruction(unsigned char* memLoc, Processor* proc) {
	unsigned char* opLoc = memLoc;
	char buf[65];
	std::string inst;

	Prefix* pre = Prefix::GetPrefix(memLoc);
	unsigned int preSize = 0;
	Instruction* newOut = 0;

	if(pre) {
		opLoc += preSize = pre->GetLength();
	}

	switch(*opLoc) {
		case OUT_IMM8_AL:
		case OUT_IMM8_AX:
		{
			eRegisters reg = *opLoc == OUT_IMM8_AL ? REG_AL : REG_AX;
			Operand* dst = new ImmediateOperand(*(opLoc + 1), 1);
			Operand* src = new RegisterOperand(reg, proc);
			GETINST(preSize + 2);
			snprintf(buf, 65, "OUT %s, %s", dst->GetDisasm().c_str(), reg == REG_AX ? "AX" : "AL");

			newOut = new Out(pre, buf, inst, (int)*opLoc);
			newOut->SetOperand(Operand::SRC, src);
			newOut->SetOperand(Operand::DST, dst);
			break;
		}
		case OUT_DX_AL:
		case OUT_DX_AX:
		{
			eRegisters reg = *opLoc == OUT_DX_AL ? REG_AL : REG_AX;
			Operand* dst = new RegisterOperand(REG_DX, proc);
			Operand* src = new RegisterOperand(reg, proc);
			GETINST(preSize + 1);
			snprintf(buf, 65, "OUT DX, %s", reg == REG_AX ? "AX" : "AL");
			newOut = new Out(pre, buf, inst, (int)*opLoc);
			newOut->SetOperand(Operand::SRC, src);
			newOut->SetOperand(Operand::DST, dst);
			break;
		}
	}

	return newOut;

}
コード例 #7
0
// generate: produce output, one word per line
void generate(int nwords)
{
	Prefix prefix;
	int i;

	for (i = 0; i < NPREF; i++)
		add(prefix, NONWORD);
	for (i = 0; i < nwords; i++) {
		vector<string>& suf = statetab[prefix];
		const string& w = suf[rand() % suf.size()];
		if (w == NONWORD)
			break;
		cout << w << "\n";
		prefix.pop_front();	// advance
		prefix.push_back(w);
	}
}
コード例 #8
0
ファイル: gamedialog.cpp プロジェクト: Zhbert/winegame
GameDialog::GameDialog(QWidget *parent, QString path, corelib *lib) :
    QDialog(parent),
    ui(new Ui::GameDialog),
    _path (path)
{
	Prefix *prefix = new Prefix (this, path, lib);
    ui->setupUi(this);
    //setting the UI
    if (qApp->arguments().length() > 1)
		  ui->lblIcon->setPixmap(QPixmap(path + "/icon"));
	else
	   ui->lblIcon->setPixmap(getIcoFromDisc());

    ui->lblIcon->setText("");
    ui->lblName->setText(tr("A Microsoft Windows(r) application is found on this disc. <br><br><b>%1</b><br><br> Would you like to install it? ").arg(prefix->name()));
    ui->lblDesc->setText(prefix->note());

}
コード例 #9
0
ファイル: Cwd.cpp プロジェクト: DarrenStahl/Libra
Instruction* Cwd::CreateInstruction(Memory::MemoryOffset& memLoc, Processor*) {
    Memory::MemoryOffset opLoc = memLoc;
    char buf[65];
    std::string inst;

    Prefix* pre = Prefix::GetPrefix(memLoc);
    unsigned int preSize = 0;

    if(pre) {
        opLoc += preSize = pre->GetLength();
    }

    if(*opLoc == CWD) {
        snprintf(buf, 65, "CWD");
        GETINST(preSize + 1);
        return new Cwd(pre, buf, inst, (int)*opLoc);
    }
    return 0;
}
コード例 #10
0
ファイル: TestCaching.cpp プロジェクト: luke-chang/gecko-1
static void
SetupCacheEntry(LookupCacheV4* aLookupCache,
                const nsCString& aCompletion,
                bool aNegExpired = false,
                bool aPosExpired = false)
{
  FullHashResponseMap map;

  Prefix prefix;
  prefix.FromPlaintext(aCompletion);

  CachedFullHashResponse* response = map.LookupOrAdd(prefix.ToUint32());

  response->negativeCacheExpirySec =
    aNegExpired ? EXPIRED_TIME_SEC : NOTEXPIRED_TIME_SEC;
  response->fullHashes.Put(GeneratePrefix(aCompletion, COMPLETE_SIZE),
                           aPosExpired ? EXPIRED_TIME_SEC : NOTEXPIRED_TIME_SEC);

  aLookupCache->AddFullHashResponseToCache(map);
}
コード例 #11
0
ファイル: component.hpp プロジェクト: ebott/boneyard
   void generate(int ows, size_t pl)
   {
      outwords_ = ows;
      prefix_len_ = pl;
      string buff;
      Prefix prefix;
      for(size_t j=0; j < prefix_len_; ++j)
         {
            prefix.push_back("\n");
         }

      ifstream infile (filename_);

      while(!getline(infile,buff).eof())
      {
         parse_words(prefix, buff);
      }

      gen_output();
   }
コード例 #12
0
ファイル: TestCaching.cpp プロジェクト: luke-chang/gecko-1
// This testcase check if an cache entry whose negative cache time is expired
// and it doesn't have any postive cache entries in it, it should be removed
// from cache after calling |Has|.
TEST(UrlClassifierCaching, NegativeCacheExpireV2)
{
  _PrefixArray array = { GeneratePrefix(NEG_CACHE_EXPIRED_URL, 8) };
  UniquePtr<LookupCacheV2> cache = SetupLookupCache<LookupCacheV2>(array);

  nsCOMPtr<nsICryptoHash> cryptoHash = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID);

  MissPrefixArray misses;
  Prefix* prefix = misses.AppendElement(fallible);
  prefix->FromPlaintext(NEG_CACHE_EXPIRED_URL);

  AddCompleteArray dummy;
  cache->AddGethashResultToCache(dummy, misses, EXPIRED_TIME_SEC);

  // Ensure it is in cache in the first place.
  EXPECT_EQ(cache->IsInCache(prefix->ToUint32()), true);

  // It should be removed after calling Has API.
  TestCache<LookupCacheV2>(NEG_CACHE_EXPIRED_URL, true, false, false, cache.get());
}
コード例 #13
0
ファイル: Main.cpp プロジェクト: vvolis/MarkovWriter
void GenerateText(int wordCount, ofstream& outFile)
{
	Prefix prefix;
	int i;
	for (i = 0; i < PREFIX_LENGTH; i++){
		AddEntry(prefix, NONWORD);
	}
		
	for (i = 0; i < wordCount; i++) {
		vector<string>& suffix = dictionary[prefix]; 
		const string& word = suffix[rand() % suffix.size()];
		if (word == NONWORD){
			break;
		}
			
		outFile << word << " ";
		//shift the prefix by a word, to keep generating.
		prefix.pop_front();
		prefix.push_back(word);
	}
}
コード例 #14
0
ファイル: TestCaching.cpp プロジェクト: luke-chang/gecko-1
TEST(UrlClassifierCaching, NegativeCacheExpireV4)
{
  _PrefixArray array = { GeneratePrefix(NEG_CACHE_EXPIRED_URL, 8) };
  UniquePtr<LookupCacheV4> cache = SetupLookupCache<LookupCacheV4>(array);

  FullHashResponseMap map;
  Prefix prefix;
  nsCOMPtr<nsICryptoHash> cryptoHash = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID);
  prefix.FromPlaintext(NEG_CACHE_EXPIRED_URL);
  CachedFullHashResponse* response = map.LookupOrAdd(prefix.ToUint32());

  response->negativeCacheExpirySec = EXPIRED_TIME_SEC;

  cache->AddFullHashResponseToCache(map);

  // Ensure it is in cache in the first place.
  EXPECT_EQ(cache->IsInCache(prefix.ToUint32()), true);

  // It should be removed after calling Has API.
  TestCache<LookupCacheV4>(NEG_CACHE_EXPIRED_URL, true, false, false, cache.get());
}
コード例 #15
0
ファイル: symmetryObject.cpp プロジェクト: gralm/symmetry
Prefix getPrefixFromWC(VEC coord)
{
	Prefix pfx;
	Orientation ori(SYMMETRY_HEXAGONAL);

	if (coord.y > 0)
	{
		if (!(coord * VEC(COS30, -SIN30) > 0 && coord.x>0)){
			ori.rotate(VP);
			pfx.rotate(VP);
		}
	} else {
		ori.rotate(VN);
		pfx.rotate(VN);
	}

	VEC vertexpoint_[3];
	double dist[3];
	vertexpoint_[0] = ori.getWCFromOC(VEC(0, 0)) - coord;
	vertexpoint_[1] = ori.getWCFromOC(VEC(COS30, -SIN30)) - coord;
	vertexpoint_[2] = ori.getWCFromOC(VEC(COS30, SIN30)) - coord;

	for (int i=0; i<3; i++)
		dist[i] = vertexpoint_[i]*vertexpoint_[i];
	

	if (dist[1] < dist[0])
		pfx.rotate((dist[2]<dist[1])? FN: FP);
	else if (dist[2] < dist[0])
		pfx.rotate(FN);


	for (int i=0; i<3; i++)
	{
		if (ori.getOCFromWC(coord).x > COS30)
			return Prefix();
	}

	return pfx;		
}
コード例 #16
0
ファイル: symmetryObject.cpp プロジェクト: gralm/symmetry
void SymmetryObject::test()
{

	Prefix diff;
	edge edgeA, edgeB;

	/*edgeA.fr.index = 0;
	edgeA.fr.Pfx;
	edgeA.to.index = FACE_CENTERED;
	edgeA.to.Pfx.rotate(FN);

	edgeB.fr.index = FACE_CENTERED;
	edgeB.fr.Pfx.rotate(FN);
	edgeB.to.index = 0;
	edgeB.to.Pfx.rotate(FN);*/

	
	edgeA.fr.index = 0;
	//edgeA.fr.Pfx;
	edgeA.to.index = 0;
	edgeA.to.Pfx.rotate(FN);
	edgeA.to.Pfx.rotate(VN);


	cout << "edgeA: ";
	 edgeA.print();
	 cout << endl;
	//cout << "edgeB: " << edgeB.toString() << endl;

	if (edgeA.isOppositeOf(edgeA, &diff))
	{
		cout << "is opposite: ";
		diff.print();
		cout << endl;
	} else {
		cout << "not opposite" << endl;
	}
}
コード例 #17
0
ファイル: Aas.cpp プロジェクト: rdnelson/Libra
Instruction* Aas::CreateInstruction(unsigned char* memLoc, Processor* proc) {
	unsigned char* opLoc = memLoc;
	char buf[65];
	std::string inst;

	Prefix* pre = Prefix::GetPrefix(memLoc);
	unsigned int preSize = 0;
	Instruction* newAas = 0;

	if(pre) {
		opLoc += preSize = pre->GetLength();
	}

	if(*opLoc == AAS) {

		GETINST(preSize + 1);
		snprintf(buf, 65, "AAS");

		newAas = new Aas(pre, buf, inst, (int)*opLoc);
	}

	return newAas;

}
コード例 #18
0
ファイル: Aaa.cpp プロジェクト: DarrenStahl/Libra
Instruction* Aaa::CreateInstruction(Memory::MemoryOffset& memLoc, Processor*) {
	Memory::MemoryOffset opLoc = memLoc;
	char buf[65];
	std::string inst;

	Prefix* pre = Prefix::GetPrefix(memLoc);
	unsigned int preSize = 0;
	Instruction* newAaa = 0;

	if(pre) {
		opLoc += preSize = pre->GetLength();
	}

	if(*opLoc == AAA) {

		GETINST(preSize + 1);
		snprintf(buf, 65, "AAA");

		newAaa = new Aaa(pre, buf, inst, (int)*opLoc);
	}

	return newAaa;

}
コード例 #19
0
ファイル: others.cpp プロジェクト: gralm/symmetry
	// returns true if e is opposite edge. If pfx != null, pfx
bool edge::isOppositeOf(const edge &e, Prefix *pfx)
{
		// avsluta om inte ens punkterna stämmer
	if (fr.index != e.to.index || to.index != e.fr.index)
		return false;

	Prefix X;

		//
	cout << " ** drive isOppositeOf" << endl;
	cout << "this: " << endl;
	this->print();
	cout << endl << "edge e: " << endl;
	e.print();


	switch(fr.index)
	{
		case VERTEX_CENTERED: {
			cout << "a" << endl;

				// fr = X e.to
			X = fr.Pfx;
			X.rotate(e.to.Pfx.getInverse());
			Point e_fr(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [VP] = X e.to
			X = fr.Pfx;
			X.rotate(VP);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [VN] = X e.to
			X = fr.Pfx;
			X.rotate(VN);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

			cout << "a" << endl;
			break;
		}
		case EDGE_CENTERED: {
			cout << "b" << endl;

			X = fr.Pfx;
			X.rotate(e.to.Pfx.getInverse());
			Point e_fr(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [VP] = X e.to
			X = fr.Pfx;
			X.rotate(VP);
			X.rotate(FP);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

			break;
		}
		case FACE_CENTERED: {
			cout << "c" << endl;

				// fr = X e.to
			X = fr.Pfx;
			X.rotate(e.to.Pfx.getInverse());
			Point e_fr(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [FP] = X e.to
			X = fr.Pfx;
			X.rotate(FP);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [FN] = X e.to
			X = fr.Pfx;
			X.rotate(FN);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

			cout << "c" << endl;
			break;
		}
		default: {

			cout << "D" << endl;
			X = fr.Pfx;
			X.rotate(e.to.Pfx.getInverse());
			Point e_fr(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}
			cout << "D" << endl;
			break;
		}
	}


	//pfx->R.clear();
	return false;
}
コード例 #20
0
ファイル: point.cpp プロジェクト: gralm/symmetry
bool Point::equalTo(Point &A) {
	Prefix subPfx = Pfx.difference(A.Pfx);
	bool keepTrying = (index<-1);
	subPfx.simplify();

	//cout << endl << "subPfx before: ";
	//subPfx.print();
	//cout << endl;


	//for (list<TYP>::reverse_iterator rit = R.rbegin(); rit != R.rend(); rit++)
		//toReturn.R.push_back(INV_ROTATION(*rit));

	int previousEcTYP = 0;
	int k = 0;

	keepTrying = true;
	for (list<TYP>::reverse_iterator ritR = subPfx.R.rbegin(); keepTrying && ritR != subPfx.R.rend();)
	{
		k++;
		//cout << "now is ritR = ";
		//rotationPrint(*ritR);
		//cout << endl;

		if (index == VERTEX_CENTERED && (*ritR == VN || *ritR == VP)) {
			//cout << "VC" << endl;
			/*subPfx.R.erase(--(ritR.base()));
			ritR = subPfx.R.rbegin();*/
			ritR = list<TYP>::reverse_iterator(subPfx.R.erase(--(ritR.base())));
			//cout << "ritR efter erase: ";
			//rotationPrint(*ritR);
			//cout << endl;
		} else if (index == FACE_CENTERED && (*ritR == FN || *ritR == FP)) {
			//cout << "FC" << endl;
			ritR = list<TYP>::reverse_iterator(subPfx.R.erase(--(ritR.base())));
			//cout << "ritR efter erase: ";
			//rotationPrint(*ritR);
		} else if (index == EDGE_CENTERED) {
			//TYP ritRold = *ritR;
			if ((previousEcTYP == FP && *ritR == VP) || (previousEcTYP == VN && *ritR == FN)) {
				//cout << "ECa" << endl;
				subPfx.R.pop_back();
				subPfx.R.pop_back();
				ritR = subPfx.R.rbegin();
				//ritR = list<TYP>::reverse_iterator(subPfx.R.erase(--(ritR.base())));
				//ritR = list<TYP>::reverse_iterator(subPfx.R.erase(--(ritR.base())));
				previousEcTYP = 0;
			} else if ((previousEcTYP == VN && *ritR == FP) || (previousEcTYP == VN && *ritR == FP)){
				//cout << "ECd" << endl;
				subPfx.R.pop_back();
				subPfx.R.pop_back();
				subPfx.R.push_back(FN);
				ritR = subPfx.R.rbegin();
				subPfx.print();
				//cout << endl;
				subPfx.simplify();
				subPfx.print();
				//cout << endl;
				previousEcTYP = 0;
				//cout << endl;
			} else if (previousEcTYP == 0 && (*ritR == FP || *ritR == VN)) {
				//cout << "ECb" << endl;
				previousEcTYP = *ritR;
				ritR++;
			} else {
				//cout << "ECc" << endl;
				keepTrying = false;
			}
		} else {

			//cout << "0" << endl;
			keepTrying = false;
		}
		if (k > 10)
			break; 
	}


	//cout << endl << "subPfx efter: ";
	//subPfx.print();
	//cout << endl;

	return (subPfx.size() == 0);
}
コード例 #21
0
ファイル: VM.cpp プロジェクト: DarrenStahl/Libra
int VM::LoadVirgoFile(const char* filename) {

	mLoaded = false;
	mInstructions.clear();
	mLabels.clear();
	mMem.Clear();

	std::ifstream fin;
	fin.open(filename, std::ios_base::in);
	if(fin.fail()) {
		return VM_ERR_FOPEN;
	}

	//parse header
	int numInitArgs, numLines, addrStart, bytesTotal;
	fin >> numInitArgs;
	fin >> numLines;
	fin >> addrStart;
	fin >> bytesTotal;


	int i = 0;
	unsigned int hexSize;
	char* hex;
	char label[128];
	char disasm[256];
	unsigned int addr;
	unsigned int delay;
	char line[512];
	char text[TEXT_LEN];
	memset(line, 0, 512);
	fin.ignore(100, '\n');

	while(!fin.eof()) {
		fin.getline(line, 512);
		if(fin.eof())
			break;
		//swap all "quotation marks" with nulls
		for(char* c = line; *c != '\0'; c++)
			*c = *c == '\x001f' ? '\0' : *c;
		hex = 0;
		label[0] = '\0';
		disasm[0] = '\0';
		delay = 0;
		char* cl = line;
		cl++;

		//Parse Address
		if(strlen(cl) != 0)
			sscanf(cl, "%x", &addr);

		//Skip to next field
		cl += strlen(cl) + 2;

		//Number of bytes in hex representation
		if(strlen(cl) != 0)
			sscanf(cl, "%d", &hexSize);
		//Next Field
		cl += strlen(cl) + 2;

		//Create a buffer for the hex
		unsigned int hexArrSize = (hexSize > 1024 ? 1024 : (hexSize == 0 ? 1 : (hexSize * 2 + 1)) * sizeof(char));
		hex = new char[hexArrSize];

		//copy hex into buffer
		if(strlen(cl) != 0) {
			strncpy(hex, cl, hexArrSize);
		} else {
			hex[0] = '\0';
		}
		//Next Field
		cl += strlen(cl) + 2;

		//Copy label if it exists
		if(strlen(cl) != 0)
			strncpy(label, cl, 128);
		//next Field
		cl += strlen(cl) + 2;

		//copy disassembled version
		if(strlen(cl) != 0)
			strncpy(disasm, cl, 256);

		//next Field
		cl += strlen(cl) + 2;

		//copy delay (20)
		if(strlen(cl) != 0)
			sscanf(cl, "%d", &delay);

		//Check for invalid hex string
		if(strlen(hex) % 2 != 0 || strlen(hex) / 2 != hexSize) { //odd number of hex digits, not bytes
			delete hex;
			mLoaded = false;
			return VM_ERR_CORRUPT;
		}

		//convert ascii hex into real hex
		memset(text, 0, TEXT_LEN);
		for(size_t j = 0; j < strlen(hex); j++) {
			if(j == TEXT_LEN) {
				delete hex;
				mLoaded = false;
				return VM_ERR_OVERFLOW;
			}
			if(hex[j] >= '0' && hex[j] <= '9') {
				text[j/2] |= (hex[j] - '0') << (j % 2 == 0 ? 4 : 0);
			}else if(toupper(hex[j])  >= 'A' && toupper(hex[j]) <= 'F') {
				text[j/2] |= (hex[j] - 'A' + 10) << (j % 2 == 0 ? 4 : 0);
			}
		}


		//Try to build a prefix
		Prefix* pre = Prefix::GetPrefix((unsigned char*)text, TEXT_LEN);
		char* opLoc = text;
		if(pre) {
			opLoc += pre->GetLength();
		}

		std::string s;
		std::string dis(disasm);

		//trim whitespace from disassemblu
		dis.erase(dis.find_last_not_of(" \f\n\r\t\v") + 1);
		dis.erase(0, dis.find_first_not_of(" \f\n\r\t\v"));

		//Prefix with label
//		dis = label + ('\t' + dis);

		s.insert(0, hex);

		//clear up buffer from above
		delete hex;

		if(hexSize != 0) {
			memcpy(mMem.getPtr() + (addr % MEM_SIZE), text, hexSize);
		}

		if((dis.size() == 0 || (hexSize == 0 && label[0] == '\0')) && (strlen(label) == 0))
			continue;

		Instruction* inst = new VirgoInstruction(pre, dis, s, (int)*opLoc);
		inst->SetAddress(addr);

		mInstructions.push_back(inst);
		mLabels.push_back(label);


		if(++i >= numLines)
			break;
	}

	mLoaded = true;
	mVirgo = true;

	mProc.Initialize(addrStart);

	return VM_SUCCESS;
}
コード例 #22
0
ファイル: Mov.cpp プロジェクト: DarrenStahl/Libra
Instruction* Mov::CreateInstruction(Memory::MemoryOffset& memLoc, Processor* proc) {
	Memory::MemoryOffset opLoc = memLoc;
	char buf[65];
	std::string inst;

	Prefix* pre = Prefix::GetPrefix(memLoc);
	unsigned int preSize = 0;

	Instruction* newMov = 0;

	if(pre) {
		opLoc += preSize = pre->GetLength();
	}

	switch(*opLoc) {
		case MOV_MOD8_REG8:
		case MOV_MOD16_REG16:
		{
			unsigned int size = (*opLoc == MOV_MOD8_REG8 ? 1 : 2);
			Operand* src = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::REG, size);
			Operand* dst = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::MOD, size);

			snprintf(buf, 65, "MOV %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 2 + dst->GetBytecodeLen() + src->GetBytecodeLen());

			newMov = new Mov(pre, buf, inst, (unsigned char)*opLoc);
			newMov->SetOperand(Operand::SRC, src);
			newMov->SetOperand(Operand::DST, dst);
			break;
		}

		case MOV_REG8_MOD8:
		case MOV_REG16_MOD16:
		{
			unsigned int size = (*opLoc == MOV_REG8_MOD8 ? 1 : 2);
			Operand* src = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::MOD, size);
			Operand* dst = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::REG, size);

			snprintf(buf, 65, "MOV %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 2 + dst->GetBytecodeLen() + src->GetBytecodeLen());

			newMov = new Mov(pre, buf, inst, (unsigned char)*opLoc);
			newMov->SetOperand(Operand::SRC, src);
			newMov->SetOperand(Operand::DST, dst);
			break;
		}
		case MOV_MOD16_SEGREG:
		{
			Operand* src = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::SEGREG, 2);
			Operand* dst = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::MOD, 2);

			snprintf(buf, 65, "MOV %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 2 + dst->GetBytecodeLen() + src->GetBytecodeLen());

			newMov = new Mov(pre, buf, inst, (unsigned char)*opLoc);
			newMov->SetOperand(Operand::SRC, src);
			newMov->SetOperand(Operand::DST, dst);
			break;
		}

		case MOV_SEGREG_MOD16:
		{
			Operand* src = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::MOD, 2);
			Operand* dst = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::SEGREG, 2);

			snprintf(buf, 65, "MOV %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 2 + dst->GetBytecodeLen() + src->GetBytecodeLen());

			newMov = new Mov(pre, buf, inst, (unsigned char)*opLoc);
			newMov->SetOperand(Operand::SRC, src);
			newMov->SetOperand(Operand::DST, dst);
			break;
		}

		case MOV_AL_MOFF8:
		case MOV_AX_MOFF16:
		{
			unsigned int size = (*opLoc == MOV_AL_MOFF8 ? 1 : 2);
			Operand* dst = new RegisterOperand(*opLoc == MOV_AL_MOFF8 ? REG_AL : REG_AX, proc);

			unsigned int val = (int)*(opLoc + 1);
			val += ((int)*(opLoc + 2)) << 8;

			Memory::MemoryOffset tmpMem = opLoc.getNewOffset(val);
			Operand* src = AddressOperand::GetAddressOperand(proc, tmpMem, size);

			snprintf(buf, 65, "MOV %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 3);

			newMov = new Mov(pre, buf, inst, (unsigned char)*opLoc);
			newMov->SetOperand(Operand::SRC, src);
			newMov->SetOperand(Operand::DST, dst);
			break;
		}

		case MOV_MOFF8_AL:
		case MOV_MOFF16_AX:
		{
			unsigned int size = (*opLoc == MOV_MOFF8_AL ? 1 : 2);
			Operand* src = new RegisterOperand(*opLoc == MOV_MOFF8_AL ? REG_AL : REG_AX, proc);

			unsigned int val = (int)*(opLoc + 1);
			val += ((int)*(opLoc + 2)) << 8;

			Memory::MemoryOffset tmpMem = opLoc.getNewOffset(val);
			Operand* dst = AddressOperand::GetAddressOperand(proc, tmpMem, size);

			snprintf(buf, 65, "MOV %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 3);

			newMov = new Mov(pre, buf, inst, (unsigned char)*opLoc);
			newMov->SetOperand(Operand::SRC, src);
			newMov->SetOperand(Operand::DST, dst);
			break;
		}

		case MOV_AL_IMM8:
		case MOV_CL_IMM8:
		case MOV_DL_IMM8:
		case MOV_BL_IMM8:
		case MOV_AH_IMM8:
		case MOV_CH_IMM8:
		case MOV_DH_IMM8:
		case MOV_BH_IMM8:
		case MOV_AX_IMM16:
		case MOV_CX_IMM16:
		case MOV_DX_IMM16:
		case MOV_BX_IMM16:
		case MOV_SP_IMM16:
		case MOV_BP_IMM16:
		case MOV_SI_IMM16:
		case MOV_DI_IMM16:
		{
			unsigned int size = 0;
			Operand* dst = 0;

			if(*opLoc <= MOV_BL_IMM8) {
				//The 8 bit omes
				size = 1;
				dst = new RegisterOperand((eRegisters)(*opLoc - MOV_AL_IMM8 + REG_AL), proc);
			} else if(*opLoc <= MOV_BH_IMM8) {
				size = 1;
				dst = new RegisterOperand((eRegisters)(*opLoc - MOV_AH_IMM8 + REG_AH), proc);
			} else {
				size = 2;
				dst = new RegisterOperand((eRegisters)(*opLoc - MOV_AX_IMM16), proc);
			}

			unsigned int val = (int)*(opLoc + 1 + dst->GetBytecodeLen());
			if(size == 2) {
				val += (int)*(opLoc + 2 + dst->GetBytecodeLen()) << 8;
			}
			Operand* src = new ImmediateOperand(val, size, (opLoc + 1 + dst->GetBytecodeLen()).getOffset());
			snprintf(buf, 65, "MOV %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 1 + dst->GetBytecodeLen() + src->GetBytecodeLen());

			newMov = new Mov(pre, buf, inst, (unsigned char)*opLoc);
			newMov->SetOperand(Operand::SRC, src);
			newMov->SetOperand(Operand::DST, dst);
			break;
		}

		case MOV_MOD8_IMM8:
		case MOV_MOD16_IMM16:
		{
			unsigned int size = (*opLoc == MOV_MOD8_IMM8 ? 1 : 2);
			Operand* dst = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::MOD, size);

			unsigned int val = (int)*(opLoc + 2 + dst->GetBytecodeLen());
			if(size == 2) {
				val += (int)*(opLoc + 3 + dst->GetBytecodeLen()) << 8;
			}
			Operand* src = new ImmediateOperand(val, size, (opLoc + 2 + dst->GetBytecodeLen()).getOffset());
			snprintf(buf, 65, "MOV %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 2 + dst->GetBytecodeLen() + src->GetBytecodeLen());

			newMov = new Mov(pre, buf, inst, (unsigned char)*opLoc);
			newMov->SetOperand(Operand::SRC, src);
			newMov->SetOperand(Operand::DST, dst);
		}
		break;
	}

	return newMov;
}
コード例 #23
0
ファイル: Test.cpp プロジェクト: DarrenStahl/Libra
Instruction* Test::CreateInstruction(Memory::MemoryOffset& memLoc, Processor* proc) {
	Memory::MemoryOffset opLoc = memLoc;
	char buf[65];
	std::string inst;

	Prefix* pre = Prefix::GetPrefix(memLoc);
	unsigned int preSize = 0;
	Instruction* newTest = 0;

	if(pre) {
		opLoc += preSize = pre->GetLength();
	}

	switch(*opLoc) {
		case TEST_AL_IMM8:
		case TEST_AX_IMM16:
		{
			unsigned int size = (*opLoc == TEST_AL_IMM8 ? 1 : 2);

			unsigned int val = (int)*(opLoc + 1);
			if(size == 2) {
				val += (int)*(opLoc + 2) << 8;
			}

			GETINST(preSize + 1 + size);


			Operand* src = new ImmediateOperand(val, size, (opLoc + 1).getOffset());
			Operand* dst = new RegisterOperand(*opLoc == TEST_AL_IMM8 ? REG_AL : REG_AX, proc);

			snprintf(buf, 65, "TEST %s, %s", size == 1 ? "AL" : "AH", src->GetDisasm().c_str());
			newTest = new Test(pre, buf, inst, (unsigned char)*opLoc);
			newTest->SetOperand(Operand::SRC, src);
			newTest->SetOperand(Operand::DST, dst);
			break;
		}
		case TEST_MOD8_IMM8:
		case TEST_MOD16_IMM16:
		{
			if((unsigned int)((*(opLoc + 1) & 0x38) >> 3) != TEST_SUB_OPCODE)
				return 0;

			unsigned int size = (*opLoc == TEST_MOD8_IMM8 ? 1 : 2);

			unsigned int val = (int)*(opLoc + 1);
			if(size == 2) {
				val += (int)*(opLoc + 2) << 8;
			}


			Operand* src = new ImmediateOperand(val, size, (opLoc + 1).getOffset());
			Operand* dst = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::MOD, size);

			snprintf(buf, 65, "TEST %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 2 + size + dst->GetBytecodeLen());
			newTest = new Test(pre, buf, inst, (unsigned char)*opLoc);
			newTest->SetOperand(Operand::SRC, src);
			newTest->SetOperand(Operand::DST, dst);
			break;
		}
		case TEST_MOD8_REG8:
		case TEST_MOD16_REG16:
		{
			unsigned int size = (*opLoc == TEST_MOD8_REG8 ? 1 : 2);
			
			Operand* src = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::REG, size);
			Operand* dst = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::MOD, size);

			snprintf(buf, 65, "TEST %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			GETINST(preSize + 2 + dst->GetBytecodeLen() + src->GetBytecodeLen());
			newTest = new Test(pre, buf, inst, (unsigned char)*opLoc);
			newTest->SetOperand(Operand::SRC, src);
			newTest->SetOperand(Operand::DST, dst);
			break;
		}

	}

	return newTest;

}
コード例 #24
0
ファイル: Push.cpp プロジェクト: DarrenStahl/Libra
Instruction* Push::CreateInstruction(Memory::MemoryOffset& memLoc, Processor* proc) {

    Memory::MemoryOffset opLoc = memLoc;
    char buf[65];
    std::string inst;
    Prefix* pre = Prefix::GetPrefix(memLoc);
    unsigned int preSize = 0;
    Instruction* newPush = 0;

    if(pre) {
        opLoc += preSize = pre->GetLength();
    }

    switch(*opLoc) {
    case PUSH_MOD16:
    {
        if((unsigned int)((*(opLoc + 1) & 0x38) >> 3) != PUSH_SUB_OPCODE)
            return newPush;
        Operand* dst = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::MOD, 2);
        snprintf(buf, 65, "PUSH %s", dst->GetDisasm().c_str());
        GETINST(preSize + 2 + dst->GetBytecodeLen());
        newPush = new Push(pre, buf, inst, (unsigned char)*opLoc);
        newPush->SetOperand(Operand::DST, dst);
        break;
    }
    case PUSH_REG_AX:
    case PUSH_REG_CX:
    case PUSH_REG_DX:
    case PUSH_REG_BX:
    case PUSH_REG_SP:
    case PUSH_REG_BP:
    case PUSH_REG_SI:
    case PUSH_REG_DI:
    {
        Operand* dst = new RegisterOperand((eRegisters)(*opLoc - PUSH_REG_AX + REG_AX),
                                           proc);
        snprintf(buf, 65, "PUSH %s", dst->GetDisasm().c_str());
        GETINST(preSize + 1 + dst->GetBytecodeLen());
        newPush = new Push(pre, buf, inst, (unsigned char)*opLoc);
        newPush->SetOperand(Operand::DST, dst);
        break;
    }
    case PUSH_IMM8:
    case PUSH_IMM16:
    {
        unsigned int val = *(opLoc + 1);
        unsigned int size = *opLoc == PUSH_IMM8 ? 1 : 2;

        if(size == 2) {
            val += *(opLoc + 2) << 0x8;
        } else {
            val += (val >= 0x80) ? 0xFF00 : 0x0000;
        }

        Operand* dst = new ImmediateOperand(val, 2, (opLoc + 1).getOffset());
        snprintf(buf, 65, "PUSH %s", dst->GetDisasm().c_str());
        GETINST(preSize + 1 + size);
        newPush = new Push(pre, buf, inst, (unsigned char)*opLoc);
        newPush->SetOperand(Operand::DST, dst);
        break;
    }
    case PUSH_CS:
    case PUSH_SS:
    case PUSH_DS:
    case PUSH_ES:
    {
        eRegisters reg = REG_CS;
        if(*opLoc == PUSH_CS)
            reg = REG_CS;
        else if(*opLoc == PUSH_DS)
            reg = REG_DS;
        else if(*opLoc == PUSH_SS)
            reg = REG_SS;
        else if(*opLoc == PUSH_ES)
            reg = REG_ES;

        Operand* dst = new RegisterOperand(reg, proc);
        snprintf(buf, 65, "PUSH %s", dst->GetDisasm().c_str());
        GETINST(preSize + 1 + dst->GetBytecodeLen());
        newPush = new Push(pre, buf, inst, (unsigned char)*opLoc);
        newPush->SetOperand(Operand::DST, dst);
        break;
    }
    case PUSHF:
    {
        Operand* dst = new RegisterOperand(REG_FLAGS, proc);
        snprintf(buf, 65, "PUSHF");
        GETINST(preSize + 1);
        newPush = new Push(pre, buf, inst, (unsigned char)*opLoc);
        newPush->SetOperand(Operand::DST, dst);
        break;
    }
    case PUSHA:
    {
        snprintf(buf, 65, "PUSHA");
        GETINST(preSize + 1);
        newPush = new Push(pre, buf, inst, (unsigned char)*opLoc);
    }
    }
    return newPush;

}
コード例 #25
0
ファイル: symmetryObject.cpp プロジェクト: gralm/symmetry
bool SymmetryObject::addNewEP(int sluten)
{
	//cout << "i addfacetobe so is sluten = " << sluten << endl;
			//vector<edge>::iterator ite = E_ToBe.end();
	int sizE = E.size();

	//		Fixa:
	// Rootera tillbaka ytan så att början
	//och slutet alltid rör  en rootPoint.
	Prefix draBortPfxInv = E_ToBe[0].fr.Pfx;//.getSize();
	cout << "The following prefix ska dras away" << endl;
	draBortPfxInv.print();
	draBortPfxInv = draBortPfxInv.getInverse();

	for (unsigned int i=0; i<E_ToBe.size()-1; i++)
	{
		edge edgeToPushBack;

		Prefix enAnnanPrefixIgen = draBortPfxInv;
		enAnnanPrefixIgen.rotate(E_ToBe[i].fr.Pfx);
		enAnnanPrefixIgen.simplify();
		edgeToPushBack.fr.Pfx = enAnnanPrefixIgen;
		edgeToPushBack.fr.index = E_ToBe[i].fr.index;

		enAnnanPrefixIgen = draBortPfxInv;
		enAnnanPrefixIgen.rotate(E_ToBe[i].to.Pfx);
		enAnnanPrefixIgen.simplify();
		edgeToPushBack.to.Pfx = enAnnanPrefixIgen;
		edgeToPushBack.to.index = E_ToBe[i].to.index;

		Prefix PfxNext;
		Prefix PfxPrev;

		switch (sluten) {
			case NOT_CENTERED: {
				edgeToPushBack.next = Edge(PfxNext, (i==E_ToBe.size()-2? sizE: sizE + i + 1));
				edgeToPushBack.prev = Edge(PfxPrev, (i==0? sizE + E_ToBe.size() - 2: sizE + i - 1));
				break;
			}
			case VERTEX_CENTERED: {

				if (i==0)
					PfxPrev.rotate(VN);
				if (i==E_ToBe.size()-2)
					PfxNext.rotate(VP);
				edgeToPushBack.next = Edge(PfxNext, (i==E_ToBe.size()-2? sizE: sizE + i + 1));
				edgeToPushBack.prev = Edge(PfxPrev, i==0? sizE + E_ToBe.size() - 2: sizE + i - 1);
				//edgeToPushBack.next = (i==E_ToBe.size()-2? Edge(Pfx, sizE): Edge(Prefix(), sizE + i + 1));
				break;
			}
			case EDGE_CENTERED: {
				Prefix cpPrefixHelvete;

				cpPrefixHelvete = E_ToBe[E_ToBe.size()-1].fr.Pfx;
				cpPrefixHelvete.rotate(draBortPfxInv);

				cout << "when it is done, it becomasar: ";
				cpPrefixHelvete.print();
				cout << endl;

				if (i==0) {
					PfxPrev = cpPrefixHelvete;
				}


				if (i==E_ToBe.size()-2) {
					PfxNext = cpPrefixHelvete;
				}

				edgeToPushBack.next = Edge(PfxNext, (i==E_ToBe.size()-2? sizE: sizE + i + 1));
				edgeToPushBack.prev = Edge(PfxPrev, (i==0? sizE + E_ToBe.size() - 2: sizE + i - 1));
				break;
			}
			case FACE_CENTERED: {
				Prefix PfxNext;
				Prefix PfxPrev;

				if (i==0)
					PfxPrev.rotate(FN);
				if (i==E_ToBe.size()-2)
					PfxNext.rotate(FP);
				edgeToPushBack.next = Edge(PfxNext, (i==E_ToBe.size()-2? sizE: sizE + i + 1));
				edgeToPushBack.prev = Edge(PfxPrev, (i==0? sizE + E_ToBe.size() - 2: sizE + i - 1));
				break;
			}
			default:
				cout << "symmetryObject.cpp\tHIT SKA DEN INTE KOMMA!!!!!!!!!!!" << endl;
				break;
		}

			// kolla genom om man kan hitta någon opposite
		cout << endl;
		//int kortastePrefix = 10000000;
		edgeToPushBack.oppo.index = -1;
		//edgeToPushBack.





			// kolla genom om man kan hitta någon opposite, IGEN
		if (edgeToPushBack.oppo.index == -1) {
			for (unsigned int j=0; j<E.size(); j++)
			{
				Prefix oppositeOfPrefix;
				//if (E[j].isOppositeOf(E_ToBe[i], &oppositeOfPrefix)) {
				if (E[j].isOppositeOf(edgeToPushBack, &oppositeOfPrefix)) {
					edgeToPushBack.oppo = Edge(oppositeOfPrefix.getInverse(), j);
					E[j].oppo = Edge(oppositeOfPrefix, i + sizE);

					break;
				}
			}
		}
		//cout << "a" << endl;

		Prefix oppositeOfPrefix;
		if (edgeToPushBack.oppo.index == -1)
		{
			//if (E_ToBe[i].isOppositeOf(E_ToBe[i], &oppositeOfPrefix)) {
			if (E_ToBe[i].isOppositeOf(edgeToPushBack, &oppositeOfPrefix)) {
				edgeToPushBack.oppo = Edge(oppositeOfPrefix.getInverse(), i + sizE);
			}
		}

		E.push_back(edgeToPushBack);
	}

	F.push_back(face(sizE, E.size() - sizE, sluten));
	cout << "          *****************************************            " << endl;
	cout << "tjena nu is jag here" << endl;
		// uppdatera GUI:et
	char strToSend[200];
		// id, first edge, num of edges, type, görasigplatt-styrka
	snprintf(strToSend, 200, "%d,%d,%d,%d", F.size()-1, sizE, E.size() - sizE, sluten);
	cout << "detta skickas when face skapas: " << strToSend << endl;

	E_ToBe.clear();
	printAll();
	return true;
}
コード例 #26
0
ファイル: symmetryObject.cpp プロジェクト: gralm/symmetry
	// 	detta är en fullständig test som kollar inte 
	//	bara sista tillagda edgen utan alla edges i facet
	// 		returnerar:
	// 0 om det är felaktigt
	// 1 om det är ok men icke sluten
	// 2 om face är ok.
	//#define NOT_CENTERED		(-1)
	//#define VERTEX_CENTERED	(-2)
	//#define EDGE_CENTERED		(-3)
	//#define FACE_CENTERED		(-4)
int SymmetryObject::checkE_ToBe()
{
	/*VEC AA[3];
	AA[0] = VEC(0.154, 0.07);
	AA[1] = VEC(3.738, 2.) / 9.;
	AA[2] = VEC(0.622, 7.7) /3.;*/


	int siz = E_ToBe.size();
	if (siz <= 1)
		return 1;

		// kolla om den roterar i positiv z-riktning
	VEC fr_ = getWcFromPoint(E_ToBe[0].fr);
	VEC to_ = getWcFromPoint(E_ToBe[0].to);
	VEC edge0_ = to_ - fr_;
	VEC edge1_;
	for (int i=1; i<siz-1; i++)
	{
		fr_ = to_;
		to_ = getWcFromPoint(E_ToBe[i].to);
		edge1_ = to_ - fr_;

		if ((~edge0_ * edge1_) < 0.0)
		{
			cout << "******** EDGES INVALID ********* " << endl;
			cout << "edge0: " << edge0_;
			//edge0_.print();
			cout << "\t edge1: " << edge1_ << endl;
			
			return 0;
		}
		edge0_ = edge1_;
	}



		// kolla om den korsar sig själv
	for (int i=2; i<siz-1; i++)
	{
		for (int j=0; j<i-1; j++)
		{
			VEC Afr_ = getWcFromPoint(E_ToBe[j].fr);
			VEC Ato_ = getWcFromPoint(E_ToBe[j].to);
			VEC Bfr_ = getWcFromPoint(E_ToBe[i].fr);
			VEC Bto_ = getWcFromPoint(E_ToBe[i].to);
			
			VEC P_ = ~(Afr_ - Bfr_);
			VEC Q_ = Ato_ - Afr_;
			VEC R_ = Bto_ - Bfr_;

			double divider_ = Q_ * ~R_;
			double a_ = (Q_ * P_) / divider_;
			double b_ = (R_ * P_) / divider_;

			//cout << "a_: " << a_ << "\tb_: " << b_ << endl;
			if (a_>0 && a_<1 && b_>0 && b_<1)
			{
				cout << "EDGES FUNKAR ICKE ICKE ICKE!!!" << endl;
				cout << "korsar varandra i=" << i << " och j=" << j << endl;
				cout << "a_: " << a_ << "\tb_: " << b_ << endl;
				return 0;
			}
		}
	}

		// kontrollera att inga Points är inkapslade av markeringen.
	list<Point> enclosedPoints;
	VEC A[3];
	A[0] = getWcFromPoint(E_ToBe[0].fr);
	cout << "nu is siz = " << siz << endl;
	for (int i=1; i<siz-2; i++)
	{
		A[1] = getWcFromPoint(E_ToBe[i].fr);
		A[2] = getWcFromPoint(E_ToBe[i+1].fr);

		int extraPoints = getEnclosedPoints(A, enclosedPoints);
		if (extraPoints)
		{
			cout << "extraPoints > 0 when i = " << i << endl;
			for (int j=0; j<3; j++)
				cout << "A[" << j << "]: " << A[j] << endl;
		}
	}
	
	cout << " ************* " << endl;

	cout << "Enclosed Points: " << enclosedPoints.size() << " st." << endl;
	for (list<Point>::iterator itP = enclosedPoints.begin(); itP != enclosedPoints.end(); itP++){
		itP->print();
		cout << "\t" << getWcFromPoint(*itP) << endl;
	}
	cout << " ************* " << endl;


	if (enclosedPoints.size() > 0) {
		cout << "enclosedPoints.size != 0, exit" << endl;
		return 0;
	}



		// Här kontrolleras om kanterna i ytan är sluten:
	if (E_ToBe[siz - 1].fr.index == E_ToBe[0].fr.index)
	{
			// Nu kan den vara sluten 
		Prefix pfxDiff = E_ToBe[0].fr.Pfx.difference(E_ToBe[siz-1].fr.Pfx);
		cout << "prefix difference: ";
		pfxDiff.print();
		cout << endl;	

			// ytan börjar och slutar i samma punkt.
			// Förutsatt att dne kommit hit ner i funktionen
			// så är kanterna slutna till en yta. Toppen!
		if (pfxDiff.size() == 0)
		{
			cout << "startar och slutar i samma punkt :) " << endl;
			return NOT_CENTERED;
		}

			// om pfxDiff = [VP] så kan det vara en Vertex-Centered Face.
		if (pfxDiff.size() == 1 && pfxDiff[0] == VP)
		{
			cout << "Det is en VP rotation detta :) " << endl;
			
			
				//kontrollera så att inga punkter existerar i det området
			if (vertexPointActive)
				return 1;

			Orientation ori(pat);
			ori.rotate(E_ToBe[0].fr.Pfx);
			VEC A[3];
			A[0] = getWcFromPoint(E_ToBe[0].fr);
			A[1] = getWcFromPoint(E_ToBe[siz-1].fr);
			A[2] = ori.getWCFromOC(VEC(0,0));
			list<Point> enclosedPoints;
			getEnclosedPoints(A, enclosedPoints);

			cout << "the following killar ligger in the way: " << endl;
			for (list<Point>::iterator itP = enclosedPoints.begin(); itP != enclosedPoints.end(); itP++){
				itP->print();
				cout << endl;
			}

				// Det är ingen vertexcentered face för den har punkter inom sig.
			if (enclosedPoints.size() > 0)
				return 1;


				// kontrollera 
			if (siz == 2)
				return VERTEX_CENTERED;


			// Kontrollera så att polygonen är konvex om 
			// den är sluten.

				// här kan man vara ute på riktigt hal is om 
				// man exempelvis INTE bygger 10 edgeiga faces
				// i ikosaeder-symmetri, utan istället bygger
				// snorspetsiga fula trianglar. Men skyll dig själv!
			A[0] = getWcFromPoint(E_ToBe[1].fr);
			A[2] = ori.getOCFromWC(A[0]);
			ori.rotate(VP);
			A[2] = ori.getWCFromOC(A[2]);


			if ((A[2] - A[1]) * ~(A[1] - A[0]) > 0)
			{
				// den kan antas rotera kring vertexen.
				return VERTEX_CENTERED;
			} else 
				return 1;
		}
			
			// kolla om det är en face-centered face
		if (pfxDiff.size() == 1 && pfxDiff[0] == FP)
		{
			cout << "   *******    \n Det is en FP rotation detta :) " << endl;
			
			
				//kontrollera så att inga punkter existerar i det området
			if (facePointActive)
				return 1;

			VEC A[3];
			Orientation ori(pat);
			A[2] = ori.getOCFromWC(faceCenteredPoint);

			ori.rotate(E_ToBe[0].fr.Pfx);
			A[0] = getWcFromPoint(E_ToBe[0].fr);
			A[1] = getWcFromPoint(E_ToBe[siz-1].fr);
			A[2] = ori.getWCFromOC(A[2]);

			list<Point> enclosedPoints;
			getEnclosedPoints(A, enclosedPoints);

			cout << "the following killar ligger in the way: " << endl;
			for (list<Point>::iterator itP = enclosedPoints.begin(); itP != enclosedPoints.end(); itP++){
				itP->print();
				cout << endl;
			}

				// Det är ingen vertexcentered face för den har punkter inom sig.
			if (enclosedPoints.size() > 0)
				return 1;


				// kontrollera 
			if (siz == 2)
				return FACE_CENTERED;

			cout << "kom hit" << endl;


			// Kontrollera så att polygonen är konvex om 
			// den är sluten.

				// här kan man vara ute på riktigt hal is om 
				// man exempelvis INTE bygger 10 edgeiga faces
				// i ikosaeder-symmetri, utan istället bygger
				// snorspetsiga fula trianglar. Men skyll dig själv!
			A[0] = getWcFromPoint(E_ToBe[1].fr);
			A[2] = ori.getOCFromWC(A[0]);
			ori.rotate(FP);
			A[2] = ori.getWCFromOC(A[2]);

			if ((A[2] - A[1]) * ~(A[1] - A[0]) > 0)
			{
				// den kan antas rotera kring vertexen.
				return FACE_CENTERED;
			} else 
				return 1;
		}

			// kolla om det är en edge-centered face
		if (pfxDiff.size() == 2 && ((pfxDiff[0]^pfxDiff[1]) == 6))
		{
			cout << "   *******    \n Det is en FN rotation detta :) " << endl;
			cout << "   *******    \n Det is en edge-centered kille om inga i vägen :) " << endl;
			
			
				//kontrollera så att inga punkter existerar i det området
			if (edgePointActive) {
				cout << "exit, edge-point is active" << endl;
				return 1;
			}


				// om det är ett rakt streck ?
			if (siz == 2)
				return 1;



			VEC A[3];
			Orientation ori(pat);
			ori.rotate(E_ToBe[0].fr.Pfx);

			switch(pfxDiff[0])
			{
				case FP:
				case VN:
					//A[0] = ori.getWCFromOC(VEC(COS30, -SIN30)*.5);
					A[0] = getWcFromPoint(E_ToBe[0].fr);
					break;
				case FN:
				case VP:
					//A[0] = ori.getWCFromOC(VEC(COS30, SIN30)*.5);
					A[0] = getWcFromPoint(E_ToBe[0].fr);
					break;
				default:
					cout << "hit ska jag typ icke kommmmma" << endl;
					break;
			}

			list<Point> enclosedPoints;

			for (int k=1; k<siz-1; k++)
			{
				A[1] = getWcFromPoint(E_ToBe[k].fr);
				A[2] = getWcFromPoint(E_ToBe[k+1].fr);
				cout << "\t ************ k=" << k << endl;

				cout << "E_tobe[" << 0 << "] = " << A[0] << endl;
				cout << "E_tobe[" << k << "] = " << A[1] << endl;
				cout << "E_tobe[" << (k+1) << "] = " << A[2] << endl;

				getEnclosedPoints(A, enclosedPoints);
			}


			cout << "the following killar ligger in the way: " << endl;
			for (list<Point>::iterator itP = enclosedPoints.begin(); itP != enclosedPoints.end(); itP++){
				itP->print();
				cout << endl;
			}

				// Det är ingen vertexcentered face för den har punkter inom sig.
			if (enclosedPoints.size() > 0) {
				cout << "Det is killar in the way" << endl;
				return 0;
			}

				// nästa punkt i serien kommer bli A[]
			A[0] = A[0]*2.0 - getWcFromPoint(E_ToBe[1].fr);


			cout << "kille0: " << A[0] << endl;
			cout << "kille1: " << A[1] << endl;
			cout << "kille2: " << A[2] << endl;
			
			cout << "value: " << ((A[0] - A[2]) * ~(A[2] - A[1])) << endl;

			if ((A[0] - A[2]) * ~(A[2] - A[1]) < 0)
				return 1;

			return EDGE_CENTERED;
		}
	}

		// allt funkar och den är inte sluten. Fortsätt bygga din fejja!!!
	return 1;
}
コード例 #27
0
ファイル: symmetryObject.cpp プロジェクト: gralm/symmetry
int SymmetryObject::checkNewEP()
{
	int siz = newEP.size();	// antal vertices i kedja
	cout << "siz = " << siz << endl;
	vector<VEC> wc;

	cout << "skriver ut ala newEP: " << endl;
	for (int i=0; i<siz; i++) {
		wc.push_back(getWcFromPoint(newEP[i]));
		cout << i << ":\t" << wc[i] << "\t" << newEP[i].toString() << endl;
	}


	if (siz <= 1) {
		cout << "return 1: siz = " << siz << "<= 1 " << endl;
		return 1;
	}


		// gå genom alla och se om någon om två vertices sträcker sig för långt
	Prefix pfxDiff;
	for (int i=siz-2; i>=0; i--)
	{
		//pfxDiff = (newEP[siz-1].Pfx / newEP[i].Pfx);
		pfxDiff = (newEP[i].Pfx.getInverse() * newEP[siz-1].Pfx);
		pfxDiff.simplify();

		switch(pfxDiff.size())
		{
		case 0:
		case 1:
			break;
		case 2:
			if ((pfxDiff[0]^pfxDiff[1]) != 6) {
				cout << "return 0: pfxDiff[0]^pfxDiff[1] = " << (pfxDiff[0]^pfxDiff[1]) << " != 6" << endl;
				cout << "PfxDiff = ";
				pfxDiff.print();
				return 0;
			}
			break;
		default:
			cout << "return 0: pfxDiff[0].size() > 2" << endl;
			return 0;
		}
	}


	cout << "pfxDiff: " << pfxDiff.toString() << endl;
	int pfxDiffSiz = pfxDiff.size();


		// kontrollera att den inte är bend åt fel håll
	if (siz > 2) {
		if (~(wc[siz-1]-wc[siz-2]) * (wc[siz-3]-wc[siz-2]) < 0)
		{
			cout << "Bend towards vrong hool" << endl;
			return 0;
		}
	}

		//kontrollera så ingen är ansluten A -> B

		//kontrollera att inga korsningar existerar


		// finns det enclosed Points:
	VEC A[3];
	list<Point> enclosedPoints;
	if (siz >= 3) {
		A[0] = wc[0];
		A[1] = wc[siz-2];
		A[2] = wc[siz-1];
		int extraPoints = getEnclosedPoints(A, enclosedPoints);

		cout << "enclosed Points: " << extraPoints << endl;
		for (list<Point>::iterator itP = enclosedPoints.begin(); itP != enclosedPoints.end(); itP++)
			cout << "\t" << itP->toString() << endl;

		if (extraPoints > 0) {
			cout << "det fanns enclosed punkter" << endl;
			return 0;
		}
	}

		// kontrollera om den inte återvänder till samma index
	if (newEP[siz-1].index != newEP[0].index) {
		cout << "index[siz-1] != index[0] so returna 1" << endl;
		return 1;
	}


		// bestäm vad det är för typ av face
	switch(pfxDiffSiz) {
	case 0:
		cout << "Not centered" << endl;
		if (siz == 2) {
			cout << "siz = 2 och returnar till samma punkt" << endl;
			return 0;
		}
		return NOT_CENTERED;
	case 1: {
		if (pfxDiff[0] == VP) {
			cout << "pfxDiff[0] = VP" << endl;
			if (vertexPointActive) {
				cout << "kan inte skapa VCF för VP är aktiv, därför return 1" << endl;
				return 1;
			}

				// gör koll om det finns enclosed Vertieces i [wc[0], wc[siz-1], getWcFromPoint(Point(E_ToBe[0].fr.Pfx))]
			A[0] = wc[0];
			A[1] = wc[siz-1];
			A[2] = getWcFromPoint(Point(newEP[0].Pfx, VERTEX_CENTERED));
			this->getEnclosedPoints(A, enclosedPoints);
			if (enclosedPoints.size() > 0)
			{
				cout << "kan inte skapa VCF för att man enclosar Points, därför return 1";
				return 1;
			}

				// kontrollera att sista och påföljande edge inte buktar åt fel håll., då returneras 1

			cout << "lyckades skapa VCF, return VERTEX_CENTERED" << endl;
			return VERTEX_CENTERED;

		} else if (pfxDiff[0] == FP) {
			cout << "pfxDiff[0] = FP" << endl;
			if (facePointActive) {
				cout << "kan inte skapa FCF för FP är aktiv, därför return 1" << endl;
				return 1;
			}

				// gör koll om det finns enclosed Vertieces i [wc[0], wc[siz-1], getWcFromPoint(Point(E_ToBe[0].fr.Pfx))]
			A[0] = wc[0];
			A[1] = wc[siz-1];
			A[2] = getWcFromPoint(Point(newEP[0].Pfx, FACE_CENTERED));
			this->getEnclosedPoints(A, enclosedPoints);
			if (enclosedPoints.size() > 0)
			{
				cout << "kan inte skapa VCF för att man enclosar Points, därför return 1";
				return 1;
			}

				// kontrollera att sista och påföljande edge inte buktar åt fel håll., då returneras 1

			cout << "lyckades skapa FCF, return FACE_CENTERED" << endl;
			return FACE_CENTERED;
		} else {
			cout << "pfxDiffSiz = 1, men pfxDiff[0] = " << (pfxDiff[0] == VN? "VN": "FN") << ", return 1" << endl;
			return 1;
		}
	}
	case 2: {
		cout << "pfxDiff[i]^pfxDiff[siz-1] != 6" << endl;

		if (edgePointActive) {
			cout << "kan inte meeta edge opposite Point om EP active, return 0" << endl;
			return 0;
		}

			// behöver inte leta efter points inom något område för allt är redan avsökt.


			// kontrollera att sista och påföljande edge inte buktar åt fel håll., då returneras 0

		cout << "lyckades skapa ECF, return EDGE_CENTERED" << endl;
		return EDGE_CENTERED;
		break;
	}
	default:
		cout << "ska inte komma hit till default, return 0" << endl;
		return 0;
		break;
	}


	/*
n[]
    om e<3                    0
    annars                    -1

n[VP]    om VCV = true                1
    om innesluten vertex i A, B, VCP    1
    annars                     -2

n[VP FP]
n[FN VN]    om e<2                1
    om ECV = true                0
    annars                    -3

n[FP]    om FCV = true                1
    om innesluten vertex i A, B, FCP    1
    annars                    -4
	 */

	cout << "kom hit " << endl;
	return 1;


	/*

Första = A
Sista  = B

Prefix pfxDiff = (B.Pfx / A.Pfx).simplify();
switch(pfxDiff.size())
{
    case 1:
        break;
    case 2:
        if (pfxDiff[0]^pfxDiff[1]!=6)
            0
        break;
    default:
            0
        break;
}

kontrollera så ingen är ansluten A -> B

Face-centered vertex = FCV
Face-centered position = FCP

2    Färdig
1    Fortsätt leta
0    Förstörd ta bort
-1    Not centered
-2    vertex centered
-3    edge centered
-4    face centered


c = inneslutna hörn
e = antal edges

c>0                        0

n[]
    om e<3                    0
    annars                    -1

n[VP]    om VCV = true                1
    om innesluten vertex i A, B, VCP    1
    annars                     -2

n[VP FP]
n[FN VN]    om e<2                1
    om ECV = true                0
    annars                    -3

n[FP]    om FCV = true                1
    om innesluten vertex i A, B, FCP    1
    annars                    -4

	 * */


}
コード例 #28
0
ファイル: EAN.cpp プロジェクト: dragonsoup2/Projects
//checks if EAN is a registered number in the prefixtable.
bool EAN::isRegistered(const Prefix& fp)
{
    bool farea = false;
    bool fpub = false;

    char areatmp[5] = {0};
    char pubtmp[8] = {0};
    char titletmp[7] = {0};

    int len;
    int lenpub;
    int lentitle;
    int areano;
    int pospub, postitle;

		for(int i=3; i < 8 && farea == false; i++)
		{
			len = strlen(areatmp);
			areatmp[len] = ean[i];
			areatmp[len+1] = '\0';
			areano = atoi(areatmp);
			farea = fp.isRegistered(areano);
			//cout << "area 3 " << areatmp << endl;
			pospub = i + 1;
		}
		strcpy(area,areatmp);

	isRegister = farea;
    if(isRegister != false)
    {
        for(int i = pospub; i < 11 && fpub == false; i++)
        {
            lenpub = strlen(pubtmp);
            pubtmp[lenpub] = ean[i];
            pubtmp[lenpub+1] = '\0';
			//cout << "publisher 1" << pubtmp << endl;
            //cout << "---------------------------------------" << endl;
            //cout << "pubtmpdigit : " << pubtmp << endl;
            fpub = fp.isRegistered(atoi(area),pubtmp);
            postitle = i + 1;
        }

        isRegister = fpub;

        for(int i = postitle; i < 13; i++)
        {

			if(i == 12)
			{
				checkdigit = ean[i];
			}
			else
			{
				lentitle = strlen(titletmp);
				titletmp[lentitle] = ean[i];
				titletmp[lentitle+1] = '\0';
			}
        }
		strcpy(publisher, pubtmp);
		strcpy(title, titletmp);

    }
	if(isRegister == true)
	{

		stylee = '-';
	}
	emptyy = false;
    //cout << "title ---->" << titletmp << endl;
    return isRegister;
}
コード例 #29
0
ファイル: Or.cpp プロジェクト: DarrenStahl/Libra
Instruction* Or::CreateInstruction(Memory::MemoryOffset& memLoc, Processor* proc) {

	Memory::MemoryOffset opLoc = memLoc;
	int prefixLen = 0;
	char buf[65];
	int tInt1 = 0;
	unsigned char modrm = 0;

	Prefix* prefix = 0;

	Instruction* newOr = 0;

	//Build a prefix if possible
	prefix = Prefix::GetPrefix(memLoc);

	//Start looking after the prefix
	if(prefix) {
		opLoc += prefix->GetLength();
		prefixLen += prefix->GetLength();
	}


	std::string inst;
	//Switch for the different valid opcodes
	switch(*opLoc) {
		case OR_AL_IMM8:
			sprintf(buf, "OR AL, 0x%02X", (int)*(opLoc + 1));

			GETINST(prefixLen + 2);

			newOr = new Or(prefix, buf, inst, (unsigned char)*opLoc);
			newOr->SetOperand(Operand::SRC, new ImmediateOperand(*(opLoc + 1), 1,(opLoc + 1).getOffset()));
			newOr->SetOperand(Operand::DST, new RegisterOperand(REG_AL, proc));

			break;
		case OR_AX_IMM16:
			tInt1 = (unsigned char)*(opLoc + 1);
			tInt1 |= (((unsigned char)*(opLoc + 2)) << 8);

			sprintf(buf, "OR AX, 0x%04X", tInt1);

			GETINST(prefixLen + 3);

			newOr = new Or(prefix, buf, inst, (unsigned char)*opLoc);
			newOr->SetOperand(Operand::SRC, new ImmediateOperand(tInt1, 2, (opLoc + 1).getOffset()));
			newOr->SetOperand(Operand::DST, new RegisterOperand(REG_AX, proc));

			break;

		case GRP1_OR_MOD8_IMM8:
		case GRP1_OR_MOD16_IMM16:
		case GRP1_OR_MOD16_IMM8:
			modrm = (*(opLoc + 1) & 0x38) >> 3;
			if(modrm == 1) {
				unsigned int immSize = (*opLoc == GRP1_OR_MOD8_IMM8) ? 1 : 2;

				Operand* dst = ModrmOperand::GetModrmOperand(
							proc, opLoc, ModrmOperand::MOD, immSize);

				tInt1 = (int)*(opLoc+2+dst->GetBytecodeLen());
				if(immSize == 2) {
					if(*opLoc == GRP1_OR_MOD16_IMM16) {
						tInt1 += ((int)*(opLoc+3+dst->GetBytecodeLen())) << 8;
					}else {
						tInt1 = (tInt1 >= 0x80) ? 0xFF00 + tInt1 : tInt1;
					}
				}

				if(immSize == 1)
					sprintf(buf, "OR %s, 0x%02X", "", tInt1);
				else
					sprintf(buf, "OR %s, 0x%04X", "", tInt1);

				GETINST(prefixLen + 2 + immSize + dst->GetBytecodeLen() - (*opLoc == GRP1_OR_MOD16_IMM8 ? 1 : 0));
				newOr = new Or(prefix, buf, inst, (unsigned char)*opLoc);
				newOr->SetOperand(Operand::SRC, new ImmediateOperand(tInt1, immSize, (opLoc + 2 + dst->GetBytecodeLen()).getOffset()));
				newOr->SetOperand(Operand::DST, dst);
			}
			break;

		case GRP2_OR_MOD8_REG8:
		case GRP2_OR_MOD16_REG16:
			{
				unsigned int size = (*opLoc == GRP2_OR_MOD8_REG8) ? 1 : 2;

				Operand* dst = ModrmOperand::GetModrmOperand(
						proc, opLoc, ModrmOperand::MOD, size);
				Operand* src = ModrmOperand::GetModrmOperand(
						proc, opLoc, ModrmOperand::REG, size);
				sprintf(buf, "OR %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
				GETINST(prefixLen + 2 + dst->GetBytecodeLen() + src->GetBytecodeLen());
				newOr = new Or(prefix, buf, inst, (unsigned char)*opLoc);
				newOr->SetOperand(Operand::SRC, src);
				newOr->SetOperand(Operand::DST, dst);
				break;
			}

		case GRP3_OR_REG8_MOD8:
		case GRP3_OR_REG16_MOD16:
			{
				unsigned int size = *opLoc == GRP3_OR_REG8_MOD8 ? 1 : 2;

				Operand* dst = ModrmOperand::GetModrmOperand(
						proc, opLoc, ModrmOperand::REG, size);
				Operand* src = ModrmOperand::GetModrmOperand(
						proc, opLoc, ModrmOperand::MOD, size);
				sprintf(buf, "OR %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
				GETINST(prefixLen + 2 + dst->GetBytecodeLen() + src->GetBytecodeLen());
				newOr = new Or(prefix, buf, inst, (unsigned char)*opLoc);
				newOr->SetOperand(Operand::SRC, src);
				newOr->SetOperand(Operand::DST, dst);
				break;


			}

		default:
			break;
	}

	return newOr;

}
コード例 #30
0
ファイル: Xor.cpp プロジェクト: rdnelson/Libra
Instruction* Xor::CreateInstruction(unsigned char* memLoc, Processor* proc) {
	unsigned char* opLoc = memLoc;
	unsigned int preSize = 0;
	char buf[65];
	std::string inst;
	Instruction* newXor = 0;

	Prefix* pre = Prefix::GetPrefix(memLoc);

	if(pre) {
		opLoc += preSize = pre->GetLength();
	}

	switch(*opLoc) {
		case XOR_AL_IMM8:
		case XOR_AX_IMM16:
		{
			unsigned int size = (*opLoc) == XOR_AL_IMM8 ? 1 : 2;
			unsigned int val = (int)*(opLoc + 1);
			if(size == 2) {
				val += (int)*(opLoc + 2) << 8;
			}

			GETINST(preSize + 1 + size);

			Operand* dst = new RegisterOperand(size == 1 ? REG_AL : REG_AX, proc);
			Operand* src = new ImmediateOperand(val, size);
			snprintf(buf, 65, "XOR %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			newXor = new Xor(pre, buf, inst, (int)*opLoc);
			newXor->SetOperand(Operand::SRC, src);
			newXor->SetOperand(Operand::DST, dst);
			break;
		}
		case XOR_MOD8_IMM8:
		case XOR_MOD16_IMM16:
		case XOR_MOD16_IMM8:
		{
			if(((*(opLoc + 1) & 0x38) >> 3) != XOR_REG_CONST)
				break;

			unsigned int size = *opLoc == XOR_MOD8_IMM8 ? 1 : 2;
			Operand* dst = ModrmOperand::GetModrmOperand(proc, opLoc, ModrmOperand::MOD, size);

			unsigned int val = (int)*(opLoc + 2 +dst->GetBytecodeLen());
			if(size == 2) {
				if(*opLoc == XOR_MOD16_IMM16)
					val += (int)*(opLoc + 3 + dst->GetBytecodeLen()) << 8;
				else
					val += val >= 0x80 ? 0xFF00 : 0x0000;
			}

			Operand* src = new ImmediateOperand(val, size);
			
			GETINST(preSize + 2 + (*opLoc == XOR_MOD16_IMM8 ? 1 : size) + dst->GetBytecodeLen());
			snprintf(buf, 65, "XOR %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());

			newXor = new Xor(pre, buf, inst, (int)*opLoc);
			newXor->SetOperand(Operand::SRC, src);
			newXor->SetOperand(Operand::DST, dst);
			break;
		}
		case XOR_MOD8_REG8:
		case XOR_MOD16_REG16:
		case XOR_REG8_MOD8:
		case XOR_REG16_MOD16:
		{
			unsigned int size = (*opLoc == XOR_MOD8_REG8 || *opLoc == XOR_REG8_MOD8) ? 1 : 2;
			
			Operand* dst = ModrmOperand::GetModrmOperand(
					proc,
					opLoc,
					(*opLoc == XOR_MOD8_REG8 || *opLoc == XOR_MOD16_REG16) ? 
						ModrmOperand::MOD : ModrmOperand::REG,
					size);
			Operand* src = ModrmOperand::GetModrmOperand(
					proc,
					opLoc,
					(*opLoc == XOR_REG8_MOD8 || *opLoc == XOR_REG16_MOD16) ? 
						ModrmOperand::MOD : ModrmOperand::REG,
					size);

			GETINST(preSize + 2 + src->GetBytecodeLen() + dst->GetBytecodeLen());
			snprintf(buf, 65, "XOR %s, %s", dst->GetDisasm().c_str(), src->GetDisasm().c_str());
			newXor = new Xor(pre, buf, inst, (int)*opLoc);
			newXor->SetOperand(Operand::SRC, src);
			newXor->SetOperand(Operand::DST, dst);
			break;
		}
	}

	return newXor;

}