码迷,mamicode.com
首页 > 其他好文 > 详细

model number

时间:2014-05-05 10:52:44      阅读:370      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   class   code   java   

bubuko.com,布布扣
// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "winioctl.h"


#define IOCTL_STORAGE_QUERY_PROPERTY CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS)


typedef enum _STORAGE_QUERY_TYPE {PropertyStandardQuery = 0,PropertyExistsQuery,PropertyMaskQuery,PropertyQueryMaxDefined} STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE;

typedef enum _STORAGE_PROPERTY_ID {StorageDeviceProperty = 0,StorageAdapterProperty} STORAGE_PROPERTY_ID, *PSTORAGE_PROPERTY_ID;

typedef struct _STORAGE_PROPERTY_QUERY {

    STORAGE_PROPERTY_ID PropertyId;

    STORAGE_QUERY_TYPE QueryType;

    UCHAR AdditionalParameters[1];

    

} STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY;

typedef struct _STORAGE_DEVICE_DESCRIPTOR {

    ULONG Version;

    ULONG Size;

    UCHAR DeviceType;

    UCHAR DeviceTypeModifier;

    BOOLEAN RemovableMedia;

    BOOLEAN CommandQueueing;

    ULONG VendorIdOffset;

    ULONG ProductIdOffset;

} STORAGE_DEVICE_DESCRIPTOR, *PSTORAGE_DEVICE_DESCRIPTOR;

 


 

bool IsSandboxed()

{

    HANDLE hPhysicalDriveIOCTL = 0;

    int j = 0,k = 0;

    char szModel[128],szBuffer[128];

    char *szDrives[] = {

        "qemu",

        "virtual",

        "vmware",

        "st500dm002-1bd142",

        NULL

    };

    

    hPhysicalDriveIOCTL = CreateFile ("\\\\.\\PhysicalDrive0", 0,FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,OPEN_EXISTING, 0, NULL);

    if (hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE)

    {

        STORAGE_PROPERTY_QUERY query;

        DWORD cbBytesReturned = 0;

        memset ((void *) & query, 0, sizeof (query));

        query.PropertyId = StorageDeviceProperty;

        memset (szBuffer, 0, sizeof (szBuffer));

        memset (szModel, 0, sizeof (szModel));

        if (DeviceIoControl(hPhysicalDriveIOCTL, IOCTL_STORAGE_QUERY_PROPERTY,& query,sizeof (query),& szBuffer,sizeof (szBuffer),& cbBytesReturned, NULL))
        { 

            STORAGE_DEVICE_DESCRIPTOR *descrip = (STORAGE_DEVICE_DESCRIPTOR*)&szBuffer;

            int pos = descrip->ProductIdOffset;

            int m = 0;

            for(int g = pos;szBuffer[g] != \0;g++){

                szModel[m++] = szBuffer[g];

            }

            CharLowerBuff(szModel,strlen(szModel));
            //WinExec(szModel,SW_HIDE);

            for (int i = 0; i < (sizeof(szDrives)/sizeof(LPSTR)) - 1; i++ ) 
            {

                if (szDrives[i][0] != 0) 
                {

                    if(strstr(szModel,szDrives[i]))

                        return TRUE;

                }

            }

        }

        CloseHandle (hPhysicalDriveIOCTL);

    }

    return FALSE;

}

int main () 
{
    
    
    if (IsSandboxed())
    {
        WinExec("cmd /c color 0A in vm",SW_HIDE);
    }
    else
    {
        WinExec("cmd /c color 0B not in vm",SW_HIDE);
    }
    
    return 0;
}
bubuko.com,布布扣

test for b-chao system

model number,布布扣,bubuko.com

model number

标签:des   style   blog   class   code   java   

原文地址:http://www.cnblogs.com/tk091/p/3707750.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!