unsigned char namelength;
again i like to thank everyone for there help with this.
I'm wondering how do i get the HEXVALUE to display in Hexadecimal format.
Code:#include <fstream> #include <iostream> using namespace std; int main() { char signature[5]; //is logi unsigned int version; //greater than 5 unsigned int entries; //number of entries ifstream ifs("testfile.dat", ios::binary); //OPEN FILE ifs.read((char *)&signature,4); //Get Signature signature[4] = '\0'; ifs.read((char *)&version, 4); //Get Version ifs.read((char *)&entries, 4); //Get Num Entries unsigned char lenth; //Get Namelenth unsigned int nlenth; ifs.read((char *)&lenth,1); nlenth = (int)lenth; unsigned char *name; //Get NAME name = new unsigned char [nlenth+1]; ifs.read((char *)&*name,nlenth); name[nlenth]='\0'; unsigned char hexinput[6]; //Get HEXVALUE ifs.read((char *)&hexinput,6); //output data to console. cout << "File information\n"; cout << "Signature: " << signature << endl; cout << "FileVersion: " << version << endl; cout << "Entries count: " << entries << endl; cout << "Lenth of name: " << nlenth << endl; cout << "The Name: " << name <<endl; cout << "The hexvalue is: " << hexinput << endl; //How do i make this look like the Hexadecimal value ; return 0; }
1) You have to operate on a character at a time
2) The *prinft and *scanf functions have a formatter of "%x" that will aid you in your mission.
Mainframe assembler programmer by trade. C coder when I can.
alright i got it to print in hex but how do i make it set this value to a string.
also how do i get the 64bit interger of FILETIME and show the date and time it is representing.
Code:#include <fstream> #include <iostream> using namespace std; /* class Header { public: char signature[5]; //is logi unsigned int version; //greater than 5 unsigned int entries; //number of entries };*/ int main() { char signature[5]; //is logi unsigned int version; //greater than 5 unsigned int entries; //number of entries ifstream ifs("testfile.dat", ios::binary); //OPEN FILE ifs.read((char *)&signature,4); //Get Signature signature[4] = '\0'; ifs.read((char *)&version, 4); //Get Version ifs.read((char *)&entries, 4); //Get Num Entries unsigned char lenth; //Get Namelenth unsigned int nlenth; ifs.read((char *)&lenth,1); nlenth = (int)lenth; unsigned char *name; //Get NAME name = new unsigned char [nlenth+1]; ifs.read((char *)&*name,nlenth); name[nlenth]='\0'; //OUTPUT data to CONSOLE. cout << "File information\n"; cout << "Signature: " << signature << endl; cout << "FileVersion: " << version << endl; cout << "Entries count: " << entries << endl; cout << "Lenth of name: " << nlenth << endl; cout << "The Name: " << name <<endl; cout << "The hexvalue is: " ; unsigned char hexinput; //Get HEXVALUE unsigned int hexoutput; for (int i=1;i<6;i++) { ifs.read((char *)&hexinput,1); hexoutput = (int)hexinput; cout.setf(ios_base::hex, ios_base::basefield); if (hexoutput < 17) { cout << 0;} cout << std::hex << hexoutput ; //How do i make this look like the Hexdicimal value in a string ; } cout << endl; /* unsigned long long filetime; // DOESNT WORK; ifs.read((char *)&filetime,8); cout << "The date: " << filetime; */ return 0; }
Instead of sending it to cout, you can send it to a StringStream. A very handy class.
Mainframe assembler programmer by trade. C coder when I can.
hi dino thank you for the replay Stringstream works very well.
now the only part I'm having problems with right now is the. FILETIME i need to know what is the right way to get this 64bit int out of the file and how i can convert this to unixtime so PHP can read it.
-----------------------------------------------------------------------------------------------------------
just something off subject here. last night i made the program. read all the logi entries i had in one directory right around 30,000,000 of them so I left the computer on to see how long it would take. and when i woke up in the morning i had an out of memory error. i thought well what can this program be doing that takes so much memory it shouldn't take more than about 2 megabytes. so i look at the code and didn't see any problems. i look at it again an there it was the for loop
Code:for(int f=1;f<files;f++){ for (int i=1;i<=entries;i++){ }
declaring the variable in the loop was taking all my memory
so i added it to the head of the code and now the program takes only about 839k of memory.i know this might be old for some of you but who know maybe someone is here reading this right now that doesn't know where to look for a memory problem.
Code:int i; int f; for(f=1;f<files;f++){ for(i=1;i<entries;i++){}}
anyways i need to get back to figuring out how to get the FILETIME from the file and read it. thank you all for your help on this program.
As to the FILETIME thing, do you know how the timestamp is output? (We've gone around and around and around with people who have a "perfectly standard timestamp" that no one knows how to interpret.) More importantly, that might give you some idea of how to read it in.
Anyway, g++ might take long long, or int64_t if you include inttypes.h. (I don't believe C++ has a standard way of getting at "types of a specific size, provided they exist" like C does.)
FILETIME is the number of 100-nanosecond since January 1, of 1601.... or something like that... I would not recommend using FILETIME if you are wanting to make your program work on OSes that are not Windows.
For the sake of tabstop's personal gratification (though I know him well enough to know he probably doesn't care terribly much). This example I wrote sort of unravels the mystery for you.
(Oh and for anyone who gives a damn: 11644473600 is the number of milliseconds between Jan 1, 1601 and Jan 1, 1970. And that other magic number is the coversion rate between 100-nanosecond or whatever to milliseconds)
Last edited by master5001; 10-17-2008 at 03:23 PM.
nano you ninny. (I think)
Mainframe assembler programmer by trade. C coder when I can.
Yeah, ok. So you do know what that is, never mind. So it just comes down to getting that 64-bit variable (or, if push comes to shove, int filetime[2] and pretend its a 64-bit variable with some extra special math).Originally Posted by the beginning of the thread
@master: sorry I meant the OP. But you, too, can use an array of two ints to solve the problem of finding a 64-bit variable!
No biggy. I used the M$ structures to serve the same function as an array of two ints. For no other reason than to guarantee correct alignment.