Recent Posts

Pages: 1 ... 8 9 [10]
91
Programming with NASM / Re: segmentation fault when using ebp-4/ebp-8
« Last post by iAnzu on June 04, 2019, 02:00:30 PM »
Thanks a lot, that solved it! I'm still curious, why windows didn't catch/notice this problem?
92
NASMX / Subtle Bug (I think)
« Last post by pprocacci on June 04, 2019, 01:55:02 AM »
While reading through nasmx.inc trying to learn nasm's preprocessor since it's godly, I was trying to invoke the %else in the below snippet:


Code: [Select]
nasmx.inc: line 1248-1255


%iftoken %{2}_size
%assign %%__argsize %{2}_size
%if (%%__argsize < 1)
%fatal invalid size for %{$__nx_name}.%{1}: %{2}
%endif
%else
%fatal unknown size for %{$__nx_name}.%{1}: %{2}
%endif


I couldn't.  Everything I was throwing at this test was always returning true.

A sample of what I was trying:

Code: [Select]
%include 'nasmx.inc'

NASMX_STRUC POINT
 NASMX_RESERVE x, yadda, 1
 NASMX_RESERVE y, uint32_t, 1
NASMX_ENDSTRUC

Now, it's possible that I'm simply doing it wrong, and quite frankly if it works, why should I care right?
It just bothers me that ${2}_size evaluates to a true value even when it isn't defined as a token as yadda_size for instance isn't defined.

Am I missing something?
93
Other Discussion / Delay in starting a program.
« Last post by Jenneferhart on June 02, 2019, 04:39:25 PM »
:     This  Jennefer again. As you remember I am learning Assembly Language. I use a laptop & Window 10.  I have one question. I am planning to write a Assembly Program, which inquire the price of various vegitables. But before I leave the progam I want activate the same Program few minutes or few hours. I have researched the same question on the Internet, but on Window 10 none of the heading are same as people recomends. Does any body knows what the code is?
94
Programming with NASM / Re: segmentation fault when using ebp-4/ebp-8
« Last post by fredericopissarra on June 02, 2019, 11:42:11 AM »
Are you allocating space on stack for local vars?

Code: [Select]
  push ebp
  mov  ebp,esp
  ...
  sub  esp,4   ; allocate 4 bytes of "local" stack space.
  ...
  mov dword [ebp-4],0
  ...
  add  esp,4  ; deallocate
  ...
  pop ebp
  ret
95
Programming with NASM / segmentation fault when using ebp-4/ebp-8
« Last post by iAnzu on June 02, 2019, 05:43:07 AM »
Hello and thanks for reading!

Windows 64 / Nasm x86 / gcc

A friend helped me with some code and he used ebp-4/ebp-8 to store temporal variables, I thought it would make it more readable to allocate variables in .bss section and use them. Later, I thought I didn't want to have too many variables in .bss section and decided to go back to my friends implementation, also, at that time, my brain already started to like to use ebp-X to store temporal variables.

Linux 64 / Nasm x86 / gcc

Segmentation fault, and I didn't know why for a really long period of time. it occurred to me, as a last resort, to create variables for ebp-4 and others. That made it, no more segmentation fault; but I'm still curious about why did this happened? Why couldn't I use ebp-4 to store temporal variables on Linux when on Windows it was just fine?

nasm -f elf32 -o
gcc  -m32 -o

%macro HexToBin 3 
        ...;code
        ...
        mov         dword [ebp-4], dword 0  ; Segmentation fault
        ...
        ...;code
%%hextobinE:
%endmacro
96
Programming with NASM / Re: fgets, gets, scanf
« Last post by Frank Kotler on June 02, 2019, 12:31:32 AM »
"gets()" is dangerous. Please don't use it - and don't write a gets-equivalent. A big buffer just gives attackerz lots of room to play.

"sys-read" from the keyboard always ends in a linefeed (10). Check the last byte entered, and if it's not 10. read a byte at a time into a dummy buffer until it shows up. That's how I'd handle it.

Best,
Frank

97
Programming with NASM / Re: fgets, gets, scanf
« Last post by iAnzu on June 01, 2019, 09:02:14 PM »
Something I came up with is, since I know the length of the string to be entered, I know where the "null" character will be (with gets), therefore, I just check if the null character is added , if not, I ask again for the string.  ;D

This auxiliar buffer's length is 123 bytes, so if the user enters more than that, the program will break... but at least is more serviceable! I think

98
Programming with NASM / fgets, gets, scanf
« Last post by iAnzu on June 01, 2019, 05:00:51 PM »
Hi,

I'm doing a little nasmx86 program, and at many places I need to get user input, with an specified length.
I'm using Linux  and building as:
nasm -f elf32 -o
gcc  -m32 -o

I would like to know if the user entered more/less than the expected, in which case I would like to clear stdin, and tell the user to try again.


gets:
The problem with this, is I can't control how much input the user will enter, I'm using gets, and then copying "n" bytes to another string, so if I want a 5 char name, and the user enters "123456", it won't cause any problem, because, gets has a large reserved memory to allocate it, then I copy the first 5 bytes to another place and it's done. But it doesn't look good visually.

scanf:
Using special arguments ("%3s") solves the problem, but if the user entered more than the allowed digits, those digits will stay in stdin, and will be used when there's a new call that uses stdin.

fgets:
Same problem with scanf...

I've tried...
- For the case of fgets, and scanf, if the user entered more than the allowed digits I can do a dummy call to gets, to flush stdin, but if the user entered less than the allowed digits, the dummy call to gets is useless, and will make the program ask for non required additional input.
99
Example Code / Re: nasm or SASM?
« Last post by Jenneferhart on May 29, 2019, 12:09:38 AM »
Thanks everybody. I used the "syscall" method.

                                                           Jenn
100
Example Code / Re: nasm or SASM?
« Last post by fredericopissarra on May 28, 2019, 05:18:17 PM »
The way a process terminates depends on the operating system. On Linux, in amd64 version, you can use the syscall instruction to invoke calls to the kernel (system calls). One of them is equivalent to C's exit() function:
Code: [Select]
  mov eax,60  ; 60 is the code for exit().
  mov edi,0  ; 0 on EDI is the code passed to exit().
  syscall  ; finally calls exit(0) - ending the process
But, if you are using Linux, 32 bits version, the syscall instruction isn't present. You must use int 0x80 interface to do system calls. The equivalent from above is:
Code: [Select]
  mov eax,1  ; 1 is the code for exit().
  mov ebx,0  ; 0 on EBX is the code to pass to exit().
  int 0x80  ; calls exit(0), ending the process
Notice the codes are different for amd64 and i386 linuxes...
I don't know how to do for Windows Desktop Applications, except the old DOS way:
Code: [Select]
  mov ax,0x4c00  ; 0x4C is exit; 0x00 is the errorlevel.
  int 0x21

If you disassemble a code created by a C compiler, you'll see a RET instruction in the end of the main() funcion. It is this way because main() is called by the "runtime" object file linked to your program without you knowing... this runtime will call main() and exit your process when main() returns (doing some housekeeping like closing all files, freeing memory, etc)...
Pages: 1 ... 8 9 [10]