'2018-03-10 T 12:42:46
'extract dll procedure names
'create unprototyped omniheader
uses console
'
'kernel/user/gdi/oleaut/Comctl/Comdlg/shell
string ff="kernel"
string fi=ff+"32.dll"
string fo=ff+"W.inc"
sys hl=loadlibrary fi
if not hl then
  printl "Unable to find " fi 
  goto done
end if
printl "filename " fi
sys  ps=hl
sys  *ph
word *pw
char*pc
sys pcoff
int i
'
@ph=ps+0x3c
@pw=ps+ph+0x18
'printl "magic: " hex pw
pcoff=ps+ph
int*sh
if pw=0x10b then
  printl "32 bit"
  @ph=pcoff+0x78 'offset data here
  @sh=pcoff+0xf8
else
  printl "64 bit"
  @ph=pcoff+0x88
  @sh=pcoff+0x108
end if
printl "Offset of export section header table " hex ph
int*pl
'@pl=@ph+4
'printl "Length of export section header table " hex pl 
'
sys pa    'returned from GetProcAddress
sys pt    'address of string
int*px    'RVA names list
int*pq    'count of names
int*pn    'dereferencer
word*dn   'ordinal table entry
sys fn    'function address
string fs 'number string
int oo    'name list and function list strider
string bb 'output buffer
string ss 'composed declaration line
'
@px=ps+ph+0x0c       'RVA of name of table
@pc=ps+px            'name of table
@pq=ps+ph+0x18       'number of names
@px=ps+ph+0x20       'offset of names list
printl pc            'print name of table
bb=nuls pq*100       'allow 100 bytes each record
word*pb              'buffer position / and white space patcher
int le               'length of string
@pb=strptr bb        'set to start of buffer
ss="extern lib "+qu+fi+qu+cr
le=len(ss)
@pc=strptr ss
copy @pb,@pc, le 'patch in
@pb+=le          '
'
for i=1 to pq        'each function in the export table
  @pn=ps+px+oo       'address of function name
  @pc=ps+pn          'function name
  ss="! "+pc
  if right(ss,1)="W"
    le=len(ss)
    'create alias
    ss=left(ss,le-1)+" "+qu+pc+qu
  end if
  @pc=strptr ss
  le=len ss
  oo+=4            'stride for next entry
  copy @pb,@pc, le 'patch in function name
  @pb+=le          '
  pb=0x0a0d        'patch in crlf
  @pb+=2           '
next
ss="end extern"+cr
le=len(ss)
@pc=strptr ss
copy @pb,@pc, le 'patch in
@pb+=le          '
le=@pb-strptr bb 'length of list
putfile fo, left bb,le
printl "saved as " fo
freelibrary hl
done:
wait
