Author Topic: Creating a PMGPI.DLL empty forwarder  (Read 1110 times)

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 221
  • -Receive: 41
  • Posts: 1517
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Creating a PMGPI.DLL empty forwarder
« 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)

Development
For the empty forwarder I just got:
1) PMGPI.DEF
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


- Error 2



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
« Last Edit: March 15, 2017, 06:04:01 pm by Martin Iturbide »


Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 6
  • -Receive: 74
  • Posts: 931
    • View Profile
Re: Creating a PMGPI.DLL empty forwarder
« Reply #1 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.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 6
  • -Receive: 74
  • Posts: 931
    • View Profile
Re: Creating a PMGPI.DLL empty forwarder
« Reply #2 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.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 221
  • -Receive: 41
  • Posts: 1517
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Creating a PMGPI.DLL empty forwarder
« Reply #3 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
« Last Edit: March 16, 2017, 10:23:19 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 6
  • -Receive: 74
  • Posts: 931
    • View Profile
Re: Creating a PMGPI.DLL empty forwarder
« Reply #4 on: March 16, 2017, 11:56:39 pm »
Perhaps 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.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 221
  • -Receive: 41
  • Posts: 1517
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Creating a PMGPI.DLL empty forwarder
« Reply #5 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

Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 6
  • -Receive: 74
  • Posts: 931
    • View Profile
Re: Creating a PMGPI.DLL empty forwarder
« Reply #6 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.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 221
  • -Receive: 41
  • Posts: 1517
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Creating a PMGPI.DLL empty forwarder
« Reply #7 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.

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

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 6
  • -Receive: 74
  • Posts: 931
    • View Profile
Re: Creating a PMGPI.DLL empty forwarder
« Reply #8 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.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 221
  • -Receive: 41
  • Posts: 1517
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Creating a PMGPI.DLL empty forwarder
« Reply #9 on: March 21, 2017, 10:05:08 pm »
Hi

I tried that change and it gives me the same error has before:


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
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 6
  • -Receive: 74
  • Posts: 931
    • View Profile
Re: Creating a PMGPI.DLL empty forwarder
« Reply #10 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

André Heldoorn

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 111
    • View Profile
Re: Creating a PMGPI.DLL empty forwarder
« Reply #11 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.

Lars

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 19
  • Posts: 117
    • View Profile
Re: Creating a PMGPI.DLL empty forwarder
« Reply #12 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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 221
  • -Receive: 41
  • Posts: 1517
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Creating a PMGPI.DLL empty forwarder
« Reply #13 on: March 24, 2017, 02:01:15 pm »
Thanks Lars, it looks interesting. I will check it on detail and post back.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 221
  • -Receive: 41
  • Posts: 1517
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Creating a PMGPI.DLL empty forwarder
« Reply #14 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
Martin Iturbide
OS2World NewsMaster
... just share the dream.