Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- AS 4.0 - digital signature check with colorize
- version 1.0.2 - Oct 11, 2023
- */
- //var_dump($argv);
- $f = "";
- if( count($argv) >= 2 ) {
- $par = "file="; $p = strpos($argv[1], $par); if( $p !== false ) { $f = substr($argv[1], strlen($par)); }
- }
- //echo $f . PHP_EOL;
- function formatPrint(array $format=[],string $text = '') {
- //color codes: https://misc.flogisoft.com/bash/tip_colors_and_formatting
- $codes=[
- 'bold'=>1,'italic'=>3, 'underline'=>4, 'strikethrough'=>9,
- 'black'=>30, 'red'=>31, 'green'=>32, 'yellow'=>33,'blue'=>34, 'magenta'=>35, 'cyan'=>36, 'white'=>37,
- 'blackbg'=>40, 'redbg'=>41, 'greenbg'=>42, 'lyellowbg'=>103,'bluebg'=>44, 'magentabg'=>45, 'cyanbg'=>46, 'lightgreybg'=>47
- ];
- $formatMap = array_map(function ($v) use ($codes) { return $codes[$v]; }, $format);
- return "\e[".implode(';',$formatMap).'m'.$text."\e[0m";
- }
- function formatPrintLn(array $format=[], string $text='') {
- return formatPrint($format, $text) . "\r\n";
- }
- /*
- //Examples:
- formatPrintLn(['bold', 'white', 'greenbg'], " Wohoo ");
- formatPrintLn(['bold', 'white', 'redbg'], " I'm invicible ");
- */
- if( $f != "" && file_exists($f) ) {
- //https://www.geeksforgeeks.org/php-shell_exec-vs-exec-function/
- $promt = shell_exec('"C:\Program Files (x86)\SysinternalsSuite\sigcheck64.exe" "'.$f.'"');
- //echo $promt;
- //echo strlen($promt);
- //file_put_contents("cmd-" . date("Y-m-d H-i-s") . ".log.txt", $promt);
- $signed = "Signed";
- $unsigned = "Unsigned";
- $verified = "Verified:";
- $bad1 = "The digital signature of the object did not verify.";
- $bad2 = "A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.";
- $bad3 = "A certificate chain could not be built to a trusted root authority.";
- $lines = explode("\n", $promt);
- array_splice($lines, 2, 2); // remove Sigcheck credential details, 2 lines
- $lines = array_values( $lines );
- /*
- //echo count($lines);
- $linesToString = implode("\n", $lines);
- file_put_contents("cmd-" . date("Y-m-d H-i-s") . ".log.txt", $linesToString);
- exit;
- */
- for($r = 0; $r < count($lines); $r++) {
- $out = "";
- $l = $lines[$r];
- if (($p = strpos($l, $signed)) !== false) {
- $out .= substr($l, 0, $p) . formatPrint(['bold', 'white', 'greenbg'], $signed) . substr($l, $p + strlen($signed));
- } elseif (($p = strpos($l, $unsigned)) !== false) {
- $out .= substr($l, 0, $p) . formatPrint(['bold', 'white', 'redbg'], $unsigned) . substr($l, $p + strlen($unsigned));
- } elseif (($p = strpos($l, $verified)) !== false) {
- $p += strlen($verified);
- $out .= substr($l, 0, $p);
- $part2 = substr($l, $p);
- $n = 0;
- for ($i = 0; $i < strlen($part2); $i++) {
- if ($part2[$i] != "\t") {
- $n = $i;
- break;
- }
- $out .= $part2[$i]; //tab(s)
- }
- $part2 = substr($part2, $n);
- //echo strlen($part2)." ".$part2;
- //echo strlen($bad1)." ".$bad1;
- if($part2 == $bad1) {
- $out .= formatPrint(['bold', 'white', 'redbg'], $part2); //The digital signature...did not verify
- }
- else
- if($part2 == $bad2) {
- $out .= formatPrint(['bold', 'white', 'magentabg'], $part2); //A certificate chain terminated in...not trusted provider
- }
- else
- if($part2 == $bad3) {
- $out .= formatPrint(['bold', 'cyan', 'magentabg'], $part2); //A certificate could not be built to...trusted authority
- }
- else
- $out .= formatPrint(['magenta', 'lyellowbg'], $part2); //another
- }
- if( $out != "" && $out != $l )
- $lines[$r] = $out;
- }
- $linesToString = implode("\n", $lines);
- //file_put_contents("cmd-" . date("Y-m-d H-i-s") . ".log.txt", $linesToString);
- echo $linesToString;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement