Targetting your application four windows getVersionEx

Started by TouEnMasm, October 30, 2015, 07:22:58 PM

Previous topic - Next topic

TouEnMasm

:biggrin:
Find the soluce
In the sample upper , i have added a proc in asm called by the winmain.

// 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

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

Manifest do the trick, look here<?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>
    .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

TouEnMasm

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


qWord

Quote from: ToutEnMasm on November 01, 2015, 04:43:24 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!

TouEnMasm

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

Quote from: ToutEnMasm on November 01, 2015, 07:18:55 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 thisLIBRARY msvcrt.dll
EXPORTS
printf
scanf
wprintf
_getch

Please use PEView.exe to examine that program.

I don't mess with Visual Studio 2015.

jj2007

Quote from: ToutEnMasm 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.

Quote from: jj2007 on October 06, 2015, 03:45:38 AMRtlGetNtVersionNumbers 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

GetVersionPEB example don't follow compatibility mode?

TouEnMasm

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

TouEnMasm


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

Quote from: ToutEnMasm 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?????
????????????  ::)
Do you you mean console-mode?

TouEnMasm

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

Hi ToutEnMasm,

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

http://agner.org/optimize/

TouEnMasm

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