[plzHelp]Ich will parameter meiner Festplatte auslesen



  • Hey @ll,

    ich bin gerade auf der suche nach irgendwas wo ein Beispiel / Tutorial wo erklärt wird wie ich mit S.M.A.R.T. Parametern Arbeite, an diese rankomme...

    Kennt da wer was? Ich weiß darüber nur, was sie mir sagen, also wozu sie da sind...

    MFG und Danke im vorraus.



  • [url="Gefunden"]http://www.comprenica.com/atrevida/atrtut06.html[/url] habe ich dies hier... Ich weiß nicht ob es mir hilft aber ich glaube da kann icha uch irgendwie auf die Festplatte Zielen, und ihr Daten entlocken...

    Jetzt eine Frage: geht "inp" nur bei 16-Bit Compilern? Er kennt das nämlich nicht.

    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>
    
    int main( void )
    {
    	int ret;
    
    	ret = inport(0x3DA);//von irgendeinem Port einlesen
    
    	printf( "%d\n", ret );//anzeigen
    }
    

    aber er sagt

    ./ccySaaaa.o:hnpPort.c:(.text+0xe): undefined reference to `inport'
    

    Kann mir da wer helfen oder bin ich gerade total auf dem Holzweg?!



  • lippoliv schrieb:

    Jetzt eine Frage: geht "inp" nur bei 16-Bit Compilern? Er kennt das nämlich nicht.

    das ist weniger eine frage des compilers, sondern das OS (zumindest windoofs) verbietet hardware-zugriffe aus dem user-mode. mit tricks gehts natürlich wieder:
    http://wookey.org/usermodehardwareportio.html
    🙂



  • Du meinst wahrscheinlich _inp( ). Damit wirst Du aber im User-Mode von Windows pech haben.

    greetz, Swordfish



  • DICKES DANKE... hatte gerade gedacht ich währe hilflos ausgeliefert...

    Erstmal: Bin ich gerade auf dem richtigen weg?

    Zweitensmal: wenn mir der Link hilft... kann mir da wer was genauer zu sagen? Ich bin mir nicht sicher was da getan wird...

    Drittens: Wo finde ich so die Ports, oder eher; wofür sie sind?

    DANKE IHR SEID SUPER



  • Ob du auf dem Richtigen Weg™ bist, hängt davon ab, was du vor hast. Willst du eine Anwengung entwickeln, die an normale Benutzer verteilt wird: nein. Nicht jeder arbeitet gerne als Teil des Betriebssystems.

    Vielleicht hilft Dir WMI Support for SMART Drives.

    greetz, Swordfish



  • Gut also ich habe jetz hier was anderes, von nem Klassenkameraden empfohlen das ist:

    int main( void )
    {
    	int ret;
    	HANDLE storage;
    	DISK_GEOMETRY myDiskGeo;
    	DWORD tmp;
    
    	storage = 	CreateFile(
    					"\\\\.\\PhysicalDrive0",			//the drive
    					0,									//no access to the drive
    					FILE_SHARE_READ | FILE_SHARE_WRITE,
    					NULL,								//default sec. attributes
    					OPEN_EXISTING,						//just try to open the file
    					0,									//file attributes
    					NULL								//dont copy file attributes
    				);
    
    	if( INVALID_HANDLE_VALUE != storage )
    	{
    		ret = 	DeviceIoControl( 
    					storage,
    					IOCTL_DISK_GET_DRIVE_GEOMETRY,
    					NULL,
    					0,
    					&myDiskGeo,
    					sizeof(myDiskGeo),
    					&tmp,
    					NULL
    				);
    		CloseHandle( storage );
    	}
    
    	printf( "Zelinder: %l\n", myDiskGeo.Cylinders );
    
    	return 0;
    }
    

    Wer fehler findet darf sie vorerst behalten 😃

    Es geht um Folgendes: es muss die "winioctl.h" verwendet werden und da bekommm ich:

    /mingw/include/winioctl.h:193: error: syntax error before "BAD_TRACK_NUMBER"
    /mingw/include/winioctl.h:196: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:200: error: syntax error before "BIN_RANGE"
    /mingw/include/winioctl.h:204: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:206: error: syntax error before '}' token
    /mingw/include/winioctl.h:213: error: syntax error before "GUID"
    /mingw/include/winioctl.h:217: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:221: error: syntax error before "_ANONYMOUS_UNION"
    /mingw/include/winioctl.h:232: error: syntax error before "BOOLEAN"
    /mingw/include/winioctl.h:234: error: syntax error before "WriteCacheEnabled"
    /mingw/include/winioctl.h:237: error: syntax error before "DisablePrefetchTransf
    erLength"
    /mingw/include/winioctl.h:238: error: syntax error before "PrefetchScalar"
    /mingw/include/winioctl.h:239: error: syntax error before "union"
    /mingw/include/winioctl.h:241: error: syntax error before "WORD"
    /mingw/include/winioctl.h:243: error: syntax error before "MaximumBlocks"
    /mingw/include/winioctl.h:246: error: syntax error before "WORD"
    /mingw/include/winioctl.h:249: error: syntax error before '}' token
    /mingw/include/winioctl.h:257: error: syntax error before "WORD"
    /mingw/include/winioctl.h:259: error: syntax error before "SectorsPerTrack"
    /mingw/include/winioctl.h:260: error: syntax error before "MaxHeads"
    /mingw/include/winioctl.h:261: error: syntax error before "NumberDrives"
    /mingw/include/winioctl.h:264: error: syntax error before "WORD"
    /mingw/include/winioctl.h:266: error: syntax error before "ExCylinders"
    /mingw/include/winioctl.h:267: error: syntax error before "ExHeads"
    /mingw/include/winioctl.h:268: error: syntax error before "ExSectorsPerTrack"
    /mingw/include/winioctl.h:269: error: syntax error before "ExSectorsPerDrive"
    /mingw/include/winioctl.h:270: error: syntax error before "ExSectorSize"
    /mingw/include/winioctl.h:271: error: syntax error before "ExReserved"
    /mingw/include/winioctl.h:274: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:276: error: syntax error before "union"
    /mingw/include/winioctl.h:312: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:314: error: syntax error before "TracksPerCylinder"
    /mingw/include/winioctl.h:315: error: syntax error before "SectorsPerTrack"
    /mingw/include/winioctl.h:316: error: syntax error before "BytesPerSector"
    /mingw/include/winioctl.h:319: error: syntax error before "DISK_GEOMETRY"
    /mingw/include/winioctl.h:321: error: syntax error before "Data"
    /mingw/include/winioctl.h:322: error: syntax error before '}' token
    /mingw/include/winioctl.h:324: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:328: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:330: error: syntax error before "union"
    /mingw/include/winioctl.h:332: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:335: error: syntax error before "GUID"
    /mingw/include/winioctl.h:337: error: syntax error before '}' token
    /mingw/include/winioctl.h:340: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:342: error: syntax error before "ReadTime"
    /mingw/include/winioctl.h:343: error: syntax error before "WriteTime"
    /mingw/include/winioctl.h:344: error: syntax error before "ReadCount"
    /mingw/include/winioctl.h:345: error: syntax error before "WriteCount"
    /mingw/include/winioctl.h:346: error: syntax error before "QueueDepth"
    /mingw/include/winioctl.h:349: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:351: error: syntax error before "EndTime"
    /mingw/include/winioctl.h:352: error: syntax error before "VirtualAddress"
    /mingw/include/winioctl.h:353: error: syntax error before "NumberOfBytes"
    /mingw/include/winioctl.h:354: error: syntax error before "DeviceNumber"
    /mingw/include/winioctl.h:355: error: syntax error before "ReadRequest"
    /mingw/include/winioctl.h:358: error: syntax error before "BYTE"
    /mingw/include/winioctl.h:360: error: syntax error before "BufferSize"
    /mingw/include/winioctl.h:363: error: syntax error before "LONGLONG"
    /mingw/include/winioctl.h:365: error: syntax error before "QuotaLimit"
    /mingw/include/winioctl.h:369: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:371: error: syntax error before "StartHeadNumber"
    /mingw/include/winioctl.h:372: error: syntax error before "EndHeadNumber"
    /mingw/include/winioctl.h:376: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:378: error: syntax error before "StartHeadNumber"
    /mingw/include/winioctl.h:379: error: syntax error before "EndHeadNumber"
    /mingw/include/winioctl.h:380: error: syntax error before "FormatGapLength"
    /mingw/include/winioctl.h:381: error: syntax error before "SectorsPerTrack"
    /mingw/include/winioctl.h:382: error: syntax error before "SectorNumber"
    /mingw/include/winioctl.h:383: error: syntax error before '}' token
    /mingw/include/winioctl.h:385: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:388: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:392: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:394: error: syntax error before "End"
    /mingw/include/winioctl.h:395: error: syntax error before "Average"
    /mingw/include/winioctl.h:396: error: syntax error before "AverageRead"
    /mingw/include/winioctl.h:397: error: syntax error before "AverageWrite"
    /mingw/include/winioctl.h:398: error: syntax error before "Granularity"
    /mingw/include/winioctl.h:399: error: syntax error before "Size"
    /mingw/include/winioctl.h:400: error: syntax error before "ReadCount"
    /mingw/include/winioctl.h:401: error: syntax error before "WriteCount"
    /mingw/include/winioctl.h:402: error: syntax error before "Histogram"
    /mingw/include/winioctl.h:405: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:407: error: syntax error before "ExtentLength"
    /mingw/include/winioctl.h:410: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:412: error: syntax error before '}' token
    /mingw/include/winioctl.h:414: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:416: error: syntax error before "HiddenSectors"
    /mingw/include/winioctl.h:417: error: syntax error before "PartitionNumber"
    /mingw/include/winioctl.h:418: error: syntax error before "PartitionType"
    /mingw/include/winioctl.h:419: error: syntax error before "BootIndicator"
    /mingw/include/winioctl.h:420: error: syntax error before "RecognizedPartition"
    /mingw/include/winioctl.h:421: error: syntax error before "RewritePartition"
    /mingw/include/winioctl.h:424: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:426: error: syntax error before "PartitionEntry"
    /mingw/include/winioctl.h:427: error: syntax error before '}' token
    /mingw/include/winioctl.h:429: error: syntax error before "GUID"
    /mingw/include/winioctl.h:431: error: syntax error before "UsableLength"
    /mingw/include/winioctl.h:432: error: syntax error before "MaxPartitionCount"
    /mingw/include/winioctl.h:435: error: syntax error before "ULONG"
    /mingw/include/winioctl.h:438: error: syntax error before "BYTE"
    /mingw/include/winioctl.h:440: error: syntax error before "RecognizedPartition"
    /mingw/include/winioctl.h:441: error: syntax error before "HiddenSectors"
    /mingw/include/winioctl.h:444: error: syntax error before "GUID"
    /mingw/include/winioctl.h:446: error: syntax error before "Attributes"
    /mingw/include/winioctl.h:447: error: syntax error before "Name"
    /mingw/include/winioctl.h:448: error: syntax error before '}' token
    /mingw/include/winioctl.h:451: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:453: error: syntax error before "PartitionNumber"
    /mingw/include/winioctl.h:454: error: syntax error before "RewritePartition"
    /mingw/include/winioctl.h:455: error: syntax error before "union"
    /mingw/include/winioctl.h:461: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:463: error: syntax error before "union"
    /mingw/include/winioctl.h:467: error: syntax error before "PartitionEntry"
    /mingw/include/winioctl.h:468: error: syntax error before '}' token
    /mingw/include/winioctl.h:470: error: syntax error before "HANDLE"
    /mingw/include/winioctl.h:472: error: syntax error before "StartingLcn"
    /mingw/include/winioctl.h:473: error: syntax error before "ClusterCount"
    /mingw/include/winioctl.h:476: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:478: error: syntax error before "BinsRanges"
    /mingw/include/winioctl.h:479: error: syntax error before '}' token
    /mingw/include/winioctl.h:481: error: syntax error before "BOOLEAN"
    /mingw/include/winioctl.h:484: error: syntax error before "DWORD"
    /mingw/include/winioctl.h:487: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:490: error: syntax error before '}' token
    /mingw/include/winioctl.h:492: error: syntax error before "WORD"
    /mingw/include/winioctl.h:494: error: syntax error before "BlockNumber"
    /mingw/include/winioctl.h:495: error: syntax error before '}' token
    /mingw/include/winioctl.h:497: error: syntax error before "BYTE"
    /mingw/include/winioctl.h:500: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:503: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:506: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:510: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:512: error: syntax error before "Buffer"
    /mingw/include/winioctl.h:513: error: syntax error before '}' token
    /mingw/include/winioctl.h:515: error: syntax error before "LARGE_INTEGER"
    /mingw/include/winioctl.h:517: error: syntax error before "TotalClusters"
    /mingw/include/winioctl.h:518: error: syntax error before "FreeClusters"
    /mingw/include/winioctl.h:519: error: syntax error before "TotalReserved"
    /mingw/include/winioctl.h:520: error: syntax error before "BytesPerSector"
    /mingw/include/winioctl.h:521: error: syntax error before "BytesPerCluster"
    /mingw/include/winioctl.h:522: error: syntax error before "BytesPerFileRecordSeg
    ment"
    /mingw/include/winioctl.h:523: error: syntax error before "ClustersPerFileRecord
    Segment"
    /mingw/include/winioctl.h:524: error: syntax error before "MftValidDataLength"
    /mingw/include/winioctl.h:525: error: syntax error before "MftStartLcn"
    /mingw/include/winioctl.h:526: error: syntax error before "Mft2StartLcn"
    /mingw/include/winioctl.h:527: error: syntax error before "MftZoneStart"
    /mingw/include/winioctl.h:528: error: syntax error before "MftZoneEnd"
    

    Super geil... Wo bekomm ich ne funktionierende her?



  • Ich würde mal noch ein

    #include <windows.h>
    

    zu deiner Include-Liste hinzufügen.



  • Ich hatte:

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

    richtig währe:

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

    Tja wenn man verpeilt ist...

    Danke



  • Sry wegen DoublePost...

    So siehts jetzt aus:

    #include <stdio.h>
    #include <windows.h>
    #include <ddk/ntdddisk.h>
    
    int main( void )
    {
    	int ret;
    	HANDLE storage;
    	DRIVERSTATUS myDriveState;
    	DWORD tmp;
    	ULONGLONG DiskSize = 0;
    
    	storage = 	CreateFile(
    					"\\\\.\\PhysicalDrive0",			//the drive
    					0,									//no access to the drive
    					FILE_SHARE_READ | FILE_SHARE_WRITE,
    					NULL,								//default sec. attributes
    					OPEN_EXISTING,						//just try to open the file
    					0,									//file attributes
    					NULL								//dont copy file attributes
    				);
    
    	if( INVALID_HANDLE_VALUE != storage )
    	{
    		ret = 	DeviceIoControl( 	//hier ist nocch was falsches in den parametern
    					storage,
    					SMART_RCV_DRIVE_DATA,
    					NULL,
    					0,
    					&myDriveState,
    					sizeof(myDriveState),
    					&tmp,
    					NULL
    				);
    		CloseHandle( storage );
    		printf( "Failure: %d\n", GetLastError() );
    	}
    
    	system( "pause" );
    	return 0;
    }
    

    und ich kriege Failure 5 (access denied) auch als Admin geht da nichts...

    Leider weiß ich auch gar nicht was ich da setzen muss...
    http://www.codeproject.com/KB/winsdk/Hard_drive_Information.aspx
    hier ist ja nicht viel zu sehen ... Hat jemand von euch sowas schonmal gemacht?

    [edit]

    jetzt gehts.. sieht schon anders aus... allerdings meint er da sind inkomplitable typen in assignment...

    UCHAR			buff[512];
    
    	SENDCMDINPARAMS		inCommandParam 	= { 0 };
    	SENDCMDOUTPARAMS	outCommandParam	= { 0 };
    
    	outCommandParam.cBufferSize = 512;
    	outCommandParam.bBuffer = buff;
    

    habe erst buff als char gehabt, aber auch das ging nicht...

    angeblich ist bBuffer aber UCHAR...

    MSDN schrieb:

    typedef struct _SENDCMDOUTPARAMS {
    ULONG cBufferSize;
    DRIVERSTATUS DriverStatus;
    UCHAR bBuffer[1];
    } SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS;



  • push...



  • Der aktuelle Code, mit fehler 998 "Invalid access to memory location." wobei ich nich weiß was das bedeutet...

    Kann mir wer helfen?

    #include <stdio.h>
    #include <windows.h>
    #include <ddk/ntdddisk.h>
    #include <tchar.h>
    
    #define DRIVE_HEAD_REG	0xA0
    
    BOOL allowUserForHardwareIO();
    BOOL erlaubeZugriffAufHardwareIO( PTCHAR privilege );
    
    int main( void )
    {
    	int 			ret;
    	HANDLE 			storage;
    	DRIVERSTATUS 	myDriveState;
    	DWORD 			tmp;
    	BYTE			getAttributes;
    
    	SENDCMDINPARAMS		inCommandParam;
    	SENDCMDOUTPARAMS	outCommandParam;
    
    	//if( allowUserForHardwareIO() )
    	//{
    
    		/*inCommandParam.cBufferSize = 0;//buffer size
    		inCommandParam.bDriveNumber = 1;//wird angeblich ignoriert
    		inCommandParam.irDriveRegs.bFeaturesReg = ENABLE_SMART;	//was gemacht werden soll
    		inCommandParam.irDriveRegs.bSectorCountReg = 1;//IDE SECTOR COUNT
    		inCommandParam.irDriveRegs.bSectorNumberReg = 1;//SECTOR NUMBER REGISTER
    		inCommandParam.irDriveRegs.bCylLowReg = SMART_CYL_LOW;//low order register
    		inCommandParam.irDriveRegs.bCylHighReg = SMART_CYL_HI;//high order register
    		inCommandParam.irDriveRegs.bDriveHeadReg = DRIVE_HEAD_REG;//ide drive/head register
    		inCommandParam.irDriveRegs.bCommandReg = SMART_CMD;//command register
    		*/
    
    		storage = 	CreateFile(
    						"\\\\.\\PhysicalDrive0",			//the drive
    						GENERIC_READ|GENERIC_WRITE,			//no access to the drive
    						FILE_SHARE_READ | FILE_SHARE_WRITE,
    						NULL,								//default sec. attributes
    						OPEN_EXISTING,						//just try to open the file
    						FILE_ATTRIBUTE_SYSTEM,				//file attributes
    						NULL								//dont copy file attributes
    					);
    
    		if( INVALID_HANDLE_VALUE != storage )
    		{
    			/*ret = 	DeviceIoControl( 	//hier ist nocch was falsches in den parametern
    						storage,					//handle to device
    						SMART_SEND_DRIVE_COMMAND,	//command
    						&inCommandParam,			//incommand
    						sizeof(inCommandParam),		//sizeof(incommand)
    						&outCommandParam,			//outcommand
    						sizeof(outCommandParam),	//sizeof(outcommand)
    						&tmp,						//buffer
    						NULL						//?
    					);
    			if( ret )	//hat geklappt
    			{
    				if( 0 == outCommandParam.DriverStatus.bDriverError )
    					printf( "No error\n" );
    				else
    					printf( "Error on HDD\n" );*/
    
    				inCommandParam.bDriveNumber = 0;	//was gemacht werden soll
    				inCommandParam.irDriveRegs.bFeaturesReg = RETURN_SMART_STATUS|READ_ATTRIBUTES;	//was gemacht werden soll
    				inCommandParam.irDriveRegs.bCommandReg = SMART_CMD;
    				inCommandParam.cBufferSize = 255;	//was gemacht werden soll
    				inCommandParam.bBuffer[0] = 255;	//was gemacht werden soll
    
    				ret = 	DeviceIoControl( 	//hier ist nocch was falsches in den parametern
    						storage,					//handle to device
    						SMART_RCV_DRIVE_DATA,		//command
    						&inCommandParam,			//incommand
    						512,		//sizeof(incommand)
    						&outCommandParam,			//outcommand
    						512,	//sizeof(outcommand)
    						&tmp,						//buffer
    						NULL						//?
    					);
    				if( ret )
    					printf( "out:%s", outCommandParam.bBuffer );
    				else
    					printf( "Failure SMART_RCV_DRIVE_DATA: %d\n", GetLastError() );
    					/*
    			}
    			else		//hat nicht geklappt
    				printf( "Failure DeviceIoControl: %d\n", GetLastError() );*/
    
    			CloseHandle( storage );
    		}
    		else
    			printf( "Failure: %d\n", GetLastError() );
    	//}
    	//else
    		//printf( "Can't get User-Rights... %d\n", GetLastError() );
    	system( "pause" );
    	return 0;
    }
    
    BOOL allowUserForHardwareIO()
    {
    	typedef ULONG (__stdcall* pfn_ZwSetInformationProcess)	(	//typen erzeugen, der später auf die adresse einer funktion gelegt wird
    										                    HANDLE,
    										                    ULONG, 
    										                    PVOID, 
    										                    ULONG
    															);
    	BOOL returnValue = FALSE;
    	HMODULE modNtDll = NULL;	//modulehandle zu der dll
    	ULONG	IOPL = 3;
    	int		usrModeIOPL = 16;	//rechte
    	pfn_ZwSetInformationProcess myProcInfo;	//ist im spätereen verlauf eine funktion
    	modNtDll = GetModuleHandle( "ntdll.dll" ); //dll library anzapfen
    
    	if( modNtDll )
    	{
    		myProcInfo = (pfn_ZwSetInformationProcess)GetProcAddress( modNtDll, "ZwSetInformationProcess" ); //addresse einer funktion in der dll auslesen
    		if( myProcInfo )//wenn erfolgreich
    		{
    			returnValue = erlaubeZugriffAufHardwareIO( SE_TCB_NAME ); //zugriff für user erlauben
    
    			if( returnValue )
    			{
    				returnValue = myProcInfo( GetCurrentProcess(), usrModeIOPL, &IOPL, sizeof(IOPL) );
    				//if 0 is returned the function is TRUE, so switch the values
    				returnValue = !returnValue;
    				if( !returnValue )
    					printf( "ZwSetInformationProcess: %d\n", GetLastError() );
    			}
    
    		}
    	}
    
    	return returnValue;
    }
    
    BOOL erlaubeZugriffAufHardwareIO( PTCHAR privilege )
    {
    	BOOL returnValue;
    	HANDLE myHandle;//unbekannt
    	LUID luid; //unbekannt
    	TOKEN_PRIVILEGES tokenPriv;
    
    	returnValue = 	OpenProcessToken(
    							GetCurrentProcess(),					//prozess handle
    							TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,	//zugriffsrechte
    							&myHandle								//handle zu den neuen zugriffsrechten
    					);
    	if( !returnValue )
    		printf( "OpenProcessToken: %d\n", GetLastError() );
    
    	if( returnValue )
    	{
    		returnValue = 	LookupPrivilegeValue(
    										NULL,		//null-terminierter string der den namen des systems festlegt, bei dem die previlege ausgeschaut werden sollen
    										privilege,	//name des previleges
    										&luid		//die LUID bei der diese Previlegien bekannt sind
    						);
    		if( !returnValue )
    			printf( "LookupPrivilegeValue: %d\n", GetLastError() );
    
    		if( returnValue )
    		{
    			tokenPriv.PrivilegeCount = 1; //ein privileg enthalten
    			tokenPriv.Privileges[0].Luid = luid; //ein privileg enthalten
    			tokenPriv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; //ein privileg enthalten
    
    			//privilege speichern
    			returnValue = 	AdjustTokenPrivileges(
    								myHandle,			//handle mit den in openprocesstoken erhaschten rechten
    								FALSE,				//deaktivieren aller previlegien für diesen bereich
    								&tokenPriv,			//neue privilegien
    								sizeof(tokenPriv),	//bufferlänge
    								NULL,				//den alten previlegienstand speichern
    								NULL				//erhaltene bufferlänge 
    							);
    			if( !returnValue )
    				printf( "AdjustTokenPrivileges: %d\n", GetLastError() );
    		}
    	}
    
    	if( myHandle )
    		CloseHandle( myHandle );
    
    	return returnValue;
    }
    

    fehler 122(The data area passed to a system call is too small.) erreiche ich mit:

    ret = 	DeviceIoControl( 	//hier ist nocch was falsches in den parametern
    						storage,					//handle to device
    						SMART_RCV_DRIVE_DATA,		//command
    						&inCommandParam,			//incommand
    						sizeof(inCommandParam),		//sizeof(incommand)
    						&outCommandParam,			//outcommand
    						sizeof(inCommandParam),	//sizeof(outcommand)
    						&tmp,						//buffer
    						NULL						//?
    					);
    


  • lippoliv schrieb:

    fehler 122(The data area passed to a system call is too small.) erreiche ich mit:

    ret = 	DeviceIoControl( 	//hier ist nocch was falsches in den parametern
    						storage,					//handle to device
    						SMART_RCV_DRIVE_DATA,		//command
    						&inCommandParam,			//incommand
    						sizeof(inCommandParam),		//sizeof(incommand)
    						&outCommandParam,			//outcommand
    						sizeof(inCommandParam),	//sizeof(outcommand)
    						&tmp,						//buffer
    						NULL						//?
    					);
    

    das hier:

    sizeof([u]in[/u]CommandParam),    //sizeof([i]out[/i]command)
    

    stimmt doch sicher nicht, oder?



  • ups. Danke.
    Allerdings schien das falsch gewesen zu sein, der 5te Parameter muss ein BYTE-Array sein und der sechste dann halt seine größe,
    jetzt sagt mir mein Programm auch schon das was in Zeile 82 ("out:") steht, allerdings halt ohne irgendwas, also kein String oder so.

    wie Zeige ich den BYTE an?

    BYTE			getAttributes[sizeof(SENDCMDOUTPARAMS)+512-1];
    //code
    printf( "out:%d\n", getAttributes );//geht nich
    printf( "out:%s\n", getAttributes );//geht nich
    

    [edit]//schwachsinn
    [edit2]del::schwachsinn
    [edit3]

    #include <stdio.h>
    #include <windows.h>
    #include <ddk/ntdddisk.h>
    #include <tchar.h>
    
    #define DRIVE_HEAD_REG	0xA0
    
    BOOL allowUserForHardwareIO();
    BOOL erlaubeZugriffAufHardwareIO( PTCHAR privilege );
    
    int main( void )
    {
    	int 			ret;
    	HANDLE 			storage;
    	DRIVERSTATUS 	myDriveState;
    	DWORD 			tmp,
    					diskDate[256];
    	BYTE			getAttributes[sizeof(SENDCMDOUTPARAMS)] = { 0 };
    	int 			i;
    	SENDCMDINPARAMS		inCommandParam;
    	SENDCMDOUTPARAMS	outCommandParam;
    
    	//if( allowUserForHardwareIO() )
    	//{
    
    		storage = 	CreateFile(
    						"\\\\.\\PhysicalDrive0",			//the drive
    						GENERIC_READ|GENERIC_WRITE,			//no access to the drive
    						FILE_SHARE_READ | FILE_SHARE_WRITE,
    						NULL,								//default sec. attributes
    						OPEN_EXISTING,						//just try to open the file
    						FILE_ATTRIBUTE_SYSTEM,				//file attributes
    						NULL								//dont copy file attributes
    					);
    
    		if( INVALID_HANDLE_VALUE != storage )
    		{
    
    				inCommandParam.bDriveNumber = 0;	//was gemacht werden soll
    				inCommandParam.irDriveRegs.bFeaturesReg = RETURN_SMART_STATUS|READ_ATTRIBUTES;	//was gemacht werden soll
    				inCommandParam.irDriveRegs.bCommandReg = ID_CMD;
    				outCommandParam.cBufferSize = 512;
    				outCommandParam.bBuffer[0] = 255;
    
    				ret = 	DeviceIoControl( 	//hier ist nocch was falsches in den parametern
    						storage,					//handle to device
    						SMART_RCV_DRIVE_DATA,		//command
    						&inCommandParam,			//incommand
    						sizeof(SENDCMDINPARAMS) - 1,
    						&outCommandParam,			//dort werden daten erhalten
    						sizeof(SENDCMDOUTPARAMS)+512,
    						&tmp,						//buffer
    						NULL						//?
    					);
    				if( ret )
    				{
    					for( i = 0; i < 256; i++ )
    						printf( "out:%c\n", outCommandParam.bBuffer[i] );
    				}
    				else
    					printf( "Failure SMART_RCV_DRIVE_DATA: %d\n", GetLastError() );
    
    			CloseHandle( storage );
    		}
    		else
    			printf( "Failure: %d\n", GetLastError() );
    	//}
    	//else
    		//printf( "Can't get User-Rights... %d\n", GetLastError() );
    	system( "pause" );
    	return 0;
    }
    

    dass ist jetzt mal mit ausgabe.
    aber ziemlich komisch...



  • Also,
    ich finde das ja schlecht...

    sizeof(SENDCMDOUTPARAMS)+512 ist falsch als übergabeparameter, weil er sonst andere variablem im mem überschreibt, aber wie kann ich im vorraus speicher allokieren um ihn an outCommandParam.bBuffer als Pointer zu übergeben?

    UCHAR*			myBuff = NULL;
    //flupp
    outCommandParam.cBufferSize = 512;
    myBuff = malloc( sizeof(UCHAR) * outCommandParam.cBufferSize);
    outCommandParam.bBuffer = myBuff;
    

    geht nich.

    error: incompatible types in assignment
    

    wie kann ich also einen Pointer übergeben?

    [eidt]
    erster erfolg 😃
    Ich habe es anhand dieseslinks geschafft, meinen Code anzupassen.
    Ich bin in der lage Seriennummer und Modell auszulesen.

    Jetzt mache ich mich daran die richtigen Parameter zu erhalten, also ob die Platte einen Fehler hat.

    [edit2]
    Danke an alle die mir geholfen haben, habe es gerade geschaft;
    C++ Code umschreiben ist schon witzig(die codes von Codeprojekt sollten mehr kommentiert werden 😃 )
    Ich werde nochmal nen Link online stellen, damit leute die diesen Thread durch eine suche finden, einen beispielcode haben.


Anmelden zum Antworten