Skip to content

Commit 4672c2d

Browse files
committed
Fix short jmp assemble in x86.nz, add rasm2 -O <outputfile>
1 parent 05b2fb5 commit 4672c2d

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

TODO.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
0.9.8
88
=====
9-
* Rename anal.plugin into anal.arch ??? to keep in sync with asm.arch
10-
* use __unused if available
9+
--> add test * pdr doesnt works well with antidisasm tricks
10+
* option to disable aslr in rarun2?
1111
* rafind2 : add support for unicode/widestring search
1212
* .dr- # documented... but not working
1313
* libr/debug/p/drx.c <- not used .. debug must have a hw reg api for drx and gpio
1414
* ah -> add hint to define calls that do not return
15-
* pdr doesnt works well with antidisasm tricks, wtf
1615
* continue execution until condition happen (reg, mem, ..)
1716
* rabin2 -x should not work on non-fatmach0 files
1817
* foldable stuff .. was in r1..redo?
@@ -30,10 +29,6 @@
3029
* refactor vmenus.c -> refresh function must be redefined for each menu
3130
// show hints for
3231
0x100005eca ff2540130000 jmp qword [rip+0x1340] [1]
33-
* bar for cursor?
34-
* p= show entropy of current block
35-
- show number of occurrences for each byte
36-
- maybe in 'ad' command, analyze data
3732
* highlight search hits in hexdump
3833
* Implement debugger backtrace properly
3934
* p7 : 7bit encoding (sms)

binr/rasm2/rasm2.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* radare - LGPL - Copyright 2009-2013 - pancake, nibble */
1+
/* radare - LGPL - Copyright 2009-2014 - pancake, nibble */
22

33
#include <stdio.h>
44
#include <string.h>
@@ -44,6 +44,7 @@ static int rasm_show_help(int v) {
4444
" -l [len] Input/Output length\n"
4545
" -L List supported asm plugins\n"
4646
" -o [offset] Set start address for code (default 0)\n"
47+
" -O [file] Output file name (rasm2 -Bf a.asm -O a)\n"
4748
" -s [syntax] Select syntax (intel, att)\n"
4849
" -B Binary input/output (-l is mandatory for binary input)\n"
4950
" -v Show version information\n"
@@ -165,7 +166,7 @@ int main(int argc, char *argv[]) {
165166
char buf[R_ASM_BUFSIZE];
166167
char *arch = NULL, *file = NULL, *filters = NULL, *kernel = NULL, *cpu = NULL;
167168
ut64 offset = 0;
168-
int dis = 0, ascii = 0, bin = 0, ret = 0, bits = 32, c, whatsop = 0;
169+
int fd =-1, dis = 0, ascii = 0, bin = 0, ret = 0, bits = 32, c, whatsop = 0;
169170
ut64 len = 0, idx = 0, skip = 0;
170171

171172
a = r_asm_new ();
@@ -182,7 +183,7 @@ int main(int argc, char *argv[]) {
182183

183184
r_asm_use (a, R_SYS_ARCH);
184185
r_asm_set_big_endian (a, R_FALSE);
185-
while ((c = getopt (argc, argv, "i:k:DCc:eva:b:s:do:Bl:hLf:F:w")) != -1) {
186+
while ((c = getopt (argc, argv, "i:k:DCc:eva:b:s:do:Bl:hLf:F:wO:")) != -1) {
186187
switch (c) {
187188
case 'k':
188189
kernel = optarg;
@@ -219,6 +220,11 @@ int main(int argc, char *argv[]) {
219220
case 'o':
220221
offset = r_num_math (NULL, optarg);
221222
break;
223+
case 'O':
224+
fd = open (optarg, O_TRUNC|O_RDWR|O_CREAT, 0644);
225+
if (fd != -1)
226+
dup2 (fd, 1);
227+
break;
222228
case 'B':
223229
bin = 1;
224230
break;
@@ -345,7 +351,7 @@ int main(int argc, char *argv[]) {
345351
else ret = rasm_asm (buf, offset, length, a->bits, bin);
346352
idx += ret;
347353
offset += ret;
348-
if (!ret) return 0;
354+
if (!ret) goto beach;
349355
} while (!len || idx<length);
350356
return idx;
351357
}
@@ -365,7 +371,10 @@ int main(int argc, char *argv[]) {
365371
a->bits, ascii, bin, dis-1);
366372
} else ret = rasm_asm (argv[optind], offset, len, a->bits, bin);
367373
if (!ret) eprintf ("invalid\n");
368-
return !ret;
374+
ret = !!!ret;
369375
}
370-
return 0;
376+
beach:
377+
if (fd != -1)
378+
close (fd);
379+
return ret;
371380
}

libr/asm/p/asm_x86_nz.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2008-2013 - pancake */
1+
/* Copyright (C) 2008-2014 - pancake */
22

33
#include <stdio.h>
44
#include <string.h>
@@ -920,11 +920,11 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
920920
return -1;
921921
}
922922
} else {
923-
st64 dst = getnum (a, arg) - offset;
923+
st64 dst = getnum (a, arg); // - offset;
924924
ut32 addr = dst;
925925
ut8 *ptr = (ut8 *)&addr;
926926

927-
if (dst+offset == 0 && *arg != '0') {
927+
if (dst == 0 && *arg != '0') {
928928
data[l++] = '\xff';
929929
data[l] = getreg (arg) | 0xe0;
930930
if (data[l] != 0xff)
@@ -942,7 +942,7 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
942942
if (dst>-0x80 && dst<0x7f) {
943943
/* relative byte address */
944944
data[l++] = 0xeb;
945-
data[l++] = (char)(addr-offset-2);
945+
data[l++] = (char)(dst-2);
946946
return l;
947947
} else {
948948
/* absolute address */

libr/socket/socket.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,12 @@ R_API int r_socket_listen (RSocket *s, const char *port, const char *certfile) {
299299
return R_FALSE;
300300
linger.l_onoff = 1;
301301
linger.l_linger = 1;
302-
setsockopt (s->fd, SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof (linger));
302+
setsockopt (s->fd, SOL_SOCKET, SO_LINGER, (void*)&linger, sizeof (linger));
303303
{ // fix close after write bug //
304304
int x = 1500;
305-
setsockopt (s->fd, SOL_SOCKET, SO_SNDBUF, (const char *)&x, sizeof (int));
305+
setsockopt (s->fd, SOL_SOCKET, SO_SNDBUF, (void*)&x, sizeof (int));
306306
}
307-
setsockopt (s->fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
307+
setsockopt (s->fd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof optval);
308308
memset (&s->sa, 0, sizeof (s->sa));
309309
s->sa.sin_family = AF_INET;
310310
s->sa.sin_addr.s_addr = htonl (s->local? INADDR_LOOPBACK: INADDR_ANY);

libr/util/sys.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,11 @@ R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output,
366366
return R_FALSE;
367367
}
368368

369-
if (output) {
370-
*output = outputptr;
371-
} else if (outputptr) {
372-
free(outputptr);
373-
}
369+
if (output) *output = outputptr;
370+
else free (outputptr);
374371
return R_TRUE;
375372
}
376-
free(outputptr);
373+
free (outputptr);
377374
return R_FALSE;
378375
}
379376
#elif __WINDOWS__

0 commit comments

Comments
 (0)