aboutsummaryrefslogtreecommitdiff
path: root/subhook_x86.c
diff options
context:
space:
mode:
authorZeex <zeex@rocketmail.com>2013-01-15 03:57:07 +0700
committerZeex <zeex@rocketmail.com>2013-01-15 03:57:07 +0700
commit75f746195d54a90480431c42b126bb9be952bfd8 (patch)
tree192b9ff0a516aaebd1b7e4d33b8bee2710fca31b /subhook_x86.c
parent8347e1a37008e2ae73e97080c4e8455fd2213815 (diff)
downloadsubhook-75f746195d54a90480431c42b126bb9be952bfd8.zip
subhook-75f746195d54a90480431c42b126bb9be952bfd8.tar.gz
subhook-75f746195d54a90480431c42b126bb9be952bfd8.tar.bz2
Move arch initialization/cleanup to subhook_arch_{new,free}
Diffstat (limited to 'subhook_x86.c')
-rw-r--r--subhook_x86.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/subhook_x86.c b/subhook_x86.c
index a040cb3..a838ed8 100644
--- a/subhook_x86.c
+++ b/subhook_x86.c
@@ -38,6 +38,17 @@ struct subhook_x86 {
unsigned char code[SUBHOOK_JUMP_SIZE];
};
+int subhook_arch_new(struct subhook *hook) {
+ if ((hook->arch = malloc(sizeof(struct subhook_x86))) == NULL)
+ return -ENOMEM;
+
+ return 0;
+}
+
+void subhook_arch_free(struct subhook *hook) {
+ free(hook->arch);
+}
+
SUBHOOK_EXPORT int SUBHOOK_API subhook_install(struct subhook *hook) {
static const unsigned char jmp = 0xE9;
void *src, *dst;
@@ -49,12 +60,6 @@ SUBHOOK_EXPORT int SUBHOOK_API subhook_install(struct subhook *hook) {
src = subhook_get_source(hook);
dst = subhook_get_destination(hook);
- /* allocate machine-specific data on frist install */
- if (hook->arch == NULL) {
- if ((hook->arch = malloc(sizeof(struct subhook_x86))) == NULL)
- return -ENOMEM;
- }
-
subhook_unprotect(src, SUBHOOK_JUMP_SIZE);
memcpy(((struct subhook_x86 *)hook->arch)->code, src, SUBHOOK_JUMP_SIZE);