flat assembler
Message board for the users of flat assembler.
Index
> Windows > Help aply a algorythm to a string |
Author |
|
r22 12 Mar 2006, 03:14
There's a handful of errors that I saw right off ...
1- name DB 51h means you are defining 1 byte with the value 51h You want name RB 51h which means you are reserving 51h bytes for the name. This goes for serial as well. 2- You use PTR in some cases and in other cases you don't. Get rid of all the PTR's. For instance, mov al,byte ptr name should be mov al, byte[name] 3- To get the value stored in memory you need to put that memory address in brackets []. So to get the first byte's value in the name you need to use mov al, byte [name]. To get the address of name you don't use brackets and make sure the destination is 32bits so mov eax, name would give you the address in memory of the name. 4- You didn't check your code carefully. A little syntax error mov byte ptr serial, I assume you want to store al in the appropriate location in serial, so mov byte [serial], al will work. 5- Your algorithm doesn't iterate through the characters in name or serial. Code: invoke GetDlgItemText,[hwnddlg],IDC_EDIT1,name,50h mov ecx,eax mov byte[serial + ecx], 00h ;;make sure the null is at the end dec ecx ;;we will iterate through the characters backwards loop1: mov al,byte [name + ecx] ;algo rol al,2 add al,32 xor al,15 xor al,16 rol al,2 add al,32 xor al,15 xor al,16 mov byte [serial + ecx], al dec ecx ;;while ecx >= 0 keep going jns loop1 ; end algo The above algorithm should work the way you inteded. There may be more bugs, but assembly programming is best learned by trial, error, and research. |
|||
12 Mar 2006, 03:14 |
|
||CyrUS|| 12 Mar 2006, 15:51
Thank you very much. It works.
One more question how can hi get the handle of a CreateFile and do a WriteFile to the file I have created? |
|||
12 Mar 2006, 15:51 |
|
||CyrUS|| 12 Mar 2006, 15:52
Code: invoke CreateFile,filenam,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 invoke GetDlgItemText,[hwnddlg],IDC_EDIT1,name,50 mov ecx,eax mov byte[serial + ecx], 00h ;;make sure the null is at the end dec ecx ;;we will iterate through the characters backwards mov ebx,ecx loop1: mov al,byte [name + ecx] ;algo rol al,2 add al,32 xor al,15 xor al,16 rol al,2 add al,32 xor al,15 xor al,16 mov byte [serial + ecx], al dec ecx ;;while ecx >= 0 keep going jns loop1 ; end algo invoke MessageBox,HWND_DESKTOP,serial,serial,MB_OK invoke WriteFile,ebp,serial,ebx,0,0 ; ebp??? hfile?? |
|||
12 Mar 2006, 15:52 |
|
okasvi 12 Mar 2006, 16:17
not sure but i think CreateFile returns the handle to created file if it was successful
to where ever you keep data Code: hFile rd 1 for CreateFile Code: invoke CreateFile,filenam,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 mov [hFile],eax for WriteFile Code: invoke WriteFile,[hFile],serial,ebx,0,0 _________________ When We Ride On Our Enemies support reverse smileys |: |
|||
12 Mar 2006, 16:17 |
|
||CyrUS|| 12 Mar 2006, 18:21
Thanks!!
I dont understand why: when I run the program writefile writes the correct bytes in the file and the program crash and leave. Code: invoke CreateFile,filenam,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 mov [hFile],eax invoke GetDlgItemText,[hwnddlg],IDC_EDIT1,name,50 mov ecx,eax mov byte[serial + ecx], 00h ;;make sure the null is at the end mov ebx,ecx dec ecx loop1: mov al,byte [name + ecx] ;algo rol al,2h add al,32h xor al,15h xor al,16h rol al,2h add al,32h xor al,15h xor al,16h mov byte [serial + ecx], al dec ecx ;;while ecx >= 0 keep going jns loop1 ; end algo invoke WriteFile,[hFile],serial,ebx,0,0 ; ebp??? hfile?? invoke CloseHandle,[hFile] |
|||
12 Mar 2006, 18:21 |
|
r22 12 Mar 2006, 19:54
Your 2nd to last parameter in WriteFile needs to be a memory address so the api can store how many bytes were written.
A quick hack such as invoke WriteFile,[hFile],serial,ebx,esp-16,0 should fix the error. |
|||
12 Mar 2006, 19:54 |
|
Madis731 13 Mar 2006, 08:07
can you push "esp-16"? Maybe [esp-16]...or you can sub 16 before pushing it
...anyway you can try erasing the handle Code: invoke WriteFile,[hFile],serial,ebx,0,0 Because handles opened by the program are mercylessly closed when program is shut down But that is not good programming practice. You should define Code: invoke WriteFile,[hFile],serial,ebx,WrittenBytes,0 ;... WrittenBytes dd ? instead |
|||
13 Mar 2006, 08:07 |
|
||CyrUS|| 14 Mar 2006, 17:35
I've found how to do it work!!
Code: hFile dd ? written dd ? Code: invoke WriteFile,[hFile],serial,ebx,written,NULL Thanks all!! |
|||
14 Mar 2006, 17:35 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.