diff --git a/dumper/dumper.d b/dumper/dumper.d index d603e165..d19695e8 100644 --- a/dumper/dumper.d +++ b/dumper/dumper.d @@ -86,30 +86,13 @@ const(char)* opt_section_name; long opt_baseaddress; const(char)* opt_extractfile; -int selected_headers() { return opt_selected & Select.headers; } -int selected_sections() { return opt_selected & Select.sections; } -int selected_relocs() { return opt_selected & Select.relocs; } -int selected_exports() { return opt_selected & Select.exports; } -int selected_imports() { return opt_selected & Select.imports; } -int selected_rsrc() { return opt_selected & Select.rsrc; } -int selected_debug() { return opt_selected & Select.debug_; } -int selected_dirs() { return opt_selected & Select.dirs; } -int selected_loadcfg() { return opt_selected & Select.loadcfg; } - -int setting_blob() { return opt_settings & Setting.blob; } -int setting_hexdump() { return opt_settings & Setting.hexdump; } -int setting_extract() { return opt_settings & Setting.extract; } -int setting_extract_any() { return opt_settings & Setting.extractAny; } - -int setting_disasm() { return opt_settings & Setting.disasm; } -int setting_disasm_all() { return opt_settings & Setting.disasmAll; } -int setting_disasm_stats() { return opt_settings & Setting.disasmStats; } -int setting_disasm_any() { return opt_settings & Setting.disasmAny; } +int SELECTED(Select selection) { return opt_selected & selection; } +int SETTING(Setting setting) { return opt_settings & setting; } /// Dump given file to stdout. /// Returns: Error code if non-zero int dump(const(char)* path) { - if (setting_blob()) { + if (SETTING(Setting.blob)) { // NOTE: Program exits and memory is free'ds by OS size_t size = void; ubyte *buffer = readall(path, &size); @@ -134,7 +117,7 @@ int dump(const(char)* path) { // If anything was selected to dump specifically if (opt_selected) { // If not in any "extract" mode, print file info - if (setting_extract_any() == 0) { + if (SETTING(Setting.extractAny) == 0) { print_string("filename", path); print_u64("filesize", o.file_size); print_string("format", adbg_object_format_name(o)); @@ -360,10 +343,10 @@ void print_reloc16(uint index, ushort seg, ushort off) { } void print_data(const(char)* name, void *data, size_t size, ulong baseaddress = 0) { - if (setting_hexdump()) + if (SETTING(Setting.hexdump)) hexdump(name, data, size, baseaddress); - if (setting_extract()) + if (SETTING(Setting.extract)) rawdump(opt_extractfile, data, size, baseaddress); } @@ -461,7 +444,7 @@ int dump_disassemble(AdbgMachine machine, void* data, ulong size, ulong base_add adbg_dis_start(dis, data, cast(size_t)size, base_address); // stats mode - if (setting_disasm_stats()) { + if (SETTING(Setting.disasmStats)) { uint stat_avg; /// instruction average size uint stat_min = uint.max; /// smallest instruction size uint stat_max; /// longest instruction size diff --git a/dumper/format/ar.d b/dumper/format/ar.d index 0422fdbc..362f42b6 100644 --- a/dumper/format/ar.d +++ b/dumper/format/ar.d @@ -18,9 +18,9 @@ import common.utils : realstring; extern (C): int dump_archive(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_archive_firstheader(o); - if (selected_exports()) + if (SELECTED(Select.exports)) dump_archive_allheaders(o); return 0; } @@ -55,7 +55,7 @@ void dump_archive_firstheader(adbg_object_t *o) { } void dump_archive_memberdata(adbg_object_t *o, ar_member_header *member) { - if (setting_extract_any() == false) + if (SETTING(Setting.extractAny) == false) return; ar_member_data m = adbg_object_ar_data(o, member); diff --git a/dumper/format/coff.d b/dumper/format/coff.d index 64913284..9e7aac15 100644 --- a/dumper/format/coff.d +++ b/dumper/format/coff.d @@ -17,7 +17,7 @@ import dumper; import common.utils : realstring; int dump_coff(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_coff_hdr(o); return 0; diff --git a/dumper/format/dmp.d b/dumper/format/dmp.d index a3f8a8da..284705c6 100644 --- a/dumper/format/dmp.d +++ b/dumper/format/dmp.d @@ -15,7 +15,7 @@ import dumper; extern (C): int dump_dmp(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_dmp_header(o); return 0; diff --git a/dumper/format/elf.d b/dumper/format/elf.d index 64e2dce8..f3959fdc 100644 --- a/dumper/format/elf.d +++ b/dumper/format/elf.d @@ -17,18 +17,18 @@ import common.utils : realchar, hexstr; extern (C): int dump_elf(adbg_object_t *o) { - if (selected_headers()) { + if (SELECTED(Select.headers)) { dump_elf_ehdr(o); dump_elf_phdr(o); } - if (selected_sections()) + if (SELECTED(Select.sections)) dump_elf_sections(o); - if (selected_exports()) + if (SELECTED(Select.exports)) dump_elf_exports(o); - if (setting_disasm_any()) + if (SETTING(Setting.disasmAny)) dump_elf_disasm(o); return 0; @@ -439,7 +439,7 @@ void dump_elf_sections(adbg_object_t *o) { if (opt_section_name && strncmp(sname, opt_section_name, SNMLEN)) continue; - if (setting_extract_any()) { + if (SETTING(Setting.extractAny)) { void *data = o.buffer + shdr.sh_offset; print_data(opt_section_name, data, shdr.sh_size, shdr.sh_offset); return; @@ -481,7 +481,7 @@ void dump_elf_sections(adbg_object_t *o) { if (opt_section_name && strncmp(sname, opt_section_name, SNMLEN)) continue; - if (setting_extract_any()) { + if (SETTING(Setting.extractAny)) { void *data = o.buffer + shdr.sh_offset; print_data(opt_section_name, data, cast(uint)shdr.sh_size, shdr.sh_offset); return; @@ -615,7 +615,7 @@ void dump_elf_exports(adbg_object_t *o) { void dump_elf_disasm(adbg_object_t *o) { print_header("Disassembly"); - int all = setting_disasm_all(); /// dump all + int all = SETTING(Setting.disasmAll); /// dump all switch (o.i.elf32.ehdr.e_ident[ELF_EI_CLASS]) { case ELF_CLASS_32: diff --git a/dumper/format/lx.d b/dumper/format/lx.d index 4f8caa76..6e1ae684 100644 --- a/dumper/format/lx.d +++ b/dumper/format/lx.d @@ -14,7 +14,7 @@ import dumper; extern (C): int dump_lx(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_lx_hdr(o); return 0; } diff --git a/dumper/format/macho.d b/dumper/format/macho.d index bf523c8d..15a1146c 100644 --- a/dumper/format/macho.d +++ b/dumper/format/macho.d @@ -11,7 +11,7 @@ import adbg.object.format.macho; import dumper; int dump_macho(adbg_object_t *o) { - if (selected_headers) + if (SELECTED(Select.headers)) dump_macho_hdr(o); return 0; diff --git a/dumper/format/mdmp.d b/dumper/format/mdmp.d index 61f0e4ed..89d2c19e 100644 --- a/dumper/format/mdmp.d +++ b/dumper/format/mdmp.d @@ -15,10 +15,10 @@ import dumper; import common.utils : realstring; int dump_minidump(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_minidump_headers(o); - //if (selected_debug()) + //if (SELECTED(Select.debug_)) // dump_minidump_debug(o); return 0; diff --git a/dumper/format/mscoff.d b/dumper/format/mscoff.d index 924e8d11..2491c94b 100644 --- a/dumper/format/mscoff.d +++ b/dumper/format/mscoff.d @@ -14,7 +14,7 @@ import adbg.utils.uid; import dumper; int dump_mscoff(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_mscoff_hdr(o); return 0; diff --git a/dumper/format/mz.d b/dumper/format/mz.d index 0a52ea31..5b3fba91 100644 --- a/dumper/format/mz.d +++ b/dumper/format/mz.d @@ -19,15 +19,12 @@ extern (C): /// o = Object instance. /// Returns: Non-zero on error. int dump_mz(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_mz_hdr(o); - - if (selected_relocs()) + if (SELECTED(Select.relocs)) dump_mz_relocs(o); - - if (setting_disasm_any()) + if (SETTING(Setting.disasmAny)) dump_mz_disasm(o); - return 0; } diff --git a/dumper/format/ne.d b/dumper/format/ne.d index 280ee428..78465d93 100644 --- a/dumper/format/ne.d +++ b/dumper/format/ne.d @@ -14,7 +14,7 @@ import dumper; extern (C): int dump_ne(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_ne_hdr(o); return 0; } diff --git a/dumper/format/omf.d b/dumper/format/omf.d index 86876f92..016166a2 100644 --- a/dumper/format/omf.d +++ b/dumper/format/omf.d @@ -12,9 +12,9 @@ import dumper; extern (C): int dump_omf(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_omf_hdr(o); - if (selected_debug()) + if (SELECTED(Select.debug_)) dump_omf_debug(o); return 0; } diff --git a/dumper/format/pdb20.d b/dumper/format/pdb20.d index 16da4dc5..af0d1f70 100644 --- a/dumper/format/pdb20.d +++ b/dumper/format/pdb20.d @@ -14,7 +14,7 @@ import dumper; extern (C): int dump_pdb20(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_pdb20_header(o); return 0; diff --git a/dumper/format/pdb70.d b/dumper/format/pdb70.d index 2d438646..7df829b4 100644 --- a/dumper/format/pdb70.d +++ b/dumper/format/pdb70.d @@ -18,12 +18,10 @@ import dumper; extern (C): int dump_pdb70(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_pdb70_header(o); - - if (selected_debug()) + if (SELECTED(Select.debug_)) dump_pdb70_debug(o); - return 0; } diff --git a/dumper/format/pe.d b/dumper/format/pe.d index 447fcb18..9e99d962 100644 --- a/dumper/format/pe.d +++ b/dumper/format/pe.d @@ -23,24 +23,18 @@ extern (C): /// o = Object instance. /// Returns: Non-zero on error. int dump_pe(adbg_object_t *o) { - if (selected_headers()) + if (SELECTED(Select.headers)) dump_pe_hdr(o); - - if (selected_sections()) + if (SELECTED(Select.sections)) dump_pe_sections(o); - - if (selected_exports()) + if (SELECTED(Select.exports)) dump_pe_exports(o); - - if (selected_imports()) + if (SELECTED(Select.imports)) dump_pe_imports(o); - - if (selected_debug()) + if (SELECTED(Select.debug_)) dump_pe_debug(o); - - if (setting_disasm_any()) + if (SETTING(Setting.disasmAny)) dump_pe_disasm(o); - return 0; } @@ -48,7 +42,7 @@ private: // Returns true if the machine value is unknown void dump_pe_hdr(adbg_object_t *o) { - if (setting_extract_any()) { + if (SETTING(Setting.extractAny)) { print_data("Header", o.i.pe.header, PE_HEADER.sizeof, mz_hdr_ext.sizeof); return; } @@ -241,7 +235,7 @@ void dump_pe_sections(adbg_object_t *o) { if (opt_section_name && strncmp(Name.ptr, opt_section_name, Name.sizeof)) continue; - if (setting_extract_any()) { + if (SETTING(Setting.extractAny)) { void *data = o.buffer + PointerToRawData; print_data(opt_section_name, data, SizeOfRawData, PointerToRawData); } @@ -812,7 +806,7 @@ void dump_pe_debug(adbg_object_t *o) { void dump_pe_disasm(adbg_object_t *o) { print_header("Disassembly"); - int all = setting_disasm_all(); + int all = SETTING(Setting.disasmAll); PE_SECTION_ENTRY *section = void; size_t i; while ((section = adbg_object_pe_section(o, i++)) != null) with (section) {