| @@ -103,7 +103,7 @@ class Dis: · 102 unmodified lines |
| 103 | i = 0 | 103 | i = 0 |
| 104 | | 104 | |
| 105 | while i < self.type_size: | 105 | while i < self.type_size: |
| 106 | self.types.append(Type(f)) | 106 | self.types.append(Type().read(f)) |
| 107 | i += 1 | 107 | i += 1 |
| 108 | | 108 | |
| 109 | def read_data(self, f): | 109 | def read_data(self, f): |
| @@ -162,7 +162,8 @@ class Dis: · 52 unmodified lines |
| 162 | else: | 162 | else: |
| 163 | #print "Data", offset | 163 | #print "Data", offset |
| 164 | address = base + offset | 164 | address = base + offset |
| 165 | item = Data(f, code, count, offset, base, array_type, type_) | 165 | item = Data(base, offset, array_type, type_) |
| | 166 | item.read(f, count) |
| 166 | self.data_items.append(item) | 167 | self.data_items.append(item) |
| 167 | if address in self.data: | 168 | if address in self.data: |
| 168 | print "Overwriting existing data item at %x." % address | 169 | print "Overwriting existing data item at %x." % address |
| @@ -174,7 +175,7 @@ class Dis: · 5 unmodified lines |
| 174 | i = 0 | 175 | i = 0 |
| 175 | | 176 | |
| 176 | while i < self.link_size: | 177 | while i < self.link_size: |
| 177 | self.link.append(Link(f)) | 178 | self.link.append(Link().read(f)) |
| 178 | i += 1 | 179 | i += 1 |
| 179 | | 180 | |
| 180 | def read_ldt(self, f): | 181 | def read_ldt(self, f): |
| @@ -207,6 +208,7 @@ class Dis: · 26 unmodified lines |
| 207 | | 208 | |
| 208 | # Write the header. | 209 | # Write the header. |
| 209 | self.code_size = len(self.code) | 210 | self.code_size = len(self.code) |
| | 211 | self.type_size = len(self.types) |
| 210 | | 212 | |
| 211 | # Only unsigned files are currently supported. | 213 | # Only unsigned files are currently supported. |
| 212 | write_OP(f, XMAGIC) | 214 | write_OP(f, XMAGIC) |
| @@ -328,12 +330,21 @@ class RuntimeFlag: · 115 unmodified lines |
| 328 | | 330 | |
| 329 | class Type: | 331 | class Type: |
| 330 | | 332 | |
| 331 | def __init__(self, f): | 333 | def __init__(self, desc_number = 0, size = 0, number_ptrs = 0, array = ""): |
| | 334 | |
| | 335 | self.desc_number = desc_number |
| | 336 | self.size = size |
| | 337 | self.number_ptrs = number_ptrs |
| | 338 | self.array = array |
| | 339 | |
| | 340 | def read(self, f): |
| 332 | | 341 | |
| 333 | self.desc_number = read_OP(f) | 342 | self.desc_number = read_OP(f) |
| 334 | self.size = read_OP(f) | 343 | self.size = read_OP(f) |
| 335 | self.number_ptrs = read_OP(f) | 344 | self.number_ptrs = read_OP(f) |
| 336 | self.array = f.read(self.number_ptrs) | 345 | self.array = f.read(self.number_ptrs) |
| | 346 | |
| | 347 | return self |
| 337 | | 348 | |
| 338 | def __repr__(self): | 349 | def __repr__(self): |
| 339 | | 350 | |
| @@ -367,33 +378,36 @@ class Data: · 27 unmodified lines |
| 367 | "UTF-8 encoded string", "64-bit float", "Array", | 378 | "UTF-8 encoded string", "64-bit float", "Array", |
| 368 | "Set array address", "Restore load address"] | 379 | "Set array address", "Restore load address"] |
| 369 | | 380 | |
| 370 | def __init__(self, f, code, count, offset, base, array_type, type_): | 381 | def __init__(self, base, offset, array_type, type_ = None, array = None): |
| 371 | | 382 | |
| 372 | self.code = code | | |
| 373 | self.count = count | | |
| 374 | self.offset = offset | | |
| 375 | self.base = base | 383 | self.base = base |
| | 384 | self.offset = offset |
| 376 | self.array_type = array_type | 385 | self.array_type = array_type |
| 377 | self.type_ = type_ | 386 | self.type_ = type_ |
| 378 | | 387 | if not array: |
| 379 | self.array = [] | 388 | self.array = [] |
| | 389 | else: |
| | 390 | self.array = array |
| | 391 | |
| | 392 | def read(self, f, count): |
| | 393 | |
| 380 | base = 0 | 394 | base = 0 |
| 381 | i = 0 | 395 | i = 0 |
| 382 | while i < count: | 396 | while i < count: |
| 383 | | 397 | |
| 384 | if array_type == 1: | 398 | if self.array_type == 1: |
| 385 | # 8-bit byte | 399 | # 8-bit byte |
| 386 | self.array.append(read_B(f)) | 400 | self.array.append(read_B(f)) |
| 387 | elif array_type == 2: | 401 | elif self.array_type == 2: |
| 388 | # 32-bit word | 402 | # 32-bit word |
| 389 | self.array.append(read_W(f)) | 403 | self.array.append(read_W(f)) |
| 390 | elif array_type == 3: | 404 | elif self.array_type == 3: |
| 391 | # UTF-8 encoded string (each item is a character) | 405 | # UTF-8 encoded string (each item is a character) |
| 392 | self.array.append(f.read(1)) | 406 | self.array.append(f.read(1)) |
| 393 | elif array_type == 4: | 407 | elif self.array_type == 4: |
| 394 | # 64-bit float | 408 | # 64-bit float |
| 395 | self.array.append(read_F(f)) | 409 | self.array.append(read_F(f)) |
| 396 | elif array_type == 8: | 410 | elif self.array_type == 8: |
| 397 | # 64-bit integer | 411 | # 64-bit integer |
| 398 | self.array.append(read_L(f)) | 412 | self.array.append(read_L(f)) |
| 399 | | 413 | |
| @@ -441,10 +455,16 @@ class Data: · 41 unmodified lines |
| 441 | | 455 | |
| 442 | def write(self, f): | 456 | def write(self, f): |
| 443 | | 457 | |
| 444 | write_B(f, self.code) | 458 | code = self.array_type << 4 |
| | 459 | count = len(self.array) |
| | 460 | |
| | 461 | if count < 16: |
| | 462 | code |= count |
| 445 | | 463 | |
| 446 | if self.count >= 16: | 464 | write_B(f, code) |
| 447 | write_OP(f, self.count) | 465 | |
| | 466 | if count >= 16: |
| | 467 | write_OP(f, count) |
| 448 | | 468 | |
| 449 | write_OP(f, self.offset) | 469 | write_OP(f, self.offset) |
| 450 | | 470 | |
| @@ -464,7 +484,14 @@ class Data: · 13 unmodified lines |
| 464 | | 484 | |
| 465 | class Link: | 485 | class Link: |
| 466 | | 486 | |
| 467 | def __init__(self, f): | 487 | def __init__(self, pc = 0, desc_number = 0, sig = 0, name = ""): |
| | 488 | |
| | 489 | self.pc = pc |
| | 490 | self.desc_number = desc_number |
| | 491 | self.sig = sig |
| | 492 | self.name = name |
| | 493 | |
| | 494 | def read(self, f): |
| 468 | | 495 | |
| 469 | self.pc = read_OP(f) | 496 | self.pc = read_OP(f) |
| 470 | self.desc_number = read_OP(f) | 497 | self.desc_number = read_OP(f) |
| @@ -486,7 +513,12 @@ class Link: · 15 unmodified lines |
| 486 | | 513 | |
| 487 | class LDT: | 514 | class LDT: |
| 488 | | 515 | |
| 489 | def __init__(self, f): | 516 | def __init__(self, sig = 0, name = ""): |
| | 517 | |
| | 518 | self.sig = sig |
| | 519 | self.name = name |
| | 520 | |
| | 521 | def read(self, f): |
| 490 | | 522 | |
| 491 | self.sig = _read(f, ">I") # unsigned for hashes | 523 | self.sig = _read(f, ">I") # unsigned for hashes |
| 492 | self.name = read_C(f) | 524 | self.name = read_C(f) |