Skip to content

Commit 773e087

Browse files
sovissaes3n1n
andauthored
add seed as optional argument (#31)
* add seed as optional argument * add seed as optional argument * build(deps): bump es3n1n/common * style: reformat entry.cpp/config_parser.cpp --------- Co-authored-by: es3n1n <me@es3n.in>
1 parent 767194b commit 773e087

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ Available options:
1919
-t [name] -- Start new transform configuration
2020
-g [name] -- Start new transform global configuration
2121
-v [name] [value] -- Push value
22+
-seed [value] -- Set random seed
2223
2324
Examples:
2425
obfuscator hehe.exe -f main -t TransformName -v SomeName 1337
2526
obfuscator hehe.exe -f main -t TransformName -v SomeName 1337 -g TransformName -v SomeGlobalName 1337
2627
obfuscator hehe.exe -f main -t TransformName -v SomeName 1337 -v SomeName0 1337 -g TransformName -v SomeGlobalName 1337
2728
obfuscator hehe.exe -map mymap.map -pdb mypdb.pdb -f main -t TransformName -v SomeName 1337 -v SomeName0 1337 -g TransformName -v SomeGlobalName 1337
29+
obfuscator hehe.exe -map mymap.map -pdb mypdb.pdb -f main -seed 0xcb91ccbef7cbcdc1
2830
```
2931

3032
In case of unexpected exit without any error message or in case you feel lucky, try adjusting the chances. E.g.:

src/bin/entry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace {
1919
}
2020

2121
int startup(config_parser::Config& config) try {
22-
const auto binary_path = config.obfuscator_config().binary_path;
22+
rnd::detail::seed(config.obfuscator_config().seed);
23+
const auto& binary_path = config.obfuscator_config().binary_path;
2324

2425
logger::info("main: loading binary from {}", binary_path.string());
2526
auto file = files::read_file(binary_path);
@@ -48,7 +49,6 @@ namespace {
4849
} // namespace
4950

5051
int main(const int argc, const char* argv[]) try {
51-
rnd::detail::seed();
5252
obfuscator::startup_scheduler();
5353

5454
auto config = config_parser::from_argv(argc, argv);

src/lib/config_parser/config_parser.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace config_parser {
1717

1818
/// Allocate result
1919
Config result = {};
20-
auto& [binary_path_value] = result.obfuscator_config();
20+
auto& [binary_path_value, seed] = result.obfuscator_config();
2121
auto& func_parser_config = result.func_parser_config();
2222

2323
/// Get some stuff for transforms resolving
@@ -113,6 +113,26 @@ namespace config_parser {
113113
state.current_transform->values[next_arg_.value()] = next_next_arg_.value();
114114
skip(2);
115115
}
116+
117+
if (arg_ == "-seed" && next_arg_.has_value()) {
118+
/// \todo @sovissa:
119+
/// [1] add correct processing of literals to string_parser
120+
/// [2] add support for negative values to arg parser
121+
std::size_t seed_value_base = 10;
122+
123+
std::string_view next_arg_view{next_arg_.value()};
124+
if (next_arg_view.starts_with('-')) {
125+
next_arg_view = next_arg_view.substr(1);
126+
}
127+
if (next_arg_view.length() >= 2 && //
128+
(next_arg_view.starts_with("0x") || next_arg_view.starts_with("0X"))) {
129+
seed_value_base = 16;
130+
}
131+
132+
seed = string_parser::parse_uint64(next_arg_.value(), seed_value_base);
133+
skip(1);
134+
continue;
135+
}
116136
}
117137

118138
return result;

src/lib/config_parser/structs.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace config_parser {
1717

1818
struct obfuscator_config_t {
1919
std::filesystem::path binary_path = "";
20+
std::optional<std::uint64_t> seed = std::nullopt;
2021
};
2122

2223
struct func_parser_config_t {

0 commit comments

Comments
 (0)