int dump_hook_init(PDRIVER_OBJECT drv_obj)
{
	PLDR_DATA_TABLE_ENTRY table;
	PHYSICAL_ADDRESS      high_addr;
	PLIST_ENTRY           entry;
	NTSTATUS              status;
	int                   resl = 0;

	ExInitializeFastMutex(&dump_sync);

	ExAcquireFastMutex(&dump_sync);

	/* find PsLoadedModuleListHead */
	entry = ((PLIST_ENTRY)(drv_obj->DriverSection))->Flink;

	while (entry != drv_obj->DriverSection)
	{
		table = CONTAINING_RECORD(entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
		entry = entry->Flink;

		if ( (table->BaseDllName.Length == 0x18) && 
			 (p32(table->BaseDllName.Buffer)[0] == 0x0074006E) )
		{
			ps_loaded_mod_list = pv(table->InLoadOrderLinks.Blink);
			break;
		}
	}

	ExReleaseFastMutex(&dump_sync);

	do
	{
		if (ps_loaded_mod_list == NULL) break;

		status = PsSetLoadImageNotifyRoutine(load_img_routine);
		if (NT_SUCCESS(status) == FALSE) break;

		high_addr.HighPart = 0;
		high_addr.LowPart  = 0xFFFFFFFF;

		dump_mem = MmAllocateContiguousMemory(DUMP_MEM_SIZE, high_addr);
		if (dump_mem == NULL) break;
		dump_mdl = IoAllocateMdl(dump_mem, DUMP_MEM_SIZE, FALSE, FALSE, NULL); 
		if (dump_mdl == NULL) break;

		MmBuildMdlForNonPagedPool(dump_mdl);
		memset(dump_mem, 0, DUMP_MEM_SIZE);
		resl = 1;
	} while (0);

	if (resl == 0) {
		if (dump_mdl != NULL) IoFreeMdl(dump_mdl);
		if (dump_mem != NULL) MmFreeContiguousMemory(dump_mem);
	}
	return resl;	
}
Exemple #2
0
int dbg_get_version(syscall *data)
{
	if (data->out_size == sizeof(u32))
	{
		p32(data->out_data)[0] = DBG_VERSION;

		return 1;
	}

	return 0;
}
void _stdcall serpent256_decrypt(const unsigned char *in, unsigned char *out, serpent256_key *key)
{
	u32 *k = key->expkey;
	u32	 r0, r1, r2, r3, r4;

	r0 = p32(in)[0]; r1 = p32(in)[1];
	r2 = p32(in)[2]; r3 = p32(in)[3];

	K(r0,r1,r2,r3,32);
	SI7(r0,r1,r2,r3,r4); KL(r1,r3,r0,r4,r2,31);
	SI6(r1,r3,r0,r4,r2); KL(r0,r2,r4,r1,r3,30);
	SI5(r0,r2,r4,r1,r3); KL(r2,r3,r0,r4,r1,29);
	SI4(r2,r3,r0,r4,r1); KL(r2,r0,r1,r4,r3,28);
	SI3(r2,r0,r1,r4,r3); KL(r1,r2,r3,r4,r0,27);
	SI2(r1,r2,r3,r4,r0); KL(r2,r0,r4,r3,r1,26);
	SI1(r2,r0,r4,r3,r1); KL(r1,r0,r4,r3,r2,25);
	SI0(r1,r0,r4,r3,r2); KL(r4,r2,r0,r1,r3,24);
	SI7(r4,r2,r0,r1,r3); KL(r2,r1,r4,r3,r0,23);
	SI6(r2,r1,r4,r3,r0); KL(r4,r0,r3,r2,r1,22);
	SI5(r4,r0,r3,r2,r1); KL(r0,r1,r4,r3,r2,21);
	SI4(r0,r1,r4,r3,r2); KL(r0,r4,r2,r3,r1,20);
	SI3(r0,r4,r2,r3,r1); KL(r2,r0,r1,r3,r4,19);
	SI2(r2,r0,r1,r3,r4); KL(r0,r4,r3,r1,r2,18);
	SI1(r0,r4,r3,r1,r2); KL(r2,r4,r3,r1,r0,17);
	SI0(r2,r4,r3,r1,r0); KL(r3,r0,r4,r2,r1,16);
	SI7(r3,r0,r4,r2,r1); KL(r0,r2,r3,r1,r4,15);
	SI6(r0,r2,r3,r1,r4); KL(r3,r4,r1,r0,r2,14);
	SI5(r3,r4,r1,r0,r2); KL(r4,r2,r3,r1,r0,13);
	SI4(r4,r2,r3,r1,r0); KL(r4,r3,r0,r1,r2,12);
	SI3(r4,r3,r0,r1,r2); KL(r0,r4,r2,r1,r3,11);
	SI2(r0,r4,r2,r1,r3); KL(r4,r3,r1,r2,r0,10);
	SI1(r4,r3,r1,r2,r0); KL(r0,r3,r1,r2,r4,9);
	SI0(r0,r3,r1,r2,r4); KL(r1,r4,r3,r0,r2,8);
	SI7(r1,r4,r3,r0,r2); KL(r4,r0,r1,r2,r3,7);
	SI6(r4,r0,r1,r2,r3); KL(r1,r3,r2,r4,r0,6);
	SI5(r1,r3,r2,r4,r0); KL(r3,r0,r1,r2,r4,5);
	SI4(r3,r0,r1,r2,r4); KL(r3,r1,r4,r2,r0,4);
	SI3(r3,r1,r4,r2,r0); KL(r4,r3,r0,r2,r1,3);
	SI2(r4,r3,r0,r2,r1); KL(r3,r1,r2,r0,r4,2);
	SI1(r3,r1,r2,r0,r4); KL(r4,r1,r2,r0,r3,1);
	SI0(r4,r1,r2,r0,r3); K(r2,r3,r1,r4,0);

	p32(out)[0] = r2; p32(out)[1] = r3;
	p32(out)[2] = r1; p32(out)[3] = r4;
}
void _stdcall serpent256_encrypt(const unsigned char *in, unsigned char *out, serpent256_key *key)
{
	u32 *k = key->expkey;
	u32  r0, r1, r2, r3, r4;

	r0 = p32(in)[0]; r1 = p32(in)[1];
	r2 = p32(in)[2]; r3 = p32(in)[3];

	K(r0,r1,r2,r3,0);
	S0(r0,r1,r2,r3,r4);	LK(r2,r1,r3,r0,r4,1);
	S1(r2,r1,r3,r0,r4);	LK(r4,r3,r0,r2,r1,2);
	S2(r4,r3,r0,r2,r1);	LK(r1,r3,r4,r2,r0,3);
	S3(r1,r3,r4,r2,r0);	LK(r2,r0,r3,r1,r4,4);
	S4(r2,r0,r3,r1,r4);	LK(r0,r3,r1,r4,r2,5);
	S5(r0,r3,r1,r4,r2);	LK(r2,r0,r3,r4,r1,6);
	S6(r2,r0,r3,r4,r1);	LK(r3,r1,r0,r4,r2,7);
	S7(r3,r1,r0,r4,r2);	LK(r2,r0,r4,r3,r1,8);
	S0(r2,r0,r4,r3,r1);	LK(r4,r0,r3,r2,r1,9);
	S1(r4,r0,r3,r2,r1);	LK(r1,r3,r2,r4,r0,10);
	S2(r1,r3,r2,r4,r0);	LK(r0,r3,r1,r4,r2,11);
	S3(r0,r3,r1,r4,r2);	LK(r4,r2,r3,r0,r1,12);
	S4(r4,r2,r3,r0,r1);	LK(r2,r3,r0,r1,r4,13);
	S5(r2,r3,r0,r1,r4);	LK(r4,r2,r3,r1,r0,14);
	S6(r4,r2,r3,r1,r0);	LK(r3,r0,r2,r1,r4,15);
	S7(r3,r0,r2,r1,r4);	LK(r4,r2,r1,r3,r0,16);
	S0(r4,r2,r1,r3,r0);	LK(r1,r2,r3,r4,r0,17);
	S1(r1,r2,r3,r4,r0);	LK(r0,r3,r4,r1,r2,18);
	S2(r0,r3,r4,r1,r2);	LK(r2,r3,r0,r1,r4,19);
	S3(r2,r3,r0,r1,r4);	LK(r1,r4,r3,r2,r0,20);
	S4(r1,r4,r3,r2,r0);	LK(r4,r3,r2,r0,r1,21);
	S5(r4,r3,r2,r0,r1);	LK(r1,r4,r3,r0,r2,22);
	S6(r1,r4,r3,r0,r2);	LK(r3,r2,r4,r0,r1,23);
	S7(r3,r2,r4,r0,r1);	LK(r1,r4,r0,r3,r2,24);
	S0(r1,r4,r0,r3,r2);	LK(r0,r4,r3,r1,r2,25);
	S1(r0,r4,r3,r1,r2);	LK(r2,r3,r1,r0,r4,26);
	S2(r2,r3,r1,r0,r4);	LK(r4,r3,r2,r0,r1,27);
	S3(r4,r3,r2,r0,r1);	LK(r0,r1,r3,r4,r2,28);
	S4(r0,r1,r3,r4,r2);	LK(r1,r3,r4,r2,r0,29);
	S5(r1,r3,r4,r2,r0);	LK(r0,r1,r3,r2,r4,30);
	S6(r0,r1,r3,r2,r4);	LK(r3,r4,r1,r2,r0,31);
	S7(r3,r4,r1,r2,r0);	 K(r0,r1,r2,r3,32);

	p32(out)[0] = r0; p32(out)[1] = r1;
	p32(out)[2] = r2; p32(out)[3] = r3;
}
Exemple #5
0
void tst_expr_rand(unsigned num_files) {
    ast_manager m;
    
    m.register_plugin(symbol("bv"), alloc(bv_decl_plugin));
    m.register_plugin(symbol("array"), alloc(array_decl_plugin));

    expr_rand er(m);    
    er.initialize_bv(20);
    er.seed(rand_seed);
    parameter p1(1);
    parameter p2(2);
    parameter p8(8);
    parameter p32(32);
    family_id bvfid = m.mk_family_id("bv");
    sort* bv1  = m.mk_sort(bvfid, BV_SORT, 1, &p1);
    sort* bv2  = m.mk_sort(bvfid, BV_SORT, 1, &p2);
    sort* bv8  = m.mk_sort(bvfid, BV_SORT, 1, &p8);
    sort* bv32 = m.mk_sort(bvfid, BV_SORT, 1, &p32);
    er.initialize_array(3, bv8, bv32);
    er.initialize_array(3, bv1, bv1);
    er.initialize_array(3, bv1, bv2);
    er.initialize_array(3, bv2, bv1);
    er.initialize_array(3, bv2, bv2);
    er.initialize_array(3, bv8, bv8);
    er.initialize_array(3, bv32, bv32);
    er.initialize_basic(20);

    for (unsigned i = 0; i < num_files; ++i) {
        expr_ref e(m);
        er.get_next(m.mk_bool_sort(), e);
        ast_smt_pp pp(m);

        pp.set_logic(symbol("QF_AUFBV"));
        std::ostringstream buffer;
        buffer << "random_bv_" << i << ".smt";
        std::cout << buffer.str() << "\n";
        std::ofstream file(buffer.str().c_str());
        pp.display(file, e.get());
        file.close();

    }
}
Exemple #6
0
void sha512_pkcs5_2(
	   int i_count,
	   const void *pwd,  size_t pwd_len, 
	   const char *salt, size_t salt_len,
	   char *dk,   size_t dklen
	   )
{
	u8       buff[128];
	u8       blk[SHA512_DIGEST_SIZE];
	u8       hmac[SHA512_DIGEST_SIZE];
	u32      block = 1;
	size_t   c_len, j;
	int      i;

	while (dklen != 0)
	{
		/* first interation */
		mincpy(buff, salt, salt_len);
		p32(buff + salt_len)[0] = BE32(block);
		sha512_hmac(pwd, pwd_len, buff, salt_len + 4, hmac);
		autocpy(blk, hmac, SHA512_DIGEST_SIZE);

		/* next interations */
		for (i = 1; i < i_count; i++) 
		{
			sha512_hmac(pwd, pwd_len, hmac, SHA512_DIGEST_SIZE, hmac);

			for (j = 0; j < SHA512_DIGEST_SIZE; j++) {
				blk[j] ^= hmac[j];
			}
		}
		c_len = min(dklen, SHA512_DIGEST_SIZE);
		mincpy(dk, blk, c_len);
		dk += c_len; dklen -= c_len; block++;
	}
	/* prevent leaks */
	zeroauto(buff, sizeof(buff));
	zeroauto(blk,  sizeof(blk));
	zeroauto(hmac, sizeof(hmac));
}
int bios_call(int num, rm_ctx *ctx)
{
	/* copy initial context to real mode buffer */
	if (ctx != NULL) {
		mincpy(&bdat->rmc, ctx, sizeof(rm_ctx));
	}
	/* get interrupt seg/off */
	if ( (num == 0x13) && (bdat->old_int13 != 0) ) {
		bdat->segoff = bdat->old_int13;
	} else {
		bdat->segoff = p32(0)[num];
	}
	bdat->rmc.efl = FL_IF;
	/* call to real mode */
	bdat->call_rm();
	
	/* copy changed context */
	if (ctx != NULL) {
		mincpy(ctx, &bdat->rmc, sizeof(rm_ctx));
	}
	return (bdat->rmc.efl & FL_CF) == 0;
}
bool Surface::collapse(Edge& e)
{

    timespec t0,t1,t;
    clock_gettime(CLOCK_REALTIME,&t0);
    Point* p1 = e.p1;
    Point* p2 = e.p2;

    assert(p1);
    assert(p2);



    if(p1->faces.size() ==0 || p2->faces.size()==0) //Do not simplify boundary corners
    {
        //cerr << "*ERROR: EMPTY VERTEX.\n";
        failed_collapses++;
        //cout << redtty << "failed.\n" << deftty;
        return false;
    }

    //Iterating faces
  vector<Face*> for_removal;
  //clock_gettime(CLOCK_REALTIME,&t0);
    for(vector<Face*>::iterator fit = p1->faces.begin(); fit!=p1->faces.end(); ++fit)
    {
        bool removeface = false;
        vector<Point*>::iterator auxp1;
        for(vector<Point*>::iterator pit = (*fit)->points.begin(); pit != (*fit)->points.end() ; ++pit)
        {
            if((*pit) == p2)
            {
                removeface = true;
                break;
            }
            else if ((*pit) == p1)
            {
                auxp1 = pit;
            }
        }
        if(removeface) //p1 and p2 share face, remove it.
        {
            for_removal.push_back((*fit));
        }
        else //Swap p1 for p2 for this face
        {
            //Face is about to be modified. Checking intersection.
            Point3 p30((*fit)->points[0]->x,(*fit)->points[0]->y,(*fit)->points[0]->z);
            Point3 p31((*fit)->points[1]->x,(*fit)->points[1]->y,(*fit)->points[1]->z);
            Point3 p32((*fit)->points[2]->x,(*fit)->points[2]->y,(*fit)->points[2]->z);

            Triangle3 face(p30,p31,p32);

            for(face_vec_it fit2 = m_faces.begin(); fit2 != m_faces.end(); ++fit2)
            {
              Face* f = (*fit2);
              Point3 pf0(f->points[0]->x,f->points[0]->y,f->points[0]->z);
              Point3 pf1(f->points[1]->x,f->points[1]->y,f->points[1]->z);
              Point3 pf2(f->points[2]->x,f->points[2]->y,f->points[2]->z);
              Triangle3 face2(pf0,pf1,pf2);

              if(CGAL::do_intersect(face,face2))
              {
                cerr << "***Faces " << (*fit)->id << " X " << f->id << endl;
              }
            }

            (*auxp1) = p2;
            p2->faces.push_back((*fit));
        }
    }



    //cerr << "Removing faces: ";
    for(vector<Face*>::iterator it = for_removal.begin(); it != for_removal.end(); ++it)
    {
      //cerr << (*it)->id << " ";
       removeFace(*it);
       (*it)->removed = true;
       //delete (*it);
    }

    //Set position of p2 as midpoint between p1-p2
    p2->x = e.placement->x;
    p2->y = e.placement->y;
    p2->z = e.placement->z;


    clock_gettime(CLOCK_REALTIME,&t1);
    t = diff(t0,t1);
    time_faces+= getNanoseconds(t);


    //TODO: more efficient to use std::remove_if
    clock_gettime(CLOCK_REALTIME,&t0);
    removeEdge(m_edges[e.id]);

    vector<Edge*> edges_to_remove;
    edge_vec_it eit = p1->to.begin();
    //Remove double edges to
    while(eit != p1->to.end())
    {
      Edge* e = (*eit);
      bool found = false;
      edge_vec_it it = p2->to.begin();
      while(it != p2->to.end())
      {
        Edge* e2 = (*it);
        if(e->p1->id == e2->p1->id)
        {
          //cerr << "Found " << e->id << " " << e->p1->id << " " << e->p2->id << endl;
          edges_to_remove.push_back(e);
          found = true;
          break;
        }

        it++;
      }
      if(!found)
      {
        e->p2 = p2;
        if(e->p1->id == e->p2->id)
          edges_to_remove.push_back(e);
      }
      eit++;
    }

    //Remove double edges from
    eit = p1->from.begin();
    while(eit!=p1->from.end())
    {
      Edge* e = (*eit);
      bool found = false;
      edge_vec_it it = p2->from.begin();
      while(it != p2->from.end())
      {
        Edge* e2 = (*it);
        if(e->p2->id == e2->p2->id)
        {
          //cerr << "Found from " << e->id << " " << e->p1->id << " " <<e->p2->id << endl;
          edges_to_remove.push_back(e);
          found =true;
          break;
        }
        it++;
      }
      if(!found)
      {
        e->p1=p2;
        if(e->p1->id == e->p2->id)
          edges_to_remove.push_back(e);
      }
      eit++;
    }

    eit = edges_to_remove.begin();
    while(eit != edges_to_remove.end())
    {
      removeEdge(*eit);
      eit++;
    }

    //Append p1 edges to p2
    p2->to.insert(p2->to.end(), p1->to.begin(), p1->to.end());
    p2->from.insert(p2->from.end(),p1->from.begin(), p1->from.end());

    clock_gettime(CLOCK_REALTIME,&t1);
    t = diff(t0,t1);
    time_edges += getNanoseconds(t);

    //Can remove point p1
    clock_gettime(CLOCK_REALTIME,&t0);
    removePoint(p1);
    clock_gettime(CLOCK_REALTIME,&t1);
    t = diff(t0,t1);
    time_point+=getNanoseconds(t);

    return true;
}
Exemple #9
0
static
int dc_add_single_kf(dc_pass *pass, wchar_t *path)
{
	kf_ctx *k_ctx;
	HANDLE  h_file;
	int     resl, i;
	int     succs;
	u32     bytes;

	h_file = NULL; k_ctx = NULL;
	do
	{
		if ( (k_ctx = secure_alloc(sizeof(kf_ctx))) == NULL ) {
			resl = ST_NOMEM; break;
		}

		h_file = CreateFile(
			path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

		if (h_file == INVALID_HANDLE_VALUE) {
			h_file = NULL; resl = ST_ACCESS_DENIED; break;
		}

		/* initialize sha512 for hashing keyfile */
		sha512_init(&k_ctx->sha);

		do
		{
			succs = ReadFile(h_file, k_ctx->kf_block, KF_BLOCK_SIZE, &bytes, NULL);

			if ( (succs == 0) || (bytes == 0) ) {
				break;
			}
			sha512_hash(&k_ctx->sha, k_ctx->kf_block, bytes);
		} while (1);		
	
		/* done hasing */
		sha512_done(&k_ctx->sha, k_ctx->hash);

		/* zero unused password buffer bytes */
		zeromem(
			p8(pass->pass) + pass->size, (MAX_PASSWORD*2) - pass->size);

		/* mix the keyfile hash and password */
		for (i = 0; i < (SHA512_DIGEST_SIZE / sizeof(u32)); i++) {
			p32(pass->pass)[i] += p32(k_ctx->hash)[i];
		}
		pass->size = max(pass->size, SHA512_DIGEST_SIZE); 
		resl = ST_OK;		
	} while (0);

	if (h_file != NULL) {
		CloseHandle(h_file);
	}

	if (k_ctx != NULL) {
		secure_free(k_ctx);
	}

	return resl;
}
Exemple #10
0
GeometryTools::IntersectionStatus inPlaneLineIntersect(
    double x1, double y1,
    double x2, double y2,
    double x3, double y3,
    double x4, double y4,
    double l1NormalizedTolerance, double l2NormalizedTolerance,
    double *x, double *y, double* fractionAlongLine1, double* fractionAlongLine2)
{
   double mua, mub;
   double denom, numera, numerb;

   denom  = (y4-y3) * (x2-x1) - (x4-x3) * (y2-y1);
   numera = (x4-x3) * (y1-y3) - (y4-y3) * (x1-x3);
   numerb = (x2-x1) * (y1-y3) - (y2-y1) * (x1-x3);

    double EPS = 1e-40;

   // Are the line coincident? 
   if (fabs(numera) < EPS && fabs(numerb) < EPS && fabs(denom) < EPS) 
   {
#if 0
       *x = 0;
       *y = 0;
       *fractionAlongLine1 = 0;
       *fractionAlongLine2 = 0;
       return GeometryTools::LINES_OVERLAP;
#else
       cvf::Vec3d p12(x2-x1, y2-y1, 0);
       cvf::Vec3d p13(x3-x1, y3-y1, 0);
       cvf::Vec3d p34(x4-x3, y4-y3, 0);

       double length12 = p12.length();
       double length34 = p34.length();

       // Check if the p1 p2 line is a point
      
       if (length12 < EPS )
       {
           cvf::Vec3d p34(x4-x3, y4-y3, 0);
           *x = x1;
           *y = y1;
           *fractionAlongLine1 = 1;
           *fractionAlongLine2 = p13.length()/p34.length();
           return GeometryTools::LINES_OVERLAP;
       }

       cvf::Vec3d p14(x4-x1, y4-y1, 0);
       cvf::Vec3d p32(x2-x3, y2-y3, 0);

       cvf::Vec3d e12 = p12.getNormalized(); 
       double normDist13 =  e12*p13 / length12;
       double normDist14 =  e12*p14 / length12;

       // Check if both points on the p3 p4 line is outside line p1 p2.
       if( (normDist13 < 0 - l1NormalizedTolerance && normDist14 < 0-l1NormalizedTolerance )|| (normDist13 > 1 +l1NormalizedTolerance  && normDist14 > 1+l1NormalizedTolerance ) ) 
      {
           *x = 0;
           *y = 0;
           *fractionAlongLine1 = 0;
           *fractionAlongLine2 = 0;
          return GeometryTools::NO_INTERSECTION;
       }

       double normDist32 =  e12*p32 / length34;
       //double normDist31 = -e12*p13 / length34;

       // Set up fractions along lines to the edge2 vertex actually touching edge 1.
       /// if two, select the one furthest from the start
       bool pt3IsInside = false;
       bool pt4IsInside = false;
       if ((0.0 - l1NormalizedTolerance) <= normDist13 && normDist13 <= (1.0 +l1NormalizedTolerance) ) pt3IsInside = true;
       if ((0.0 - l1NormalizedTolerance) <= normDist14 && normDist14 <= (1.0 +l1NormalizedTolerance) ) pt4IsInside = true;

       if (pt3IsInside && !pt4IsInside)
       {
           *fractionAlongLine1 = normDist13;
           *fractionAlongLine2 = 0.0;
           *x = x3;
           *y = y3;
       }
       else if (pt4IsInside && !pt3IsInside)
       {
           *fractionAlongLine1 = normDist14;
           *fractionAlongLine2 = 1.0;
           *x = x4;
           *y = y4;
       }
       else if (pt3IsInside && pt4IsInside)
       {
           // Return edge 2 vertex furthest along edge 1
           if (normDist13 <= normDist14)
           {
               *fractionAlongLine1 =  normDist14 ;
               *fractionAlongLine2 =  1.0;
               *x = x4;
               *y = y4;
           }
           else
           {
               *fractionAlongLine1 = normDist13;
               *fractionAlongLine2 =  0.0;
               *x = x3;
               *y = y3;
           }
      }
       else // both outside on each side
       {
           // Return End of edge 1
            *fractionAlongLine1 = 1.0;
            *fractionAlongLine2 = normDist32;
            *x = x2;
            *y = y2;
       } 
  
      return GeometryTools::LINES_OVERLAP;
#endif
   }

   /* Are the line parallel */
   if (fabs(denom) < EPS) {
      *x = 0;
      *y = 0;
      *fractionAlongLine1 = 0;
      *fractionAlongLine2 = 0;

      return GeometryTools::NO_INTERSECTION;
   }

   /* Is the intersection along the the segments */
   mua = numera / denom;
   mub = numerb / denom;

   *x = x1 + mua * (x2 - x1);
   *y = y1 + mua * (y2 - y1);
   *fractionAlongLine1 = mua;
   *fractionAlongLine2 = mub;

   if (mua < 0 - l1NormalizedTolerance || 1 + l1NormalizedTolerance < mua  || mub < 0 - l2NormalizedTolerance ||  1 + l2NormalizedTolerance < mub) 
   {
      return GeometryTools::LINES_INTERSECT_OUTSIDE;
   }
   else if (fabs(mua) < l1NormalizedTolerance || fabs(1-mua) < l1NormalizedTolerance || 
            fabs(mub) < l2NormalizedTolerance || fabs(1-mub) < l2NormalizedTolerance )
   {
       if (fabs(mua)   < l1NormalizedTolerance) *fractionAlongLine1 = 0;
       if (fabs(1-mua) < l1NormalizedTolerance) *fractionAlongLine1 = 1;
       if (fabs(mub)   < l2NormalizedTolerance) *fractionAlongLine2 = 0;
       if (fabs(1-mub) < l2NormalizedTolerance) *fractionAlongLine2 = 1;
       return GeometryTools::LINES_TOUCH;
   }
   else
   {
       return GeometryTools::LINES_CROSSES;
   }
}
int main(int argc, char* argv[])
{
	CS325Graphics window(argc, argv);

	float delta = 0.1;

	Point2D p1(CS325Graphics::X_MIN, CS325Graphics::Y_MAX / 4.5);
	Point2D p2(CS325Graphics::X_MAX, CS325Graphics::Y_MAX / 4.5);
	Point2D p3(CS325Graphics::X_MIN, CS325Graphics::Y_MIN);
	Point2D p4(CS325Graphics::X_MAX, CS325Graphics::Y_MAX);

	//Points 41, 42, 45, 46 control the sandbox. DON"T MESS WITH THEM!

	Point3D p30(0.5,  0.5,-3.5);
	Point3D p31(0.5, -0.5,-3.5);
	Point3D p32(-0.5,-0.5,-3.5);
	Point3D p33(-0.5, 0.5,-3.5);
	Point3D p34(0.5,  0.5,-1.5);
	Point3D p35(0.5, -0.5,-1.5);
	Point3D p36(-0.5,-0.5,-1.5);
	Point3D p37(-0.5, 0.5,-1.5);

	Point3D p40( -70.8, 28.8, -50.8);
	Point3D p41( 50.8,-2.8,  50.8);
	Point3D p42(-50.8,-2.8,  50.8);
	Point3D p43(-58.8, 25.8,  50.8);
	Point3D p44( 50.8, 50.8, -50.8);
	Point3D p45( 50.8,-2.8, -50.8);
	Point3D p46(-50.8,-2.8, -50.8);
	Point3D p47(-84.8,-2.8, -50.8);
	Point3D p49(-8.5,22.0, 50.8);
	Point3D p48(70,20,50.8);

	Point3D p50(3.5,  0.5,-3.5);
	Point3D p51(3.5, -0.5,-3.5);
	Point3D p52(2.5,-0.5,-3.5);
	Point3D p53(2.5, 0.5,-3.5);
	Point3D p54(3.5,  0.5,-1.5);
	Point3D p55(3.5, -0.5,-1.5);
	Point3D p56(2.5,-0.5,-1.5);
	Point3D p57(2.5, 0.5,-1.5);

	Point3D p60(3.5,  0.5, 13.5);
	Point3D p61(3.5, -0.5, 13.5);
	Point3D p62(2.5,-0.5,  13.5);
	Point3D p63(2.5, 0.5,  13.5);
	Point3D p64(3.5,  0.5, 16.5);
	Point3D p65(3.5, -0.5, 16.5);
	Point3D p66(2.5,-0.5,  16.5);
	Point3D p67(2.5, 0.5,  16.5);

	

	Point2D viewPos;
	Vector2D viewDir;
	Vector3D deltaV;
	viewDir.setAngle(0);


	// move view position

	for(int i = 0; i < MOVE_TEST; i){
		/*window.DrawLineOnScreen(p1, p2);*/
		//window.DrawLineOnScreen(p4, p3);

		window.DrawLineInSpace(p30, p31);
		window.DrawLineInSpace(p31, p32);
		window.DrawLineInSpace(p32, p33);
		window.DrawLineInSpace(p33, p30);
		window.DrawLineInSpace(p34, p35);
		window.DrawLineInSpace(p35, p36);
		window.DrawLineInSpace(p36, p37);
		window.DrawLineInSpace(p37, p34);
		window.DrawLineInSpace(p30, p34);
		window.DrawLineInSpace(p31, p35);
		window.DrawLineInSpace(p32, p36);
		window.DrawLineInSpace(p33, p37);

		window.DrawLineInSpace(p50, p51);
		window.DrawLineInSpace(p51, p52);
		window.DrawLineInSpace(p52, p53);
		window.DrawLineInSpace(p53, p50);
		window.DrawLineInSpace(p54, p55);
		window.DrawLineInSpace(p55, p56);
		window.DrawLineInSpace(p56, p57);
		window.DrawLineInSpace(p57, p54);
		window.DrawLineInSpace(p50, p54);
		window.DrawLineInSpace(p51, p55);
		window.DrawLineInSpace(p52, p56);
		window.DrawLineInSpace(p53, p57);

		window.DrawLineInSpace(p60, p61);
		window.DrawLineInSpace(p61, p62);
		window.DrawLineInSpace(p62, p63);
		window.DrawLineInSpace(p63, p60);
		window.DrawLineInSpace(p64, p65);
		window.DrawLineInSpace(p65, p66);
		window.DrawLineInSpace(p66, p67);
		window.DrawLineInSpace(p67, p64);
		window.DrawLineInSpace(p60, p64);
		window.DrawLineInSpace(p61, p65);
		window.DrawLineInSpace(p62, p66);
		window.DrawLineInSpace(p63, p67);


		//window.DrawLineInSpace(p40, p41);
		window.DrawLineInSpace(p41, p42);
		window.DrawLineInSpace(p42, p43);
		//window.DrawLineInSpace(p43, p40);
		//window.DrawLineInSpace(p44, p45);
		window.DrawLineInSpace(p45, p46);
		//window.DrawLineInSpace(p46, p47);
		//window.DrawLineInSpace(p47, p44);
		window.DrawLineInSpace(p40, p45);
		window.DrawLineInSpace(p41, p45);
		window.DrawLineInSpace(p42, p46);
		window.DrawLineInSpace(p43, p47);
		window.DrawLineInSpace(p40, p47);
		window.DrawLineInSpace(p41, p49);
		window.DrawLineInSpace(p42, p49);
		window.DrawLineInSpace(p41, p48);
		window.DrawLineInSpace(p45, p48);


				if(GetAsyncKeyState(VK_DOWN)) // the DOWN arrow was pressed, let's do something
		{
		delta = -.1;
		viewPos.setY(viewPos.getY() + cos(-viewDir.getAngle())*delta);
		viewPos.setX(viewPos.getX() + sin(-viewDir.getAngle())*delta);
		window.SetViewPosition(viewPos);
		cout << "view pos: " << viewPos.toString() << endl;

		window.DisplayNow();
		Sleep(50);
				}

			if(GetAsyncKeyState(VK_UP)) // the UP arrow was pressed, let's do something
		{
		delta = .1;
		viewPos.setY(viewPos.getY() + cos(-viewDir.getAngle())*delta);
		viewPos.setX(viewPos.getX() + sin(-viewDir.getAngle())*delta);
		window.SetViewPosition(viewPos);
		cout << "view pos: " << viewPos.toString() << endl;

		window.DisplayNow();
		Sleep(50);
				}
				if(GetAsyncKeyState(VK_RIGHT)) // the RIGHT arrow was pressed, let's do something
		{
	
		delta = .1;

		viewDir.setAngle(viewDir.getAngle()+delta);
		window.SetViewDirection(viewDir);
		cout << "view dir: " << viewDir.getAngle() << endl;

		window.DisplayNow();
		Sleep(50);	
			}
			
			if(GetAsyncKeyState(VK_LEFT)) // the LEFT arrow was pressed, let's do something
		{
	
		delta = -.1;

		viewDir.setAngle(viewDir.getAngle()+delta);
		window.SetViewDirection(viewDir);
		cout << "view dir: " << viewDir.getAngle() << endl;

		window.DisplayNow();
		Sleep(50);	
			}

		if(GetAsyncKeyState(VK_ESCAPE))
		{
			return 1;
		}
	}


		
	
}
Exemple #12
0
NTSTATUS dc_drv_control_irp(PDEVICE_OBJECT dev_obj, PIRP irp)
{
	PIO_STACK_LOCATION irp_sp = IoGetCurrentIrpStackLocation(irp);
	NTSTATUS           status = STATUS_INVALID_DEVICE_REQUEST; // returned status
	ULONG              length = 0; // returned length
	//
	void              *data    = irp->AssociatedIrp.SystemBuffer;
	u32                in_len  = irp_sp->Parameters.DeviceIoControl.InputBufferLength;
	u32                out_len = irp_sp->Parameters.DeviceIoControl.OutputBufferLength;
	
	switch (irp_sp->Parameters.DeviceIoControl.IoControlCode)
	{
		case DC_GET_VERSION:
			if (irp_sp->Parameters.DeviceIoControl.OutputBufferLength != sizeof(ULONG))
			{
				status = STATUS_INVALID_PARAMETER;
				break;
			}
			*((PULONG)irp->AssociatedIrp.SystemBuffer) = DC_DRIVER_VER;
			status = STATUS_SUCCESS;
			length = sizeof(ULONG);
		break;
		case DC_CTL_CLEAR_PASS:
			dc_clean_pass_cache();
			status = STATUS_SUCCESS;
		break;
		case DC_CTL_ADD_SEED:
			if (irp_sp->Parameters.DeviceIoControl.InputBufferLength == 0)
			{
				status = STATUS_INVALID_PARAMETER;
				break;
			}
			cp_rand_add_seed(irp->AssociatedIrp.SystemBuffer, irp_sp->Parameters.DeviceIoControl.InputBufferLength);
			status = STATUS_SUCCESS;
			// prevent leaks
			RtlSecureZeroMemory(irp->AssociatedIrp.SystemBuffer, irp_sp->Parameters.DeviceIoControl.InputBufferLength);
		break;
		case DC_CTL_GET_RAND:
			if (irp_sp->Parameters.DeviceIoControl.OutputBufferLength == 0)
			{
				status = STATUS_INVALID_PARAMETER;
				break;
			}
			if ( (data = MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority)) == NULL )
			{
				status = STATUS_INSUFFICIENT_RESOURCES;
				break;
			}
			if (cp_rand_bytes(data, irp_sp->Parameters.DeviceIoControl.OutputBufferLength) == 0)
			{
				status = STATUS_INTERNAL_ERROR;
				break;
			}
			status = STATUS_SUCCESS;
			length = irp_sp->Parameters.DeviceIoControl.OutputBufferLength;
		break;
		case DC_CTL_LOCK_MEM:
			if (irp_sp->Parameters.DeviceIoControl.InputBufferLength != sizeof(DC_LOCK_MEMORY))
			{
				status = STATUS_INVALID_PARAMETER;
				break;
			}
			status = mm_lock_user_memory( PsGetProcessId(IoGetRequestorProcess(irp)), ((PDC_LOCK_MEMORY)irp->AssociatedIrp.SystemBuffer)->ptr,
				                                                                      ((PDC_LOCK_MEMORY)irp->AssociatedIrp.SystemBuffer)->length );
		break;
		case DC_CTL_UNLOCK_MEM:
			if (irp_sp->Parameters.DeviceIoControl.InputBufferLength != sizeof(PVOID*))
			{
				status = STATUS_INVALID_PARAMETER;
				break;
			}
			status = mm_unlock_user_memory( PsGetProcessId(IoGetRequestorProcess(irp)), *((PVOID*)irp->AssociatedIrp.SystemBuffer) );
		break;
		case DC_CTL_GET_FLAGS:
			if (irp_sp->Parameters.DeviceIoControl.OutputBufferLength != sizeof(DC_FLAGS))
			{
				status = STATUS_INVALID_PARAMETER;
				break;
			}
			((PDC_FLAGS)irp->AssociatedIrp.SystemBuffer)->conf_flags = dc_conf_flags;
			((PDC_FLAGS)irp->AssociatedIrp.SystemBuffer)->load_flags = dc_load_flags;
			status = STATUS_SUCCESS;
			length = sizeof(DC_FLAGS);
		break;
		case DC_CTL_SET_FLAGS:
			if (irp_sp->Parameters.DeviceIoControl.InputBufferLength != sizeof(DC_FLAGS))
			{
				status = STATUS_INVALID_PARAMETER;
				break;
			}
			dc_conf_flags = ((PDC_FLAGS)irp->AssociatedIrp.SystemBuffer)->conf_flags;

			if ( !(dc_conf_flags & CONF_CACHE_PASSWORD) ) dc_clean_pass_cache();
			dc_init_encryption();

			status = STATUS_SUCCESS;
		break;
		case DC_CTL_BSOD:
			mm_clean_secure_memory();
			dc_clean_keys();

			KeBugCheck(IRQL_NOT_LESS_OR_EQUAL);
		break;
		case DC_GET_DUMP_HELPERS: // This IOCTL is allowed only from kernel mode
			if (irp->RequestorMode != KernelMode)
			{
				status = STATUS_ACCESS_DENIED;
				break;
			}
			if (irp_sp->Parameters.DeviceIoControl.OutputBufferLength != sizeof(DC_DUMP_HELPERS))
			{
				status = STATUS_INVALID_PARAMETER;
				break;
			}

			memcpy(irp->UserBuffer, &dc_dump_helpers, sizeof(DC_DUMP_HELPERS));
			status = STATUS_SUCCESS;
			length = sizeof(DC_DUMP_HELPERS);
		break;
		//
		case DC_CTL_STATUS:
			{
				dc_ioctl  *dctl = data;
				dc_status *stat = data;
				dev_hook  *hook;

				if ( (in_len == sizeof(dc_ioctl)) && (out_len == sizeof(dc_status)) )
				{
					dctl->device[MAX_DEVICE] = 0;

					if (hook = dc_find_hook(dctl->device))
					{
						if (hook->pdo_dev->Flags & DO_SYSTEM_BOOT_PARTITION) {
							hook->flags |= F_SYSTEM;
						}

						dc_get_mount_point(hook, stat->mnt_point, sizeof(stat->mnt_point));

						stat->crypt        = hook->crypt;
						stat->dsk_size     = hook->dsk_size;
						stat->tmp_size     = hook->tmp_size;
						stat->flags        = hook->flags;
						stat->mnt_flags    = hook->mnt_flags;
						stat->disk_id      = hook->disk_id;
						stat->paging_count = hook->paging_count;
						stat->vf_version   = hook->vf_version;
						status             = STATUS_SUCCESS; 
						length             = sizeof(dc_status);

						dc_deref_hook(hook);
					}
				}
			}
		break;
		case DC_CTL_BENCHMARK:
			{
				 if ( (in_len == sizeof(int)) && (out_len == sizeof(dc_bench_info)) )
				 {
					 if (dc_k_benchmark(p32(data)[0], pv(data)) == ST_OK) {
						 status = STATUS_SUCCESS; 
						 length = sizeof(dc_bench_info);
					 }
				 }
			}
		break;
		
		case DC_BACKUP_HEADER:
			{
				dc_backup_ctl *back = data;
				
				if ( (in_len == sizeof(dc_backup_ctl)) && (out_len == in_len) )
				{
					back->device[MAX_DEVICE] = 0;

					back->status = dc_backup_header(back->device, &back->pass, back->backup);

					/* prevent leaks */
					burn(&back->pass, sizeof(back->pass));

					status = STATUS_SUCCESS;
					length = sizeof(dc_backup_ctl);
				}
			}
		break;
		case DC_RESTORE_HEADER:
			{
				dc_backup_ctl *back = data;
				
				if ( (in_len == sizeof(dc_backup_ctl)) && (out_len == in_len) )
				{
					back->device[MAX_DEVICE] = 0;

					back->status = dc_restore_header(back->device, &back->pass, back->backup);

					/* prevent leaks */
					burn(&back->pass, sizeof(back->pass));

					status = STATUS_SUCCESS;
					length = sizeof(dc_backup_ctl);
				}
			}
		break;
		default: 
			{
				dc_ioctl *dctl = data;

				if ( (in_len == sizeof(dc_ioctl)) && (out_len == sizeof(dc_ioctl)) )
				{					
					/* limit null-terminated string length */
					dctl->device[MAX_DEVICE] = 0;
					
					/* process IOCTL */
					dctl->status = dc_ioctl_process(irp_sp->Parameters.DeviceIoControl.IoControlCode, dctl);

					/* prevent leaks  */
					burn(&dctl->passw1, sizeof(dctl->passw1));
					burn(&dctl->passw2, sizeof(dctl->passw2));

					status = STATUS_SUCCESS;
					length = sizeof(dc_ioctl);
				}
			}
		break;
	}
	return dc_complete_irp(irp, status, length);
}
Exemple #13
0
static int pe2mod(wchar_t *in, wchar_t *out) 
{
	IMAGE_DOS_HEADER     *d_head;
	IMAGE_NT_HEADERS     *n_head;
	IMAGE_SECTION_HEADER *t_sect;
	boot_mod             *b_mod = NULL;
	HMODULE               image = NULL;
	u32                  *reloc = NULL;
	int                   resl  = 1;
	u32                   r_num, offs;
	HANDLE                h_out;
	u32                   i, found;
	u32                   code_off;
	u32                   bytes, n;
	u8                   *s_data;
	u32                   s_size;

	do
	{
		if ( (image = LoadLibraryEx(in, NULL, DONT_RESOLVE_DLL_REFERENCES)) == NULL ) {
			break;
		}
		d_head = pv(dSZ(image) & ~(PAGE_SIZE - 1));
		n_head = addof(d_head, d_head->e_lfanew);
		t_sect = IMAGE_FIRST_SECTION(n_head);
		found  = 0;

		/* find '.text' section */
		for (i = 0; i < n_head->FileHeader.NumberOfSections; i++, t_sect++) {
			if (_stricmp(t_sect->Name, ".text") == 0) {	found = 1; break; }
		}
		if (found == 0) {
			wprintf(L"Invalid PE image %s, section '.text' is not found\n", in); 
			break;
		}
		if ( (reloc = calloc(1, n_head->OptionalHeader.SizeOfImage)) == NULL ) {
			break;
		}
		if ( (b_mod = calloc(1, n_head->OptionalHeader.SizeOfImage)) == NULL ) {
			break;
		}
		if (r_num = pe_save_relocs(d_head, reloc)) 
		{
			/* save needed relocs */
			for (i = 0, n = 0; i < r_num; i++) 
			{
				if (in_reg(reloc[i], t_sect->VirtualAddress, t_sect->Misc.VirtualSize) != 0) {
					b_mod->relocs[n++] = reloc[i]; 
				}
			}
			b_mod->n_rels = n;
			code_off = _align(sizeof(boot_mod) + n * sizeof(u32), 16);			
		} else {
			code_off = _align(sizeof(boot_mod), 16);
		}
		s_data = addof(d_head, t_sect->VirtualAddress);
		s_size = t_sect->SizeOfRawData;

		/* find minimum section RAW size */
		for (i = t_sect->SizeOfRawData - 1; i != 0; i--, s_size--) {
			if (s_data[i] != 0) break;
		}
		b_mod->mod_sign  = 'DCBM';
		b_mod->raw_size  = s_size + code_off;
		b_mod->virt_size = t_sect->Misc.VirtualSize + code_off;
		b_mod->entry_rva = n_head->OptionalHeader.AddressOfEntryPoint - 
			t_sect->VirtualAddress + code_off;

		memcpy(addof(b_mod, code_off), s_data, s_size);

		/* rebase image and fix relocs */
		for (i = 0; i < b_mod->n_rels; i++)
		{
			offs = b_mod->relocs[i] - t_sect->VirtualAddress + code_off;			
			p32(addof(b_mod, offs))[0] -= n_head->OptionalHeader.ImageBase + 
				t_sect->VirtualAddress - code_off;
			b_mod->relocs[i] = offs;
		}
		h_out = CreateFile(
			out, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);

		if (h_out != INVALID_HANDLE_VALUE) 
		{
			if (WriteFile(h_out, b_mod, b_mod->raw_size, &bytes, NULL) != 0) 
			{
				wprintf(L"Boot module OK (Virtual size: %d, Raw size: %d, EP: %d)\n", 
					b_mod->virt_size, b_mod->raw_size, b_mod->entry_rva);
				resl = 0;
			}
			CloseHandle(h_out);
		} else {
			wprintf(L"Can not write to %s", out);
		}
	} while (0);

	if (reloc != NULL) { free(reloc); }
	if (b_mod != NULL) { free(b_mod); }
	if (image != NULL) { FreeLibrary(image); }

	return resl;
}
Exemple #14
0
int main(int argc, char** argv)
{
  // parse command
  unsigned int pos = 1;
  unsigned int mask = (argc >= 2) ? 0 : 0xFFFF;
  while(pos < argc)
  {
    unsigned int sceneNumber = atoi(argv[pos++]);
    mask |= 1 << sceneNumber;
  }


  // Initialize
  phong p32(32.0f);
  phong p64(64.0f);
  phong p16(16.0f);
  diffuse d;
  constantAlbedo red(color(1.0f, 0.0f, 0.0f));
  constantAlbedo green(color(0.0f, 1.0f, 0.0f));
  constantAlbedo blue(color(0.0f, 0.0f, 1.0f));
  constantAlbedo white(color(1.0f, 1.0f, 1.0f));

  std::vector<triangle> sphere = createSphere( vec3d(0.0f, 0.0f, 0.0f), 1.0f, 16, 16 );
  std::vector<triangle> plane = createPlane( vec3d(-1.0f, -1.0f, 0.0f), vec3d(0.0f, 2.0f, 0.0f), vec3d(2.0f, 0.0f, 0.0f) );

  material redMaterial;
  redMaterial.addComponent( reflectanceComponent(&red, &d) );
  redMaterial.addComponent( reflectanceComponent(&white, &p32) );

  material greenMaterial;
  greenMaterial.addComponent( reflectanceComponent(&green, &d) );
  greenMaterial.addComponent( reflectanceComponent(&white, &p64) );

  material blueMaterial;
  blueMaterial.addComponent( reflectanceComponent(&blue, &d) );
  blueMaterial.addComponent( reflectanceComponent(&white, &p16) );

  material whiteMaterial;
  whiteMaterial.addComponent( reflectanceComponent(&white, &d) );

  triangleMesh redSphere(sphere, redMaterial);
  triangleMesh greenSphere(sphere, greenMaterial);
  triangleMesh blueSphere(sphere, blueMaterial);
  triangleMesh whitePlane(plane, whiteMaterial);

  sceneGraphObject redSphereObject(redSphere);
  sceneGraphObject greenSphereObject(greenSphere);
  sceneGraphObject blueSphereObject(blueSphere);
  sceneGraphObject whitePlaneObject(whitePlane);

  camera cam( vec3d(0.0f, 0.0f, 5.0f),
	      vec3d(0.0f, 0.0f, -1.0f),
	      vec3d(0.0f, 1.0f, 0.0f),
	      35.0f * M_PI / 180.0f,
	      512, 512 );

  directionalLightsource ls( color(1.0f, 1.0f, 1.0f), vec3d(0.0f, -1.0f, -1.0f) );
  directionalLightsource frontal( color(1.0f, 1.0f, 1.0f), vec3d(0.0f, 0.0f, -1.0f) );


  /////////////////////////////////////////////////////

  if((mask & 2) != 0)
  {
    sceneGraphNode sg1;
    sg1.addChildNode(redSphereObject);
  
    std::cout << "Generating Image 1." << std::endl;
    image result1 = generateImage(cam, sg1, ls);
    result1.save("hw4-result1.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 4) != 0)
  {
    sceneGraphNode sg2node1(translation3d(vec3d(+1.0f, 0.0f, 0.0f)));
    sg2node1.addChildNode(redSphereObject);

    sceneGraphNode sg2node2(translation3d(vec3d(-1.0f, 0.0f, 0.0f)));
    sg2node2.addChildNode(blueSphereObject);

    sceneGraphNode sg2;
    sg2.addChildNode(sg2node1);
    sg2.addChildNode(sg2node2);

    std::cout << "Generating Image 2." << std::endl;
    image result2 = generateImage(cam, sg2, ls);
    result2.save("hw4-result2.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 8) != 0)
  {
    sceneGraphNode sg3node1(scale3d(2.0f, 0.5f, 0.5f));
    sg3node1.addChildNode(greenSphereObject);

    sceneGraphNode sg3;
    sg3.addChildNode(sg3node1);
  
    std::cout << "Generating Image 3." << std::endl;
    image result3 = generateImage(cam, sg3, ls);
    result3.save("hw4-result3.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 16) != 0)
  {
    sceneGraphNode sg2node1(translation3d(vec3d(+1.0f, 0.0f, 0.0f)));
    sg2node1.addChildNode(redSphereObject);

    sceneGraphNode sg2node2(translation3d(vec3d(-1.0f, 0.0f, 0.0f)));
    sg2node2.addChildNode(blueSphereObject);

    sceneGraphNode sg2;
    sg2.addChildNode(sg2node1);
    sg2.addChildNode(sg2node2);

    sceneGraphNode sg4node1(rotationY3d(M_PI));
    sg4node1.addChildNode(sg2);

    sceneGraphNode sg4;
    sg4.addChildNode(sg4node1);
  
    std::cout << "Generating Image 4." << std::endl;
    image result4 = generateImage(cam, sg4, ls);
    result4.save("hw4-result4.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 32) != 0)
  {
    sceneGraphNode sg5node0(scale3d(0.5f, 0.5f, 0.5f));
    sceneGraphNode sg5node1(rotationY3d(0.5 * M_PI));
    sceneGraphNode sg5node2(rotationX3d(0.5 * M_PI));
    sceneGraphNode sg5node3(translation3d(vec3d(0.0f, 2.0f, 0.0f)));
    sceneGraphNode sg5node4(rotationX3d(0.5 * M_PI));
    sceneGraphNode sg5node5(translation3d(vec3d(0.0f, 2.0f, 0.0f)));
    sceneGraphNode sg5node6(rotationX3d(0.5 * M_PI));
    sceneGraphNode sg5node7(translation3d(vec3d(0.0f, 2.0f, 0.0f)));
    sceneGraphNode sg5node8(rotationX3d(0.5 * M_PI));
    sceneGraphNode sg5node9(translation3d(vec3d(0.0f, 2.0f, 0.0f)));

    sceneGraphNode sg5;
    sg5.addChildNode(sg5node0);
    sg5node0.addChildNode(sg5node1);
    sg5node1.addChildNode(sg5node2);
    sg5node2.addChildNode(sg5node3);
    sg5node3.addChildNode(redSphereObject);
    sg5node3.addChildNode(sg5node4);
    sg5node4.addChildNode(sg5node5);
    sg5node5.addChildNode(greenSphereObject);
    sg5node5.addChildNode(sg5node6);
    sg5node6.addChildNode(sg5node7);
    sg5node7.addChildNode(blueSphereObject);
    sg5node7.addChildNode(sg5node8);
    sg5node8.addChildNode(sg5node9);
    sg5node9.addChildNode(blueSphereObject);
    
    std::cout << "Generating Image 5." << std::endl;
    image result5 = generateImage(cam, sg5, ls);
    result5.save("hw4-result5.ppm");
  }


  /////////////////////////////////////////////////////

  if((mask & 64) != 0)
  {
    sceneGraphNode cubeside( translation3d(vec3d(0.0f, 0.0f, 1.0f)) );
    cubeside.addChildNode(whitePlaneObject);

    sceneGraphNode cubeNode1( rotationY3d(0.0f / 2.0f * M_PI) );
    cubeNode1.addChildNode(cubeside);
    sceneGraphNode cubeNode2( rotationY3d(1.0f / 2.0f * M_PI) );
    cubeNode2.addChildNode(cubeside);
    sceneGraphNode cubeNode3( rotationY3d(2.0f / 2.0f * M_PI) );
    cubeNode3.addChildNode(cubeside);
    sceneGraphNode cubeNode4( rotationY3d(3.0f / 2.0f * M_PI) );
    cubeNode4.addChildNode(cubeside);
    sceneGraphNode cubeNode5( rotationX3d(0.5f * M_PI) );
    cubeNode5.addChildNode(cubeside);
    sceneGraphNode cubeNode6( rotationX3d(-0.5f * M_PI) );
    cubeNode6.addChildNode(cubeside);
    
    sceneGraphNode cube;
    cube.addChildNode(cubeNode1);
    cube.addChildNode(cubeNode2);
    cube.addChildNode(cubeNode3);
    cube.addChildNode(cubeNode4);
    cube.addChildNode(cubeNode5);
    cube.addChildNode(cubeNode6);
    
    sceneGraphNode sg6( rotation3d(0.25*M_PI, vec3d(1.0f, 0.75f, 0.5f)) );
    sg6.addChildNode(cube);
  
    std::cout << "Generating Image 6." << std::endl;
    image result6 = generateImage(cam, sg6, frontal);
    result6.save("hw4-result6.ppm");
  }

  // Done.
  return 0;
}
Exemple #15
0
void boot_main()
{
	list_entry *entry;
	hdd_inf    *hdd;
	prt_inf    *prt, *active;
	char       *error;
	int         login, i;
	int         n_mount;

	active = NULL; error = NULL;
	login = 0; n_mount = 0;

	/* init crypto */
	dc_init_crypto(conf.options & OP_HW_CRYPTO);

	/* prepare MBR copy buffer */
	autocpy(conf.save_mbr + 432, p8(0x7C00) + 432, 80);

	if (dc_scan_partitions() == 0) {
		error = "partitions not found\n";
		goto error;
	}

	if (hdd = find_hdd(boot_dsk))
	{
		/* find active partition on boot disk */
		entry = hdd->part_head.flink;
		
		while (entry != &hdd->part_head)
		{
			prt   = contain_record(entry, prt_inf, entry_hdd);
			entry = entry->flink;

			if (prt->active != 0) {
				active = prt; break;
			}
		}
	}
retry_auth:;	
	if (conf.logon_type & LT_GET_PASS) 
	{
		login = dc_get_password();

		if ( (conf.options & OP_NOPASS_ERROR) && (login == 0) ) 
		{
			dc_password_error(active);

			if (conf.error_type & ET_RETRY) {
				goto retry_auth;
			} else {
				/* halt system */
				__halt();
			}
		}
	}

	/* add embedded keyfile to password buffer */
	if (conf.logon_type & LT_EMBED_KEY) 
	{
		sha512_ctx sha;
		u8         hash[SHA512_DIGEST_SIZE];

		sha512_init(&sha);
		sha512_hash(&sha, conf.emb_key, sizeof(conf.emb_key));
		sha512_done(&sha, hash);

		/* mix the keyfile hash and password */
		for (i = 0; i < (SHA512_DIGEST_SIZE / sizeof(u32)); i++) {
			p32(bd_dat->password.pass)[i] += p32(hash)[i];
		}
		bd_dat->password.size = max(bd_dat->password.size, SHA512_DIGEST_SIZE);

		/* prevent leaks */
		zeroauto(hash, sizeof(hash));
		zeroauto(&sha, sizeof(sha));
	}

	if (bd_dat->password.size != 0) 
	{
		if (n_mount = dc_mount_parts()) {
			/* hook BIOS interrupts */
			bios_hook_ints();
		} else {
			/* clean password buffer to prevent leaks */
			zeroauto(&bd_dat->password, sizeof(dc_pass));
		}
	}

	if ( (n_mount == 0) && (login != 0) ) 
	{
		dc_password_error(active);

		if (conf.error_type & ET_RETRY) {
			goto retry_auth;
		} else {
			/* halt system */
			__halt();
		}
	}
	
	switch (conf.boot_type)
	{
		case BT_MBR_BOOT: 			  
		  {
			  if (hdd == NULL) {
				  error = "boot disk not found\n";
				  goto error;
			  }
			  boot_from_mbr(hdd, n_mount);
		  }
	    break;
		case BT_MBR_FIRST: 
		  {
			  if ( (hdd = find_bootable_hdd()) == NULL ) {
				  error = "boot disk not found\n";
				  goto error;
			  }			 			  
			  boot_from_mbr(hdd, n_mount);
		  }
	    break;
		case BT_ACTIVE:
		  {
			  if (active == NULL) {
				  error = "active partition not found\n";
				  goto error;
			  } else {	  
				  boot_from_partition(active, n_mount);
			  }
		  }
	  	break;
		case BT_AP_PASSWORD:
		  {
			  /* find first partition with appropriate password */
			  entry = prt_head.flink;

			  while (entry != &prt_head)
			  {
				  prt   = contain_record(entry, prt_inf, entry_glb);
				  entry = entry->flink;

				  if ( (prt->extend == 0) && (prt->mnt_ok != 0) ) {
					  boot_from_partition(prt, n_mount);
				  }
			  }

			  error = "bootable partition not mounted\n";
			  goto error;
		  }
	    break;
		case BT_DISK_ID:
		  {
			  /* find partition by disk_id */
			  entry = prt_head.flink;

			  while (entry != &prt_head)
			  {
				  prt   = contain_record(entry, prt_inf, entry_glb);
				  entry = entry->flink;

				  if ( (prt->extend == 0) && (prt->mnt_ok != 0) &&
					   (prt->disk_id == conf.disk_id) ) 
				  {
					  boot_from_partition(prt, n_mount);
				  }
			  }
			  
			  error = "disk_id equal partition not found\n";
			  goto error;
		  }
		break;
	}

error:;
	if (error != NULL) {
		puts(error); 
	}	
	while (1);
}
Exemple #16
0
static void
print_espstats(const struct espstat *espstat)
{
#define	p32(f, m) if (espstat->f || sflag <= 1) \
    printf("\t%u" m, (unsigned int)espstat->f, plural(espstat->f))
#define	p64(f, m) if (espstat->f || sflag <= 1) \
    printf("\t%ju" m, (uintmax_t)espstat->f, plural(espstat->f))
#define	hist(f, n, t) \
    ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t));

	p32(esps_hdrops, " packet%s shorter than header shows\n");
	p32(esps_nopf, " packet%s dropped; protocol family not supported\n");
	p32(esps_notdb, " packet%s dropped; no TDB\n");
	p32(esps_badkcr, " packet%s dropped; bad KCR\n");
	p32(esps_qfull, " packet%s dropped; queue full\n");
	p32(esps_noxform, " packet%s dropped; no transform\n");
	p32(esps_badilen, " packet%s dropped; bad ilen\n");
	p32(esps_wrap, " replay counter wrap%s\n");
	p32(esps_badenc, " packet%s dropped; bad encryption detected\n");
	p32(esps_badauth, " packet%s dropped; bad authentication detected\n");
	p32(esps_replay, " possible replay packet%s detected\n");
	p32(esps_input, " packet%s in\n");
	p32(esps_output, " packet%s out\n");
	p32(esps_invalid, " packet%s dropped; invalid TDB\n");
	p64(esps_ibytes, " byte%s in\n");
	p64(esps_obytes, " byte%s out\n");
	p32(esps_toobig, " packet%s dropped; larger than IP_MAXPACKET\n");
	p32(esps_pdrops, " packet%s blocked due to policy\n");
	p32(esps_crypto, " crypto processing failure%s\n");
	p32(esps_tunnel, " tunnel sanity check failure%s\n");
	hist(espstat->esps_hist, ipsec_espnames, "ESP output");

#undef p32
#undef p64
#undef hist
}
Exemple #17
0
static void
print_ipcompstats(const struct ipcompstat *ipcompstat)
{
	uint32_t version;
#define	p32(f, m) if (ipcompstat->f || sflag <= 1) \
    printf("\t%u" m, (unsigned int)ipcompstat->f, plural(ipcompstat->f))
#define	p64(f, m) if (ipcompstat->f || sflag <= 1) \
    printf("\t%ju" m, (uintmax_t)ipcompstat->f, plural(ipcompstat->f))
#define	hist(f, n, t) \
    ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t));

#ifndef IPCOMPSTAT_VERSION
	version = 0;
#else
	version = ipcompstat->version;
#endif
	p32(ipcomps_hdrops, " packet%s shorter than header shows\n");
	p32(ipcomps_nopf, " packet%s dropped; protocol family not supported\n");
	p32(ipcomps_notdb, " packet%s dropped; no TDB\n");
	p32(ipcomps_badkcr, " packet%s dropped; bad KCR\n");
	p32(ipcomps_qfull, " packet%s dropped; queue full\n");
	p32(ipcomps_noxform, " packet%s dropped; no transform\n");
	p32(ipcomps_wrap, " replay counter wrap%s\n");
	p32(ipcomps_input, " packet%s in\n");
	p32(ipcomps_output, " packet%s out\n");
	p32(ipcomps_invalid, " packet%s dropped; invalid TDB\n");
	p64(ipcomps_ibytes, " byte%s in\n");
	p64(ipcomps_obytes, " byte%s out\n");
	p32(ipcomps_toobig, " packet%s dropped; larger than IP_MAXPACKET\n");
	p32(ipcomps_pdrops, " packet%s blocked due to policy\n");
	p32(ipcomps_crypto, " crypto processing failure%s\n");
	hist(ipcompstat->ipcomps_hist, ipsec_compnames, "COMP output");
	if (version >= 1) {
	p32(ipcomps_threshold, " packet%s sent uncompressed; size < compr. algo. threshold\n");
	p32(ipcomps_uncompr, " packet%s sent uncompressed; compression was useless\n");
	}

#undef p32
#undef p64
#undef hist
}
Exemple #18
0
NTSTATUS dc_drv_control_irp(PDEVICE_OBJECT dev_obj, PIRP irp)
{
	PIO_STACK_LOCATION  irp_sp  = IoGetCurrentIrpStackLocation(irp);
	NTSTATUS            status  = STATUS_INVALID_DEVICE_REQUEST;
	void               *data    = irp->AssociatedIrp.SystemBuffer;
	u32                 in_len  = irp_sp->Parameters.DeviceIoControl.InputBufferLength;
	u32                 out_len = irp_sp->Parameters.DeviceIoControl.OutputBufferLength;
	u32                 code    = irp_sp->Parameters.DeviceIoControl.IoControlCode;
	u32                 bytes   = 0;
	
	switch (code)
	{
		case DC_GET_VERSION:
			{
				if (out_len == sizeof(u32)) 
				{
					p32(data)[0] = DC_DRIVER_VER;
					bytes        = sizeof(u32);
					status       = STATUS_SUCCESS;
				}
			}
		break;
		case DC_CTL_CLEAR_PASS:
			{
				dc_clean_pass_cache();
				status = STATUS_SUCCESS;
			}
		break;		
		case DC_CTL_STATUS:
			{
				dc_ioctl  *dctl = data;
				dc_status *stat = data;
				dev_hook  *hook;

				if ( (in_len == sizeof(dc_ioctl)) && (out_len == sizeof(dc_status)) )
				{
					dctl->device[MAX_DEVICE] = 0;

					if (hook = dc_find_hook(dctl->device))
					{
						if (hook->pdo_dev->Flags & DO_SYSTEM_BOOT_PARTITION) {
							hook->flags |= F_SYSTEM;
						}

						dc_get_mount_point(hook, stat->mnt_point, sizeof(stat->mnt_point));

						stat->crypt        = hook->crypt;
						stat->dsk_size     = hook->dsk_size;
						stat->tmp_size     = hook->tmp_size;
						stat->flags        = hook->flags;
						stat->mnt_flags    = hook->mnt_flags;
						stat->disk_id      = hook->disk_id;
						stat->paging_count = hook->paging_count;
						stat->vf_version   = hook->vf_version;
						status             = STATUS_SUCCESS; 
						bytes              = sizeof(dc_status);

						dc_deref_hook(hook);
					}
				}
			}
		break;
		case DC_CTL_ADD_SEED:
			{
				 if (in_len != 0) 
				 {
					 cp_rand_add_seed(data, in_len);
					 status = STATUS_SUCCESS;
					 /* prevent leaks */
					 burn(data, in_len);
				 }
			}
		break;
		case DC_CTL_GET_RAND:
			{
				dc_rand_ctl *rctl = data;
				
				if (in_len == sizeof(dc_rand_ctl))
				{
					__try
					{
						ProbeForWrite(rctl->buff, rctl->size, sizeof(u8));

						if (cp_rand_bytes(rctl->buff, rctl->size) != 0) {
							status = STATUS_SUCCESS;
						}
					} 
					__except(EXCEPTION_EXECUTE_HANDLER) {
						status = GetExceptionCode();
					}
				}
			}
		break;
		case DC_CTL_BENCHMARK:
			{
				 if ( (in_len == sizeof(int)) && (out_len == sizeof(dc_bench_info)) )
				 {
					 if (dc_k_benchmark(p32(data)[0], pv(data)) == ST_OK) {
						 status = STATUS_SUCCESS; 
						 bytes  = sizeof(dc_bench_info);
					 }
				 }
			}
		break;
		case DC_CTL_BSOD:
			{
				lock_inc(&dc_dump_disable);
				dc_clean_pass_cache();
				mm_unlock_user_memory(NULL, NULL);
				dc_clean_keys();

				KeBugCheck(IRQL_NOT_LESS_OR_EQUAL);
			}
		break;
		case DC_CTL_GET_CONF:
			{
				dc_conf *conf = data;

				if (out_len == sizeof(dc_conf)) {
					conf->conf_flags = dc_conf_flags;
					conf->load_flags = dc_load_flags;
					status = STATUS_SUCCESS;
					bytes  = sizeof(dc_conf);
				}
			}
		break;
		case DC_CTL_SET_CONF:
			{
				dc_conf *conf = data;
				
				if (in_len == sizeof(dc_conf))
				{
					dc_conf_flags = conf->conf_flags;
					status        = STATUS_SUCCESS;

					if ( !(dc_conf_flags & CONF_CACHE_PASSWORD) ) {
						dc_clean_pass_cache();
					}
					dc_init_encryption();
				}
			}
		break;
		case DC_CTL_LOCK_MEM:
			{
				PEPROCESS    process = IoGetRequestorProcess(irp);
				dc_lock_ctl *smem = data;				

				if ( (process != NULL) && (in_len == sizeof(dc_lock_ctl)) && (out_len == in_len) ) 
				{
					smem->resl = mm_lock_user_memory(smem->data, smem->size, process);

					status = STATUS_SUCCESS; bytes = sizeof(dc_lock_ctl);
				}
			}
		break;
		case DC_CTL_UNLOCK_MEM:
			{
				PEPROCESS    process = IoGetRequestorProcess(irp);
				dc_lock_ctl *smem = data;

				if ( (process != NULL) && (in_len == sizeof(dc_lock_ctl)) && (out_len == in_len) )
				{
					mm_unlock_user_memory(smem->data, process);

					status = STATUS_SUCCESS; bytes = sizeof(dc_lock_ctl);
					smem->resl = ST_OK;
				}
			}
		break; 
		case DC_BACKUP_HEADER:
			{
				dc_backup_ctl *back = data;
				
				if ( (in_len == sizeof(dc_backup_ctl)) && (out_len == in_len) )
				{
					back->device[MAX_DEVICE] = 0;

					back->status = dc_backup_header(back->device, &back->pass, back->backup);

					/* prevent leaks */
					burn(&back->pass, sizeof(back->pass));

					status = STATUS_SUCCESS;
					bytes  = sizeof(dc_backup_ctl);
				}
			}
		break;
		case DC_RESTORE_HEADER:
			{
				dc_backup_ctl *back = data;
				
				if ( (in_len == sizeof(dc_backup_ctl)) && (out_len == in_len) )
				{
					back->device[MAX_DEVICE] = 0;

					back->status = dc_restore_header(back->device, &back->pass, back->backup);

					/* prevent leaks */
					burn(&back->pass, sizeof(back->pass));

					status = STATUS_SUCCESS;
					bytes  = sizeof(dc_backup_ctl);
				}
			}
		break;
		default: 
			{
				dc_ioctl *dctl = data;

				if ( (in_len == sizeof(dc_ioctl)) && (out_len == sizeof(dc_ioctl)) )
				{					
					/* limit null-terminated string length */
					dctl->device[MAX_DEVICE] = 0;
					
					/* process IOCTL */
					dctl->status = dc_ioctl_process(code, dctl);

					/* prevent leaks  */
					burn(&dctl->passw1, sizeof(dctl->passw1));
					burn(&dctl->passw2, sizeof(dctl->passw2));

					status = STATUS_SUCCESS;
					bytes  = sizeof(dc_ioctl);
				}
			}
		break;
	}