Giter VIP home page Giter VIP logo

amx_assembly's Introduction

Overview

  • addressof.inc - Provide addressof to get the compiled address of a function, plus runtime compilation to a simple constant, and a lightweight version with no disasm dependency.
  • amx.inc - Read/write contents of the AMX structure (AMX struct in C code).
  • amx_base.inc - Get base address of the AMX in memory (amx->base).
  • amx_header.inc - Read contents of the AMX header (AMX_HEADER) and query header tables such as publics, natives, tags, etc.
  • amx_memory.inc - Read/write contents of variables using their AMX address (kind of like pointers in C).
  • asm.inc - @emit() for generating new assembly at runtime, similar to what #emit and __emit are for compile-time.
  • codescan.inc - Find patterns in bytecode.
  • disasm.inc - Example of how to disassemble AMX bytecode (i.e. self-disassembly).
  • dynamic_call.inc - Call any function by address or index. Can be very powerful in combination with amx_header.inc.
  • frame_info.inc - Get information about call frames from the stack.
  • heap_alloc.inc - Allocate memory on the AMX heap.
  • jit.inc - Check if running under the JIT plugin.
  • opcode.inc - List of AMX opcodes and utility functions for (un-)relocating opcodes on Linux.
  • os.inc - Detect operating system (Windows vs Linux).
  • phys_memory.inc - Read/write memory of the host process (outside of AMX data).
  • profiler.inc - Simple profiler written purely in Pawn. It can measure execution time of public functions.
  • shellcode.inc - Execute arbitrary native code (doesn't work on Linux).
  • stack_dump.inc - Print stack contents to the console.
  • stack_trace.inc - Print stack trace.
  • windows/import_table.inc - Read the PE import table of the host process.
  • windows/ShellExecute.inc - How to use shellcode and import_table to call a Win32 API function (in this case ShellExecuteA).

Installation

Simply install to your project:

sampctl package install amx_assembly

Include in your code and begin using the library:

#include <amx_assembly\include_name_here>

Usage

There are a few example scripts in the test directory that show how to use some of these includes.

amx_assembly's People

Contributors

is4code avatar oscar-broman avatar y-less avatar zeex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amx_assembly's Issues

FastJumpTargets

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.

GetAmxAddress on Linux

I was looking at porting this function to work on Linux as well, since the comments currently say that it only works on Windows:

// to this script. This function works only on Windows!

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:

ae06f5d

Which only seems to support my theory. Is it just that the comment is wrong?

JIT plugin issue

This cause the JIT plugin to crash, even if the code is not run:

#emit switch 0

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.

windows ShellExecute crash

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"

x32dbg_2018-07-30_19-45-43

Double macros

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.

Add the pawn-package topic.

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.

Empty statement error when using @emit without the "-;+" flag

When the -;+ flag is not passed to the compiler it complains about extra semicolons on each @emitline:

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

Constant parameters failing

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)

ERROR

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()"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.