diff options
| -rw-r--r-- | fake-lib.c | 70 | ||||
| -rw-r--r-- | fake-msi.c | 110 | ||||
| -rw-r--r-- | fake-winterop.c | 6 |
3 files changed, 183 insertions, 3 deletions
diff --git a/fake-lib.c b/fake-lib.c new file mode 100644 index 0000000..f8dbea4 --- /dev/null +++ b/fake-lib.c | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | #include <stdbool.h> | ||
| 5 | #include <stdarg.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <uchar.h> | ||
| 8 | #include <err.h> | ||
| 9 | |||
| 10 | #include <sys/types.h> | ||
| 11 | #include <sys/wait.h> | ||
| 12 | #include <unistd.h> | ||
| 13 | |||
| 14 | static char *ascii(const char16_t *wstr, bool translate_slashes) | ||
| 15 | { | ||
| 16 | size_t len = 0; | ||
| 17 | for (const char16_t *wp = wstr; *wp; wp++) | ||
| 18 | len++; | ||
| 19 | char *ret = malloc(len + 1); | ||
| 20 | char *p = ret; | ||
| 21 | for (const char16_t *wp = wstr; *wp; wp++) | ||
| 22 | *p++ = (*wp == '\\' && translate_slashes ? '/' : | ||
| 23 | *wp < 0x80 ? *wp : | ||
| 24 | '?'); | ||
| 25 | *p = '\0'; | ||
| 26 | return ret; | ||
| 27 | } | ||
| 28 | |||
| 29 | static void system_argv(const char *cmd, ...) | ||
| 30 | { | ||
| 31 | int nargs, nchars; | ||
| 32 | const char *word; | ||
| 33 | va_list ap; | ||
| 34 | |||
| 35 | va_start(ap, cmd); | ||
| 36 | nargs = 1; /* terminating NULL */ | ||
| 37 | nchars = 0; | ||
| 38 | for (word = cmd; word; word = va_arg(ap, const char *)) { | ||
| 39 | nargs++; | ||
| 40 | nchars += 1 + strlen(word); | ||
| 41 | } | ||
| 42 | va_end(ap); | ||
| 43 | |||
| 44 | char *args[nargs], chars[nchars]; | ||
| 45 | char **argp = args, *charp = chars; | ||
| 46 | va_start(ap, cmd); | ||
| 47 | for (word = cmd; word; word = va_arg(ap, const char *)) { | ||
| 48 | *argp++ = charp; | ||
| 49 | strcpy(charp, word); | ||
| 50 | charp += 1 + strlen(word); | ||
| 51 | } | ||
| 52 | va_end(ap); | ||
| 53 | *argp++ = NULL; | ||
| 54 | |||
| 55 | pid_t pid = fork(); | ||
| 56 | if (pid < 0) | ||
| 57 | err(1, "fork"); | ||
| 58 | |||
| 59 | if (pid == 0) { | ||
| 60 | execvp(args[0], args); | ||
| 61 | warn("execvp"); | ||
| 62 | _exit(127); | ||
| 63 | } | ||
| 64 | |||
| 65 | int status; | ||
| 66 | if (waitpid(pid, &status, 0) != pid) | ||
| 67 | err(1, "waitpid"); | ||
| 68 | if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) | ||
| 69 | errx(1, "subcommand failed"); | ||
| 70 | } | ||
| @@ -7,9 +7,117 @@ | |||
| 7 | #include <uchar.h> | 7 | #include <uchar.h> |
| 8 | #include <err.h> | 8 | #include <err.h> |
| 9 | 9 | ||
| 10 | #include <fcntl.h> | ||
| 11 | |||
| 12 | static char *ascii(const char16_t *wstr, bool translate_slashes) | ||
| 13 | { | ||
| 14 | size_t len = 0; | ||
| 15 | for (const char16_t *wp = wstr; *wp; wp++) | ||
| 16 | len++; | ||
| 17 | char *ret = malloc(len + 1); | ||
| 18 | char *p = ret; | ||
| 19 | for (const char16_t *wp = wstr; *wp; wp++) | ||
| 20 | *p++ = (*wp == '\\' && translate_slashes ? '/' : | ||
| 21 | *wp < 0x80 ? *wp : | ||
| 22 | '?'); | ||
| 23 | *p = '\0'; | ||
| 24 | return ret; | ||
| 25 | } | ||
| 26 | |||
| 27 | static void c16cpy(char16_t *out, uint32_t *outsize, char *s) | ||
| 28 | { | ||
| 29 | uint32_t retlen = 0; | ||
| 30 | while (retlen < *outsize) { | ||
| 31 | char16_t c = (out[retlen] = (unsigned char)*s++); | ||
| 32 | if (!c) | ||
| 33 | break; | ||
| 34 | retlen++; | ||
| 35 | } | ||
| 36 | *outsize = retlen; | ||
| 37 | } | ||
| 38 | |||
| 10 | uint32_t MsiGetFileVersionW(const char16_t *filename, | 39 | uint32_t MsiGetFileVersionW(const char16_t *filename, |
| 11 | char16_t *version, uint32_t *version_size, | 40 | char16_t *version, uint32_t *version_size, |
| 12 | char16_t *language, uint32_t *language_size) | 41 | char16_t *language, uint32_t *language_size) |
| 13 | { | 42 | { |
| 14 | errx(1, "NYI: MsiGetFileVersion"); | 43 | warnx("FIXME: MsiGetFileVersion(%s)", ascii(filename, true)); |
| 44 | if (version) { | ||
| 45 | c16cpy(version, version_size, "0.1.2.3"); | ||
| 46 | } | ||
| 47 | if (language) { | ||
| 48 | c16cpy(language, language_size, "2057"); | ||
| 49 | } | ||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | uint32_t MsiOpenDatabaseW(const char16_t *filename, | ||
| 54 | const char16_t *persist, | ||
| 55 | void **handle) | ||
| 56 | { | ||
| 57 | char *file = ascii(filename, true); | ||
| 58 | warnx("FIXME: MsiOpenDatabaseW(%s,%p)", file, persist); | ||
| 59 | close(open(file, O_WRONLY | O_CREAT, 0666)); | ||
| 60 | *handle = (void *)1; | ||
| 61 | return 0; | ||
| 62 | } | ||
| 63 | |||
| 64 | uint32_t MsiCloseHandle(void *handle) | ||
| 65 | { | ||
| 66 | warnx("FIXME: MsiCloseHandle(%p)", handle); | ||
| 67 | return 0; | ||
| 68 | } | ||
| 69 | |||
| 70 | uint32_t MsiDatabaseImportW(void *handle, const char16_t *folder, | ||
| 71 | const char16_t *file) | ||
| 72 | { | ||
| 73 | warnx("FIXME: MsiDatabaseImport(%p,%s,%s)", handle, ascii(folder, true), | ||
| 74 | ascii(file, true)); | ||
| 75 | return 0; | ||
| 76 | } | ||
| 77 | |||
| 78 | uint32_t MsiDatabaseOpenViewW(void *handle, const char16_t *query, | ||
| 79 | void **outhandle) | ||
| 80 | { | ||
| 81 | warnx("FIXME: MsiDatabaseOpenView(%p,%s)", handle, ascii(query, false)); | ||
| 82 | *outhandle = (void *)2; | ||
| 83 | return 0; | ||
| 84 | } | ||
| 85 | |||
| 86 | uint32_t MsiViewExecute(void *handle, void *params) | ||
| 87 | { | ||
| 88 | warnx("FIXME: MsiViewExecute(%p)", handle); | ||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | |||
| 92 | void *MsiCreateRecord(uint32_t nparams) | ||
| 93 | { | ||
| 94 | warnx("FIXME: MsiCreateRecord(%u)", (unsigned)nparams); | ||
| 95 | return (void *)3; | ||
| 96 | } | ||
| 97 | |||
| 98 | uint32_t MsiRecordSetStringW(void *handle, uint32_t field, char16_t *value) | ||
| 99 | { | ||
| 100 | warnx("FIXME: MsiRecordSetString(%p,%u,%s)", handle, (unsigned)field, | ||
| 101 | ascii(value, false)); | ||
| 102 | return 0; | ||
| 103 | } | ||
| 104 | |||
| 105 | uint32_t MsiRecordSetStreamW(void *handle, uint32_t field, char16_t *path) | ||
| 106 | { | ||
| 107 | warnx("FIXME: MsiRecordSetStream(%p,%u,%s)", handle, (unsigned)field, | ||
| 108 | ascii(path, true)); | ||
| 109 | return 0; | ||
| 110 | } | ||
| 111 | |||
| 112 | uint32_t MsiViewModify(void *vhandle, uint32_t mode, void *rechandle) | ||
| 113 | { | ||
| 114 | warnx("FIXME: MsiViewModify(%p,%u,%p)", | ||
| 115 | vhandle, (unsigned)mode, rechandle); | ||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | |||
| 119 | uint32_t MsiDatabaseCommit(void *handle) | ||
| 120 | { | ||
| 121 | warnx("FIXME: MsiDatabaseCommit(%p)", handle); | ||
| 122 | return 0; | ||
| 15 | } | 123 | } |
diff --git a/fake-winterop.c b/fake-winterop.c index 828b8fa..ae4b8ef 100644 --- a/fake-winterop.c +++ b/fake-winterop.c | |||
| @@ -86,15 +86,17 @@ uint32_t CreateCabBegin(const char16_t *wzCab, const char16_t *wzCabDir, | |||
| 86 | uint32_t dwMaxThresh, int compression, | 86 | uint32_t dwMaxThresh, int compression, |
| 87 | void **out_ctx) | 87 | void **out_ctx) |
| 88 | { | 88 | { |
| 89 | fprintf(stderr, "CreateCabBegin(\"%s\", \"%s\", ...)!\n", | 89 | fprintf(stderr, "CreateCabBegin(\"%s\", \"%s\", ...)\n", |
| 90 | ascii(wzCab, true), ascii(wzCabDir, true)); | 90 | ascii(wzCab, true), ascii(wzCabDir, true)); |
| 91 | *out_ctx = (void *)10; | ||
| 91 | return 0; | 92 | return 0; |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | uint32_t CreateCabAddFile(const char16_t *wzFile, const char16_t *wzToken, | 95 | uint32_t CreateCabAddFile(const char16_t *wzFile, const char16_t *wzToken, |
| 95 | void *pmfHash, void *ctx) | 96 | void *pmfHash, void *ctx) |
| 96 | { | 97 | { |
| 97 | fprintf(stderr, "CreateCabAddFile!\n"); | 98 | fprintf(stderr, "CreateCabAddFile(%p,%s,%s)\n", ctx, |
| 99 | ascii(wzFile, true), ascii(wzToken, false)); | ||
| 98 | return 0; | 100 | return 0; |
| 99 | } | 101 | } |
| 100 | 102 | ||
