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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
typedef unsigned char BYTE;
long getFileSize(FILE *file)
{
long lCurPos, lEndPos;
lCurPos = ftell(file);
fseek(file, 0, 2);
lEndPos = ftell(file);
fseek(file, lCurPos, 0);
return lEndPos;
}
int main(){
double integer=0; //used for calculation of Hex value
int total; //also used for calculation of Hex value
const char *filePath = "C:\\temp.hps";
BYTE *fileBuf; // Pointer to our buffered data
FILE *file = NULL; // File pointer
streamoff offset;
cout<<"Please enter the offset in Hex:" <<endl;
cin>>hex>>offset;
cout<<"Please Enter how long the audio is in seconds:"<<endl;
cin>>integer;
total=32000*integer*(16.0/14.0)+15;
//takes total and changes it into a hexidecimal string
char Hex[9];
_itoa(total, Hex, 16);
// Open the file in binary mode using the "r+b" format string
if ((file = fopen(filePath, "rb")) == NULL)
cout << "Could not open specified file" << endl;
else
cout << "File opened successfully" << endl;
string Hexy=Hex;
cout<< "The appropriate hex is:"<<endl<<Hexy<<endl;
cout<<"Now putting the hex into the correct offset."<<endl;
//takes the string Hexy and puts it into an int that is usable.
int x;
fstream ss;
ss <<hex << Hexy;
ss >>x;
int *HexNum=&x;
// Get the size of the file in bytes
long fileSize = getFileSize(file);
// Allocate space in the buffer for the whole file
fileBuf = new BYTE[fileSize];
// Read the file in to the buffer
fread(fileBuf, fileSize, 1, file);
//go to the given offset and write the calculated Hex value there
fseek(file, offset, SEEK_CUR);
fwrite(HexNum, 1, 8, file);
//just printing to make sure it is at the right offset
for(int i = offset; i < offset+500; i++)
{
printf("%X ", fileBuf[i]);
}
cin.get();
delete[]fileBuf;
fclose(file);
system("pause");
}
|