473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Little Patch Program in C++

Ok what does the program do:
opens a file binary, jumps to an specific offset (0x3529BC9) reads out
the string which is 7 bytes (7 chars) long (which starts at the
offset), then generates a random string 7 char long sting (string
s[7]).
Thats what I was able to do, but now I want to replace this offset by
this random string and write the patched file to back to the file. i
didnt know how do do it with vectors, also this file write operations
were not working the way i wanted it, heres my code:

Ok what does the program do:
opens a file, jumps to an specific offset reads out the string which is
7 bytes or 7 chars long, then generates a random string.
thats what i was able to do but now i want to replace this offset by
this random string and write the patched file to back to the file. i
didnt know how do do it with vectors, also this file write opertions
were not working the way i wanted it, heres my code:

#include <iostream>
#include <fstream>
#include <string>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, _TCHAR* argv[])
{
char _string[7];
char _filename[128];
int _offset = 0x3529BC;

if(argc == 1)
{
system("cls");
cout << "\nUsage: patch.exe
[path/filename]\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" ;
cout << "Enter path and filename to your
FlashpointResistance.exe\n\n";
cout << "(eg. C:/Desktop/ofp.exe): ";
cin >> _filename;
}
else
{
strcpy(_filename, argv[1]);
}

ifstream ofp;
ofp.open(_filename, ios_base::in | ios::binary);

if(!ofp.is_open())
{
system("cls");
cout << "\nResults:\n";
cout << " File \"" << _filename << "\" not found.\n\n";
}
else
{
system("cls");
//##### Create the "random" 7 bytes long string ######
ostringstream os;
os << hex << time(0);
string s = os.str();
s.resize(7);

//###### Read the string[7] at offset 0x3529BC ######
ofp.seekg(_offset, ios::beg);
ofp.read(_string, 7);
ofp.close();

ostringstream os2;
os2 << _string;
string s2 = os2.str();
s2.resize(7);

//##### Prints the results out ##########
cout << "\nFilename: \t\t" << _filename << endl;
cout << "Random Filestring: \t" << s << endl;
cout << "Existing String: \t" << s2 << endl;
//#####Here starts the part where the string is to be replaced and
the file to be saved (overwritten) #####
ifstream ofp;

// ###### here i tryed it somehow with vectors but i have no idead
how #######
std::vector<char> v(0x3529BC);
ofp.read(&v[0],0x3529BC);
}

return 0;
}

Jul 23 '05 #1
10 3688
Son of Sam wrote:
Ok what does the program do:
opens a file binary, jumps to an specific offset (0x3529BC9) reads out
the string which is 7 bytes (7 chars) long (which starts at the
offset), then generates a random string 7 char long sting (string
s[7]).
Thats what I was able to do, but now I want to replace this offset by
this random string and write the patched file to back to the file. i
didnt know how do do it with vectors, also this file write operations
were not working the way i wanted it, heres my code:

Ok what does the program do:
opens a file, jumps to an specific offset reads out the string which is
7 bytes or 7 chars long, then generates a random string.
thats what i was able to do but now i want to replace this offset by
this random string and write the patched file to back to the file. i
didnt know how do do it with vectors, also this file write opertions
were not working the way i wanted it, heres my code:

#include <iostream>
#include <fstream>
#include <string>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, _TCHAR* argv[])
{
char _string[7];
char _filename[128];
int _offset = 0x3529BC;

if(argc == 1)
{
system("cls");
cout << "\nUsage: patch.exe
[path/filename]\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" ;
cout << "Enter path and filename to your
FlashpointResistance.exe\n\n";
cout << "(eg. C:/Desktop/ofp.exe): ";
cin >> _filename;
}
else
{
strcpy(_filename, argv[1]);
}

//ifstream ofp;
//ofp.open(_filename, ios_base::in | ios::binary);

fstream ofp;
ofp.open(_filename, ios_base::in |ios_base::out | ios::binary);


if(!ofp.is_open())
{
system("cls");
cout << "\nResults:\n";
cout << " File \"" << _filename << "\" not found.\n\n";
}
else
{
system("cls");
//##### Create the "random" 7 bytes long string ######
ostringstream os;
os << hex << time(0);
string s = os.str();
s.resize(7);

//###### Read the string[7] at offset 0x3529BC ######
//ofp.seekg(_offset, ios::beg);
//ofp.read(_string, 7);
//ofp.close();

ofp.pubseekoff(_offset, ios_base::beg,
ios_base::in | ios_base::out);
ofp.read(_string, 7);


ostringstream os2;
os2 << _string;
string s2 = os2.str();
s2.resize(7);

//##### Prints the results out ##########
cout << "\nFilename: \t\t" << _filename << endl;
cout << "Random Filestring: \t" << s << endl;
cout << "Existing String: \t" << s2 << endl;
//#####Here starts the part where the string is to be replaced and
the file to be saved (overwritten) ##### //ifstream ofp;

// ###### here i tryed it somehow with vectors but i have no idead
how #######
//std::vector<char> v(0x3529BC);
//ofp.read(&v[0],0x3529BC);

ofp.pubseekoff(_offset, ios_base::beg,
ios_base::in | ios_base::out);
ofp.write(s.c_str(), 7);
ofp.close();


}

return 0;
}

Jul 23 '05 #2
Hi thanks for this code, my compiler says: error C2039: 'pubseekoff' :
is not a member of 'std::basic_fstream<_Elem,_Traits>'

I use msvs c++ (2003) as compiler.

Heres the code:

#pragma once

#include <iostream>
#include <fstream>
#include <string>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, _TCHAR* argv[])
{
char _string[7];
char _filename[128];
int _offset = 0x3529BC;

if(argc == 1)
{
system("cls");
cout << "\nUsage: patch.exe
[path/filename]\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" ;
cout << "Enter path and filename to your
FlashpointResistance.exe\n\n";
cout << "(eg. C:/Desktop/ofp.exe): ";
cin >> _filename;
}
else
{
strcpy(_filename, argv[1]);
}

//ifstream ofp;
//ofp.open(_filename, ios_base::in | ios::binary);

fstream ofp;
ofp.open(_filename, ios_base::in |ios_base::out | ios::binary);

if(!ofp.is_open())
{
system("cls");
cout << "\nResults:\n";
cout << " File \"" << _filename << "\" not found.\n\n";
}
else
{
system("cls");
//##### Create the "random" 7 bytes long string ######
ostringstream os;
os << hex << time(0);
string s = os.str();
s.resize(7);

//###### Read the string[7] at offset 0x3529BC ######
//ofp.seekg(_offset, ios::beg);
//ofp.read(_string, 7);
//ofp.close();
ofp.pubseekoff(_offset, ios_base::beg, ios_base::in |
ios_base::out);
ofp.read(_string, 7);

ostringstream os2;
os2 << _string;
string s2 = os2.str();
s2.resize(7);

cout << "\nFilename: \t\t" << _filename << endl;
cout << "Random Filestring: \t" << s << endl;
cout << "Existing String: \t" << s2 << endl;
//################################################## ############
//ifstream ofp;
//std::vector<char> v(0x3529BC);
//ofp.read(&v[0],0x3529BC);
ofp.pubseekoff(_offset, ios_base::beg,
ios_base::in | ios_base::out);
ofp.write(s.c_str(), 7);
ofp.close();

}

return 0;
}

Jul 23 '05 #3
* Son of Sam:
Ok what does the program do:
opens a [FlashpointResistance] file binary, jumps to an specific
offset (0x3529BC9) reads out the string which is 7 bytes (7 chars)
long (which starts at the offset), then generates a random string
7 char long sting (string > s[7]).


<ot>If this patch is in order to defeat some copy protection
scheme you'll soon have a horde of very angry very competent Russian
hackers displeased with you -- which would please _me_. :-) </ot>

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #4
> If this patch is in order to defeat some copy protection scheme
Nope, copyprotection of the FlashpointResistance.exe for exmple comes
without a copyprotection ;)

Thanks for the code Larry I Smith, heres the finished code:

#include <iostream>
#include <fstream>
#include <string>
#include <tchar.h>
#include <stdio.h>
#include <time.h>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
[...]
fstream ofp;
ofp.open(_filename, ios_base::in |ios_base::out | ios::binary);

if(!ofp.is_open())
{
system("cls");
cout << "\nResults:\n";
cout << " File \"" << _filename << "\" not found.\n\n";
}
else
{
system("cls");
//##### Create the "random" 7 bytes long string ######
ostringstream os;
os << hex << time(0);
string s = os.str();
s.resize(7);

//###### Read the string[7] at offset 0x3529BC ######
ofp.pubseekoff(_offset, ios_base::beg, ios_base::in |
ios_base::out);
ofp.read(_string, 7);

ostringstream os2;
os2 << _string;
string s2 = os2.str();
s2.resize(7);

cout << "\nFilename: \t\t" << _filename << endl;
cout << "Random Filestring: \t" << s << endl;
cout << "Existing String: \t" << s2 << endl;
//################################################## ############
ofp.pubseekoff(_offset, ios_base::beg,
ios_base::in | ios_base::out);
ofp.write(s.c_str(), 7);
ofp.close();

}

....but my compiler gives me following error message: error C2039:
'pubseekoff' : is not a member of 'std::basic_fstream<_Elem,_Traits>'

How can I fix that?

Jul 23 '05 #5
Son of Sam wrote:
Hi thanks for this code, my compiler says: error C2039: 'pubseekoff' :
is not a member of 'std::basic_fstream<_Elem,_Traits>'

I use msvs c++ (2003) as compiler.

Heres the code:


[snip]
Try looking in the manual. Read the docs on streams.

It should be:

ofp.rdbuf()->pubseekoff(_offset, ios_base::beg,
ios_base::in |ios_base::out);

Larry
Jul 23 '05 #6
Son of Sam wrote:
If this patch is in order to defeat some copy protection scheme Nope, copyprotection of the FlashpointResistance.exe for exmple comes
without a copyprotection ;)


[snip]

...but my compiler gives me following error message: error C2039:
'pubseekoff' : is not a member of 'std::basic_fstream<_Elem,_Traits>'

How can I fix that?


Try looking in the manual. Read the docs on streams.

It should be:

ofp.rdbuf()->pubseekoff(_offset, ios_base::beg,
ios_base::in |ios_base::out);

Larry
Jul 23 '05 #7
> Try looking in the manual. RTFM :p
Yes I did,
http://www.cplusplus.com/ref/iostrea...ubseekoff.html here I
looked at the exmaple but it was not like this code here thats why I
wasnt sure what to do.

But anyways thanks that.

Jul 23 '05 #8
pubseekoff is a member of basic_streambuf which is not derived from when
forming the fstream class. Try using seekp (for write position) and
seekg (for read position) instead.

Son of Sam wrote:
Hi thanks for this code, my compiler says: error C2039: 'pubseekoff' :
is not a member of 'std::basic_fstream<_Elem,_Traits>'

I use msvs c++ (2003) as compiler.

Jul 23 '05 #9
ok i fixed it.

Jul 23 '05 #10
ok i fixed it, my project is finished.

Jul 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: PatchFactory Support | last post by:
Description: Professional and easy-to-use patch building environment that can help you to create instant patch packages for software and file updating. Generated patch packages are small size...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 259 open ( -5) / 2573 closed (+17) / 2832 total (+12) Bugs : 745 open ( +0) / 4405 closed (+21) / 5150 total (+21) RFE : 150 open...
0
by: liu | last post by:
as we know that In MS. Visual Studio.Net, we can create a setup program to install our program. I had create a window application in vb.net and create the setup file. but now, i don't know how to...
3
by: Joe | last post by:
Back in March I submitted a patch for cgi.py to sourceforge to fix a problem with the handling of an invalid REQUEST_METHOD. I thought I followed all the steps to properly submit the bug and...
2
by: gaffar | last post by:
Sir, In a form i have kept 2 textboxes(a,b) and a button(add). which supports only of integer values i have written. after entering the values in the textboxes and after clicking the add...
5
by: djoefish | last post by:
Does anyone know how to install a patch on Winodws? For example, I want to install the patch 'ocmalloc-free-arenas.diff' in Python 2.3. thanks...
2
by: djoefish | last post by:
sequel to the topic "install patch on windows"..... I am currently running Python2.3 with Enthought on a windows PC. I have been running into a memory problem (see...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 342 open (-38) / 3712 closed (+54) / 4054 total (+16) Bugs : 951 open (-14) / 6588 closed (+33) / 7539 total (+19) RFE : 257 open...
11
by: Don | last post by:
QUESTIONS: 1. Has anyone figured out how to successfully install the Office 97 Pro Service Release 2 patch in Vista? 2. Has anyone successfully installed an Office 97 Pro CD (SR2 version) in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.