diff options
-rw-r--r-- | fake-winterop.c | 153 | ||||
-rw-r--r-- | libwinterop.so.la | 42 |
2 files changed, 195 insertions, 0 deletions
diff --git a/fake-winterop.c b/fake-winterop.c new file mode 100644 index 0000000..828b8fa --- /dev/null +++ b/fake-winterop.c | |||
@@ -0,0 +1,153 @@ | |||
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 | } | ||
71 | |||
72 | uint32_t HashPublicKeyInfo(void *pCertContext, | ||
73 | void *rgbSubjectKeyIdentifier, | ||
74 | uint32_t *pcbSubjectKeyIndentifier) | ||
75 | { | ||
76 | errx(1, "HashPublicKeyInfo NYI"); | ||
77 | } | ||
78 | |||
79 | uint32_t ResetAcls(const char16_t **pwzFiles, uint32_t cFiles) | ||
80 | { | ||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | uint32_t CreateCabBegin(const char16_t *wzCab, const char16_t *wzCabDir, | ||
85 | uint32_t dwMaxFiles, uint32_t dwMaxSize, | ||
86 | uint32_t dwMaxThresh, int compression, | ||
87 | void **out_ctx) | ||
88 | { | ||
89 | fprintf(stderr, "CreateCabBegin(\"%s\", \"%s\", ...)!\n", | ||
90 | ascii(wzCab, true), ascii(wzCabDir, true)); | ||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | uint32_t CreateCabAddFile(const char16_t *wzFile, const char16_t *wzToken, | ||
95 | void *pmfHash, void *ctx) | ||
96 | { | ||
97 | fprintf(stderr, "CreateCabAddFile!\n"); | ||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | uint32_t CreateCabAddFiles(const char16_t *const *pwzFiles, | ||
102 | const char16_t *const *pwzTokens, | ||
103 | void *pmfHash, uint32_t cFiles, void *hContext) | ||
104 | { | ||
105 | fprintf(stderr, "CreateCabAddFiles!\n"); | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | uint32_t CreateCabFinish(void *hContext, void *newCabNamesCallBackAddress) | ||
110 | { | ||
111 | /* FIXME: newCabNamesCallBackAddress is actually a fn ptr of some kind */ | ||
112 | fprintf(stderr, "CabCFinish(%p,%p)!\n", | ||
113 | hContext, newCabNamesCallBackAddress); | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | void CreateCabCancel(void *hContext) | ||
118 | { | ||
119 | fprintf(stderr, "CabCCancel(%p)!\n", hContext); | ||
120 | } | ||
121 | |||
122 | uint32_t ExtractCabBegin(void) | ||
123 | { | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | uint32_t ExtractCab(const char16_t *wzCabinet, const char16_t *wzExtractDir) | ||
128 | { | ||
129 | char *cab = ascii(wzCabinet, true), *dir = ascii(wzExtractDir, true); | ||
130 | fprintf(stderr, "ExtractCab(\"%s\", \"%s\"\n", cab, dir); | ||
131 | system_argv("cabextract", "-d", dir, cab, (const char *)NULL); | ||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | void ExtractCabFinish(void) | ||
136 | { | ||
137 | } | ||
138 | |||
139 | uint32_t EnumerateCabBegin(void) | ||
140 | { | ||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | uint32_t EnumerateCab(const char16_t *wzCabinet, void *pfnNotify) | ||
145 | { | ||
146 | /* FIXME: fpnNotify looks like a fn ptr again */ | ||
147 | fprintf(stderr, "EnumerateCab!\n"); | ||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | void EnumerateCabFinish(void) | ||
152 | { | ||
153 | } | ||
diff --git a/libwinterop.so.la b/libwinterop.so.la new file mode 100644 index 0000000..74b9ccc --- /dev/null +++ b/libwinterop.so.la | |||
@@ -0,0 +1,42 @@ | |||
1 | # libsane-u12.la - a libtool library file | ||
2 | # Generated by libtool (GNU libtool) 2.4.2 | ||
3 | # | ||
4 | # Please DO NOT delete this file! | ||
5 | # It is necessary for linking the library. | ||
6 | |||
7 | # The name that we can dlopen(3). | ||
8 | dlname='libwinterop.so' | ||
9 | |||
10 | # Names of this library. | ||
11 | library_names='libwinterop.so' | ||
12 | |||
13 | # The name of the static archive. | ||
14 | old_library='libwinterop.a' | ||
15 | |||
16 | # Linker flags that can not go in dependency_libs. | ||
17 | inherited_linker_flags='' | ||
18 | |||
19 | # Libraries that this one depends upon. | ||
20 | dependency_libs='' | ||
21 | |||
22 | # Names of additional weak libraries provided by this library | ||
23 | weak_library_names='' | ||
24 | |||
25 | # Version information for libwinterop. | ||
26 | current=1 | ||
27 | age=0 | ||
28 | revision=0 | ||
29 | |||
30 | # Is this an already installed library? | ||
31 | installed=no | ||
32 | |||
33 | # Should we warn about portability when linking against -modules? | ||
34 | shouldnotlink=no | ||
35 | |||
36 | # Files to dlopen/dlpreopen | ||
37 | dlopen='' | ||
38 | dlpreopen='' | ||
39 | |||
40 | # Directory that this library needs to be installed in: | ||
41 | libdir='/usr/lib/x86_64-linux-gnu' | ||
42 | |||