1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) DIGITEO - 2010-2011 - Allan CORNET
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
13 //=============================================================================
14 function dllinfolist = dlwDllInfo(dllname, options)
15 //=============================================================================
16 function symbolslist = dllinfoimports(dllname)
18 [result,bOK] = dos("dumpbin /IMPORTS """ + dllname +"""");
21 result = stripblanks(result);
23 result(result == "") = [];
24 result(grep(result, "Import Address")) = [];
25 result(grep(result, "Import Name")) = [];
26 result(grep(result, "Index of first")) = [];
27 result(grep(result, "time date stamp")) = [];
28 dllext = grep(result, getdynlibext());
29 result(1:dllext(1) - 1) = [];
30 data_index = grep(result, ".data");
31 result(data_index(1) - 1 : $) = [];
32 indicedotdll = grep(result, getdynlibext())
33 if (indicedotdll <> []) then
34 dlllist = result(indicedotdll);
35 for i = 1:size(dlllist, "*")
37 if (i == size(dlllist,"*")) then
38 symbolsdllstr = result(indicedotdll(i) + 1:$);
40 symbolsdllstr = result(indicedotdll(i) + 1:indicedotdll(i + 1) - 1);
42 for j = 1: size(symbolsdllstr, "*")
43 tok = tokens(symbolsdllstr(j), " ");
44 if size(tok, "*") >= 2 then
45 symbolsdll(j) = tok(2);
48 symbolslist(i)= list(dlllist(i), symbolsdll);
53 //=============================================================================
54 function symbolslist = dllinfoexports(dllname)
57 [result, bOK] = dos("dumpbin /EXPORTS """ + dllname +"""");
59 result(result == "") = [];
60 ilastcomment = grep(result, "ordinal hint RVA");
61 if ilastcomment <> [] then
62 result(1:ilastcomment) = [];
63 data_index = grep(result, ".data");
64 result(data_index(1) - 1 : $) = [];
65 for i = 1:size(result, "*")
66 tok = tokens(result(i), " ");
67 if size(tok,"*") >=4 then
68 symbolsdll = [symbolsdll; tok(4)];
71 [pat, nam, ext] = fileparts(dllname);
72 symbolslist = list(nam + ext, symbolsdll);
76 //=============================================================================
77 function dllinfolist = dllinfomachine(dllname)
80 [result,bOK] = dos("dumpbin /HEADERS """ + dllname +"""");
82 iMachine = grep(result, "machine (");
83 if iMachine <> [] then
84 infomachinestr = result(iMachine(1));
85 tok = tokens(infomachinestr, " ");
86 if size(tok, "*") == 3 then
87 machine = strsubst(tok(3), ")", "");
88 machine = strsubst(machine, "(", "");
90 [pat, nam, ext] = fileparts(dllname);
91 dllinfolist = list(nam + ext, machine);
95 //=============================================================================
103 if type(dllname) <> 10 | size(dllname) <> 1 then
104 error(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"), "dllinfo", 1));
107 if fileinfo(dllname) == [] then
108 error(msprintf(gettext("%s: The file %s does not exist.\n"), "dllinfo", dllname));
111 fext = fileext(dllname);
112 if ~(strcmp(fext, ".exe", "i") == 0 | strcmp(fext, ".dll", "i")== 0) then
113 error(msprintf(gettext("%s: Cannot open file %s.\n"), "dllinfo", dllname));
116 if type(options) <> 10 | size(options) <> 1 then
117 error(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"), "dllinfo", 2));
120 if ~(strcmp(options, "imports", "i")== 0 | strcmp(options, "exports", "i")== 0 | strcmp(options, "machine", "i")== 0) then
121 error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), "dllinfo", 2, "''imports'', ''exports'', ''machine''"));
124 dllinfolist = list();
126 if findmsvccompiler() <> "unknown" then
127 if strcmp(options, "imports", "i")== 0 then
128 dllinfolist = dllinfoimports(dllname);
131 if strcmp(options, "exports", "i")== 0 then
132 dllinfolist = dllinfoexports(dllname);
135 if strcmp(options, "machine", "i")== 0 then
136 dllinfolist = dllinfomachine(dllname);
140 warning(msprintf(gettext("%s: This feature required Microsoft visual studio C compiler.\n"), "dllinfo"));
144 //=============================================================================