WIP
This commit is contained in:
parent
69e7476904
commit
cb80922d38
2 changed files with 775 additions and 3187 deletions
|
|
@ -445,19 +445,11 @@ impl DexWriter {
|
|||
}
|
||||
Instruction::ConstString { .. } => {
|
||||
let size = ins
|
||||
.get_raw_ins(
|
||||
Some(&self.strings),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.with_context(|| format!("In code of {}", method_id.__repr__()))?
|
||||
.get_raw_ins(GetRawInsParam {
|
||||
strings: Some(&self.strings),
|
||||
..GetRawInsParam::default()
|
||||
})
|
||||
.with_context(|| format!("Error in code of {}", method_id.__repr__()))?
|
||||
.size()
|
||||
/ 2;
|
||||
min_addr += size;
|
||||
|
|
@ -481,18 +473,10 @@ impl DexWriter {
|
|||
}
|
||||
Instruction::ConstString { .. } => {
|
||||
addr += ins
|
||||
.get_raw_ins(
|
||||
Some(&self.strings),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)?
|
||||
.get_raw_ins(GetRawInsParam {
|
||||
strings: Some(&self.strings),
|
||||
..GetRawInsParam::default()
|
||||
})?
|
||||
.size()
|
||||
/ 2;
|
||||
// should not fail after
|
||||
|
|
@ -539,45 +523,43 @@ impl DexWriter {
|
|||
// https://cs.android.com/android/platform/superproject/main/+/main:art/runtime/verifier/method_verifier.cc;drc=e8c3e7be783937a340cd4f3280b69962d6f1ea0c;l=1347
|
||||
// The ART check if the array data table is 4 bytes aligned (= 2 ins alligned)
|
||||
// TODO: check how it is donne in android and other dex generation code.
|
||||
let nop = (Instruction::Nop {}).get_raw_ins(
|
||||
None, None, None, None, None, None, None, None, None, None,
|
||||
)?;
|
||||
let nop = (Instruction::Nop {}).get_raw_ins(GetRawInsParam::default())?;
|
||||
payload_addr += nop.size() / 2;
|
||||
payloads.push(nop);
|
||||
}
|
||||
let data_offset = payload_addr as i32 - addr as i32;
|
||||
payload_addr += payload.size() / 2;
|
||||
payloads.push(payload);
|
||||
let ins = ins.get_raw_ins(
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(data_offset),
|
||||
)?;
|
||||
let ins = ins
|
||||
.get_raw_ins(GetRawInsParam {
|
||||
data_offset: Some(data_offset),
|
||||
..GetRawInsParam::default()
|
||||
})
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to convert instruction {} (found in code of {}) to raw instruction",
|
||||
ins.__repr__(),
|
||||
method_id.__repr__()
|
||||
)
|
||||
})?;
|
||||
addr += ins.size() / 2;
|
||||
insns.push(ins);
|
||||
}
|
||||
Instruction::Goto { .. } => {
|
||||
let goto_size = goto_sizes[goto_idx];
|
||||
goto_idx += 1;
|
||||
let ins = ins.get_raw_ins(
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some((addr, &label_addrs)),
|
||||
Some(goto_size),
|
||||
None,
|
||||
)?;
|
||||
let ins = ins.get_raw_ins(GetRawInsParam {
|
||||
jump_data: Some((addr, &label_addrs)),
|
||||
goto_size: Some(goto_size),
|
||||
..GetRawInsParam::default()
|
||||
})
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to convert instruction {} (found in code of {}) to raw instruction",
|
||||
ins.__repr__(),
|
||||
method_id.__repr__()
|
||||
)
|
||||
})?;
|
||||
addr += ins.size() / 2;
|
||||
insns.push(ins);
|
||||
}
|
||||
|
|
@ -608,63 +590,58 @@ impl DexWriter {
|
|||
// https://cs.android.com/android/platform/superproject/main/+/main:art/runtime/verifier/method_verifier.cc;drc=e8c3e7be783937a340cd4f3280b69962d6f1ea0c;l=1464
|
||||
// The ART check if the switch table is 4 bytes aligned (= 2 ins alligned)
|
||||
// TODO: check how it is donne in android and other dex generation code.
|
||||
let nop = (Instruction::Nop {}).get_raw_ins(
|
||||
None, None, None, None, None, None, None, None, None, None,
|
||||
)?;
|
||||
let nop = (Instruction::Nop {}).get_raw_ins(GetRawInsParam::default())?;
|
||||
payload_addr += nop.size() / 2;
|
||||
payloads.push(nop);
|
||||
}
|
||||
let data_offset = payload_addr as i32 - addr as i32;
|
||||
payload_addr += payload.size() / 2;
|
||||
payloads.push(payload);
|
||||
let ins = ins.get_raw_ins(
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(data_offset),
|
||||
)?;
|
||||
let ins = ins.get_raw_ins(GetRawInsParam {
|
||||
data_offset: Some(data_offset),
|
||||
..GetRawInsParam::default()
|
||||
})
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to convert instruction {} (found in code of {}) to raw instruction",
|
||||
ins.__repr__(),
|
||||
method_id.__repr__()
|
||||
)
|
||||
})?;
|
||||
addr += ins.size() / 2;
|
||||
insns.push(ins);
|
||||
}
|
||||
Instruction::InvokeCustom { call_site, .. } => {
|
||||
let call_site_idx = self.call_site_ids.len();
|
||||
self.insert_call_site_item(&call_site)?;
|
||||
let ins = ins.get_raw_ins(
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(call_site_idx),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)?;
|
||||
let ins = ins.get_raw_ins(GetRawInsParam {
|
||||
call_site_idx: Some(call_site_idx),
|
||||
..GetRawInsParam::default()
|
||||
})
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to convert instruction {} (found in code of {}) to raw instruction",
|
||||
ins.__repr__(),
|
||||
method_id.__repr__()
|
||||
)
|
||||
})?;
|
||||
addr += ins.size() / 2;
|
||||
insns.push(ins);
|
||||
}
|
||||
Instruction::ConstMethodHandle { handle, .. } => {
|
||||
let method_handle_idx = self.method_handles.len();
|
||||
self.insert_method_handle(&handle)?;
|
||||
let ins = ins.get_raw_ins(
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(method_handle_idx),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)?;
|
||||
let ins = ins.get_raw_ins(GetRawInsParam {
|
||||
method_handle_idx: Some(method_handle_idx),
|
||||
..GetRawInsParam::default()
|
||||
})
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to convert instruction {} (found in code of {}) to raw instruction",
|
||||
ins.__repr__(),
|
||||
method_id.__repr__()
|
||||
)
|
||||
})?;
|
||||
addr += ins.size() / 2;
|
||||
insns.push(ins);
|
||||
}
|
||||
|
|
@ -728,24 +705,21 @@ impl DexWriter {
|
|||
Instruction::Label { .. } => (),
|
||||
_ => {
|
||||
let ins = ins
|
||||
.get_raw_ins(
|
||||
Some(&self.strings),
|
||||
Some(&self.type_ids),
|
||||
Some(&self.field_ids),
|
||||
Some(&self.method_ids),
|
||||
Some(&self.proto_ids),
|
||||
None,
|
||||
None,
|
||||
Some((addr, &label_addrs)),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.get_raw_ins(GetRawInsParam {
|
||||
strings: Some(&self.strings),
|
||||
type_ids: Some(&self.type_ids),
|
||||
field_ids: Some(&self.field_ids),
|
||||
method_ids: Some(&self.method_ids),
|
||||
proto_ids: Some(&self.proto_ids),
|
||||
jump_data: Some((addr, &label_addrs)),
|
||||
..GetRawInsParam::default()
|
||||
})
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to convert instruction {} (found in code of {}) to raw instruction",
|
||||
ins.__repr__(),
|
||||
method_id.__repr__()
|
||||
)
|
||||
"Failed to convert instruction {} (found in code of {}) to raw instruction",
|
||||
ins.__repr__(),
|
||||
method_id.__repr__()
|
||||
)
|
||||
})?;
|
||||
addr += ins.size() / 2;
|
||||
insns.push(ins);
|
||||
|
|
@ -754,8 +728,7 @@ impl DexWriter {
|
|||
}
|
||||
if addr % 2 != 0 {
|
||||
// make sure the payload section is 4 bytes aligned
|
||||
let nop = (Instruction::Nop {})
|
||||
.get_raw_ins(None, None, None, None, None, None, None, None, None, None)?;
|
||||
let nop = (Instruction::Nop {}).get_raw_ins(GetRawInsParam::default())?;
|
||||
//addr += nop.size() / 2;
|
||||
insns.push(nop);
|
||||
}
|
||||
|
|
@ -796,10 +769,10 @@ impl DexWriter {
|
|||
self.debug_info_items.push(item);
|
||||
debug_info_off + 1
|
||||
};
|
||||
let handlers = if handlers.list.is_empty() {
|
||||
let handlers = if encoded_handlers.list.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(handlers)
|
||||
Some(encoded_handlers)
|
||||
};
|
||||
let item = CodeItem {
|
||||
registers_size: code.registers_size,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue