Код библиотеки
Скрипт inno
Проблема в том, что не пойму, как правильно выгрузить dll при неправильном пароле (или ошибке), то что свой поток нужен это понятно, где-то ошибка в коде?
C++:
#include <windows.h>
#include <strsafe.h>
#include <shlwapi.h>
#define call __stdcall
static HMODULE unarc_dll = 0;
FARPROC LoadFromDLL(char *funcname)
{
return GetProcAddress(unarc_dll, funcname);
}
typedef int Number;
typedef int call cbtype(char *what, Number int1, Number int2, char *str);
bool UnarcError = false;
/* ERRCODE unarc.dll
{
FREEARC_OK= 0; (* ALL RIGHT *)
FREEARC_ERRCODE_GENERAL= -1; (* Some error when (de)compressing *)
FREEARC_ERRCODE_INVALID_COMPRESSOR= -2; (* Invalid compression method or parameters *)
FREEARC_ERRCODE_ONLY_DECOMPRESS= -3; (* Program builded with FREEARC_DECOMPRESS_ONLY, so don't try to use compress *)
FREEARC_ERRCODE_OUTBLOCK_TOO_SMALL= -4; (* Output block size in (de)compressMem is not enough for all output data *)
FREEARC_ERRCODE_NOT_ENOUGH_MEMORY= -5; (* Can't allocate memory needed for (de)compression *)
FREEARC_ERRCODE_READ= -6; (* Error when reading data *)
FREEARC_ERRCODE_BAD_COMPRESSED_DATA= -7; (* Data can't be decompressed *)
FREEARC_ERRCODE_NOT_IMPLEMENTED= -8; (* Requested feature isn't supported *)
FREEARC_ERRCODE_NO_MORE_DATA_REQUIRED= -9; (* Required part of data was already decompressed *)
FREEARC_ERRCODE_OPERATION_TERMINATED= -10; (* Operation terminated by user *)
FREEARC_ERRCODE_WRITE= -11; (* Error when writing data *)
FREEARC_ERRCODE_BAD_CRC= -12; (* File failed CRC check *)
FREEARC_ERRCODE_BAD_PASSWORD= -13; (* Password/keyfile failed checkcode test *)
FREEARC_ERRCODE_BAD_HEADERS= -14; (* Archive headers are corrupted *)
FREEARC_ERRCODE_INTERNAL= -15; (* It should never happen: implementation error. Please report this bug to developers! *)
}
*/
int call callback(char *what, Number int1, Number int2, char *str)
{
if (!strcmp(what, "error") && (int1 < 0) && (int1 != -10))
{
wchar_t buf[16];
wsprintf(buf, L"%i", abs(int1));
MessageBox(NULL, buf, L"", MB_OK);
if (UnarcError == FALSE)
UnarcError = TRUE;
}
/* switch (ArcErrCode)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
//case 14:
//case 15:
UnarcError = true;
break;
default:
UnarcError = false;
break;
}
} */
return UnarcError ? -127 : 0;
}
void call ISArcExtract(char *InName, char *OutPath, char *ExtractedPath, char *Password, char *CfgFile, char *WorkPath)
{
if (PathFileExistsA(InName))
{
char CfgFileExt[MAX_PATH] = "-cfg";
if (lstrlenA(CfgFile) > 0)
StringCchCatA(CfgFileExt, MAX_PATH, CfgFile);
char WorkPathExt[MAX_PATH] = "-w";
if (lstrlenA(WorkPath) > 0)
StringCchCatA(WorkPathExt, MAX_PATH, WorkPath);
char ExtractedPathExt[MAX_PATH] = "-ap";
if (lstrlenA(ExtractedPath) > 0)
StringCchCatA(ExtractedPathExt, MAX_PATH, ExtractedPath);
char OutPathExt[MAX_PATH] = "-dp";
if (lstrlenA(OutPath) > 0)
StringCchCatA(OutPathExt, MAX_PATH, OutPath);
char PasswordExt[MAX_PATH] = "-p";
if (lstrlenA(Password) > 2)
StringCchCatA(PasswordExt, MAX_PATH, Password);
// Load function from unarc.dll
int(*FreeArcExtract) (cbtype *callback, ...) = (int(*) (cbtype *callback, ...)) LoadFromDLL("FreeArcExtract");
if (!FreeArcExtract) MessageBox(NULL, L"Cannot load FreeArcExtract from unarc.dll!", L"", MB_OK);
else {
if (FreeArcExtract(callback, "l", PasswordExt, "--", InName, "", "", "", "", "", "") == 0)
{
FreeArcExtract(callback, "x", "-o+", CfgFileExt, PasswordExt, WorkPathExt, ExtractedPathExt, OutPathExt, "--", InName, "");
//
//wchar_t buf[16];
//wsprintf(buf, L"%i", lstrlenA(InName));
//MessageBox(NULL, buf, L"", MB_OK);
}
}
} else MessageBox(NULL, L"It is not found any file specified for unarc.dll!", L"", MB_OK);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
{
// Get path
WCHAR path[MAX_PATH];
GetModuleFileName(hinstDLL, path, MAX_PATH);
PathRemoveFileSpec(path);
StringCchCat(path, MAX_PATH, L"\\unarc.dll");
unarc_dll = LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
{
// Unload unarc.dll
if (unarc_dll)
{
void(*UnloadDLL) (void) = (void(*) (void)) LoadFromDLL("UnloadDLL");
UnloadDLL;
FreeLibrary(unarc_dll);
}
}
break;
}
return TRUE;
}
code_language.pascal:
[Setup]
AppName=ReactIW4
AppVersion=1.3.2
DefaultDirName={pf}\ReactIW4
OutputDir=.
[Files]
Source: unarc.dll; DestDir: {tmp}; Flags: dontcopy deleteafterinstall
Source: ISFreeArcExtract.dll; DestDir: {tmp}; Flags: dontcopy deleteafterinstall
[UninstallDelete]
Type: filesandordirs; Name: {app}
[Code]
procedure ISArcExtract(InName, OutPath, ExtractedPath, Password, CfgFile, WorkPath: AnsiString); external 'ISArcExtract@files:ISFreeArcExtract.dll stdcall delayload';
function InitializeSetup(): Boolean;
begin
if not FileExists(ExpandConstant('{tmp}\unarc.dll')) then ExtractTemporaryFile('unarc.dll');
if not FileExists(ExpandConstant('{tmp}\ISFreeArcExtract.dll')) then ExtractTemporaryFile('ISFreeArcExtract.dll');
Result:= True;
end;
procedure InitializeWizard();
begin
//
ISArcExtract(ExpandConstant('{src}\data.arc'), ExpandConstant('{src}\tmp'), '', '123456', '', '');
end;
Последнее редактирование: