@@ -587,7 +587,7 @@ void Rule::process(std::string& plaintext) {
587587 return rule_processor (plaintext);
588588}
589589
590- std::string Rule::print (int output_channel) { // 0 = stdout, 1 = error, 2 = return
590+ std::string Rule::print (int output_channel, bool hashcat_output ) { // 0 = stdout, 1 = error, 2 = return
591591 std::string rule_1_copy = rule_value_1;
592592 std::string rule_2_copy = rule_value_2;
593593 std::string debug_string;
@@ -601,60 +601,103 @@ std::string Rule::print(int output_channel) { // 0 = stdout, 1 = error, 2 = ret
601601 if (start_pos != std::string::npos) {
602602 rule_2_copy.replace (start_pos, 1 , " \\ x09" );
603603 }
604- // start_pos = rule_1_copy.find(' ');
605- // if(start_pos != std::string::npos) {
606- // rule_1_copy.replace(start_pos, 1, "\\x20");
607- // }
608- // start_pos = rule_2_copy.find(' ');
609- // if(start_pos != std::string::npos) {
610- // rule_2_copy.replace(start_pos, 1, "\\x20");
611- // }
612-
613- if (Rule::rule_identify (rule) == 3 ) {
614- if (rule_value_1.size () > 1 ) { // intentionally take rule_value_1 to not take escapes into account.
615- start_pos = rule_1_copy.find (' /' );
616- if (start_pos != std::string::npos) {
617- rule_1_copy.replace (start_pos, 1 , " \\ /" );
618- }
619604
620- start_pos = rule_2_copy.find (' /' );
621- if (start_pos != std::string::npos) {
622- rule_2_copy.replace (start_pos, 1 , " \\ /" );
623- }
605+ if (hashcat_output) {
606+ start_pos = rule_1_copy.find (' ' );
607+ if (start_pos != std::string::npos) {
608+ rule_1_copy.replace (start_pos, 1 , " \\ x20" );
609+ }
610+ start_pos = rule_2_copy.find (' ' );
611+ if (start_pos != std::string::npos) {
612+ rule_2_copy.replace (start_pos, 1 , " \\ x20" );
613+ }
614+ }
624615
616+ switch (Rule::rule_identify (rule)) {
617+ case 1 :
625618 if (output_channel == 0 ) {
626- std::cerr << rule << ' / ' << rule_1_copy << ' / ' << rule_2_copy ;
619+ std::cout << rule;
627620 } else if (output_channel == 1 ) {
628- std::cout << rule << ' / ' << rule_1_copy << ' / ' << rule_2_copy ;
621+ std::cerr << rule;
629622 } else if (output_channel == 2 ) {
630623 debug_string += rule;
631- debug_string += ' /' ;
632- debug_string += rule_1_copy;
633- debug_string += ' /' ;
634- debug_string += rule_2_copy;
635624 }
636-
637- } else {
625+ break ;
626+ case 2 :
638627 if (output_channel == 0 ) {
639- std::cerr << rule << ' / ' << rule_1_copy << ' / ' << rule_2_copy ;
628+ std::cout << rule << rule_1_copy;
640629 } else if (output_channel == 1 ) {
641- std::cout << rule << ' / ' << rule_1_copy << ' / ' << rule_2_copy ;
630+ std::cerr << rule << rule_1_copy;
642631 } else if (output_channel == 2 ) {
643632 debug_string += rule;
644633 debug_string += rule_1_copy;
645- debug_string += rule_2_copy;
646634 }
647- }
648- } else {
649- if (output_channel == 0 ) {
650- std::cerr << rule << ' /' << rule_1_copy << ' /' << rule_2_copy;
651- } else if (output_channel == 1 ) {
652- std::cout << rule << ' /' << rule_1_copy << ' /' << rule_2_copy;
653- } else if (output_channel == 2 ) {
654- debug_string += rule;
655- debug_string += rule_1_copy;
656- debug_string += rule_2_copy;
657- }
635+ break ;
636+ case 3 :
637+ if (rule_value_1.size () > 1 ) { // if the first rule is multi-byte
638+ start_pos = rule_1_copy.find (' /' );
639+ if (start_pos != std::string::npos) {
640+ rule_1_copy.replace (start_pos, 1 , " \\ /" );
641+ }
642+
643+ start_pos = rule_2_copy.find (' /' );
644+ if (start_pos != std::string::npos) {
645+ rule_2_copy.replace (start_pos, 1 , " \\ /" );
646+ }
647+
648+ if (output_channel == 0 ) {
649+ std::cout << rule << ' /' << rule_1_copy << ' /' << rule_2_copy;
650+ } else if (output_channel == 1 ) {
651+ std::cerr << rule << ' /' << rule_1_copy << ' /' << rule_2_copy;
652+ } else if (output_channel == 2 ) {
653+ debug_string += rule;
654+ debug_string += ' /' ;
655+ debug_string += rule_1_copy;
656+ debug_string += ' /' ;
657+ debug_string += rule_2_copy;
658+ }
659+ } else if (rule_value_2.size () > 1 ) { // if the second rule is multi-byte
660+ start_pos = rule_1_copy.find (' /' );
661+ if (start_pos != std::string::npos) {
662+ rule_1_copy.replace (start_pos, 1 , " \\ /" );
663+ }
664+
665+ start_pos = rule_2_copy.find (' /' );
666+ if (start_pos != std::string::npos) {
667+ rule_2_copy.replace (start_pos, 1 , " \\ /" );
668+ }
669+
670+ if (output_channel == 0 ) {
671+ if (hashcat_output) {
672+ std::cout << rule << rule_1_copy << rule_2_copy;
673+ } else {
674+ std::cout << rule << ' /' << rule_1_copy << ' /' << rule_2_copy;
675+ }
676+ } else if (output_channel == 1 ) {
677+ if (hashcat_output) {
678+ std::cerr << rule << rule_1_copy << rule_2_copy;
679+ } else {
680+ std::cerr << rule << ' /' << rule_1_copy << ' /' << rule_2_copy;
681+ }
682+ } else if (output_channel == 2 ) {
683+ debug_string += rule;
684+ if (!hashcat_output) debug_string += ' /' ;
685+ debug_string += rule_1_copy;
686+ if (!hashcat_output) debug_string += ' /' ;
687+ debug_string += rule_2_copy;
688+ }
689+ } else { // rule 1 is not multi-byte
690+ if (output_channel == 0 ) {
691+ std::cout << rule << rule_1_copy << rule_2_copy;
692+ } else if (output_channel == 1 ) {
693+ std::cerr << rule << rule_1_copy << rule_2_copy;
694+ } else if (output_channel == 2 ) {
695+ debug_string += rule;
696+ debug_string += rule_1_copy;
697+ debug_string += rule_2_copy;
698+ }
699+ }
700+ break ;
658701 }
659702 return debug_string;
660703}
0 commit comments