News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Recent posts

#1
Pelle's C compiler and tools / Enumerating users
Last post by Vortex - October 13, 2024, 08:37:20 PM
Enumerating local and remote users, example code by MS :

// https://learn.microsoft.com/en-us/windows/win32/api/lmaccess/nf-lmaccess-netuserenum

#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")

#include <stdio.h>
#include <assert.h>
#include <windows.h>
#include <wchar.h>
#include <lm.h>

int wmain(int argc, wchar_t *argv[])
{
   LPUSER_INFO_0 pBuf = NULL;
   LPUSER_INFO_0 pTmpBuf;
   DWORD dwLevel = 0;
   DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
   DWORD dwEntriesRead = 0;
   DWORD dwTotalEntries = 0;
   DWORD dwResumeHandle = 0;
   DWORD i;
   DWORD dwTotalCount = 0;
   NET_API_STATUS nStatus;
   LPTSTR pszServerName = NULL;

   if (argc > 2)
   {
      fwprintf(stderr, L"Usage: %ls [\\\\ServerName]\n", argv[0]);
      exit(1);
   }
   // The server is not the default local computer.
   //
   if (argc == 2)
      pszServerName =  (LPTSTR) argv[1];
   wprintf(L"\nUser account on %ls: \n", pszServerName);
   //
   // Call the NetUserEnum function, specifying level 0;
   //   enumerate global user account types only.
   //
   do // begin do
   {
      nStatus = NetUserEnum((LPCWSTR) pszServerName,
                            dwLevel,
                            FILTER_NORMAL_ACCOUNT, // global users
                            (LPBYTE*)&pBuf,
                            dwPrefMaxLen,
                            &dwEntriesRead,
                            &dwTotalEntries,
                            &dwResumeHandle);
      //
      // If the call succeeds,
      //
      if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
      {
         if ((pTmpBuf = pBuf) != NULL)
         {
            //
            // Loop through the entries.
            //
            for (i = 0; (i < dwEntriesRead); i++)
            {
               assert(pTmpBuf != NULL);

               if (pTmpBuf == NULL)
               {
                  fprintf(stderr, "An access violation has occurred\n");
                  break;
               }
               //
               //  Print the name of the user account.
               //
               wprintf(L"\t-- %ls\n", pTmpBuf->usri0_name);

               pTmpBuf++;
               dwTotalCount++;
            }
         }
      }
      //
      // Otherwise, print the system error.
      //
      else
         fprintf(stderr, "A system error has occurred: %d\n", nStatus);
      //
      // Free the allocated buffer.
      //
      if (pBuf != NULL)
      {
         NetApiBufferFree(pBuf);
         pBuf = NULL;
      }
   }
   // Continue to call NetUserEnum while
   //  there are more entries.
   //
   while (nStatus == ERROR_MORE_DATA); // end do
   //
   // Check again for allocated memory.
   //
   if (pBuf != NULL)
      NetApiBufferFree(pBuf);
   //
   // Print the final count of users enumerated.
   //
   fprintf(stderr, "\nTotal of %d entries enumerated\n", dwTotalCount);

   return 0;
}
#2
Poasm / Re: Run-Time Dynamic Linking E...
Last post by sinsi - October 13, 2024, 04:11:04 AM
KERNEL32 uses it all the time, e.g.
GetProcessHeap:
    mov  eax,[fs:30h]
    mov  eax,[eax+18h]
    ret
#3
Poasm / Re: Run-Time Dynamic Linking E...
Last post by Vortex - October 13, 2024, 03:47:37 AM
Hi NoCforMe,

QuoteSo what, exactly, are we supposed to learn from this?

The utility of the Process Environment Block :

PEB STRUCT                                                    ; sizeof = 0210h
    InheritedAddressSpace               BYTE         ?        ; 0000h
    ReadImageFileExecOptions            BYTE         ?        ; 0001h
    BeingDebugged                       BYTE         ?        ; 0002h
    SpareBool                           BYTE         ?        ; 0003h
    Mutant                              DWORD        ?        ; 0004h
    ImageBaseAddress                    DWORD        ?        ; 0008h
    Ldr                                 DWORD        ?        ; 000Ch PTR PEB_LDR_DATA
    ProcessParameters                   DWORD        ?        ; 0010h PTR RTL_USER_PROCESS_PARAMETERS
    SubSystemData                       DWORD        ?        ; 0014h
    ProcessHeap                         DWORD        ?        ; 0018h
    FastPebLock                         DWORD        ?        ; 001Ch PTR RTL_CRITICAL_SECTION
    FastPebLockRoutine                  DWORD        ?        ; 0020h
    FastPebUnlockRoutine                DWORD        ?        ; 0024h
    EnvironmentUpdateCount              DWORD        ?        ; 0028h
    KernelCallbackTable                 DWORD        ?        ; 002Ch
    SystemReserved                      DWORD    1 dup(?)     ; 0030h
    PebBits                             PEB_BITS    <>        ; 0034h named by Four-F
    FreeList                            DWORD        ?        ; 0038h PTR PEB_FREE_BLOCK
    TlsExpansionCounter                 DWORD        ?        ; 003Ch
    TlsBitmap                           DWORD        ?        ; 0040h
    TlsBitmapBits                       DWORD    2 dup(?)     ; 0044h
    ReadOnlySharedMemoryBase            DWORD        ?        ; 004Ch
    ReadOnlySharedMemoryHeap            DWORD        ?        ; 0050h
    ReadOnlyStaticServerData            DWORD        ?        ; 0054h
    AnsiCodePageData                    DWORD        ?        ; 0058h
    OemCodePageData                     DWORD        ?        ; 005Ch
    UnicodeCaseTableData                DWORD        ?        ; 0060h
    NumberOfProcessors                  DWORD        ?        ; 0064h
    NtGlobalFlag                        DWORD        ?        ; 0068h
                                        DWORD        ?        ; 0064h padding
    CriticalSectionTimeout              LARGE_INTEGER <>      ; 0070h
    HeapSegmentReserve                  DWORD        ?        ; 0078h
    HeapSegmentCommit                   DWORD        ?        ; 007Ch
    HeapDeCommitTotalFreeThreshold      DWORD        ?        ; 0080h
    HeapDeCommitFreeBlockThreshold      DWORD        ?        ; 0084h
    NumberOfHeaps                       DWORD        ?        ; 0088h
    MaximumNumberOfHeaps                DWORD        ?        ; 008Ch
    ProcessHeaps                        DWORD        ?        ; 0090h
    GdiSharedHandleTable                DWORD        ?        ; 0094h
    ProcessStarterHelper                DWORD        ?        ; 0098h
    GdiDCAttributeList                  DWORD        ?        ; 009Ch
    LoaderLock                          DWORD        ?        ; 00A0h
    OSMajorVersion                      DWORD        ?        ; 00A4h
    OSMinorVersion                      DWORD        ?        ; 00A8h
    OSBuildNumber                       WORD         ?        ; 00ACh
    OSCSDVersion                        WORD         ?        ; 00AEh
    OSPlatformId                        DWORD        ?        ; 00B0h
    ImageSubsystem                      DWORD        ?        ; 00B4h
    ImageSubsystemMajorVersion          DWORD        ?        ; 00B8h
    ImageSubsystemMinorVersion          DWORD        ?        ; 00BCh
    ImageProcessAffinityMask            DWORD        ?        ; 00C0h
    GdiHandleBuffer                     DWORD       34 dup(?) ; 00C4h
    PostProcessInitRoutine              DWORD        ?        ; 014Ch
    TlsExpansionBitmap                  DWORD        ?        ; 0150h
    TlsExpansionBitmapBits              DWORD       32 dup(?) ; 0154h
    SessionId                           DWORD        ?        ; 01D4h
    AppCompatFlags                      LARGE_INTEGER <>      ; 01D8h
    AppCompatFlagsUser                  LARGE_INTEGER <>      ; 01E0h
    pShimData                           DWORD        ?        ; 01E8h
    AppCompatInfo                       DWORD        ?        ; 01ECh
    CSDVersion                          UNICODE_STRING <>     ; 01F0h
    ActivationContextData               DWORD        ?        ; 01F8h
    ProcessAssemblyStorageMap           DWORD        ?        ; 01FCh
    SystemDefaultActivationContextData  DWORD        ?        ; 0200h
    SystemAssemblyStorageMap            DWORD        ?        ; 0204h
    MinimumStackCommit                  DWORD        ?        ; 0208h
                                        DWORD        ?        ; 020Ch padding
PEB ENDS

These fields are providing valuable information :

    OSMajorVersion                      DWORD        ?
    OSMinorVersion                      DWORD        ?
    OSBuildNumber                       WORD         ?
#4
Game Development / Pacman source code
Last post by zedd151 - October 13, 2024, 01:56:34 AM
The original "Pacman" (Atari version) source code on github.  :biggrin:
Pacman-Source-Code

Now to attempt porting it to Masm assembly.  :greensml:  But not me.  :tongue:

Quote from: taken from the linked github pagePacman-Source-Code
The Source Code to the original Atari Pacman game!

The history of Pac-Man encompasses its origins as an innovative arcade game, its widespread popularity and impact on popular culture, the expansion into home console ports and merchandise, and its enduring legacy as an iconic and beloved video game.

Development (1979): Pac-Man was created by Toru Iwatani, a Japanese game designer working at Namco. Inspired by the concept of eating and the image of a pizza with a slice missing, Iwatani aimed to create a game that would appeal to a broader audience beyond the traditional male demographic of arcade games at the time.

Release (1980): Pac-Man was officially released in arcades in May 1980. The game introduced a novel concept where players controlled a round, yellow character named Pac-Man, navigating mazes filled with dots, power pellets, and four ghosts - Blinky, Pinky, Inky, and Clyde. The objective was to eat all the dots while avoiding the ghosts.

Popularity and Impact: Pac-Man quickly became a cultural phenomenon, captivating players around the world. Its simple yet addictive gameplay, colorful graphics, and catchy music contributed to its immense popularity. Pac-Man's universal appeal attracted both male and female players, broadening the demographic reach of video games.

Pac-Man Fever: The game's popularity extended beyond arcades and into popular culture. In 1981, a hit single called "Pac-Man Fever" by Buckner & Garcia was released. The song featured lyrics inspired by the game and became a chart-topping hit, solidifying Pac-Man's status as a cultural icon.

Home Console Ports: Pac-Man's success led to numerous ports for home gaming consoles and computers. The Atari 2600 version, released in 1982, became one of the best-selling games for the console. Other popular ports included versions for the Atari 5200, Commodore 64, and the Nintendo Entertainment System (NES), among others.

Spin-offs and Sequels: The popularity of Pac-Man spawned a variety of spin-offs and sequels. Ms. Pac-Man, released in 1982, became one of the most successful arcade games of all time. Other notable sequels and spin-offs included Super Pac-Man, Pac-Man Plus, Pac-Mania, Pac-Land, and Pac-Man Championship Edition. These games introduced new gameplay mechanics, mazes, and power-ups, expanding upon the original concept.

Merchandising: Pac-Man's popularity translated into a wide range of merchandise. The game's iconic characters and imagery appeared on toys, clothing, board games, lunch boxes, and more. Pac-Man-themed animated television shows, such as "Pac-Man: The Animated Series" (1982-1983), further popularized the character and his adventures.

Legacy: Pac-Man's legacy is undeniable. It remains one of the most influential video games of all time, defining the maze chase genre and inspiring countless game developers. The character of Pac-Man is instantly recognizable, and the game's distinctive "waka-waka" sound effect has become synonymous with gaming. Pac-Man has been included in numerous video game compilations, anniversary releases, and reimagined versions for modern gaming platforms, ensuring its enduring presence in the gaming industry.

I used to really love playing pacman, I had wasted away countless hours ( possibly days, weeks) playing that highly addictive game.  :biggrin:



#5
Examples / Re: Dialog As Main
Last post by ognil - October 12, 2024, 12:20:42 PM
Thank you Vortex, :thumbsup:

Same but not as complicated and 1K shorter:

include     Dialog64.inc

.code

start           proc 
                xor     ecx, ecx
                call    GetModuleHandle             ; invoke  GetModuleHandle,NULL
                lea     rcx, DialogBoxParam
                xor     r8d, r8d
                xchg    rcx, rax
                lea     r9,  DlgProc      
                mov     [rsp+4*8],r8
                lea     rdx, Resource
                call    qword ptr [rax]             ; invoke  DialogBoxParam,rcx,ADDR Resource,NULL,ADDR DlgProc,NULL
start           endp

DlgProc         proc
                cmp     rdx,WM_CTLCOLORDLG
                jne     Is_WM_CLOSE
                mov     ecx, 0FF0000h
                call    CreateSolidBrush            ; invoke  CreateSolidBrush,Blue=0FF0000hh
                mov     hBrush,rax
                ret
Is_WM_CLOSE:
                cmp     rdx,WM_CLOSE
                je      @Ret
Is_WM_COMMAND:
                cmp     rdx, WM_COMMAND
                jne     @Exit
                test    r9, r9
                jne     @Is_BN_CLICKED
               
                cmp     r8w, IDM_EXIT
                je      @Ret
                cmp     r8w, IDM_ABOUT
                jne     @Exit
                mov     r9d, MB_OK
                lea     r8,  title1
                lea     rdx, msg
                xor     ecx, ecx
                call    MessageBox                  ; invoke  MessageBox,NULL,ADDR msg,ADDR title1,MB_OK
                jmp     @Exit
@Is_BN_CLICKED:
                mov     rax, r8
                shr     rax, 16
                cmp     ax, BN_CLICKED
                jne     @Exit
                cmp     r8w, IDC_EXIT
                je      @Ret
                cmp     r8w, IDC_ABOUT
                jne     @Exit
                xor     r9d,r9d
                mov     r8d, IDM_ABOUT
                mov     edx, WM_COMMAND
                call    SendMessage                 ; invoke  SendMessage,hWnd,WM_COMMAND,IDM_ABOUT,0
                jmp     @Exit
@Ret:   
                xor     ecx, ecx
                call    ExitProcess                 ; invoke  ExitProcess,rcx
@Exit:       
                xor     eax, eax
                ret
DlgProc         endp

END

#6
Examples / Re: Dialog As Main
Last post by NoCforMe - October 12, 2024, 08:32:08 AM
Good. I was going to suggest that you at least minimally populate the dialog with something, which I see you've done, so that n00bs will get the idea.

Dialogs are kewl.
#7
Examples / Re: Dialog As Main
Last post by Vortex - October 12, 2024, 07:46:55 AM
Here is another dialog box with menu.
#8
ObjAsm / Adding graphics to DebugCenter
Last post by HSE - October 12, 2024, 05:41:16 AM
Hi all!

Some time ago I thought that could be useful an interface that allow little programs to show results in a graphical way.

Then I made some additions to DebugCenter for that.

Now a little console program like this can show a graphic:
start proc                                              ;Here is the program entry point
  SysInit                                              ;Runtime initialization of the OOP model
  DbgClearAll                                          ;Clear all DebugCenter windows
 
    ForLpR ir, FP8(0.0), FP8(500.0), FP8(20.0)
        DbgDataPoint ir, @fSlv8(ir^1.5), 0, "primera"
        DbgDataPoint ir, @fSlv8(ir^1.8), 1, "primera"
        DbgDataPoint ir, @fSlv8(ir^2.0), 2, "primera"
    NextR ir
    DbgDrawGraph "primera"

  SysDone                                              ;Runtime finalization of the OOP model

  invoke ExitProcess, 0                                ;Exit program returning 0 to Windows OS
start endp



Naturally, is just a first step  :biggrin:

All files from DebugCenter project, and others files added or changed, are in the zip (binary is 64bits).

Regards, HSE.
#9
Poasm / Re: Run-Time Dynamic Linking E...
Last post by HSE - October 11, 2024, 11:44:02 PM
Fantastic Vortex  :thumbsup:

Just yesterday I was reading that from PEB a program can know if is running inside a debugger  :biggrin:
#10
Examples / Re: Dialog As Main
Last post by zedd151 - October 11, 2024, 11:28:55 AM
Quote from: NoCforMe on October 11, 2024, 11:21:31 AMHmm; when I run this I get a blank window, black, with the title "IDD_DLG". No menu, no nothing.
Apparently it is a "bare bones" template or "skeleton" for the user to use as they see fit. He did say it was a "skeleton".   :smiley:

Thanks for sharing the example, BugCatcher.   :thumbsup: