File: modify_opcode_map.pl

package info (click to toggle)
libdisasm 0.23-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,460 kB
  • ctags: 1,988
  • sloc: sh: 9,233; ansic: 7,971; perl: 1,915; asm: 694; makefile: 192; ruby: 3
file content (45 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl
# Quickhack script for making modifications to the opcode table

my %tables;
my @table_table;
my $line = "";
my $pfx="ia32";

open(FILE, shift());
foreach (<FILE>){
	chomp;
	if ( /^TABLE ([A-Za-z0-9_]+)\tindex ([0-9]+)\tshift ([0-9]+)\tmask ([0-9]+)\tminlim ([0-9]+)\tmaxlim ([0-9]+)/ ) {
		# code to handle table start
		$table_table[$2] = sprintf 
			"{ $1, 0x%02X, 0x%02X, 0x%02X, 0x%02X } /* $2 */",
				$3, $4, $5, $6;
		print;
	} elsif ( /^INSN (.+)$/ ) {
		# code to handle insn
		#Table|MnemFlag|DestFlag|SrcFlag|AuxFlag|CPU|mnem|dest|src|aux|flags_effected|cmt
		($t,$mf,$df,$sf,$af,$cpu,$m,$d,$s,$a,$flg,$cmt) = 
			split '\t', $1;

		# -------------------------------------------------
		# OK, add some custom code here to modify the insn
		# -------------------------------------------------


		$line = "$t\t$mf\t$df\t$sf\t$af\t$cpu\t";
		$line = $line . "$m\t$d\t$s\t$a\t$flg\t$cmt";
		print "INSN $line\n";

	} elsif ( /^END TABLE/ ) {
		# code to handle table end
		print;
	} elsif ( /^#/ or /^\s*$/ ) {
		# code to handle comments and blank lines
		print;
	} else {
		# default: print line
		print;
	}
}
close(FILE);