Re: [Selfext-user] Protection of SFX
Brought to you by:
mweth
|
From: Mike W. <mik...@nt...> - 2003-09-12 19:21:58
|
On Friday 12 September 2003 10:38 am, Ho Kei Lau wrote:
> Hello, I would like to protect my SFX from being able to be opened by other
> archivers like WinZip. I want to do it simply by removing the first 4 bytes
> ("MSCF") from the cabinet, then in file_read(), add the 4 bytes to the
> buffer temporarily. I have tried to do this .. but seems it only retrieves
> the header information, but NOT extracting the files
> inside. FNREAD(file_read) {
> DWORD rslt;
> if(SetFilePointer(GetHandle(hf), 0, 0, FILE_CURRENT)==g_iExeSize+8)
> {
> char* cTmp = (char*) pv;
> lstrcpy(cTmp, "MSCF");
> ReadFile(GetHandle(hf), &cTmp[4], cb-4, &rslt, NULL);
> return (rslt+4);
> } else
> {
> ReadFile(GetHandle(hf), pv, cb, &rslt, NULL);
> return rslt;
> }
> }
> What's wrong? Can somebody please help me? Kei
Hi Kei,
That's an interesting idea.
If you remove the 4 signature bytes (rather than just changing them), you
also need to subtract 4 from nOffset in Extract() so that all the seeking is
offset by 4 bytes.
Currently CheckValid() doesn't open the file using the 'filename|<nnnnnn>'
syntax to fake the start of the file, so a slight mod is needed there (see
below).
And then finally a change like you have there is needed to file_read().
You can get the offset to the start of the cab data within the executable
using GetPtr(hf) (see below).
Below is a patch for you that does this. I hope this helps, let me know if
you come across any difficulties applying it.
Mike
Index: ExtFdi.cpp
===================================================================
RCS file: /cvsroot/selfext/selfext/ExtFdi.cpp,v
retrieving revision 1.2
diff -u -2 -r1.2 ExtFdi.cpp
--- ExtFdi.cpp 18 Sep 2002 09:25:52 -0000 1.2
+++ ExtFdi.cpp 12 Sep 2003 18:48:22 -0000
@@ -204,5 +204,17 @@
{
DWORD rslt;
- ReadFile(GetHandle(hf), pv, cb, &rslt, NULL);
+
+ const file_struct *pfs = GetPtr(hf);
+
+ ReadFile(pfs->m_hFile, pv, cb, &rslt, NULL);
+
+ if (SetFilePointer(pfs->m_hFile, 0, 0, FILE_CURRENT) == pfs->m_nOffset + rslt)
+ {
+ if (cb > 4) cb = 4;
+ char *p = (char *)pv;
+ while (cb--)
+ p[cb] = "MSCF"[cb];
+ }
+
return rslt;
}
@@ -290,5 +302,8 @@
return LoadOsError(IDS_ERR_EXTRACTING, ERROR_CANCELLED);
- int hf = file_open((LPSTR)pszFilename, _O_BINARY|_O_RDONLY, 0);
+ CHAR szFile[MAX_PATH+11];
+ wsprintf(szFile, "%s|%d", pszFilename, nOffset);
+
+ int hf = file_open(szFile, _O_BINARY|_O_RDONLY, 0);
if (hf == -1)
return LoadOsError(IDS_ERR_EXTRACTING);
@@ -296,10 +311,4 @@
FDICABINETINFO fdici;
- if (file_seek(hf, nOffset, SEEK_SET) != nOffset)
- {
- LoadOsError(IDS_ERR_EXTRACTING);
- goto handle_error;
- }
-
if (!FDIIsCabinet(hfdi, hf, &fdici))
{
@@ -376,4 +385,6 @@
if (hfdi == NULL)
return LoadError(IDS_ERR_CABINIT, IDS_FDIERROR_NONE + erf.erfOper);
+
+ nOffset -= 4;
// check the file is a valid cabinet
|