diff options
Diffstat (limited to 'fake-msi.c')
-rw-r--r-- | fake-msi.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -193,6 +193,44 @@ uint32_t MsiGetFileVersionW(const char16_t *filename, | |||
193 | sfree(fname); | 193 | sfree(fname); |
194 | return toret; | 194 | return toret; |
195 | } | 195 | } |
196 | |||
197 | struct MsiHash { | ||
198 | uint32_t structure_size; | ||
199 | uint32_t hash_words[4]; | ||
200 | }; | ||
201 | |||
202 | uint32_t MsiGetFileHashW(const char16_t *filename, uint32_t options, | ||
203 | struct MsiHash *hash) | ||
204 | { | ||
205 | char *fname = ascii(filename, true); | ||
206 | int fd = -1; | ||
207 | void *mapv = MAP_FAILED; | ||
208 | uint32_t toret; | ||
209 | |||
210 | fd = open(fname, O_RDONLY); | ||
211 | if (fd < 0) | ||
212 | err(1, "%s: open", fname); | ||
213 | struct stat st; | ||
214 | if (fstat(fd, &st) < 0) | ||
215 | err(1, "%s: fstat", fname); | ||
216 | size_t fsize = st.st_size; | ||
217 | mapv = mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, fd, 0); | ||
218 | if (mapv == MAP_FAILED) | ||
219 | err(1, "%s: mmap", fname); | ||
220 | |||
221 | MD5Simple(mapv, fsize, hash->hash_words); | ||
222 | warnx("MsiGetFileHash(%s) -> %08x:%08x:%08x:%08x", fname, | ||
223 | (unsigned)hash->hash_words[0], (unsigned)hash->hash_words[1], | ||
224 | (unsigned)hash->hash_words[2], (unsigned)hash->hash_words[3]); | ||
225 | toret = 0; | ||
226 | |||
227 | cleanup: | ||
228 | if (mapv != MAP_FAILED) | ||
229 | munmap(mapv, fsize); | ||
230 | if (fd != -1) | ||
231 | close(fd); | ||
232 | sfree(fname); | ||
233 | return toret; | ||
196 | } | 234 | } |
197 | 235 | ||
198 | typedef struct MsiTypePrefix { | 236 | typedef struct MsiTypePrefix { |