Пример #1
0
UnitReference GatherAction::nearest_dropsite() {

	// find nearest dropsite from the targeted resource
	auto ds = find_near(*this->target.get()->location,
		[=](const TerrainObject &obj) {
			return &obj.unit != this->entity &&
			       &obj.unit != this->target.get() &&
			       obj.unit.has_attribute(attr_type::building) &&
			       obj.unit.has_attribute(attr_type::owner) &&
			       obj.unit.get_attribute<attr_type::owner>().player.owns(*this->entity);
	});

	if (ds) {
		return ds->unit.get_ref();
	}
	else {
		this->entity->log(MSG(dbg) << "no dropsite found");
		return UnitReference();
	}
}
int main(int argc, char* argv[])
{
FILE * Temp_File;
    if ( argc < 11 ) /* argc should be 2 for correct execution */
    {
        /* We print argv[0] assuming it is the program name */
        printf( "Correct arguments: %s host_postgis port dbname user password tolerance tablename shapefilewithoutdotshp EPSG:CODE precision output.csv", argv[0] );
    }
Temp_File = fopen (argv[11],"w");
//verifica se o arquivo shape esta abrindo
char nomeX_metadado[150];
char nomefolha[30];
char nomeshp[100];
int number_of_points;
strcpy (nomefolha,argv[8]);
strcpy (nomeX_metadado,nomefolha);
strcpy (nomeshp,nomefolha);
set_output_metadata(nomeX_metadado);
find_file_shp(nomeshp,nomeX_metadado);
number_of_points = count_shape_points(nomeshp);
for (int b = 0; b < number_of_points; b++)
{

double *point;


point = get_coordinate_point(b,nomeshp);
// Cria uma conexão com um banco PostgreSQL

PGconn *conn = PQsetdbLogin(
argv[1], // host
argv[2], // port
NULL, // options
NULL, // tty
argv[3], // dbName
argv[4], // login
argv[5] // password
);
printf("\n");
printf("Point Shapefile: ");
fprintf(Temp_File,"Point Shapefile;");
for (int i = 0; i < 3; i++)
{
printf("%f ",point[i]);
char shpoint[16];
char * dot1;
sprintf(shpoint,"%f", point[i]);
dot1 = strchr(shpoint,'.');
if (dot1){*dot1 = ',';}
fprintf(Temp_File,"%s;",shpoint);
}
double *result;
result = find_near(conn,point[0], point[1],point[2],atof(argv[6]),argv[7],argv[9],atof(argv[10]));
printf("Point Near: ");
fprintf(Temp_File,"Point Near;");
for (int i = 0; i < 3; i++)
{
printf("%f ",result[i]);
char resultpoint[16];
char * dot2;
sprintf(resultpoint,"%f", result[i]);
dot2 = strchr(resultpoint,'.');
if (dot2){*dot2 = ',';}
fprintf(Temp_File,"%s;",resultpoint);
}
printf("\n");
fprintf(Temp_File,"\n");
// Fecha a conexão com o banco
PQfinish(conn);
}
fclose (Temp_File);
return 0;
}
Пример #3
0
void throw_hook(void *orig, void *repl, void **orig_ptr)
{
  //__DBG("throw_hook: (%p)\n", orig);
    opst x;
#ifdef __x86_64__
    x.a = 0xb848; // mov rax, target
    x.c = 0xc350; // pop rax; ret
#elif __i386__
    x.a = 0xE9;   // abs jump
#endif
    
    pthread_mutex_lock(&hook_lck);

    void *tramp = zalloc(&zone_free_list);

    int hook_size = sizeof(opst);
    
#ifdef __x86_64__
#ifdef __x86_64__COMPACT_HOOK
    opst_compact xc;
    vm_address_t nalloc=0;
    xc.a = 0xE9;
    if (IS_NEAR(orig,repl)) {
        printf("no trampoline needed for short jump to %p from %p\n", repl, orig);
        hook_size = sizeof(opst_compact);
    } else
    if (( nalloc = find_near((vm_address_t)orig)) != 0) {
        printf("allocated trampoline at %p\n", nalloc);
        hook_size = sizeof(opst_compact);
        x.b = (native_word_t) repl - ABSJUMP_SUB(orig);
        memcpy((void*)nalloc, &x, sizeof(x));
        repl = (void*) nalloc;
        assert(IS_NEAR(orig,repl));
    }
#endif
#endif
    
    // orig_ptr
    size_t eaten = eat_instructions(orig, hook_size);
    if (!eaten) {
        printf("throw_hook: eaten = 0, couldn't analyse function to hook\n");
        goto out;
    }
    
    x.b = (native_word_t) repl - ABSJUMP_SUB(orig);

    vm_protect(mach_task_self_, (vm_address_t)orig, PAGE_SIZE, 0, VM_PROT_ALL);
    vm_protect(mach_task_self_, (vm_address_t)orig+sizeof(opst), PAGE_SIZE, 0, VM_PROT_ALL);
    
#ifdef __x86_64__
#ifdef __x86_64__COMPACT_HOOK
    if ( hook_size == sizeof(opst_compact) ) {
        xc.b =  (uint32_t) (repl - ABSJUMP_SUB_COMPACT(orig));
        memcpy(tramp, orig, eaten);
        memset(orig, 0x90, eaten);
        memcpy(orig, &xc, sizeof(opst_compact));
    } else
#endif
#endif
    {
        memcpy(tramp, orig, eaten);
        memset(orig, 0x90, eaten);
        memcpy(orig, &x, sizeof(opst));
    }
    x.b = (native_word_t) (orig + eaten) - ABSJUMP_SUB(tramp+eaten);
    
    memcpy(tramp+eaten, &x, sizeof(opst));
    
    vm_protect(mach_task_self_, (vm_address_t)orig, PAGE_SIZE, 0, VM_PROT_READ|VM_PROT_EXECUTE);
    vm_protect(mach_task_self_, (vm_address_t)orig+sizeof(opst), PAGE_SIZE, 0, VM_PROT_READ|VM_PROT_EXECUTE);

    if (orig_ptr) {
        *orig_ptr = tramp;
    }
out:
    pthread_mutex_unlock(&hook_lck);
}