NO

Author Topic: Length of string in data section?  (Read 2841 times)

Offline bitcoin

  • Member
  • *
  • Posts: 179
Length of string in data section?
« on: February 05, 2021, 11:20:13 PM »
Hello,
in Masm I can use:

Code: [Select]
fName    db  '\??\D:\Sysenter.txt',0    ;// name of file
fLen     =   $ - fName                  ;// len of name

but Poasm not. What is right way? I tried this:
Code: [Select]
fName    db  "\??\D:\Sysenter.txt",0 
fLen    SIZESTR "\??\D:\Sysenter.txt"

because
Code: [Select]
fLen    SIZESTR fName returned 0x5

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: Length of string in data section?
« Reply #1 on: February 06, 2021, 09:42:13 AM »
Hi bitcoin,

The $ operator has another meaning in Poasm. Reading the manual :

Quote
Assembler identifiers (IA32, AMD64)

You cannot use keywords as identifiers. You can however escape a keyword, by prefixing it with a $ character, to force POASM to handle it as an identifier.

Examples :

.
.
$fastcall  ; will be forced as identifier fastcall, not keyword fastcall

A simple macro can do the job :

Code: [Select]
.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG

includelib  \PellesC\lib\Win\kernel32.lib
includelib  msvcrt.lib


DefStr MACRO id,str

.data

    id  db str
    db  0

    slen SIZESTR str

.code

ENDM


.data

msg     db 'Lenght of the string = %u',0

.code

start:

    DefStr  string,"Hello world!"

    invoke  printf,ADDR msg,slen

    invoke  ExitProcess,0

END start

EDIT : I added the missing file msvcrt.def to the attachment.
« Last Edit: February 07, 2021, 04:03:24 PM by Vortex »
Code it... That's all...

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: Length of string in data section?
« Reply #2 on: February 07, 2021, 04:12:56 PM »
Hi bitcoin,

Another attempt without macros :


Code: [Select]
.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG

includelib  \PellesC\lib\Win\kernel32.lib
includelib  msvcrt.lib

.data

string      db 'Hello world!'
nullterm    db 0

slen        EQU OFFSET nullterm - OFFSET string
msg         db 'Lenght of the string = %u',0
 
.code

start:

    invoke  printf,ADDR msg,slen

    invoke  ExitProcess,0

END start
Code it... That's all...

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: Length of string in data section?
« Reply #3 on: February 08, 2021, 01:54:42 PM »
Thank you Vortex !