OS2 World Community Forum

OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: Martin Iturbide on March 15, 2017, 05:50:22 pm

Title: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on March 15, 2017, 05:50:22 pm
Hi

As a part of an experiment I want to create a PMGPI.DLL empty forwarder to XPMGPI.DLL (XPMPGPI.DLL it is just the IBM's PMGPI.DLL renamed).

My very simple goals are:
* Stage 1: Create an empty forwarder.
* Stage 2: Create a wrap with a counter of the functions called on PMGPI. To create a log on PMGPI functions called by the OS.

* Requirement: I want to use the GCC compiler and no calls directly to CPI.

But I'm still locked on Stage 1, so I will not worry about Stage 2.

Since I'm learning all of this (I don't do development) I got some samples and recommendation on how to do that but it is not working.

Information:
To know what PMGPI.DLL does I used LX2DUMP and LXLite to see the functions and ordinals required
(lxlite_output.txt (http://www.os2world.com/forum/index.php?action=dlattach;topic=1318.0;attach=1720))

Development
For the empty forwarder I just got:
1) PMGPI.DEF  (http://www.os2world.com/forum/index.php?action=dlattach;topic=1318.0;attach=1719)
2) wrap.c (empty file)

Compile
To compile:
1) gcc -Zomf -c wrap.c -o wrap.o
2) gcc -Zomf -Zdll -o pmgpi.dll pmgpi.def wrap.o

Installation
1) Copied IBM's PMGPI.DLL to XPMGPI.DLL
2) Unlock IBM's PMGPI.DLL and put the new empty forwarder PMGPI.DLL

Errors
When I reboot I got the following errors (on my experimental VM):
- Error 1
(http://www.os2world.com/forum/index.php?action=dlattach;topic=1318.0;attach=1723;image)

- Error 2
(http://www.os2world.com/forum/index.php?action=dlattach;topic=1318.0;attach=1721;image)


Any ideas on this? Any tip of what can it be wrong? Am I missing more information about PMGPI.DLL so I can create a forwarder?

Thanks
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Dave Yeo on March 15, 2017, 06:38:14 pm
You can't just rename an OS/2 DLL. It's internal name (referenced in the DEF file on the LIBRARY line) has to correspond to the file name. You can hexedit the internal name (there are tools on Hobbes to automate this) but you can not make the name longer. Perhaps rename PMGPI to XMGPI and hexedit the internal name to reflect the new name and then try again.
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Dave Yeo on March 15, 2017, 06:49:19 pm
I've never created a forwarder DLL, but the process is described in the Toolkits "Tools Reference" and the toolkit includes a program, fwdstamp.exe to automate the process. The created DEF should be usable with GCC. Not sure if you even need the wrap.c step.
I'd suggest reading the documentation and testing fwdstamp to learn, though quickly looking it looks like you're on the right track but I think you also need exports in your DEF file.
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on March 16, 2017, 09:37:31 pm
Hi Dave, thanks for the reply.

I renamed it to "XMGPI.DLL" (and modified the DEF file) just to maintain the same name length of the file.
But, like you said, it may be something to modify on XMGPI.DLL to work. Using PMDLL, the new PMGPI.DLL does not seems to find XMGPI.DLL on the same C:\os2\dll directory. (check picture)

To fix this, is it just with hexedit? or there are any tools to easy this?

I'm also reading about "fwdstamp", but I'm not sure if that tool will help me modify IBM's PMGPI.DLL (to create XMGPI.DLL) or will help me to create the new PMGPI.DLL forwarder file, or both...??

Regards
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Dave Yeo on March 16, 2017, 11:56:39 pm
Perhaps http://hobbes.nmsu.edu/download/pub/os2/util/system/renmodul2_0_0.zip (http://hobbes.nmsu.edu/download/pub/os2/util/system/renmodul2_0_0.zip), seems there were others but I can't remember the names. Or just use a hex editor. As long as you  backup PMGPI.DLL, it can't hurt.
I'll attach an attempt at renaming it using EPM, untested.
Reading more about fwdstamp, it may not help you, and looking closer at your def file, it seems it should work though I've never tried.
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on March 17, 2017, 03:47:53 pm
Hi Dave.

It seems that your modifications to the XMGPI.DLL file worked out. It gives me a different error (check attachments).
Was the change you made with EPM? Did you modified every word that said PMGPI to XMGPI ?

It seems that the DEF file is missing some "ordinals" that where not reported by lxlite.  Why? Maybe I need something different to take more information of DLLs.

Regards

Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Dave Yeo on March 17, 2017, 04:26:57 pm
Hi Martin,
I only found one instance of the string pmgpi in the dll, changed the p to an x and used save as to save the dll. Double checked it was the same length as my first try with a different editor created a longer file (converted LF->CR LF) and figured it was fine.
As for why lxlite missed some ordinals, I'm not sure. I do know that the table of functions isn't complete in lxlite and needs more updating. Not sure what other tool to use, perhaps there is something to make sense out of the sym files?
I tried
Code: [Select]
emximp -o pmgpi.def PMGPI.DLLand the resulting def also didn't list a 625 ordinal, perhaps it is in PMSPL.DEF.
I guess you could add the ordinals that fail and see if you get further.
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on March 21, 2017, 08:52:46 pm
Hi

I have no luck yet. I will keep trying with the missing ordinals, there is a little bit more information on the EDM2 PMGPI.DLL page.  (http://www.edm2.com/index.php/PMGPI.DLL)

I will keep trying with some aditional changes to the DEF file.

Regards
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Dave Yeo on March 21, 2017, 09:12:12 pm
Maybe the problem is that you're importing all the symbols from XMGPI. Instead of
Code: [Select]
DevStdOpen=XMGPI.625it should be
Code: [Select]
DevStdOpen=PMSPL.625Along with a lot of similar changes.
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on March 21, 2017, 10:05:08 pm
Hi

I tried that change and it gives me the same error has before:
(http://www.os2world.com/forum/index.php?action=dlattach;topic=1318.0;attach=1736;image)

What I don't understand if it is PMSPL.DLL that is trying to call PMGPI.625, and how to validate that PMGPI.625 is really Dev32StdOpen or DevStdOpen (I tried both), since I can not find that ordinal with lx2dump, lxlite or  emximp.

Regards
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Dave Yeo on March 21, 2017, 11:50:28 pm
Yea, looking at pmspl.dll, it looks to be printing functions.
Looking at pmgpi.sym, there seems to be DEV32STDOPEN and DEV16STDOPEN. Be nice to know of a utility to deconstruct the sym files.
Pmgpi.sym is (here in ArcaOS, pretty sure eCS is the same) on the DVD in \os2image\sym_1\os2\dll.
Not sure which is calling which, seems weird that it is giving you the sys1919
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: André Heldoorn on March 24, 2017, 12:48:29 pm
Stage 2: Create a counter of the functions called on PMGPI. To create a log on PMGPI functions called by the OS.

PMGPI.DLL can be TRACEd, FWIW. I'm not supposed to tell you if the Trace Facility will log all desired details.
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Lars on March 24, 2017, 01:44:52 pm
Get this:
http://www.edm2.com/common/snippets/newc2.zip

unpack it and read it. It does exactly what you are trying to achieve. Additionally, it replaces exactly one function by real code (DosOpen in this case).

Lars
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on March 24, 2017, 02:01:15 pm
Thanks Lars, it looks interesting. I will check it on detail and post back.

Regards
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on April 21, 2017, 09:43:11 pm
Hi

I read the file that Lar's suggested. It does something different from what I'm trying to do. For what I understand this file makes a DOSCALLS.DLL replacement by creating NEWCALLS.DLL and linking os2386.lib inside it. After that it modifies with PMMMERGE.DLL (with dllrname.exe) so all the calls to DOSCALLS goes to NEWCALLS.

But it gives me the idea of what to do with the unknown/undocumented ordinals on the PMGPI.DLL file.

So I had included all the missing ordinals on the DEF files so it links it XMGPI.DLL even the ones that I don't know if exists. But I still get problems booting OS/2 with that PMGPI.DLL replacement.

I'm attaching my PMGPI.DEF forwarder just in case someone can give me a hint of what I'm missing.

Regards
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Lars on April 22, 2017, 12:02:11 am
In the "IMPORTS" section, replace all "XPMGPI" against "GPI".
Of course that is not gaining you any functionality at all.
But it will forward all "GPI" calls to your "XPMGPI" dll as the "EXPORTS" section now exports all the very same entry points.

Lars
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on April 22, 2017, 01:42:40 am
Hi Lars

Can you please give me just in example of the first function and I will take it from there?
like... DEVOPENDC=XMGPI.1 should be replace by ....????

Thanks for your help.

Regards
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Lars on April 22, 2017, 10:26:20 pm
DEVOPENDC=GPI.1
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on May 04, 2017, 05:02:28 pm
Hi Lars.

It didn't worked that way, it did not compile. (Check attachment).

When I compile it with "gcc -Zomf -Zdll -o pmgpi.dll pmgpi.def" I get this error:

Code: [Select]
weakld: error: Unresolved symbol (UNDEF) 'MTGETFIRSTGRAPHICSDATA'.
weakld: info: The symbol is referenced by:
    C:/Desktop/WarpGPI/PMGPI.DEF
weakld: error: Unresolved symbol (UNDEF) 'GPIQUERYDRAWCONTROL'.
weakld: info: The symbol is referenced by:
    C:/Desktop/WarpGPI/PMGPI.DEF
weakld: error: Unresolved symbol (UNDEF) 'GPIQUERYREGIONBOX'.
weakld: info: The symbol is referenced by:
    C:/Desktop/WarpGPI/PMGPI.DEF
weakld: error: Unresolved symbol (UNDEF) 'GPISETPS'.
weakld: info: The symbol is referenced by:
    C:/Desktop/WarpGPI/PMGPI.DEF
weakld: error: Unresolved symbol (UNDEF) 'GPIQUERYBITMAPPARAMETERS'.
weakld: info: The symbol is referenced by:
    C:/Desktop/WarpGPI/PMGPI.DEF
Ignoring unresolved externals reported from weak prelinker.
weakld: error: Parse error 4 on line 11. (errorcode=81 stmt=12)
emxomfld: Invalid statement (line 4 of C:/Desktop/WarpGPI/PMGPI.DEF)

Regards
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Lars on May 05, 2017, 07:33:51 am
You forgot the "IMPORTS" keyword ...
Look at your original DEF file.
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Martin Iturbide on May 05, 2017, 04:19:32 pm
Thanks, huge mistake from this side.

It compiles, but I don't know if it is the same that I had been doing. My goal was to rename IBM's PMGPI.DLL to XMGPI.DLL and have a fake PMGPI.DLL that forward the functions to XMGPI.DLL.

It compiles but it refers now to GPI.DLL, even if I rename IBM's PMGPI.DLL to GPI.DLL, it will give me the same boot errors when I load eCS 2.2 with the "fake PMGPI.DLL" I created.

Regards

Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: Lars on May 05, 2017, 08:30:54 pm
IMPORTS
   DEVOPENDC=XMGPI.1
   etc.
EXPORTS
   can and will have to stay the same as before


then, use a DLL rename tool (VAC comes with one but I think there is another one on Hobbes) to rename the original PMGPI.DLL to XMGPI.DLL.
It is NOT sufficient to just rename the file from PMGPI.DLL to XMGPI.DLL. The DLL has an internal module name that must also change from PMGPI to XMGPI.
By the way: the renamed DLL has to have the very same name length as the original file (which it does if you rename from PMGPI to XMGPI).

Lars
Title: Re: Creating a PMGPI.DLL empty forwarder
Post by: André Heldoorn on May 10, 2017, 05:22:50 pm
I think there is another one on Hobbes

I guess that's http://hobbes.nmsu.edu/download/pub/os2/util/system/renmodul2_0_0.zip (http://hobbes.nmsu.edu/download/pub/os2/util/system/renmodul2_0_0.zip).