File tree 8 files changed +36
-255
lines changed
8 files changed +36
-255
lines changed Original file line number Diff line number Diff line change 1
1
[submodule "extern/zydis "]
2
2
path = extern/zydis
3
3
url = https://github.com/zyantific/zydis
4
+ [submodule "extern/pe-builder "]
5
+ path = extern/pe-builder
6
+ url = https://github.com/jonomango/pe-builder
Original file line number Diff line number Diff line change @@ -11,8 +11,6 @@ add_executable(chum
11
11
"source/symbol.h"
12
12
"source/disassembler.h"
13
13
"source/disassembler.cpp"
14
- "source/pe-builder.h"
15
- "source/pe-builder.cpp"
16
14
"source/util.h"
17
15
"source/util.cpp"
18
16
)
@@ -26,4 +24,5 @@ target_compile_features(chum PRIVATE
26
24
# dependencies
27
25
target_link_libraries (chum PRIVATE
28
26
Zydis
27
+ pe-builder
29
28
)
Original file line number Diff line number Diff line change 1
1
#include " binary.h"
2
- #include " pe-builder.h"
3
2
4
3
#include < cassert>
5
4
#include < algorithm>
6
5
#include < fstream>
7
6
8
7
#include < Windows.h>
9
8
#include < zycore/Format.h>
9
+ #include < pe-builder/pe-builder.h>
10
10
11
11
namespace chum {
12
12
@@ -221,7 +221,32 @@ void binary::print(bool const verbose) {
221
221
222
222
// Create a new PE file from this binary.
223
223
bool binary::create (char const * const path) const {
224
- return pe_builder (*this ).create (path);
224
+ pb::pe_builder pe;
225
+ pe.file_characteristics (IMAGE_FILE_DLL);
226
+
227
+ // We don't want to resize in the middle of adding sections.
228
+ if (pe.sections_until_resize () < 1 + data_blocks_.size ())
229
+ return false ;
230
+
231
+ // Create the .text section for holding code.
232
+ auto & text_sec = pe.section ()
233
+ .name (" .text" )
234
+ .characteristics (IMAGE_SCN_MEM_EXECUTE);
235
+ auto & text_sec_data = text_sec.data ();
236
+
237
+ // Write every instruction to the text section (first pass).
238
+ for (auto const & bb : basic_blocks_) {
239
+ for (auto const & instr : bb->instructions ) {
240
+ // This is ENTIRELY wrong, but its a good start...
241
+ text_sec_data.insert (end (text_sec_data),
242
+ instr.bytes , instr.bytes + instr.length );
243
+ }
244
+ }
245
+
246
+ // Set the entrypoint to the start of the text section.
247
+ pe.entrypoint (pe.virtual_address (text_sec));
248
+
249
+ return pe.write (path);
225
250
}
226
251
227
252
// Get the entrypoint of this binary, if it exists.
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ int main() {
62
62
63
63
bin->print (true );
64
64
65
- if (!bin->create (" C:\\ Users\\ realj\\ Desktop\\ chum-output.exe " )) {
65
+ if (!bin->create (" C:\\ Users\\ realj\\ Desktop\\ chum-output.dll " )) {
66
66
std::printf (" [!] Failed to create output binary.\n " );
67
67
return 0 ;
68
68
}
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2
2
option (ZYDIS_BUILD_EXAMPLES "" OFF )
3
3
option (ZYDIS_BUILD_TOOLS "" OFF )
4
4
add_subdirectory (zydis)
5
+
6
+ # pe-builder
7
+ add_subdirectory (pe-builder)
You can’t perform that action at this time.
0 commit comments