Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 108
» Latest member: Michael Burns
» Forum threads: 73
» Forum posts: 500

Full Statistics

Latest Threads
The Future
Forum: Suggestions and discussion about PUMP
Last Post: Colin Schmidt
9 hours ago
» Replies: 30
» Views: 2,006
Comments re High resoluti...
Forum: Programming
Last Post: David Roberts
09-14-2025, 05:34 PM
» Replies: 12
» Views: 342
High resolution replaceme...
Forum: Source Code Library
Last Post: David Roberts
09-14-2025, 08:11 AM
» Replies: 2
» Views: 269
Pac-Man maze
Forum: Programming
Last Post: Brian Alvarez
09-08-2025, 06:31 PM
» Replies: 11
» Views: 900
gbLocator (Discussion)
Forum: PowerBASIC for Windows
Last Post: Mike Doty
09-07-2025, 12:50 PM
» Replies: 2
» Views: 234
New Announcements?
Forum: Suggestions and discussion about PUMP
Last Post: Stuart McLachlan
09-06-2025, 03:43 AM
» Replies: 0
» Views: 173
WMIC removed in WIn11 25H...
Forum: Programming
Last Post: Stuart McLachlan
09-06-2025, 03:23 AM
» Replies: 0
» Views: 101
Promoting PowerBASIC docu...
Forum: PowerBASIC Documentation
Last Post: Graham McPhee
09-05-2025, 09:46 PM
» Replies: 4
» Views: 1,856
Very Fast WString /Object...
Forum: Programming
Last Post: Stanley Durham
09-05-2025, 07:03 PM
» Replies: 7
» Views: 462
Very Fast WString /Object...
Forum: Source Code Library
Last Post: Stanley Durham
09-05-2025, 01:29 AM
» Replies: 0
» Views: 140

 
  Leap days (or not) in February for PBDOS
Posted by: Dale Yarker - 03-08-2025, 08:48 AM - Forum: Source Code Library - Replies (2)

'DECLARE not needed if FUNCTION source is before the CALL
'here the CALL is in PBMAIN
'I call it bottom up because PBMAIN is last and flow goes up
'
'Pretty sure PUSHes and POPs not needed in FUNCTION
'They will be needed to use "inside" code in-line with BASIC
'
'Used PBCC v6 to test. I no longer have PBDOS available.
function Tage_im_Februar(byval iJahr as integer) as integer
  local FebruarTage as integer
  ! push ax
  ! mov FebruarTage, 28&  'not a leap year, pre-set to 28
  ! mov ax, 1582%
  ! cmp ax, iJahr
  ! jge Julian
  ! mov ax, 3%
  ! and ax, iJahr    'conditionally equivalent MOD 4
  ! jz MOD100        '0 is possible leap year
  ! jmp Done
  MOD100:
  ! push bx          'for divisor
  ! push dx          'for high part of dividend, remainder (MOD)
  ! xor dx, dx
  ! mov ax, iJahr
  ! mov bx, 100%
  ! div bx
  ! cmp dx, 0%    'does MOD 100 = 0 ?
  ! pop dx
  ! pop bx
  ! jz MOD400        '0 is possibly not a leap year
  ! jmp Is29Days      'non 0 is a leap year
  MOD400:
  ! and ax, 3%    'EAX has Year\100, so conditionally equivalent MOD 400
  ! jnz Done
  Julian:
  ! mov ax, 3%
  ! and ax, iJahr
  ! jnz Done
  Is29Days:
  ! mov FebruarTage, 29%
  Done:
  ! pop ax
  function = FebruarTage
end function
function pbmain () as long 'put only to demonstrate Tage_im_Februar
  local iJahr as integer
  iJahr = 2000
  print Tage_im_Februar(iJahr); " 2000, divisible by 400, is leap"
  iJahr = 2100
  print Tage_im_Februar(iJahr); " 2100, divisible by 100 not 400, not leap"
  iJahr = 2104
  print Tage_im_Februar(iJahr); " 2104, divisible by 4 not 100, is leap"
  iJahr = 2103
  print Tage_im_Februar(iJahr); " 2103, not divide 4, not leap
  print "julian, did not check rule for prior to Gregorian myself"
  iJahr = 1204
  print Tage_im_Februar(iJahr); " 1204, divisible by 4, is leap
  iJahr = 1201
  print Tage_im_Februar(iJahr)  " 1201, not divisible by 4, not leap
  waitkey$
end function

Print this item

  The LeapYear
Posted by: Andy Dee - 03-07-2025, 04:09 PM - Forum: Programming - Replies (11)

Here, Dale Yarker shows a fast Way to find a Leap Year.

This looks very nice - for 32-Bit Systems.

Programming in 16-Bit PB 3.5  for DOS, I can only make  Cry eyes…  Huh

I use a much slower routine, calculating results for julian and gregorian calendar.

Code:
Declare _
Function iFeb(ByVal iJahr As Integer)        As Integer
Function iFeb(ByVal iJahr As Integer) Public As Integer
  If iJahr < 1582% then
    Function = 29% _
             + ( _
                 ( _
                   iJahr Mod 4% _
                 ) _
                 <> 0% _
               )
  Else
    Function = 29% _
             + ( _
                 ( _
                   iJahr/4 _
                 ) _
                 <> _
                 ( _
                   iJahr\4 _
                 ) _
                 Or _
                 ( _
                   iJahr/100 _
                 ) _
                 = _
                 ( _
                   iJahr\100 _
                 ) _
                 And _
                 ( _
                   iJahr/400 _
                 ) _
                 <> _
                 ( _
                   iJahr\400 _
                 ) _
               )
  End If
End Function

Does someone has an idea, how this could look in 16-Bit-Inline-Asm?

Print this item

  Bug found: →
Posted by: Andy Dee - 03-07-2025, 12:32 PM - Forum: PowerBASIC for DOS - Replies (5)

Hello everyone

In a text block commented out with $If 0 - $EndIF, the control character "→" appears at some point. This causes PB 3.5 to assume that the file ends here, which is acknowledged with error 436 during compilation.
There used to be this bug with the "ü", but it was fixed quite quickly.
Perhaps of interest and use to someone.

Andy

Edit:
Dieser Fehler tritt auch beim Auskommentieren mit "'" oder "Rem" auf.

Edit 2 (sorry for German language):
This error also occurs when commenting out with “'” or “Rem”.

Print this item

  Turning http to https?
Posted by: Andy Dee - 03-06-2025, 01:20 PM - Forum: Suggestions and discussion about PUMP - Replies (3)

Hello to all, especially to the Admin,

do you see a chance, to turn the http://… to a more secure https://… ?

Wish us all the very best,
Andy

Print this item

  2003 Podcast featuring PowerBASIC founder Bob Zale
Posted by: Frank Ferrell - 02-22-2025, 09:08 PM - Forum: This and that - friendly chat - No Replies

Greetings ....

Found this purely by chance ....

From March 24th 2003, a 53-minute podcast interview by PowerBASIC's Bob Zale, as well as PDQ creator Ethan Winer.

The interview can be downloaded as an mp3 audio file -- just click-on the three dots to the right of the playback field and choose DOWNLOAD.

Here's the link -- Net Rocks Podcast: March 24th 2003

Thanx-A-Lot, Frank

Print this item

  New sub-forum and some housekeeping work
Posted by: Albert Richheimer - 01-30-2025, 01:52 PM - Forum: Suggestions and discussion about PUMP - No Replies

Hi @all

Today I have created an new sub-forum Alternatives to PowerBASIC. Here we can discuss alternatives to the PowerBASIC compiler.

Also I have done some housekeeping. You will see the prefix "Moved". I have moved some threads to the proper place. Please take care when creating a new thread. Thank you!

Cheers,
Albert

Print this item

  Detecting VM discussion
Posted by: Anne Wilson - 01-29-2025, 09:52 PM - Forum: PowerBASIC for Windows - No Replies

I have listed some pertinent codes on detecting Virtual Machines, these are :

Detect QEMU Virtual Machine
http://pump.richheimer.de/showthread.php...160#pid160


Detect Hyper-V Virtual Machine
http://pump.richheimer.de/showthread.php...159#pid159

Detect WINE emulator
http://pump.richheimer.de/showthread.php...146#pid146

Detect the Virtual Box Virtual Machine
http://pump.richheimer.de/showthread.php...143#pid143

This thread forms the discussions for these codes, if you encounter detections through
the use of these programs or not able to detect , please let me know.

These VM and emulator are commonly used in the Windows and Linux platforms
by users who can pirate your programs,  therefore detections are vital to
discourage the use of VM to pirate your products. 

Once a VM is detected, just stop the program and exit.  Or  make it GPF 
or do something irrelevant to make it difficult for them to make copies of your programs ?

Print this item

  Detect QEMU Virtual Machine
Posted by: Anne Wilson - 01-29-2025, 09:39 PM - Forum: Source Code Library - No Replies

This program will detect if it is being run in a QEMU  Virtual Machine VM.
Note that hackers will place your programs to run in a VM so that they can
pirate or hack your programs.  

This is to detect whether the user is using a QEMU  VM and to do the 
necessary counter action.   

Please let me know if you encounter issue with this program.

Code:
  ' Detect QEMU.bas


'   This program uses multiple detection methods for QEMU VM to increase accuracy.
'   However, no single method is foolproof, as virtualization environments
'   can be customized or masked by hackers.

    #COMPILE EXE
    #DIM ALL
    #INCLUDE "Win32Api.inc"

     %KEY_QUERY_VALUE     = &H0001
     %ERROR_SUCCESS       = 0




'============================
  FUNCTION PBMAIN () AS LONG
    IF IsQEMU() THEN
        ? "Running inside a QEMU virtual machine."
    ELSE
        ? "Not running inside a QEMU virtual machine."
    END IF
END FUNCTION





'===============================
'   Detects QEMU VM using several methods
FUNCTION IsQEMU() AS LONG
    LOCAL hqeKey  AS DWORD
    LOCAL dwType  AS DWORD
    LOCAL dwData  AS DWORD
    LOCAL cbData  AS DWORD
    LOCAL qresult AS LONG

  ' Indicator for various QEMU types
    LOCAL tmpQe   AS LONG
    tmpQe = 0

    ' Check for QEMU-specific registry key (System Manufacturer)
    ' HARDWARE\DESCRIPTION\System\BIOS
    qresult = RegOpenKeyEx(%HKEY_LOCAL_MACHINE, hwBios, 0, %KEY_QUERY_VALUE, hqeKey)
    IF qresult = %ERROR_SUCCESS THEN
        cbData = 256
      ' SystemManufacturer
        qresult = RegQueryValueEx(hqeKey, SysManf , 0, dwType, BYVAL VARPTR(dwData), cbData)
         IF qresult = %ERROR_SUCCESS THEN
            'QEMU
            IF INSTR(UCASE$(PEEK$(VARPTR(dwData), cbData)), StQE) > 0 THEN
                tmpQe = 1
            END IF
        END IF
        RegCloseKey hqeKey
    END IF

    IF tmpQe > 0 THEN
       IsQEMU = 1
       EXIT FUNCTION
    END IF


    ' Check for QEMU-specific driver (qxl.sys or virtio drivers)
    ' such as QXL video adapter or VirtIO devices
    ' C:\Windows\System32\drivers\qxl.sys       and
    ' C:\Windows\System32\drivers\vioinput.sys
    IF ISFILE(qxlS ) OR ISFILE(vioinp) THEN
        tmpQe = 2
    END IF

    IF tmpQe > 0 THEN
       IsQEMU = 1
       EXIT FUNCTION
    END IF

    ' Check for QEMU-specific hardware (QXL video or VirtIO devices)
    ' C:\Windows\System32\drivers\qxl.dll    and
    ' C:\Windows\System32\drivers\viostor.sys
    IF ISFILE(stQxl) OR ISFILE(stVio) THEN
        tmpQe = 3
    END IF

    IF tmpQe > 0 THEN
       IsQEMU = 1
       EXIT FUNCTION
    END IF

  ' Not running inside QEMU
    IsQEMU = 0
END FUNCTION





' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
'    C:\Windows\System32\drivers\vioinput.sys
FUNCTION vioinp() AS STRING

  ' Text is 40 bytes excluding the terminating zero

    #REGISTER NONE

    LOCAL src  AS DWORD
    LOCAL dst  AS DWORD
    LOCAL outpt$

    src = CODEPTR(datalabel)

    outpt$ = NUL$(40)
    dst = STRPTR(outpt$)

  ' -------------------
  ' copy data to string
  ' -------------------
    ! mov esi, src
    ! mov edi, dst
    ! mov ecx, 40
    ! rep movsb

    src = CODEPTR(paddlabel)

  ' -----------------------------
  ' xor string data to unique pad
  ' -----------------------------
    ! mov esi, dst
    ! mov ebx, 40
    ! mov edi, src
    ! add esi, ebx
    ! add edi, ebx
    ! neg ebx

  lbl0:
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jnz lbl0

  lbl1:
    FUNCTION = outpt$
    EXIT FUNCTION

  #ALIGN 4
  datalabel:
    ! db 137,244,134,19,90,252,4,157,27,48,199,3,14,247,228,3
    ! db 175,250,190,186,216,209,84,46,134,104,244,174,243,136,210,100
    ! db 103,146,120,43,36,182,157,78,0

  #ALIGN 4
  paddlabel:
    ! db 202,206,218,68,51,146,96,242,108,67,155,80,119,132,144,102
    ! db 194,201,140,230,188,163,61,88,227,26,135,242,133,225,189,13
    ! db 9,226,13,95,10,197,228,61,0

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤



' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
   '  C:\Windows\System32\drivers\qxl.sys
FUNCTION qxlS() AS STRING

  ' Text is 35 bytes excluding the terminating zero

    #REGISTER NONE

    LOCAL src  AS DWORD
    LOCAL dst  AS DWORD
    LOCAL outpt$

    src = CODEPTR(datalabel)

    outpt$ = NUL$(35)
    dst = STRPTR(outpt$)

  ' -------------------
  ' copy data to string
  ' -------------------
    ! mov esi, src
    ! mov edi, dst
    ! mov ecx, 35
    ! rep movsb

    src = CODEPTR(paddlabel)

  ' -----------------------------
  ' xor string data to unique pad
  ' -----------------------------
    ! mov esi, dst
    ! mov ebx, 35
    ! mov edi, src
    ! add esi, ebx
    ! add edi, ebx
    ! neg ebx

  lbl0:
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jnz lbl0

  lbl1:
    FUNCTION = outpt$
    EXIT FUNCTION

  #ALIGN 4
  datalabel:
    ! db 39,193,199,194,34,252,156,45,109,153,235,30,232,30,74,199
    ! db 100,250,27,119,124,175,212,177,7,207,147,66,236,149,73,81
    ! db 143,69,39,0

  #ALIGN 4
  paddlabel:
    ! db 100,251,155,149,75,146,248,66,26,234,183,77,145,109,62,162
    ! db 9,201,41,43,24,221,189,199,98,189,224,30,157,237,37,127
    ! db 252,60,84,0

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤





' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
'C:\Windows\System32\drivers\qxl.dll
FUNCTION stQxl() AS STRING

  ' Text is 35 bytes excluding the terminating zero

    #REGISTER NONE

    LOCAL src  AS DWORD
    LOCAL dst  AS DWORD
    LOCAL outpt$

    src = CODEPTR(datalabel)

    outpt$ = NUL$(35)
    dst = STRPTR(outpt$)

  ' -------------------
  ' copy data to string
  ' -------------------
    ! mov esi, src
    ! mov edi, dst
    ! mov ecx, 35
    ! rep movsb

    src = CODEPTR(paddlabel)

  ' -----------------------------
  ' xor string data to unique pad
  ' -----------------------------
    ! mov esi, dst
    ! mov ebx, 35
    ! mov edi, src
    ! add esi, ebx
    ! add edi, ebx
    ! neg ebx

  lbl0:
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jnz lbl0

  lbl1:
    FUNCTION = outpt$
    EXIT FUNCTION

  #ALIGN 4
  datalabel:
    ! db 107,242,156,222,105,186,235,71,251,111,207,178,223,54,223,160
    ! db 48,66,192,5,85,78,114,228,105,10,125,30,253,8,13,29
    ! db 29,250,74,0

  #ALIGN 4
  paddlabel:
    ! db 40,200,192,137,0,212,143,40,140,28,147,225,166,69,171,197
    ! db 93,113,242,89,49,60,27,146,12,120,14,66,140,112,97,51
    ! db 121,150,38,0

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
   '   C:\Windows\System32\drivers\viostor.sys
FUNCTION stVio() AS STRING

  ' Text is 39 bytes excluding the terminating zero

    #REGISTER NONE

    LOCAL src  AS DWORD
    LOCAL dst  AS DWORD
    LOCAL outpt$

    src = CODEPTR(datalabel)

    outpt$ = NUL$(39)
    dst = STRPTR(outpt$)

  ' -------------------
  ' copy data to string
  ' -------------------
    ! mov esi, src
    ! mov edi, dst
    ! mov ecx, 39
    ! rep movsb

    src = CODEPTR(paddlabel)

  ' -----------------------------
  ' xor string data to unique pad
  ' -----------------------------
    ! mov esi, dst
    ! mov ebx, 39
    ! mov edi, src
    ! add esi, ebx
    ! add edi, ebx
    ! neg ebx

  lbl0:
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jnz lbl0

  lbl1:
    FUNCTION = outpt$
    EXIT FUNCTION

  #ALIGN 4
  datalabel:
    ! db 249,253,198,251,223,113,140,156,245,139,234,192,79,79,251,90
    ! db 10,141,82,54,82,155,166,16,138,158,122,123,208,158,228,122
    ! db 211,170,16,201,173,76,240,0

  #ALIGN 4
  paddlabel:
    ! db 186,199,154,172,182,31,232,243,130,248,182,147,54,60,143,63
    ! db 103,190,96,106,54,233,207,102,239,236,9,39,166,247,139,9
    ! db 167,197,98,231,222,53,131,0

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤




' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
     '  QEMU
FUNCTION StQE() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(4)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+0], 81
    ! mov BYTE PTR [esi+2], 77
    ! mov BYTE PTR [esi+1], 69
    ! mov BYTE PTR [esi+3], 85

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤





' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  ' SystemManufacturer
FUNCTION SysManf() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(18)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+14], 117
    ! mov BYTE PTR [esi+5], 109
    ! mov BYTE PTR [esi+9], 117
    ! mov BYTE PTR [esi+16], 101
    ! mov BYTE PTR [esi+15], 114
    ! mov BYTE PTR [esi+17], 114
    ! mov BYTE PTR [esi+11], 97
    ! mov BYTE PTR [esi+8], 110
    ! mov BYTE PTR [esi+13], 116
    ! mov BYTE PTR [esi+3], 116
    ! mov BYTE PTR [esi+4], 101
    ! mov BYTE PTR [esi+2], 115
    ! mov BYTE PTR [esi+0], 83
    ! mov BYTE PTR [esi+1], 121
    ! mov BYTE PTR [esi+7], 97
    ! mov BYTE PTR [esi+12], 99
    ! mov BYTE PTR [esi+6], 77
    ! mov BYTE PTR [esi+10], 102

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤




' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
   ' HARDWARE\DESCRIPTION\System\BIOS
FUNCTION hwBios() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(32)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+28], 66
    ! mov BYTE PTR [esi+29], 73
    ! mov BYTE PTR [esi+27], 92
    ! mov BYTE PTR [esi+17], 73
    ! mov BYTE PTR [esi+4], 87
    ! mov BYTE PTR [esi+30], 79
    ! mov BYTE PTR [esi+20], 92
    ! mov BYTE PTR [esi+16], 84
    ! mov BYTE PTR [esi+21], 83
    ! mov BYTE PTR [esi+25], 101
    ! mov BYTE PTR [esi+31], 83
    ! mov BYTE PTR [esi+12], 67
    ! mov BYTE PTR [esi+15], 80
    ! mov BYTE PTR [esi+22], 121
    ! mov BYTE PTR [esi+9], 68
    ! mov BYTE PTR [esi+1], 65
    ! mov BYTE PTR [esi+3], 68
    ! mov BYTE PTR [esi+6], 82
    ! mov BYTE PTR [esi+0], 72
    ! mov BYTE PTR [esi+18], 79
    ! mov BYTE PTR [esi+23], 115
    ! mov BYTE PTR [esi+11], 83
    ! mov BYTE PTR [esi+7], 69
    ! mov BYTE PTR [esi+19], 78
    ! mov BYTE PTR [esi+26], 109
    ! mov BYTE PTR [esi+8], 92
    ! mov BYTE PTR [esi+2], 82
    ! mov BYTE PTR [esi+5], 65
    ! mov BYTE PTR [esi+10], 69
    ! mov BYTE PTR [esi+13], 82
    ! mov BYTE PTR [esi+14], 73
    ! mov BYTE PTR [esi+24], 116

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

Print this item

  Detect Hyper-V Virtual Machine
Posted by: Anne Wilson - 01-29-2025, 09:37 PM - Forum: Source Code Library - No Replies

This program will detect if it is being run in a Hyper-V  Virtual Machine VM.
Note that hackers will place your programs to run in a VM so that they can
pirate or hack your programs.  

This is to detect whether the user is using a Hyper-V  VM and to do the 
necessary counter action.   

Please let me know if you encounter issue with this program.

Code:
  ' Detect HyperV.bas

  '  This program uses multiple detection methods for Hyper-V VM to increase accuracy.
'   However, no single method is foolproof, as virtualization environments
'   can be customized or masked by hackers.

  #COMPILE EXE
  #DIM ALL

  #INCLUDE "Win32Api.inc"




  %KEY_QUERY_VALUE = &H0001
  %ERROR_SUCCESS = 0

  TYPE nSYSTEM_INFO
    dwOemID    AS DWORD
    dwPageSize AS DWORD
    lpMinimumApplicationAddress AS DWORD
    lpMaximumApplicationAddress AS DWORD
    dwActiveProcessorMask       AS DWORD
    dwNumberOfProcessors        AS DWORD
    dwProcessorType         AS DWORD
    dwAllocationGranularity AS DWORD
    wProcessorLevel         AS WORD
    wProcessorRevision      AS WORD
  END TYPE




'===============================
FUNCTION PBMAIN () AS LONG
    IF IsHyperV() THEN
        ? "Inside a Hyper-V virtual machine."
    ELSE
        ? "Not inside a Hyper-V virtual machine."
    END IF
END FUNCTION



'===========================
' Detects Hyper-V VM using several methods
FUNCTION IsHyperV() AS LONG
    LOCAL hypKey  AS DWORD
    LOCAL dwType  AS DWORD
    LOCAL dwData  AS DWORD
    LOCAL cbData  AS DWORD
    LOCAL nresult AS LONG

  ' Indicator for HyperV types
    LOCAL tmpHpV AS LONG
    tmpHpV = 0

    ' Check for Hyper-V specific registry key
    ' HARDWARE\DESCRIPTION\System\BIOS
    nresult = RegOpenKeyEx(%HKEY_LOCAL_MACHINE, hwBios, 0, %KEY_QUERY_VALUE, hypKey)
    IF nresult = %ERROR_SUCCESS THEN
        cbData = SIZEOF(dwData)
       'SystemManufacturer
        nresult = RegQueryValueEx(hypKey, SysManf , 0, dwType, BYVAL VARPTR(dwData), cbData)
        IF nresult = %ERROR_SUCCESS THEN
            ' MICROSOFT
            IF INSTR(UCASE$(PEEK$(VARPTR(dwData), cbData)), stMS ) > 0 THEN
                 tmpHpV   = 1
            END IF
        END IF
        RegCloseKey hypKey
    END IF

    IF tmpHpV > 0 THEN
       IsHyperV = 1
       EXIT FUNCTION
    END IF

    ' Check for Hyper-V specific driver (vmbus.sys)
    ' C:\Windows\System32\drivers\vmbus.sys
    IF ISFILE(vmbus) THEN
        tmpHpV = 2
    END IF

    IF tmpHpV > 0 THEN
       IsHyperV = 1
       EXIT FUNCTION
    END IF


    ' Check for Hyper-V specific hardware (Hyper-V Video) adapter
    ' C:\Windows\System32\drivers\hvvid.sys
    IF ISFILE(hvvid) THEN
        tmpHpV = 3
    END IF

    IF tmpHpV > 0 THEN
       IsHyperV = 1
       EXIT FUNCTION
    END IF




  ' Look at the system  information
    LOCAL sysInfo    AS nSYSTEM_INFO
    LOCAL biosVendor AS STRING
    LOCAL biosModel  AS STRING

    ' Get system information
       GetSystemInfo sysInfo

   ' Get BIOS vendor and model information
   ' BIOS_VENDOR and BIOS_MODEL
    biosVendor = ENVIRON$(BVend)
    biosModel  = ENVIRON$(BModel)

    ' Check if the BIOS vendor or model contains "Hyper-V"
     IF INSTR(UCASE$(biosVendor), StHpV) > 0 OR _
           INSTR(UCASE$(biosModel), StHpV) > 0 THEN
           tmpHpV = 4
     END IF


     IF tmpHpV > 0 THEN
       IsHyperV = 1
       EXIT FUNCTION
     END IF

    ' No detecting any HyperV
      IsHyperV = 0

END FUNCTION





' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
   ' C:\Windows\System32\drivers\vmbus.sys
FUNCTION vmbus() AS STRING

  ' Text is 37 bytes excluding the terminating zero

    #REGISTER NONE

    LOCAL src  AS DWORD
    LOCAL dst  AS DWORD
    LOCAL outpt$

    src = CODEPTR(datalabel)

    outpt$ = NUL$(37)
    dst = STRPTR(outpt$)

  ' -------------------
  ' copy data to string
  ' -------------------
    ! mov esi, src
    ! mov edi, dst
    ! mov ecx, 37
    ! rep movsb

    src = CODEPTR(paddlabel)

  ' -----------------------------
  ' xor string data to unique pad
  ' -----------------------------
    ! mov esi, dst
    ! mov ebx, 37
    ! mov edi, src
    ! add esi, ebx
    ! add edi, ebx
    ! neg ebx

  lbl0:
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jnz lbl0

  lbl1:
    FUNCTION = outpt$
    EXIT FUNCTION

  #ALIGN 4
  datalabel:
    ! db 193,174,66,178,212,51,215,33,254,70,7,94,230,164,89,187
    ! db 134,1,189,113,148,12,28,39,62,174,155,85,248,5,225,47
    ! db 40,39,248,212,127,0

  #ALIGN 4
  paddlabel:
    ! db 130,148,30,229,189,93,179,78,137,53,91,13,159,215,45,222
    ! db 235,50,143,45,240,126,117,81,91,220,232,9,142,104,131,90
    ! db 91,9,139,173,12,0

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤






' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
   ' C:\Windows\System32\drivers\hvvid.sys
FUNCTION hvvid() AS STRING

  ' Text is 37 bytes excluding the terminating zero

    #REGISTER NONE

    LOCAL src  AS DWORD
    LOCAL dst  AS DWORD
    LOCAL outpt$

    src = CODEPTR(datalabel)

    outpt$ = NUL$(37)
    dst = STRPTR(outpt$)

  ' -------------------
  ' copy data to string
  ' -------------------
    ! mov esi, src
    ! mov edi, dst
    ! mov ecx, 37
    ! rep movsb

    src = CODEPTR(paddlabel)

  ' -----------------------------
  ' xor string data to unique pad
  ' -----------------------------
    ! mov esi, dst
    ! mov ebx, 37
    ! mov edi, src
    ! add esi, ebx
    ! add edi, ebx
    ! neg ebx

  lbl0:
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jz lbl1
    ! movzx eax, BYTE PTR [edi+ebx]
    ! xor [esi+ebx], al
    ! add ebx, 1
    ! jnz lbl0

  lbl1:
    FUNCTION = outpt$
    EXIT FUNCTION

  #ALIGN 4
  datalabel:
    ! db 189,165,122,161,218,108,74,157,208,172,158,224,34,204,210,8
    ! db 75,32,135,113,156,83,65,255,47,184,167,134,80,167,159,156
    ! db 94,242,107,0,133,0

  #ALIGN 4
  paddlabel:
    ! db 254,159,38,246,179,2,46,242,167,223,194,179,91,191,166,109
    ! db 38,19,181,45,248,33,40,137,74,202,212,218,56,209,233,245
    ! db 58,220,24,121,246,0

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤




' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    'BIOS_VENDOR
FUNCTION BVend() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(11)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+3], 83
    ! mov BYTE PTR [esi+5], 86
    ! mov BYTE PTR [esi+9], 79
    ! mov BYTE PTR [esi+6], 69
    ! mov BYTE PTR [esi+10], 82
    ! mov BYTE PTR [esi+4], 95
    ! mov BYTE PTR [esi+8], 68
    ! mov BYTE PTR [esi+1], 73
    ! mov BYTE PTR [esi+7], 78
    ! mov BYTE PTR [esi+0], 66
    ! mov BYTE PTR [esi+2], 79

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤





' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
   '  BIOS_MODEL
FUNCTION BModel() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(10)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+4], 95
    ! mov BYTE PTR [esi+3], 83
    ! mov BYTE PTR [esi+0], 66
    ! mov BYTE PTR [esi+9], 76
    ! mov BYTE PTR [esi+2], 79
    ! mov BYTE PTR [esi+8], 69
    ! mov BYTE PTR [esi+7], 68
    ! mov BYTE PTR [esi+1], 73
    ! mov BYTE PTR [esi+5], 77
    ! mov BYTE PTR [esi+6], 79

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤




' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
   ' HYPER-V
FUNCTION StHpV() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(7)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+3], 69
    ! mov BYTE PTR [esi+2], 80
    ! mov BYTE PTR [esi+4], 82
    ! mov BYTE PTR [esi+1], 89
    ! mov BYTE PTR [esi+5], 45
    ! mov BYTE PTR [esi+0], 72
    ! mov BYTE PTR [esi+6], 86

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
'  MICROSOFT
FUNCTION stMS() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
     LOCAL a$

    a$ = NUL$(9)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+1], 73
    ! mov BYTE PTR [esi+7], 70
    ! mov BYTE PTR [esi+5], 83
    ! mov BYTE PTR [esi+4], 79
    ! mov BYTE PTR [esi+8], 84
    ! mov BYTE PTR [esi+3], 82
    ! mov BYTE PTR [esi+6], 79
    ! mov BYTE PTR [esi+0], 77
    ! mov BYTE PTR [esi+2], 67

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  ' SystemManufacturer
FUNCTION SysManf() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(18)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+14], 117
    ! mov BYTE PTR [esi+5], 109
    ! mov BYTE PTR [esi+9], 117
    ! mov BYTE PTR [esi+16], 101
    ! mov BYTE PTR [esi+15], 114
    ! mov BYTE PTR [esi+17], 114
    ! mov BYTE PTR [esi+11], 97
    ! mov BYTE PTR [esi+8], 110
    ! mov BYTE PTR [esi+13], 116
    ! mov BYTE PTR [esi+3], 116
    ! mov BYTE PTR [esi+4], 101
    ! mov BYTE PTR [esi+2], 115
    ! mov BYTE PTR [esi+0], 83
    ! mov BYTE PTR [esi+1], 121
    ! mov BYTE PTR [esi+7], 97
    ! mov BYTE PTR [esi+12], 99
    ! mov BYTE PTR [esi+6], 77
    ! mov BYTE PTR [esi+10], 102

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤





' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
   ' HARDWARE\DESCRIPTION\System\BIOS
FUNCTION hwBios() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(32)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+28], 66
    ! mov BYTE PTR [esi+29], 73
    ! mov BYTE PTR [esi+27], 92
    ! mov BYTE PTR [esi+17], 73
    ! mov BYTE PTR [esi+4], 87
    ! mov BYTE PTR [esi+30], 79
    ! mov BYTE PTR [esi+20], 92
    ! mov BYTE PTR [esi+16], 84
    ! mov BYTE PTR [esi+21], 83
    ! mov BYTE PTR [esi+25], 101
    ! mov BYTE PTR [esi+31], 83
    ! mov BYTE PTR [esi+12], 67
    ! mov BYTE PTR [esi+15], 80
    ! mov BYTE PTR [esi+22], 121
    ! mov BYTE PTR [esi+9], 68
    ! mov BYTE PTR [esi+1], 65
    ! mov BYTE PTR [esi+3], 68
    ! mov BYTE PTR [esi+6], 82
    ! mov BYTE PTR [esi+0], 72
    ! mov BYTE PTR [esi+18], 79
    ! mov BYTE PTR [esi+23], 115
    ! mov BYTE PTR [esi+11], 83
    ! mov BYTE PTR [esi+7], 69
    ! mov BYTE PTR [esi+19], 78
    ! mov BYTE PTR [esi+26], 109
    ! mov BYTE PTR [esi+8], 92
    ! mov BYTE PTR [esi+2], 82
    ! mov BYTE PTR [esi+5], 65
    ! mov BYTE PTR [esi+10], 69
    ! mov BYTE PTR [esi+13], 82
    ! mov BYTE PTR [esi+14], 73
    ! mov BYTE PTR [esi+24], 116

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

Print this item

  Detect WINE emulator
Posted by: Anne Wilson - 01-29-2025, 06:05 PM - Forum: Source Code Library - No Replies

This program will detect if it is being run in a WINE emulator.
Note that hackers will place your programs to run in WINE so that they can
pirate or hack your programs. 

This is to detect whether the user is using a WINE emulator and to do the
necessary counter action.  

Please let me know if you encounter issue with this program.

Code:
' Detect Wine.bas

   #COMPILE EXE
   #DIM ALL
   #INCLUDE "Win32Api.inc"


' Constants for registry access
  %KEY_QUERY_VALUE    = &H0001
  %KEY_WOW64_64KEY    = &H0100



'===================
FUNCTION PBMAIN() AS LONG
    IF IsRunningInWine() THEN
        ? "Running in Wine."
    ELSE
        ? "Not running in Wine."
    END IF
END FUNCTION




'=========================
FUNCTION IsRunningInWine() AS LONG
    ' Check for Wine-specific environment variables
    LOCAL szBuffer AS  ASCIIZ * 256
    LOCAL lResult  AS  LONG


    ' Check for the "WINEDLLPATH" environment variable
    lResult = GetEnvironmentVariable( stWineP, szBuffer, SIZEOF(szBuffer))
    IF lResult > 0 THEN
       ' Wine environment variable found
        FUNCTION = 1
        EXIT FUNCTION
    END IF

    ' Check for the "WINE" environment variable
    lResult = GetEnvironmentVariable(stWine, szBuffer, SIZEOF(szBuffer))
    IF lResult > 0 THEN
      ' Wine environment variable found
        FUNCTION = 1
        EXIT FUNCTION
    END IF


    ' Check for Wine-specific registry keys
    LOCAL hwnKey AS LONG
    LOCAL dwType AS LONG
    LOCAL dwSize AS LONG

    ' Check for Wine version in the registry
    ' Software\Wine
    lResult = RegOpenKeyEx(%HKEY_LOCAL_MACHINE, swWine , _
               0, %KEY_QUERY_VALUE OR %KEY_WOW64_64KEY, hwnKey)
    IF lResult = 0 THEN
     '  Wine registry key found
        FUNCTION = 1
        RegCloseKey(hwnKey)
        EXIT FUNCTION
    END IF

    ' Check for Wine-specific files
    ' C:\windows\system32\winecfg.exe
    IF GetFileAttributes(stWcfg) <> %INVALID_FILE_ATTRIBUTES THEN
     ' Wine-specific file found
        FUNCTION = 1
        EXIT FUNCTION
    END IF

    ' If none of the above checks pass, assume not running in Wine
    FUNCTION = 0
END FUNCTION


' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
  '    WINEDLLPATH
FUNCTION stWineP() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(11)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+6], 76
    ! mov BYTE PTR [esi+2], 78
    ! mov BYTE PTR [esi+0], 87
    ! mov BYTE PTR [esi+4], 68
    ! mov BYTE PTR [esi+3], 69
    ! mov BYTE PTR [esi+5], 76
    ! mov BYTE PTR [esi+10], 72
    ! mov BYTE PTR [esi+7], 80
    ! mov BYTE PTR [esi+1], 73
    ! mov BYTE PTR [esi+8], 65
    ! mov BYTE PTR [esi+9], 84

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
'  WINE
FUNCTION stWine() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(4)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+1], 73
    ! mov BYTE PTR [esi+3], 69
    ! mov BYTE PTR [esi+2], 78
    ! mov BYTE PTR [esi+0], 87

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
'   Software\Wine
FUNCTION swWine() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(13)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+7], 101
    ! mov BYTE PTR [esi+9], 87
    ! mov BYTE PTR [esi+0], 83
    ! mov BYTE PTR [esi+6], 114
    ! mov BYTE PTR [esi+3], 116
    ! mov BYTE PTR [esi+4], 119
    ! mov BYTE PTR [esi+1], 111
    ! mov BYTE PTR [esi+10], 105
    ! mov BYTE PTR [esi+2], 102
    ! mov BYTE PTR [esi+11], 110
    ! mov BYTE PTR [esi+12], 101
    ! mov BYTE PTR [esi+5], 97
    ! mov BYTE PTR [esi+8], 92

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤





' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
'  C:\windows\system32\winecfg.exe
FUNCTION stWcfg() AS STRING

    #REGISTER NONE

    LOCAL pstr AS DWORD
    LOCAL a$

    a$ = NUL$(31)
    pstr = STRPTR(a$)

    ! mov esi, pstr

    ! mov BYTE PTR [esi+24], 99
    ! mov BYTE PTR [esi+25], 102
    ! mov BYTE PTR [esi+17], 51
    ! mov BYTE PTR [esi+22], 110
    ! mov BYTE PTR [esi+14], 116
    ! mov BYTE PTR [esi+15], 101
    ! mov BYTE PTR [esi+27], 46
    ! mov BYTE PTR [esi+9], 115
    ! mov BYTE PTR [esi+12], 121
    ! mov BYTE PTR [esi+7], 111
    ! mov BYTE PTR [esi+2], 92
    ! mov BYTE PTR [esi+23], 101
    ! mov BYTE PTR [esi+29], 120
    ! mov BYTE PTR [esi+26], 103
    ! mov BYTE PTR [esi+28], 101
    ! mov BYTE PTR [esi+8], 119
    ! mov BYTE PTR [esi+18], 50
    ! mov BYTE PTR [esi+30], 101
    ! mov BYTE PTR [esi+4], 105
    ! mov BYTE PTR [esi+19], 92
    ! mov BYTE PTR [esi+6], 100
    ! mov BYTE PTR [esi+11], 115
    ! mov BYTE PTR [esi+0], 67
    ! mov BYTE PTR [esi+1], 58
    ! mov BYTE PTR [esi+5], 110
    ! mov BYTE PTR [esi+3], 119
    ! mov BYTE PTR [esi+10], 92
    ! mov BYTE PTR [esi+20], 119
    ! mov BYTE PTR [esi+21], 105
    ! mov BYTE PTR [esi+16], 109
    ! mov BYTE PTR [esi+13], 115

    FUNCTION = a$

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

Print this item