summarylogtreecommitdiffstats
path: root/hydan-0.13.patch
blob: c44a0fa16123a2d22b846b66fb769ae362c8605b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
diff -aur hydan/hdn_crypto.c hydan.fix/hdn_crypto.c
--- hydan/hdn_crypto.c	2004-06-24 01:03:49.000000000 +0000
+++ hydan.fix/hdn_crypto.c	2018-01-28 01:29:43.646404182 +0000
@@ -68,7 +68,9 @@
 uint8_t *hdn_crypto_hash (char *in)
 {
     uint8_t *digest;
-    EVP_MD_CTX ctx;
+    EVP_MD_CTX *ctx;
+
+    ctx = EVP_MD_CTX_new();
 
     if (!in)
         return NULL;
@@ -76,9 +78,11 @@
     if (!(digest = malloc (EVP_MAX_MD_SIZE)))
         return NULL;
 
-    EVP_DigestInit (&ctx, HASH_ALGO);
-    EVP_DigestUpdate (&ctx, in, strlen (in));
-    EVP_DigestFinal (&ctx, digest, NULL);
+    EVP_DigestInit (ctx, HASH_ALGO);
+    EVP_DigestUpdate (ctx, in, strlen (in));
+    EVP_DigestFinal (ctx, digest, NULL);
+
+    EVP_MD_CTX_free (ctx);
 
     return digest;
 }
@@ -88,26 +92,30 @@
     uint8_t *cipher = NULL;
     uint32_t out_sz, sz, total_sz;
     hdn_data_t *in = (*inout);
-    EVP_CIPHER_CTX ctx;
+    EVP_CIPHER_CTX *ctx;
+
+    ctx = EVP_CIPHER_CTX_new ();
+    if (!ctx)
+        HDN_EXIT ("Error allocating memory for encryption context. ");
 
     /*
      * init context, bf in cbc mode, default impl
      */
-    EVP_EncryptInit (&ctx, CRYPTO_ALGO, key, iv);
-    cipher = malloc (sizeof (in->sz) + in->sz + EVP_CIPHER_CTX_block_size(&ctx));
+    EVP_EncryptInit (ctx, CRYPTO_ALGO, key, iv);
+    cipher = malloc (sizeof (in->sz) + in->sz + EVP_CIPHER_CTX_block_size(ctx));
 
     if (!cipher)
         HDN_EXIT ("Error allocating memory for encryption. "
                   "Requested %d bytes of memory.",
-                  sizeof (in->sz) + in->sz + EVP_CIPHER_CTX_block_size(&ctx));
+                  sizeof (in->sz) + in->sz + EVP_CIPHER_CTX_block_size(ctx));
 
     /*
      * save the size, and make sure that it's a multiple of the cipher
      * block size
      */
     sz = in->sz;
-    in->sz += EVP_CIPHER_CTX_block_size(&ctx) -
-        ((in->sz + sizeof (in->sz)) % EVP_CIPHER_CTX_block_size(&ctx));
+    in->sz += EVP_CIPHER_CTX_block_size(ctx) -
+        ((in->sz + sizeof (in->sz)) % EVP_CIPHER_CTX_block_size(ctx));
 
     /*
      * whiten it
@@ -117,10 +125,10 @@
     /*
      * encrypt everything
      */
-    EVP_EncryptUpdate (&ctx, cipher, &out_sz, (char *)in, sizeof(in->sz) + sz);
+    EVP_EncryptUpdate (ctx, cipher, &out_sz, (char *)in, sizeof(in->sz) + sz);
     total_sz = out_sz;
 
-    EVP_EncryptFinal (&ctx, cipher + total_sz, &out_sz);
+    EVP_EncryptFinal (ctx, cipher + total_sz, &out_sz);
     total_sz += out_sz;
 
     /*
@@ -138,8 +146,9 @@
     /*
      * cleanup
      */
-    EVP_CIPHER_CTX_cleanup (&ctx);
+    EVP_CIPHER_CTX_cleanup (ctx);
     if (cipher) free (cipher);
+    if (ctx) EVP_CIPHER_CTX_free (ctx);
 }
 
 void hdn_crypto_decrypt (hdn_data_t **inout, uint8_t *key)
@@ -147,23 +156,27 @@
     uint8_t *plain = NULL;
     uint32_t out_sz;
     hdn_data_t *in = (*inout);
-    EVP_CIPHER_CTX ctx;
+    EVP_CIPHER_CTX *ctx;
+
+    ctx = EVP_CIPHER_CTX_new ();
+    if (!ctx)
+        HDN_EXIT ("Error allocating memory for encryption context. ");
 
     /*
      * init
      */
-    EVP_DecryptInit (&ctx, CRYPTO_ALGO, key, iv);
-    plain = malloc (in->sz + EVP_CIPHER_CTX_block_size(&ctx));
+    EVP_DecryptInit (ctx, CRYPTO_ALGO, key, iv);
+    plain = malloc (in->sz + EVP_CIPHER_CTX_block_size(ctx));
 
     if (!plain)
         HDN_EXIT ("Error allocating memory for decryption. "
-                  "Requested %d bytes.", in->sz + EVP_CIPHER_CTX_block_size(&ctx));
+                  "Requested %d bytes.", in->sz + EVP_CIPHER_CTX_block_size(ctx));
 
     /*
      * decrypt
      */
-    EVP_DecryptUpdate (&ctx, plain, &out_sz, in->content, in->sz);
-    EVP_DecryptFinal (&ctx, plain + out_sz, &out_sz);
+    EVP_DecryptUpdate (ctx, plain, &out_sz, in->content, in->sz);
+    EVP_DecryptFinal (ctx, plain + out_sz, &out_sz);
 
     /*
      * store only the right length worth of decryption
@@ -181,7 +194,8 @@
     /*
      * cleanup
      */
-    EVP_CIPHER_CTX_cleanup (&ctx);
+    EVP_CIPHER_CTX_cleanup (ctx);
     if (plain) free (plain);
+    if (ctx) EVP_CIPHER_CTX_free (ctx);
 }
 
diff -aur hydan/hdn_exe.c hydan.fix/hdn_exe.c
--- hydan/hdn_exe.c	2004-05-26 19:42:44.000000000 +0000
+++ hydan.fix/hdn_exe.c	2018-01-28 01:27:02.940370747 +0000
@@ -11,7 +11,7 @@
 /*
  * checks wether a section is code or not
  */
-inline char hdn_exe_section_is_code (hdn_sections_t *hs)
+char hdn_exe_section_is_code (hdn_sections_t *hs)
 {
 #if (defined(__CYGWIN32__) || defined(_Windows) || defined(_WIN32))
 
diff -aur hydan/hdn_exe.h hydan.fix/hdn_exe.h
--- hydan/hdn_exe.h	2004-05-26 16:16:38.000000000 +0000
+++ hydan.fix/hdn_exe.h	2018-01-28 01:26:57.247059868 +0000
@@ -19,6 +19,6 @@
 /*
  * is a section code or not?
  */
-inline char hdn_exe_section_is_code (hdn_sections_t *hs);
+char hdn_exe_section_is_code (hdn_sections_t *hs);
 
 #endif//!HDN_EXE_H_
diff -aur hydan/hdn_io.c hydan.fix/hdn_io.c
--- hydan/hdn_io.c	2004-05-26 14:56:23.000000000 +0000
+++ hydan.fix/hdn_io.c	2018-01-29 21:18:48.275372408 +0000
@@ -128,7 +128,7 @@
 {
     int fd;
 
-    if ( (fd = open (filename, O_CREAT | O_WRONLY | O_TRUNC)) < 0)
+    if ( (fd = open (filename, O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU)) < 0)
     {
         perror ("open");
         exit (1);
diff -aur hydan/libdisasm/src/arch/i386/libdisasm/bastard.c hydan.fix/libdisasm/src/arch/i386/libdisasm/bastard.c
--- hydan/libdisasm/src/arch/i386/libdisasm/bastard.c	2003-12-01 01:13:35.000000000 +0000
+++ hydan.fix/libdisasm/src/arch/i386/libdisasm/bastard.c	2018-01-29 21:09:02.240952152 +0000
@@ -1,4 +1,6 @@
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include "./libdis.h"
 #include "./bastard.h"
 #ifdef _MSC_VER
diff -aur hydan/libdisasm/src/arch/i386/libdisasm/i386_invariant.c hydan.fix/libdisasm/src/arch/i386/libdisasm/i386_invariant.c
--- hydan/libdisasm/src/arch/i386/libdisasm/i386_invariant.c	2003-12-01 01:13:35.000000000 +0000
+++ hydan.fix/libdisasm/src/arch/i386/libdisasm/i386_invariant.c	2018-01-29 21:11:13.993780351 +0000
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include "./i386_opcode.h"
 #ifdef _MSC_VER
 	#include <memory.h>
diff -aur hydan/libdisasm/src/arch/i386/libdisasm/vm.c hydan.fix/libdisasm/src/arch/i386/libdisasm/vm.c
--- hydan/libdisasm/src/arch/i386/libdisasm/vm.c	2003-12-01 01:13:35.000000000 +0000
+++ hydan.fix/libdisasm/src/arch/i386/libdisasm/vm.c	2018-01-29 21:20:00.525095533 +0000
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <string.h>
 #include "./libdis.h"
 #include "./i386.h"
 #ifdef _MSC_VER