Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrar.dll - technical proposal for correct extraction and find for load algoritm used after Git-2ce8617ba #1116

Open
VictorVG opened this issue Dec 31, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@VictorVG
Copy link

commented Dec 31, 2018

Users make reasonable comments about the loss of portability of the program after Git 2ce8617 - the unrar.dll library is always unpacked in the %LOCALAPPDATA%\SumatraPDF\Extracted<randomdiir> directory even if it is in the same directory as the SumatraPDF executable.

To eliminate their comments, I propose to adjust the algorithm for searching and loading this DL like:

Proc DLLTools(); 
 Dcl CDir Char
  Dcl DllPatch Char
  CDir = GetEnv(%CurrentDir%);
      Begin; 
          IfFileExists(CDir\unrar.dll) Then Load(CDir\unrar.dll) Else
              Begin
                   If (GetFileAttrib(CDir) == "Read Only") or (GetDirLockStatus(CDir) == "Locked")) Then 
                      DllPatch = GetEnv(%TEMP%)..L'\SumatraPDF\Extracted Else DllPatch = CDir;
                   End;
                     Put(unrar.dll,DllPatch);
                     Load(unrar.dll,DllPatch)
               End;
            End;
        End; 
      Return;      
   End;

P.S.

And taking this opportunity, let me congratulate you on the upcoming New Year and wish you happiness, health and more good and interesting people on the path of life.

@kjk

This comment has been minimized.

Copy link
Member

commented Dec 31, 2018

Thanks for the good wishes and happy New Year to you as well.

Yes, I'll improve this to use existing dll first.

@VictorVG

This comment has been minimized.

Copy link
Author

commented Dec 31, 2018

Thank you And once again you a Happy New Year!

@VictorVG

This comment has been minimized.

Copy link
Author

commented Feb 26, 2019

I rewrites src\AppTools.cpp DLL extract algorithm and added try check for Read Only folders:

Rewrites src\AppTools.cpp DLL extract algorithm

/* Begin startup variable block */

Dcl ExePath Char
Dcl DllPath Char

/* Get random part for DLL patch */

   Suf = Subst(1,32,Random());

/* Get 'SumatraPDF.exe' patch use WinAPI */

   ExePath = GetExePath('SumatraPDF.exe');

/* End startup variable block */

/* Begin function block */

/* Check startup patch */

/* Check "%Program Files%" or "%Program Files(x86)%" */
  Function CheckPF()
     Return = (Subst(4,13,ExePath) == "Program Files");
  End;

/* End function block */

/* Begin SumatraPDF.exe DLL init block */

   If ((CheckPF() or IsAttrib(ExePath,ReadOnly)) Then
      Begin:
        If IsAmd64('SumatraPDF.exe') Then
          Put('unrar64.dll',GetEnv('APPDATA').."\Local\SumatraPDF\extracted");
         Else
          Put('unrar.dll',GetEnv('APPDATA').."\Local\SumatraPDF\extracted");
        End;
          DllPath = GetEnv('APPDATA').."\Local\SumatraPDF\extracted";
      End;
     Else
      Begin;
       If not (IsExist('unrar.dll',ExePath) or IsExist('unrar64.dll',ExePath)) Then
        If IsAmd64('SumatraPDF.exe') Then Put('unrar64.dll',ExePath) Else Put('unrar.dll',ExePath) End;
        DllPath = ExePath;
       End;
      End;
    End;

/* Load needed DLL */

    If IsAmd64 Then load('unrar64.dll',DllPath) Else load('unrar.dll',DllPath) End;

/* End SumatraPDF.exe DLL init block */

Reasone for editing is minimized write's on Flash/SSD disks

@VictorVG

This comment has been minimized.

Copy link
Author

commented Mar 1, 2019

Test files for check open RAR 5.0 format - test-rar29.cbr - used RAR 2.9 format is supported the lib unaar and test-rar50.cbr used RAR 5.0 format (header signature 0x52 0x61 0x72 0x21 0x1a 0х00 0x00) not supported existing version lib unaar.

test-rar29.cbr.zip
test-rar50.cbr.zip

@VictorVG

This comment has been minimized.

Copy link
Author

commented Apr 20, 2019

I read Rar unpack code in to rar/rar rar.c (212):

    if (memcmp(signature, "Rar!\x1A\x07\x00", sizeof(signature)) != 0) {
        if (memcmp(signature, "Rar!\x1A\x07\x01", sizeof(signature)) == 0)
            warn("RAR 5 format isn't supported");

and in the yard the 2019th year :)

ps. - fix typo

@VictorVG

This comment has been minimized.

Copy link
Author

commented Apr 23, 2019

I added wish up to unarr project for add support RAR5 format Issues #3 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.