Skip to content

Commit

Permalink
Fix vala bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed May 8, 2024
1 parent e3f8cca commit 9df8745
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 104 deletions.
6 changes: 4 additions & 2 deletions vapi/r_anal.vapi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2010-2018 - pancake */
/* radare - LGPL - Copyright 2010-2024 - pancake */

/* this vapi is broken as shit... we need to rename some stuff here ..
if we can just avoid to use cname CCode attribute... */
Expand Down Expand Up @@ -342,8 +342,10 @@ namespace Radare {
// public Block bb_from_offset (uint64 addr);

[Compact]
[CCode (cprefix="r_anal_op_", cname="RAnalOp")]
[CCode (cprefix="r_anal_op_", free_function="r_anal_op_free", cname="RAnalOp")]
public class Op {
[CCode (cname = "r_anal_op_new")]
public Op ();
public string mnemonic;
public uint64 addr;
public int type;
Expand Down
48 changes: 3 additions & 45 deletions vapi/r_asm.vapi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* radare - LGPL - Copyright 2010-2024 - pancake */

namespace Radare {
/**
Expand Down Expand Up @@ -91,49 +92,6 @@ public class RAsm {
SRCREG2
}

/**
* Represents assembly opcodes.
*/
[CCode (cname="RAsmOp", destroy_function="", unref_function="")]
public struct Op {
/**
* The instruction length.
*/
public int size;
/**
* The instruction size in bits
*/
public int bitsize;
/**
* The instruction payload.
*/
public int payload;

/*
XXX valabind doesnt support inner structs that are not pointers
/**
* The bytes
*
public RStrBuf buf;
/**
* The assembly representation.
*
public RStrBuf buf_asm;
*/

/**
* Retrieves the hexadecimal representation of the instruction.
* @return the actual opcode, in hexadecimal.
*/
public string get_hex();
/**
* Retrieves the assembly representation of the instruction.
* @return such representation.
*/
public string get_asm();
}

/**
* Models decompiled assembly code.
*/
Expand Down Expand Up @@ -174,11 +132,11 @@ public class RAsm {
public bool set_big_endian(bool big);
*/
// TODO: Use Code? instead of op??
public int disassemble(out Op op, uint8* buf, int length);
public int disassemble(RAnal.Op op, uint8* buf, int length);
/**
* Assemble provided instruction into an Op, returns instruction size in bytes.
*/
public int assemble(out Op op, string buf);
public int assemble(RAnal.Op op, string buf);
public Code? mdisassemble(uint8 *buf, int length);
public Code? massemble(string buf);
// public Code? assemble_file(string file);
Expand Down
50 changes: 49 additions & 1 deletion vapi/r_crypto.vapi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009 pancake<@nopcode.org> */
/* radare - LGPL - Copyright 2009-2024 pancake<@nopcode.org> */

[CCode (cheader_filename="r_crypto.h", cprefix="r_crypto", lower_case_cprefix="r_crypto_")]
namespace Radare {
Expand Down Expand Up @@ -29,4 +29,52 @@ namespace Radare {
public int final(uint8 *buf, int len);
public uint8* get_output();
}
/* This vapi has been manually generated by me */
[Compact]
[CCode (cheader_filename="r_hash.h", cprefix="r_hash_", cname="RHash", free_function="r_hash_free")]
public class RHash {
[CCode (cprefix="R_HASH_")]
[Flags]
public enum Algorithm {
ALL = 0,
MD5 = 1,
SHA1 = 2,
SHA256 = 4,
SHA384 = 8,
SHA512 = 16,
}

[CCode (cprefix="R_HASH_SIZE_", cname="int")]
public enum Size {
MD4 = 16,
MD5 = 16,
SHA1 = 16,
SHA256 = 32,
SHA384 = 64,
SHA512 = 64,
}
public RHash(bool rst, int bits);

/* checksum */
// public static uint16 crc16(uint16 crc, uint8 *buf, uint64 len);
// public static uint32 crc32(uint8 *buf, uint64 len);
public static uint16 xor(uint8 *buf, uint64 len);
public static uint32 xorpair(uint8 *buf, uint64 len);
public static uint8 parity(uint8 *buf, uint64 len);
public static uint8 mod255(uint8 *buf, uint64 len);

/* analitics */
public static uint8 hamdist(uint8 *buf, uint64 len);
public static double entropy(uint8 *buf, uint64 len);
public static int pcprint(uint8 *buf, uint64 len);

/* methods */
//public RHash(bool rst);
public uint8 *do_md4(uint8 *input, uint32 len);
public uint8 *do_md5(uint8 *input, uint32 len);
public uint8 *do_sha1(uint8 *input, uint32 len);
public uint8 *do_sha256(uint8 *input, uint32 len);
public uint8 *do_sha384(uint8 *input, uint32 len);
public uint8 *do_sha512(uint8 *input, uint32 len);
}
}
50 changes: 0 additions & 50 deletions vapi/r_hash.vapi

This file was deleted.

5 changes: 3 additions & 2 deletions vapi/t/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ search:
valac --vapidir=.. search.vala --pkg r_search --pkg r_util

asm:
valac --vapidir=.. --pkg r_asm asm.vala
#valac --vapidir=.. --pkg r_asm asm.vala
valac --vapidir=.. --pkg r_anal --pkg r_asm --pkg r_syscall asm.vala

bin:
valac --vapidir=.. bin.vala --pkg r_bin --pkg r_util

hash:
valac --vapidir=.. hash.vala --pkg r_hash
valac --vapidir=.. hash.vala --pkg r_crypto

socket:
valac --vapidir=.. socket.vala --pkg r_socket --pkg posix
Expand Down
6 changes: 3 additions & 3 deletions vapi/t/asm.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class RAsmExample
}, pseudo);
*/

RAsm.Op op;
RAnal.Op op = new RAnal.Op();
uint8 *buf = "\x83\xe4\xf0";
string buf2 = "jmp _foo;nop;nop;nop;_foo:push eax";
if (st.disassemble(out op, buf, 3) <1) {
if (st.disassemble(op, buf, 3) <1) {
stderr.printf ("internal error\n");
} else {
stdout.printf ("disasm: %s\n", op.get_asm());
stdout.printf ("disasm: %s\n", op.mnemonic);
}
RAsm.Code? code = st.massemble(buf2);
if (code == null) {
Expand Down
5 changes: 4 additions & 1 deletion vapi/t/bin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ public void main (string[] args) {
// bin.iob.bind (io);
bfo.fd = desc.fd;
// if (bin.load (args[1], 0,0,0,desc.fd,0) != 1)
if (bin.open (args[1], ref bfo) != 1)
if (bin.open (args[1], ref bfo) != 1) {
error ("Cannot open binary file\n");
}

uint64 baddr = bin.get_baddr();
print ("Base addr: 0x%08"+uint64.FORMAT_MODIFIER+"x\n", baddr);
/*
foreach (var sym in bin.get_symbols ())
print ("0x%08"+uint64.FORMAT_MODIFIER+"x - %s\n",
baddr+sym.vaddr, sym.name);
foreach (var sec in bin.get_sections())
print ("0x%08"+uint64.FORMAT_MODIFIER+"x - %s\n",
baddr+sec.vaddr, sec.name);
*/
}

0 comments on commit 9df8745

Please sign in to comment.