dawsonliu 发表于 2024-7-28 09:47

16位C/C++代码调用DLL问题

各位大神,

论坛里有一个帖子:【新提醒】数据库逆向工程(三) - 『脱壳破解区』 - 吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

英文原文:https://medium.com/@MorteNoir/database-reverse-engineering-part-3-code-reuse-conclusion-b2145420b09b

讲的是如何通过直接调用`FNAUTIL2.dll`来读取图片压缩数据`MCImage.DAT`文件的,我尝试了很久,试过在Windows XP下通过`Open Watcom C`来调用,但都失败了。
有了解这个的大神吗?能给一些指导,我将非常感激!


```C
#include <windows.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>

typedef struct {
    long unk_1;
    long unk_2;
    int unk_3;
    int mcimage;
} ImageFileData;

typedef int (FAR PASCAL *GETCOMPRESSEDIMAGE)( LPINT, LPLONG, LPLONG, LONG, LONG, ImageFileData*);

BOOL decrypt_image(const char* mcimage_path,
            unsigned long enc_image_offset,
            unsigned long enc_image_size)
{
    HANDLE hDrv;
    GETCOMPRESSEDIMAGE GETCOMPRESSEDIMAGE_Addr;

    char message;
    HBITMAP bitmap;
    int mcimage;
    long screen_width = 0;
    long screen_height = 0;
    int ret_val = 0;
    ImageFileData data = {0,0,0,0};

    if ((hDrv = LoadLibrary("FAPUTIL.DLL")) < 32) {
      MessageBox(NULL, "ERROR: failed to load GETCOMPRESSEDIMAGE from FAPUTIL.DLL\n", "Error", MB_OK | MB_TASKMODAL);
      return FALSE;
    } else {
      sprintf(message, "%s -> %d", "Works LoadLibrary: ", hDrv);
      MessageBox(NULL, message, "Success", MB_OK | MB_TASKMODAL);
    }

    GETCOMPRESSEDIMAGE_Addr = GetProcAddress(hDrv, "GETCOMPRESSEDIMAGE");

    if (! GETCOMPRESSEDIMAGE_Addr) {
      MessageBox(NULL, "ERROR: failed to GetProcAddress GETCOMPRESSEDIMAGE from FAPUTIL.DLL\n", "Error", MB_OK | MB_TASKMODAL);
      return FALSE;
    } else {
      sprintf(message, "%s -> %d", "Works GETCOMPRESSEDIMAGE_Addr: ", GETCOMPRESSEDIMAGE_Addr);
      MessageBox(NULL, message, "Success", MB_OK | MB_TASKMODAL);
    }

    mcimage = open(mcimage_path, O_RDONLY | O_BINARY);

    sprintf(message, "%s %s %d", mcimage_path, " -> ", mcimage);
    MessageBox(NULL, message, "Success", MB_OK | MB_TASKMODAL);

    data.mcimage = mcimage;

    bitmap = (*(GETCOMPRESSEDIMAGE) GETCOMPRESSEDIMAGE_Addr)(&ret_val, &screen_height, &screen_width, enc_image_size, enc_image_offset, &data);

    sprintf(message, "%s %d", " bitmap -> ", bitmap);
    MessageBox(NULL, message, "Success", MB_OK | MB_TASKMODAL);

    close(mcimage);
    return TRUE;
}

int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
    char* mcimage_path = "C:\\FAP_data\\MCImage.DAT";

    if (!LoadDLL(mcimage_path, 377759538, 21337))
    {
      MessageBox(NULL, "Could not load dll!", "Error", MB_OK | MB_TASKMODAL);
    }

    return (0);
}

```
页: [1]
查看完整版本: 16位C/C++代码调用DLL问题