Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SystemTest.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <Windows.h>
- #include <direct.h>
- #include <string>
- #include <iostream>
- #include <stdio.h>
- #include <stdint.h>
- #include "FileReader.h"
- #include "FileWriter.h"
- using namespace std;
- void RunDriveSpaceCheck(){
- int const drive = _getdrive();
- struct _diskfree_t diskfree;
- _getdiskfree(drive, &diskfree);
- unsigned __int64 totalDisk = diskfree.total_clusters;
- totalDisk*=diskfree.sectors_per_cluster;
- totalDisk*=diskfree.bytes_per_sector;
- totalDisk /= 1048576; //To MB
- unsigned __int64 availDisk = diskfree.avail_clusters;
- availDisk*=diskfree.sectors_per_cluster;
- availDisk*=diskfree.bytes_per_sector;
- availDisk /= 1048576;
- cout << "Hard drive check:" << endl;
- //cout <<" Bytes per sector: " << diskfree.bytes_per_sector << endl;
- //cout <<" Sectors per cluster: " << diskfree.sectors_per_cluster << endl;
- //cout <<" ===========================" << endl;
- cout <<" Total disk space: " << totalDisk << " MB <= Is this correct?" << endl;
- cout <<" Available disk space : " << availDisk << " MB <= Is this correct?" << endl;
- }
- void RunRAMCheck(){
- MEMORYSTATUSEX status; //Can also grab Virtual RAM
- status.dwLength=sizeof(status);
- GlobalMemoryStatusEx(&status);
- unsigned __int64 PRAM = status.ullTotalPhys / 1048576; //in MB
- unsigned __int64 VRAM = status.ullTotalVirtual / 1048576; //in MB
- cout << "RAM check:" << endl;
- cout <<" Total Physical RAM: " << PRAM << " MB <= Is this correct?" << endl;
- cout <<" Total Virtual RAM: " << VRAM << " MB" << endl;
- }
- bool VerifyEndian(){
- /*short int word = 0x0001;
- char *byte = (char *) &word;
- if(byte[0]==0)
- return true; //Big Endian
- else
- return false; //LE*/
- int x = 1;
- if(*(char *)&x == 1)
- return false; //LE
- else
- return true; //BE
- }
- short ShortSwap( short s )
- {
- unsigned char b1, b2;
- b1 = s & 255;
- b2 = (s >> 8) & 255;
- return (b1 << 8) + b2;
- }
- int IntSwap (int i)
- {
- unsigned char b1, b2, b3, b4;
- b1 = i & 255;
- b2 = ( i >> 8 ) & 255;
- b3 = ( i>>16 ) & 255;
- b4 = ( i>>24 ) & 255;
- return ((int)b1 << 24) + ((int)b2 << 16) + ((int)b3 << 8) + b4;
- }
- /*void TestWrite(){
- FileWriter file("test1.bin");
- file.WriteCharString( "CharSTRING", 10);
- file.WriteShort(32700);
- file.WriteChar('x');
- file.WriteString("STRING");
- file.WriteInt(0x0FAA00FF);
- }
- void TestSwappedWrite(){
- FileWriter file("test2.bin");
- file.WriteCharString( "CharSTRING", 10);
- file.WriteShort(ShortSwap(32700));
- file.WriteChar('x');
- file.WriteString("STRING");
- file.WriteInt(IntSwap(0x0FAA00FF));
- }*/
- bool TestRead(string str, char endian){
- FileReader file(str);
- int test = 0x0FAA00FF;
- string s(10, '0');
- short sh=0;
- char ch=0;
- string s2(6, '0');
- int in=0;
- if(file.IsValid()){
- s = file.ReadString(10);
- sh = file.ReadShort();
- ch = file.ReadChar();
- s2 = file.ReadString(6);
- in = file.ReadInt();
- }else{
- cout << " Converted reading failed! (EC: 0x00)" << endl;
- FileWriter wfile("Native.dump");
- wfile.WriteString( s);
- wfile.WriteShort(sh);
- wfile.WriteChar(ch);
- wfile.WriteString(s2);
- wfile.WriteInt(in);
- wfile.WriteChar('0');
- wfile.WriteChar(endian);
- return true;
- }
- if(s=="CharSTRING" && sh==32700 && ch=='x' && s2=="STRING" && in==0x0FAA00FF){
- cout << " Native reading success!" << endl;
- return false;
- }else{
- cout << " Native reading failed! (EC: 0x01)" << endl;
- FileWriter wfile("Native.dump");
- wfile.WriteString( s);
- wfile.WriteShort(sh);
- wfile.WriteChar(ch);
- wfile.WriteString(s2);
- wfile.WriteInt(in);
- wfile.WriteChar('1');
- wfile.WriteChar(endian);
- return true;
- }
- }
- bool TestSwappedRead(string str, char endian){
- FileReader file(str);
- string s(10, '0');
- short sh=0;
- char ch=0;
- string s2(6, '0');
- int in=0;
- if(file.IsValid()){
- s = file.ReadString(10);
- sh = ShortSwap(file.ReadShort());
- ch = file.ReadChar();
- s2 = file.ReadString(6);
- in = IntSwap(file.ReadInt());
- }else{
- cout << " Converted reading failed! (EC: 0x00)" << endl;
- FileWriter wfile("Native.dump");
- wfile.WriteString( s);
- wfile.WriteShort(sh);
- wfile.WriteChar(ch);
- wfile.WriteString(s2);
- wfile.WriteInt(in);
- wfile.WriteChar('0');
- wfile.WriteChar(endian);
- return true;
- }
- if(s=="CharSTRING" && sh==32700 && ch=='x' && s2=="STRING" && in==0x0FAA00FF){
- cout << " Converted reading success!" << endl;
- return false;
- }else{
- cout << " Converted reading failed! (EC: 0x01)" << endl;
- FileWriter wfile("Converted.dump");
- wfile.WriteString( s);
- wfile.WriteShort(sh);
- wfile.WriteChar(ch);
- wfile.WriteString(s2);
- wfile.WriteInt(in);
- wfile.WriteChar('1');
- wfile.WriteInt(endian);
- return true;
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- using namespace std;
- cout << endl;
- RunDriveSpaceCheck();
- cout << endl << endl;
- RunRAMCheck();
- cout << endl << endl;
- //TestWrite();
- //TestSwappedWrite();
- bool error=false;
- if(VerifyEndian()){
- cout << "System Configuration Big Endian:" << endl;
- error=TestRead("testBE.bin", 1);
- error=TestSwappedRead("testLE.bin", 1);
- }else{
- cout << "System Configuration Little Endian:" << endl;
- error=TestRead("testLE.bin", 2);
- error=TestSwappedRead("testBE.bin", 2);
- }
- cout << endl << endl;
- //error=true;
- if(error){
- cout << "One or both tests have failed. Please pass me the created dump files:"<<endl;
- cout << "\"Native.dump\" and/or \"Converted.dump\"." << endl;
- cout << endl << endl;
- }
- cout<<"Thank you for your help. Press any key to close this console..."; getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement