From revision 15, version 11 we can get the address of loaded functions (from external libraries)
We use for this example the PathAddBackslash function from Shlwapi.dll (version 4.71 or later):
https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathaddbackslashw
Description copied from link above:
Adds a backslash to the end of a string to create the correct syntax for a path. If the source path already has a trailing backslash, no backslash will be added.
There are two versions, the A (Ansi) and W (Unicode Utf16Le). We use the W one, so we place the UTF16LE at buffer BinaryData at offset 0. The PathAddBackSlash get a LPTSTR as parameter which is a long pointer to a string. This string must written with 2 zero bytes (2 for W version). So we make the buffer using clause Clear to fill the buffer with 0.
We read at the link above this: [in, out] pszPath which say that we get to same pointer the output
Also this function has a Return value. This value is the LPSTR (which we provide pushing this in stack), or NULL (zero) if the max_path (internal constant) not allow to add a character blackslash (2 bytes because we have the W version).
Print leftpart$(a$, 32), leftpart$(a$, "5")
// from Version 11 Revision 15
// All declared external functions can return the address using the name only as read only variable.
Declare PathAddBackslash Lib "Shlwapi.PathAddBackslashW" { &Path$ }
Hex "Address of PathAddBackslash: ";PathAddBackslash
// Setup Buffers for Machine Code
Buffer Clear BinaryData as byte*1024
Return BinaryData, 0:="C:"
// Execution buffer change to READ ONLY at code execution.
Buffer code alfa as byte*1024
// Simple program:
// push BinaryData(0)
// call PathAddBackslash
// ; xor eax, eax ; clear eax ; optional
// ret
Pc=0
//* example of __stdcall */ push argN : push arg2 : push arg1 and then Call function
OpLong(0x68, BinaryData(0)) ' parameter the real address of BinaryData at offset 0.
OpLong(0xE8, PathAddBackslash-pc-5-alfa(0)) ' rel32 (relative addres 32bit)
// OpByte(0x31, 0xC0) ' now eax=0 ' without this we get non zero in
Ret() ' return
// PathAddBackslash
Try Ok {
Execute Code alfa, 0
// if eax<>0 then Execute Code raise Error with Error number = eax
Print "eax=0" // not displayed
}
Print "RetValue in eax:";Uint(Error)
Print LeftPart$(eval$(BinaryData, 0, 255),0)
// Call the function PathAddBackslash() (the former way)
Test1()
End
Sub Test1()
Local P$ = "C:"+String$(Chr$(0), 250)
Local A= PathAddBackslash(&P$)
Print LeftPart$(P$,0)
End Sub
Sub Ret()
Return alfa, pc:=0xC3
pc++
End Sub
Sub OpByte()
Return alfa, pc:=number, pc+1:=number
pc+=2
End Sub
Sub OpLong()
Return alfa, pc:=number, pc+1:=number as long
pc+=5
End Sub
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.