flat assembler
Message board for the users of flat assembler.

Index > Windows > SetProcessAffinityMask Error : Invalid Operand

Author
Thread Post new topic Reply to topic
mzneo



Joined: 20 Aug 2008
Posts: 8
mzneo 18 Apr 2009, 07:23
here is the code where i wanted to set the affinity to cpu1, but it fails
Code:

dwcpu1 dd 0x1 -> data

code
invoke SetProcessAffinityMask,[hProcess],dwcpu1
    


but the same above works for dwcpu0 dd 0x0 , here is the affinity was changed to cpu 0.

but i am getting invalid operand for dword value of "1" ?!
Post 18 Apr 2009, 07:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20522
Location: In your JS exploiting you and your system
revolution 18 Apr 2009, 07:30
I think you need it like this:
Code:
invoke SetProcessAffinityMask,[hProcess],[dwcpu1]    
Post 18 Apr 2009, 07:30
View user's profile Send private message Visit poster's website Reply with quote
mzneo



Joined: 20 Aug 2008
Posts: 8
mzneo 18 Apr 2009, 07:48
Code:
BOOL WINAPI SetProcessAffinityMask(
  __in  HANDLE hProcess,
  __in  DWORD_PTR dwProcessAffinityMask
);
    


but i tried debugging with ollydbg by changing and using both of these instruction,
Code:
invoke SetProcessAffinityMask,[hProcess],[dwcpu1]


invoke SetProcessAffinityMask,[hProcess],dwcpu
    

both instruction set the last error as -> ERROR_INVALID_PARAMETER(57)

here i am using GetCurrentProcess to get the handle to the process.
Post 18 Apr 2009, 07:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20522
Location: In your JS exploiting you and your system
revolution 18 Apr 2009, 09:50
My Win32 doc has this:
Code:
   BOOL SetProcessAffinityMask(

    HANDLE hProcess,     // handle to process
    DWORD dwProcessAffinityMask // process affinity mask
   );    
Quote:
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero
Post 18 Apr 2009, 09:50
View user's profile Send private message Visit poster's website Reply with quote
mzneo



Joined: 20 Aug 2008
Posts: 8
mzneo 18 Apr 2009, 11:59
You are right , but i am still getting the same error, here is the stack before the call was made
Code:
0007FFBC              FFFFFFFF  |Arg1 = FFFFFFFF
0007FFC0              00000000  \Arg2 = 00000000

    


but i am getting invalid parameter error, i am also using GetCurrnetProcess.i am not sure where i am going wrong here ?!

here is the error
Code:
ERROR_INVALID_PARAMETER (00000057)
    
Post 18 Apr 2009, 11:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20522
Location: In your JS exploiting you and your system
revolution 18 Apr 2009, 12:09
You can't set an affinity mask of 0. You have to have at least one CPU selected in the mask. Try a value of 1 and see if you get the same error.
Post 18 Apr 2009, 12:09
View user's profile Send private message Visit poster's website Reply with quote
kempis



Joined: 12 Jun 2008
Posts: 49
kempis 18 Apr 2009, 15:08
When using dwcpu0 dd 0x0, no errors.
When using dwcpu1 dd 0x1, error.
Question
Post 18 Apr 2009, 15:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20522
Location: In your JS exploiting you and your system
revolution 18 Apr 2009, 15:46
This works for me:
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.data' readable executable

dwcpu1 dd 0x1

section '.text' code readable executable

start:
    invoke  GetCurrentProcess
   invoke  SetProcessAffinityMask,eax,[dwcpu1]
 stdcall ShowLastError,HWND_DESKTOP
  invoke  ExitProcess,0

proc ShowErrorMessage hWnd,dwError
  local lpBuffer:DWORD
       lea     eax,[lpBuffer]
      invoke  FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0
    invoke  MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK
        invoke  LocalFree,[lpBuffer]
        ret
endp

; VOID ShowLastError(HWND hWnd);

proc ShowLastError hWnd
  invoke  GetLastError
        stdcall ShowErrorMessage,[hWnd],eax
 ret
endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
      user,'USER32.DLL'

  import kernel,\
      GetLastError,'GetLastError',\
    SetLastError,'SetLastError',\
    FormatMessage,'FormatMessageA',\
         LocalFree,'LocalFree',\
  GetCurrentProcess,'GetCurrentProcess',\
  SetProcessAffinityMask,'SetProcessAffinityMask',\
        ExitProcess,'ExitProcess'

  import user,\
         MessageBox,'MessageBoxA'    
Post 18 Apr 2009, 15:46
View user's profile Send private message Visit poster's website Reply with quote
mzneo



Joined: 20 Aug 2008
Posts: 8
mzneo 18 Apr 2009, 16:56
Revolution thanks you are right, with value 0x1 it was working fine now.Thanks a lot Smile
Post 18 Apr 2009, 16:56
View user's profile Send private message Reply with quote
mzneo



Joined: 20 Aug 2008
Posts: 8
mzneo 20 Apr 2009, 06:04
I tried your program , but i am getting following error

"The Specified module could not be found"

when tried to debug i found that EP the error was set as


"ERROR_MOD_NOT_FOUND (0000007E)" - this is causing the issue.
Post 20 Apr 2009, 06:04
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.