Author Topic: Targetting your application four windows getVersionEx  (Read 5290 times)

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: Targetting your application four windows getVersionEx
« Reply #15 on: November 01, 2015, 04:43:24 AM »
:biggrin:
Find the soluce
In the sample upper , i have added a proc in asm called by the winmain.
Code: [Select]
// targetting.cpp : définit le point d'entrée pour l'application.
//
#include "stdafx.h"
#include "targetting.h"
#pragma comment (lib,"H://sdkrc81/crt_lib/IX86/release/crt10_32")

// Variables globales :
HINSTANCE hInst;                                // instance actuelle
CHAR szversion[100];
// __cdecl, __thiscall, __fastcall and the wonderfully named __naked. __stdcall

// Pré-déclarations des fonctions incluses dans ce module de code :
int  Version (POSVERSIONINFOA  pversion);
int  StartJwasmProc(_In_ HINSTANCE hInstance,_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR    lpCmdLine,
_In_ int       nCmdShow);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);
//OSVERSIONINFOEX * pointeur;
StartJwasmProc(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
   return 0;
}

The called asm must be a syscall proto
Code: [Select]
include sdk32.inc
include conio.sdk
include stdio.sdk
include stdlib.sdk

?StartJwasmProc@@YAHPAUHINSTANCE__@@0PA_WH@Z PROTO syscall hInstance:HINSTANCE ,hPrevInstance:HINSTANCE,\
lpCmdLine:LPWSTR,nCmdShow:DWORD
;includelib msvcrt.lib
includelib H:\sdkrc81\crt_lib\IX86\release\crt10_32.lib ;needed only windows 10
;InitInstance PROTO :DWORD
.const
;EXTERNDEF sprintf_s
TXT MACRO quoted_text:VARARG
local etiquette
.data
etiquette db quoted_text,0
.code
EXITM<addr etiquette>
ENDM
.data
osversion OSVERSIONINFOEX <>
chaine db 200 dup(0)
.code
;StartJwasmProc(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
?StartJwasmProc@@YAHPAUHINSTANCE__@@0PA_WH@Z proc syscall  hInstance:HINSTANCE ,hPrevInstance:HINSTANCE,\
lpCmdLine:LPWSTR,nCmdShow:DWORD

lea edx,osversion
      mov [edx].OSVERSIONINFOEX.dwOSVersionInfoSize,sizeof OSVERSIONINFOEX ;156
invoke GetVersionEx,edx ;OSVERSIONINFOEX <>
invoke sprintf_s,addr chaine,sizeof chaine,TXT("Windows version %d.%d",13,10,\
"Windows prouctype %d",13,10," Platformid %d"),osversion.dwMajorVersion,osversion.dwMinorVersion,osversion.wProductType,osversion.dwPlatformId
invoke MessageBox,NULL,addr chaine,TXT("JWASM"),MB_OK
mov eax,0
ret
?StartJwasmProc@@YAHPAUHINSTANCE__@@0PA_WH@Z endp
end

and now you have here the first asm proc able to return the correct value with GetversionEx.
The method give at the asm prog the same properties as the c++ proc.
Fa is a musical note to play with CL

TWell

  • Member
  • ****
  • Posts: 748
Re: Targetting your application four windows getVersionEx
« Reply #16 on: November 01, 2015, 06:13:24 AM »
Manifest do the trick, look here
Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
  <application>
     <!-- Application supports Windows 10 -->
     <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
     <!-- Application supports Windows 8.1 -->
     <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
     <!-- Application supports Windows 8 -->
     <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
     <!-- Application supports Windows 7 -->
     <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
     <!-- Application supports Windows Vista -->
     <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
  </application>
</compatibility>

</assembly>
Code: [Select]
    .386
    .model flat, stdcall
    option casemap:none

ExitProcess proto stdcall :dword
GetVersionExA proto stdcall :dword
includelib kernel32.lib

printf proto cdecl :vararg
_getch proto cdecl
includelib msvcrt.lib

OSVERSIONINFOEXA struct
  dwOSVersionInfoSize dd ?
  dwMajorVersion dd ?
  dwMinorVersion dd ?
  dwBuildNumber dd ?
  dwPlatformId dd ?
  szCSDVersion db 128 dup (?)
  wServicePackMajor dw ?
  wServicePackMinor dw ?
  wSuiteMask dw ?
  wProductType db ?
  wReserved db ?
OSVERSIONINFOEXA ends

.data
osviex OSVERSIONINFOEXA <sizeof OSVERSIONINFOEXA>
sMsg db "Version %u.%u",13,10,0
sEnd db "Press any key to continue...",13,10,0

.code
mainCRTStartup proc c
    invoke GetVersionExA, offset osviex
    invoke printf, offset sMsg, osviex.dwMajorVersion, osviex.dwMinorVersion
    invoke printf, offset sEnd
    invoke _getch
    invoke ExitProcess, 0
mainCRTStartup endp
end mainCRTStartup

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: Targetting your application four windows getVersionEx
« Reply #17 on: November 01, 2015, 07:12:14 AM »
I know all the trick on the subject that i have already posted.
They don't work with asm Under WINDOWS 10.
If you have a full application who can be tested,post it here.
Fa is a musical note to play with CL

TWell

  • Member
  • ****
  • Posts: 748
Re: Targetting your application four windows getVersionEx
« Reply #18 on: November 01, 2015, 07:21:32 AM »
Sure

qWord

  • Member
  • *****
  • Posts: 1454
  • The base type of a type is the type itself
    • SmplMath macros
Re: Targetting your application four windows getVersionEx
« Reply #19 on: November 01, 2015, 08:12:10 AM »
?StartJwasmProc@@YAHPAUHINSTANCE__@@0PA_WH@Z proc syscall  ...
man's work - extern "C" would be too simple ;)
MREAL macros - when you need floating point arithmetic while assembling!

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: Targetting your application four windows getVersionEx
« Reply #20 on: November 01, 2015, 07:18:55 PM »
Ok,the extern "C" made the name more simple.
For the manifest he had no effect in a Windows prog  in Windows 10.
Your prog is a dos (not Windows) and not compiled in Windows 10.
In this case,it is more simple to solve.

The _getch function in used need a special lib,it is INLINE in Windows 10,it's at that I see you haven't compile it Under Windows 10.
The c++ (/WX-) made the job instead of the manifest

I search a way to put the wWinMain proc in a lib who works as the msvcrt.lib,that is just include the lib with no declaration of the entry point ?
any idea ?


Fa is a musical note to play with CL

TWell

  • Member
  • ****
  • Posts: 748
Re: Targetting your application four windows getVersionEx
« Reply #21 on: November 01, 2015, 08:27:45 PM »
For the manifest he had no effect in a Windows prog  in Windows 10.
Your prog is a dos (not Windows) and not compiled in Windows 10.

The _getch function in used need a special lib,it is INLINE in Windows 10,it's at that I see you haven't compile it Under Windows 10.
My example is compiled and tested under Windows 10.
My msvcrt.dll is version 7.10....
and _getch() is there.
i create msvcrt.lib from msvcrt.def like this
Code: [Select]
LIBRARY msvcrt.dll
EXPORTS
printf
scanf
wprintf
_getch
Please use PEView.exe to examine that program.

I don't mess with Visual Studio 2015.

jj2007

  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: Targetting your application four windows getVersionEx
« Reply #22 on: November 01, 2015, 08:52:37 PM »
I know all the trick on the subject that i have already posted.
They don't work with asm Under WINDOWS 10.
If you have a full application who can be tested,post it here.

RtlGetNtVersionNumbers returns hardcoded version numbers.

The issue here is whether you really want to know the OS version, then RtlGetNtVersionNumbers is the way to go, or whether you want to tell your app "you are running in xyz, believe it or not". The other options rely on the TIB, and Windows will set it based on compatibility modes.

RtlGetNtVersionNumbers returns hardcoded version numbers.

The issue here is whether you really want to know the OS version, then RtlGetNtVersionNumbers is the way to go, or whether you want to tell your app "you are running in xyz, believe it or not". The other options rely on the TIB, and Windows will set it based on compatibility modes.

RtlGetNtVersionNumbers returns hardcoded version numbers.

The issue here is whether you really want to know the OS version, then RtlGetNtVersionNumbers is the way to go, or whether you want to tell your app "you are running in xyz, believe it or not". The other options rely on the TIB, and Windows will set it based on compatibility modes.

RtlGetNtVersionNumbers returns hardcoded version numbers.

The issue here is whether you really want to know the OS version, then RtlGetNtVersionNumbers is the way to go, or whether you want to tell your app "you are running in xyz, believe it or not". The other options rely on the TIB, and Windows will set it based on compatibility modes.


(I know it's difficult to understand, so I repeated it a few times 8))

Output for Win7-64, no compatibility mode:
RtlGetVersion   6.1 SP 1.0 build 7601
Suite mask      0300: SINGLEUSERTS PERSONAL
ProductType     WORKSTATION
CSDVersion      Service Pack 1

RtlGetNtVersionNumbers (same for all 'compatibility modes'):
major   6
minor   1
build   7601


Output for Win7-64 but compatibility mode 'server 2008':
RtlGetVersion   6.0 SP 1.0 build 6001
Suite mask      0300: SINGLEUSERTS PERSONAL
ProductType     WORKSTATION
CSDVersion      Service Pack 1

RtlGetNtVersionNumbers:
major   6
minor   1
build   7601

Output for Win7-64 but compatibility mode 'Vista SP2':
RtlGetVersion   6.0 SP 2.0 build 6002
Suite mask      0300: SINGLEUSERTS PERSONAL
ProductType     WORKSTATION
CSDVersion      Service Pack 2

RtlGetNtVersionNumbers:
major   6
minor   1
build   7601

Output for Win7-64 but compatibility mode 'Vista':
RtlGetVersion   6.0 SP 0.0 build 6000

Output for Win7-64 but compatibility mode 'Windows 7':
RtlGetVersion   6.1 SP 0.0 build 7600

TWell

  • Member
  • ****
  • Posts: 748
Re: Targetting your application four windows getVersionEx
« Reply #23 on: November 01, 2015, 10:32:09 PM »
GetVersionPEB example don't follow compatibility mode?

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: Targetting your application four windows getVersionEx
« Reply #24 on: November 02, 2015, 12:49:54 AM »
For your re-posted sample it is always in dos mode.


Did you know what is a Windows program?????



I repeat the problem.
The problem is to have the same results using the c++ or masm in Windows mode.
Fa is a musical note to play with CL

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: Targetting your application four windows getVersionEx
« Reply #25 on: November 02, 2015, 01:23:01 AM »

Miss an answer:
Where can be found the printf function in Windows 10 ?????
here:
Quote
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h

_Check_return_opt_
_CRT_STDIO_INLINE int __CRTDECL printf(
    _In_z_ _Printf_format_string_ char const* const _Format,
    ...)
#if defined _NO_CRT_STDIO_INLINE
;
#else
{
    int _Result;
    va_list _ArgList;
    __crt_va_start(_ArgList, _Format);
    _Result = _vfprintf_l(stdout, _Format, NULL, _ArgList);
    __crt_va_end(_ArgList);
    return _Result;
}
#endif

I am agree  to pay for an asm compiler able to compile INLINE functions written in c++



Fa is a musical note to play with CL

TWell

  • Member
  • ****
  • Posts: 748
Re: Targetting your application four windows getVersionEx
« Reply #26 on: November 02, 2015, 01:43:49 AM »
For your re-posted sample it is always in dos mode.
Did you know what is a Windows program?????
????????????  ::)
Do you you mean console-mode?

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: Targetting your application four windows getVersionEx
« Reply #27 on: November 02, 2015, 02:48:27 AM »
That looks better,but:
You use the poasm tools who import is own libraries.
I use only the sdk libraries.
It isn't the same things.
Fa is a musical note to play with CL

Vortex

  • Member
  • *****
  • Posts: 1704
Re: Targetting your application four windows getVersionEx
« Reply #28 on: November 02, 2015, 03:15:24 AM »
Hi ToutEnMasm,

Concerning the symbol decoration problem, you can use Agner Fog's objconv tool to rename the symbols :

http://agner.org/optimize/

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: Targetting your application four windows getVersionEx
« Reply #29 on: November 02, 2015, 03:30:45 AM »
Thanks,
Perhaps Someone have the answer to Library question.
I had try to put the start proc in C++ in a Library,the c++ proc is  given as the entry point.
This work with a c source file (the Library work as the msvcrt.lib),WinMain entry point.
                 But,there is no effect on getversionex who failed.
The same proc in a .cpp accept to build a lib,he accept only wWinMain or WinMainCRTStartup as name.
Then when included lib,the start don't work with msvcrt.lib.There is only the /ENTRY option who work but had not the same effect.
Any experiment in this ?


Fa is a musical note to play with CL