Article View: borland.public.cppbuilder.nativeapi
Article #11953Re: Write to file
From: Remy Lebeau (TeamB)
Date: Thu, 08 Jan 2004 19:10
Date: Thu, 08 Jan 2004 19:10
26 lines
1864 bytes
1864 bytes
"Oliver Young" <none> wrote in message
news:3ffd501f$1@newsgroups.borland.com...
> How can I read bytes from an .exe and change (write to) i.e.
> bytes from 20000 to 20050?
Assuming you are only altering the existing bytes, but not adding/removing
bytes, then simply:
1) open the file in read/write mode
2) seek the file to position 20000
3) read 50 bytes into a buffer
4) alter the buffer as needed
5) seek the file back to position 20000
6) write the new buffer, it will overwrite the existing bytes
> Also, I need to search for keyword to find proper place in .exe file.
I would suggest looking at using a Memory Mapping via CreateFileMapping()
and MapViewOfFile(). That way, you can treat the file contents as a simple
char[] array, any use any number of existing buffer searching functions that
are available.
Gambit
Technical Details
Message-ID:
<3ffda9ba$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!fu-berlin.de!newsmi-eu.news.garr.it!newsmi-us.news.garr.it!NewsITBone-GARR!newsfeed.media.kyoto-u.ac.jp!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3ffd501f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,5ed80b5109227f83 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-08 11:16:16 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ffd501f$1@newsgroups.borland.com> Subject: Re: Write to file Date: Thu, 8 Jan 2004 11:10:25 -0800 Lines: 28 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.138.253 Message-ID: <3ffda9ba$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1073588666 67.22.138.253 (8 Jan 2004 11:04:26 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!fu-berlin.de!newsmi-eu.news.garr.it!newsmi-us.news.garr.it!NewsITBone-GARR!newsfeed.media.kyoto-u.ac.jp!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail