2013年6月18日 星期二

Procedure.s apicall(call.s)



Procedure.s apicall(call.s)
  argc.l=Val(StringField(call, 1, "|"))
  lib.s=StringField(call, 2, "|")
  func.s=StringField(call, 3, "|")
  Dim argv.s(argc-1)
  Dim argv2.s(argc-1)
  Dim argvp.l(argc-1)
  Dim argvv.l(argc-1)
  Dim returnarg.l(argc-1)
  For i=0 To argc-1
    argv(i)=StringField(call, 4+i, "|")
    argv2(i)=Space(1024)
    argvp(i)=@argv2(i)
    argvv(i)=0 
    Select Left(argv(i),1)
      Case "@"
        argv2(i)=Mid(argv(i),2)
      Case "s"
        returnarg(i)=1
      Case "v"
        argvp(i)=@argvv(i)
        If Len(argv(i))>1
          argvv(i)=Val(Mid(argv(i),2))
        EndIf
        returnarg(i)=2
      Default
        argvp(i)=Val(argv(i))
    EndSelect
   
  Next
 
  result.l=OpenLibrary(#PB_Any,lib)
 
 
  point.l=GetFunction(result,func)
 
  returns.s=""
 

  Select argc
    Case 0    
      returns=Str(CallFunctionFast(Point))+"|"
    Case 1   
      returns=Str(CallFunctionFast(Point,argvp(0)))+"|"
    Case 2       
      returns=Str(CallFunctionFast(Point,argvp(0),argvp(1)))+"|"
    Case 3        
      returns=Str(CallFunctionFast(Point,argvp(0),argvp(1),argvp(2)))+"|"
    Case 4    
      returns=Str(CallFunctionFast(Point,argvp(0),argvp(1),argvp(2),argvp(3)))+"|"
    Case 5        
      returns=Str(CallFunctionFast(Point,argvp(0),argvp(1),argvp(2),argvp(3),argvp(4)))+"|"
    Case 6    
      returns=Str(CallFunctionFast(Point,argvp(0),argvp(1),argvp(2),argvp(3),argvp(4),argvp(5)))+"|" 
    Case 7    
      returns=Str(CallFunctionFast(Point,argvp(0),argvp(1),argvp(2),argvp(3),argvp(4),argvp(5),argvp(6)))+"|"
    Case 8    
      returns=Str(CallFunctionFast(Point,argvp(0),argvp(1),argvp(2),argvp(3),argvp(4),argvp(5),argvp(6),argvp(7)))+"|"     
     
  EndSelect
  CloseLibrary(result)
 
  For i=0 To argc-1
   
    Select returnarg(i)
      Case 1
        For j=0 To 1023
          If PeekB(@argv2(i)+j)=0
            PokeB(@argv2(i)+j,32) 
          EndIf
        Next j
        argv2(i)=RTrim(argv2(i))
        returns=returns+argv2(i)+"|"
      Case 2
        returns=returns+Str(argvv(i))+"|"
    EndSelect
   
  Next
 
  ProcedureReturn returns
EndProcedure
;s: output string, v: output value
;api USER32.DLL|MessageBoxA|0|hello world 1|test|0
;Debug apicall("4|USER32.DLL|MessageBoxA|0|@hello world 1|@test|0")
;Debug apicall("2|Kernel32.dll|GetWindowsDirectoryA|s|512")
;Debug apicall("2|Kernel32.dll|GetTempPathA|512|s")
;Debug apicall("3|Advapi32.dll|RegOpenKeyA|2147483650|@SOFTWARE\Microsoft\Windows\CurrentVersion\Run|v")
;Debug apicall("6|Advapi32.dll|RegSetValueExA|handle_number|@WindowsInit|0|1|@c:\windows\test.exe|19")
;Debug apicall("6|Shell32.dll|ShellExecuteA|0|0|@notepad.exe|0|0|1") 
;debug apicall("2|Kernel32.dll|GetComputerNameA|s|v256")
apicall("4|USER32.DLL|MessageBoxA|0|@hello world 1|@test|0")

沒有留言:

張貼留言