24 lines
1.3 KiB
C
24 lines
1.3 KiB
C
/* codec_run.exe <dll> <mode> <hex input> [repeat]: calls gw_codec_serialize, prints rc/size/hex head; checks heap. */
|
|
#include <windows.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
typedef int (*Serialize)(uint32_t, const void *, uint32_t, uint32_t, void *, uint32_t, uint32_t *);
|
|
int main(int argc, char **argv) {
|
|
if (argc < 4) return 1;
|
|
HMODULE codec = LoadLibraryA(argv[1]); if (!codec) return 2;
|
|
Serialize s = (Serialize)(void *)GetProcAddress(codec, "gw_codec_serialize"); if (!s) return 3;
|
|
uint32_t mode = strtoul(argv[2], NULL, 10); size_t n = strlen(argv[3]) / 2;
|
|
unsigned char *in = malloc(n); for (size_t i = 0; i < n; ++i) sscanf(argv[3] + 2 * i, "%2hhx", &in[i]);
|
|
int rep = argc > 4 ? atoi(argv[4]) : 1;
|
|
for (int k = 0; k < rep; ++k) {
|
|
uint32_t bytes = 0; int rc = s(mode, in, (uint32_t)n, 0, NULL, 0, &bytes);
|
|
unsigned char *out = malloc(bytes ? bytes : 1); int rc2 = s(mode, in, (uint32_t)n, 0, out, bytes, &bytes);
|
|
if (k == 0) { printf("rc=%d rc2=%d bytes=%u :", rc, rc2, bytes); for (uint32_t i = 0; i < bytes && i < 160; ++i) printf("%02x", out[i]); printf("\n"); }
|
|
free(out);
|
|
if (!HeapValidate(GetProcessHeap(), 0, NULL)) { printf("HEAP CORRUPT after %d\n", k); return 9; }
|
|
}
|
|
printf("heap ok\n"); return 0;
|
|
}
|