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