1_Integer, 2_Long, 3_Single, 4_Double, 5_Currency, 6_Variant, 7_String, 8_String *
  m00A8(0) = "<no/std obj>"
  m00A8(3) = "<ctrl>"      
  m00A8(2) = "<class>"     
  m00A8(1) = "<prop>"

1%	Integer
2&	Long
3!	Single
4#	Double
5@	Currency
6  Variant
7$	String

8$*String * 0
9-Obj
a-Type
b-MType

(A)rray
(O)bject
(T)ype
(v)ariant
(^)Pointers  (arrays, types, objects and strings are always handled by implicit pointers (not flagged))

ByVal or ByRef
 If a string is passed ByVal to a subroutine,
 a pointer to a copy of the string is passed as argument.
 That's why the Discompiler cannot decide whether a string is passed ByVal or ByRef,
 if the subroutine is never called.

the second column
%()	FreeFile
Holds the >stack arguments< and >operations< of a token
They are listed , in a function-like notation.
The 'name' of the function is the data type pushed to the stack,
the 'arguments' are the arguments' types popped off the stack.

Example
v($,%) means a >string< and an >integer< are popped off the stack,
       and a variant is pushed instead

FreeFile() as Integer
%()	FreeFile


Scopes - gLocalVarsScope
   fnPreFix(  0) = "g?"     sub Main
   fnPreFix(&H1) = "gn"

   fnPreFix(&H2) = "gv"		scope_Global_Var
   fnPreFix(&H3) = "gc"		scope_Global_Const
   fnPreFix(&H4) = "T"		scope_Type_Def
   fnPreFix(&H5) = "M"		scope_Type_DefMember

   fnPreFix(&H6) = "sub"	scope_Sub
   fnPreFix(&H7) = "fn"		scope_Function
 8 fnPreFix(6+2) = "extsub"scope_DeclareSub
 9 fnPreFix(7+2) = "extfn"	scope_DeclareFunction
10 fnPreFix(&HA) = "event"

11 fnPreFix(&HB) = "v?"		scope_v_
12 fnPreFix(&HC) = "v"		scope_v
13 fnPreFix(&HD) = "m"		scope_Module_Dim or Static
14 fnPreFix(&HE) = "g"		scope_g
15 fnPreFix(&HF) = "f"		Type_fnCall
16 fnPreFix(&H10) = "l"		scope_local
17 fnPreFix(&H11) = "p"		scope_ByRef_Param
18 fnPreFix(&H12) = "pv"	scope_ByVal_Param Var that is modified insde the func
19 fnPreFix(&H13) = "mc"	scope_Module_Const (Const)
20 fnPreFix(&H14) = "o?"	scope_o_

21 fnPreFix(&H15) = "f?"   Type_fnDef

gcTypeCharacters
"t%&!#@vOT*A$4|"

                                                                    Idx Type
                                                                     1   t
  gVB_a_TypeConv(1) = "Int"   gVB_a_DataTypes(1) = "Integer"         2   %
  gVB_a_TypeConv(2) = "Lng"   gVB_a_DataTypes(2) = "Long"            3   &
  gVB_a_TypeConv(3) = "Sng"   gVB_a_DataTypes(3) = "Single"          4   !
  gVB_a_TypeConv(4) = "Dbl"   gVB_a_DataTypes(4) = "Double"          5   #
  gVB_a_TypeConv(5) = "Cur"   gVB_a_DataTypes(5) = "Currency"        6   @
  gVB_a_TypeConv(6) = "Var"   gVB_a_DataTypes(6) = "Variant"         7   v
  gVB_a_TypeConv(7) = "Str"   gVB_a_DataTypes(7) = "String"          8   O
                 8            gVB_a_DataTypes(8) = "String *"        9   T
                 9                            9     O               10   *
                11                           10     T               11   A
                12                           11                     12   $
                                             12                     13   4
                                                                    14   |
                                                                    15   1
Types For
gLocalVarTypes And gc_MaskType_0001_1111

 0   t   ?Undef    
 1   %   Integer   
 2   &   Long      
 3   !   Single    
 4   #   Double    
 5   @   Currency  
 6   v   Variant   
 7   $   String    
 8   *   String *  
 9   O   Object    
10   T   Type      
11   A   Array     


13   4   ?Func     
14   |   ?Pointers 
15   1   ?Byte     
16   U   ?MType    
                   
----------------------------------
Type And mc_TypeArrayFlag = 16 ' &H10% -> is Array

Decompile/Tokens (pScan.Type)

 Idx Type
  1   t   ?Undef       0 = 1  
  2   %   Integer      1 = 2  
  3   &   Long         2 = 3  
  4   !   Single       3 = 4  
  5   #   Double       4 = 5  
  6   @   Currency     5 = 6  
  7   v   Variant      6 = 7  
  8   O   Object       9 = 8     
  9   T   Type        10 = 9  
 10   *   String *     8 = 10 
 11   A   Array               
 12   $   String       7 = 12 
 13   4   ?Func
 14   |   ?Pointers
 15   1   ?Byte
 16   U   ?MType




Token
TypeNScope   TypeSignShort
12				 $


"~.[asf14|c"
 1  ~
 2  .
 3  [
 4  a
 5  s
 6  f
 7  1
 8  4
 9  |
10  c






Used For debug output in ScanPhase:
	
	gc_Scope1_Chars
	"?pmlgcfOTas"
	 1  ?
	 2  p		Parameter
	 3  m		Modul
	 4  l		Local 
	 5  g		Global
	 6  c		Const
	 7  f		Function
	 8  O		Object
	 9  T		Type
	10  a		Array
	11  s		St
	
	
	"t%&!#@vOT*A$4|1U"
  ' g_ConvTypeTok_To_Flags             
    '        BA98 7654 3210            
  '  1  0000 0111 1111 1111        0x07FF      Val_TypeTok_t_all   ( 32bit high part 0000 0000 0011 1111)
  User Types
  '  2  0000_0000_0000_00%0        0x0002      gc_TypeTok_% %&!#@
  '  3  0000_0000_0000_0&00        0x0004      gc_TypeTok_&
  '  4  0000_0000_0000_!000        0x0008      gc_TypeTok_!
  '  5  0000_0000_000#_0000        0x0010      gc_TypeTok_#
  '  6  0000_0000_00@0_0000        0x0020      gc_TypeTok_@
  '  7  0000_0000_0v00_0000        0x0040      gc_TypeTok_v
  '  8  0000_0000_OO00_0000        0x0080      gc_TypeTok_O
  '  9  0000_000T_0000_0000        0x0100      gc_TypeTok_T
  '  A  0000_00*0_0000_0000        0x0200      gc_TypeTok_*
  '  B  0000_0A00_0000_0000        0x0400      gc_TypeTok_A
  '  C  0000_$000_0000_0000        0x0800      gc_TypeTok_$

  '  D  0000 0$A* 0T0@ 00&0        0x07C2      gc_TypeTok_4         ( 32bit high part 0000 0000 0011 1111)
  '  E  0000 0$00 0000 00&0        0x0402      gc_TypeTok_PIPE_unk
  '  F  0                          0x0000      
  ' 10  0                          0x0000      
  ' 11  0000 0$A* TO00 0000        0x07C0      gc_TypeTok_U_ser 
  Array Types    0x12..0x17
  ' 12  0000_0000_0000_0001 - ...  0x1001      gc_TypeTok_%  
  ' 13  0000_0000_0000_0010 - ...  0x1002      gc_TypeTok_&
  ' 14  0000_0000_0000_0100 - ...  0x1004      gc_TypeTok_!
  ' 15  0000_0000_0000_1000 - ...  0x1008      gc_TypeTok_#
  ' 16  0000_0000_0001_0000 - ...  0x1010      gc_TypeTok_@
  ' 17  0000_0000_0010_0000 - ...  0x1020      gc_TypeTok_v
  for Extended Types    0x18..0x1C
  ' 18  0000_0000_0100_0000        0x1040      gc_TypeTok_O
  ' 19  0000_0000_1000_0000        0x1080      gc_TypeTok_T
  ' 1A  0000_0001_0000_0000        0x1100      gc_TypeTok_*
  ' 1D  0000_0010_0000_0000        0x1120      gc_TypeTok_A
  ' 1C  0000_0100_0000_0000        0x1040      gc_TypeTok_$






gVB_BasicTypes() from std_p_e.300
0 ""
1 "Integer" 
2 "Long"    
3 "Single"  
4 "Double"  
5 "Currency"
6 "Variant" 
7 "String"  
8 "String *"
9 "Control"



Integer, Long, Single, Double, Currency, Variant, String

Global Const gc_TypeArrayPlus = 16 ' &H10%
Global Const gc_TypeUnDefined = 16 ' &H10%
Global Const gType_ArrayRange = 17 ' &H11%


 

Global Const gc_ScopeLocalStaticArray = 32 ' &H20%
Global Const gc_ScopeParam = 64 ' &H40%
Global Const gc_ScopeLocal = 128 ' &H80% 'on local scope can mean Dim or Func
Global Const gc_ScopeConst = 192 ' &HC0%


Global Const gc_ScopeModul = 96 ' &H60% 'on local scope it means static
Global Const gc_ScopeGlobal = 160 ' &HA0%

Global Const gc_ScopeFunc = 224 ' &HE0% 'mc_MaskScope 


Const mcUserTypeDef = 225 ' &HE1%
Const mcUserTypeEnd = 226 ' &HE2%
Const gc_ScopeNTypeFunction = 227 ' &HE3%
Const gc_ScopeNType_EOF_MODUL = &HE5  '  &HE8
Const mcTypeConst = 231 ' &HE7%
Const mc_TypeSubOrFunction = 233 ' &HE9%




pScope    1110_0000 ->2*2*2    =  8 Possible Scopes
Type      0000_1111 ->2*2*2*2  = 16 Possible Types
Glob/Loc  0001_0000 ->         =  2 Possible Types

Scopes
 20           ??? gc_ScopeLocalStaticArray

 40           gc_ScopeParam							     gc_ScopeParam
 60     +20   gc_ScopeParam+???                      gc_ScopeModul

 80           gc_ScopeLocal                          gc_ScopeLocal    Dim...
 A0     +20   gc_ScopeLocal+???                      gc_ScopeGlobal/gc_ScopeTypeMember
 C0 +40       gc_ScopeLocal+gc_ScopeParam        -19 gc_ScopeConst    Const mc0084 = 1 ' &H1%
 E0 +40 +20   gc_ScopeLocal+gc_ScopeParam+???        gc_ScopeFunc

Local Modul Globalgc_ScopeFunc
Local          	gc_ScopeLocal
      Modul       gc_ScopeParam
Local Modul Const	gc_ScopeFunc
Local Modul Const	gc_ScopeFunc





gLocalVarsValues(i) And &HF000

	&H8000 'Control

	&HC000 'Form like (me.Caption; me.Tag)
	&HC0FE "Controls"
	&HC0FD "Count"



TmpFileFormat:
  Baseformat Int16

	Version=8

	gLocalVarsCount
	gLocalVarTypes[gLocalVarsCount] as byte
	gLocalVarsTypeScope[gLocalVarsCount] as integer

	gLocalPropertyNamesCount
	gLocalPropertyNames[gLocalPropertyNamesCount] as TLenI16_Stringdata

	gVarToFunc[gLocalVarsCount] as integer

	Final=0


Globaldata (usaved)
gGlobalVarValues(gGlobalVarCount)    Const(-3) or Var (-2)
gGlobalVarTypes(gGlobalVarCount)

gGlobalVarFileData(gGlobalVarCount) Data from exeFile


IsLocalVar
   (gLocalVarsValues(VarIndex) And &H8001)
   else param

IsLocalConst
   (gLocalVarsValues(VarIndex) <> 0)

------
Accessing a Local Const:
	GVarIdx= gLocalVarsValues(VarIdx)\ 2
	GType = Asc(Mid$(gGlobalVarTypes, GVarIdx, 2), 1))

  'GTypeBits_CurInVal = Asc(Mid$(gGlobalVarTypes, gLocalVarsValues(VarIdx)\ 2, 1))

---------


 Format: VBDIS2X.DAT / VBDIS3X.DAT
 Baseformat Int16

	Version As Integer 		                        ; 0x0302 <-expected Version

   VBDIS.VBdis3i_Link_idx(&H2A55) As Integer       ;=0x54AC Bytes !          'Index to VBdis3i what contains more TokenDetails
                                                   ;  21676 Bytes !
   VBDIS_TypesInfo As String * &H2A55*3            ;   0x2A55 * 3 => 0x7EFF) 'Contains: isValid | Scope | Type
                                                   ;  ' 10837 * 3 =>  32511
	VBDIS2_Size As Integer                          ;  Normally its    32511!
   VBDIS2  As String * VBDIS2_Size                 ;=0x7EFF Bytes !  (incase VBDIS2_Size Is 0x7EFF)
																	;VBDIS2 Is used On Typescan On Stage 2.(Decompile Stage) only
																	; 

 Format: vbdis3i.dat
 Baseformat Int16

	VBdis3i_KeyWordStrings_Size

	VBdis3i_TokenData() As T_VBdis_Struct	;StartIdx To Keyword And other processinginfo's Like InParams or following parameters
	VBdis3i_KeyWordStrings As String *   		;Contains Keywords Sperated by ; Example: "Exit ForExpFalseFileAttr..."


Decompilation Is Done On three stages
	Stage 1. Scan        Very simple scan through the token To prelog variables Types/scopes FuncArguments
	Stage 2. Decompile   Second pass / improving refining Types/scopes FuncArguments
	Stage 3.	Output      Rebuilding sourcecode With help of all tokeninfo's and a Stack
	




 Format: STD_P_E.300 / VBRUN200.300 / VBRUN300.300
 Baseformat Int16

	VBX_Version  As Integer 		                   ; 0x0003 <-expected Version
	gKnowControlsData(VBX_Size) As T_VBXFile






BugFix #1:

Errorsituration      Decompiled

Sub a()              Sub a()
	dim var1 as long  	dim l0012 as long
	var1=2            	var1=2
end sub              end sub

Sub b()              Sub b()
end sub              	dim l0012 as long
                     end sub
Sub c()
end sub              Sub c()
                     	dim l0012 as long
                     end sub

Location:
  module16.bas 24140 Sub Output_Declarations()

Reason: Fence post error


BugFix #2:

in Stage3(Output Decompilation)
improve Type don't check is it's const when it find a module var belowing to different functions:

Location:
  module16.bas 24030 Sub ImproveLocalScope(VarIdx As Integer, pScope As Integer)
...
       'Does Var belongs to some other Func?
      If FuncNum <> CurFuncNum Then

        'it's a Static or Modul Dim
        If pScope = mc_ScopeModul Then

         'Get LType
          LScope = Asc(Mid$(gLocalVarTypes, VarIdx, 1)) And Not mask_1110_0000

         'Mask LType with Extra or No Const
>          If (LScope And gc_MaskExtraDataFlag) Or Not (IsLocalVarConst(VarIdx)) Then

          Else
           ' Make it Const
             pScope = mc_ScopeModConst
             Mid$(gLocalVarTypes, VarIdx, 1) = Chr$(LScope Or pScope)

            gTypesLocalChanged = True
          End If
          Exit Sub

BugFix #2:
Location:
  module16.bas 24030 Sub ProcessType(VarOffset As Integer, pScope As Integer, pType As Integer)

ProcessType don't care about Type after it is called on the same var again
so Undefined Types can't be improved

 'Seperate Type and Scope
  LScope = LType And gc_MaskScope_1110_0000
  LType = LType Xor LScope         'Mask out Scope Part

   'improve if scope was already set(var already known)
    If gLocalVarsScope(VarIdx) Then
      ImproveLocalScope VarIdx, LScope
>'      Exit Sub 'This will stop that further a VarType can be improved
    End If

' Exit is LType is a GlobalArrayOrFixString (0x10)
  If LType And gc_MaskExtraDataFlag Then








'==============================================                                                                 
'=============== Basic Types ==================                                                                 
                                                                                                                
   ' 0_, 1_Integer, 2_Long, 3_Single, 4_Double, 5_Currency,                                                     
   ' 6_String, 7_String * ?, 8_Control                                                                          
    gVB_BasicTypes(i)                                                                                           
                                                                                                                
'==================================================                                                             
'============== load PropertyTypes  ===============                                                             
                                                                                                                
 ' load Standard 'build-in' propertiesTypes (gVB_PropertyTypes)                                                 
   ' 0_Control, 1_hsz, 2_short, 3_long, 4_bool, 5_color, 6_enum, 7_real, 8_xpos,                                
   ' 9_xsize, 10_ypos, 11_ysize, 12_Picture, 13_hlstr, 14_Date, 15_, 16_Collection(of?), 17_Database,           
   ' 18_Recordset, 19_, 20_, 21_, 22_, 23_, 24_, 25_, 26_, 27_, 28_, 29_Index,                                  
   ' 30_Name, 31_Form, 32_Object                                                                                
    gVB_PropertyTypes(i)
                                                                                            
'========================================================                                                       
'============== load standard properties  ===============                                                       
                                                                                                                
 ' load Standard 'build-in' properties (gVB_Properties_Data)                                                    
   ', 0_, -1_Name, -2_Index, -3_hWnd, -4_BackColor, -5_ForeColor, -6_Left, -7_Top, -8_Width, -9_Height,         
   '-10_Enabled, -11_Visible, -12_MousePointer, -13_Caption, -14_FontName, -15_FontBold, -16_FontItalic,        
   '-17_FontStrikethru, -18_FontUnderline, -19_FontSize, -20_TabIndex, -21_Parent, -22_DragMode, -23_DragIcon,  
   '-24_BorderStyle, -25_TabStop, -26_Tag, -27_Name, -28_Text, -29_BorderStyle, -30_ClipControls, -31_<none>,   
   '-32_HelpContextID, -33_LinkMode, -34_LinkItem, -35_LinkTopic, -36_LinkTimeout, -37_Left, -38_Top, -39_Align,
   '-40_<imemode>, -41_DataSource, -42_DataField, -43_DataChanged                                               
  gVB_Properties_Data(1 - i).PropertyNameStr             
                                                                                                                
'====================================================                                                           
'============== load standard Events  ===============                                                           
                                                                                                                
 'load Standard 'build-in' Events (gVB_Events_Data)                                                             
'0_, -1_Click, -2_DblClick, -3_DragDrop, -4_DragOver, -5_GotFocus, -6_KeyDown, -7_KeyPress,                     
'-8_KeyUp, -9_LostFocus, -10_MouseDown, -11_MouseMove, -12_MouseUp, -13_LinkError, -14_LinkOpen,                
'-15_LinkClose, -16_LinkNotify, -17_Change                                                                      
   gVB_Events_Data(1 - i)                                                                         