...
|
...
|
@@ -92,14 +92,15 @@ if(ctx->limits && ctx->limits->maxfilesize && (CHK) > ctx->limits->maxfilesize)
|
92
|
92
|
} \
|
93
|
93
|
}
|
94
|
94
|
|
95
|
|
-#define CLI_UNPTEMP(NAME,...) \
|
|
95
|
+#define CLI_UNPTEMP(NAME,FREEME) \
|
96
|
96
|
if(!(tempfile = cli_gentemp(NULL))) { \
|
97
|
|
- cli_multifree(__VA_ARGS__,0); \
|
|
97
|
+ cli_multifree FREEME; \
|
98
|
98
|
return CL_EMEM; \
|
99
|
99
|
} \
|
100
|
100
|
if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) { \
|
101
|
101
|
cli_dbgmsg(NAME": Can't create file %s\n", tempfile); \
|
102
|
|
- cli_multifree(tempfile,__VA_ARGS__,0); \
|
|
102
|
+ free(tempfile); \
|
|
103
|
+ cli_multifree FREEME; \
|
103
|
104
|
return CL_EIO; \
|
104
|
105
|
}
|
105
|
106
|
|
...
|
...
|
@@ -131,14 +132,15 @@ if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) { \
|
131
|
131
|
free(tempfile); \
|
132
|
132
|
break; \
|
133
|
133
|
|
134
|
|
-#define CLI_UNPRESULTS_(NAME,FSGSTUFF,EXPR,GOOD,...) \
|
|
134
|
+#define CLI_UNPRESULTS_(NAME,FSGSTUFF,EXPR,GOOD,FREEME) \
|
135
|
135
|
switch(EXPR) { \
|
136
|
136
|
case GOOD: /* Unpacked and rebuilt */ \
|
137
|
137
|
if(cli_leavetemps_flag) \
|
138
|
138
|
cli_dbgmsg(NAME": Unpacked and rebuilt executable saved in %s\n", tempfile); \
|
139
|
139
|
else \
|
140
|
140
|
cli_dbgmsg(NAME": Unpacked and rebuilt executable\n"); \
|
141
|
|
- cli_multifree(__VA_ARGS__,exe_sections,0); \
|
|
141
|
+ cli_multifree FREEME; \
|
|
142
|
+ free(exe_sections); \
|
142
|
143
|
fsync(ndesc); \
|
143
|
144
|
lseek(ndesc, 0, SEEK_SET); \
|
144
|
145
|
cli_dbgmsg("***** Scanning rebuilt PE file *****\n"); \
|
...
|
...
|
@@ -153,19 +155,20 @@ if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) { \
|
153
|
153
|
free(tempfile); \
|
154
|
154
|
return CL_CLEAN; \
|
155
|
155
|
\
|
156
|
|
-FSGSTUFF \
|
|
156
|
+FSGSTUFF; \
|
157
|
157
|
\
|
158
|
158
|
default: \
|
159
|
159
|
cli_dbgmsg(NAME": Unpacking failed\n"); \
|
160
|
160
|
close(ndesc); \
|
161
|
161
|
unlink(tempfile); \
|
162
|
|
- cli_multifree(__VA_ARGS__,tempfile,0); \
|
|
162
|
+ cli_multifree FREEME; \
|
|
163
|
+ free(tempfile); \
|
163
|
164
|
}
|
164
|
165
|
|
165
|
166
|
|
166
|
|
-#define CLI_UNPRESULTS(NAME,EXPR,GOOD,...) CLI_UNPRESULTS_(NAME,,EXPR,GOOD,__VA_ARGS__)
|
167
|
|
-#define CLI_UNPRESULTSFSG1(NAME,EXPR,GOOD,...) CLI_UNPRESULTS_(NAME,FSGCASE(NAME,free(sections)),EXPR,GOOD,__VA_ARGS__)
|
168
|
|
-#define CLI_UNPRESULTSFSG2(NAME,EXPR,GOOD,...) CLI_UNPRESULTS_(NAME,FSGCASE(NAME,),EXPR,GOOD,__VA_ARGS__)
|
|
167
|
+#define CLI_UNPRESULTS(NAME,EXPR,GOOD,FREEME) CLI_UNPRESULTS_(NAME,NULL,EXPR,GOOD,FREEME)
|
|
168
|
+#define CLI_UNPRESULTSFSG1(NAME,EXPR,GOOD,FREEME) CLI_UNPRESULTS_(NAME,FSGCASE(NAME,free(sections)),EXPR,GOOD,FREEME)
|
|
169
|
+#define CLI_UNPRESULTSFSG2(NAME,EXPR,GOOD,FREEME) CLI_UNPRESULTS_(NAME,FSGCASE(NAME,NULL),EXPR,GOOD,FREEME)
|
169
|
170
|
|
170
|
171
|
struct offset_list {
|
171
|
172
|
uint32_t offset;
|
...
|
...
|
@@ -1142,8 +1145,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1142
|
1142
|
uselzma = 0;
|
1143
|
1143
|
}
|
1144
|
1144
|
|
1145
|
|
- CLI_UNPTEMP("MEW",src,exe_sections);
|
1146
|
|
- CLI_UNPRESULTS("MEW",(unmew11(i, src, offdiff, ssize, dsize, EC32(optional_hdr32.ImageBase), exe_sections[0].rva, uselzma, NULL, NULL, ndesc)),1,src);
|
|
1145
|
+ CLI_UNPTEMP("MEW",(src,exe_sections,0));
|
|
1146
|
+ CLI_UNPRESULTS("MEW",(unmew11(i, src, offdiff, ssize, dsize, EC32(optional_hdr32.ImageBase), exe_sections[0].rva, uselzma, NULL, NULL, ndesc)),1,(src,0));
|
1147
|
1147
|
break;
|
1148
|
1148
|
}
|
1149
|
1149
|
}
|
...
|
...
|
@@ -1253,8 +1256,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1253
|
1253
|
return CL_EIO;
|
1254
|
1254
|
}
|
1255
|
1255
|
|
1256
|
|
- CLI_UNPTEMP("Upack",dest,exe_sections);
|
1257
|
|
- CLI_UNPRESULTS("Upack",(unupack(upack, dest, dsize, epbuff, vma, ep, EC32(optional_hdr32.ImageBase), exe_sections[0].rva, ndesc)),1,dest);
|
|
1256
|
+ CLI_UNPTEMP("Upack",(dest,exe_sections,0));
|
|
1257
|
+ CLI_UNPRESULTS("Upack",(unupack(upack, dest, dsize, epbuff, vma, ep, EC32(optional_hdr32.ImageBase), exe_sections[0].rva, ndesc)),1,(dest,0));
|
1258
|
1258
|
break;
|
1259
|
1259
|
}
|
1260
|
1260
|
}
|
...
|
...
|
@@ -1348,8 +1351,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1348
|
1348
|
return CL_EMEM;
|
1349
|
1349
|
}
|
1350
|
1350
|
|
1351
|
|
- CLI_UNPTEMP("FSG",src,dest,exe_sections);
|
1352
|
|
- CLI_UNPRESULTSFSG2("FSG",(unfsg_200(newesi - exe_sections[i + 1].rva + src, dest, ssize + exe_sections[i + 1].rva - newesi, dsize, newedi, EC32(optional_hdr32.ImageBase), newedx, ndesc)),1,src,dest);
|
|
1351
|
+ CLI_UNPTEMP("FSG",(src,dest,exe_sections,0));
|
|
1352
|
+ CLI_UNPRESULTSFSG2("FSG",(unfsg_200(newesi - exe_sections[i + 1].rva + src, dest, ssize + exe_sections[i + 1].rva - newesi, dsize, newedi, EC32(optional_hdr32.ImageBase), newedx, ndesc)),1,(src,dest,0));
|
1353
|
1353
|
break;
|
1354
|
1354
|
}
|
1355
|
1355
|
|
...
|
...
|
@@ -1471,8 +1474,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1471
|
1471
|
oldep = vep + 161 + 6 + cli_readint32(epbuff+163);
|
1472
|
1472
|
cli_dbgmsg("FSG: found old EP @%x\n", oldep);
|
1473
|
1473
|
|
1474
|
|
- CLI_UNPTEMP("FSG",src,dest,sections,exe_sections);
|
1475
|
|
- CLI_UNPRESULTSFSG1("FSG",(unfsg_133(src + newesi - exe_sections[i + 1].rva, dest, ssize + exe_sections[i + 1].rva - newesi, dsize, sections, sectcnt, EC32(optional_hdr32.ImageBase), oldep, ndesc)),1,src,dest,sections);
|
|
1474
|
+ CLI_UNPTEMP("FSG",(src,dest,sections,exe_sections,0));
|
|
1475
|
+ CLI_UNPRESULTSFSG1("FSG",(unfsg_133(src + newesi - exe_sections[i + 1].rva, dest, ssize + exe_sections[i + 1].rva - newesi, dsize, sections, sectcnt, EC32(optional_hdr32.ImageBase), oldep, ndesc)),1,(src,dest,sections,0));
|
1476
|
1476
|
break; /* were done with 1.33 */
|
1477
|
1477
|
}
|
1478
|
1478
|
|
...
|
...
|
@@ -1593,8 +1596,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1593
|
1593
|
oldep = vep + gp + 6 + cli_readint32(src+gp+2+oldep);
|
1594
|
1594
|
cli_dbgmsg("FSG: found old EP @%x\n", oldep);
|
1595
|
1595
|
|
1596
|
|
- CLI_UNPTEMP("FSG",src,dest,sections,exe_sections);
|
1597
|
|
- CLI_UNPRESULTSFSG1("FSG",(unfsg_133(src + newesi - exe_sections[i + 1].rva, dest, ssize + exe_sections[i + 1].rva - newesi, dsize, sections, sectcnt, EC32(optional_hdr32.ImageBase), oldep, ndesc)),1,src,dest,sections);
|
|
1596
|
+ CLI_UNPTEMP("FSG",(src,dest,sections,exe_sections,0));
|
|
1597
|
+ CLI_UNPRESULTSFSG1("FSG",(unfsg_133(src + newesi - exe_sections[i + 1].rva, dest, ssize + exe_sections[i + 1].rva - newesi, dsize, sections, sectcnt, EC32(optional_hdr32.ImageBase), oldep, ndesc)),1,(src,dest,sections,0));
|
1598
|
1598
|
break; /* were done with 1.31 */
|
1599
|
1599
|
}
|
1600
|
1600
|
|
...
|
...
|
@@ -1706,7 +1709,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1706
|
1706
|
free(src);
|
1707
|
1707
|
free(exe_sections);
|
1708
|
1708
|
|
1709
|
|
- CLI_UNPTEMP("UPX/FSG",dest);
|
|
1709
|
+ CLI_UNPTEMP("UPX/FSG",(dest,0));
|
1710
|
1710
|
|
1711
|
1711
|
if((unsigned int) write(ndesc, dest, dsize) != dsize) {
|
1712
|
1712
|
cli_dbgmsg("UPX/FSG: Can't write %d bytes\n", dsize);
|
...
|
...
|
@@ -1780,8 +1783,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1780
|
1780
|
}
|
1781
|
1781
|
}
|
1782
|
1782
|
|
1783
|
|
- CLI_UNPTEMP("Petite",dest,exe_sections);
|
1784
|
|
- CLI_UNPRESULTS("Petite",(petite_inflate2x_1to9(dest, min, max - min, exe_sections, nsections - (found == 1 ? 1 : 0), EC32(optional_hdr32.ImageBase),vep, ndesc, found, EC32(optional_hdr32.DataDirectory[2].VirtualAddress),EC32(optional_hdr32.DataDirectory[2].Size))),0,dest);
|
|
1783
|
+ CLI_UNPTEMP("Petite",(dest,exe_sections,0));
|
|
1784
|
+ CLI_UNPRESULTS("Petite",(petite_inflate2x_1to9(dest, min, max - min, exe_sections, nsections - (found == 1 ? 1 : 0), EC32(optional_hdr32.ImageBase),vep, ndesc, found, EC32(optional_hdr32.DataDirectory[2].VirtualAddress),EC32(optional_hdr32.DataDirectory[2].Size))),0,(dest,0));
|
1785
|
1785
|
}
|
1786
|
1786
|
}
|
1787
|
1787
|
|
...
|
...
|
@@ -1809,8 +1812,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1809
|
1809
|
return CL_EIO;
|
1810
|
1810
|
}
|
1811
|
1811
|
|
1812
|
|
- CLI_UNPTEMP("PESpin",spinned,exe_sections);
|
1813
|
|
- CLI_UNPRESULTS_("PEspin",SPINCASE(),(unspin(spinned, fsize, exe_sections, nsections - 1, vep, ndesc, ctx)),0,spinned);
|
|
1812
|
+ CLI_UNPTEMP("PESpin",(spinned,exe_sections,0));
|
|
1813
|
+ CLI_UNPRESULTS_("PEspin",SPINCASE(),(unspin(spinned, fsize, exe_sections, nsections - 1, vep, ndesc, ctx)),0,(spinned,0));
|
1814
|
1814
|
}
|
1815
|
1815
|
|
1816
|
1816
|
|
...
|
...
|
@@ -1835,8 +1838,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1835
|
1835
|
return CL_EIO;
|
1836
|
1836
|
}
|
1837
|
1837
|
|
1838
|
|
- CLI_UNPTEMP("yC",spinned,exe_sections);
|
1839
|
|
- CLI_UNPRESULTS("yC",(yc_decrypt(spinned, fsize, exe_sections, nsections-1, e_lfanew, ndesc)),0,spinned);
|
|
1838
|
+ CLI_UNPTEMP("yC",(spinned,exe_sections,0));
|
|
1839
|
+ CLI_UNPRESULTS("yC",(yc_decrypt(spinned, fsize, exe_sections, nsections-1, e_lfanew, ndesc)),0,(spinned,0));
|
1840
|
1840
|
}
|
1841
|
1841
|
|
1842
|
1842
|
|
...
|
...
|
@@ -1901,7 +1904,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1901
|
1901
|
|
1902
|
1902
|
free(wwp);
|
1903
|
1903
|
|
1904
|
|
- CLI_UNPTEMP("WWPack",dest,exe_sections);
|
|
1904
|
+ CLI_UNPTEMP("WWPack",(dest,exe_sections,0));
|
1905
|
1905
|
|
1906
|
1906
|
if((unsigned int) write(ndesc, dest, dsize) != dsize) {
|
1907
|
1907
|
cli_dbgmsg("WWPack: Can't write %d bytes\n", dsize);
|
...
|
...
|
@@ -1970,8 +1973,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
1970
|
1970
|
break;
|
1971
|
1971
|
}
|
1972
|
1972
|
|
1973
|
|
- CLI_UNPTEMP("Aspack",src,exe_sections);
|
1974
|
|
- CLI_UNPRESULTS("Aspack",(unaspack212((uint8_t *)src, ssize, exe_sections, nsections, vep-1, EC32(optional_hdr32.ImageBase), ndesc)),1,src);
|
|
1973
|
+ CLI_UNPTEMP("Aspack",(src,exe_sections,0));
|
|
1974
|
+ CLI_UNPRESULTS("Aspack",(unaspack212((uint8_t *)src, ssize, exe_sections, nsections, vep-1, EC32(optional_hdr32.ImageBase), ndesc)),1,(src,0));
|
1975
|
1975
|
break;
|
1976
|
1976
|
}
|
1977
|
1977
|
|
...
|
...
|
@@ -2044,8 +2047,8 @@ int cli_scanpe(int desc, cli_ctx *ctx)
|
2044
|
2044
|
eprva=eprva+5+cli_readint32(nbuff+1);
|
2045
|
2045
|
cli_dbgmsg("NsPack: OEP = %08x\n", eprva);
|
2046
|
2046
|
|
2047
|
|
- CLI_UNPTEMP("NsPack",src,dest,exe_sections);
|
2048
|
|
- CLI_UNPRESULTS("NsPack",(unspack(src, dest, ctx, exe_sections[0].rva, EC32(optional_hdr32.ImageBase), eprva, ndesc)),0,src,dest);
|
|
2047
|
+ CLI_UNPTEMP("NsPack",(src,dest,exe_sections,0));
|
|
2048
|
+ CLI_UNPRESULTS("NsPack",(unspack(src, dest, ctx, exe_sections[0].rva, EC32(optional_hdr32.ImageBase), eprva, ndesc)),0,(src,dest,0));
|
2049
|
2049
|
break;
|
2050
|
2050
|
}
|
2051
|
2051
|
|