Convert the contents of C:\WINDOWSSYSTEM32\cmc into a text file and open in Matlab
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all. How to Convert the contents of C:\WINDOWSSYSTEM32\cmc to a text file and open this text file in matlab?
1 comentario
Walter Roberson
el 11 de Sept. de 2023
Can you install Certificate Services? If so then see https://stackoverflow.com/questions/4648118/converting-a-binary-file-to-hex-representation-using-batch-file
Respuestas (2)
Steven Lord
el 11 de Sept. de 2023
I'm guessing your actual question is not about decompiling one of the executables included with Microsoft Windows into its source file or a text representation of the binary executable file. I suspect you want to run some code using the system function in MATLAB and work in MATLAB with whatever that code would print to the system command prompt. If that's the case, call the system function with two outputs and work with the contents of the second of those outputs.
As an example, call the system's date function and convert it into a datetime array. Compare with the output of the datetime function in MATLAB.
Note that this code is being run on a Linux machine, so I'm using the Linux date function. For Windows I believe you'd want to run 'date /T' to only display the current date setting and you'd need to change the value of the InputFormat input to the datetime call that creates dt2.
dt1 = datetime('now', 'TimeZone', 'UTC')
[status, output] = system('date')
output = replace(output, newline, '') % Remove the extra newline
dt2 = datetime(output, 'InputFormat', 'eee MMM dd HH:mm:ss z yyyy', 'TimeZone', 'UTC')
[dt1; dt2]
3 comentarios
Steven Lord
el 13 de Sept. de 2023
Are you running the Fortran 77 executable using the system command? If so call system with two outputs (as I did in the example above) and parse the second output (much like I did to convert it into a form the datetime function could handle.) Using an approximation to the data you showed:
t = char(' AA', ...
'1', ...
' BB', ...
'2', ...
'A', ...
' 0.50 0.50 0.50', ...
' 0.50 0.50 0.50', ...
' 0.50 0.50 0.50')
if I know the matrix starts on row 6 of the data:
data = str2num(t(6:end, :), Evaluation='restricted')
Using the Evaluation option requires release R2022a or later, so you may not be able to use it if you're using an older release, but it can be safer (avoiding some "Bobby Tables" scenarios.)
Walter Roberson
el 12 de Sept. de 2023
cmd.exe is the Windows command shell, which absolutely will not contain anything pertaining to the fortran program you are running.
You have a few different options:
- use MATLAB's system() to run the fortran executable and examine the second output. In practice you might need to set up some environment variables so that the executable can find its run-time libraries. Getting the environment variables right can be a bit of a nuisance but is not usually too hard
- use the .NET interface System.Diagnostic.Process in MATLAB to run the fortran executable. This is more flexible than using system -- for example you can ask to read one line of output at a time. You will probably still need to set up environment variables correctly so the executable can find its run-time libraries
- if the proper interface is constructed, then fortran functions can be called directly from MATLAB, including passing variables back and forth. This possibility takes the most set-up work, and would not typically be done for "small" programs -- more for "libraries"
2 comentarios
Walter Roberson
el 13 de Sept. de 2023
Movida: Walter Roberson
el 13 de Sept. de 2023
If you use system() then the second output will be a character vector with embedded newlines. You can use text processing to process the character vector.
You might want to use code similar to
%break at lines that start with an identifier
parts = regexp(OUTPUT, '^\s*(?=[A-Za-z]', 'split');
%remove leading and trailing space on every line
parts = regexprep(parts, {'^\s+', '\s+$'}, '', 'lineanchors');
%remove empty areas
parts(cellfun(@isempty, parts)) = [];
parts will now be a cell array of character vector. Each section of parts should now begin with an alphabetic character, and all leading and trailing spaces on lines will have been removed. Any line that contained only whitespace will have been removed.
To the level of validation and pre-processing done so far, there is no guarantee that each section of parts will have only a single variable on the first line (and nothing else), or that the lines after that will contain matrices of numbers.
You can pick out the first word by using cellfun to textscan with format '%s' and count 1. You can attempt to pick out the numeric parts by using cellfun to textscan with format '' and 'HeaderLines', 1 .
Walter Roberson
el 13 de Sept. de 2023
However, please read http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval for information about why we strongly recommend against creating variable names dynamically.
It would be better if you were to use dynamic field names in a struct.
Ver también
Categorías
Más información sobre Data Import and Export en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!