Davidyese Posted March 25 Posted March 25 I'm requesting an Autoit code to check if file has true digital sinature or fale without using 3rd part tools like : sigtool.exe for example either using Autoit or cmd or powershell through Autoit to achieve this goal with very fast result to show True or False of digital signature i saw this Code but it doesn't tell anything about true or false the dogital sinature https://www.autoitscript.com/forum/topic/124467-verifying-signed-files/#findComment-866254 if anyone tell me how to use this code to tell : true or False for the digital sign of file Thanks in advance
Solution Davidyese Posted April 8 Author Solution Posted April 8 The Code for Information of the digital Certificate expandcollapse popup$sFile = @AutoItExe _PrintSignerInfo($sFile) Func _PrintSignerInfo($sFile) If Not FileExists($sFile) Then Return SetError(1) Local Const $CERT_QUERY_OBJECT_FILE = 0x1 Local Const $CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED = 10 Local Const $CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED = 2 ^ $CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED Local Const $CERT_QUERY_FORMAT_BINARY = 0x1 Local Const $CERT_QUERY_FORMAT_FLAG_BINARY = 2 ^ $CERT_QUERY_FORMAT_BINARY Local Const $CMSG_SIGNER_INFO_PARAM = 0x6 Local Const $X509_ASN_ENCODING = 0x00000001 Local Const $PKCS_7_ASN_ENCODING = 0x00010000 Local Const $CERT_FIND_SUBJECT_CERT = 720896 Local $aCall = DllCall("Crypt32.dll", "bool", "CryptQueryObject", _ "dword", $CERT_QUERY_OBJECT_FILE, _ "wstr", $sFile, _ "dword", $CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, _ "dword", $CERT_QUERY_FORMAT_FLAG_BINARY, _ "dword", 0, _ "dword*", 0, _ "dword*", 0, _ "dword*", 0, _ "handle*", 0, _ "handle*", 0, _ "ptr", 0) Local $iMsgAndCertEncodingType = $aCall[6] Local $iContentType = $aCall[7] Local $iFormatType = $aCall[8] Local $hCertStore = $aCall[9] Local $hMsg = $aCall[10] ConsoleWrite("MsgAndCertEncodingType = " & $iMsgAndCertEncodingType & @CRLF) ConsoleWrite("ContentType = " & $iContentType & @CRLF) ConsoleWrite("FormatType = " & $iFormatType & @CRLF) ConsoleWrite("CertStore = " & $hCertStore & @CRLF) ConsoleWrite("Msg = " & $hMsg & @CRLF & @CRLF) ; Simple check If Not $hMsg Then Return $aCall = DllCall("Crypt32.dll", "bool", "CryptMsgGetParam", _ "handle", $hMsg, _ "dword", $CMSG_SIGNER_INFO_PARAM, _ "dword", 0, _ "ptr", 0, _ "dword*", 0) Local $iSize = $aCall[5] Local $tBuffer = DllStructCreate("byte[" & $iSize & "]") $aCall = DllCall("Crypt32.dll", "bool", "CryptMsgGetParam", _ "handle", $hMsg, _ "dword", $CMSG_SIGNER_INFO_PARAM, _ "dword", 0, _ "ptr", DllStructGetPtr($tBuffer), _ "dword*", DllStructGetSize($tBuffer)) ; Shorter CMSG_SIGNER_INFO structure (I want Issuer only) Local $tCMSG_SIGNER_INFO_MOD = DllStructCreate("dword Version;" & _ "dword_ptr IssuerSize;" & _ "ptr Issuer;", _ DllStructGetPtr($tBuffer)) $aCall = DllCall("Crypt32.dll", "dword", "CertNameToStrW", _ "dword", 1, _ ; X509_ASN_ENCODING "ptr", DllStructGetPtr($tCMSG_SIGNER_INFO_MOD, "IssuerSize"), _ "dword", 0x08000003, _ ; CERT_X500_NAME_STR|CERT_NAME_STR_CRLF_FLAG "wstr", "", _ "dword", 65536) ConsoleWrite($aCall[4] & @CRLF) EndFunc Danyfirex and mLipok 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now