[ Vojislav Milunovic @ 11.11.2004. 00:55 ] @
Code: ; File open/write/close foobar shitz some shitz with memory ; c0mrad 11/11/2004 ([email protected]) .486 .model flat, stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\user32.lib .data file db "c:\masm32\progz\a.txt",0 oldstr db "Resource",0 newstr db "c0mrad- ",0 msgT db "Done",0 msgTx db 512 dup(0) format db "' %s ' changed with ' %s ' in file : %s",0dh db " coded by c0mrad in MASM",0 errT db "Error",0 errTx db "Just Error, won't dooooo =(",0 .data? hFile dd ? ;file handle fsize dd ? ;variable for the filesize memptr dd ? ;pointer to allocated memory bread dd ? ;number of read bytes bwrite dd ? ;number of written bytes strlen dd ? ;len of string blabla dd ? ;jedan buffer u koji premestam sumnjiv string da bi ga poredio sa lstrcmp off dd ? ;I need offset to add to memptr so we get ; addres of string we have to change =)) sedx dd ? ; lets save edx !! secx dd ? ; lets save ecx !! .code ; OK here we go =))) start: invoke CreateFile, ADDR file, GENERIC_WRITE + GENERIC_READ,\ NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,\ NULL .IF eax == NULL jmp err .ENDIF mov hFile, eax invoke GetFileSize, hFile, NULL mov fsize, eax invoke GlobalAlloc, GMEM_FIXED, fsize .IF eax == NULL jmp err .ENDIF mov memptr, eax invoke lstrlen, ADDR oldstr mov strlen, eax invoke ReadFile, hFile, memptr, fsize, ADDR bread, NULL .IF eax == NULL jmp err .ENDIF ; ok we have our file loaded to memory and we can start mov eax, strlen add eax, 1 invoke GlobalAlloc, GMEM_FIXED, eax .IF eax == NULL jmp err .ENDIF mov blabla, eax ; Address of our small buffer mov eax, strlen add eax, 1 invoke RtlZeroMemory, blabla, eax mov ecx, memptr ; address of loaded file xor eax, eax ;set eax to 0 with 1 instruction =))) xor ebx, ebx xor edx, edx mov bl, byte ptr[oldstr]; our first letter "R" =) ; Ocigledno se i edx i ecx menjaju kroz ove funkcije tako da ne znam kome od njih ; da jebem mater... ahhhhhhhh e to mi ide na k**** kad se funkcije jebu sa registrima ; pa ih ne vracaju na mesto,,, ali zato uvodim dve nove variable(uostalom kad su ih vracali) ; secx == save ecx ; sedx == save edx ; da sacuvam ova dva registra pre nego sto mi program padne... Jebote covece koji jebeni trip ; ocu CCCCCCCCCCCCCCCCCCCCCCCC nazad..... ; etoooooooooooooooooooooo .WHILE edx != fsize mov sedx, edx mov secx, ecx .IF byte ptr[ecx] == bl ;we got 1st letter, lets check for whole word invoke RtlMoveMemory, blabla, ecx, strlen invoke lstrcmpi, blabla, ADDR oldstr .IF eax == 0 ;we have 2 same stringz! xor eax,eax mov eax, edx ; edx is our offset counter add eax, memptr ; we get memptr+offset now (string in memptr) invoke RtlMoveMemory, eax, ADDR newstr, strlen ;change our stringz .ENDIF .ENDIF mov edx, sedx mov ecx, secx inc ecx ;increment memory pointer inc edx ;increment WHILE counter, i nas offset takodje... .ENDW invoke SetFilePointer, hFile, 0, NULL, FILE_BEGIN invoke WriteFile, hFile, memptr, fsize, ADDR bwrite, NULL .IF eax == NULL jmp err .ENDIF invoke GlobalFree, blabla invoke GlobalFree, memptr invoke CloseHandle, hFile invoke wsprintf, ADDR msgTx, ADDR format, ADDR oldstr, ADDR newstr, ADDR file invoke MessageBox, NULL, ADDR msgTx, ADDR msgT, MB_OK .IF eax == IDOK ; samo iz zajebancije gledam da li je pritisnuto jedino raspolozivo dugme =) .ENDIF invoke ExitProcess, NULL err: invoke MessageBox, NULL, ADDR errTx, ADDR errT, MB_ICONWARNING invoke ExitProcess, NULL end start A da ovaj djavo samo radi sa .txt filovima... E ono sto me ubija jeste da li u windows api ima nesto slicno sa memcmp iz C jezika? Ako ima dajte recite ubi se trazeci to i morao sam da se okrenem samo *.txt filovima da se ne bi smarao i pisao svoj memcmp sto me iskreno mrzi i smara jel sam sve zaboravio... pa sam zato pribegao koriscenju lstrlen funkcije... i da li ima prokleti memcmp ili stogodj slicno medju APIima??? dajte neki savet gde sam pogresio jer stvarno se vise niceg ne secam o asm programiranju =((( poz... ps A da ovaj /masm32/progz/a.txt je neki file koji je pun Resource reci pa sam njih prve uhvatio kao primer koje se menjaju i oldstr i newstr su iste duzine, malo sam koristio " "(razmak) da ih ucinim iste duzine =)))))) |