Forum Discussion

han's avatar
han
Contributor
14 years ago

Check 32/64 bit dll

Is it possible to use TestComplete to check if a dll is 64 or 32 bit.

Found a perl script that checks machine in the PE headen but need some help converting it to VBscript





---perl code---

open(EXE, $exe) or die "can't open $exe: $!";

if (read(EXE, $doshdr, 68)) {

 

   ($magic,$skip,$offset)=unpack('a2a58l', $doshdr);

   die("Not an executable") if ($magic ne 'MZ');

 

   seek(EXE,$offset,SEEK_SET);

   if (read(EXE, $pehdr, 6)){

       ($sig,$skip,$machine)=unpack('a2a2v', $pehdr);

       die("No a PE Executable") if ($sig ne 'PE');

 

       if ($machine == 0x014c){

            print "i386\n";

       }

       elsif ($machine == 0x0200){

            print "IA64\n";

       }

       elsif ($machine == 0x8664){

            print "AMD64\n";

       }

       else{

            printf("Unknown machine type 0x%lx\n", $machine);

       }

   }

}

close(EXE);

3 Replies

  • Hi Hakan,


    TC 7 does not have any functionality to determine whether a DLL is 64 or 32 bit.

  • Allen,



    Do you know if TestComplete 8 will have this capability? It's something I was looking into as well.



    -Chuck Firment
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Håkan and Chuck,



    It may be something like this:

    '-----------------------------------------------------------------------------


    Function GetExecutableBitness(ByVal strFullFileName)

      Dim oFile

      Dim iOffset

      Dim oValue


      GetExecutableBitness = -1

      If (Not aqFile.Exists(strFullFileName)) Then _

        Log.Error(strFullFileName & " file was not found")


      Set oFile = aqFile.OpenBinaryFile(strFullFileName, aqFile.faRead, False)

      oFile.Cursor = &H3C ' contains offset to segmented .EXE header

      iOffset = oFile.ReadInt()


      oFile.Cursor = iOffset ' move to segmented .EXE header start

      oValue = Chr(oFile.ReadByte)

      oValue = oValue & Chr(oFile.ReadByte)

      If ("PE" <> oValue) Then _

        Log.Error(strFullFileName & " file does not contain the required 'PE' signature")


      oFile.Cursor = oFile.Cursor + 2

      oValue = oFile.ReadShort

      Log.Message(aqString.Format("File bitness: 0x%X (%id)", oValue, oValue))

      GetExecutableBitness = aqString.Format("0x%X", oValue)


      If (Not oFile.Close) Then _

        Log.Error(strFullFileName & " file cannot be closed properly")


    End Function

    '-----------------------------------------------------------------------------


    Sub TestGetExecutableBitness()

      Dim strBitness


      strBitness = GetExecutableBitness("C:\Program Files\Automated QA\TestComplete 7\Bin\msxml4r.dll")

      Select Case strBitness

        Case "0x14C"

          Log.Message("i386")

        Case "0x200"

          Log.Message("IA64")

        Case "0x8664"

          Log.Message("AMD64")

        Case Else

          Log.Warning("Unknown machine type " & strBitness)

      End Select

    End Sub

    '-----------------------------------------------------------------------------