Skip to content

Commit

Permalink
fix small produce-idc print issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed Feb 13, 2025
1 parent 84d544c commit 08b4fa9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/id0/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl ID0Section {
b".".iter()
.chain(&info_ref_key)
.chain(b"S")
.chain(&label_ref)
.chain(&label_ref[..7])
.copied()
.collect()
} else {
Expand All @@ -308,7 +308,7 @@ impl ID0Section {
b".".iter()
.chain(&info_ref_key)
.chain(b"S")
.chain(&label_ref)
.chain(&label_ref[..3])
.copied()
.collect()
};
Expand Down
38 changes: 29 additions & 9 deletions src/tools/produce_idc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,22 @@ fn inner_produce_idc(
produce_types(fmt, til)?;
}

// TODO only if non-zero patches
writeln!(fmt)?;
produce_patches(fmt, id0)?;

writeln!(fmt)?;
produce_bytes_info(fmt, id0, til)?;

// TODO only if non-zero functions
writeln!(fmt)?;
produce_functions(fmt, id0, til)?;

writeln!(fmt)?;
produce_seg_regs(fmt, id0, til)?;

writeln!(fmt)?;
produce_patches(fmt, id0, til)?;
produce_all_patches(fmt, id0, til)?;

writeln!(fmt)?;
produce_bytes(fmt, id0, til)?;
Expand Down Expand Up @@ -191,14 +196,14 @@ fn produce_gen_info(
};
writeln!(
fmt,
" set_processor_type(\"{}\", SETPROC_USER)",
" set_processor_type(\"{}\", SETPROC_USER);",
String::from_utf8_lossy(cpu)
)?;
let compiler = match &info {
idb_rs::id0::IDBParam::V1(x) => x.compiler,
idb_rs::id0::IDBParam::V2(x) => x.cc_id.into(),
};
writeln!(fmt, " set_inf_attr(INF_COMPILER, {compiler})")?;
writeln!(fmt, " set_inf_attr(INF_COMPILER, {compiler});")?;
let strlit_break = match &info {
idb_rs::id0::IDBParam::V1(x) => x.ascii_break,
idb_rs::id0::IDBParam::V2(x) => x.strlit_break,
Expand Down Expand Up @@ -230,7 +235,7 @@ fn produce_gen_info(
idb_rs::id0::IDBParam::V1(_x) => {
todo!("flag from V1 x.outflags.show_auto()")
}
idb_rs::id0::IDBParam::V2(x) => x.outflags.show_auto(),
idb_rs::id0::IDBParam::V2(x) => x.outflags.show_auto() as u8,
};
writeln!(
fmt,
Expand Down Expand Up @@ -348,7 +353,7 @@ fn produce_segments(fmt: &mut impl Write, id0: &ID0Section) -> Result<()> {
idb_rs::id0::IDBParam::V1(x) => x.lowoff,
idb_rs::id0::IDBParam::V2(x) => x.lowoff,
};
writeln!(fmt, "set_inf_attr(INF_LOW_OFF, {low_off:#X});")?;
writeln!(fmt, " set_inf_attr(INF_LOW_OFF, {low_off:#X});")?;
let high_off = match &ida_info {
idb_rs::id0::IDBParam::V1(x) => x.highoff,
idb_rs::id0::IDBParam::V2(x) => x.highoff,
Expand Down Expand Up @@ -381,6 +386,21 @@ fn produce_types(fmt: &mut impl Write, til: &TILSection) -> Result<()> {
Ok(())
}

fn produce_patches(fmt: &mut impl Write, _id0: &ID0Section) -> Result<()> {
// InnerRef 66961e377716596c17e2330a28c01eb3600be518 0x1b170e
writeln!(fmt, "//------------------------------------------------------------------------")?;
writeln!(fmt, "// Information about patches")?;
writeln!(fmt)?;
writeln!(fmt, "static Patches_0(void)")?;
writeln!(fmt, "{{")?;
writeln!(fmt, " auto x;")?;
writeln!(fmt, "#define id x")?;
writeln!(fmt)?;
writeln!(fmt, " TODO();")?;
writeln!(fmt, "}}")?;
Ok(())
}

fn produce_type_load(
fmt: &mut impl Write,
_til: &TILSection,
Expand Down Expand Up @@ -489,15 +509,15 @@ fn produce_functions(
_til: &TILSection,
) -> Result<()> {
// TODO find the number of functions
writeln!(fmt, "static Functions_0() ")?;
writeln!(fmt, "static Functions_0(void) ")?;
writeln!(fmt, "{{")?;
writeln!(fmt, " TODO();")?;
writeln!(fmt, "}}")?;
writeln!(fmt)?;
writeln!(fmt, "//------------------------------------------------------------------------")?;
writeln!(fmt, "// Information about functions")?;
writeln!(fmt)?;
writeln!(fmt, "static Functions()")?;
writeln!(fmt, "static Functions(void)")?;
writeln!(fmt, "{{")?;
writeln!(fmt, " Functions_0();")?;
writeln!(fmt, "}}")?;
Expand All @@ -519,13 +539,13 @@ fn produce_seg_regs(
Ok(())
}

fn produce_patches(
fn produce_all_patches(
fmt: &mut impl Write,
_id0: &ID0Section,
_til: &TILSection,
) -> Result<()> {
writeln!(fmt, "//------------------------------------------------------------------------")?;
writeln!(fmt, "// Information about patched bytes")?;
writeln!(fmt, "// Information about all patched bytes:")?;
writeln!(fmt)?;
writeln!(fmt, "static Patches(void)")?;
writeln!(fmt, "{{")?;
Expand Down

0 comments on commit 08b4fa9

Please sign in to comment.