call a packer-plugin from the command line?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
wolf.b
Junior Member
Junior Member
Posts: 45
Joined: 2006-01-26, 05:38 UTC

call a packer-plugin from the command line?

Post by *wolf.b »

Dear all,
is there a way to call a packer-plugin from the command line?

I use the Microsoft Help compiler to create my own chm-file.
And, I have found I can reduce the file size afterwards with TC like this:
- open Total Commander (plugin CHMDir.wcx installed)
- left file panel: go to the sources folder for my chm-file (contains Style.css)
- right file panel: go to the target folder, where I have my new chm-file (already there)
- in the right panel: cursor on chm-file - then press Ctrl+PgDn to open like zip-file
- in the left panel: cursor on Style.css - then press F5, Enter, Enter
- wait for completion of the operation
- close Total Commander
- *pat myself on the back*

This whole procedure can be automated with AutoHotkey. I have already done that.
Pseudo code: AHK = [ Run new instance of TC, send keystrokes, wait, close TC ] :smile: :wink:
This works well within its limitations: AHK has to "remotely" open an application,
and I hope that nothing interferes while the script runs.
That's probably as good as it gets with this approach. Maybe? I don't know.

Now I wonder, is there a way (maybe using RunDLL32.exe?) to construct a command line that will do the same? something like:
RunDLL32.exe %TC_Dir%\Plugins\WCX\CHMDir\CHMDir.wcx,<entrypoint> <optional arguments>
RunDLL32.exe %TC_Dir%\Plugins\WCX\CHMDir\CHMDir.wcx,PackFiles <command> <switches> %CHM_file% Style.css

Thank you for reading this much too long post.
I appreciate any hints.
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Re: call a packer-plugin from the command line?

Post by *milo1012 »

wolf.b wrote:is there a way to call a packer-plugin from the command line
No, there isn't, unless some wrapper executable calls plugin functions (in a specific order!).
wolf.b wrote:maybe using RunDLL32.exe
No way, as many wcx plug-ins need a setup (PackSetDefaultParams)
and, even more important, specific memory structures are delivered with each function call,
in which most input/output parameters reside.
No way to simulate such thing via a rundll function directly,
not to mention that the plugin DLL needs to reside in memory for subsequent function calls.

You might want to take a look at:
http://www.ghisler.ch/board/viewtopic.php?t=43086
It *might* ease up the work for you, but it depends on the specific plug-in you want to use.
I tested it some time ago, and it was quite buggy.
TC plugins: PCREsearch and RegXtract
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Rundll32 can only be used for calling functions w/o arguments or with only single string argument, and WFX API functions are not the case.

There is a tool actually that does exactly what has been asked.
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Post by *milo1012 »

MVV wrote:There is a tool actually that does exactly what has been asked.
This tool is only for unpacking, as far as I can see it,
but it was asked to pack files via command line.
TC plugins: PCREsearch and RegXtract
wolf.b
Junior Member
Junior Member
Posts: 45
Joined: 2006-01-26, 05:38 UTC

Post by *wolf.b »

While I was looking for information on the web, I always thought I read in the past about a tool that "command-linerizes" any WCX packer plugin.
Thank you, MVV for the link. That settles my mind.

But, milo1012 is, of course, correct: I just checked the asm-file inside util_cmdTotal_2.02.rar which has some text at the start, and the tool goes the other way than I need here.

The plugin in question (CHMDir) even comes with "UnCHMw.exe", a standalone command line unpacker, which works very well, but there is no packer functionality.

Thank you milo1012 for your insights, I appreciate them very much. I was hoping, rather naively, that a single call would be possible, since I only need to "refresh" the archive.

I also looked at TC4Shell, which looks interesting, but I rather automate TC with AutoHotkey.
wolf.b
Junior Member
Junior Member
Posts: 45
Joined: 2006-01-26, 05:38 UTC

Re: call a packer-plugin from the command line?

Post by *wolf.b »

milo1012 wrote:[...] wcx plug-ins need a setup (PackSetDefaultParams)
and, even more important, specific memory structures are delivered with each function call,
in which most input/output parameters reside.
No way to simulate such thing via a rundll function directly,
not to mention that the plugin DLL needs to reside in memory for subsequent function calls.
I believe, AutoHotkey can do all of that.
Would you or anybody else know, where I can find the source code of CHMDir? Is it open source?
I know that forum user Flint has recompiled the sources for 64bit in march 2012, and said he will publish the modified sources later, but I cannot find them.
http://www.ghisler.ch/board/viewtopic.php?p=244090#244090
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Re: call a packer-plugin from the command line?

Post by *milo1012 »

wolf.b wrote:I believe, AutoHotkey can do all of that.
Well, you need to tell AutoHotkey in detail how to call PackFiles,
maybe
https://autohotkey.com/docs/commands/DllCall.htm
would actually work.
Still, you'd need to distinguish Unicode-only plugins (PackFilesW) from non-Unicode plugins.
AutoHotkey isn't really suited for all that.
And if a plugin really needs PackSetDefaultParams, you need to keep the DLL loaded in the memory of some process, before you can call PackFiles.
(I'm not sure if AutoHotkey could invoke some "dummy" process)

I think the easiest solution would be to write some similar tool as cmdTotal,
or even extent it to include pack support
(but I think the assembler source doesn't make it that easy to extent it (for most people)
- no idea why he didn't write some simple c program).
wolf.b wrote:where I can find the source code of CHMDir? Is it open source?
...
The official location
http://totalcmd.net/plugring/chmdir.html
doesn't list it as open source, so I guess it is not.

This post in the Russian TC forum links to the same package,
so I guess there really is no newer/different one.
You could ask Flint for the source via mail.
TC plugins: PCREsearch and RegXtract
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Since you really only need to call a single PackFiles function, it shouldn't be too hard from AHK. It accepts three null-terminated strings and stringlist (buffer with with null-terminated strings and another null character at the end), and also constant integer (0 in your case):

Code: Select all

int __stdcall PackFiles (char *PackedFile, char *SubPath, char *SrcPath, char *AddList, int Flags);
(additional details are here)

Though I think that packing should be added to cmdTotal tool.
wolf.b
Junior Member
Junior Member
Posts: 45
Joined: 2006-01-26, 05:38 UTC

Post by *wolf.b »

After a little work, and hints from milo1012 and MVV, I was able to write a AHK-script that calls CHMDir.wcx to refresh the archive, resulting in a smaller file size.
Thank you both very much again for your time and effort. I appreciate it. You guys rock!
MVV wrote:I think that packing should be added to cmdTotal tool.
That would be awesome, yes.
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Post by *milo1012 »

wolf.b wrote:I was able to write a AHK-script that calls CHMDir.wcx to refresh the archive
That's good to hear.

Any interest in sharing such script?
As for myself, I wouldn't touch DLLs with AHK,
but it still might be helpful for others.
wolf.b wrote:
MVV wrote:I think that packing should be added to cmdTotal tool.
That would be awesome, yes.
But only if it would respect the WCX interface we have since TC 5.51 (!),
and would call PackSetDefaultParams (no matter the operation at hand).
TC plugins: PCREsearch and RegXtract
wolf.b
Junior Member
Junior Member
Posts: 45
Joined: 2006-01-26, 05:38 UTC

Post by *wolf.b »

milo1012 wrote:Any interest in sharing such script?
No problem, here it is:

Edit: script in next post
Last edited by wolf.b on 2016-03-12, 09:52 UTC, edited 1 time in total.
wolf.b
Junior Member
Junior Member
Posts: 45
Joined: 2006-01-26, 05:38 UTC

Post by *wolf.b »

Code: Select all

#NoEnv ; don't check empty variables
If Not (A_PtrSize = 4) { ; need 32bit
    Run, "%A_AhkPath%\..\AutoHotkeyA32.exe" "%A_ScriptFullPath%"
    ExitApp
}

DllFile := "D:\TotalCMD\Plugins\WCX\CHMDir\CHMDir.wcx"
PackedFile := "R:\Bandaged Cubes\Bandaged Cubes.chm"
oFileList := [ "" ]

; calculate required size for AddList and set capacity
AddList_Size := 1
Loop, % oFileList.MaxIndex()
    AddList_Size += StrLen(oFileList[A_Index]) + 1
VarSetCapacity(AddList, AddList_Size, 0)

; fill wth zero-terminated strings
Offset := 0
Loop, % oFileList.MaxIndex()
    StrPut(oFileList[A_Index], &AddList + Offset, "CP0")
    , Offset += StrLen(oFileList[A_Index]) + 1

; call packer DLL
DllCall(DllFile "\PackFiles", "UInt", &PackedFile, "UInt", &SubPath
    , "UInt", &SrcPath, "UInt", &AddList, "Int", 0)
Post Reply