Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | #!/usr/bin/perl |
michael@0 | 2 | |
michael@0 | 3 | my $bigend; # little/big endian |
michael@0 | 4 | my $nxstack; |
michael@0 | 5 | |
michael@0 | 6 | $nxstack = 0; |
michael@0 | 7 | |
michael@0 | 8 | eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}' |
michael@0 | 9 | if $running_under_some_shell; |
michael@0 | 10 | |
michael@0 | 11 | while ($ARGV[0] =~ /^-/) { |
michael@0 | 12 | $_ = shift; |
michael@0 | 13 | last if /^--/; |
michael@0 | 14 | if (/^-n/) { |
michael@0 | 15 | $nflag++; |
michael@0 | 16 | next; |
michael@0 | 17 | } |
michael@0 | 18 | die "I don't recognize this switch: $_\\n"; |
michael@0 | 19 | } |
michael@0 | 20 | $printit++ unless $nflag; |
michael@0 | 21 | |
michael@0 | 22 | $\ = "\n"; # automatically add newline on print |
michael@0 | 23 | $n=0; |
michael@0 | 24 | |
michael@0 | 25 | $thumb = 0; # ARM mode by default, not Thumb. |
michael@0 | 26 | @proc_stack = (); |
michael@0 | 27 | |
michael@0 | 28 | LINE: |
michael@0 | 29 | while (<>) { |
michael@0 | 30 | |
michael@0 | 31 | # For ADRLs we need to add a new line after the substituted one. |
michael@0 | 32 | $addPadding = 0; |
michael@0 | 33 | |
michael@0 | 34 | # First, we do not dare to touch *anything* inside double quotes, do we? |
michael@0 | 35 | # Second, if you want a dollar character in the string, |
michael@0 | 36 | # insert two of them -- that's how ARM C and assembler treat strings. |
michael@0 | 37 | s/^([A-Za-z_]\w*)[ \t]+DCB[ \t]*\"/$1: .ascii \"/ && do { s/\$\$/\$/g; next }; |
michael@0 | 38 | s/\bDCB\b[ \t]*\"/.ascii \"/ && do { s/\$\$/\$/g; next }; |
michael@0 | 39 | s/^(\S+)\s+RN\s+(\S+)/$1 .req r$2/ && do { s/\$\$/\$/g; next }; |
michael@0 | 40 | # If there's nothing on a line but a comment, don't try to apply any further |
michael@0 | 41 | # substitutions (this is a cheap hack to avoid mucking up the license header) |
michael@0 | 42 | s/^([ \t]*);/$1@/ && do { s/\$\$/\$/g; next }; |
michael@0 | 43 | # If substituted -- leave immediately ! |
michael@0 | 44 | |
michael@0 | 45 | s/@/,:/; |
michael@0 | 46 | s/;/@/; |
michael@0 | 47 | while ( /@.*'/ ) { |
michael@0 | 48 | s/(@.*)'/$1/g; |
michael@0 | 49 | } |
michael@0 | 50 | s/\{FALSE\}/0/g; |
michael@0 | 51 | s/\{TRUE\}/1/g; |
michael@0 | 52 | s/\{(\w\w\w\w+)\}/$1/g; |
michael@0 | 53 | s/\bINCLUDE[ \t]*([^ \t\n]+)/.include \"$1\"/; |
michael@0 | 54 | s/\bGET[ \t]*([^ \t\n]+)/.include \"${ my $x=$1; $x =~ s|\.s|-gnu.S|; \$x }\"/; |
michael@0 | 55 | s/\bIMPORT\b/.extern/; |
michael@0 | 56 | s/\bEXPORT\b/.global/; |
michael@0 | 57 | s/^(\s+)\[/$1IF/; |
michael@0 | 58 | s/^(\s+)\|/$1ELSE/; |
michael@0 | 59 | s/^(\s+)\]/$1ENDIF/; |
michael@0 | 60 | s/IF *:DEF:/ .ifdef/; |
michael@0 | 61 | s/IF *:LNOT: *:DEF:/ .ifndef/; |
michael@0 | 62 | s/ELSE/ .else/; |
michael@0 | 63 | s/ENDIF/ .endif/; |
michael@0 | 64 | |
michael@0 | 65 | if( /\bIF\b/ ) { |
michael@0 | 66 | s/\bIF\b/ .if/; |
michael@0 | 67 | s/=/==/; |
michael@0 | 68 | } |
michael@0 | 69 | if ( $n == 2) { |
michael@0 | 70 | s/\$/\\/g; |
michael@0 | 71 | } |
michael@0 | 72 | if ($n == 1) { |
michael@0 | 73 | s/\$//g; |
michael@0 | 74 | s/label//g; |
michael@0 | 75 | $n = 2; |
michael@0 | 76 | } |
michael@0 | 77 | if ( /MACRO/ ) { |
michael@0 | 78 | s/MACRO *\n/.macro/; |
michael@0 | 79 | $n=1; |
michael@0 | 80 | } |
michael@0 | 81 | if ( /\bMEND\b/ ) { |
michael@0 | 82 | s/\bMEND\b/.endm/; |
michael@0 | 83 | $n=0; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | # ".rdata" doesn't work in 'as' version 2.13.2, as it is ".rodata" there. |
michael@0 | 87 | # |
michael@0 | 88 | if ( /\bAREA\b/ ) { |
michael@0 | 89 | my $align; |
michael@0 | 90 | $align = "2"; |
michael@0 | 91 | if ( /ALIGN=(\d+)/ ) { |
michael@0 | 92 | $align = $1; |
michael@0 | 93 | } |
michael@0 | 94 | if ( /CODE/ ) { |
michael@0 | 95 | $nxstack = 1; |
michael@0 | 96 | } |
michael@0 | 97 | s/^(.+)CODE(.+)READONLY(.*)/ .text/; |
michael@0 | 98 | s/^(.+)DATA(.+)READONLY(.*)/ .section .rdata/; |
michael@0 | 99 | s/^(.+)\|\|\.data\|\|(.+)/ .data/; |
michael@0 | 100 | s/^(.+)\|\|\.bss\|\|(.+)/ .bss/; |
michael@0 | 101 | s/$/; .p2align $align/; |
michael@0 | 102 | # Enable NEON instructions but don't produce a binary that requires |
michael@0 | 103 | # ARMv7. RVCT does not have equivalent directives, so we just do this |
michael@0 | 104 | # for all CODE areas. |
michael@0 | 105 | if ( /.text/ ) { |
michael@0 | 106 | # Separating .arch, .fpu, etc., by semicolons does not work (gas |
michael@0 | 107 | # thinks the semicolon is part of the arch name, even when there's |
michael@0 | 108 | # whitespace separating them). Sadly this means our line numbers |
michael@0 | 109 | # won't match the original source file (we could use the .line |
michael@0 | 110 | # directive, which is documented to be obsolete, but then gdb will |
michael@0 | 111 | # show the wrong line in the translated source file). |
michael@0 | 112 | s/$/; .arch armv7-a\n .fpu neon\n .object_arch armv4t/; |
michael@0 | 113 | } |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | s/\|\|\.constdata\$(\d+)\|\|/.L_CONST$1/; # ||.constdata$3|| |
michael@0 | 117 | s/\|\|\.bss\$(\d+)\|\|/.L_BSS$1/; # ||.bss$2|| |
michael@0 | 118 | s/\|\|\.data\$(\d+)\|\|/.L_DATA$1/; # ||.data$2|| |
michael@0 | 119 | s/\|\|([a-zA-Z0-9_]+)\@([a-zA-Z0-9_]+)\|\|/@ $&/; |
michael@0 | 120 | s/^(\s+)\%(\s)/ .space $1/; |
michael@0 | 121 | |
michael@0 | 122 | s/\|(.+)\.(\d+)\|/\.$1_$2/; # |L80.123| -> .L80_123 |
michael@0 | 123 | s/\bCODE32\b/.code 32/ && do {$thumb = 0}; |
michael@0 | 124 | s/\bCODE16\b/.code 16/ && do {$thumb = 1}; |
michael@0 | 125 | if (/\bPROC\b/) |
michael@0 | 126 | { |
michael@0 | 127 | my $prefix; |
michael@0 | 128 | my $proc; |
michael@0 | 129 | /^([A-Za-z_\.]\w+)\b/; |
michael@0 | 130 | $proc = $1; |
michael@0 | 131 | $prefix = ""; |
michael@0 | 132 | if ($proc) |
michael@0 | 133 | { |
michael@0 | 134 | $prefix = $prefix.sprintf("\t.type\t%s, %%function; ",$proc); |
michael@0 | 135 | push(@proc_stack, $proc); |
michael@0 | 136 | s/^[A-Za-z_\.]\w+/$&:/; |
michael@0 | 137 | } |
michael@0 | 138 | $prefix = $prefix."\t.thumb_func; " if ($thumb); |
michael@0 | 139 | s/\bPROC\b/@ $&/; |
michael@0 | 140 | $_ = $prefix.$_; |
michael@0 | 141 | } |
michael@0 | 142 | s/^(\s*)(S|Q|SH|U|UQ|UH)ASX\b/$1$2ADDSUBX/; |
michael@0 | 143 | s/^(\s*)(S|Q|SH|U|UQ|UH)SAX\b/$1$2SUBADDX/; |
michael@0 | 144 | if (/\bENDP\b/) |
michael@0 | 145 | { |
michael@0 | 146 | my $proc; |
michael@0 | 147 | s/\bENDP\b/@ $&/; |
michael@0 | 148 | $proc = pop(@proc_stack); |
michael@0 | 149 | $_ = "\t.size $proc, .-$proc".$_ if ($proc); |
michael@0 | 150 | } |
michael@0 | 151 | s/\bSUBT\b/@ $&/; |
michael@0 | 152 | s/\bDATA\b/@ $&/; # DATA directive is deprecated -- Asm guide, p.7-25 |
michael@0 | 153 | s/\bKEEP\b/@ $&/; |
michael@0 | 154 | s/\bEXPORTAS\b/@ $&/; |
michael@0 | 155 | s/\|\|(.)+\bEQU\b/@ $&/; |
michael@0 | 156 | s/\|\|([\w\$]+)\|\|/$1/; |
michael@0 | 157 | s/\bENTRY\b/@ $&/; |
michael@0 | 158 | s/\bASSERT\b/@ $&/; |
michael@0 | 159 | s/\bGBLL\b/@ $&/; |
michael@0 | 160 | s/\bGBLA\b/@ $&/; |
michael@0 | 161 | s/^\W+OPT\b/@ $&/; |
michael@0 | 162 | s/:OR:/|/g; |
michael@0 | 163 | s/:SHL:/<</g; |
michael@0 | 164 | s/:SHR:/>>/g; |
michael@0 | 165 | s/:AND:/&/g; |
michael@0 | 166 | s/:LAND:/&&/g; |
michael@0 | 167 | s/CPSR/cpsr/; |
michael@0 | 168 | s/SPSR/spsr/; |
michael@0 | 169 | s/ALIGN$/.balign 4/; |
michael@0 | 170 | s/ALIGN\s+([0-9x]+)$/.balign $1/; |
michael@0 | 171 | s/psr_cxsf/psr_all/; |
michael@0 | 172 | s/LTORG/.ltorg/; |
michael@0 | 173 | s/^([A-Za-z_]\w*)[ \t]+EQU/ .set $1,/; |
michael@0 | 174 | s/^([A-Za-z_]\w*)[ \t]+SETL/ .set $1,/; |
michael@0 | 175 | s/^([A-Za-z_]\w*)[ \t]+SETA/ .set $1,/; |
michael@0 | 176 | s/^([A-Za-z_]\w*)[ \t]+\*/ .set $1,/; |
michael@0 | 177 | |
michael@0 | 178 | # {PC} + 0xdeadfeed --> . + 0xdeadfeed |
michael@0 | 179 | s/\{PC\} \+/ \. +/; |
michael@0 | 180 | |
michael@0 | 181 | # Single hex constant on the line ! |
michael@0 | 182 | # |
michael@0 | 183 | # >>> NOTE <<< |
michael@0 | 184 | # Double-precision floats in gcc are always mixed-endian, which means |
michael@0 | 185 | # bytes in two words are little-endian, but words are big-endian. |
michael@0 | 186 | # So, 0x0000deadfeed0000 would be stored as 0x0000dead at low address |
michael@0 | 187 | # and 0xfeed0000 at high address. |
michael@0 | 188 | # |
michael@0 | 189 | s/\bDCFD\b[ \t]+0x([a-fA-F0-9]{8})([a-fA-F0-9]{8})/.long 0x$1, 0x$2/; |
michael@0 | 190 | # Only decimal constants on the line, no hex ! |
michael@0 | 191 | s/\bDCFD\b[ \t]+([0-9\.\-]+)/.double $1/; |
michael@0 | 192 | |
michael@0 | 193 | # Single hex constant on the line ! |
michael@0 | 194 | # s/\bDCFS\b[ \t]+0x([a-f0-9]{8})([a-f0-9]{8})/.long 0x$1, 0x$2/; |
michael@0 | 195 | # Only decimal constants on the line, no hex ! |
michael@0 | 196 | # s/\bDCFS\b[ \t]+([0-9\.\-]+)/.double $1/; |
michael@0 | 197 | s/\bDCFS[ \t]+0x/.word 0x/; |
michael@0 | 198 | s/\bDCFS\b/.float/; |
michael@0 | 199 | |
michael@0 | 200 | s/^([A-Za-z_]\w*)[ \t]+DCD/$1 .word/; |
michael@0 | 201 | s/\bDCD\b/.word/; |
michael@0 | 202 | s/^([A-Za-z_]\w*)[ \t]+DCW/$1 .short/; |
michael@0 | 203 | s/\bDCW\b/.short/; |
michael@0 | 204 | s/^([A-Za-z_]\w*)[ \t]+DCB/$1 .byte/; |
michael@0 | 205 | s/\bDCB\b/.byte/; |
michael@0 | 206 | s/^([A-Za-z_]\w*)[ \t]+\%/.comm $1,/; |
michael@0 | 207 | s/^[A-Za-z_\.]\w+/$&:/; |
michael@0 | 208 | s/^(\d+)/$1:/; |
michael@0 | 209 | s/\%(\d+)/$1b_or_f/; |
michael@0 | 210 | s/\%[Bb](\d+)/$1b/; |
michael@0 | 211 | s/\%[Ff](\d+)/$1f/; |
michael@0 | 212 | s/\%[Ff][Tt](\d+)/$1f/; |
michael@0 | 213 | s/&([\dA-Fa-f]+)/0x$1/; |
michael@0 | 214 | if ( /\b2_[01]+\b/ ) { |
michael@0 | 215 | s/\b2_([01]+)\b/conv$1&&&&/g; |
michael@0 | 216 | while ( /[01][01][01][01]&&&&/ ) { |
michael@0 | 217 | s/0000&&&&/&&&&0/g; |
michael@0 | 218 | s/0001&&&&/&&&&1/g; |
michael@0 | 219 | s/0010&&&&/&&&&2/g; |
michael@0 | 220 | s/0011&&&&/&&&&3/g; |
michael@0 | 221 | s/0100&&&&/&&&&4/g; |
michael@0 | 222 | s/0101&&&&/&&&&5/g; |
michael@0 | 223 | s/0110&&&&/&&&&6/g; |
michael@0 | 224 | s/0111&&&&/&&&&7/g; |
michael@0 | 225 | s/1000&&&&/&&&&8/g; |
michael@0 | 226 | s/1001&&&&/&&&&9/g; |
michael@0 | 227 | s/1010&&&&/&&&&A/g; |
michael@0 | 228 | s/1011&&&&/&&&&B/g; |
michael@0 | 229 | s/1100&&&&/&&&&C/g; |
michael@0 | 230 | s/1101&&&&/&&&&D/g; |
michael@0 | 231 | s/1110&&&&/&&&&E/g; |
michael@0 | 232 | s/1111&&&&/&&&&F/g; |
michael@0 | 233 | } |
michael@0 | 234 | s/000&&&&/&&&&0/g; |
michael@0 | 235 | s/001&&&&/&&&&1/g; |
michael@0 | 236 | s/010&&&&/&&&&2/g; |
michael@0 | 237 | s/011&&&&/&&&&3/g; |
michael@0 | 238 | s/100&&&&/&&&&4/g; |
michael@0 | 239 | s/101&&&&/&&&&5/g; |
michael@0 | 240 | s/110&&&&/&&&&6/g; |
michael@0 | 241 | s/111&&&&/&&&&7/g; |
michael@0 | 242 | s/00&&&&/&&&&0/g; |
michael@0 | 243 | s/01&&&&/&&&&1/g; |
michael@0 | 244 | s/10&&&&/&&&&2/g; |
michael@0 | 245 | s/11&&&&/&&&&3/g; |
michael@0 | 246 | s/0&&&&/&&&&0/g; |
michael@0 | 247 | s/1&&&&/&&&&1/g; |
michael@0 | 248 | s/conv&&&&/0x/g; |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | if ( /commandline/) |
michael@0 | 252 | { |
michael@0 | 253 | if( /-bigend/) |
michael@0 | 254 | { |
michael@0 | 255 | $bigend=1; |
michael@0 | 256 | } |
michael@0 | 257 | } |
michael@0 | 258 | |
michael@0 | 259 | if ( /\bDCDU\b/ ) |
michael@0 | 260 | { |
michael@0 | 261 | my $cmd=$_; |
michael@0 | 262 | my $value; |
michael@0 | 263 | my $prefix; |
michael@0 | 264 | my $w1; |
michael@0 | 265 | my $w2; |
michael@0 | 266 | my $w3; |
michael@0 | 267 | my $w4; |
michael@0 | 268 | |
michael@0 | 269 | s/\s+DCDU\b/@ $&/; |
michael@0 | 270 | |
michael@0 | 271 | $cmd =~ /\bDCDU\b\s+0x(\d+)/; |
michael@0 | 272 | $value = $1; |
michael@0 | 273 | $value =~ /(\w\w)(\w\w)(\w\w)(\w\w)/; |
michael@0 | 274 | $w1 = $1; |
michael@0 | 275 | $w2 = $2; |
michael@0 | 276 | $w3 = $3; |
michael@0 | 277 | $w4 = $4; |
michael@0 | 278 | |
michael@0 | 279 | if( $bigend ne "") |
michael@0 | 280 | { |
michael@0 | 281 | # big endian |
michael@0 | 282 | $prefix = "\t.byte\t0x".$w1.";". |
michael@0 | 283 | "\t.byte\t0x".$w2.";". |
michael@0 | 284 | "\t.byte\t0x".$w3.";". |
michael@0 | 285 | "\t.byte\t0x".$w4."; "; |
michael@0 | 286 | } |
michael@0 | 287 | else |
michael@0 | 288 | { |
michael@0 | 289 | # little endian |
michael@0 | 290 | $prefix = "\t.byte\t0x".$w4.";". |
michael@0 | 291 | "\t.byte\t0x".$w3.";". |
michael@0 | 292 | "\t.byte\t0x".$w2.";". |
michael@0 | 293 | "\t.byte\t0x".$w1."; "; |
michael@0 | 294 | } |
michael@0 | 295 | $_=$prefix.$_; |
michael@0 | 296 | } |
michael@0 | 297 | |
michael@0 | 298 | if ( /\badrl\b/i ) |
michael@0 | 299 | { |
michael@0 | 300 | s/\badrl\s+(\w+)\s*,\s*(\w+)/ldr $1,=$2/i; |
michael@0 | 301 | $addPadding = 1; |
michael@0 | 302 | } |
michael@0 | 303 | s/\bEND\b/@ END/; |
michael@0 | 304 | } continue { |
michael@0 | 305 | printf ("%s", $_) if $printit; |
michael@0 | 306 | if ($addPadding != 0) |
michael@0 | 307 | { |
michael@0 | 308 | printf (" mov r0,r0\n"); |
michael@0 | 309 | $addPadding = 0; |
michael@0 | 310 | } |
michael@0 | 311 | } |
michael@0 | 312 | #If we had a code section, mark that this object doesn't need an executable |
michael@0 | 313 | # stack. |
michael@0 | 314 | if ($nxstack) { |
michael@0 | 315 | printf (" .section\t.note.GNU-stack,\"\",\%\%progbits\n"); |
michael@0 | 316 | } |