Exemple #1
0
BOOL PNDASPhysicalDrive::Open( int iDrive )
{
	CHAR errMsg[200];

	BOOL bResults;
	if(!m_bInitialized)
	{
		MessageBox(NULL, "API not initialized", "Open NDAS.", MB_OK | MB_ICONERROR);
		return FALSE;
	}
	
	char **OpenParameter = (char **)iDrive;

	if(NULL == OpenParameter)
		return FALSE;

	if(NULL == OpenParameter[0])
		return FALSE;
	
	PartitionInfo **ppPI = (PartitionInfo **)OpenParameter[0];

	if(NULL == OpenParameter[1])
		return FALSE;

	CopyMemory(&m_ConnectionInfo, (PNDAS_CONNECTION_INFO)OpenParameter[1], sizeof(m_ConnectionInfo));

	m_hNDAS = NdasCommConnect(&m_ConnectionInfo);
	if(!m_hNDAS)
	{
		sprintf(errMsg, "Error %s %d %08x", __FILE__, __LINE__, ::GetLastError());
		MessageBox(NULL, errMsg, "Open NDAS.", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	bResults = NdasCommGetDeviceInfo(m_hNDAS, &m_Info);
	if(!bResults)
	{
		sprintf(errMsg, "Error %s %d %08x", __FILE__, __LINE__, ::GetLastError());
		MessageBox(NULL, errMsg, "Open NDAS.", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	bResults = NdasCommGetUnitDeviceInfo(m_hNDAS, &m_UnitInfo);
	if(!bResults)
	{
		sprintf(errMsg, "Error %s %d %08x", __FILE__, __LINE__, ::GetLastError());
		MessageBox(NULL, errMsg, "Open NDAS.", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	bResults = NdasCommGetUnitDeviceDynInfo(&m_ConnectionInfo, &m_UnitDynInfo);
	if(!bResults)
	{
		sprintf(errMsg, "Error %s %d %08x", __FILE__, __LINE__, ::GetLastError());
		MessageBox(NULL, errMsg, "Open NDAS.", MB_OK | MB_ICONERROR);
		return FALSE;
	}

#define MEDIA_TYPE_BLOCK_DEVICE 1

	if(MEDIA_TYPE_BLOCK_DEVICE != m_UnitInfo.MediaType)
	{
		MessageBox(NULL, "Packet device not supported.", "Open NDAS", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	m_BytesPerSector = 512;

	m_PI.m_dwDrive = 0xff;
	m_PI.m_dwPartition = 0xff;
	m_PI.m_bIsPartition = TRUE;
	m_PI.m_dwBytesPerSector = (unsigned long)m_BytesPerSector;
	m_PI.m_NumberOfSectors = m_UnitInfo.SectorCount;
	m_PI.m_StartingOffset = 0;
	m_PI.m_StartingSector = 0;
	m_PI.m_PartitionLength = m_UnitInfo.SectorCount * m_BytesPerSector;

	*ppPI = &m_PI;

	return TRUE;
}
Exemple #2
0
BOOL PNDASPhysicalDrive::GetDriveLayout( LPBYTE lpbMemory, DWORD dwSize )
{
	if(!IsOpen())
		return FALSE;

	BOOL bResults = NdasCommGetUnitDeviceDynInfo(&m_ConnectionInfo, &m_UnitDynInfo);
	if(!bResults)
		return FALSE;

	PCHAR lpszDesc = (PCHAR)lpbMemory;
	CHAR bufferModel[100];
	CHAR bufferFwRev[100];
	CHAR bufferSerialNo[100];

	memcpy(bufferModel, (const char *)m_UnitInfo.Model, sizeof(m_UnitInfo.Model)); bufferModel[sizeof(m_UnitInfo.Model)] = '\0';
	memcpy(bufferFwRev, (const char *)m_UnitInfo.FwRev, sizeof(m_UnitInfo.FwRev)); bufferFwRev[sizeof(m_UnitInfo.FwRev)] = '\0';
	memcpy(bufferSerialNo, (const char *)m_UnitInfo.SerialNo, sizeof(m_UnitInfo.SerialNo)); bufferSerialNo[sizeof(m_UnitInfo.SerialNo)] = '\0';

	sprintf(
		lpszDesc,
		"Hardware Type : %d\n"
		"Hardware Version : %d\n"
		"Hardware Protocol Type : %d\n"
		"Hardware Protocol Version : %d\n"
		"Number of slot : %d\n"
		"Maximum transfer blocks : %d\n"
		"Maximum targets : %d\n"
		"Maximum LUs : %d\n"
		"Header Encryption : %s\n"
		"Data Encryption : %s\n"
		"\n"
		"Sector count : %I64d\n"
		"Supports LBA : %s\n"
		"Supports LBA48 : %s\n"
		"Supports PIO : %s\n"
		"Supports DMA : %s\n"
		"Supports UDMA : %s\n"
		"Model : %s\n"
		"Firmware Rev : %s\n"
		"Serial number : %s\n"
		"Media type : %s\n"
		"\n"
		"Present : %s\n"
		"Number of hosts with RW priviliage : %d\n"
		"Number of hosts with RO priviliage : %d\n",
		m_Info.HWType,
		m_Info.HWVersion,
		m_Info.HWProtoType,
		m_Info.HWProtoVersion,
		m_Info.iNumberofSlot,
		m_Info.iMaxBlocks,
		m_Info.iMaxTargets,
		m_Info.iMaxLUs,
		(m_Info.iHeaderEncryptAlgo) ? "YES" : "NO",
		(m_Info.iDataEncryptAlgo) ? "YES" : "NO",
		m_UnitInfo.SectorCount,
		(m_UnitInfo.bLBA) ? "YES" : "NO",
		(m_UnitInfo.bLBA48) ? "YES" : "NO",
		(m_UnitInfo.bPIO) ? "YES" : "NO",
		(m_UnitInfo.bDma) ? "YES" : "NO",
		(m_UnitInfo.bUDma) ? "YES" : "NO",
		bufferModel,
		bufferFwRev,
		bufferSerialNo,
		(m_UnitInfo.MediaType == MEDIA_TYPE_UNKNOWN_DEVICE) ? "Unknown device" :
		(m_UnitInfo.MediaType == MEDIA_TYPE_BLOCK_DEVICE) ? "Non-packet mass-storage device (HDD)" :
		(m_UnitInfo.MediaType == MEDIA_TYPE_COMPACT_BLOCK_DEVICE) ? "Non-packet compact storage device (Flash card)" :
		(m_UnitInfo.MediaType == MEDIA_TYPE_CDROM_DEVICE) ? "CD-ROM device (CD/DVD)" :
		(m_UnitInfo.MediaType == MEDIA_TYPE_OPMEM_DEVICE) ? "Optical memory device (MO)" :
		"Unknown device",
		(m_UnitDynInfo.bPresent) ? "YES" : "NO",
		m_UnitDynInfo.NRRWHost,
		m_UnitDynInfo.NRROHost);


	return TRUE;
} // GetDriveLayout()
Exemple #3
0
int __cdecl main()
{
	DWORD dwError = 0;
	BOOL bRet;
	HNDAS hNdas;
	CHAR data[512 * 128];

	_hModule = LoadLibrary(L"ndascomm.dll");
	if (NULL == _hModule) {
		wprintf(L"Unable to load ndascomm.dll.\n");
		return 1;
	}

  NdasCommInitialize();

  NDAS_CONNECTION_INFO ci;
  ZeroMemory(&ci, sizeof(ci));
  ci.type = NDAS_CONNECTION_INFO_TYPE_MAC_ADDRESS;
  ci.UnitNo = 0;
  ci.bWriteAccess = FALSE;
  ci.protocol = IPPROTO_LPXTCP;
  ci.MacAddress[0] = 0x00;
  ci.MacAddress[1] = 0x0b;
  ci.MacAddress[2] = 0xd0;
  ci.MacAddress[3] = 0x00;
  ci.MacAddress[4] = 0xb8;
  ci.MacAddress[5] = 0xad;

  HNDAS hNDAS;
  hNDAS = NdasCommConnect(&ci);
  if(NULL == hNDAS)
  {
    printf("NULL == hNDAS %08X\n", ::GetLastError());
    return FALSE;
  }

  NdasCommDisconnect(hNDAS);
  hNDAS = NdasCommConnect(&ci);
  if(NULL == hNDAS)
  {
    printf("NULL == hNDAS %08X\n", ::GetLastError());
    return FALSE;
  }

  bRet = NdasCommBlockDeviceRead(hNDAS, 0, 128, data);

  NDAS_UNIT_DEVICE_DYN_INFO dynInfo;
  BOOL bResults;
  bResults = NdasCommGetUnitDeviceDynInfo(&ci, &dynInfo);
  if(FALSE == bResults)
  {
    printf("FALSE == bResults %08X\n", ::GetLastError());
    return FALSE;
  }

  printf("%d %d %d %d",
    dynInfo.iNRTargets,
    dynInfo.bPresent,
    dynInfo.NRRWHost,
    dynInfo.NRROHost);


//  hNdas = NdasRawConnectW(L"GNVXGA4MPQSVY6CSLJ7K", L"3CG70", 0x1F4A50731530EABB /* HASH_KEY_USER */, 214 /* IPPROTO_LPXTCP */);
//  ZeroMemory(data, 512*128);
//  data[0] = 0xff;
//  data[3] = 0xff;
//  NdasRawBlockDeviceWriteSafeBuffer(hNdas, 0, 1, data);
//  ZeroMemory(data, 512*128);
//  NdasRawBlockDeviceRead(hNdas, 0, 1, data);
//  NdasRawDisconnect(hNdas);



//	dwError = t1();
//	dwError = t12();
//	dwError = t2();
//	NdasRawConnectW proc = (NdasRawConnect)GetProcAddress(_hModule, "NdasRawConnectW");
//	if(!proc) {
//		wprintf(L"Unable to load function NdasRawConnectW.\n");
//		return 1;
//	}

//	dwError = proc(NULL, NULL, 0, 0);

	wprintf(_T("Error %d (0x%08x)\n"), GetLastError(), GetLastError());

	FreeLibrary(_hModule);
}