topics/44988-validation-de-procedure-dll
La procédure étant validée..
Etat des lieux:
Je fais partie d'une équipe (bénévole) pour l'amélioration d'un jeu de simulation, Fa18 jane's , La socièté EA US n'ayant plus les sources, nous avons eu l'accord de travailler sur le code assembleur..vive le reverse enginering!! bref..
L'assembleur va bien un moment..Le problème qui se pose est d'attaquer une DLL dont on a juste une description des fonctions/classes dans un Header..
// skunkcmp.h
// my attempt at the class spec for:
// CCat
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
//------------------------------------------------------------------
// CLASS CCat
// Supports read/write of a file type called a catalog.
// A catalog contains one or more compressed data files.
// The first 32bit word in the file is the number of data files.
// 4 more unknown words follow. The file record table then follows.
// It is a table consisting of one entry for each file. Each entry
// is of the type FILEHDR (see below).
//------------------------------------------------------------------
typedef struct
{ // 92 bytes for each file in a catalog
// this table starts at byte 0x14 in the catalog file
// there is one entry for each file in the catalog
char filename[64]; // original name of expanded file
int sizeex; // original size of expanded_file;
int sizecmp; // original size of compressed_file;
char* offset; // distance from top of file to the compressed data;
int unk1;
int unk2;
char* filelocation; // location of expanded and loaded file in memory
int unk4;
} FILEHDR;
//__declspec(dllexport) void CCat(void);
class DLLIMPORT CCat {
// data members 288 bytes
private:
char Unk[260]; // unknown maybe temp storage for compression routine?
int FileHandle; // windows assigned file handle
FILEHDR* pFileHeader; // pointer to top of FILEHDR table (probably should be public)
int FileCount; // number of files in file
int Unk1;
int Unk2;
int Unk3;
int Unk4;
public:
//
// GetFileCount
// returns number of files in current CCat
int GetFileCount(void);
//
// Open
// opens file with name pointed to by c1
// reads the FILEHDR record table from the file
// returns 0=failure 1=success
int Open(char* c1);
//
// LoadFile
// reads and decompresses file with name pointed to by c1
// from the currently open CCat
// stores the location of the decompressed file at a
// location pointed to by p1
// stores the length of the files at a location
// pointed to by u1
int LoadFile(char* c1,void** p1,unsigned long * u1);
//
// WriteFileToDisk
// writes a decompressed copy file with index i1 in the
// currently open CCat to disk into a file named c1
// i2==1 force overwrite, i2==0 disallow overwrite
int WriteFileToDisk(int i1,char* c1,int i2);
//
// LoadFile
// reads and decompresses file with index i1 in the currently open CCat
// stores the location of the decompressed file at a
// location pointed to by p1
// stores the length of the files at a location
// pointed to by u1
int LoadFile(int i1,void** p1,unsigned long * u1);
//
// FreeAll
// release all expanded files that have been loaded into memory
void FreeAll(void);
//
// Close
// closes the currently open CCat
void Close(void);
//
// FreeFile
// release file c1 from memory
int FreeFile(char* c1);
//
// FreeFile
// release file i1 from memory
int FreeFile(int i1);
//
// LoadAll
// load all file in catalog. return number of successful loads
// the pointers to each expanded file needs to be obtained from
// the FILEHDR table separately
int LoadAll(void);
//
// CCat assignment operator
CCat& operator=( const CCat& );
//
// ExpandFile
// expands a single compressed file c1
// into a single exploded file c2
// this function is unrelated to the CCat
// catalogs, and thus is static
static int ExpandFile(char* c1,char* c2);
//
// CompressFile
// compresses a single file c1
// into a single compressed file c2
// this function is unrelated to the CCat
// catalogs, and thus is static
// the newly compressed file is not openable via the Open function
static int CompressFile(char* c1,char* c2);
// probably determines if file c1 is compressed using
// the CompressFile function. Since this is static, it
// is unlikely that it is usable on the CCat catalogs
static int IsCompressed(char* c1);
//
// GetFileName
// returns a pointer to the filename of file with index i1 in the
// currently open catalog
char* GetFileName(int i1);
//
// Constructor
CCat();
//
// Destructor
~CCat(void);
protected:
//
//**GetFileHdr
// returns pointer to the file table entry for
// file c1 in the currently open CCat
FILEHDR* GetFileHdr(char* c1);
//
//**GetFileHdr
// returns pointer to the file table entry for
// file index i1 in the currently open CCat
FILEHDR* GetFileHdr(int i1);
//
//**LoadFile
// called by the other LoadFile functions.
// This is where the real action is.
int LoadFile(FILEHDR* p1);
//
//**CacheFile
// this is called from LoadFile(FILEHDR*)
// allocates space for the file to be loaded,
// and then acutually reads and decompresses the file
// and stores the location of the decompressed file into
// the filelocation slot of the current FILEHDR
int CacheFile(FILEHDR* p1);
//
//**FreeFile
// frees up memory for the file referenced by p1
int FreeFile(FILEHDR* p1);
public:
//
// CreateCatalog
// opens a dialog box for selecting files
// to be added to a new catalog file.
int CreateCatalog(void);
};
#endif /* _DLL_H_ */
Voici le prog principal:
#include "skunkcmp.h"
#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
using namespace std;
char *c1="C:\FA-18\Wrapper\Brief.cmp";
int main(int argc, char *argv[])
{
CCat *myCCat = new CCat() ;
myCCat->Open(c1) ;
system("pause") ;
return 0;
}
Pour créer ma librairie d'importation, j'ai utilisé ce fichier .def:
obtenu avec pexport et réinjecter dans dlltool..
LIBRARY SkunkCmp.dll
EXPORTS
??0CCat@@QAE@XZ
??0CChunkFile@@QAE@XZ
??1CCat@@QAE@XZ
??1CChunkFile@@QAE@XZ
??4CCat@@QAEAAV0@ABV0@@Z
??4CChunkFile@@QAEAAV0@ABV0@@Z
?AddChunk@CChunkFile@@QAEHKKPAXKH@Z
?CheckChunkFileSize@CChunkFile@@IAEHK@Z
?Close@CCat@@QAEXXZ
?Close@CChunkFile@@QAEXXZ
?ExpandFile@CCat@@SAHPAD0@Z
?ExtendFileSize@CChunkFile@@IAEHK@Z
?FindChunk@CChunkFile@@IAEPAUCHUNKREC@@KK@Z
?FreeAll@CCat@@QAEXXZ
?FreeFile@CCat@@IAEHPAUFILEHDR@@@Z
?FreeFile@CCat@@QAEHH@Z
?FreeFile@CCat@@QAEHPAD@Z
?GetCurrentFileSize@CChunkFile@@IAEKXZ
?GetFileCount@CCat@@QAEHXZ
?GetFileHdr@CCat@@IAEPAUFILEHDR@@H@Z
?Open@CCat@@QAEHPAD@Z
?Open@CChunkFile@@QAEHPADHK@Z
Voilà mon erreur de compil:
Compilateur: Default compiler
Building Makefile: "D:\++p\TestDll\tools\dev\Makefile.win"
Exécution de make...
make.exe -f "D:\++p\TestDll\tools\dev\Makefile.win" all
g++.exe main.o -o "Skunkcmp.exe" -L"H:/DEV-CPP/lib" -L"D:/++p/TestDll/tools/dev" -lskunkcmp
main.o(.text+0x5a):main.cpp: undefined reference to `CCat::CCat()'
main.o(.text+0x6b):main.cpp: undefined reference to `CCat::Open(char*)'
Exécution terminée
Pour vérifier les noms des fonctions: j'ai même utilisé IDA pro sur la Dll en question :
??0CCat@@QAE@XZ proc near
jmp ds:__imp_??0CCat@@QAE@XZ ; __declspec(dllimport) CCat::CCat(void)
??0CCat@@QAE@XZ endp
public: int __thiscall CCat::Open(char *)
?Open@CCat@@QAEHPAD@Z proc near
jmp ds:__imp_?Open@CCat@@QAEHPAD@Z ; __declspec(dllimport) CCat::Open(char *)
?Open@CCat@@QAEHPAD@Z endp
; public: __thiscall CCat::~CCat(void)
??1CCat@@QAE@XZ proc near
jmp ds:__imp_??1CCat@@QAE@XZ ; __declspec(dllimport) CCat::~CCat(void)
??1CCat@@QAE@XZ endp
et même fait un dump ascii de la lib d'importation!!:
_?Open@CCat@@QAEHPAD@Z
__imp__?Open@CCat@@QAEHPAD@Z
etc..
Je ne vois pas du tout ce que j'ai fait comme erreur
si un expert de la DLL passe dans le coin, le bar est ouvert.....
Je pense que je vous ai fait un topo complet sur le petit projet..et je n'ai rien oublié..