Jump to content
faustf

read p7m file why fileread not work ?

Recommended Posts

hi guys  i try to read  a file .p7m  , if i open it with notepad or notepad++ , i can  see all xml inside, ofcurse the  cript-sign no , but   for me is important read xml part inside of them , but when i try to read whit fileopen etc..  returnme  a  0x30821D5F06092A864886F70D010702A0821D5030821D4C020101310F300D060960864801650304020105003082118606092A8648.......

some time know how resolve it ?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>

local $Path = @scriptdir &"\file.p7m"

Local $sLFattXmlP7m = _True_ReadFile($Path 0)

Func _True_ReadFile($sFilePath, $attribute)

    Local $hFileOpen = FileOpen($sFilePath, $attribute)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
        Return False
    EndIf
    Local $sFileRead = FileRead($hFileOpen)
    FileClose($hFileOpen)
    Return $sFileRead
EndFunc   ;==>_True_ReadFile

 

Share this post


Link to post
Share on other sites

Check what encoding Notepad++ is using and set the proper FileOpen mode parameter based on that.

Edit: Notepad++ literally has a button on the top menu that says "Encoding" click it  😐

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Share this post


Link to post
Share on other sites

how can Check what encoding Notepad++

?

2 minutes ago, Jos said:

What have you done to debug? 

i try to rename a p7m in xml , for look if have the same problem and yes i have and  start to googeling

Share this post


Link to post
Share on other sites
1 hour ago, faustf said:

how can Check what encoding Notepad++

In general, you can also determine the encoding of a file with :

#include <FileConstants.au3>

Global $g_sFullFilename
$g_sFullFilename = @ScriptDir & '\file.p7m'

ConsoleWrite('> ==> ' & $g_sFullFilename & @CRLF)
ConsoleWrite('< =====> ' & _GetEncoding($g_sFullFilename) & @CRLF)

Func _GetEncoding($sFilename)
    Local $iEncoding, $sReturnVal
    $iEncoding = FileGetEncoding($sFilename)
    Switch $iEncoding
        Case $FO_UTF16_LE
            $sReturnVal = 'UTF16 Little Endian'
        Case $FO_UTF16_BE
            $sReturnVal = 'UTF16 Big Endian'
        Case $FO_UTF8
            $sReturnVal = 'UTF8 (with BOM)'
        Case $FO_UTF8_NOBOM
            $sReturnVal = 'UTF8 (without BOM)'
        Case $FO_ANSI
            $sReturnVal = 'ANSI (containing char > 127 and < 255)'
        Case $FO_UTF16_LE_NOBOM
            $sReturnVal = 'UTF16 Little Endian (without BOM)'
        Case $FO_UTF16_BE_NOBOM
            $sReturnVal = 'UTF16 Big Endian (without BOM) '
        Case Else
            $sReturnVal = 'other ... '
    EndSwitch
    Return($sReturnVal)
EndFunc   ;==>_GetEncoding

but that probably won't help you in this case.


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

You should take a look in my cert util UDF 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2019-10-01

Share this post


Link to post
Share on other sites
13 hours ago, Musashi said:

#include <FileConstants.au3> Global $g_sFullFilename $g_sFullFilename = @ScriptDir & '\file.p7m' ConsoleWrite('> ==> ' & $g_sFullFilename & @CRLF) ConsoleWrite('< =====> ' & _GetEncoding($g_sFullFilename) & @CRLF) Func _GetEncoding($sFilename)     Local $iEncoding, $sReturnVal     $iEncoding = FileGetEncoding($sFilename)     Switch $iEncoding         Case $FO_UTF16_LE             $sReturnVal = 'UTF16 Little Endian'         Case $FO_UTF16_BE             $sReturnVal = 'UTF16 Big Endian'         Case $FO_UTF8             $sReturnVal = 'UTF8 (with BOM)'         Case $FO_UTF8_NOBOM             $sReturnVal = 'UTF8 (without BOM)'         Case $FO_ANSI             $sReturnVal = 'ANSI (containing char > 127 and < 255)'         Case $FO_UTF16_LE_NOBOM             $sReturnVal = 'UTF16 Little Endian (without BOM)'         Case $FO_UTF16_BE_NOBOM             $sReturnVal = 'UTF16 Big Endian (without BOM) '         Case Else             $sReturnVal = 'other ... '     EndSwitch     Return($sReturnVal) EndFunc   ;==>_GetEncoding

yea return me 

< =====> other ...
+>11:05:09 AutoIt3.exe ended.rc:0
+>11:05:09 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 3.914

Share this post


Link to post
Share on other sites
4 minutes ago, faustf said:

where i find your cert util UDF  ?

Support topic : https://www.autoitscript.com/forum/topic/184937-certutil-udf-support-topic/

Download : https://www.autoitscript.com/forum/files/file/421-certutil-udf/


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

another questions , i try to read a file with cmd  type , and  i can read like in notepad  i try to crete by autoit and run

Func _CMD_Type($path)
    Local $iPID =Run(@ComSpec & " /c " &'type '&$path, "",   @SW_HIDE ,$STDIN_CHILD + $STDOUT_CHILD)
    Sleep(1000)
    ;ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : StdoutRead($iPID) = ' & StdoutRead($iPID) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
;Sleep(1000)
    ;StdinWrite($iPID, "list disk" & @CRLF)
    ;StdinWrite($iPID, "Exit" & @CRLF)
    ProcessWaitClose($iPID)
    ;Sleep(1000)
    ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
    Local $sOutput = StdoutRead($iPID)
    ConsoleWrite($sOutput)



EndFunc

but return me  only top header criptograph , and body text readable not

why ?

 

Share this post


Link to post
Share on other sites
1 hour ago, faustf said:

why ?

Are we still talking about P7M files ?

In case yes, please read the text that @Nine has linked to : https://filext.com/file-extension/P7M

P7M files are encrypted and you need a suitable software to read them (and of course the password).


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

yea openssl i think i read a tute right now  i must try ,soon if  find a solution i post somthing  thankz again >D

 

Share this post


Link to post
Share on other sites

finally , after test many conbination uff.....   i find  a openssl key .

1. instal openssl in c:\openssl

2. enter in cmd  and go in bin of c:\openssll

3 run command for  extract content ..... this for xml   for italian Fattura Elettronica

openssl smime -verify -noverify -in file.xml.p7m -inform DER -out file.xml

this not  work for xml, but work  for pdf probably

openssl smime -in documento.pdf.p7m -inform PEM -verify -CAfile CA.pem -out documento.pdf

or

openssl smime -verify -noverify -in documento.pdf.p7m -inform DER -out documento.pdf

now  i try to automate by autoit ..... saty tuned  :D

thankz at all for support

Share this post


Link to post
Share on other sites

little bit questions  i set openssl path in  ambient variable , if  i open cmd , in anyelse position and call openssl  work , but if i run it by autoit return me

'openssl' is not recognized as an internal or external command,
operable program or batch file.

how is possible ??

Func _OpenSSL_Conv($path)

    ; syntax for convert =>  "openssl smime -verify -noverify -in file.xml.p7m -inform DER -out file.xml "
    Local $sLPathXMLNew=StringTrimRight($path,"4")


    ConsoleWrite ('openssl smime -verify -noverify -in ' & $path & ' -inform DER -out '&$sLPathXMLNew &@CRLF)
    Local $iPID = Run(@ComSpec & " /c " & 'openssl smime -verify -noverify -in ' & $path & ' -inform DER -out '&$sLPathXMLNew, "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
    ;Sleep(1000)
    ;ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : StdoutRead($iPID) = ' & StdoutRead($iPID) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    ;Sleep(1000)
    ;StdinWrite($iPID, "list disk" & @CRLF)
    ;StdinWrite($iPID, "Exit" & @CRLF)
    ProcessWaitClose($iPID)
    ;Sleep(1000)
    ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.

    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : StdoutRead($iPID) = ' & StdoutRead($iPID) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

    ProcessWaitClose($iPID)
    Local $sOutput = StdoutRead($iPID)
    ConsoleWrite($sOutput)



EndFunc   ;==>_CMD_Type

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...