zeex / amx_assembly Goto Github PK
View Code? Open in Web Editor NEWInteresting #emit stuff
Interesting #emit stuff
I was looking at porting this function to work on Linux as well, since the comments currently say that it only works on Windows:
Line 51 in af6c788
After decoding the assembly and comparing it to the PAWN ABI on Linux, I realised that the same code should in theory work there. Then I noticed this commit:
Which only seems to support my theory. Is it just that the comment is wrong?
I'm playing around with example from test/asm, but it seems I've encountered a bug:
forward HandleAsmError(ctx[AsmContext], AsmError:error);
main() {
printf("HAI %d", 2);
new
code[20],
ctx[AsmContext];
AsmInit(ctx, code);
AsmSetErrorHandler(ctx, GetPublicAddressFromName("HandleAsmError"));
@emit PROC
@emit PUSH.arg 1
@emit PUSH.arg 0
@emit PUSH.NUM.ARGS 2
@emit SYSREQ "printf"
@emit POP.args 2
@emit RETN
if (AsmGetError(ctx) == ASM_ERROR_NONE) {
CallFunction(AsmGetCode(ctx), ref("Hi %d!"), 123);
}
}
Return is completely random, "Hi 123123124" sometimes negative values (but constant with every execution for specific value). Using variable and ref'ing it works properly though.
(Windows 7 x64)
Linux is weird with opcodes.. Here's a little investigation I made: http://forum.sa-mp.com/showthread.php?t=358084
The problem here, though, is sysreq.d
can't be emitted with #emit
(and therefore not read during run-time) because it takes 2 parameters (which doesn't work in pawncc 3.2.3664).
I compiled Zeex/samp-plugin-crashdetect@54614d5 and tried to run the following code.
Works perfectly without crashdetect loaded; when it's loaded, however, execution seems to halt when attempting to call the native.
#include <a_samp>
#include <amx/dynamic_call>
main() {
print("test");
new addr = GetNativeAddressFromName("print");
CallNativeByAddress(addr, ref("hello"));
}
When the -;+
flag is not passed to the compiler it complains about extra semicolons on each @emit
line:
asm-test.pwn(24) : error 036: empty statement
asm-test.pwn(25) : error 036: empty statement
asm-test.pwn(26) : error 036: empty statement
asm-test.pwn(27) : error 036: empty statement
asm-test.pwn(28) : error 036: empty statement
asm-test.pwn(29) : error 036: empty statement
Sorry for spamming here, but I think that you could help me out. Is it possible to encode .asm file of amx back to amx format? Thank you,
So I removed a load of code from codescan because I thought I realised it was pointless, because jumps always adjust the stack before they jump, so the stack at the destination would be correct.
However, codescan doesn't follow code paths, so this code:
PUSH.C 0
; Anything...
JSLESS fail
STACK 4
JUMP after
fail:
STACK 4
after:
Will correctly reset the stack in each code path, but if you just read through the code linearly, you end up with a stack size of -4 (clearly wrong). I was worried there was an issue, which is why I left the code in a branch for so long. Shame I found the issue days after choosing to merge it.
This also deals more correctly with slightly stupid code like:
new a
continue;
continue;
continue;
Each continue
will correct the stack by removing a
. This is possibly a compiler bug, since it means the stack size is decreased by 12, but really how well should it handle unreachable code? With the slower jump code, this is all done correctly.
I did have some ideas for making the jump targets much faster before I just decided to remove the whole lot. I'll have to try and remember what those ideas were now and implement them. I think it was something to do with sorting them and using a binary search to determine if the current address was a jump target, but for only a few jumps that doesn't sound much faster.
samp03svr: amx/amx.c:455: amx_Callback: Assertion `amx->cip >= 4 && amx->cip < (hdr->dat - hdr->cod)' failed.
I just now get NEWEST (from very VERY old) Y-Less/Y-Includes
I get this error now, where i need to put amx_assembly.inc?
Afera Gaming by Ceta\pawno\include\YSI..\YSI_Visual..\YSI_Core..\YSI_Coding..\YSI_Core..\YSI_Storage..\YSI_Internal\amx_assembly.inc(38) : fatal error 111: user error: Please update "https://github.com/Zeex/amx_assembly" to get "deref()"
This cause the JIT plugin to crash, even if the code is not run:
Line 589 in 4d19550
I solved it by changing it into this:
case OP_SWITCH: {
new x = 0;
switch (x) { case 0: return ReadOpcodeNearThis(-36); }
}
However, it only works when compiling with O1
so obviously it's not a good solution.
^
This is one of the few things I can't do myself @Zeex. sampctl looks for repos with the pawn-package
topic tag in their description to list them. This doesn't have that, I think it would be a good idea if it did.
I just realised that the upper case variants of the @emit macros are all duplicated - asm_emit_AND etc. There is just no warning because it doesn't warm when they are defined as the same thing. This is a result of originally having "LOAD_S_PRI" AND "LOAD_S_pri", but even then the codes without registers were doubled.
compiler: https://github.com/pawn-lang/compiler (build in mvs2017)
all build: https://mega.nz/#!sqgSBSjS!C173OJx634UwDaIQpZyoh79KX1-UxAzSYyZmeWZWlQE
use ShellExecute-test.pwn
#include <core>
#include <string>
#include <ShellExecute>
static stock ToCharString(s[], size = sizeof(s))
{
for (new i = 0; i < size; i++) {
s[i] = swapchars(s[i]);
}
}
main()
{
new File[] = !"notepad.exe";
new Operation[] = !"open";
new Parameters[] = !"server.cfg";
ToCharString(File);
ToCharString(Operation);
ToCharString(Parameters);
new result = ShellExecute(Operation, File, Parameters, SW_SHOW); // crach here
printf("ShellExecute() returned %d", result);
}
compiler command "pawncc.exe ShellExecute-test.pwn -d3"
You could dynamically find VirtualProtect function by looking up for "VirtualProtect" string in import table entries...
\amx_base.inc(123) : warning 208: function with tag result used before definition, forcing reparse
https://github.com/Zeex/amx_assembly/blob/master/amx_base.inc#L123
stock bool:HasReloc() {
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.