Commits

Palmer, 2E0EOL committed 2bca880

Initial commit.

Comments (0)

Files changed (4)

+#ifndef __INC_PATCHER_H
+#define __INC_PATCHER_H
+
+// Main program header
+//------------------------------------------------------------------------------
+#define __PATCHER_VERSION_MAJOR	0
+#define __PATCHER_VERSION_MINOR	01
+
+void ShowTitle(void);
+void ShowSyntax(void);
+//------------------------------------------------------------------------------
+#endif // __INC_PATCHER_H
Binary file added.
+File Patcher for MS-DOS V0.1 by David Duncan Ross Palmer
+Copyright 1998, Daybo Logic, all rights reserved.
+
+WARNING! DO NOT USE PATCHER	 LATER RELEASES WILL BE
+OK BUT THIS ONE DOESN'T WORK PROPERLY OR WITH LARGE FILES
+--------------------------------------------------------
+
+This program is not supposed to be used as a tool by the user,
+let's say one released a text file that described the internal
+working of a male brain, the file was 15 Megs and
+was called MALEBRAN.TXT, then on reading
+it one day you noticed the following text:
+
+'A brain text file would only need 20 Kbytes to describe'
+
+now that's wrong, obiously the text should read:
+
+'A brain text file could not be written as the logic used
+is erratic and bizzare'
+
+First of all one mutters a bit.  Next considering that releasing a new
+file would require about 11 disks (15/1.44) rounded and disks cost
+money, how about just correcting part of the user's file:
+
+USE PATCHER
+
+Remember: There must be enough space, PATCHER does not insert so
+if the file is longer than the bit of text you want to replace
+following text would be overwritten, one's individual circumstances
+dictate which action one takes and usually executable file that
+contain preset data that had to be changed would be the most likely
+candidate for PATCHER.
+
+OK let's say the correct text was in "NEWDATA.PAT", (NOTE that the
+file does not have to have a .PAT extention).
+
+...and the offset into the 15 Meg text file where the new text
+was to be inserted at was 3,444,049, offsets are relative to file base
+like 0 means right at the start, 1 means 1 byte after the start etc.
+
+NOTE: If the offset is greater than the file length and/or the
+patch data (the new stuff) will exceed the file length from the
+following calculation (offset + patch data length) the
+target data will be extended to accomodate the patch.
+
+Create a batch file containing the following to relieve the user of
+knowing the technical details:
+
+@Echo off
+echo Updating your text...
+PATCHER MALEBRAN.TXT NEWDATA.PAT 3444049
+echo Update complete, sorry about the error old chap, glad to be
+echo of assistance!
+
+This would do the job, remember to display messages because to
+hide the technical details the program (when run with correct
+parameters) displays nothing.
+#include <IOStream.H> // for cout
+#include <StdLib.H> // Standard library
+#include <Sys\Stat.H> // S_I... access mode constants
+#include <IO.H>
+#include <MEM.H>
+#pragma hdrstop
+
+#include "Patcher.h" // Main header
+#include "PieCrust.h" // Essentials
+#include "SmlFuncs.h" // namepsace SmallFuncs
+#include "BinHead.h" // Binary headers and file handling classes
+#include "PCIntern.h" // for BYTE and the like
+//------------------------------------------------------------------------------
+using namespace PieCrust;
+using namespace SmallFuncs;
+
+int main(int /*argc*/, char* argv[])
+{
+	if (!StdCmdLineFaults(3,3)) // Bad command line
+   {
+   	cout << endl;
+      ShowTitle();
+      ShowSyntax();
+      StdWin32ConsoleExit();
+   }
+   if (!CheckFileExistance(argv[1])) // Target to patch missing
+   {
+   	ShowTitle();
+   	cout << "Target file \"" << argv[1] << "\" missing.  Sorry!\n";
+      StdWin32ConsoleExit();
+   }
+   if (!CheckFileExistance(argv[2])) // Patch data file missing
+   {
+   	ShowTitle();
+   	cout << "Patch data file \"" << argv[2] << "\" missing.  Sorry!\n";
+      StdWin32ConsoleExit();
+   }
+   BinHeaders::TGenericClassedFile targetfile(argv[1], S_IWRITE);
+   targetfile.Open(); // Open the file ready for output
+   BinHeaders::TGenericClassedFile patchfile(argv[2], S_IREAD);
+   patchfile.Open(); // Open the file ready for input
+
+   lseek(targetfile.GetHandle(), (atoi(argv[3]) - 1), SEEK_SET); // Seek in target file to where to "paste" the patch
+   struct SmallFuncs::FILE_BLOCK_SIZE FileBlockSize; // Create structure on stack to get file block size info
+   CalcFileBlockSize(filelength(patchfile.GetHandle()), &FileBlockSize);
+
+   BYTE* Buffer = new BYTE[FileBlockSize.BufferSize]; // Allocate buffer
+   setmem(Buffer, FileBlockSize.BufferSize, 0x0); // Initialize memory
+   for (unsigned long _Loops=0;_Loops<FileBlockSize.Loops;_Loops++)
+   {
+   	read(patchfile.GetHandle(), Buffer, FileBlockSize.BufferSize); // Read data into the buffer
+      write(targetfile.GetHandle(), Buffer, FileBlockSize.BufferSize); // Write the data to the target
+   }
+   delete[] Buffer; // Deallocate buffer
+   if (FileBlockSize.Remainder) // ...and there's more
+   {
+   	Buffer = new BYTE[FileBlockSize.Remainder]; // Reallocate buffer with a different size
+      setmem(Buffer, FileBlockSize.BufferSize, 0x0); // Init mem
+      read(patchfile.GetHandle(), Buffer, FileBlockSize.Remainder); // Read remaining patch data
+      write(targetfile.GetHandle(), Buffer, FileBlockSize.Remainder); // Write remainding patch data to target
+      delete[] Buffer; // Release buffer
+   }
+
+   return EXIT_SUCCESS; // Successful exit
+}
+//------------------------------------------------------------------------------
+void ShowTitle()
+{
+	char tit[80/*max line*/]; // Title message space
+   char cvtnum[5]; // Space for itoa() conversions
+   strcpy(tit, "File Patcher for MS-DOS V");
+   strcat(tit, itoa(__PATCHER_VERSION_MAJOR, cvtnum, 10));
+   strcat(tit, ".");
+   strcat(tit, itoa(__PATCHER_VERSION_MINOR, cvtnum, 10));
+   strcat(tit, " by David Duncan Ross Palmer");
+   cout << tit << endl; // Output title and end line
+   cout << "Copyright 1998, Daybo Logic, all rights reserved.\n";
+   const size_t Lentit = strlen(tit); // Get the length of the copyright string
+   for (int i=0;i<Lentit;i++) // For every char above this line
+   	cout << "-"; // Output a hyphen to underline it
+   cout << endl; // end the line
+   return;
+}
+//------------------------------------------------------------------------------
+void ShowSyntax()
+{
+	cout << "PATCHER <TargetFile> <PatchFile> n\n";
+   cout << endl;
+   cout << "<TargetFile> - Filename of file to patch (usually an executable)\n";
+   cout << "<PatchFile> - File containing the patch data\n";
+   cout << "n - n specifies the offset that the patch data will patched into the\n"
+           "       target file at. This is a DWORD (between 1 and 2^32 inclusive).\n";
+   cout << "	- THESE PARAMETERS MUST ALL BE SUPPLIED (IN THIS ORDER) -\n";
+}
+//------------------------------------------------------------------------------