annotate tool/patchhook.c @ 6:87e9f30f5f86

ti-libpatch: patching implemented
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sat, 06 Jun 2015 04:51:15 +0000
parents
children 04fd47d382c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements the "patch hook" that checks if an archive member
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 * needs to be patched and invokes all necessary patch processing.
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4 */
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <time.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "ar.h"
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "globals.h"
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "patchinfo.h"
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 extern struct ar_hdr ar_hdr;
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 update_ar_timestamp()
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 {
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 time_t curtime;
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 time(&curtime);
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 sprintf(ar_hdr.ar_date, "%-12lu", (u_long) curtime);
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 }
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 patch_hook()
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 {
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 struct patch_module_desc *pmd;
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 struct patch_desc *patch;
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 for (pmd = patch_module_list; pmd; pmd = pmd->next)
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 if (!strcmp(pmd->member_name, member_name))
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 break;
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 if (!pmd)
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 return(0);
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 /* yes, we need to patch it: start digging into it */
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 parse_coff_hdr();
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 for (patch = pmd->patches; patch; patch = patch->next)
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 apply_patch(patch);
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 update_ar_timestamp();
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 return(1);
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 }