Skip to content

Commit

Permalink
[REFACT] Moved params info to separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Nov 5, 2018
1 parent a08689f commit c78463c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 44 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ set (utils_hdrs

set (srcs
pe_sieve.cpp
pe_sieve_params_info.cpp
report_formatter.cpp
results_dumper.cpp
pe_reconstructor.cpp
Expand All @@ -77,6 +78,7 @@ set (srcs

set (hdrs
pe_sieve.h
pe_sieve_params_info.h
report_formatter.h
results_dumper.h
pe_reconstructor.h
Expand Down
46 changes: 2 additions & 44 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "utils/process_privilege.h"

#include "utils/util.h"
#include "pe_sieve_params_info.h"

#include "peconv.h"
#include "pe_sieve.h"
Expand Down Expand Up @@ -39,49 +40,6 @@ void print_in_color(int color, std::string text)
SetConsoleTextAttribute(hConsole, 7); // back to default color
}

std::string translate_dump_mode(const peconv::t_pe_dump_mode dump_mode)
{
switch (dump_mode) {
case peconv::PE_DUMP_AUTO:
return "autodetect (default)";
case peconv::PE_DUMP_VIRTUAL:
return "virtual (as it is in the memory, no unmapping)";
case peconv::PE_DUMP_UNMAP:
return "unmapped (converted to raw using sections' raw headers)";
case peconv::PE_DUMP_REALIGN:
return "realigned raw (converted raw format to be the same as virtual)";
}
return "undefined";
}

std::string translate_out_filter(const t_output_filter o_filter)
{
switch (o_filter) {
case OUT_FULL:
return "no filter: dump everything (default)";
case OUT_NO_DUMPS:
return "don't dump the modified PEs, but save the report";
case OUT_NO_DIR:
return "don't dump any files";
}
return "undefined";
}

std::string translate_modules_filter(DWORD m_filter)
{
switch (m_filter) {
case LIST_MODULES_DEFAULT:
return "no filter (as the scanner)";
case LIST_MODULES_32BIT:
return "32bit only";
case LIST_MODULES_64BIT:
return "64bit only";
case LIST_MODULES_ALL:
return "all accessible (default)";
}
return "undefined";
}

peconv::t_pe_dump_mode normalize_dump_mode(size_t mode_id)
{
if (mode_id > peconv::PE_DUMP_MODES_COUNT) {
Expand Down Expand Up @@ -259,7 +217,7 @@ int main(int argc, char *argv[])
std::cout << "PID: " << args.pid << std::endl;
std::cout << "Modules filter: " << translate_modules_filter(args.modules_filter) << std::endl;
std::cout << "Output filter: " << translate_out_filter(args.out_filter) << std::endl;
std::cout << "Dump mode: " << translate_dump_mode(peconv::t_pe_dump_mode(args.dump_mode)) << std::endl;
std::cout << "Dump mode: " << translate_dump_mode(args.dump_mode) << std::endl;
}
ProcessScanReport* report = scan_process(args);
if (report != nullptr) {
Expand Down
48 changes: 48 additions & 0 deletions pe_sieve_params_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "pe_sieve_params_info.h"

#include <peconv.h>
#include <Windows.h>
#include <Psapi.h>

std::string translate_dump_mode(const DWORD dump_mode)
{
switch (dump_mode) {
case peconv::PE_DUMP_AUTO:
return "autodetect (default)";
case peconv::PE_DUMP_VIRTUAL:
return "virtual (as it is in the memory, no unmapping)";
case peconv::PE_DUMP_UNMAP:
return "unmapped (converted to raw using sections' raw headers)";
case peconv::PE_DUMP_REALIGN:
return "realigned raw (converted raw format to be the same as virtual)";
}
return "undefined";
}

std::string translate_out_filter(const t_output_filter o_filter)
{
switch (o_filter) {
case OUT_FULL:
return "no filter: dump everything (default)";
case OUT_NO_DUMPS:
return "don't dump the modified PEs, but save the report";
case OUT_NO_DIR:
return "don't dump any files";
}
return "undefined";
}

std::string translate_modules_filter(DWORD m_filter)
{
switch (m_filter) {
case LIST_MODULES_DEFAULT:
return "no filter (as the scanner)";
case LIST_MODULES_32BIT:
return "32bit only";
case LIST_MODULES_64BIT:
return "64bit only";
case LIST_MODULES_ALL:
return "all accessible (default)";
}
return "undefined";
}
8 changes: 8 additions & 0 deletions pe_sieve_params_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <iostream>
#include "pe_sieve.h"

std::string translate_dump_mode(const DWORD dump_mode);
std::string translate_out_filter(const t_output_filter o_filter);
std::string translate_modules_filter(DWORD m_filter);

0 comments on commit c78463c

Please sign in to comment.