hi everyone, i have this problem: i'm makeing a program to list/add/extract files from a archive(it's a .DRV file from a psx game, which has all the actual files used by the game)
The problem is that when i read a byte with value bigger than 127, it gives me some weird error: for 127 it returns 127(0x7F), but for 128(0x80) it returns 16777088 (0xFFFF80), tried using a unsigned short int but returns 0xFF80
this is a piece of the archive (the file table)
00000000 80 00 00 00 01 00 00 00 00 00 00 00 22 2B 43 3A 45 56 45 4E 54 00 00 00 00 00 00 00 00 00 00 00 ............"+C:EVENT...........
00000020 80 00 00 00 11 00 00 00 00 00 00 00 D2 22 43 3A 4F 42 4A 45 43 54 00 00 00 00 00 00 00 00 00 00 ............."C:OBJECT..........
00000040 80 00 00 00 BD 01 00 00 00 00 00 00 2C AD 5E 3A 45 56 4F 5F 50 41 4B 00 00 00 00 00 00 00 00 00 ............,.^:EVO_PAK.........
00000060 80 00 00 00 C8 01 00 00 00 00 00 00 14 64 62 3A 44 45 42 55 47 00 00 00 00 00 00 00 00 00 00 00 .............db:DEBUG...........
00000080 01 41 52 43 52 0C 00 00 1C 12 00 00 D8 DF EE 39 55 4E 49 54 5F 45 46 46 00 00 00 00 00 00 00 00 .ARCR..........9UNIT_EFF........
000000A0 01 50 41 4B 55 0C 00 00 FC C4 06 00 22 C2 EF 3A 41 52 45 41 30 34 00 00 00 00 00 00 00 00 00 00 .PAKU......."..:AREA04..........
000000C0 01 50 41 4B 2E 0D 00 00 80 E9 06 00 22 C2 EF 3A 41 52 45 41 30 35 00 00 00 00 00 00 00 00 00 00 .PAK........"..:AREA05..........
000000E0 01 50 41 4B 0C 0E 00 00 00 F8 06 00 22 C2 EF 3A 41 52 45 41 30 31 00 00 00 00 00 00 00 00 00 00 .PAK........"..:AREA01..........
00000100 01 50 41 4B EB 0E 00 00 EC 42 06 00 22 C2 EF 3A 41 52 45 41 30 36 00 00 00 00 00 00 00 00 00 00 .PAK.....B.."..:AREA06..........
00000120 01 50 41 4B B4 0F 00 00 8C 54 07 00 22 C2 EF 3A 41 52 45 41 30 32 00 00 00 00 00 00 00 00 00 00 .PAK.....T.."..:AREA02..........
00000140 01 50 41 4B 9F 10 00 00 50 72 07 00 22 C2 EF 3A 41 52 45 41 30 33 00 00 00 00 00 00 00 00 00 00 .PAK....Pr.."..:AREA03..........
00000160 01 50 41 4B 8E 11 00 00 78 E3 06 00 22 C2 EF 3A 41 52 45 41 30 30 00 00 00 00 00 00 00 00 00 00 .PAK....x..."..:AREA00..........
00000180 01 50 41 4B 6B 12 00 00 40 FF 06 00 22 C2 EF 3A 41 52 45 41 30 38 00 00 00 00 00 00 00 00 00 00 .PAKk...@..."..:AREA08..........
000001A0 01 50 41 4B 4B 13 00 00 60 A3 06 00 22 C2 EF 3A 41 52 45 41 30 39 00 00 00 00 00 00 00 00 00 00 .PAKK...`..."..:AREA09..........
000001C0 01 50 41 4B 20 14 00 00 A4 1E 07 00 22 C2 EF 3A 41 52 45 41 31 30 00 00 00 00 00 00 00 00 00 00 .PAK ......."..:AREA10..........
000001E0 01 50 41 4B 04 15 00 00 74 B2 07 00 24 C2 EF 3A 41 52 45 41 31 31 00 00 00 00 00 00 00 00 00 00 .PAK....t...$..:AREA11..........
00000200 01 50 41 4B FB 15 00 00 34 DC 06 00 22 C2 EF 3A 41 52 45 41 30 37 00 00 00 00 00 00 00 00 00 00 .PAK....4..."..:AREA07..........
00000220 01 53 43 43 D7 16 00 00 F0 00 00 00 2E C2 EF 3A 56 53 53 56 45 52 00 00 00 00 00 00 00 00 00 00 .SCC...........:VSSVER..........
00000240 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000280 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000002A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000002C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000002E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000300 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
as i figure it it reads every 32 bytes like this:
* first 4 bytes: 1 byte the Type and 3 bytes the Extension if not a folder
* second 4 bytes are the address, it's in big endian, and the real address is the numeber multiplyed by 2048 (0x800) (ej. 01 BD x 800 = DE800 = 911360)
* third 4 bytes: the size of the file
* fourth 4: no idea (attributes?)
* fifth and sixth: the name
* seventh and eigth: no idea
well, here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <iostream>
#include <fstream>
using namespace std;
typedef unsigned short int uint;
int length(0);
void GetData (char Input[32],int * Address, int * Size){ //HERE IS THE PROBLEM
//look at the end of the post, the output of this
cout << hex << short (unsigned (int (Input[4]))) << " " << unsigned (short (int (Input[5]))) << " " << unsigned (short (int (Input[6]))) << " " << unsigned (short (int (Input[7]))) \
<< "\t" << unsigned (short (int (Input[8]))) << " " << unsigned (short (int (Input[9]))) << " " << unsigned (short (int (Input[10]))) << " " << unsigned (short (int (Input[11]))) << endl;
int a = (unsigned (short (int (Input[4]))) + unsigned (short (int (Input[5]))) * 256 + unsigned (short (int (Input[6]))) * 65536 + unsigned (short (int (Input[7]))) * 16777216)*2048;
int b = (unsigned (short (int (Input[8]))) + unsigned (short (int (Input[9]))) * 256 + unsigned (short (int (Input[10]))) * 65536 + unsigned (short (int (Input[11]))) * 16777216);
cout << dec << a << "\t\t" << b << endl;
return;
}
void GetLength (ifstream * inFile, int * Target){
int i = inFile->tellg();
inFile->seekg (0, ios::end);
*Target = inFile->tellg();
inFile->seekg (i);
}
bool IsDivisible (int a, int b){
if (!a ==0 && a % b == 0){return true;}else{return false;}
}
void ListFiles (ifstream * inFile){
char buffer [32];
int Address = 0;
int Size = 0;
inFile->seekg(0);
for (int i = 0; i < 60; i++){
inFile->read(buffer, 32);
GetData(buffer, &Address, &Size);
}
return;
}
int main(int argc, char *argv[]) {
ifstream drvfile(argv[1], ios::binary);
if (drvfile.is_open()){
GetLength (&drvfile, &length);
cout << length << "bytes" << endl;
ListFiles(&drvfile); //just testing the function
drvfile.close();
}
else {cout << "error al abrir el archivo:" << argv[1] << endl;}
return 0;
}
|
and this is th output:
11976704bytes
1 0 0 0 0 0 0 0
2048 0
11 0 0 0 0 0 0 0
34816 0
ffbd 1 0 0 0 0 0 0
387072 0
ffc8 1 0 0 0 0 0 0
409600 0
52 c 0 0 1c 12 0 0
6459392 4636
FFBD are 2 bytes and the value is suposely a short int (1 byte)
and 387072 is BD*800, the correct value should be 911360 which is 1BD*800
C52 on the other side is correct 6459392 which is C52*800
anyone has any idea? what i need is to get the unsigned value for every byte (0-255) so that I can sum and multiply them to get the address value.
It seems to me that the file is opened as text, bypassing the binary flag
NOTE: Using linux (ubuntu 9.10) and Code:blocks with gcc